Skip to content
  • There are no suggestions because the search field is empty.

Global Custom Data

Define global custom data that will be appended to all events tracked by the SDK.

 

Global custom data allows you to attach key-value pairs that are automatically included with every event during the current browser session.

Important Notes

  • Session-scoped: This data is only available for the current page session. It is not persistent across browser sessions or page reloads.
  • CRM Integration: To receive this data in your CRM or other integrations, you must configure the Custom Fields in your dashboard for your integration.

Common Use Cases

  • User identifiers (e.g., puidcustomerId)
  • Session information (e.g., sessionId)
  • Campaign tracking (e.g., campaignIdutm_source)
  • Device or context information (e.g., deviceTypeappVersion)

Array Format (Recommended)

_oirtrk.push(['set', key, value]);
 

Example:

<script type="text/javascript">
function getSessionId() {
return Math.random().toString(36).substr(2, 9);
}
</script>

<script type="text/javascript">
!(function (e) {
e._oirtrk = e._oirtrk || [];
e._oirtrk.push(['set', 'puid', '12345']); // Hard-coded value
e._oirtrk.push(['set', 'sessionId', getSessionId()]); // Dynamic value
e._oirtrk.push(['set', 'campaignId', 'summer_2024']); // Campaign tracking
e._oirtrk.push(['set', 'deviceType', 'mobile']); // Device information
})(window);
</script>
 

Object Format (Alternative)

Set multiple values at once using an object:

_oirtrk.push(['set', { key1: value1, key2: value2 }]);
 

Example:

_oirtrk.push([
'set',
{
sessionId: getSessionId(),
campaignId: 'summer_2024',
deviceType: 'mobile',
},
]);
 

Supported Data Types

The set command supports all JavaScript data types:

// String values
_oirtrk.push(['set', 'userId', 'user_12345']);

// Numeric values
_oirtrk.push(['set', 'orderValue', 99.99]);
_oirtrk.push(['set', 'quantity', 5]);

// Boolean values
_oirtrk.push(['set', 'isPremium', true]);
_oirtrk.push(['set', 'hasDiscount', false]);

// Object values
_oirtrk.push(['set', 'userData', { name: 'John', age: 30 }]);

// Null/undefined values
_oirtrk.push(['set', 'optionalField', null]);
_oirtrk.push(['set', 'anotherField', undefined]);
 

Common Use Cases

Campaign Tracking

// Extract UTM parameters from URL
const urlParams = new URLSearchParams(window.location.search);

_oirtrk.push([
'set',
{
utm_source: urlParams.get('utm_source'),
utm_medium: urlParams.get('utm_medium'),
utm_campaign: urlParams.get('utm_campaign'),
},
]);
 

User Context

// Set user context from your application
_oirtrk.push([
'set',
{
puid: user.id,
userType: user.subscription,
signupDate: user.createdAt,
},
]);
 

Session Information

// Generate and persist session data
_oirtrk.push([
'set',
{
sessionId: generateSessionId(),
landingPage: window.location.pathname,
referrer: document.referrer || 'direct',
},
]);
 

Next Steps

  1. User Identification Guide - Identify users with email
  2. Custom Events Guide - Track custom business events
  3. Configuration Guide - Configure SDK options