Cross-platform tracking

You can recognize the same visitor across an app and a website. This lets you identify the same visitor when they move from a WebView in the app to the website in their mobile browser.

You can also track when users move from a website to an app using deep links.

Tracking users who move from the mobile browser to the mobile application

The setVisitorIdFromDeepLink method sets a visitor ID from pk_vid parameter in a deep link:

boolean result = getTracker().setVisitorIdFromDeepLink("piwik://example?pk_vid=25a3c7d060a94360");

boolean result = getTracker().setVisitorIdFromDeepLink(Uri.parse("piwik://example?pk_vid=35a3c7d060a94360"));
val result = tracker.setVisitorIdFromDeepLink("piwik://example?pk_vid=25a3c7d060a94360")

val result = tracker.setVisitorIdFromDeepLink(Uri.parse("piwik://example?pk_vid=35a3c7d060a94360"))
  • deepLink (String or Uri) – The deep link that contains pk_vid parameter.

The method returns true if the visitor ID was set successfully. It returns false if the pk_vid parameter is missing, the value is invalid, or there is no value to set.

Tracking users who move from the mobile app to a WebView.

To improve visitor recognition, set the same user agent in the WebView as the one used by the Piwik PRO SDK.

The getUserAgent() method returns the default user agent parameter used in the Piwik PRO SDK.

String userAgent = getTracker().getUserAgent();
val userAgent = tracker.userAgent

Session hash

The sessionHash field controls the session hash feature by sending the sh parameter to the tracker.

You can set it with the setSessionHash(SessionHash sessionHash) method:

getTracker().setSessionHash(SessionHash sessionHash);
tracker.sessionHash = sessionHash
  • sessionHash (SessionHash, required) – The session hash option. Available values:
  • ENABLED – Sets the sh parameter to 1.
  • DISABLED – Sets the sh parameter to 0.
  • NOT_SET – Doesn’t set the sh parameter. The processing service uses the current value from the Privacy tab in global or app settings.

The Piwik PRO SDK persists the provided value and keeps it after the SDK is initialized again.

You can get sessionHash value using getSessionHash() method:

getTracker().getSessionHash();
tracker.sessionHash

Default value is set to DISABLED.