TIP

Google Ads script: Search Terms Must Match - try it out!

This script creates completely new possibilities for Google Ads account optimization and brings back the old keyword options "exact match" and phrase if you want. Not only for search campaigns but also for shopping campaigns, you can use this script to define keywords to which search queries must match.

Alert Monitoring Save costs Optimization Changes in Google Ads (optional) Read-only (if desired) Google Sheet is created Google Ads Editor (optional)
Sends an e-mail when something should be checked
The script monitors the Google Ads account (hourly or daily execution).
The script helps to avoid unnecessary or unwanted expenditure.
The script can improve the profitability (ROAS / CPA) of Google Ads accounts.
If desired, changes can be made directly in the Google Ads account.
If desired, no changes will be made in Google Ads, the Merchant Center or Google Analytics.
A spreadsheet file is created or edited in your Google Drive that only you have access to.
If desired, generated data can be used in the Google Ads Editor.

 Many possible applications

Making brand campaigns more profitable

  • Problem: Bids are usually high in brand campaigns because you want to be at the top. This pleases Google, and since virtually all keyword options are now more or less brad, more and more search queries are being displayed in brand campaigns that do not even contain the brand name.
  • Solution: The Search Terms Must Match script monitors the search queries and automatically adds negative keywords for search queries that do not match the defined keywords, if you want.

Standard Shopping campaigns for high-priced products

  • Problem: You only want to run Shopping ads if one of your product names appears in the search query. General search queries such as "red shoes" or "leather bag" will only eat up your budget.
  • Solution: Define a negative keyword list with brand names and use it as a "positive keyword list". If search queries in the shopping campaign do not match any of these keywords in the list, the script can automatically add negative keywords and/or notify you by email which search queries with more than x clicks should perhaps be excluded.

Route search queries to the right ad groups

  • Problem: The search queries match your products, but the ads or the landing page are often not ideal in the ad group selected by Google.
  • Solution: Define as paused (!!) keywords (example) in ad groups which words should appear in search queries. This script informs you about non-conforming search queries with more than x impressions.
    You can then exclude them, expand the whitelist or create new ad groups for these search queries.


Used correctly, this Google Ads script offers completely new possibilities for Google Ads optimization!

 Example alert email

Up to 100 search queries that did not match the defined filter keywords are listed in the email with important key figures. The complete list can be found in a Google Spreadsheet file.
The table can be copied directly from the email and pasted into the Google Ads Editor. This makes it quick and easy to manually determine which excluded keywords should be added.

Google Ads Script Search Terms Must Match Alarm Email

 Inform and/or automatically exclude

You can configure whether the script should only inform you if search queries with more than x impressions or clicks do not match the defined criteria or whether excluded keywords are added as exact match automatically.

 Get [Exact match] and "Phrase" back in the original behavior

If you simply want to try out the script before going into the setting options in more detail, we recommend the following procedure. This will give you back the original behavior of [exact match] and "prase". Let's assume you have these keywords in an ad group:

  • [adwords agency]
  • "google ads agency"
  • google ads optimization

Then the script will inform you about all search queries with at least 50 impressions and at least 3 clicks that would match if they were NEGATIVE keywords. If you change the script from "inform" to "automatically add negative keywords", you would have the old behavior of [exact match] and "word group" back. However, 'broad match' becomes much more restrictive than an active keyword normally is (just the way an excluding, broad matching keyword behaves).

 Example script configuration

Link to the demo configuration sheet for Search Terms Must Match.



 Quick start

If you simply want to try out the script, you can select the following settings for a Google Ads account of your choice. No changes will be made to the account, you will only receive an email if unsuitable search queries are found.

A) Check search terms in search campaigns

All active ad groups in all active search campaigns will be checked to see if the words appear in active and paused keywords in search queries. If not, the search query will be reported by email.

ParameterDescription
campaignNamesPattern*
addNegativeKeywordsFALSE
mustMatchActiveKeywordsTRUE
mustMatchPausedKeywordsTRUE
activeKeywordsConsiderAsCONTAINS
With the CONTAINS setting, the keyword 'red bag' matches the search queries 'red handbags' and 'bags red leather'.
searchTermsOfLastXdays28 for larger accounts, 365 for very small accounts
minMetrics_impressions50
minMetrics_clicks1 for small accounts, 10 for larger accounts

If you do not receive an email after an hour, reduce minMetrics_impressions and/or increase searchTermsOfLastXdays.
If the script reports an error that the execution was interrupted, please reduce searchTermsOfLastXdays and/or increase minMetrics_clicks.

B) Keyword options EXACT and PHARSE

You can also use the script to more or less achieve the keyword options EXACT and PHRASE via excluding keywords in the original, name-giving functionality.

ParameterDescription
campaignNamesPattern*
addNegativeKeywordsFALSE
TRUE if automatically negative keywords shall be added
mustMatchActiveKeywordsTRUE
mustMatchPausedKeywordsFALSE
TRUE if you want to allow variants such as plurals, misspellings etc. via paused keywords.
activeKeywordsConsiderAsAS_DEFINED
searchTermsOfLastXdays28 for larger accounts, 365 for very small accounts
minMetrics_impressions50
minMetrics_clicks1 for small accounts, 10 for larger accounts

C) Check search queries in a shopping ad group

These settings are used to check whether the search queries in a shopping campaign ad group match the keywords stored in the config sheet.

ParameterDescription
campaignNamesPatternthe name of your shopping campaign
adGroupNamesPatternthe name of the ad group in the shopping campaign
addNegativeKeywordsFALSE
mustMatchTheseKeywords_brand1_,_brand2_,_brand3_
Example:_gucci_,_louis_ _vuitton_,_prada_
searchTermsOfLastXdays28 for larger accounts, 365 for very small accounts
minMetrics_impressions50
minMetrics_clicks1 for small accounts, 10 for larger accounts

D) Check search queries in a campaign with a whitelist

We use a negative keyword list here as a POSITIVE keyword list. The list can contain product and brand names, for example. This allows us to check whether the ads in this campaign are being displayed for specific search terms or whether money has been burned with generic search queries.
You could also set addNegativeKeywords to TRUE here. Then search terms that have not yet triggered a conversion after 100 clicks are automatically excluded.

ParameterDescription
campaignNamesPatternName of the campaign to be checked (Search or Shopping)
addNegativeKeywordsFALSE
mustMatchNegativeKeywordListsName of the keyword list
searchTermsOfLastXdays28 for larger accounts, 365 for very small accounts
minMetrics_clicks100
lessMetrics_conversions0.001


 Tips on how to use

If this script reports search queries, you should perform one of the following three actions:

  1. The search query is generally uninteresting:
    => Add the search query – or parts of it – to a negative keyword list that applies to all campaigns. Alternatively, use the negative keyword list at account level.
  2. The search query is relevant, but the ad copy in this ad group is not ideal for it:
    => Optimize the ad copy in the ad group or create a new ad group with a suitable ad copy.
  3. The search query matches the ad group (false alarm):
    => Simply add a paused keyword to the ad group (see below for an explanation).
    Alternatively, you can of course also add an active keyword or add keywords in the mustMatchTheseKeywords column.

You will receive a relatively large number of false positives during the first few script executions. But by using keyword patterns with _ (see below for an explanation) and sensible specifications for minMetrics_clicks, you can quickly achieve a state, that you only receive emails if search queries with relevant traffic do not match.
It can also be useful to run the script only every Monday (add mo in column #days) so that you do not receive too many emails from this script.



 New keyword options + paused keywords as filters

>>> Paused keywords as "positive filter"

Google Ads script SearchTermsMustMatch positve keywords

Assuming you have defined these keywords in an ad group. You can now configure the script so that search queries are checked to see whether they match the active and/or paused keywords.
This means that only search queries will be allowed that contain vacation or holiday as well as tip or recommendation.

Option "contains" = with _ before and after the keyword

An underscore before and after a PAUSED keyword means that the text in between must appear anywhere in the search query.

_vacation_ _tip_ would therefore match the following search queries.

  • online vacation tips
  • onlinetipps for vacations

In this way, it does not matter whether "tip" is used in singular or plural form in the search queries, whether with one or two p's or whether tip occurs somewhere in the middle of a word. The same of course also applies to "vacation".

Option "starts with" = with _ after the keyword

_vacation_ tip_ (without _ before "tip") would therefore match the following search queries.

  • online vacation tips
  • onlinetipps for vacations
  • online tipps for vacations

Option "ends with" = with _ before the keyword

_vacation_ _tip (without _ after "tip") would therefore match the following search queries.

  • online vacation tips
  • online vacation tip
  • onlinetipps for vacations
  • onlinetip for vacations

Options broad match, phrase and exact match

These options work for paused keywords in the same way as they used to and still do for negative keywords.
However, there is a setting option for active keywords to pretend that all active keywords have the option "broad match" or "contains" (for all words of a keyword).

 Configuration in Google Ads and/or the config sheet

Unfortunately, you cannot define keywords for Shopping campaigns. However, you can specify the "filter keywords" either in the name of the ad group or in the config sheet.

Filter keywords in the name of the ad group with ASMmm:

Keywords in the name of the ad group

The Search Terms Must Match script searches for ad groups that contain "ASMmm:". You can define various things after the colon. In this example that would be:

  • @: Inform by e-mail about search queries with more than x impressions/clicks (defined in the config sheet) that do not match the filter keywords in {}.
  • +: Automatically add exact match keywords for search queries with more than x impressions/clicks that do not match the filter keywords.
  • {...}: Search queries must match these filter keywords. For example:
    "gucci handbags", "bags by gucci", "gucci purses" or "guccipocket"
    All search queries that do not contain the word "gucci" would be rejected. In addition, "bag" or "purse" or "pocket" must be anywhere in the search query too.
  • While it works well in search campaigns to direct Google to the right ad group for certain search queries with negative keywords, in our experience this should not be overdone in Shopping ads. We look forward to hearing about your experiences :-)

