How to fuck up click tracking with the JavaScript onclick trigger

Fuck up click trackingThere’s a somewhat heated debate over at Sphinn and many other places as well where folks call each other guppy and dumbass try to figure out whether a particular directory’s click tracking sinks PageRank distribution or not. Besides interesting replies from Matt Cutts, an essential result of this debate is that Sphinn will implement a dumbass button.

Usually I wouldn’t write about desperate PageRank junkies going cold turkey, not even as a TGIF post, but the reason why this blog directory most probably doesn’t pass PageRank is interesting, because it has nothing to do with onclick myths. Of course the existence of an intrinsic event handler (aka onclick trigger) in an A element alone has nothing to do with Google’s take on the link’s intention, hence an onclick event itself doesn’t pull a link’s ability to pass Google-juice.

To fuck up your click tracking you really need to forget everything you’ve ever read in Google’s Webmaster Guidelines. Unfortunately, Web developers usually don’t bother reading dull stuff like that and code the desired functionality in a way that Google as well as other search engines puke on the generated code. However, ignorance is no excuse when Google talks best practices.

Lets look at the code. Code reveals everything and not every piece of code is poetry. That’s crap:
.html: <a href=""
onclick="return o('sebastians-blog');"></a>

.js: function o(lnk){'/out/'+lnk+'.html'); return false; }

The script /out/sebastians-blog.html counts the click and then performs a redirect to the HREF’s value.

Why can and most probably will Google consider the hapless code above deceptive? A human visitor using a JavaScript enabled user agent clicking the link will land exactly where expected. The same goes for humans using a browser that doesn’t understand JS, and users surfing with JS turned off. A search engine crawler ignoring JS code will follow the HREF’s value pointing to the same location. All final destinations are equal. Nothing wrong with that. Really?

Nope. The problem is that Google’s spam filters can analyze client sided scripting, but don’t execute JavaScript. Google’s algos don’t ignore JavaScript code, they parse it to figure out the intent of links (and other stuff as well). So what does the algo do, see, and how does it judge eventually?

It understands the URL in HREF as definitive and ultimate destination. Then it reads the onclick trigger and fetches the external JS files to lookup the o() function. It will notice that the function returns an unconditional FALSE. The algo knows that the return value FALSE will not allow all user agents to load the URL provided in HREF. Even if o() would do nothing else, a human visitor with a JS enabled browser will not land at the HREF’s URL when clicking the link. Not good.

Next the statement loads, not (truncating the trailing slash is a BS practice as well, but that’s not the issue here). The URLs put in HREF and built in the JS code aren’t identical. That’s a full stop for the algo. Probably it does not request the redirect script to analyze its header which sends a Location: line. (Actually, this request would tell Google that there’s no deceiptful intent, just plain hapless and overcomplicated coding, what might result in a judgement like “unreliable construct, ignore this link” or so, depending on other signals available).

From the algo’s perspective the JavaScript code performs a more or less sneaky redirect. It flags the link as shady and moves on. Guess what happens in Google’s indexing process with pages that carry tons of shady links … those links not passing PageRank sounds like a secondary problem. Perhaps Google is smart enough not to penalize legit sites for, well, hapless coding, but that’s sheer speculation.

However, shit happens, so every once in a while such a link will slip thru and may even appear in reverse citation results like link: searches or Google Webmaster Central link reports. That’s enough to fool even experts like Andy Beard (maybe Google even shows bogus link data to mislead SEO researches of any kind? Never mind).

Ok, now that we know how not to implement onclick click tracking, here’s an example of a bullet-proof method to track user clicks with the onclick event:
<a href=""
onclick="return trackclick(this.href,;">
Sebastian's Pamphlets</a>
trackclick() is a function that calls a server sided script to store the click and returns TRUE without doing a redirect or opening a new window.

