Commit 168dbece by Demid Merzlyakov

LAST_SEEN_CITY event implemented.

parent 1155d35a
......@@ -8,6 +8,7 @@
import Foundation
import CoreLocation
import UIKit
import MoEngage
public protocol LocationManagerDelegate: class {
func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?)
......@@ -54,11 +55,14 @@ public class LocationManager {
DispatchQueue.main.async { [weak self] in
self?._locations = locations
self?._selectedLocationIndex = selectedIndex
self?.lastSeenCityId = self?.selectedLocation?.cityId
self?.handleLocationsChange(locationsChanged: true, selectedLocationChanged: true)
self?.updateEverythingIfNeeded()
}
}
private var lastSeenCityId: String?
private func handleLocationsChange(locationsChanged: Bool, selectedLocationChanged: Bool) {
if locationsChanged {
log.info("Locations list updated: \(locations.map { $0.description }.joined(separator: ", "))")
......@@ -73,6 +77,16 @@ public class LocationManager {
guard let self = self else { return }
delegate.locationManager(self, changedSelectedLocation: newLocation)
}
if newLocation?.cityId != lastSeenCityId {
analytics(log: .ANALYTICS_PUSH_NOTIFICATIONS_LAST_SEEN_CITY,params: [
.ANALYTICS_KEY_LAST_SEEN_CITY_COUNTRY: newLocation?.countryCode ?? "",
.ANALYTICS_KEY_LAST_SEEN_CITY_STATE: newLocation?.region ?? "",
.ANALYTICS_KEY_LAST_SEEN_CITY_CITY: newLocation?.cityName ?? "",
.ANALYTICS_KEY_LAST_SEEN_CITY_CITY_ID: newLocation?.cityId ?? "::"
])
MoEngage.sharedInstance().setUserAttribute(newLocation?.cityId, forKey: "LAST_SEEN_CITY")
lastSeenCityId = newLocation?.cityId
}
}
storage.save(locations: locations, selectedIndex: selectedLocationIndex)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment