matomo-org / matomo-sdk-android

SDK for Android to measure your apps with Matomo. Works on Android phones, tablets, Fire TV sticks, and more!
BSD 3-Clause "New" or "Revised" License
388 stars 162 forks source link

Update guide from v1.0.2 to v2.0 of the SDK #161

Closed PattaFeuFeu closed 7 years ago

PattaFeuFeu commented 7 years ago

Is there any resource that guides through the changes that occurred during the version upgrade from v1 to v2 of the SDK? Changes like “TrackHelper can now be found under sdk.extra instead of sdk”, “Instead of ‘setOptOut’, please use XY now”, and so on?

d4rken commented 7 years ago

Unfortunately not.

Could write one and we'll add it to the wiki?

PattaFeuFeu commented 7 years ago

At the moment, I don’t have the time to write an article on that matter. But I could write down a few lines underneath this ticket with findings I obtained along the way while updating from 1.0.2 to 2.0.

PattaFeuFeu commented 7 years ago

Update guide 1.0 --> 2.0

Gradle

Update from

compile 'org.piwik.sdk:piwik-sdk:1.0.2'

to

compile 'org.piwik.sdk:piwik-sdk:2.0.0'

Classes that moved

TrackHelper

TrackHelper moved from org.piwik.sdk to org.piwik.sdk.extra --- the new fully qualified name therefore becomes org.piwik.sdk.extra.TrackHelper

Methods that changed

Creation of a new tracker

Previously, you could add a new tracker by calling Piwik.newTracker(String piwikUrl, int siteId).

Now, you need to create a new TrackerConfig which you then supply to the method, like so:

Piwik.newTracker(new TrackerConfig("https://piwik.example.com", "4223", "DEFAULT_TRACKER"));

A createDefault(String piwikUrl, int siteId) method is available so that no tracker name has to be supplied. This shortens the previous call to:

Piwik.newTracker(TrackerConfig.createDefault("https://piwik.example.com", "4223"));

See: https://github.com/piwik/piwik-sdk-android/pull/157

CustomVariables

CustomVariables have been deprecated. See https://github.com/piwik/piwik-sdk-android/pull/148#issuecomment-277723478

Dry run (e.g. sandbox builds, debug mode)

Instead of setting a flag on the Piwik instance by calling Piwik.getInstance(this).setDryRun(true)to enable dry run, you now supply your own list data structure to which the tracking calls are saved instead of being sent.

For example, use: piwikTracker.setDryRunTarget(debugBuild ? new ArrayList<Packet>() : null);

See: https://github.com/piwik/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/Tracker.java#L542

Opt-out

The method for opting out moved from the Piwik class to the Tracker class.

Therefore, e.g. piwikTracker.getPiwik().setOptOut(true) becomes piwikTracker.setOptOut(true)

PattaFeuFeu commented 7 years ago

What happened to setDryRun(boolean)? I cannot seem to find it.

d4rken commented 7 years ago

The dev now sets their list datastructure that the packets during dryrun will be placed into.

https://github.com/piwik/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/Tracker.java#L542

https://github.com/piwik/piwik-sdk-android/blob/master/piwik-sdk/src/main/java/org/piwik/sdk/dispatcher/Dispatcher.java#L214

PattaFeuFeu commented 7 years ago

I updated my “wiki” comment with all changes I found when updating my codebase. Feel free to add additional pieces of information and also to add my findings to the wiki.

d4rken commented 7 years ago

Awesome!

https://github.com/piwik/piwik-sdk-android/wiki/Migration