tip

Create the ultimate SEO report in Google Analytics

Skrevet af Esben Rasmussen i Google Analytics, SEO     Comments 16 kommentarer      
dec
30

With this guide you can see how well your keywords rank in Google directly in Google Analytics.

[This is the english translation of my danish article]

First you need to tell Google where to find the information about the ranking of your keywords.

This can be done in two different ways:

  1. Adding a bit of extra javascript to the Google Analytics code
  2. By setting up an advanced filter in Google Analytics (and using it on a profile)

I will now demonstrate both methods.

Method nr. 1 – locating ranking information using javascript

The standard Google Analytics code looks like this:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Now add the following code:

if(document.referrer.length > 0){
var regex = new RegExp("cd=([0-9]+)");
var match = regex.exec(document.referrer);
var rank = match[1];

if (match) {
_gaq.push(['_trackPageview', '/googleRank/' + rank + '.html']);
}
}

so the overall code looks like:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);

/* Added SEO tracking code begin */

if(document.referrer.length > 0){
var regex = new RegExp("cd=([0-9]+)");
var match = regex.exec(document.referrer);
var rank = match[1];

if (match) {
_gaq.push(['_trackPageview', '/googleRank/' + rank + '.html']);
}
}

/* Added SEO tracking code end */

_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

Whenever a user enters your website through a Google search this method tells Google Analytics that it should register a visit to the page /googleRank/#.html (where # is the ranking of your keyword).

To prevent your stats from getting bloated due to the extra fake page views, I recommend that you in Google Analytics create a new SEO profile while at the same time filtering the fake page views – those beginning with /googleRank/ – out of all other profiles.

Should you choose not to filter it out of your other profiles the result will be a lot of fake extra visits and a bounce rate of zero for (almost) all visitors from Google.

If you are unsure about how to use filters, you can read more about filters and profiles at Google.

Method nr. 2 – using an advanced filter to locate ranking information

Enter the Filter Manager (located in the lower right hand corner of your account)  and choose Add Filter.

[For extra guidance see image below description]

  1. Give your filter a meaningful name – such as SEO monitor, SERP tracking etc. – so you can easily recognize your filter and know what it does
  2. Select the filtertype Custom filter
  3. Select the subtype Advanced
  4. Click in the list next to Field A -> Extract A, scroll down and select Referral
  5. In the empty textfield to the right you need to enter “cd=([0-9]+)” – without quotationmarks
  6. Leave the fields next to Field B -> Extract B
  7. Click in the list next to Output to -> Constructor and select Request-URI
  8. In the empty textfield to the right you need to enter “/googleRank/$A1.html” – without quotationmarks
  9. Make sure that Field A Required is set to Yes
  10. Make sure that Field B Required is set to No
  11. Make sure that Override Output Field is set to Yes
  12. Make sure that Case Sensitive is set to No
  13. Select which profile should have this filter applied (or wait until  you have created a SEO profile) – make sure it is not your normal profile
  14. Click on Save Changes

The profile which uses this filter will now store the ranking info as virtual pageviews of the page /googleRank/#.html (where # is the ranking of your keyword).

If you have used one of the two methods described, Google Analytics will record the ranking info of your keyword as it was when the user clicked on your search result in Google (since this is the only search engine where this little trick works).

Example: If a user clicks on your result in Google where it is presented as number four then that will be recorded as a visit to the page /googleRank/4.html.

Next page: Prepare the data in Google Analytics

Sider: 1 2 3

