< Back to Blog

How to Use a Google Ads N-Gram Script to Find Hidden Keyword Winners (and Losers)

Learn how a Google Ads n-gram script breaks your search terms into individual words and phrases so you can cut wasted spend, find new keywords, and optimize campaigns faster.

If you run Google Ads campaigns with more than a handful of keywords, you know the pain. Your search terms report is an endless list of long queries, each with barely enough data to tell you anything. But hidden inside all those queries are patterns - patterns that can save you money or help you spend it better.

That is where n-gram analysis comes in. It takes every search query and breaks it into its individual words and short phrases. Then it adds up the performance data across thousands of queries so you can finally see which words bring in conversions and which ones waste your budget.

This post covers what n-grams are, why they matter for paid search, how to set up a free Google Ads n-gram script, and what to do with the results.

What Is an N-Gram?

An n-gram is just a sequence of words pulled from a longer piece of text. The "n" is how many words are in the sequence.

  • 1-gram = one word (like "certification")
  • 2-gram = two words (like "online certification")
  • 3-gram = three words (like "coaching certification online")

In Google Ads, n-gram analysis takes your search terms and breaks them into these smaller pieces. Instead of looking at each full query on its own, you look at the individual words and short phrases that appear across many queries.

Here is a simple example. Say three search queries triggered your ads:

Search Query Clicks Conversions
life coach certification online 12 2
best online coaching certification 8 1
coaching certification programs near me 15 0

On their own, none of those queries gives you a clear signal. But n-gram analysis would show you that the word "certification" appeared in all three queries and racked up 35 clicks and 3 conversions. Meanwhile, the word "near" only showed up in the query with zero conversions. That is the kind of insight you can act on immediately.

For paid search, the most useful n-gram sizes are:

  • 1-grams and 2-grams: Great for finding negative keyword candidates (words that waste money)
  • 3-grams and 4-grams: Great for finding high-intent phrases worth adding as exact or phrase match keywords

Why the Search Terms Report Is Not Enough

The built-in search terms report in Google Ads is a starting point, but it has real limitations when you need to optimize at scale:

  • Too many one-off queries. Most search terms only show up once or twice. There is not enough data on any single query to make a confident decision.
  • Hidden spending patterns. A word like "free" or "salary" might be scattered across hundreds of different queries, quietly eating your budget. You would never spot it just scrolling through the report.
  • Performance Max blind spots. PMAX campaigns show you very limited search term data. N-gram analysis helps you squeeze more insight out of the little data you get.
  • Scale problems. Accounts with thousands of search terms make manual review impossible. N-grams compress all that noise into a clean, sortable dataset.

An n-gram script fixes these problems by adding up metrics - clicks, impressions, cost, conversions, conversion value - at the word and phrase level. That gives you enough data to actually make decisions.

How the Script Works

The most popular n-gram script in the PPC community was originally built by Brainlabs (Daniel Gilbert) and has been kept up to date by contributors like Nils Rooijmans. It is free, open source, and runs inside the Google Ads Scripts editor - no coding skills required.

Here is what the script does in plain terms:

  1. Pulls your search query data from Google Ads for a date range you choose.
  2. Breaks each query into pieces - 1-grams, 2-grams, 3-grams, and 4-grams.
  3. Adds up the numbers for each word or phrase across every query where it appears.
  4. Writes the results to a Google Sheet with separate tabs for each n-gram size.
  5. Optionally checks your existing negatives so already-blocked queries do not clutter the results.

The output gives you columns for impressions, clicks, CTR, cost, conversions, conversion value, CPC, CPA, and ROAS for every n-gram. You can sort and filter immediately.

Setting It Up in 5 Steps

Step 1: Create a Google Sheet

Open Google Sheets and create a new blank spreadsheet. Copy the URL - the script needs it to know where to write the data.

Step 2: Open Google Ads Scripts

In your Google Ads account, go to Tools > Bulk Actions > Scripts. Click the blue plus button to create a new script.

Step 3: Paste the Script

Copy the Brainlabs/Nils Rooijmans n-gram script code (linked in the Resources section below) and paste it into the script editor. Replace the placeholder URL with your Google Sheet URL from Step 1.

Step 4: Adjust the Settings

