diff --git a/bwi/MatomoAnalytics/BWIAnalytics.swift b/bwi/MatomoAnalytics/BWIAnalytics.swift index e9d4d7f82..d2b944836 100644 --- a/bwi/MatomoAnalytics/BWIAnalytics.swift +++ b/bwi/MatomoAnalytics/BWIAnalytics.swift @@ -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()