The work of Google Ads specialists has not become any easier in recent years. Where you used to have a keyword, bid and ad text in order to be able to distinguish yourself, you now also have to take into account ad planning, target groups, devices, locations, demographics and advertising extensions (again 11 different types of extensions).

To ensure that your campaigns are optimally organized, you need a lot of time. Time that you may not have available for every customer. To make the most of the available time, you can therefore use Ads scripts and automate routine work.

On our blog we will publish some scripts in the coming period that can help every SEA specialist make her / his work a lot more fun.

Non-branded search queries in branded (shopping) campaigns

We are probably not the only ones who always organize our campaign structure for Google Shopping campaigns in branded and non-branded campaigns. The non-branded campaigns have a higher priority, but here you exclude branded keywords, so you can catch them with your brand campaign and increase bids.

Although in theory full-proof, in practice there is still a lot of non-branded traffic in your branded campaigns. This means that you must exclude these keywords from your campaign on a regular basis.

That can be easier! With the script below you can automatically exclude nonbranded search queries in your branded campaigns, so that the splitting of your traffic is optimal.

The script

This script is intended for advertisers where branded is only intended for their own brand name. This applies, for example, to producers, such as our customer Paula's Choice. Here we split all our Google Shopping traffic into search terms with and without the brand name 'Paula's Choice'. When you add the script to your account, make sure it runs every hour.

Do you have campaigns with many different brands? Then this script does not work. But do not worry, we have also built a solution for this, based on the product feed.

// Copyright 2019. Increase BV. All Rights Reserved.
// Created by: Tibbe van Asten
// for Increase B.V.
// Created: 14-06-2018
// Last update: 08-04-2019
// With this script you can exclude non-branded queries 
// from branded shopping campaigns. By doing this 
// every day, the accountstructure will remain clean.

var config = {
  	LOG : true,

  	// Branded search query. Make sure to use quotes.
  	// If you only use 2 branded keywords, remove variable + row in var report
  	// The mark for every branded campaign in the account
	B_SELECTOR : "[B]"					


function main() {
    var report =
      'SELECT CampaignName, AdGroupId, AdGroupName, Query ' +
      'WHERE CampaignStatus = ENABLED AND AdGroupStatus = ENABLED ' +
      'AND CampaignName CONTAINS_IGNORE_CASE "' + config.B_SELECTOR + '" ' +
      ' AND QueryTargetingStatus = NONE'

    var rows = report.rows();
    while (rows.hasNext()) {
      var row =;
      var query = trimQuery(row);

      var shoppingAdGroupIterator = AdsApp
        .withCondition("Id = '"+row["AdGroupId"]+"'")
      while (shoppingAdGroupIterator.hasNext()) {
        var shoppingAdGroup =;
        if(config.LOG === true){
          Logger.log(" ");       
      } // shoppingAdGroupIterator
      var adGroupIterator = AdsApp
        .withCondition("Id = '"+row["AdGroupId"]+"'")
      while (adGroupIterator.hasNext()) {
        var adGroup =;

        if(config.LOG === true){	
          Logger.log(" ");   
      } // adGroupIterator
    } // rowIterator  
    Logger.log("Thanks for using this custom script by Tibbe van Asten. Winning!");
} // function main()


function trimQuery(row){

  // When the searchquery exceeds the limit of 10 words, we will split
  // the query and put max. 10 words back together as a phrasematch query
  var query = "";
  if (row["Query"].split(" ").length < 10) {
    query = "[" + row["Query"] + "]";
  } else {
    for (var i = 0; (i < row["Query"].split(" ").length) && (i < 10); i++){
      query += row["Query"].split(" ")[i] + " ";
    query = '"' + query.replace(/\s+$/,'') + '"';

  return query;

} // function trimQuery()

Sharing Knowledge is all about sharing knowledge. In the current market, PPC specialists like to keep their knowledge and experience to themselves. We're convinced that sharing knowledge can ensure that everyone gets better at their work. We want to change this by sharing our knowledge about scripts with everyone.

Do you also want to contribute? We are open to new ideas and feedback on everything you find on

Contact us

Nils Rooijmans
Google Ads Scripter
Water Cooler Topics
Nils Rooijmans, Google Ads Scripter
Bas Baudoin
Teamleader PPC
Happy Leads
Bas Baudoin, Teamleader PPC
Martijn Kraan
Freelance PPC Specialist
Martijn Kraan, Freelance PPC Specialist
Tibbe van Asten
PPC Specialist
Founder Adsscripts
Tibbe van Asten, Senior PPC Automation Specialist