Custom Dimensions
Add contextual data to your events with up to 10 custom dimensions per property.
Overview
Custom dimensions allow you to attach additional data to your analytics events. Each property supports 10 custom data slots (cd1-cd10) that can hold strings, numbers, or booleans.
Custom data belongs to the page it describes. Calling pushNavigation() clears the slots
along with the rest of the page context, so each page declares its own — see
Content Dimensions.
On the web, this only concerns single-page applications: a site that loads a real
document per page is unaffected. On iOS and tvOS it concerns every application,
because there is no document load to act as an implicit boundary — a screen that does not
call pushNavigation() inherits the slots of the one before it.
Looking for content hierarchy, article metadata or reader context? Those are named dimensions of their own — see Content Dimensions. On the web, setDimension('cd1', value) is an alias of setCustomData(1, value), so both kinds can be set through the same call.
Setting Custom Data
setCustomData()
// String value
alkeAnalytics.setCustomData(1, "category_tech");
// Number value
alkeAnalytics.setCustomData(2, 42);
// Boolean value
alkeAnalytics.setCustomData(3, true);
// Clear a dimension
alkeAnalytics.setCustomData(1, null);
| Parameter | Type | Description |
|---|---|---|
id | numberrequired | Dimension index (1-10) |
value | string|number|boolean|nullrequired | Value to store. Use `null` to clear. |
Returns true when the value was accepted, false otherwise.
setCustomData() and setLateCustomData() used to return false on rejection and
undefined on success. They now return a plain boolean, like setDimension() — of
which setDimension('cd1', value) is an alias. Code testing the result with
=== undefined or typeof result === 'undefined' must be updated.Late Values
Sometimes you don’t have all data available when the pageview starts. Use late values to update dimensions before the event is sent.
setLateCustomData()
For values resolved asynchronously:
// Promise-based late value
const userTypePromise = fetchUserType();
alkeAnalytics.setLateCustomData(1, userTypePromise);
// The value will be included when the pageview flushes
Returns true when the slot id is valid, false otherwise. The promise’s own outcome
is reported in the console — a value that resolves after the event was sent is simply
left out of it.
Consent-Wrapped Values
For GDPR compliance, wrap sensitive values so they’re only sent when consent is granted for the specified TCF purposes.
// Only sent if user consented to purpose 1 (store/access info)
alkeAnalytics.setCustomData(1,
alkeAnalytics.holdUntilConsent(email, null, [1])
);
// With fallback value
alkeAnalytics.setCustomData(2,
alkeAnalytics.holdUntilConsent(userId, "anonymous", [1, 9])
);
See Consent Management for more details on available purposes and behavior.