sampleRate

The sampleRate property controls client-side sampling for analytics events. Before an event is stored, the SDK may skip it so that only part of the traffic is sent. The default is 100, meaning no sampling.

Syntax

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

Parameters

  • sampleRate (integer, required)
    A whole number from 1 to 100 (inclusive). Roughly sampleRate / 100 of analytics events are kept. A value of 100 keeps all events. Default: 100. The fraction is approximate because the SDK uses a discrete random draw.

Examples

To keep roughly 10% of analytics events, see Parameters for details about how the percentage is calculated:

PiwikTracker.sharedInstance()?.sampleRate = 10
[PiwikTracker sharedInstance].sampleRate = 10;

Notes

  • Many send... and track... methods return true even when sampling drops the event. The return value indicates that no error occurred, not that the event was queued for sending. For a similar behavior, see optOut.
  • If sampling drops an event, the SDK doesn't store it.

Related methods


Did this page help you?