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!



Cool.
Will look forward to your updates, regarding this post :)
Looking forward to the updated plugin. I’ll also start testing the script until then. Thanks.
Seems like a solid solution!
See I knew I’d learn something uber cool GA related today ! Thank’s for sharing.
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!
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.
Thanks Yoast can’t wait.
This would be awsome. But how about extracting the tld of the google referall and also store this in a custom variable?
great suggestion, let me ponder how to do that for a bit ;)
I will test this immediately it sound great. Great Job!
nice artcile i test it and i wil see thats works
I am looking forward to your plugin update,can’t wait,will test this immediately
Thanks Yoast for sharing this us i will test this immediately it sound great and very useful.
Thanks..you are always looking to help the little guy.
“TrafficColeman “Signing Off”
Well, thank you. Has been a great application.
I will be waiting for great results and you will give me a Track SEO rankings with Google Analytics plugin. thanks for information
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.
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/
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?
Plugin looks great. I think it will gonna help a lot in SEO.
So does this trick only work with google instant? Other ‘normal’ serps don’t pass the cd parameter do they?
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”.
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.
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.)
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.
Also check Joost’s latest post -> http://yoast.com/sponsored-review-seo-rank-analysis-with-authority-labs/ :)
as i understood, you are only tracking SERP Position from a clicked Person, not from Positions were “impressed” (from just impressions), isn’t it??
Correct.
Will try it soon! :)
@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?
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
I can’t wait until it gets pushed into the plugin. Thanks for the innovation.
Nice work, cant wait for the plugin! When do you think you’ll release the update?
Sounds great, looking forward to compare the positions reported in GA with the new enhance rankings stats just added to the Google Webmaster Tools
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.
Do you expect working this would be easier than using the search query report in Google Webmaster Tools?
It’s mostly just another validation of any data GWT might show :)
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.
Wow. Given that I’m obsessed with Google Analytics, I’m looking forward to the update. Keep on rockin’ Joost.
Nice one Joost, thanks!
Great! As usual!
:-) Andy
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.
Super great. Thanks for the tip. I always loves your tweaks and tips for SEO.
Great! Will try it soon!
That will be a great addition to the plugin, look forward to seeing it action!
Nice post, I am going to try it. Thanks Yoast!!
Tried it for past 2 days, doesn’t seem to work
Hmm it works for me amos :)
Is this functionality added to the Google Analytics for WordPress plugin yet? How can I get notified once it is?
Thanks!
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?)
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!!
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.
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!
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?
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.