Uncaught ReferenceError: ga is not defined

后端 未结 5 2014
野趣味
野趣味 2021-02-18 15:24

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\"

5条回答
  •  离开以前
    2021-02-18 16:10

    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

提交回复
热议问题