sessionHash

Session Hash is a Piwik PRO feature that adds session-level context so the product can match activity more reliably across environments, for example when the same person uses your app and your website, or more than one device, and you have set up that kind of tracking. How it behaves in your data still depends on your Piwik PRO configuration, not on the SDK alone.

The sessionHash property tells the SDK how to flag each analytics event: ask for Session Hash on (.enabled), ask for it off (.disabled), or do not send a preference and let the Privacy settings for the tracked app in Piwik PRO decide (.notSet). Those choices are sent as the sh parameter on the request. The SDK remembers this value between app launches.

Syntax

PiwikTracker.sharedInstance()?.sessionHash = sessionHash
[PiwikTracker sharedInstance].sessionHash = sessionHash;

Parameters

  • sessionHash SessionHash, required. One of:

    • .enabled: sends sh=1.
    • .disabled: sends sh=0. This is the default when nothing has been stored yet.
    • .notSet: omits sh so the Piwik PRO app settings (Privacy) decide processing behavior.

Examples

To turn Session Hash on:

PiwikTracker.sharedInstance()?.sessionHash = .enabled
[PiwikTracker sharedInstance].sessionHash = Enabled;

To omit sh and follow server-side privacy defaults:

PiwikTracker.sharedInstance()?.sessionHash = .notSet
[PiwikTracker sharedInstance].sessionHash = NotSet;

To read the current value:

let currentValue = PiwikTracker.sharedInstance()?.sessionHash
SessionHash currentValue = [PiwikTracker sharedInstance].sessionHash;

Notes

If visitorIDLifetime is enabled (greater than zero), the SDK forces Session Hash off (sh=0) on every analytics event for 31 minutes after the current visitor ID was last set, including right after the ID is replaced because it expired. In that window sessionHash has no effect; the SDK always sends sh=0. After 31 minutes, sessionHash behaves as described in Parameters again.

For cross-environment tracking, use a matching user agent in WKWebView where relevant. See userAgent and Cross-platform tracking.

Related methods