Google Analytics Universal Event Tracking

后端 未结 2 1618
别那么骄傲
别那么骄傲 2021-02-11 08:38

We are using the new Google Analytics Universal code, but our event tracking code does not seam to be working. Any ideas on what is wrong? Thank you.



        
相关标签:
2条回答
  • 2021-02-11 09:12
    <a onclick="ga('send', 'event', 'link', 'click', 'label', {'hitCallback': function() {document.location = 'http://outbound.com'}});">Click Here</a>
    
    0 讨论(0)
  • 2021-02-11 09:13

    This is because the Google Analytics tracking code is asynchronous. The user leaves the page before Google Analytics Javascript code can ping the Analytics server.

    To fix this, you need to either open the outbound link in a new window, or set a hit callback, which will ensure the Analytics "hit" happens before the navigation.

    <a onclick="ga('send', 'event', 'button', 'click', 'label', { 'hitCallback': function() { document.location = 'http://outbound.com'; }}); return false;" href="http://outbound.com">Click Here</a>
    

    The example code would allow you to navigate the site with and without javascript, and search engines will see the link.

    0 讨论(0)
提交回复
热议问题