Search code examples
javascriptgoogle-analyticsevent-tracking

Google Analytics Event Tracking doesn't track twice or more


I am trying to track an event via Google Analytics but unfortunately it only works for the first time I click the element. When I change the browser it only works the first time again. I use this simple code to track:

ga('send', 'event', 'footer', category , label, 1);

category and label are JS variables

Any ideas why this is not working?


Solution

  • It would help you if you install Chrome extension GA Debugger (https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en). Activate it and watch in the DevTools Console panel what happens when you click the target. It reports what was really sent to Google Analytics with the beacon. For example I have:

    ga( "send", "event", "Videos", "play", "Fall Campaign", 1 );
    

    which is called when user click the link. Every time I click the link I get in the console a new payload like:

    Running command: ga("send", "event", "Videos", "play", "Fall Campaign", 1)
    Sent beacon:
    v=1&_v=j79d&aip=1&a=1635498924&t=event..
    

    I keep also open https://analytics.google.com/analytics/web/ on Realtime/Events/Events (Last 30 min) and observer every time a new event registered.

    P.S. Just to avoid the case where some events not being really delivered to Google Analytics, let's say after code update, I have automated tests set like described here https://docs.puppetry.app/testing-techniques/testing-google-analytics-tracking-code