Writing organisation scripts
Write and test Global organisation scripts that run in Pages without disrupting the participant experience.
This guide is the developer companion to the admin script configuration article. Use it when you are writing or reviewing the JavaScript that runs in OmniLab Pages.
Where the script runs
Organisation scripts run in the consumer-facing Pages runtime, not inside Studio. Before active scripts run, OmniLab initialises window.omnilab and can expose both group data and basic contact data to the page.
window.omnilab?.contact?.externalId
window.omnilab?.contact?.email
window.omnilab?.group
window.omnilab?.group?.configuration?.variables
window.omnilab?.group?.uniqueKey
window.location.pathnameContact values are available only when the participant is already known in that flow.
Your code must contain real script tags
OmniLab expects the script code field to contain one or more valid <script>...</script> blocks. Inline scripts and external script loaders are both supported.
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "omnilab_view",
organisation_key: window.omnilab?.group?.uniqueKey,
page: window.location.pathname,
});
</script><script async src="https://www.googletagmanager.com/gtm.js?id=GTM-AB12C3D"></script>Context and trigger behavior
| Setting | What it means |
|---|---|
ALL | Run in both iframe and non-iframe Pages |
IFRAME_ONLY | Run only when OmniLab is embedded |
NON_IFRAME_ONLY | Run only when Pages is standalone |
VISIT | Load during the normal page visit |
REGISTRATION | Hold the script for the registration stage |
If the current trigger is REGISTRATION, OmniLab still keeps the other active scripts available and adds the registration-targeted scripts for that stage. In practice, use a separate REGISTRATION script for conversion events instead of overloading the base page-view script.
Safe use cases
- Analytics loaders such as GTM, a pixel base tag, or a
dataLayerbootstrap - Per-organisation behaviour based on
window.omnilab.group.configuration.variables - Lightweight event pushes on visit or registration
- Minor DOM enhancements that do not depend on fragile selectors or block interaction
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "omnilab_view",
organisation_key: window.omnilab?.group?.uniqueKey,
country: window.omnilab?.group?.configuration?.variables?.country,
locale: window.omnilab?.group?.configuration?.variables?.locale || "en_US",
page: window.location.pathname,
surface: "Pages",
});
</script><script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "registration_complete",
external_id: window.omnilab?.contact?.externalId,
email: window.omnilab?.contact?.email,
organisation_key: window.omnilab?.group?.uniqueKey,
});
</script>What to avoid
- Replacing or overriding OmniLab business logic
- Blocking synchronous work that delays page load or prevents participation
- Fragile DOM rewrites that depend on unstable class names or layout details
- Collecting extra personal data without a clear legal basis and review
- Large client-side libraries that are not essential to the participant journey
A broken script can break every embedded experience
Because these scripts execute in Pages, one bad script can affect live campaigns. Keep them small, test them in staging, and give admins a rollback plan before production.
Local testing workflow
- Build and review the script in a staging environment.
- Test both iframe and non-iframe delivery if the script depends on the container.
- If the trigger is
REGISTRATION, complete a full registration flow and inspect the browser console and network panel. - After admins save the script, publish the affected campaign again before you validate the live experience.
Handoff to admins
When you hand a script to an admin, provide:
- the script name
- the intended context (
ALL,IFRAME_ONLY, orNON_IFRAME_ONLY) - the intended trigger (
VISITorREGISTRATION) - whether the script should start active or inactive
- a rollback instruction and a staging test result
Related
Scripts (custom JavaScript injection)
Follow the admin workflow for adding, enabling, and governing scripts.
Variables at organisation level
Use organisation variables to make one script adapt to several organisations.
Kiosk integration (technical deep-dive)
Handle iframe-aware scripts and wrapper-specific testing correctly.