Commit 1cb9d692 by Demid Merzlyakov

Analytics: add support for attributes.

parent 9b3dc978
......@@ -178,6 +178,7 @@
CE14445F2638B6CF008E2162 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE14445E2638B6CF008E2162 /* StoreKit.framework */; };
CE376C98261EE484000B1159 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE376C97261EE484000B1159 /* LaunchScreen.storyboard */; };
CE3C1DB6265536360031BD72 /* AppsFlyerAnalyticsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3C1DB5265536360031BD72 /* AppsFlyerAnalyticsService.swift */; };
CE46711F265FAD4300EAD03E /* AnalyticsAttribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE46711E265FAD4300EAD03E /* AnalyticsAttribute.swift */; };
CE578FE525FB415F00E8B85D /* CityCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE225FB415F00E8B85D /* CityCell.swift */; };
CE578FE625FB415F00E8B85D /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE325FB415F00E8B85D /* LocationViewController.swift */; };
CE578FE725FB415F00E8B85D /* LocationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */; };
......@@ -429,6 +430,7 @@
CE14445E2638B6CF008E2162 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
CE376C97261EE484000B1159 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
CE3C1DB5265536360031BD72 /* AppsFlyerAnalyticsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppsFlyerAnalyticsService.swift; sourceTree = "<group>"; };
CE46711E265FAD4300EAD03E /* AnalyticsAttribute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalyticsAttribute.swift; sourceTree = "<group>"; };
CE578FE225FB415F00E8B85D /* CityCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityCell.swift; sourceTree = "<group>"; };
CE578FE325FB415F00E8B85D /* LocationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationsViewModel.swift; sourceTree = "<group>"; };
......@@ -1224,6 +1226,7 @@
CEF959972600C88100975FAA /* AnalyticsParameter.swift */,
CEF959922600C63500975FAA /* AppAnalytics.swift */,
CEF959952600C84D00975FAA /* Services */,
CE46711E265FAD4300EAD03E /* AnalyticsAttribute.swift */,
);
path = Analytics;
sourceTree = "<group>";
......@@ -1549,6 +1552,7 @@
CD32CE08260C743B00235081 /* MenuViewModel.swift in Sources */,
CD866A76260F77C500E96A5C /* SettingsDetailsCoordinator.swift in Sources */,
CE0457902632B3BC00B3C19A /* NotificationsViewModel.swift in Sources */,
CE46711F265FAD4300EAD03E /* AnalyticsAttribute.swift in Sources */,
CE13B81A262480B3007CBD4D /* AdManager.swift in Sources */,
CE13B76326246743007CBD4D /* CCPAHelper.swift in Sources */,
CDE2BF222609D4250085C930 /* ForecastWindSpeedCell.swift in Sources */,
......
//
// AnalyticsAttribute.swift
// 1Weather
//
// Created by Demid Merzlyakov on 27.05.2021.
//
import Foundation
public enum AnalyticsAttribute {
/// Format: Country Code:State Code:City name. Example: US:NY:New York, US:CA:San Francisco
case lastSeenCity
case fipsList
case lastSeenFipsCodeNonTracfone
/// True/False; Wether the splash screen has been shown to the user for the first time or not.
case splashFTUE
/// Use this instead of rawValue, because we might have different attributes with the same string value.
var attributeName: String {
switch self {
case .lastSeenCity:
return "LAST_SEEN_CITY"
case .fipsList:
return "FIPS_LIST"
case .lastSeenFipsCodeNonTracfone:
return "LAST_SEEN_FIPS_CODE_NON_TRACFONE"
case .splashFTUE:
return "SPLASH_FTUE"
}
}
}
......@@ -10,3 +10,7 @@ import Foundation
public func analytics(log event: AnalyticsEvent, params: [AnalyticsParameter: Any]? = nil) {
AppAnalytics.shared.log(event: event, params: params)
}
public func analytics(set attribute: AnalyticsAttribute, to value: Any?) {
AppAnalytics.shared.set(attribute: attribute, to: value)
}
......@@ -41,4 +41,25 @@ public class AppAnalytics {
log.info("Event \(event.rawValue) sent to \(loggedToString)")
}
}
public func set(attribute: AnalyticsAttribute, to value: Any?) {
var servicesSetTo = [String]()
for service in services {
if let attributesWhitelist = service.attributesWhitelist {
if !attributesWhitelist.contains(attribute) {
continue
}
}
servicesSetTo.append(service.name)
service.set(attribute: attribute, to: value)
}
let servicesSetToString = servicesSetTo.joined(separator: ", ")
if let value = value {
log.info("Attribute \(attribute.attributeName) set to '\(value)' for \(servicesSetToString)")
}
else {
log.info("Attribute \(attribute.attributeName) set to nil for \(servicesSetToString)")
}
}
}
......@@ -10,7 +10,9 @@ import Foundation
public protocol AnalyticsService {
var name: String { get }
var eventsWhitelist: Set<AnalyticsEvent>? { get }
var attributesWhitelist: Set<AnalyticsAttribute>? { get }
func log(event: AnalyticsEvent, params: [AnalyticsParameter: Any]?)
func set(attribute: AnalyticsAttribute, to value: Any?)
}
extension AnalyticsService {
......
......@@ -11,8 +11,13 @@ import AppsFlyerLib
internal struct AppsFlyerAnalyticsService: AnalyticsService {
public let name: String = "AppsFlyer"
let eventsWhitelist: Set<AnalyticsEvent>? = [.ANALYTICS_APP_OPEN, .ANALYTICS_USER_QUALIFIED, .ANALYTICS_D3_RETAINED, .ANALYTICS_FIRST_OPEN]
let attributesWhitelist: Set<AnalyticsAttribute>? = [] // block all
func log(event: AnalyticsEvent, params: [AnalyticsParameter : Any]?) {
AppsFlyerLib.shared().logEvent(event.rawValue, withValues: stringKeyedParams(from: params))
}
func set(attribute: AnalyticsAttribute, to value: Any?) {
// do nothing
}
}
......@@ -11,8 +11,13 @@ import Flurry_iOS_SDK
internal struct FlurryAnalyticsService: AnalyticsService {
public let name = "Flurry"
let eventsWhitelist: Set<AnalyticsEvent>? = nil
let attributesWhitelist: Set<AnalyticsAttribute>? = [] // block all
func log(event: AnalyticsEvent, params: [AnalyticsParameter : Any]?) {
Flurry.logEvent(event.rawValue, withParameters: stringKeyedParams(from: params))
}
func set(attribute: AnalyticsAttribute, to value: Any?) {
// do nothing
}
}
......@@ -11,6 +11,7 @@ import MoEngage
internal struct MoEngageAnalyticsService: AnalyticsService {
public let name = "MoEngage"
let eventsWhitelist: Set<AnalyticsEvent>? = nil
let attributesWhitelist: Set<AnalyticsAttribute>? = nil // allow all
func log(event: AnalyticsEvent, params: [AnalyticsParameter : Any]?) {
let stringKeyedParams = stringKeyedParams(from: params)
......@@ -25,4 +26,8 @@ internal struct MoEngageAnalyticsService: AnalyticsService {
MoEngage.sharedInstance().trackEvent(event.rawValue, with: nil)
}
}
func set(attribute: AnalyticsAttribute, to value: Any?) {
MoEngage.sharedInstance().setUserAttribute(value, forKey: attribute.attributeName)
}
}
......@@ -91,7 +91,8 @@ public class LocationManager {
.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")
analytics(set: .lastSeenCity, to: newLocation?.cityId)
lastSeenCityId = newLocation?.cityId
}
}
......
......@@ -55,25 +55,24 @@ public class PushNotificationsManager: NSObject {
internal var lastSetFIPSCode: String? = ""
private func updateNwsSubscriptions(with fipsList: String?, currentFipsCode: String?) {
let lastFipsCodeAttributeName = "LAST_SEEN_FIPS_CODE_NON_TRACFONE"
if configManager.config.nwsAlertsViaMoEngageEnabled {
if fipsList != lastSetFIPSList {
log.info("Set FIPS_LIST to '\(fipsList ?? "")'")
log.info("Set \(AnalyticsAttribute.fipsList.attributeName) to '\(fipsList ?? "")'")
lastSetFIPSList = fipsList
}
if currentFipsCode != lastSetFIPSCode {
log.info("Set \(lastFipsCodeAttributeName) to '\(currentFipsCode ?? "")'")
log.info("Set \(AnalyticsAttribute.lastSeenFipsCodeNonTracfone.attributeName) to '\(currentFipsCode ?? "")'")
lastSetFIPSCode = currentFipsCode
}
}
else {
log.info("Set FIPS_LIST to nil, because nwsAlertsViaMoEngage are disabled via config.")
log.info("Set \(AnalyticsAttribute.fipsList.attributeName) to nil, because nwsAlertsViaMoEngage are disabled via config.")
lastSetFIPSList = nil
log.info("Set \(lastFipsCodeAttributeName) to nil, because nwsAlertsViaMoEngage are disabled via config")
log.info("Set \(AnalyticsAttribute.lastSeenFipsCodeNonTracfone.attributeName) to nil, because nwsAlertsViaMoEngage are disabled via config")
lastSetFIPSCode = nil
}
MoEngage.sharedInstance().setUserAttribute(lastSetFIPSList, forKey: "FIPS_LIST")
MoEngage.sharedInstance().setUserAttribute(lastSetFIPSCode, forKey: lastFipsCodeAttributeName)
analytics(set: .fipsList, to: lastSetFIPSList)
analytics(set: .lastSeenFipsCodeNonTracfone, to: lastSetFIPSCode)
}
public func updateNwsSubscriptions(for locations: [Location], selectedLocation: Location?) {
......
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