Google Analytics Async: Event Tracking?

I want to use event tracking to record clicks by type of a specific type on another website. I am using jQuery, and the code that I have now is:

$('a.website').click(function(event) { var href = $(this).attr('href'); try { _gaq.push(['_trackEvent', 'website', 'click', href]); } catch(err) {} }); 

However, when I see the referrer information from another site, I do not believe that it accurately tracks clicks, possibly because _gaq.push is asynchronous and the request was not received before the browser goes to the URL and terminates any javascript on the current page.

Is there any way to detect that the _gaq.push function completed successfully, so I can use event.preventDefault() and document.location to go to the link after the event was recorded?

+13
javascript jquery google-analytics event-tracking
Nov 16 '11 at 5:16
source share
3 answers

What about the solution from this answer ?

  // Log a pageview to GA for a conversion _gaq.push(['_trackPageview', url]); // Push the redirect to make sure it happens AFTER we track the pageview _gaq.push(function() { document.location = url; }); 
+9
Nov 16 '11 at 5:23
source share

Use Google Analytics hitCallback

You can configure a custom callback for the tracker object with:

 _gaq.push(['_set', 'hitCallback', function(){}]); 

I described the code for it in a little more detail: Track the event in Google Analytics after clicking the submit button

+12
Sep 17
source share

I ran into a similar issue with tracking external links. My escape used the OnMouseDown event instead of OnClick .

+1
Nov 17 2018-11-11T00:
source share



All Articles