Skip to content

Commit

Permalink
Merge pull request #97 from CovidTrackerFr/develop
Browse files Browse the repository at this point in the history
Release 1.1.0 - Merge develop into main
  • Loading branch information
victor-sarda authored May 7, 2021
2 parents eb206cf + d6c3cb0 commit a80245a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
29 changes: 28 additions & 1 deletion ViteMaDose/Helpers/Utils/AppAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import FirebaseAnalytics

struct AppAnalytics {
enum AppAnalytics {

enum ScreenName: String {
case home = "home"
Expand Down Expand Up @@ -52,4 +52,31 @@ struct AppAnalytics {
])
}

static func trackSearchEvent(
searchResult: LocationSearchResult,
appointmentsCount: Int,
availableCentresCount: Int,
unAvailableCentresCount: Int,
sortOption: CentresListSortOption
) {
let eventName = searchResult.coordinates == nil ? "search_by_departement" : "search_by_commune"
Analytics.logEvent(eventName, parameters: [
"search_departement": "\(searchResult.departmentCode) - \(searchResult.name)",
"search_nb_doses": appointmentsCount as NSNumber,
"search_nb_lieu_vaccination": availableCentresCount as NSNumber,
"search_nb_lieu_vaccination_inactive": unAvailableCentresCount as NSNumber,
"search_filter_type": sortOption.analyticsValue
])
}
}

private extension CentresListSortOption {
var analyticsValue: String {
switch self {
case .closest:
return "au plus proche"
case .fastest:
return "au plus tot"
}
}
}
5 changes: 3 additions & 2 deletions ViteMaDose/Helpers/Utils/UserDefaultsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ extension UserDefaults {
guard case let .success(results) = searchResultData?.decode([LocationSearchResult].self) else {
return []
}
return results
return results.unique(by: \.formattedName)
}
set {
guard let encoded = try? Self.encoder.encode(newValue.uniqued()) else {
let results = newValue.unique(by: \.formattedName)
guard let encoded = try? Self.encoder.encode(results) else {
return
}
setValue(encoded, forKey: Key.lastSearchResults.rawValue)
Expand Down
8 changes: 8 additions & 0 deletions ViteMaDose/ViewModels/CentresList/CentresListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class CentresListViewModel {
let centresCells = createVaccinationCentreCellsFor(for: vaccinationCentresList)
let footerText = locationVaccinationCentres.first?.formattedLastUpdated

AppAnalytics.trackSearchEvent(
searchResult: searchResult,
appointmentsCount: availableCentres.allAppointmentsCount,
availableCentresCount: availableCentres.count,
unAvailableCentresCount: unavailableCentres.count,
sortOption: userDefaults.centresListSortOption
)

delegate?.reloadTableView(with: headingCells, andCentresCells: centresCells, animated: animated)
delegate?.reloadTableViewFooter(with: footerText)
}
Expand Down

0 comments on commit a80245a

Please sign in to comment.