Define filter keywords in the config sheet

Alternatively, it is also possible to store a list of filter keywords in the config sheet (parameter mustMatchNegativeKeywordLists) and define which campaigns or ad groups these should apply to.

 Limit the number of search queries

It is important to select the settings so that the script runs within the 30-minute time limit set by Google. To do this, it may be necessary to split search queries. To do this, duplicate a configuration line and then restrict the search query report. For example:

  • Search queries with 1-5 clicks (minMetrics_clicks=1 und maxMetrics_clicks=5)
  • Search queries with 6-20 clicks (minMetrics_clicks=6 und maxMetrics_clicks=20)
  • Search queries with >20 clicks (minMetrics_clicks=21)

If the execution of a script takes too long (>30 minutes), a corresponding error message is displayed in the "completed" column.

 Configuration parameters

ParameterDescription
useASMmmNamePatternShould only campaigns or ad groups containing "ASMmm:" in the name be taken into account? The parameters campaignNamesPattern, campaignLabelNames, adGroupNamesPattern and adGroupLabelNames have priority over useASMmmNamePattern if they are defined.
campaignNamesPatternExample: *gucci*
Only campaigns with "gucci" somewhere in the name will be considered.
campaignLabelNamesOnly include campaigns that contain a label defined here.
adGroupNamesPatternAnalogue to campaignNamesPattern
adGroupLabelNamesAnalogue to campaignLabelNames
addNegativeKeywordsShould exactly matching, excluding keywords be inserted automatically if unsuitable search queries are found? As a rule, it makes more sense to set FALSE here and to add excluding keywords manually – if possible as a broad match.
notifyNegativeKeywordsWould you like to be informed by e-mail when unsuitable search queries are found?
FALSE only makes sense if you have selected addNegativeKeywords=TRUE.
mustMatchActiveKeywordsTRUE: Search campaigns check whether the search queries match one of the active keywords in the campaign.
activeKeywordsConsiderAs
AS_DEFINEDIf the keyword option is an exact match, the search queries must also be identical to the keyword.
If the keyword option is a group of words, the words in the keyword must appear in this order in the search query.
If the keyword option is broad match, all words in the keyword must appear in the search query.
BROADFor all active keywords, the defined keyword option is ignored and assumed to be broad match.
CONTAINSFor all active keywords, the defined keyword option is ignored and 'CONTAINS' is assumed.
'CONTAINS' differs from 'broad match' in that the words in the keyword can occur anywhere in the search query.
Example: The search query "socks" matches the keyword "sock" for 'CONTAINS', as the keyword 'sock' appears in the search query "socks".
With the keyword option "broad match", the search query "socks" would not match the keyword "sock" as they are different words.
Tip: 'CONTAINS' is usually a good choice.
mustMatchPausedKeywordsTRUE: Search queries are also checked against paused keywords.
Tipp: Use paused, broad match keywords such as '_bag_ _order_'. Then all search queries containing 'bag' and 'order' are valid. For example, "handbags onlineorder".
mustMatchNegativeKeywordListsYou can use a negative keyword list as a positive keyword list!
Example: Define a list of brand names. If one of these brand names appears in the search query, the search query is valid.
mustMatchTheseKeywordsFor search and shopping campaigns, you can define comma-separated keywords for which search queries are checked.
With entries in campaignLabelNames, adGroupNamesPattern and mustMatchTheseKeywords, you can easily define keywords for search and shopping campaigns at ad group level, against which search queries are checked and, if desired, unsuitable search queries are automatically excluded.
mustMatchThisFunctionOption for experts
addNegativeKeywordsToListIf addNegativeKeywords=TRUE. you can specify here that negative keywords are not added to the campaign or the ad group, but to the negative keyword list defined here.
searchTermsOfLastXdaysThe search queries of the last x days should be checked. For large accounts with a lot of traffic, a short period (e.g. 7 or 28 days) makes sense; for very small accounts, however, you can also choose a period of one or two years.
minMetrics_impressionsIt makes sense to define minMetrics_impressions and/or minMetrics_clicks so that you are only informed about search queries that actually occur more frequently or cause relevant costs.
maxMetrics_impressions
minMetrics_clicks
maxMetrics_clicks
greaterMetrics_ctrSearch queries in the search advertising network usually have a very low click-through rate. These can be easily filtered out with this parameter.
lessMetrics_conversionsFor example 0.001, so that no search queries are recognised as invalid that have contributed even minimally to a conversion.
#daysTip: Define mo here, for example, so that the script is only executed on Mondays and you receive the list of unsuitable search queries only once a week.

Parameters that apply to all scripts

 Download Google Ads script Search Terms Must Match

Please log in or register in the Ads Scripts Store first to download the script (why is this necessary?).

E-mail address
Password:

Do you have any questions?

I will gladly answer your questions
Google Ads Experte Holger Schulz
Holger Schulz

✉ holger.schulz@ads-scripts.com

linkedin.com/showcase/ads-scripts-store/