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.
Method 1: GTM Gallery template (recommended)
The fastest way. No code to write.
- Open tagmanager.google.com and select your container
- Go to Templates → Search Gallery
- Search "Loamly" → click Add to workspace
- Go to Tags → New
- Click Tag Configuration → select "Loamly Analytics"
- Enter your domain (e.g.
example.com) — no API key needed - Click Triggering → select All Pages
- Save → Submit → Publish
Template options
- 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.
- Open tagmanager.google.com and select your container
- Go to Tags → New
- Click Tag Configuration → select Custom HTML
- 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>- Replace
yourdomain.comwith your actual domain - Click Triggering → select All Pages
- Save → Submit → Publish
Important
<script> tag. GTM requires dynamically creating the script element inside a Custom HTML tag.Server-side GTM (sGTM)
When to use this
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
- Open your GTM Server Container
- Go to Templates → Search Gallery → search "Loamly"
- Go to Tags → New → select "Loamly Analytics (Server-Side)"
- Enter your Workspace ID and API Key
- Set trigger to page_view events
- Save → Publish
Option 2: Manual import (if template not in gallery)
- Open your GTM Server Container
- Go to Templates → New
- Click the three dots menu → Import
- Download the template from github.com/loamly/loamly/gtm-templates/server-side and import the
.tplfile - Save the template
- Go to Tags → New → select the imported Loamly template
- Enter your Workspace ID and API Key
- Set trigger to page_view events
- Save → Publish
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
- In GTM, click Preview to enter debug mode
- Visit your site in the preview tab
- Check that the Loamly tag shows "Tag Fired"
- 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.aito your Content Security Policyscript-srcdirective - Debug mode — open browser console and run
Loamly.debug(true)to see tracking events
Need help? Email hello@loamly.ai