Documentation

Google Tag Manager

Add Loamly to your site using Google Tag Manager

Two options for client-side installation: the GTM Gallery template (recommended) or a custom HTML tag. If you already run a server-side GTM container, you can also install Loamly server-side for full HTTP header access.

The fastest way. No code to write.

  1. Open tagmanager.google.com and select your container
  2. Go to TemplatesSearch Gallery
  3. Search "Loamly" → click Add to workspace
  4. Go to TagsNew
  5. Click Tag Configuration → select "Loamly Analytics"
  6. Enter your domain (e.g. example.com) — no API key needed
  7. Click Triggering → select All Pages
  8. SaveSubmitPublish

Template options

The GTM template supports two optional settings:
  • Debug mode: Logs tracking events to the browser console
  • Disable auto pageview: For SPAs where you want manual control over page tracking

Method 2: Custom HTML tag

Use this if the Gallery template is not available in your region yet.

  1. Open tagmanager.google.com and select your container
  2. Go to TagsNew
  3. Click Tag Configuration → select Custom HTML
  4. Paste this code:
<script>
(function() {
  var s = document.createElement('script');
  s.src = 'https://app.loamly.ai/t.js?d=yourdomain.com';
  s.defer = true;
  document.head.appendChild(s);
})();
</script>
  1. Replace yourdomain.com with your actual domain
  2. Click Triggering → select All Pages
  3. SaveSubmitPublish

Important

Use the JavaScript snippet above, not the regular <script> tag. GTM requires dynamically creating the script element inside a Custom HTML tag.

Server-side GTM (sGTM)

When to use this

If you already have a GTM Server Container running (Stape, Cloud Run, etc.). Server-side GTM gives you the same capabilities as the DNS/Cloudflare setup: AI bot crawl detection, RFC 9421 signature verification, bot-to-click temporal matching, and prompt-to-crawl correlation. It's a full alternative to the DNS A record method.

Prerequisites:

  • GTM Server Container running and receiving events
  • A GA4 Client configured in your server container
  • Your Loamly Workspace ID and API Key (from Settings → API)

Option 1: From the GTM Gallery

  1. Open your GTM Server Container
  2. Go to TemplatesSearch Gallery → search "Loamly"
  3. Go to TagsNew → select "Loamly Analytics (Server-Side)"
  4. Enter your Workspace ID and API Key
  5. Set trigger to page_view events
  6. SavePublish

Option 2: Manual import (if template not in gallery)

  1. Open your GTM Server Container
  2. Go to TemplatesNew
  3. Click the three dots menuImport
  4. Download the template from github.com/loamly/loamly/gtm-templates/server-side and import the .tpl file
  5. Save the template
  6. Go to TagsNew → select the imported Loamly template
  7. Enter your Workspace ID and API Key
  8. Set trigger to page_view events
  9. SavePublish

The server-side tag intercepts every request to your site, detects AI bot crawls (ChatGPT-User, ClaudeBot, PerplexityBot, GPTBot), verifies their RFC 9421 signatures, and sends the data to Loamly. This enables:

  • 100% accurate AI bot identification
  • Bot crawl → human click temporal matching (within 5 minutes)
  • Prompt-to-crawl correlation with Intelligence queries
  • Full crawl analytics in the Crawls page

Enable AI verification (recommended)

The client-side GTM tag tracks page views. If you're not using server-side GTM (above), you can still get full AI bot detection via DNS setup. This enables bot crawl detection, signature verification, bot-to-click matching, and prompt-to-crawl correlation.

See the AI Visitor Verification guide for setup instructions.

Verify installation

  1. In GTM, click Preview to enter debug mode
  2. Visit your site in the preview tab
  3. Check that the Loamly tag shows "Tag Fired"
  4. Open app.loamly.ai → your workspace dashboard should show the visit within 1-2 minutes

Single-page apps (SPAs)

Loamly auto-detects route changes in React, Vue, Angular, and other SPA frameworks. No extra configuration needed.

If you need manual control (e.g. custom transitions), enable "Disable Auto Pageview" in the template settings and trigger pageviews manually:

// Trigger a pageview manually
if (window.Loamly) Loamly.pageview();

Troubleshooting

  • Tag not firing — check that the All Pages trigger is attached and the tag is not paused
  • No data in dashboard — wait 2 minutes, then verify your domain matches the workspace domain in Loamly settings
  • CSP errors — add app.loamly.ai to your Content Security Policy script-src directive
  • Debug mode — open browser console and run Loamly.debug(true) to see tracking events

Need help? Email hello@loamly.ai