Link to home
Start Free TrialLog in
Avatar of Perumal RM
Perumal RM

asked on

Google Analytics tracking not working for certain links occasionaly.

Hi,

I am having a issue with google analytics tracking my events from time to time.

We use asynchronous code for all of our tracking.

When i click the HOME button on header of my webpage, we wanted to have the click of HOME button tracked and browser redirected to HOME page.

jQuery basically rewrites the links to add google custom tracking code.

	/* Function to automatically add tracking to links on header Home */
	$("#header #btn-home").each(function(){
		var linkValue=$(this).text();
		var onClickValue="_gaq.push(['_trackEvent', 'MAIN_NAV', 'CLICK_HOME_BUTTON', '"+linkValue+"']);"
		$(this).attr("onClick", onClickValue);
	});	

Open in new window


The above jquery rewrites the link

<a class="nav-btn active" id="btn-home" href="/group/gi/index.htm">Home</a>

Open in new window


to

<a class="nav-btn active" id="btn-home" href="/group/gi/index.htm" onclick="_gaq.push(['_trackEvent', 'MAIN_NAV', 'CLICK_HOME_BUTTON', 'Home']);">Home</a>

Open in new window


When i say it works time to time, it means that some time when i click it tracks and some other time it doesn't. So when digging deep into the issue, some one figured out that the page refreshes even before Google could receive the tracking code. So they are asking me to introduce a delay of 100 milliseconds for each anchor within the website, which i feel is not right. There should be some other way for this. So wanted to turn out to experts here and get an opinion on this.
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

JustAMod: the zone which often answers this sort of question is the WebTrends/Stats zone.  Misc Web Dev and Javascript are two good other places.

Perumal_RM:
This is an excellent short writeup on using jquery to modify links for Google Analytics:
http://think2loud.com/105-use-jquery-with-google-analytics-to-track-clicks-on-outgoing-links-from-your-site/

They don't mention timing delays, so I don't think that's a normal requirement.  

However, the redirection to home could well screw up the timing on javascript execution.  

In the article above, they send the url for redirection to Google, so there's no need for redirection in your own page.  It's odd, but that might be the thing to do for your home page redirection -- have Google do it after they record the Goodle Analytics click.
Avatar of Perumal RM
Perumal RM

ASKER

I dont see the url being sent to redirection to google. IF you can point out???
I was thinking of where the page says:
"This code makes the call to Google Analytics and passes a page path of “/outgoing/” and the url of where the click was headed."

You're right -- Google Analytics isn't doing the actual redirection.

If you can take out your redirection to home on the page, then a lot of things will probably become easier.

If you want help, you probably should try some things and ask questions.  It's more likely to work if you don't leave weeks between your responses.

The issue is still open though. So even within weeks response or months response doesnt makes sense. The approach what we did though was introduce 100ms delay on every anchor link and figured out that that didnt even helped us in anything.

I think there should be some other way to attack this, I am being pushed to a corner on a wrong direction by my company architects :)
ASKER CERTIFIED SOLUTION
Avatar of Tony McCreath
Tony McCreath
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perumal_RM: my point was that if you don't respond to suggestions or answers for weeks, the question looks abandoned and is less likely to get further attention.

If you also don't choose to act on answers you get, then we can't help further.  This question is only open because you are not working on it.