setCustomDimension
The setCustomDimension() method assigns a custom dimension by ID (the supported API). Set the value before the screen view or other tracking call that should carry it.
Syntax
PiwikTracker.sharedInstance()?.setCustomDimension(
identifier: identifier,
value: "value"
)[[PiwikTracker sharedInstance] setCustomDimensionForID:identifier value:@"value"];Parameters
- identifier
integer, required- Custom dimension ID from the Piwik PRO admin (must be 1 or greater;0is rejected by the SDK). - value
string, required- Dimension value. If longer than 1024 characters, the SDK truncates it.
Examples
To set a custom dimension with the ID 1 and the value 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, you need to create a session or event custom dimension in Piwik PRO (Menu > Analytics > Settings > Custom dimensions). You then use that dimension’s ID in this API.
- After adding dimensions to a request, the SDK clears them; re-apply them before every tracking call that needs them.
- The older
setCustomDimension(index:value:scope:)API is deprecated in favor of this method.
Related methods
- includeDefaultCustomVariable()
- setCustomVariable() (deprecated)
Updated 15 days ago