Analytics events canceled

There is a serious problem connecting Google Analytics event tracking to a hyperlink on a page (as shown in the documentation).

Example:

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

When a user clicks on such a link in the Google Chrome browser, GA starts sending a request to the server (event tracking), but the browser also starts loading another page (via the link), and the GA request is “canceled”, so the event does not reach the server GA and not displayed in statistics.

How can we resist this?

For example, we can delay navigation to the linked page until the event reaches the GA server, but how can we do this if GA requests are asynchronous and we cannot find any callback functions in the documentation.

Is there a way to get notified when a pressed command is executed?

+4
source share
1 answer

Using analytics.js (part of the new universal analytics), you can specify the hitCallback function, which starts immediately after sending data. See Setting a Hit Callback

With ga.js (standard asynchronous analytics), you cannot know for sure that a gif tracking request was made (without re-writing the analytics code and sending the gif yourself). I had good results using a short delay (150 ms) before following the link.

+5
source

Source: https://habr.com/ru/post/1488657/


All Articles