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.

2 min read

Each script has two settings. Getting them wrong is the most common reason a tag reports the wrong numbers.

Where: the Script Context

Script ContextRuns whenUse it for
ALLAlwaysMost analytics and tag manager loads
IFRAME_ONLYThe experience's address carries embedded=1Scripts that talk to a website page around the experience
NON_IFRAME_ONLYThe address has no embedded=1A 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 EventFires
VISITOn the normal page visit
REGISTRATIONAt 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:

Values commonly available to scripts
window.omnilab?.group?.uniqueKey
window.omnilab?.group?.configuration?.variables
window.omnilab?.contact?.externalId
window.omnilab?.contact?.email
window.location.pathname

Contact 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:

One page-view script for every organisation
<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>

See Organisation variables.

Next steps

On this page