Track SEO rankings with Google Analytics

Mike Pantoliano of Distilled had a good post over at SEOmoz about how to turn Google Analytics into your own rank tracker. We have been playing with the cd= parameter at Yoast before to track SEO rankings, as Mike also notes, and his improvement on the idea is a welcome one.

In the comments, my buddy Richard Baxter immediately suggested this would be a good addition to the Google Analytics for WordPress plugin. The “problem” was/is that Mike’s example was in PHP, doing the rank recognition server side. This won’t work, as we all use W3 Total Cache to cache our pages, right? And then, we’d be storing the same rank over and over again, or no rank at all, or, well you get it, mayhem ensues.

So, I had to come up with a javascript version that does the same. Luckily, that’s not too hard. You simply need to do two things: check that the referrer is coming from google and that it contains the cd= parameter. If it does, get the value out of it and store it in a custom variable. Here’s an example using the asynchronous tracking code, which you could, if you wanted to, drop into your site’s footer already if you have asynchronous tracking running:

if (document.referrer.search(/[\?|&]cd=/) != -1
  && document.referrer.search(/google\./) != -1) {
	var rank=document.referrer.match(/[&|\?]cd=([\d]+)/);
	_gaq.push(['_setCustomVar',1,'rank',rank[1],3]);
}

This is now running on my blog as a test, when it works as I expected I’ll add it to the plugin. The code sample above uses custom variable “index” or “slot” 1 to store the ranking. I’m using another “slot” one here on the blog, but my plugin would take care of that. I’d love to hear your feedback and ideas on other stuff to do with this!

Tags:


Yoast.com runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!

