Google Tag Manager

Installing the Attribution snippet through Google Tag Manager, and why a direct install is better

Google Tag Manager

Google Tag Manager (GTM) is a tool for injecting scripts onto a website based on rules you set in the GTM app.

It is possible to install Attribution inside GTM. We do not recommend it, for these reasons:

  • Tag managers were designed to ship ad pixels, not analytics. They load scripts on their own schedule, after the page and after each other.
  • Delays the moment the first page view is sent, so short visits are lost.
  • Does not guarantee a tag fires, so some visits never reach Attribution.
  • Hard to debug: we cannot see inside your container when something stops tracking.
  • Form submissions and chained events are awkward to wire up.
  • More exposed to ad blockers and slow networks than a script in your page.

Every stack is different and Attribution does work inside GTM, but then GTM decides how and when our script runs, and the implementation is yours to own. In our experience, running Attribution inside GTM reduces tracking accuracy by 5 to 10% on average compared to the standalone installation.

Customer data platforms are the better alternative: a developer interface built for product data, with Attribution as a destination. See Bring your own data for Segment, RudderStack, Heap and Amplitude.

Installing the Attribution snippet with GTM

Create a Custom HTML tag, paste the snippet from Settings → Setup Instructions, and trigger it on All Pages.

📘

Tag firing priority

This tag has to fire before any other Attribution tag. Give it a Tag firing priority greater than 0 in the tag's Advanced Settings; tags with higher numbers fire first.

🚧

Robot and test proofing

GTM's scanner loads your container from gtm-msr.appspot.com and fires your tags, so you get fake visits. Wrap every Attribution tag in this check:

<script type="text/javascript">
  if (document.location.href.search('gtm-msr.appspot') == -1) {
    /* Attribution code here */
  }
</script>

Firing identify() and track() from tags

You will need further tags and triggers to call identify() and track() on events. Identifying can be the hard part: it needs a user id from your backend or an email captured from a form.

❗️

Tags must run after the snippet

Tags that call identify() or track() must run after the snippet tag has loaded. Use Tag Sequencing in the tag's Advanced Settings to fire the snippet tag first. If conversions land in Unknown Source on your dashboard, that is the sign a tag fired before the snippet, or on a page the snippet tag does not cover.

Once the tags are in place, test your install to confirm page views and events arrive.