Calculating Click Through Rates for SEO, based on Google Search Console Data (in R)
Updated June 4, 2019: Added a YouTube video which will guide you through the setup process in RStudio and how to run the script yourself.
Averages lie & average click-through rates aren’t very helpful! Here I said it. What I do believe in, is that you can calculate click-through rates (CTR) for your own site in a great way though. With data from Google Search Console. Especially while using R, so let’s dive in on how this works and what you can do with it!
Why ‘Averages’ Lie?
Look at the graph below, a great CTR for position 1. But for example, this research shows that the average CTR for position 1 is: 24% (AWR data, Feb 2019). Which one is correct? Neither of them. As it really depends on the industry, what features show up in the search results that might decrease CTR (think rich snippets like local packs, news results). All of this is making it really hard to make a good analysis of what you could expect if you rank higher for a bunch of keywords in your industry. So while I was working at Postmates on ranking certain category pages better we decided to calculate our own CTR and were intrigued by how far CTRs were off from research (the research isn’t wrong! It’s just generalized across industries). Eventually, with the data in hand, we were able to make better estimates/forecasting of how much traffic we could expect when rankings would increase in that segment. In the rest of this post, I’ll go more in-depth on the specific practice on how we calculated this.
Using Google Search Console Data
You’ve seen this report in Google Search Console, providing you with a detailed view of the performance of your keywords and the average position for your keywords. In this graph, we see something positive, a CTR & position that go up slightly over time. But what if you would want to know the average CTR for a certain segment of keywords per position. That’s way harder to do in the interface. Because of that, I used the R script from Mark Edmondson that he wrote about here almost three years ago.
It will help you extract the data from Google Search Console in a raw way so you can use it to digest it and create your own visualizations (like the one we’ll talk about next).
Visualizing CTR Curves in R
So let’s dive right into how you can do this yourself, I’ll provide you with the full R script and you will need to download RStudio yourself in step 1.
- Download and Install RStudio
- Download the following .r script from Gist
- Run these commands to install the right packages for RStudio:
- install.packages(“ggplot2”) if necessary
- Line #21 – Change this to the property name from Google Search Console
- Line #25 – Not neccesary: If you want the CTR curve for positions over 20, change the number.
- Line #40 – Recommended: Exclude the word(s) that are part of your brand name. So you get the right CTR curve for non-branded keywords only
- Line #41 – Not necessary: This script is taking a ‘sample’ of 50.000 keywords to calculate your CTR curve of. You can increase this limit to more if needed, if you have less than 50.000 keywords it’s not an issue
- Run the script! The output should be a visual as shown earlier in this post
Want to take a deep breath and let me help you go over this again? I’ve made a quick screen share video of what to do in RStudio and how to use the R script.
Hopefully, now, you’ve had a better chance to understand what the actual CTR is for your own site and you can use this to visualize CTR curves for specific parts of your site or pages that have a similar META description. Over time you could use this, for example, for measuring the impact on CTR.
Credits where credits are due! There are many use cases for using CTR data by visualizing it with R, and I’m grateful that a while ago Mark Edmondson opened my eyes about this + credits to Tim Wilson’s documentation on using R and improving visualizations.
Want to read this article in Spanish? Read it here.
April 24, 2019 - 9:22 am
Step 3 “Run these commands to install the right packages for RStudio:”
Is that in Terminal or RStudio?
April 24, 2019 - 8:42 pm
You will run this in RStudio, it’s an R package :). You can easily do that through their interface.
April 25, 2019 - 9:26 pm
Hi! Thanks for sharing this!
I’m a bit of a newb with R programming. Wondering if you can help point me in the right direction.
I went through all your steps, but I am getting:
Error: object ‘hh’ not found
Error in ggplot(click_curve, aes(positionRound, CTRmean)) :
object ‘click_curve’ not found
Any idea how i can address this? Thanks so much!
April 26, 2019 - 8:17 am
Nicely written article and I have used the script and it works well. I have created a curve for Non branded and now I want to create a curve for a set of generic keywords. Do you know how to do this as it looks like I can’t put an OR in the dimensionFilterExp.
May 14, 2019 - 10:49 pm
Good question Iwan, what you could do is gather all the data and then run a filter on the keywords that you want to include. It’s a bit more complicated though as you’re basically changing the dataset that you want to include. If it’s something that you can do with a regular expression (I assume not), then I would do it within the dimensionFilterExp.
April 29, 2019 - 4:53 pm
Great! Hope to see more post about SEO, R and analysis. Thanks
May 22, 2019 - 5:30 pm
Really cool article, I am new to RStudio. Once I ran the script I get:
 “Domain Name” Just redacted my client domain here
Any thoughts on what I fudged up?
June 18, 2019 - 8:45 pm
Hi Martin –
This is a very useful projection!
When I run the CTR plot, I get the error:
Removed 2 rows containing missing values (geom_point).
Any thoughts on what is causing this?
July 5, 2019 - 11:16 am
How to i exclude keywords in the line ?
dimensionFilterExp = c(“query!~share”)
August 20, 2019 - 1:30 am
It’s easy Jeroen, just do: c(“query!~share”, “query!~yourquery”). It’s not unlimited but you can add quite a few.
July 16, 2020 - 4:25 pm
very nice. I began to understand a little about the data exposed on search engines