Welcome to WebmasterWorld Guest from

Message Too Old, No Replies

Is this o.k. for Google

Won't hijack pages or cause a problem?

7:51 pm on Mar 19, 2005 (gmt 0)

10+ Year Member

I need to track the number of clickthroughs on outgoing links, but I don't want to stop the passing of PR to the external sites. So, I'm using the following solution:


function clk(id,link){
window.location.href= 'http://www.mydomain.com/track.cgi?ID='+id;
return false;

Example of the link to an external site:

<a href="http://www.example.com" onclick="return clk(123,this)">


I think that google spidering will bypass the javascript stuff, and just follow the link to the www.example.com external site.

Actual users who click on the link (and have javascript enabled) will allow the tracking to take place through the track.cgi script.

I checked, and if somehow google (or other spiders) follow the link in the tracking script with an ID number (e.g. [mydomain.com...] then it will go to the external site, and the server header response show 200 OK.

There is no 302 involved, so this wouldn't lead to any inadvertent hijacking problems would it?

Or does anyone else see any potential problems that this method could cause with google (or other major search engines)?

3:27 pm on Mar 20, 2005 (gmt 0)

10+ Year Member

I cant see it causing any problems. It is after all the exact same way Google counts clicks.
8:02 pm on Mar 20, 2005 (gmt 0)

10+ Year Member

It's a good solution - Google currently doesn't follow onClick links. But it's likely it will eventually, so it's good to check logs.

It's essential to put the code outside the link - if you wrote 'onClick="location.href='www.mysite.com/redir.php?url=www.othersite.com'"', Google would be able to follow this, not because of parsing JavaScript, but because it fetches the links from any text, if I'm not wrong.

The other problem is, that if Mozilla/Firefox user clicks with middle button (opening the page in new tab), there is no onClick event generated, so you won't track this click.

You can avoid this problem writing a javascript that changes a link, like


function change_link (anchor) {

old_link = this.href;
new_link = 'www.mysite.com/redir.php?url=' + old_link;

this.href = new_link;

return true;

But this is a complicated method, and there is a risk Google may think you're cloaking (it may think the same in onClick method though). It _is_ showing different link for Googlebot than for user anyway. But currently this methods are not penalized, and if used in good purpose, like in your case, they shouldn't ever be penalised.

11:20 pm on Mar 20, 2005 (gmt 0)

10+ Year Member

Thanks for the feedback. Actually, I didn't realize but the method I was using was showing the link, and then using the other tracking link/redirect to send the user to the site.

So, I've changed to using the actual google method where it loads an image that triggers the tracking script, but the user is always taken to the link that is shown in the <a href> tag.

The Javascript:

function clk(n) { if(document.images){ (new Image()).src="/track.cgi?ID="+n; } return true;}

Example Link:

<a href="http://www.example.com" onmousedown="return clk(123)">Example Site</a>

I hope that wouldn't cause any problem with google or the other major search engines.

If anyone thinks that it would, I would be interested to hear about it...

12:38 am on Mar 21, 2005 (gmt 0)

What would happen if you use the url in between the relevant <noscript> tags? Would google read that? Or would it still be within the javascript as google would read the thing?
3:12 pm on Mar 21, 2005 (gmt 0)

10+ Year Member

A link like the one below will get spidered by a search engine and should cause no problems. It's just a standard link with an onclick argument. Google will just ignore the onclick part which is fine.

<a href="http://www.example.com" onclick="return clk(123,this)"> example </a>

6:42 pm on Mar 21, 2005 (gmt 0)

10+ Year Member

Thanks. That's what I figured. It's interesting, though, that actually it won't work for me if I use 'onclick' method, but it does work for 'onmousedown'. In other words:

The onclick version:

<a href="http://www.example.com" onclick="return clk(123,this)">

Doesn't complete the track.cgi script for me (clickthrough not recorded) on my server.

The onmousedown version:

<a href="http://www.example.com" onmousedown="return clk(123,this)">

Does work (the track.cgi script records the clickthrough).

I wonder if there is a timing issue that once the click is recorded, and the user is immediately redirected, that there is no time to load the image, and run the script?

Anyway, I noticed that Google also uses onmousedown rather than onclick.

7:53 pm on Mar 21, 2005 (gmt 0)

10+ Year Member

Yes, I have just noticed that I too use the onmousedown event to track clicks. I have been using this method for over a year without problems.