最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google Analytics Events Canceled - Stack Overflow

programmeradmin1浏览0评论

There is a serious issue with attaching Google Analytics event tracking to a hyperlink on a page (as demonstrated in the documentation).

Example:

<a
    href="/"
    onclick="_gaq.push(['_trackEvent', 'Links', 'Click', 'Example Link']);"
>
    Example!
</a>

When user clicks on such a link in the Google Chrome browser, GA is starting to send the request to the server (event tracking), but browser is also starting to load another page (following the link) and the GA request is getting "canceled", so the event is not reaching the GA server and is not shown in the statistics.

How can we counter it?

For example we can delay the navigation to a linked page while event is reaching the GA server, but how can we do this if GA requests are asynchronous and we can't find any callback functionality in the documentation.

Is there a way to get notified when pushed mand gets executed?

There is a serious issue with attaching Google Analytics event tracking to a hyperlink on a page (as demonstrated in the documentation).

Example:

<a
    href="http://www.example./"
    onclick="_gaq.push(['_trackEvent', 'Links', 'Click', 'Example Link']);"
>
    Example!
</a>

When user clicks on such a link in the Google Chrome browser, GA is starting to send the request to the server (event tracking), but browser is also starting to load another page (following the link) and the GA request is getting "canceled", so the event is not reaching the GA server and is not shown in the statistics.

How can we counter it?

For example we can delay the navigation to a linked page while event is reaching the GA server, but how can we do this if GA requests are asynchronous and we can't find any callback functionality in the documentation.

Is there a way to get notified when pushed mand gets executed?

Share Improve this question edited Jun 28, 2013 at 10:04 Slava Fomin II asked Jun 28, 2013 at 9:57 Slava Fomin IISlava Fomin II 28.7k35 gold badges134 silver badges208 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

With analytics.js (part of the new Universal Analytics), you can specify a hitCallback function that runs as soon as the data has been sent. See Setting the Hit Callback

With ga.js (standard Asynchronous Analytics), thee's no way to know for sure that the tracking gif request has been made (without re-writing the analytics code and sending the gif yourself). I've had good results using a short delay (150 ms) before following the link.

发布评论

评论列表(0)

  1. 暂无评论