-
Notifications
You must be signed in to change notification settings - Fork 164
Migration
Cornelius Horstmann edited this page Jan 28, 2018
·
1 revision
Version 5.0 of the SDK changed the name from Piwik to Matomo and removed the shared instance. It now is possible to track to multiple Matomo instances.
- In the
Podfile
replacepod 'PiwikTracker'
withpod 'MatomoTracker'
- Replace all instances of
import PiwikTracker
withimport MatomoTracker
. - In your code replace all occurences
PiwikTracker.shared?.
withMatomoTracker.shared?.
. (For examplePiwikTracker.shared?.track(view: ["menu","profile"])
becomesMatomoTracker.shared?.track(view: ["menu","profile"])
)
Add an extension to MatomoTracker
that adds your already configured extension and migrate your the data from the old shared extension to the new shared extension. Make sure you only migrate the data once.
As an alternative to adding back the shared instance, create one and pass it along to the places where you want to track.
Remember to remove the old Matomo
configuration code (MatomoTracker.configureSharedInstance
).
import MatomoTracker
extension MatomoTracker {
static let shared: MatomoTracker = {
let matomoTracker = MatomoTracker(siteId: "23", baseURL: URL(string: "https://demo2.matomo.org/piwik.php")!)
matomoTracker.logger = DefaultLogger(minLevel: .info)
matomoTracker.migrateFromFourPointFourSharedInstance()
return matomoTracker
}()
private func migrateFromFourPointFourSharedInstance() {
guard !UserDefaults.standard.bool(forKey: "migratedFromFourPointFourSharedInstance") else { return }
copyFromOldSharedInstance()
UserDefaults.standard.set(true, forKey: "migratedFromFourPointFourSharedInstance")
}
}