When a Personyze campaign renders on the page, it exposes its identity through global JavaScript variables. You can read these to forward campaign and action context to your analytics platform, debug which variation a user is seeing, or trigger custom logic when a specific campaign runs.
Available variables
| Variable | Description |
|---|---|
personyzeCampaign |
Name of the campaign |
personyzeAction |
Name of the action |
personyzeActiongroup |
Name of the action group |
personyzeCampaignId |
ID of the campaign |
personyzeActiongroupId |
ID of the action group |
personyzeActionId |
ID of the action |
When they become available
The variables are set after Personyze finishes evaluating audiences and rendering whichever action wins. Reading them on initial page load — before Personyze has resolved — returns undefined. Two reliable patterns:
Wait for the personyze ready hook
(window.personyze = window.personyze || []).push(['ready', function() {
console.log('Campaign:', window.personyzeCampaign);
console.log('Action:', window.personyzeAction);
console.log('Group:', window.personyzeActiongroup);
console.log('Campaign ID:', window.personyzeCampaignId);
console.log('Action ID:', window.personyzeActionId);
}]);
Or check after a short delay
setTimeout(function() {
if (window.personyzeCampaign) {
// campaign rendered
}
}, 500);
Common use cases
Forward to Google Analytics or GTM
(window.personyze = window.personyze || []).push(['ready', function() {
if (!window.personyzeCampaign) return;
// GA4 example
gtag('event', 'personyze_campaign_view', {
campaign_name: window.personyzeCampaign,
action_name: window.personyzeAction,
campaign_id: window.personyzeCampaignId,
});
}]);
Custom conversion attribution
// On purchase, record which Personyze campaign the user saw
function trackPurchase(orderId) {
myAnalytics.send('purchase', {
order_id: orderId,
personyze_campaign: window.personyzeCampaign || null,
personyze_action: window.personyzeAction || null,
});
}
Debugging
In the browser console on any page where a Personyze campaign should be running, type any of the variable names. Empty/undefined values mean the campaign didn’t match — check audience targeting in the wizard’s QA step.
ready callback to capture each campaign’s data as it fires rather than reading globals later.