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

Selecting the tracking ID #9

Closed jesserosenfield closed 3 years ago

jesserosenfield commented 4 years ago
window.ga("set","title",n)

Was returning an undefined javascript error.

If you're initializing Google Analytics with google tag manager, this might work for you– it solved the problem for me:

var trackingID = window.ga.getAll()[0].get('name');
window.ga(trackingID + ".set","title",n);
gmrchk commented 3 years ago

Thanks for the tip. 👍 If anyone encounters GA problems, there is also Gtag plugin that should help. It probably depends mainly on how the GA is loaded in the first place, but it's good there are multiple options.