Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Analytics Events Canceled

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.com/"
    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 command gets executed?

like image 713
Slava Fomin II Avatar asked Jun 28 '13 09:06

Slava Fomin II


People also ask

Why Google Analytics suddenly stopped working?

Another reason why your Google Analytics is not working is that it might be conflicting with another script on your webpage. If you have other scripts running on your website, make sure they don't use the same variables as Google Analytics.

How do I know if Google Analytics event tracking is working?

To see if Google Analytics is firing on your page, go to any page on your site in your Chrome Browser and right-click. Click on Inspect. Then go to the Network tab. Hit refresh on your browser and watch to see the different content and scripts loading on the page.

How long until events show up in Google Analytics?

You'll need to wait 24-48 hours after setting up your Google Analytics property to see your data. While you're waiting, you can verify your tracking code is doing its job by checking your real-time reports and debug view or looking at your website source code.

What is data deleted in Google Analytics?

You need the Editor role to use this feature. If you need to delete data from the Analytics servers for any reason, then you can use the Data Deletion Requests feature to issue a request for its removal. You can have a maximum of 250 active (pending) requests per property.


1 Answers

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.

like image 103
mike Avatar answered Oct 01 '22 22:10

mike