visitorID

The visitorID property is the read-only visitor identifier used for tracking. The SDK stores it between app launches for the same site unless anonymization or visitor ID lifetime settings replace it. To use your own identifier, call setVisitorID(newVisitorID:) with a 16-character lowercase hexadecimal string, for example, 0123456789abcdef.

Syntax

PiwikTracker.sharedInstance()?.setVisitorID(newVisitorID: "0123456789abcdef")
[[PiwikTracker sharedInstance] setVisitorID:@"0123456789abcdef"];

Parameters

  • newVisitorID (string, required)
    The visitor ID to set. Must containt exactly 16 characters, lowercase hexadecimal digits (0-9, a-f). If the format is invalid, the SDK leaves the stored visitor ID unchanged.

Examples

Use an if statement and the returned Bool to confirm whether the visitor ID was updated:

let ok = PiwikTracker.sharedInstance()?.setVisitorID(newVisitorID: "0123456789abcdef") == true
BOOL ok = [[PiwikTracker sharedInstance] setVisitorID:@"0123456789abcdef"];

Notes

  • When isAnonymizationEnabled is true, the SDK generates a new visitor ID the first time it needs one during an app run, and stores it. As a result, the value can change between app launches.
    When anonymization is false, the same ID is reused across launches unless you change it with setVisitorID or it expires according to visitorIDLifetime.
  • For signed-in users, consider user ID for cross-device tracking. The visitorID is device-specific unless you override it.

Related methods


Did this page help you?