visitorIDLifetime
The visitorIDLifetime property controls how long, in seconds, the current visitor ID remains valid. When it expires, the SDK generates a new random visitor ID and treats subsequent activity as a new visitor in reporting.
When a new visitor ID is assigned, the SDK clears visit-related tracking data, including visit-scoped custom variables, custom dimensions, campaign data waiting to be attached to the next event, and internal visit and activity counters. See Notes for details.
The default value is 0, which disables expiration.
The SDK checks whether the visitor ID has expired when it queues an analytics event, before the event is stored for upload.
Syntax
PiwikTracker.sharedInstance()?.visitorIDLifetime = seconds[PiwikTracker sharedInstance].visitorIDLifetime = seconds;Parameters
- visitorIDLifetime (number, required)
Lifetime in seconds. A value of0or less disables expiration. Default:0.
Examples
To set the visitor ID lifetime to 30 days:
PiwikTracker.sharedInstance()?.visitorIDLifetime = 30 * 24 * 60 * 60[PiwikTracker sharedInstance].visitorIDLifetime = 30 * 24 * 60 * 60;To disable visitor ID expiry:
PiwikTracker.sharedInstance()?.visitorIDLifetime = 0[PiwikTracker sharedInstance].visitorIDLifetime = 0;Notes
- When the visitor ID expires, the SDK assigns a new random visitor ID and clears visit-scoped custom variables. If
includeDefaultCustomVariableis enabled (the default), the SDK recreate its built-in visit variables when the next event is built. - The SDK also clears:
- Visit-scoped custom dimensions.
- Action-scoped custom dimensions waiting to be attached to the next request.
sendCampaign()parameters stored for the next event.- Internal visit and activity counters, including related timestamps and the session clock used for those metrics.
- Replacing the visitor ID also affects the session hash. After the visitor ID changes,
sessionHashforcessh=0for 31 minutes. This also applies when you manually change the visitor ID withsetVisitorID. - The visitor ID lifetime starts when the current visitor ID is assigned. That timer resets whenever the ID changes, for example after expiry or when you use
setVisitorID. The SDK reuses the same visitor ID across app launches until it's replaced. - When
isAnonymizationEnabledis enabled,the visitorIDvalue can change between app launches. SeevisitorID. The lifetime is calculated from the moment the visitor ID was assigned, and the same expiration rules apply.
Related methods
Updated 2 months ago
Did this page help you?