
27 Jan Event tracking not working with Monster Insights Google Analytics plugin?
What is the difference between the __gaTracker and ga Analytics trackers?
Basically, the difference is pretty obvious:
Original Analytics tracking code
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXX-X', 'auto'); ga('require', 'displayfeatures'); ga('send', 'pageview'); </script>
Looks pretty standard. Now let’s look at the tracking code used by the Monsterinsights plugin:
Modified Analytics tracking code
<script type="text/javascript"> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); __gaTracker('create', 'UA-XXXXXXXX-X', 'auto'); __gaTracker('require', 'displayfeatures'); __gaTracker('send','pageview'); </script>
Now, see that little difference in front of the Analytics code? Definitely something different, but it still works. In a bit we will explain why this has a fundamental impact on your event tracking, but first, let’s dive into what __gaTracker is and why the Monsterinsights plugin uses this format.
Why does the plugin use __gaTracker?
As Google states on their advanced Analytics page of renaming the ga object:
In some cases you’d like to add analytics.js to your page, but the ga variable is already being used for something else. To deal with this, analytics.js provides a mechanism for renaming the global ga object.
So, that means that the Monsterinsights plugin is probably using gaTracker just to be safe and to avoid conflicts with any other elements using the ga.
No Comments