Skip to content

Migration

Cornelius Horstmann edited this page Jan 28, 2018 · 1 revision

Migrations

5.0

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.

Namechange

  • In the Podfile replace pod 'PiwikTracker' with pod 'MatomoTracker'
  • Replace all instances of import PiwikTracker with import MatomoTracker.
  • In your code replace all occurences PiwikTracker.shared?. with MatomoTracker.shared?.. (For example PiwikTracker.shared?.track(view: ["menu","profile"]) becomes MatomoTracker.shared?.track(view: ["menu","profile"]))

Removed shared instance

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")
    }
}
Clone this wiki locally