Use this Google Ads script for keyword optimization and an in-depth look at your search term reports.
Search query analysis is a regular task that you should be completing for any search campaign that you have in your Google Ads account. Depending on the volume of traffic that you have coming through your campaign, this could be a task that you do once a month, every other week, once a week, or maybe even a couple different days a week.
The easiest way to review your search terms is to look at them in the report in the Google Ads interface. You may find some new keywords and new negative terms there as well. However, doing any analysis beyond the basic reviews within that report is a little tough, and usually requires the implementation of a Google Ads script. In this article, I want to walk you through one of my favorite ways to review search query performance for long-term analysis: n-grams.
N-grams are a type of analysis you can have Google Ads output for you via a script. If you’ve never used Google Ads scripts before, don’t worry! We’re going step-by-step using a free copy-and-paste script.
Since an n-gram is a type of search term report analysis beyond what’s available in the Google Ads interface (more on this next), it requires a script. Before we get into the n-gram analysis for your search terms reports, let’s first take a step back to review the concept of Google Ads scripts.
Google Ads scripts are custom bits of code you can input into the platform to conduct specific functions beyond the norm. For example, a common use case for Google Ads scripts is automatically pausing underperforming assets. In this instance, you could input a script that tells Google Ads to automatically pause ads or keywords that don’t hit a certain metric threshold. For larger accounts, scripts can be a game changer since they save you from having to take the time to manually execute repetitive tasks. In our case today, Google Ads scripts can also come in handy for more in-depth reports, like the n-gram analysis.
You don’t have to be a coding wizard (or have any coding experience at all, for that matter) to take advantage of Google Ads scripts. Google Ads provides a few script templates within the platform. Additionally, there are plenty of free, copy-and-paste scripts you can find online (which is where our n-gram script is from today). Another idea is that you could even use an AI tool to draft scripts to try for you.
🚨 Could your Google Ads account benefit from using more scripts? Find out, and get more ideas to optimize, using our free Google Ads Grader!
Let’s start with a definition. N-grams refer to an analysis that is done based on the individual word within a certain search query. Rather than looking at the entire query on its own, an n-gram allows you to break the query down by the individual words and understand how those words are performing in your Google Ads account.
Let’s take a super easy example. In this account below, we’re trying to sell worker’s compensation insurance policies to local businesses. There are quite a few different ways folks will search to find this type of insurance. A few of the search queries are listed above. Each of these can be a highly valuable term for us, but with n-grams, we can better understand how each term performs.
Here we have the data broken down by each term in the report. Without this view, it might not be immediately apparent that queries with the term “comp” have a higher CPA than the terms with “compensation.” This is the type of insight we want to gain. So let’s jump into the process of running an n-gram.
🔍 Looking for more ways to perfect your keyword lists? Try our Free Keyword Tool to get a custom list of keyword ideas complete with competition and cost data.
From the outside, it might seem like this type of analysis takes a lot of technical know-how, but it really doesn’t. Well, at least it doesn’t for you and me. While you have to use a Google Ads script, you don’t have to come up with the code for it on your own. Luckily, one of my friends has already created the script that runs the n-gram, so he’s the only one who needed a lot of technical skills so you and I can do the analysis. Thanks, Nils!
There are a couple of things we’ll need to set up before the script can run in your account. First, visit this page and copy all of the script text from Nil’s website.
In the Google Ads interface, navigate to the bulk actions section and click on scripts.
Click the blue plus button then add a new script. Then in the main function window paste the text from the website.
Next, we need to tell Google where to send our data. Go to your Google Drive homepage, create a new spreadsheet, and copy the URL for your new spreadsheet from the URL bar.
Then head back into the script manager and scroll down to the point where you see the spreadsheet URL here prompt and paste in the URL of the sheet you just created.
Now we need to choose the settings for our analysis. First, you’ll need to choose a date range that you want to look back at the search queries for. In my experience, an n-gram analysis is done over a longer period of time, likely a month, a quarter, six months, or a year depending on the volume you’ve had through your account.
You can use other settings within the script code to include only certain campaigns, exclude certain campaigns, or include or exclude paused or enabled campaigns and ad groups. Most of these are pretty self-explanatory and you can likely figure them out. Just make sure you don’t change any of the surrounding punctuation marks as that might break the script.
The last thing we need to do in the settings section is to decide how many words we want to include in our n-gram analysis. For the example I have earlier, we did an n-gram of one. That means that we looked at how individual words performed across all search queries. But we can look at longer strings as well.
By default, you can see the minimum is one and the max is two. That means that only single or two-word phrases will be included in this report. I like to change this number to four so that I will find single words, two-word phrases, three-word phrases, and four-word phrases for my account. This is just a personal preference. You can adjust to whatever you want.
Once you have those finished, you’ll be prompted twice to authorize the scripts to run. Then, you can have the script run and wait for your results.
You will now have a number of new tabs in your Google spreadsheet. There will be a series of three tabs for each level of n-gram you decide to run. There will be a campaign, ad group, and account level for each. So for my example, I ended up having 12 tabs added to my spreadsheet. A campaign, ad group, and account level tab with n-grams of one to four.
In the image below, you can see what the report looks like. It has the n-gram itself along with stats on cost, clicks, impressions, conversions, cost per conversion, as well as a few others. Now that this data is in a spreadsheet, we can play with it to get a better understanding of how these words or phrases performed.
Here are a handful of ideas for filters that you can use on your n-gram reports:
Honestly, you can use any type of filter that you would use for your regular search terms report review. Rather than being limited to the queries as they show up in the interface, now you can understand how different word phrases perform in your account.
A more specific example I have came directly from a client question. While they do accept phone calls, they prefer for users to fill out the form on the site for easier intake. So their question was, “How often do people search for phone numbers and do they convert better or worse than other terms?” To the n-grams we go!
This report makes it very simple. I can go to the account single word and tab, filter for phone. Easy peasy.
But taking this one step further, I can then go to the two-word tab and review “phone number” as well as any other instance where the word “phone” is included. I can then compare how those perform to our original phrase in question. The findings from this quick review will end up dictating whether we start bidding on phone call terms and accepting phone calls conversion, or if we retain a lead form primary conversion action in the account.
As I mentioned earlier, there are also tabs for campaign or ad group-level n-grams as well. While my example above is looking at the account level, I could review the phone queries by campaign and see if brand versus non-brand or a certain campaign performed better than others when it came to phone numbers. Again, this is a pretty limited example, but you can start to see how understanding the way certain terms perform in your account can be valuable, especially if you review them at the account, campaign, and ad group levels to create much more targeted negative keywords.
The beauty of n-Gram analysis is it can tell you the shorter phrases that either do or don’t perform well in your account so that you can add them either as a keyword or a negative. That’s why I always go up to four in my analysis. I found that the one and two-word n-grams typically are great resources to find new negative keywords and the three and four-word n-grams tend to help me find new keywords to target as either exact or phase match.
Overall, n-grams are an excellent tool to help you in your search campaign optimization in a much more precise way.
I’ll leave you with some suggestions to keep in mind when you’re using this particular script.
First, the date range is static. This is likely not a script you’ll set to run on a regular frequency. Instead, each time you want to run an analysis you’ll need to go in and update the date range manually for the time frame you want to analyze.
Always reset your filters when you’re finished analyzing the data in your analysis. The script is designed to overwrite the data on the tab within the spreadsheet. But I found that if I left my filters on then the data doesn’t populate fully on that page. All you have to do is remove the filters and you should be good to go.
That’s it. Hopefully, this run-through gives you a good idea of what an n-gram analysis is, how you can run it, and what you can do with the outcome in your account. And, to Nils, thanks again for writing the script and making it free for all to use. If you enjoy this script, I highly suggest you visit his site and go through all of the other scripts he has available.
If you feel ready to take your keyword performance to the next level, see how our solutions can help you maximize your search campaigns and make the most out of the queries you show for.
To recap, here are the steps to create an n-gram script for your Google Ads search terms reports: