swup / ga-plugin

A swup plugin for integrating Google Analytics 📈
https://swup.js.org/plugins/google-analytics-plugin
MIT License
2 stars 2 forks source link

gtag.js #2

Closed josebedoya closed 4 years ago

josebedoya commented 5 years ago

Is it work with gtag.js? analytics.js is the old way to track your website

gmrchk commented 5 years ago

Hi, thanks for reporting!

I'm actually not sure. Here's the code plugin executes. Does gtag.js create global window.ga object as well?

bigskillet commented 4 years ago

I'd like to know if this works with gtag.js as well, but I'm not sure if it creates a window.ga object. Here's what the script looks like:

<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-XXXXX-Y');
</script>

It's using gtag rather than ga.

gmrchk commented 4 years ago

Then I guess this plugin won't work, but the code the plugin uses can easily be used for making the gtag work too. Here's some documentation on that.

We can also create another plugin for gtag (it would need to accept the GA_MEASUREMENT_ID in options), but I won't get to that. If you'd like to pitch in, feel free to create it and we can move it under swup org.