Commit 168dbece by Demid Merzlyakov

LAST_SEEN_CITY event implemented.

parent 1155d35a
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import Foundation import Foundation
import CoreLocation import CoreLocation
import UIKit import UIKit
import MoEngage
public protocol LocationManagerDelegate: class { public protocol LocationManagerDelegate: class {
func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?) func locationManager(_ locationManager: LocationManager, changedSelectedLocation newLocation: Location?)
...@@ -54,11 +55,14 @@ public class LocationManager { ...@@ -54,11 +55,14 @@ public class LocationManager {
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
self?._locations = locations self?._locations = locations
self?._selectedLocationIndex = selectedIndex self?._selectedLocationIndex = selectedIndex
self?.lastSeenCityId = self?.selectedLocation?.cityId
self?.handleLocationsChange(locationsChanged: true, selectedLocationChanged: true) self?.handleLocationsChange(locationsChanged: true, selectedLocationChanged: true)
self?.updateEverythingIfNeeded() self?.updateEverythingIfNeeded()
} }
} }
private var lastSeenCityId: String?
private func handleLocationsChange(locationsChanged: Bool, selectedLocationChanged: Bool) { private func handleLocationsChange(locationsChanged: Bool, selectedLocationChanged: Bool) {
if locationsChanged { if locationsChanged {
log.info("Locations list updated: \(locations.map { $0.description }.joined(separator: ", "))") log.info("Locations list updated: \(locations.map { $0.description }.joined(separator: ", "))")
...@@ -73,6 +77,16 @@ public class LocationManager { ...@@ -73,6 +77,16 @@ public class LocationManager {
guard let self = self else { return } guard let self = self else { return }
delegate.locationManager(self, changedSelectedLocation: newLocation) 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) 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