Script examples
Working code for tag managers, ad pixels, cookie banners, conversion events and scripts limited to one organisation or to some campaigns.
For whoever writes the script. Copy one, change the identifiers, and hand it to the admin who adds it. Scripts run in your campaign pages, not in Studio. For the values a script can read and its two settings, see Where and when a script runs.
Your code must contain real script tags
The Script Code field expects one or more valid <script>...</script> blocks: the code starts with <script and ends with </script>, or holds a <noscript> block too. Inline scripts and external script loaders both work. Remove the HTML comment lines a tool's own snippet often has, such as <!-- Google Tag Manager -->: they fail the check.
<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.lindenhall.example/js/analytics.js"></script>For the patterns that work and the ones that break campaigns, see Common patterns and what to avoid.
Hand it to your admin
Give the admin:
- the script name;
- the Script Context:
ALL,IFRAME_ONLYorNON_IFRAME_ONLY; - the Trigger Event:
VISITorREGISTRATION; - whether it should start active or inactive;
- a rollback instruction, and the result of your test: see Test it.
Complete example scripts
Google Tag Manager base loader
Use this when your team wants GTM available before firing more events.
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
'gtm.start': new Date().getTime(),
event: 'gtm.js',
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-LH12345');
</script>Page-view event with organisation variables
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'view_page',
country: window.omnilab?.group?.configuration?.variables?.country,
region: window.omnilab?.group?.configuration?.variables?.region,
language:
window.omnilab?.group?.configuration?.variables?.language || 'English',
locale:
window.omnilab?.group?.configuration?.variables?.locale || 'en_US',
page: window.location.pathname,
page_type: 'Experience',
organisation_key: window.omnilab?.group?.uniqueKey?.toUpperCase(),
surface: 'campaign pages',
});
</script>country, region, language and locale are organisation variables Lindenhall created, not built-in fields: see What a script can read.
Registration event with dataLayer.push
Use this to send a conversion-style event after registration.
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: 'registration_complete',
organisation_key: window.omnilab?.group?.uniqueKey?.toUpperCase(),
country: window.omnilab?.group?.configuration?.variables?.country,
locale:
window.omnilab?.group?.configuration?.variables?.locale || 'en_US',
page: window.location.pathname,
registration_status: 'complete',
});
</script>At registration, window.omnilab?.contact?.externalId and window.omnilab?.contact?.email are available too, if your measurement design needs them.
Meta Pixel registration trigger
Use this when the base Meta Pixel is already on the page, and you only need to fire an event from your campaign pages.
<script>
if (typeof window.fbq === 'function') {
window.fbq('track', 'CompleteRegistration', {
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,
});
}
</script>One organisation only
Every organisation's campaigns load Global's scripts. Use this pattern for a pixel or tag that belongs to one centre only.
<script>
(function () {
if (window.omnilab?.group?.uniqueKey !== 'lindenhall') return;
// Lindenhall's own tag goes here.
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'lindenhall_view', page: window.location.pathname });
})();
</script>uniqueKey is the organisation's Group Unique Key, here lindenhall. On any other organisation's campaigns, the script stops at its first line.
A script for selected campaigns only
Use this pattern when a script must run on some campaigns but not others. Each entry is a campaign's path: the part of its link after the domain, such as /lindenhall-autumn-kiosk.
<script>
(function () {
var CAMPAIGNS = ['/lindenhall-autumn-kiosk', '/lindenhall-christmas-kiosk'];
var path = window.location.pathname;
var listed = CAMPAIGNS.some(function (c) {
return path === c || path.indexOf(c + '/') === 0;
});
if (!listed) return;
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({ event: 'kiosk_view', page: path });
})();
</script>A path matches exactly, or as the start of a longer path, so /lindenhall-autumn alone matches nothing. It works on your default address and your custom domain alike. Give the admin the list along with the code: it grows every time a matching campaign launches.
Advertising pixels
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '<YOUR-PIXEL-ID>');
fbq('track', 'PageView');
</script>Google Ads and TikTok follow the same shape: paste the base tag the platform gives you, on the VISIT trigger. Fire conversions from a REGISTRATION script: see When: the Trigger Event.
Cookie banner
Load your own consent tool as you do on your website, on the VISIT trigger:
<script src="https://cdn.consent-tool.example/loader.js" data-site-id="<YOUR-SITE-ID>"></script>Then make your other scripts wait for its answer rather than firing regardless. Most consent tools expose a callback or a global you can check: follow that tool's documentation.
Test what happens when someone refuses
The accept path almost always works. The refuse path is where tags fire anyway, and it's the one that carries regulatory risk. Refuse consent and check your pixels stay silent.