59 Responses

  1. Navin PoeranBy Navin Poeran on 30 September, 2010

    Cool.

    Will look forward to your updates, regarding this post :)

  2. Mayur Somani (AgentWP)By Mayur Somani (AgentWP) on 30 September, 2010

    Looking forward to the updated plugin. I’ll also start testing the script until then. Thanks.

  3. Luc De BrouwerBy Luc De Brouwer on 30 September, 2010

    Seems like a solid solution!

  4. John CisarBy John Cisar on 30 September, 2010

    See I knew I’d learn something uber cool GA related today ! Thank’s for sharing.

  5. Billy GirlardoBy Billy Girlardo on 30 September, 2010

    I haven’t updated W3TC since 8.5.2 (or OpenID since last – 3.3.2), because they give me the WSOD (whoa, I just ran outside your textarea via FF 3.6.10), but I see they aren’t yours anyway :-)

    Looking forward to the update for your GA plugin, and thanks for everything!

  6. Allan CollinsBy Allan Collins on 30 September, 2010

    WOW! I am looking forward to your plugin update. Tracking rankings in Analytics will save me a lot of time and will allow me to analyze the amount of traffic for the given ranking.

  7. DanBy Dan on 1 October, 2010

    Thanks Yoast can’t wait.

  8. oblomovBy oblomov on 1 October, 2010

    This would be awsome. But how about extracting the tld of the google referall and also store this in a custom variable?

    • Joost de ValkBy Joost de Valk on 1 October, 2010

      great suggestion, let me ponder how to do that for a bit ;)

  9. lastactionseoBy lastactionseo on 1 October, 2010

    I will test this immediately it sound great. Great Job!

  10. Grün WeissBy Grün Weiss on 1 October, 2010

    nice artcile i test it and i wil see thats works

  11. Gregorio Luis!Como Ganhar DinheiroBy Gregorio Luis!Como Ganhar Dinheiro on 1 October, 2010

    I am looking forward to your plugin update,can’t wait,will test this immediately

  12. Kenneth BerkleyBy Kenneth Berkley on 1 October, 2010

    Thanks Yoast for sharing this us i will test this immediately it sound great and very useful.

  13. TrafficColemanBy TrafficColeman on 1 October, 2010

    Thanks..you are always looking to help the little guy.

    “TrafficColeman “Signing Off”

  14. OyunyurdumBy Oyunyurdum on 1 October, 2010

    Well, thank you. Has been a great application.

  15. master GO masterBy master GO master on 2 October, 2010

    I will be waiting for great results and you will give me a Track SEO rankings with Google Analytics plugin. thanks for information

  16. Joan StewartBy Joan Stewart on 2 October, 2010

    Thanks Joost,

    I will wait for the plugin, it sounds like this could really come in useful.

    As always your tips are always looked forward to and one of the first emails I always open.

  17. Chris AbernethyBy Chris Abernethy on 3 October, 2010

    You can also do this completely in GA with a custom profile and Filters, check this out for info on how to do it: http://www.chrisabernethy.com/tracking-keyword-ranking-position-with-google-analytics/

  18. ElikoBy Eliko on 4 October, 2010

    Thanks Joost. Would you mind helping me configuring my analytics advanced segment for this?
    I used your code (and Andre Scholten’s from seomoz), and setup a new GA Advanced Segment with “Custom Variable (Key 1)” / “Matches Exactly” / “Google_Ranking” (I also changed the custom-var-key-string in my website as you may see in the homepage source code).
    When I test the segment (after using the code for about 32 hours in my website), GA returns “0 visitors” :(
    Do you know why?

  19. MassoutreachBy Massoutreach on 5 October, 2010

    Plugin looks great. I think it will gonna help a lot in SEO.

  20. FrankBy Frank on 5 October, 2010

    So does this trick only work with google instant? Other ‘normal’ serps don’t pass the cd parameter do they?

    • Chris AbernethyBy Chris Abernethy on 5 October, 2010

      I’ve seen an increase in the number of google referrals that include the “cd” parameter lately, but it was definitely in use before google rolled out “instant”.

  21. Bruno HugBy Bruno Hug on 5 October, 2010

    I’ve used another technic to find the rank in Google for a visitor, by creating a filter.

    Choose Custom filter -> advanced, then:
    Field A : Campaign term : (.*)
    Field B : User defined : (\?|&)(cd)=([0-9]*)&
    Output to : Campaign term : $A1 ($B3)

    Field A required : Yes
    Filed B required : No
    Override Output field : Yes
    Case sensitive : No

    Let me know if it does not the same thing.

  22. AndyBy Andy on 5 October, 2010

    But in this way you will track only clicks. How will you track the positions, that are deeper in SERP? (like on page 5 f.e.)

    • Chris AbernethyBy Chris Abernethy on 5 October, 2010

      This method only tracks position as revealed by the referer[sic] string from google when it contains the “cd” parameter, so it only works when a user clicks on a search result listing. If you want to track your pages search result position for particular keywords in general without having to wait for a user to actually click on it, you would need to use software designed for that purpose, e.g., a scraper.

      A google search for “track keyword ranking” will direct you to several options.

    • Chris AbernethyBy Chris Abernethy on 5 October, 2010
  23. ViktorBy Viktor on 5 October, 2010

    as i understood, you are only tracking SERP Position from a clicked Person, not from Positions were “impressed” (from just impressions), isn’t it??

  24. Home of catsBy Home of cats on 5 October, 2010

    Will try it soon! :)

  25. Bruno HugBy Bruno Hug on 5 October, 2010

    @Andy

    I’m not sure to have perfectly understood you code, if so…

    What I get with the filter is things like : Keyword (Position).
    It seems to be the same as your code, or am I misunderstanding something?

  26. RoieBy Roie on 5 October, 2010

    Bruno Hug seems to have the easier solution and this way the reports can be viewed directly within regular reports instead of the custom variables report

  27. RogerBy Roger on 6 October, 2010

    I can’t wait until it gets pushed into the plugin. Thanks for the innovation.

  28. KarlBy Karl on 6 October, 2010

    Nice work, cant wait for the plugin! When do you think you’ll release the update?

  29. Udo KempenBy Udo Kempen on 6 October, 2010

    Sounds great, looking forward to compare the positions reported in GA with the new enhance rankings stats just added to the Google Webmaster Tools

  30. Iwan UswakBy Iwan Uswak on 6 October, 2010

    You should know that if the clicker has “Starred results for [keyword]” sitting before the organic results, they will influence the number/rank in the cd= parameter.

  31. StijnBy Stijn on 6 October, 2010

    Do you expect working this would be easier than using the search query report in Google Webmaster Tools?

    • Joost de ValkBy Joost de Valk on 8 October, 2010

      It’s mostly just another validation of any data GWT might show :)

  32. MortenBy Morten on 6 October, 2010

    Hi Yoast,

    This is really a cool feature :) I’m looking forward to see it live!

    If it is possible to see the highest rankings in the wordpress admin panel, that would be a cool feature.

  33. SteveBy Steve on 6 October, 2010

    Wow. Given that I’m obsessed with Google Analytics, I’m looking forward to the update. Keep on rockin’ Joost.

  34. arnout hBy arnout h on 6 October, 2010

    Nice one Joost, thanks!

  35. Andy Max JensenBy Andy Max Jensen on 6 October, 2010

    Great! As usual!

    :-) Andy

  36. Martijn BeijkBy Martijn Beijk on 6 October, 2010

    Hé Joost,

    As you know the cd number will be a bit flawed by universal search listings. a way to differentiate between these is to look out for sa=X or sa=T (x being extended, t being traditional/text). So when you see a ranking position 13 in use with sa=X it might be a very common issue that in fact the ranking position is still on page 1 instead of 2 which most people might think. Maybe it can be of use for the people storing it in the custom variable.

  37. MikalBy Mikal on 6 October, 2010

    Super great. Thanks for the tip. I always loves your tweaks and tips for SEO.

  38. frankBy frank on 6 October, 2010

    Great! Will try it soon!

  39. Brad DavisBy Brad Davis on 7 October, 2010

    That will be a great addition to the plugin, look forward to seeing it action!

  40. ClaudiaBy Claudia on 7 October, 2010

    Nice post, I am going to try it. Thanks Yoast!!

  41. amosBy amos on 7 October, 2010

    Tried it for past 2 days, doesn’t seem to work

    • Joost de ValkBy Joost de Valk on 8 October, 2010

      Hmm it works for me amos :)

  42. MiguelBy Miguel on 7 October, 2010

    Is this functionality added to the Google Analytics for WordPress plugin yet? How can I get notified once it is?

    Thanks!

  43. Ann DonnellyBy Ann Donnelly on 12 October, 2010

    I need to pay more attention to your feed! I was just thinking if I could get someone to integrate this sort of thing with data from Google Analytics, it’d make my life 100% easier.

    OK – do you know anything that will integrate this with Webmaster Tools and Adwords Keyword Tool data and I’d be working half days!

    (Is your Amazon wishlist up to date?)

  44. MichaelBy Michael on 13 October, 2010

    this is great! But tell me how would you recommend proceeding if you have a large list of keywords that you want to track – is there an automated way to load up the keywords?

    would appreciate suggestions on this!

    Thanks Yoast!!

  45. AlexBy Alex on 14 October, 2010

    I just doanloaded and installed your WordPress Analytics and I have to say thank you, this is really awesome. I love the added features for tracking. I can’t wait to explore some of your pther plugins.

  46. RobBy Rob on 15 October, 2010

    Great stuff Joost. Thanks for all the info and plugins. I have more and more clients asking for guidance on SEO and I am pointing them in the direction of your great film presentation, which I found really useful.

    I still have alot of changes to make to some of our sites, and I’ll be giving this plugin a try once I have implemented all the other great advice I have gleened from your content.

    If I am honest, I am commenting so I can see the redirect functionality after a post that you mention in the film!

  47. Todd DonaldBy Todd Donald on 16 October, 2010

    I installed the Plugin on client site running WP V 2.9.2 and it works fine, but when I tried to install it on my site which is V 3. whatever (the newest WP version), it does not appear on the dashboard. I have tried to deactivate and reactivate, I’ve tried refreshing and logging off, etc and yet it still will not show up. It does not show up as “Stats” in the view options checkbox area either. The plugin works great with WP V 2.9.2, so I would love to get this Plugin working on my site which is running the newer 3. version of WordPress, any suggestions?

  48. Jody May-ChangBy Jody May-Chang on 19 October, 2010

    I am having the same issue as Todd Donald with Google Analytics not showing up in my WP 3.0.1 dashboard. Never used it before so I have nothing to compare it to but it looks cool and I would like very much to use it.

Trackbacks

  1. [...] Track SEO Rankings with Google Analytics – Yoast Mike Pantoliano of Distilled had a good post over at SEOmoz about how to turn Google Analytics into your own rank tracker. We have been playing with the cd= parameter at Yoast before to track SEO rankings, as Mike also notes, and his improvement on the idea is a welcome one. [...]