Google Tag Manager
Deploy Loamly via GTM
Google Tag Manager (GTM) lets you manage tracking scripts without modifying your website code. This guide shows you how to deploy Loamly through GTM.
Direct installation recommended
While GTM works, we recommend direct installation for better performance. GTM adds an extra network request and slight delay to script loading.
Create the Loamly tag
- Log in to your Google Tag Manager account
- Select your website container
- Click Tags in the left sidebar
- Click New to create a new tag
- Name your tag Loamly Tracking
- Click Tag Configuration and select Custom HTML
- Paste the following code:
<script>
(function() {
var script = document.createElement('script');
script.src = 'https://app.loamly.ai/t.js?d=yourdomain.com';
script.defer = true;
document.head.appendChild(script);
})();
</script>- Replace
yourdomain.comwith your actual domain
Configure the trigger
- Click Triggering below the tag configuration
- Select All Pages trigger
- Click Save
Your tag configuration should look like this:
| Setting | Value |
|---|---|
| Tag Type | Custom HTML |
| Trigger | All Pages |
| Tag Firing Priority | Default (leave blank) |
Test in Preview mode
- Click Preview in the top right of GTM
- Enter your website URL and click Connect
- Your website will open in a new tab with GTM debug mode
- In the GTM debug panel, verify that Loamly Tracking shows as "Fired"
- Check your Loamly dashboard for the visit
Publish changes
Once you have verified the tag is working:
- Click Submit in GTM
- Add a version name like "Added Loamly tracking"
- Click Publish
Custom events via GTM
You can send custom events to Loamly based on GTM triggers. Create a new Custom HTML tag:
<script>
if (window.loamly) {
window.loamly.event('{{Event Name}}', {
category: '{{Event Category}}',
label: '{{Event Label}}'
});
}
</script>Use GTM variables (shown in double curly braces) to pass dynamic values. Set the trigger to fire on specific events like form submissions, button clicks, or scroll depth.
Tag sequencing
If you are firing custom event tags, make sure they have tag sequencing enabled to fire after the main Loamly Tracking tag. Otherwise, the
window.loamly object may not be available yet.