Tag managers
Add Loogika to Google Tag Manager
You load Loogika in Google Tag Manager (GTM) with a Custom HTML tag that fires on All Pages. Nothing changes in the code of your site. A second tag can forward events that your site already pushes to the dataLayer.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in Loogika, under the Tracking Script tab. It looks like this, with your own 12-character site ID in place of YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
Use this form, with the site ID in the address. GTM rebuilds a Custom HTML tag before it places the tag on the page, and it can drop non-standard attributes. A site ID in a data attribute is therefore not reliable in GTM.
How do you add the Loogika tag in GTM?
- In your GTM container, go to Tags, then New.
- Pick Custom HTML under Tag Configuration, then paste the script tag into the tag.
- Under Triggering, choose All Pages. That is the built-in Page View trigger.
- Name the tag, for instance Loogika - Loader, then save it with Save.
- Click Submit to publish the new version of the container.
Preview mode in GTM shows whether the tag fires on page load. Run it before you publish.
How do you forward dataLayer events to Loogika?
One extra tag can send your existing dataLayer events to Loogika. It works for sites that already push events such as dataLayer.push({ event: "signup" }). Your other GTM tags can use window.loogika once you have published the loader tag.
- Create a Custom Event trigger and tick Use regex matching. As the event name, enter a pattern, for example
signup|purchase|add_to_cart. - Add a new Custom HTML tag, attach the trigger to it and paste the code below.
<script>
if (window.loogika) {
window.loogika.event("{{Event}}", {
page: "{{Page Path}}",
referrer: "{{Referrer}}"
});
}
</script>
Event, Page Path and Referrer are built-in GTM variables. For a custom field that you push, for example plan, add a Data Layer Variable. You then reference it in the code the same way.
Can you use the click and form triggers in GTM?
Yes. The same kind of tag works with the built-in Click and Form Submission triggers. This example sends an event with the text and the address of the clicked element:
<script>
if (window.loogika) {
window.loogika.event("cta_clicked", {
text: "{{Click Text}}",
url: "{{Click URL}}"
});
}
</script>
Turn on the built-in variables Click Text and Click URL first. Go to Variables, then Configure.
How do you check that Loogika is installed?
Load your live site in a fresh browser tab and visit a few pages. The pageviews show up in the Loogika dashboard within a few seconds.
If nothing arrives, open the Network tab of your browser and reload the page. A working install loads script.js with status 200 and then sends requests to /api/track. The script troubleshooting page covers ad blockers and other causes.
Why does a GTM tag not send data to Loogika?
| Problem | Cause and fix |
|---|---|
| An event tag fires and no event arrives | An event tag can run before the loader script, because that script is deferred and both fire during one page load. The if (window.loogika) check then skips the event. Fix the order as described below the table |
| The tag shows in Preview and not on the live site | Nobody published the version of the container. Click Submit to publish it |
You can fix the order of the tags in two ways. Open the event tag and go to Advanced Settings, then Tag Sequencing. There you make the loader tag fire ahead of the event tag. The other way is to swap the Page View trigger of the event tag for Window Loaded.