← All examples

JavaScript Developer & QA

Highlight that GTM is present

Checks for the gtm.js script or a dataLayer array and shows a green badge when the page uses Tag Manager.

Code to copy

try {
  var hasScript = !!document.querySelector('script[src*="googletagmanager.com/gtm.js"]');
  var hasDL = Array.isArray(window.dataLayer);
  if (hasScript || hasDL) {
    var b = document.createElement('div');
    b.textContent = 'GTM detected' + (hasScript ? ' (gtm.js)' : ' (dataLayer)');
    b.style.cssText = 'position:fixed;top:8px;right:8px;z-index:2147483647;'
      + 'background:#34A853;color:#fff;font:700 12px sans-serif;'
      + 'padding:4px 10px;border-radius:6px;pointer-events:none;';
    document.body.appendChild(b);
  } else {
    console.log('No Google Tag Manager detected on this page.');
  }
} catch (e) {
  console.warn('GTM detection failed:', e);
}

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Paste the code into the rule's JavaScript panel and save — it runs on every page visit.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases