• Hi, I am the owner and main administrator of Styleforum. If you find the forum useful and fun, please help support it by buying through the posted links on the forum. Our main, very popular sales thread, where the latest and best sales are listed, are posted HERE

    Purchases made through some of our links earns a commission for the forum and allows us to do the work of maintaining and improving it. Finally, thanks for being a part of this community. We realize that there are many choices today on the internet, and we have all of you to thank for making Styleforum the foremost destination for discussions of menswear.
  • This site contains affiliate links for which Styleforum may be compensated.
  • STYLE. COMMUNITY. GREAT CLOTHING.

    Bored of counting likes on social networks? At Styleforum, you’ll find rousing discussions that go beyond strings of emojis.

    Click Here to join Styleforum's thousands of style enthusiasts today!

    Styleforum is supported in part by commission earning affiliate links sitewide. Please support us by using them. You may learn more here.

Javascript help - Google Analytics issue

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
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.
 

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506
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?
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
Originally Posted by dcg
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.
 

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506
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.
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
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.
 

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506
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...
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
Yeah. I tried the method he mentions as being the &quot;new way&quot; 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.
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
Holy crap, I just totally guessed and replaced the

'document.location = &quot;' + link.href + '&quot;'

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.
 

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506
Originally Posted by j
It didn't work and it messed up our pageview stats.

****, sorry.

Glad you've got it working now.
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
Originally Posted by dcg
****, 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.
 

dcg

Distinguished Member
Joined
Nov 2, 2007
Messages
3,991
Reaction score
506
Originally Posted by j
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
smile.gif
, but for what it was worth, you're welcome. Let me know if you still experience any issues.
 

Crane's

Distinguished Member
Joined
Jun 4, 2008
Messages
6,190
Reaction score
518
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.
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
I have tracking stats from yesterday! Yay.
 

j

(stands for Jerk)
Admin
Spamminator Moderator
Joined
Feb 17, 2002
Messages
14,663
Reaction score
105
Originally Posted by Crane's
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.
 

Featured Sponsor

How important is full vs half canvas to you for heavier sport jackets?

  • Definitely full canvas only

    Votes: 104 36.7%
  • Half canvas is fine

    Votes: 103 36.4%
  • Really don't care

    Votes: 36 12.7%
  • Depends on fabric

    Votes: 46 16.3%
  • Depends on price

    Votes: 41 14.5%

Forum statistics

Threads
508,214
Messages
10,600,365
Members
224,562
Latest member
timmcvickar
Top