Documentation

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

  1. Log in to your Google Tag Manager account
  2. Select your website container
  3. Click Tags in the left sidebar
  4. Click New to create a new tag
  5. Name your tag Loamly Tracking
  6. Click Tag Configuration and select Custom HTML
  7. 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>
  1. Replace yourdomain.com with your actual domain

Configure the trigger

  1. Click Triggering below the tag configuration
  2. Select All Pages trigger
  3. Click Save

Your tag configuration should look like this:

SettingValue
Tag TypeCustom HTML
TriggerAll Pages
Tag Firing PriorityDefault (leave blank)

Test in Preview mode

  1. Click Preview in the top right of GTM
  2. Enter your website URL and click Connect
  3. Your website will open in a new tab with GTM debug mode
  4. In the GTM debug panel, verify that Loamly Tracking shows as "Fired"
  5. Check your Loamly dashboard for the visit

Publish changes

Once you have verified the tag is working:

  1. Click Submit in GTM
  2. Add a version name like "Added Loamly tracking"
  3. 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.