Here is more information on search engine friendly click tracking using the onlick event. The article is from 2005, but not outdated. Of course you can add onclick triggers to all links with a few lines of JS code. That’s good practice because it avoids clutter in the A elements and makes sure that every (external) link is trackable. For this more elegant way to track clicks the warnings above apply too: don’t return false and don’t manipulate the HREF’s URL.

Share/bookmark this: del.icio.usGooglema.gnoliaMixxNetscaperedditSphinnSquidooStumbleUponYahoo MyWeb
Subscribe to      Entries Entries      Comments Comments      All Comments All Comments

35 Comments to "How to fuck up click tracking with the JavaScript onclick trigger"

  1. Richard Hearne on 15 September, 2007  #link

    Some great digging.

    Only proviso is that we’ll never know (unless they give us jobs like Mr Mu) how they are really treating this behaviour. But I for one think you’re spot on with this.

    Is it just me, or does the whole bru-ha-ha seem like there may be other hidden agendas going on?


  2. Sebastian on 15 September, 2007  #link

    Thanks Richard, and with the hidden agenda you’re spot on IMO.

  3. Andy Beard on 15 September, 2007  #link

    I really appreciate the time you spent on providing such a detailed explanation of what Google *might* interpret as sneaky, and I am sure Daniel is going to change to code to something in line with your recommendations.

    I suppose if Matt stated “yes that would be looked on as sneaky” then he might be giving away more than Google want to give away, but at the same time it might not mean automatic exclusion.

    This is the kind of issue where I would love Google to send people emails such as “Links on XYZ page are looked on by Google as sneaky redirects” but I am sure they would have countless reasons not to do it.

    Notifying spammers might encourage them to use methods Google can’t detect as easily, but at the same time there is a loss of what for Google might be valuable data from a human edited categorized directory. (lets not think about DMOZ / Mahalo)

    As to agendas, there is plenty of it, though I haven’t been involved in very much of it at all, and fully disclosed.
    Danny took some action today, I don’t think that is the first time it has happened.

    I wouldn’t exactly class myself as an expert, I know my limitations on the technical / programming side, I just love experimenting.

    Lots of SEOs actually joked about how much they promoted MyBlogLog, and that they should be given a piece of the purchase price. I gave the BC guys lots of feedback, and they wanted to reward me in some way. Consultation just seems to be the closest term I can come to explaining it in a disclosure.

  4. Sebastian on 15 September, 2007  #link

    I called this hapless because it’s kinda shooting in their own feet. If Google would really consider it sneaky, they’d see that under messages in their GWC account, and of course in their traffic stats. Obfuscating links results in links that don’t count. I’d praise Google for implementing a dumbass button pushed by the algos poking client sided routines to inform the site about such unnecessary complex architectural decisions. A tiny message like “you’ve messed it all up, ask Sebastian how to repair your malformed code” would suffice, and wouldn’t reveal too much of their secret sauce. Unfortunately, that’s not going to happen anytime soon, although there’s plenty of work to do with all the new ventures launched by SEO challenged developers. Sigh.

  5. Richard Hearne on 15 September, 2007  #link

    “you’ve messed it all up, ask Sebastian how to repair your malformed code” - you going into the business professionally then? :)

  6. Rose on 15 September, 2007  #link

    How lucky am I to have a dumbass button installed in my honor. I might be a dumbass but at least I was right that their link passed no page rank at all despite Andy calling me a lier.

  7. Sebastian on 15 September, 2007  #link

    Richard, of course you can hire me. Actually, outsourcing for example sanity checks (crawlability and all that technical stuff) makes sense for many search marketing firms and even some SEOs. ;)

  8. Sebastian on 15 September, 2007  #link

    Rose, you’re not alone. I’ve left dumbass buttons left and right during my whole career. :)

  9. Richard Hearne on 15 September, 2007  #link

    Rose - I think you may have been correct in spite of yourself. Your thesis that links that contain an onclick attribute was completely faulty. Sebastian has helped you out by digging into this and showing that the links in question *may* not be passing juice due to the JS routine called. Your original contentions, however, held about as much water as a sieve.

  10. JLH on 15 September, 2007  #link

    Nice job Sebastian.

  11. Rose on 15 September, 2007  #link

    I knew what I was talking about and it was the same thing my husband who is a programmer described. So I did not explain it correctly, but that does not mean that my statement was incorrect or that I was not on to something. I appreciate Sebastian getting them to listen, however all the credit does not go to him. This was pointed out back in June by Doubts and he was dismissed just like my husband and I were.

  12. Rose on 15 September, 2007  #link

    Here is the original link to where Shawn and I were discussing it.

  13. Shawd DesRochers on 15 September, 2007  #link

    Great post Sebastian, However I must point out that it wasn’t you who discovered this and the information you have provided is very similar to ours.

    I posted in my forums about this when Roses decided to Sphinn it Sep 14th

    If you review my forum post you will see I give the correct method of making the link SEO friendly as we use this same method on our directory…

    Which one of the blog catalog developer remarked about our directory over at

    Now Rose yes didn’t explain it correctly but she had the basics down, stating that Blog Catalogs link structure was not passing any Google Juice.

    Any idiot could see that their method was not properly implemented due to the fact of the onclick attribute embedded within the URL.

    By assigning the links a variable ID, then using an external JavaScript outside of the linking structure makes the links much more SEO friendly…

    Example a search engine bot would skip an anchor link that uses the following

    <a href=””””> </a>

    Where as a link that’s using an ID is definitely better

    <a href=”some-blog…….”>
    [It seems WordPress can’t handle your code examples. I’ve fixed the <>s but the code makes no sense to me. Sebastian]

  14. Sebastian on 16 September, 2007  #link

    Rose and Shawn,

    I’m not interested in your fights with BC, and I don’t want to see any footprints of these conflicts here. I’ve nothing to do with BC, in fact I’ve visited their site only once following a link in Andy’s article to his profile there to check out the link, what led to this post eventually.

    Your forum post you’ve linked above as well as your comments here argue with the onclick code in the link alone, which does not block outgoing PageRank in itself. IOW you didn’t and never did provide a plausible reason why these links most probably don’t pass PageRank. You and many others did not understand the posts by Matt and Brian. They’ve never stated that onclick attributes disable PageRank distribution in general. Their posts addressed particular links which were not counted for other reasons.

    I couldn’t care less who gets the “I’ve said that first” bonus, feel free to claim it. My intention was just to end a debate at Sphinn which began to become unfriendly. Also, for the sake of the BC members I’m happy that BC will change their click tracking.

  15. Richard Hearne on 16 September, 2007  #link

    Shame on you Sebastian for trying to rob the limelight from this pair of clueless attention whores.

    BTW Did you hear Matt got a promotion? ‘Matt Cutts CEO of’ - but I said it first so I get all the glory from the announcement. KK?

    I wonder do this pair know Igor?

  16. Sebastian on 16 September, 2007  #link

    Richard, I feel soooo guilty. As for Matt’s raise, I’m just digging in a forum where I posted in 2001/2 or so to find the post where I predicted that earlier than you. Doh, now you’re guilty too hehe

    BTW I’m wondering why Akismet catched your comment. Terms like “clueless attention whores” shouldn’t trigger a spam filter, at least not here since attention whore is a common term in marketing. Oh wait … Akismet caught Igor’s last comment here too …

  17. Rose DesRochers on 16 September, 2007  #link

    Wow you both are something else.

  18. Sebastian on 16 September, 2007  #link

    Can’t speak for Richard, but I don’t feel bad when I’m called an attention whore, or link whore …

  19. […] the situation later, and it does look like those links might actually have a problem with them that could affect PageRank being passed. The problem is, it is not because of what either she or her husband were asserting. If you are […]

  20. […] or could there be some other answer, like, onclick does not definitively prevent Passing PageRank. Sebastian thinks so. In this article he offers an explanation (the only rational one so far) for why […]

  21. Michael VanDeMar on 17 September, 2007  #link

    my husband who is a programmer

    Exactly how many hats is he wearing, anyways?

    Can’t speak for Richard, but I don’t feel bad when I’m called an attention whore, or link whore …

    Heh! :D

  22. Melanie Phung on 17 September, 2007  #link

    All that talk about elegant code was really hot. The squabbling that followed, not so much :(

    What is it with people who can’t let anyone else have the last word and keep digging in their heels post after post? It makes ‘em look like jackasses - and for all I know these are the nicest people in the world.

  23. Sebastian on 17 September, 2007  #link

    Melanie, thanks for stopping by. I’m not sure what you address with the squabbling bit. Probably I don’t want to understand it, because I don’t care about the side effects of this debate.

    At least here everybody behaved so far, please lets leave it by that. I don’t want to discuss personal conflicts here.

  24. […] or “Computers & Internet”. Guess what great traffic you gain with headlines about elegant click tracking or debunking meta refresh myths from blogs selling MySpace templates to teens or RFID chips to […]

  25. Stephen on 27 September, 2007  #link

    Excellent article, I recently implemented the code you described as ‘bullet-proof’ and it works exceptionally well, even when linked to a MySQL database. However, I would strongly disuade anyone wanting to use it with Wordpress etc, as for more reasons than I can understand, it fails everytime.

    Anyway, keep up the great work. Perhaps my Wordpress problem is worth another article, I could certainly use a solution! ;)

  26. Sebastian on 27 September, 2007  #link

    Thanks Stephen. Probably your WordPress theme uses the onclick event. When a JS routine loops all A elements adding an onclick trigger without checking for the existence of onclick event code that would explain your problem. Also, some analytitics software and widgets providing blog stats add onclick code. Download all external JS files and scan them.

  27. Stephen on 28 September, 2007  #link

    Hi Sebastian, I finally made the script work having gone back to the code with a fine toothcomb. It turned out that Wordpress didn’t like the directory reference to the php file called with Javascript - boy do I feel dumb. Anyway, all is working now!

    Thanks, and keep up the great work you do here. :)

  28. Terry on 6 November, 2007  #link

    does anyone has example of trackclick() javascript function which calls JSP page to logging click on the server side.

    I am little confused, how the JSP will log the access log entry, since it only does if using redirect back to the user???


  29. Terry on 14 November, 2007  #link

    hi guys,

    im still awaiting reply for someone. does anyone has a trackclick() example?


  30. Stephen on 14 November, 2007  #link

    Ok, here is an example that works for me:

    This is in the header of the page with the links:

    This is an example of one of the links:

    [Thanks for helping Stephen! My comment script eats posted code. Sebastian]

  31. Stephen on 14 November, 2007  #link

    As the code in my previous comment didn’t display well, try this instead:

  32. […] while ago I helped BlogCatalog to fix an issue with their JavaScript click tracking that Google considered somewhat crappy. The friendly BlogCatalog guys said thanks, and since then […]

  33. […] For instance, years ago search engine crawlers did not follow links embedded in JavaScript, but recent experiments have proven that at least Google does follow the less intricate […]

  34. […] uses onclick, but returns false, but the URL is not constructed… ask Sebastian if you want a definitive answer. // Tags: 301 redirect, blogger, blogspot, custom domain, labels, robots.txt, seo « […]

  35. Andy on 5 April, 2010  #link

    A little wheels within wheels conundrum

    I came across this post covering race conditions today

    Deliberately returning false to delay the page refresh to give GA time to respond.

Leave a reply

[If you don't do the math, or the answer is wrong, you'd better have saved your comment before hitting submit. Here is why.]

Be nice and feel free to link out when a link adds value to your comment. More in my comment policy.