At the top of the script, there are a few settings you can change:

  • Date range: Set your start and end dates. Use at least 90 days of data for reliable results. Shorter windows can give you misleading numbers, especially in low-volume accounts.
  • Campaign filters: Use the campaign name filters to include or exclude specific campaigns. Handy for separating branded from non-branded search.
  • N-gram range: Set the minimum and maximum n-gram length. 1 to 4 covers most use cases.
  • Paused entities: Choose whether to include or skip paused campaigns and ad groups.
  • Check negatives: If turned on, the script skips queries you have already blocked. Turn it off if the script takes too long on a large account.

Step 5: Run It

Click Authorize, grant the permissions, then click Run. It may take a few minutes depending on your account size. When it finishes, your Google Sheet will have tabs for each n-gram size, ready to explore.

What to Do With the Data

Having the spreadsheet is step one. Here is how to turn it into account improvements.

Find Words That Waste Money

Sort your 1-gram tab by cost (highest first) and filter for conversions = 0. These are words that have spent real money across multiple queries without a single conversion. Words like "free," "salary," "jobs," or "reddit" are common culprits. Add them as negative phrase match keywords at the campaign or account level.

Spot High-CPA Words

Filter for n-grams with conversions but a CPA way above your target. These are not necessarily negatives - they are signals that you might need to lower bids, rewrite your ad copy to better match the intent, or build a dedicated ad group with a more relevant landing page.

Find New Keywords to Add

Check the 3-gram and 4-gram tabs, sorted by conversions or ROAS. High-performing multi-word phrases are strong candidates to add as exact or phrase match keywords in their own ad groups. That gives you direct control over bidding for terms that already convert.

Audit Broad Match

If you use broad match keywords, n-gram analysis is one of the best ways to check what Google is actually matching you to. You can quickly spot when broad match pulls in irrelevant traffic and add negatives to tighten things up.

Improve Ad Copy

Your best-performing 2-grams and 3-grams often reveal the exact language your customers use. Working those phrases into your headlines and descriptions can improve Quality Score and ad relevance.

Mistakes to Avoid

  • Too little data. Two weeks of data can lead you to the wrong conclusions, especially in low-volume accounts. Stick to 90 days or more.
  • Being too aggressive with negatives. A 1-gram with zero conversions might still be part of a 2-gram or 3-gram that converts well. Always cross-check with longer n-grams before blocking a word.
  • Getting tripped up by fractional conversions. If you use data-driven attribution, some n-grams may show tiny conversion numbers like 0.01. That can make the CPA look insane even though almost no money was spent. Filter for at least 1 or 2 conversions to keep the analysis useful.
  • Running it once and forgetting. Search behavior changes. Run the analysis at least every quarter - monthly for larger accounts - to keep your negatives current and catch new trends.

Going Further

The free script handles most situations, but there are ways to get even more out of it:

  • BigQuery. For large accounts, export search term data to BigQuery and use the ML.NGRAMS function. This gives you more flexibility with big datasets and lets you join n-gram data with CRM or revenue data for true ROI analysis.
  • Automated scheduling. You can set the script to run on a weekly schedule. Modify the date variables to use rolling dates instead of fixed ones and it stays current without manual updates.
  • Other platforms. The same n-gram approach works for Microsoft Ads, Amazon PPC, and even organic search data from Google Search Console. Once you learn the method, it applies everywhere.

Resources

  • Brainlabs N-Gram Script (updated by Nils Rooijmans): Search for the Search Query Mining script at nilsrooijmans.com. This is the most current version compatible with the latest Google Ads script environment.
  • Google Ads Scripts documentation: The official reference at developers.google.com/google-ads/scripts for anyone who wants to dig into how scripts work.

The Bottom Line

Your search terms report has more to tell you than it shows on the surface. The Google Ads n-gram script is one of the most useful free tools available to PPC managers. It turns a noisy, fragmented report into clean data you can actually act on. You do not need to know how to code. You just need a Google Sheet, five minutes of setup, and a willingness to let the numbers guide your decisions.

If you are still scrolling through search terms one query at a time, you are working harder than you need to. Run the script. Sort by cost. Find your budget leaks. Then move that spend to where it actually converts.