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; 100 keeps all. Default: 100. The fraction is approximate (discrete random draw in the SDK).

Examples

To keep roughly 10% of Analytics events (see Parameters for why it is not exact):

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

Notes

  • Many send… and track… calls return true even when sampling dropped the event; they report no problem, not queued for sending. See optOut for the same idea.
  • If sampling drops an event, the SDK does not store it.

Related methods