Google Analytics 4 Tracking tag

This page states that Piwik is working on a GA4 version of the Google Analytics Tracking tag.

Is there currently another way to add the GA4 tag to a site via Piwik Tagmanager?

Hi. Sure, you can add the GA4 snippet (Google tag) via custom code tag. It should be available under Admin → Data streams → Web → Your site → View tag instructions. :slight_smile:

That’s easier than expected :slight_smile: Going to try it out, thanks!

Hello @kuba, this snippet corresponds to the gtag.js:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-X"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-X');
</script>

Google says it has to be implemented right after the <head> element. Therefore, I might be wrong but, using a Piwik PRO custom code tag to push it might cause GA4 to not work correctly. Because the gtag.js will be pushed in the <body> section rather than the <head>.

Thank you in advance!

Technically there should be practically no difference. They simply want to load it as soon as possible and I get it. Our tag manager also works when installed within <head>, but it’s not recommended by us as we fully test just the installation in <body>.