Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track events before page redirect with google analytics?

I use GA's trackEvent to record user's click event on search autocomplete of my site. When user click on item of autocomplete, I record two event, and then page redirect to the result page. But the problem is: the amount of the two action "click" and "view" is not equal, the amount of "click" > the amount of "view". I see the two request are sent in firebug, but they are both canceled because the page redirect. Even though they are canceled, I can see the result in GA.I just can't understand why they are not equal? The later one failed sometimes?

Here is the code part:

//trackEvent just use _gaq.push("trackEvent", xxx)
trackEvent("search", "click");
trackEvent("search", "view");
window.location.href = des;
like image 802
user1610957 Avatar asked Aug 20 '12 06:08

user1610957


People also ask

Can Google Analytics track redirects?

We have found that most of the time, when someone clicks a link that redirects from one website to another, that visit will show in Google Analytics as being just another (direct / none) visitor in Google Analytics 🙁 While the redirects sometimes have the referring domain attributed to it, most of the time they don't.

How do I track 301 redirects in Google Analytics?

Login to Google Analytics, and go to Acquisition > All Traffic > Channels then click on 'Source/Medium' as your primary dimension, then apply an in-line filter for '301'. Choosing 'Landing Page' as your secondary dimension will provide you with a list of all the 301 redirects that are sending traffic to your site.


1 Answers

Here's the answer to your question:

Google Analytics - Setting the Hit Callback

like image 160
Angelo Silva Avatar answered Sep 28 '22 06:09

Angelo Silva