Friday, March 1, 2013

Track Keyword Ranking using Google Analytics

In the past I’ve written about different ways to customize Google Analytics for SEO. This post is all about a new way to track keyword ranking using Google Analytics.
A little background…
There are lots of paid tools that will track where your content ranks in your search results. But my friend AJ Kohn wanted to try and develop a free way to measure rank with Google Analytics.
Actually, he had a brilliant idea: measuring the individual keyword rank, group keywords together into indexes and then track the average rank of those indexes over time – all with Google Analytics.

Add caption
Here’s how AJ describes a rank index:
A rank index is the aggregate rank of a basket of keywords that represent a type of query class that have an impact on your bottom line. For an eCommerce client you might have a rank index for products and for categories. I often create a rank index for each modifier class I identify for a client.
It becomes not about any one term but the aggregate rank of that index. That’s a better conversation to have in my opinion. A rank index keeps the conversation on how to move the business forward instead of moving a specific keyword up.
After a little brainstorming and testing we think we have a method to do this and would love your feedback.

How This Works

Here’s the general idea:
1. Someone clicks on an organic search results
2. The user lands on your site
3. A custom piece of code that you install on your site collects the keyword and the rank of the result using a Google Analytics event
4. Google Analytics will automatically calculate the average position for the result
5. You create indexes of keywords and analyze the data using the Event reports OR Excel and the GA API
That’s it. Nothing more.
Let’s dig into some of the details of how this work.

The Code

The code is relatively simple. All it does is looks at the referring URL and, if it’s from Google Organic, plucks out the location of the search result and sends it to Google Analytics using an Event.
Here’s the code – feel free to copy it and use it. You do not need to customize the code for your site.

This section of the code parses out the keyword and the search result location. The search result location is stored in a query string parameters named cd.

var myString = document.referrer;
var r = myString.match(/cd=(.*?)&/);
var rank = parseInt(r[1]);
var kw = myString.match(/q=(.*?)&/);
Next there is a check to see if the keyword is (not provided). If it is (not provided) then we make sure that we track the keyword as (not provided).

if (kw[1].length > 0) {
var keyWord = decodeURI(kw[1]);
} else {
keyWord = "(not provided)";
Finally we send the data to Google Analytics using an event:
_gaq.push(['_trackEvent', 'RankTracker', keyWord, p, rank, true]);
For those of you that have not used events, there are 5 parts to an event:
  • Category: This helps you categorize the events and separate them in the reports.
  • Action: What happened that you want to track?
  • Label: Provides more information about the Action.
  • Value: Some numerical value for this event.
  • Noninteractive: This is a flag, it tells Google Analytics if this event should impact bounce rate and time calculations. If you have no idea what this means read about how Google Analytics calculates time.
For this tracking technique we’re sending the following data with the event:
  • Category: RankTracker – all of the data will be grouped under the Event named RankTracker.
  • Action: [keyword] – the action will collect the search term the user entered on Google.
  • Label: [landing page] – the label will be the landing page that the user landed on.
  • Value: [SERP rank] – rank of the search result will be collected for each keyword. More on this in a second.
  • Noninteractive: TRUE – this event will NOT change your bounce rate calculations.
The most important thing to understand is that the rank of the search engine result will be tracked as the value of the event. So as you get more and more visits from a keyword the TOTAL VALUE of the event for that keyword will increase.
Google Analytics will also create an Average Value metric for each keyword event. This value will actually represent the Average Rank for each search result.
Let me say that again.
Using this technique Google Analytics will automatically calculate the average position of your content in the search results.
I also want to point out that this data is generated from real clicks to your site. It’s actual people visiting your site and (hopefully) converting. To me, this makes it a lot more valuable than just tracking ranking that does not result in clicks or conversions.
So that’s how this technique actually works. As I mentioned, all you need to get the data is install the code on your site. Just make sure it appears AFTER the standard Google Analytics page tag.

Raw Ranking data in Google Analytics

Ok, let’s look at some data. It’s all event data, so let’s go to the Content > Events > Top Events report. I’m looking for the RankTracker event category.
Rank tracking data in Google Analytics.
You can find rank tracking data in the Google Analytics Event report.
Clicking on RankTracker I see all the actions for that event, which are really just the search terms.
The search terms and ranking are stored as Google Analytics Events.
The search terms and ranking are stored as Google Analytics Events.
Here’s the cool thing. Remember that the Average Value metric is actually the Average Position for each of those keywords. So for the time range that I’m looking at I’m seeing the average position for each keyword.
Let’s play with this.
Change the data over time graph to plot the metrics Average value. Now you can see the average ranking for all your search terms over time.
Plot your average search result rank.
Change the plotted metric to see your average search result rank change over time.
You can also select multiple rows and plot the Average Value to see how the ranking changes for specific keywords over time.
Plot the keyword rank of multiple keywords.
You can view the changing rank of your keywords by plotting multiple rows.
Another cool type of analysis you can do is use a secondary dimension to view the landing page for each keyword. The landing page is stored in the Label portion of the event. This is something a lot of people do to measure (not provided)
Keyword, landing page and Average SEO rank.
View keyword, landing page and Average SEO rank in Google Analytics.
Now we have keyword, landing page and the average ranking in one report.
We can also group keywords together into an index. The easiest way to do this in Google Analytics is using an Advanced segment. Again, a lot of credit to AJ for explaining how he does this.
For something simple like my blog I can create a segment based on my name and the Analytics Talk brand. That makes it easy to view the performance of that group of keywords.
Advanced segment for a keyword index.
Create an Google Analytics Advanced Segment to group keywords together into an index.
While I can do analysis within Google Analytics, the real value is exporting this data to excel and producing more detailed report. AJ covers that nicely in his post. I’ll post some other methods next week.


The entire reason you should collect this data is to measure how your actual content-creation tactics are working. It’s granular data that helps support your overall strategy of “content marketing.”
If you’re not getting valuable traffic from content and keywords that you are optimizing for then you need to re-evaluate your tactics and change.

Caveats & Things to Remember

First, this data is only for traffic coming to your site. It does not give you the ranking for search terms if you are not getting traffic.
As mentioned above I actually like this approach. If I’m not getting traffic/conversions then my ranking sucks. I need to create better content.
Second, Google blocks the referring keyword data for secure search queries. This includes logged in users, people using Safari on iOS 6 and Firefox. There are no analytics tools in existence that will provide the blocked keywords. In Google Analytics you’ll see the keyword (not provided) in your data. You’ll also see (not provided) in this data.
So there you have it. We (me and AJ) hope that this techniques helps people track rank freely and more effectively. Feel free to innovate and develop on top of it and let us know what you think.
Like this post? Share it:

1 comment:

  1. Hello
    THis god information about the Google Analytic algorithmic is for the good post ?

    Google SEO