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.
- 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.
- User identifiers (e.g.,
puid,customerId) - Session information (e.g.,
sessionId) - Campaign tracking (e.g.,
campaignId,utm_source) - Device or context information (e.g.,
deviceType,appVersion)
_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>
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',
},
]);
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]);
// 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'),
},
]);
// Set user context from your application
_oirtrk.push([
'set',
{
puid: user.id,
userType: user.subscription,
signupDate: user.createdAt,
},
]);
// Generate and persist session data
_oirtrk.push([
'set',
{
sessionId: generateSessionId(),
landingPage: window.location.pathname,
referrer: document.referrer || 'direct',
},
]);
- User Identification Guide - Identify users with email
- Custom Events Guide - Track custom business events
- Configuration Guide - Configure SDK options