How to Track Organic Keyword Rankings with Google Analytics
By Jacob
Rankings. They’re what every SEO is after, and they can be hard to get. It’s theorized that everyone sees a different set of search results. To that end, wouldn’t it be nice to see what sort of terms drove traffic and what their position was when the searcher clicked?
Google Analytics, with a small bit of hacking around, can show you this data. Interested? Read on.
1. Create a New Website Profile
Rather than adding filters to your main Analytics profile, which can alter the data you see, we’re going to add a second profile. Log into Analytics, and click into one of your accounts. Next to the website and UA number, you’ll see a link to add a new profile on the right. Click on it
On the next screen select Add a Profile for an existing domain, which links your current analytics tracking to the new profile. Select your domain from the drop-down box. Next you will need to name the new profile. With that done we can move on the real meat: actually getting the keyword and position data.
2. Filtering Organic Traffic
For this (and the next two steps), we’ll be adding custom filters to your newly created analytics profile. Back on the main screen for your analytics account, you should see links to edit each profile on the right. Click on one and scroll down until you see the Filters Assigned to Profile box towards the bottom.
Click on “+ Add a Filter” and let’s get started.
On the new filter page you’ll see a myriad of options, most of them cryptic and confusing. To start with, we’ll be adding a new filter to the profile. Since this is the first filter (of three) name it “Google Ranking 1″ or something similar.
Under filter type, select “custom filter” and then select “include” from the next set of radio buttons. For filter field, select campaign medium, and in the filter pattern input type organic. Select No for case sensitive.
Your options should look like the screen capture below.
3. Filter Google Traffic
Next up we need to create another filter to capture only organic traffic from Google. In short, do the same thing as step two, but our filter filed will be campaign source and filter pattern will be Google. I’m using the name Google Ranking 2 for this profile. The names don’t matter, but the filters have to be a particular order so be sure to keep track of things.
Check out the image below for the whole story.
4. Actually Get the Data
With the first two filters out of the way, it’s time to actually find the keyword and ranking data. We’ll do this with another filter. Add a new filter, this time, instead of include, we’ll select “advanced”, which adds a bunch of extra fields to the screen.
Filters work by matching the contents of a given input (like Campaign Source or Medium) against a regular expression (regex) pattern. An advanced filter lets you extract data from two different fields (Field A and B) and ouput that data to something like a user defined variable which can be viewed later.
To start, we’ll set field A to campaign term, and enter the regular expression (.*) in the input. That reads like this: from campaign term extract everything. A dot in regex is any character and a * means 0 or more repetitions. So our little (.*) means extract as many repetitions of any character as you can find. Parenthesis are used for grouping (more on this later).
For field B we’re going to use Referral and extract (\?|&)cd=([^&]*). That bit of regular expression is a bit more complex, so let’s break it down. The first portion (\?|&) says match either a question mark OR an ampersand. Because the question mark is a special character in regex, we escape it with a backslash to make it literal. The next bit cd= just looks for the literal string, cd=. The final section ([^&]*) says select any character that is not an ampersand. Square brackets are ranges: [a-z] would match any lowercase character from a to z. When a carat (^) immediately follows the square bracket it changes the meaning to be the opposite — [^a-z] would match any character that isn’t a lower case a through z. So [^&] means anything but an ampersand. Our old friend * here means the same thing as it did above, 0 or more repetitions.
What we’re doing in this field is taking our referrer url, and looking for the URL parameter cd and its value.
Next up we need to send our captured data somewhere. For the next line “Output To” we’ll select User Defined. The constructor input is where it gets a little confusing. Regular expressions have something called back references. So if your match contains something like cp=([^&]*), you could reference the group in parenthesis with \1. The constructor field is is somewhat similar. Except the “back references” here take form of A (or B) followed by a number and preceded by a dollar sign: $A1. This would read, “from field A grab the first group.” Groups, as mentioned above, are defined by parenthesis. Our constructor will contain $A1 (Position: $B2).
Set both field A and B to required and set “Override Output Field” to yes. Case sensitive should be a no. The image below shows all the settings.
5. Adjusting Filter Order
As you might have guessed by the names of the filters above, they have to go in a certain order. Head back to the edit screen for your account profile and scroll down to the filters section. Click on Assign Filter Order. Adjust your filters so they appear in the correct order (1, 2, 3) if they aren’t already.
That’s it, you’re done!
Viewing Your Data
Visit the dashboard of the Analytics profile with the ranking filters. In the visitors section, there’s a place for “User Defined”. Click there and you should see a report with keywords followed by position indications.
The Good, The Bad, and the (not set)
When you visit google.com and conduct a search, and click on a result, Google runs your click through a redirect that looks something like google.com/somestuff?cd=6. The url parameter cd contains your position. Unfortunately this doesn’t happen with searches from the Firefox or Chrome search box or address bar. (not set) is the result.
Enjoy your ranking data!
Posted on August 30, 2011 in Google Analytics.














