setCustomDimension
The setCustomDimension() method assigns a custom dimension by ID. This is the recommended API for setting custom dimensions. Set the value before the screen view or other tracking call that should include it.
Syntax
PiwikTracker.sharedInstance()?.setCustomDimension(
identifier: identifier,
value: "value"
)[[PiwikTracker sharedInstance] setCustomDimensionForID:identifier value:@"value"];Parameters
- identifier (integer, required)
The custom dimension ID configured in Piwik PRO. admin Must be greater than0. - value (string, required)
The Dimension value. If the value exceeds 1024 characters, the SDK truncates it.
Examples
To set a custom dimension 1 and to 5 stars and send it with a screen view:
PiwikTracker.sharedInstance()?.setCustomDimension(identifier: 1, value: "5 stars")
PiwikTracker.sharedInstance()?.sendView(view: "Welcome")[[PiwikTracker sharedInstance] setCustomDimensionForID:1 value:@"5 stars"];
[[PiwikTracker sharedInstance] sendView:@"Welcome"];To set a custom dimension with the ID 2 and the value paid subscriber and send it with an event:
PiwikTracker.sharedInstance()?.setCustomDimension(identifier: 2, value: "paid subscriber")
PiwikTracker.sharedInstance()?.sendEvent(
category: "Subscription",
action: "Renewed",
name: nil,
value: nil,
path: nil
)[[PiwikTracker sharedInstance] setCustomDimensionForID:2 value:@"paid subscriber"];
[[PiwikTracker sharedInstance] sendEventWithCategory:@"Subscription"
action:@"Renewed"
name:nil
value:nil
path:nil];Notes
- Before setting and sending a custom dimension value, create a session or event custom dimension in Piwik PRO under Analytics > Settings > Custom dimensions. Then use that dimension’s ID with this method.
- After adding custom dimensions to a request, the SDK clears them. Reapply them before each tracking call that should include them.
- The
setCustomDimension(index:value:scope:)API is deprecated. Use this method instead.
Related methods
- includeDefaultCustomVariable()
- setCustomVariable() (deprecated)
Updated 2 months ago
Did this page help you?