16 kommentarer til “Create the ultimate SEO report in Google Analytics”

  • Although there are many weaknesses in using cd= as tracking parameter for SEO ranking, interesting solution. Especially the possibility for using alerts if ranking drops is a nice approach.

    By the way, it’s possible to achieve the same without implementing any extra codes into the website.
    Some advanced filters in Google Analytics will make it possible to extract this information and rewrite the URLs into “ranking goals”.

    • Hello Eivind

      Thank you for the feedback.

      Just out of curiosity, which weaknesses are you referring to? I mean, I know that not every browser reveals the referrer and that image results don’t use cd= (but instead use start=) but which other weaknesses would you say that cd= suffers from?

      In my opinion, if you have enough data, cd= can actually be a rather precise tool, since it reveals your subjective rankings due to the personalization of Google results, whereas more professional tools (to my knowledge) try to measure the objective ranking.

      My point being that users see subjective results and not objective, so cd= comes closer to what your users see.

      And thank you so much for pointing out that it can be done without using code. You are of course absolutely right. The reason this approach uses code is actually just re-use of code from the SEOmoz post which inspired me.

      Will definately have to try to set it up without code.

  • I should have put “weakness” in quotes, because the weakness is in the knowledge of how thing is counted with the cd parameter.

    A person not very familiar with SEO will think that the cd parameter reflects what he sees:
    10 results per page, so cd=10 will be the last result on page one. But with site links and universal search in place, what a person sees as an number 5 spot in SERP could be tracked as cd=10. Cd=18 you would normally think is on page 2, but it could be on page 1 as well.

    Another example is that if you expand a search result, cd will start from 1 again in the expanded search result.

    I know this “warning” is mentioned in the SEOmoz article (and other articles as well), but still…

    With other words, I agree with what you say that it can be a pretty precise tool, and your method (with alerts) makes it easier to get a better picture of rankings and react to changes, but there are some “but’s” with the cd parameter. :-)

    • Thanks for clarifying – I completely agree with you.

      And yes, I should probably have mentioned some of the “but’s” you mention, because they are of course very relevant… So thank you for adding this info. :)

  • Very good tutorial for ranking analytics. Thank you so much. you saved my life.

    • Hi Joe

      Thanks for the comment – really appreciate it!

      Good to hear that it was of use to you. :)

  • I have just updated the blog post with information on how to achieve the same result without extra javascript – just by creating an advanced filter i Google Analytics.

  • Hi!

    Your tutorial is super nice.

    I have one question – is there a way I set a daily analytics alert to show which keywords haven’t got any traffic yesterday, but got traffic today?

    It seems is easy to set custom alerts for single pages, but I want to set custom alerts for keywords, in general, not just one keyword.

    • Hi me

      Thank you for the kind words.

      The thing with Google Analytics is that it only registers what happens – it cannot process what doesn’t happen.

      This means that you cannot say “Give me an alert when {unspecified} [keyword] is used AND [Goal conversion rate] = zero yesterday but is > zero today”.

      The reason being that yesterday your keyword wasn’t registered – which means Google Analytics cannot compare today with yesterday because yesterday the keyword didn’t exist (according to Google’s knowledge).

      If I understand your intention correctly, what you really want is to be notified, whenever a new keyword is used: I am afraid this can’t be done in Google Analytics. You have to see if there is another (probably paid) service which integrates Google Analytics API, that offers this kind of datamining.

      Alternatively you can do it yourself (although this contradicts the purpose of alerts) by downloading your statistics and maintaining a spreadsheet where you automatically sort the list into the separate keywords.

  • Hi, since i installed the special code. My overall traffic stat went down about 70%. I have done it on 2 sites and they acted they same. i wonder what went wrong. Please help. Thanks

    • Hi Joe

      Definitely sounds weird!

      Since you didn’t mention which sites were having problems I took a chance and looked at the website which is sort of mentioned in your email address.

      On that site I can see that the Google Analytics code has been implemented twice. The first instance is my code and the second is a standard analytics code.

      Having two instances of the same Google Analytics code will definitely mess up your data. You should either use my code or your own – but not both. :)

      I would also recommend that you use the updated version of my code which works better in Internet Explorer.

      Seing as you are using the asynchronous version of the Google Analytics code I would also advise you to move it so it is located in the head section of your website per Google’s recommendations: http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=174090

      However, if you want to make sure that the code doesn’t give you any trouble, you could try to remove your implementation of my Analytics code and instead use my guide (in this article) to achieve the same result by using a filter in Google Analytcs.

      This means that you can create virtual pageviews containing the SEO rank by using a filter in Google Analytics instead of having to rely on code to do it for you.

      Hope this helps

  • This is wonderful. I am implementing on our company site. I will want to see that we can segment using the new page (meaning I can create an advanced segment for all visits where the page “/googleRank/1.html” was seen, and then see the behaviors on site from there.

    • Hi Cindy

      Glad you liked it. :)

      You could try to use regular expressions (see http://www.onlinekonsulenten.dk/seo/monitor-your-seo-with-google-analytics/2/) and then create the segments Googlerank 1-3 and Googlerank 4-6 in order to compare their metrics such as bouncerate.

      I am currently finishing my masters thesis and based on my research it would appear that results in the top 3 (to some extent top 5) in the SERP “automatically” inclines people to be more positive towards your website than lower ranking results with just as good snippets. So basically a higher ranking means a better user experience.

      However, if this is what you want to see, you probably need to look at more than just “/googleRank/1.html” (which isn’t a SERP number but the individual ranking number of the result itself) – which is why I recommend using regular expressions. :)

  • Thank you so much for this very interesting and highly useable guide! :)

    I, however, have a question: How will storing the Google Rank in the “Request URI”-variable influence the “Landing page”-variable?

    If there is an influence: How can this possibly be avoided? – As I would like to have both the “Landing page” and the “Google rank” variables available for segmentation in my reports :)

    And do you have any good, intuitively understandable, explanations on the “cd=”?

    Once again: THANK YOU SO MUCH FOR THIS GUIDE :)

    //Lars

    • Hi Lars

      Glad you found it useful!

      Yes, it will have impact on the landing page variable since the landing page will seem to be “/googleRank/#” – which is why I recommend that you separate the SEO-filter/profile from your normal profile.

      That way you can always see the “true” unmanipulated data in the normal profile and for extra SEO knowledge you can use the SEO-profile.

      If you need to create segments based on SEO data, then my SEO overview using virtual pageviews, is propably not the way to go.

      Instead I would either:

      1) select that the “Output to -> constructor” outputs to “Used defined”.
      2) Follow the method described here: http://yoast.com/track-seo-rankings-with-google-analytics/

      Using either of these methods will make you able to acces the SEO data and use it as a custom segment without it affecting your pageviews. However, this also means that you cannot create the same overview and alert I present in this article.

      When you have used either one of the above solutions, all you need to do is create a custom segment with the appropriate regular expressions in order to make the needed filtration (see http://www.onlinekonsulenten.dk/seo/monitor-your-seo-with-google-analytics/2/).

      With regards to the “cd=” as a rule of thumb you can think of it as the ranking number of the individual search result, however there are som “buts” to be aware of.

      For more in depth information about this, I would suggest that you read this blog post and its comments: http://www.seomoz.org/blog/tracking-organic-ranking-in-google-analytics-with-custom-variables

    • Now that I’ve had some more time to think about it, I believe there is actually a third option, which enables you to both use my SEO overview AND keep the landing page intact.

      This solution, however, requires you to use the code version instead of the filter version, since this enables you to call Google Analytics twice with two different URL’s.

      This is the code I have suggested above:

      /* Added SEO tracking code begin */

      if(document.referrer.length > 0){
      var regex = new RegExp("cd=([0-9]+)");
      var match = regex.exec(document.referrer);
      var rank = match[1];

      if (match) {
      _gaq.push(['_trackPageview', '/googleRank/' + rank + '.html']);
      }
      }

      /* Added SEO tracking code end */

      _gaq.push(['_trackPageview']);

      Instead of calling the virtual pageview first try to call it second:

      _gaq.push(['_trackPageview']);

      /* Added SEO tracking code begin */

      if(document.referrer.length > 0){
      var regex = new RegExp("cd=([0-9]+)");
      var match = regex.exec(document.referrer);
      var rank = match[1];

      if (match) {
      _gaq.push(['_trackPageview', '/googleRank/' + rank + '.html']);
      }
      }

      /* Added SEO tracking code end */

      This way you call the normal pageview tracking first and if there is “cd=” in the referrer string then the second virtual pageview is called.
      Be sure that if you use this method that you filter these virtual pageviews out of your standard analytics profile.

Skriv kommentar

Please insert the signs in the image: