umami icon indicating copy to clipboard operation
umami copied to clipboard

GTM Integration

Open code-jorge opened this issue 5 years ago • 1 comments

After launching an instance in AWS with RDS and verifying everything is configured properly, I tried to add the umami tracker to a website using Google Tag Manager (GTM) to handle pixels and trackers.

It does not work smoothly!

After a few minutes of research I discovered that GTM strips custom data attributes from <script> tags, so the tag got loaded without the website id, making it useless.

A possible workaround for anybody facing this issue, is to put in GTM this, instead of the script generated by default :

<script>
  (function() {
    var el = document.createElement('script');
    el.setAttribute('src', '<umami-url>');
    el.setAttribute('data-website-id', '<website-id>');
    document.body.appendChild(el);
  })();
</script>

Could this maybe be added to the documentation for future use? (I'm pretty sure I got lucky with discovering a fix)

code-jorge avatar Jan 13 '21 19:01 code-jorge

Thanks for the tip. You free to write content for the website here, https://github.com/mikecao/umami.is

mikecao avatar Feb 03 '21 05:02 mikecao