Exclude Nonbrand in Shopping (1 Brand)

When you split Shopping campaigns on branded and non-branded search terms, you often still get non-branded search terms in your branded Shopping campaign (s). This script automatically excludes these terms.

Start Now!
Exclude Nonbrand in Shopping (1 Brand)
Exclude Get started!

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.

The script
// Copyright 2022
// Free to use or alter for everyone. A mention would be nice ;-)
//
// Created by: Tibbe van Asten
//
// Created: 14-06-2018
// Last update: 16-10-2022
// 
// ABOUT THE SCRIPT
// 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
    BRANDED_KEYWORDS_1 : "",		
    BRANDED_KEYWORDS_2 : "",
    BRANDED_KEYWORDS_3 : "",
  
    // The mark for every branded campaign in the account
    B_SELECTOR : "[B]"					
 
}

////////////////////////////////////////////////////////////////////

function main() {
  
    var report = AdsApp.report(
      "SELECT campaign.name, ad_group.id, ad_group.name, search_term_view.search_term " +
      "FROM search_term_view " +
      "WHERE campaign.status = 'ENABLED' AND ad_group.status = 'ENABLED' " +
      "AND campaign.name REGEXP_MATCH '(?i)(.*)?"+config.B_SELECTOR+"(.*)?' " +
      "AND search_term_view.search_term NOT REGEXP_MATCH '(?i)(.*)?"+config.BRANDED_KEYWORDS_1+"(.*)?' " +
      "AND search_term_view.search_term NOT REGEXP_MATCH '(?i)(.*)?"+config.BRANDED_KEYWORDS_2+"(.*)?' " +
      "AND search_term_view.search_term NOT REGEXP_MATCH '(?i)(.*)?"+config.BRANDED_KEYWORDS_3+"(.*)?' " +
      "AND search_term_view.status = 'NONE'"
    );    

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

      var shoppingAdGroupIterator = AdsApp
        .shoppingAdGroups()
        .withCondition("Id = '"+row["ad_group.id"]+"'")
        .get();
      
      while (shoppingAdGroupIterator.hasNext()) {
        var shoppingAdGroup = shoppingAdGroupIterator.next();
        shoppingAdGroup.createNegativeKeyword(query);
        
        if(config.LOG === true){
          Logger.log(row["campaign.name"]);
          Logger.log(row["ad_group.name"]);
          Logger.log(query);
          Logger.log(" ");       
        }
      } // shoppingAdGroupIterator
      
      var adGroupIterator = AdsApp
        .adGroups()
        .withCondition("Id = '"+row["ad_group.id"]+"'")
        .get();
      
      while (adGroupIterator.hasNext()) {
        var adGroup = adGroupIterator.next();
        adGroup.createNegativeKeyword(query);

        if(config.LOG === true){	
          Logger.log(row["campaign.name"]);
          Logger.log(row["ad_group.name"]);
          Logger.log(query);
          Logger.log(" ");   
        }
      } // adGroupIterator
      
    } // rowIterator  
  
    Logger.log("Thanks for using this custom script by Tibbe van Asten!");
  
} // 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["search_term_view.search_term"].split(" ").length < 10) {
    query = "[" + row["search_term_view.search_term"] + "]";
  } else {
    for (var i = 0; (i < row["search_term_view.search_term"].split(" ").length) && (i < 10); i++){
      query += row["search_term_view.search_term"].split(" ")[i] + " ";
    }
    query = '"' + query.replace(/\s+$/,'') + '"';
  }

  return query;

} // function trimQuery()
Show whole script!
Loading Comments
The Experts
Tibbe van Asten Team Lead Performance Marketing
Nils Rooijmans Water Cooler Topics
Martijn Kraan Freelance PPC Specialist
Bas Baudoin Teamlead SEA @ Happy Leads
Jermaya Leijen Digital Marketing Strategist
Krzysztof Bycina PPC Specialist from Poland
How about you? JOIN US!
Sharing Knowledge
Caring

Adsscripts.com 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 Adsscripts.com.

Contact us

Training &
Workshop
Contact us!
Adsscripts Training & Workshop