I want know how many times people clicked on a particular button (should be very simple with Google analytics). However, I had an \"Uncaught ReferenceError: ga is not defined\"
This is a follow on from all the others who had an issue with the Monster Insights Wordpress plugin which renames ga
to __gaTracker
.
I didn't want to hardcode __gaTracker
in my JS (to send an event to GA) - in case someone later removed the MonsterInsights plugin and my script just stopped working.
Here is my code:
The first line creates a var called ga
which is either the original ga
object or the __gaTracker
object if ga
does not exist. Note: if ga
and __gaTracker
both don't exist you will end up with the same error ga is not defined