Styleforum › Forums › General › General Chat › Javascript help - Google Analytics issue
New Posts  All Forums:Forum Nav:

Javascript help - Google Analytics issue

post #1 of 21
Thread Starter 
Was hoping someone might have some input on this:

I just installed tracking code for Google Analytics that is supposed to track clicks on the mini and bigger banners and report them for our affiliates. However, the script uses the following to forward the user:

http://www.google.com/support/google...n&answer=55527

Code:
<script type="text/javascript">
function recordOutboundLink(link, category, action) {
  try {
    var pageTracker=_gat._getTracker("UA-1238980-1");
    pageTracker._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100)
  }catch(err){}
}
</script>

Which makes the browser disregard the "target=_blank" that usually opens the link in a new tab/window.

Could I just have it return somehow after the 100ms instead of the document.location forwarding? Google says the 100ms delay is necessary so that the code has time to load before the user clicks on it. I'm pitiful in javascript and no amount of searching has found me an answer so far.

Thanks.
post #2 of 21
Sent an email to our implementation specialist; hopefully he'll have an answer. edit - just to clarify, the issue is that currently the banners open in the existing tab, and you want them to open in a new one, correct?
post #3 of 21
Thread Starter 
Quote:
Originally Posted by dcg View Post
Sent an email to our implementation specialist; hopefully he'll have an answer. edit - just to clarify, the issue is that currently the banners open in the existing tab, and you want them to open in a new one, correct?
Yes, up until I added the tracking code, they opened in a new tab. Thanks for your help.
post #4 of 21
No problem. I also found this:

http://www.blogstorm.co.uk/track-out...gle-analytics/

But it's a few years old and looks like it works with urchin instead of the new stuff.
post #5 of 21
What do your outbound links look like?

<a href="http://www.example.com" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;" target="_blank">

Something like the above? added the

target="_blank"

to the code from the GA link.
post #6 of 21
Thread Starter 
Yes, pretty much. I don't think that other link will work with the new GA system, but it would be nice. Seems pretty quick.
post #7 of 21
There were some comments in the link mentioning the new system...seems that maybe only one line needs to be changed (the line that mentions urchin).

I'll see what I can come up with tomorrow. Wouldn't think this would be an uncommon request...
post #8 of 21
Thread Starter 
Yeah. I tried the method he mentions as being the "new way" to do this through GA (didn't try modifying his code though). It didn't work and it messed up our pageview stats. I may try the way shown in the comments anyway, since the stats are screwed up now and it shouldn't hurt anything.
post #9 of 21
Thread Starter 
Holy crap, I just totally guessed and replaced the 'document.location = "' + link.href + '"' with 'return', and now it seems to work. Here's to the rectal pluck method, hopefully it tracks the clicks. If anyone knows why it shouldn't do so or a better way please let me know though.
post #10 of 21
Quote:
Originally Posted by j View Post
It didn't work and it messed up our pageview stats.

Shit, sorry.

Glad you've got it working now.
post #11 of 21
Thread Starter 
Quote:
Originally Posted by dcg View Post
Shit, sorry.

I mean, before I asked, I did the way that's linked way down in his comments. Not your fault at all.

Hopefully these start tracking now, as I'm getting tired of messing with it.

Thanks for your help.
post #12 of 21
Quote:
Originally Posted by j View Post
I mean, before I asked, I did the way that's linked way down in his comments. Not your fault at all. Hopefully these start tracking now, as I'm getting tired of messing with it. Thanks for your help.
Not sure I provided much help , but for what it was worth, you're welcome. Let me know if you still experience any issues.
post #13 of 21
J, hopefully it works out. I run GA and it tracks all hits from this site down to the post level. What your code efforts could do for me is tell me from where people are from when they visit your site and then click through to mine.
post #14 of 21
Thread Starter 
I have tracking stats from yesterday! Yay.
post #15 of 21
Thread Starter 
Quote:
Originally Posted by Crane's View Post
J, hopefully it works out. I run GA and it tracks all hits from this site down to the post level. What your code efforts could do for me is tell me from where people are from when they visit your site and then click through to mine.
Yeah, I think I could do that by setting up "funnels" but I haven't a clue how to do that. I'll do some reading today and if it's not too difficult I'll set it up.
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: General Chat
Styleforum › Forums › General › General Chat › Javascript help - Google Analytics issue