Where and when a script runs
Choose the context and trigger for a script, and see which values it can read about the current organisation and participant.
Each script has two settings. Getting them wrong is the most common reason a tag reports the wrong numbers.
Where: the Script Context
| Script Context | Runs when | Use it for |
|---|---|---|
ALL | Always | Most analytics and tag manager loads |
IFRAME_ONLY | The experience's address carries embedded=1 | Scripts that talk to a website page around the experience |
NON_IFRAME_ONLY | The address has no embedded=1 | A cookie banner you only need then, or a tag your own page already fires when it embeds the experience |
Only website embeds carry embedded=1: the JavaScript tag adds it, and you add embedded=1 yourself to a hand-written website frame. Apps and kiosks leave it out, so their scripts use ALL, as the kiosk idle signal does. See Embed URLs and parameters.
When an experience runs inside your website, your page's own analytics is usually counting the visit already. The same tag inside the frame counts it again.
When: the Trigger Event
| Trigger Event | Fires |
|---|---|
VISIT | On the normal page visit |
REGISTRATION | At the registration stage |
Put conversion events in a separate REGISTRATION script, rather than adding conditions to the page-view script. It's easier to follow, and easier to switch off if the conversion tag misfires. At registration, your other active scripts stay loaded too.
What a script can read
Before your scripts run, the page makes these values available:
window.omnilab?.group?.uniqueKey
window.omnilab?.group?.configuration?.variables
window.omnilab?.contact?.externalId
window.omnilab?.contact?.email
window.location.pathnameContact values only exist once the participant is known at that point in the flow. On a VISIT script for an anonymous visitor they're empty, which is expected.
Only two values are guaranteed
window.omnilab.group.uniqueKey and window.location.pathname exist for every organisation. Everything under configuration.variables is a free-form store an admin created, and no keys are set up for you. Check which exist before you use one, and always give a fallback for a key that might be missing.
Turn scripts off for one campaign
Global's scripts run on every campaign, in every organisation. To keep them off one campaign, follow Change the wording, open the Global group, and set global.scripts.ignore to true. Then publish the campaign again. To keep only some scripts off, limit them to one organisation or to selected campaigns instead.
Make one script serve several organisations
If you run several organisations, such as regions, brands or centres, read organisation variables so one script adapts. It saves keeping several near-identical copies:
<script>
var vars = window.omnilab?.group?.configuration?.variables || {};
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'view_page',
organisation_key: window.omnilab?.group?.uniqueKey,
country: vars.country,
locale: vars.locale || 'en_GB',
});
</script>