MESSENGER-4494 reset matomo instance after logout -> New ID generation

This commit is contained in:
Frank Rotermund
2023-05-02 18:13:11 +02:00
parent ce085fb8cc
commit 8d60b5b9d8
+36 -28
View File
@@ -37,7 +37,7 @@ import MatomoTracker
}
}
private let matomo: MatomoTracker?
private var matomo: MatomoTracker?
private let appName: String
private let appVersion: String
private let appPlattform = "iOS"
@@ -59,32 +59,9 @@ import MatomoTracker
analyticsConfig = AnalyticsConfiguration()
if BWIBuildSettings.shared.bwiMatomoEnabled {
if let path = Bundle.main.path(forResource: "trackingConfig", ofType: "json") {
analyticsConfig.readConfig(jsonFile: path)
}
// bwi: Analytics use custom config
guard let urlPath = analyticsConfig.selectedBaseURL(),
let url = URL(string: urlPath),
let siteID = analyticsConfig.selectedSiteID() else {
matomo = nil
return
}
matomo = MatomoTracker.init(siteId: siteID, baseURL:url, userAgent: nil)
matomo?.isOptedOut = false
matomo?.dispatchInterval = 5.0
matomo?.logger = DefaultLogger(minLevel: .verbose)
matomo?.setCustomVariable(withIndex: 1, name: "App Platform", value: appPlattform)
matomo?.setCustomVariable(withIndex: 2, name: "App Version", value: appVersion)
} else {
matomo = nil
}
super.init()
resetMatomo()
}
func setSession(session: MXSession) {
@@ -115,7 +92,9 @@ import MatomoTracker
userdefaults.removeObject(forKey: "PiwikVisitorUserIDKey")
userdefaults.removeObject(forKey: "PiwikOptOutKey")
userdefaults.removeObject(forKey: "PiwikLastOrderDateKey")
}
}
resetMatomo()
}
// Uses Userdefaults instead of Account Data because it needs to be shown on every login
@@ -131,6 +110,35 @@ import MatomoTracker
return BWIAnalyticsAccountDataService(mxSession: session).needsToShowPromt()
}
private func resetMatomo() {
if BWIBuildSettings.shared.bwiMatomoEnabled {
if let path = Bundle.main.path(forResource: "trackingConfig", ofType: "json") {
analyticsConfig.readConfig(jsonFile: path)
}
// bwi: Analytics use custom config
guard let urlPath = analyticsConfig.selectedBaseURL(),
let url = URL(string: urlPath),
let siteID = analyticsConfig.selectedSiteID() else {
matomo = nil
return
}
matomo = MatomoTracker.init(siteId: siteID, baseURL:url, userAgent: nil)
matomo?.isOptedOut = false
matomo?.dispatchInterval = 5.0
matomo?.logger = DefaultLogger(minLevel: .verbose)
matomo?.setCustomVariable(withIndex: 1, name: "App Platform", value: appPlattform)
matomo?.setCustomVariable(withIndex: 2, name: "App Version", value: appVersion)
} else {
matomo = nil
}
}
func dispatchAll() {
if fastRunning {
matomo?.dispatch()