Branded Shopping Campaigns Script 

 Last Updated June 12, 2024

By Zaid Ammari

When To Use This Script?

Use this script to help branded SHOPPING campaigns attract only branded traffic and decrease the chances of having non-brand search queries show ads.

This script will:

Identify non-brand keywords attracting traffic to your specified campaigns (in this case, they should be branded campaigns) and then add those non-branded keywords are negatives to a pre determined negative keyword list of your choosing.

This script will only run correctly if you have a branded shopping campaign running with the words SHOPPING and BRAND in the campaign name. This is how the script identifies which campaign it should be running on.

Important notes:

This script won't add a duplicate keyword to a negative keyword list, so adding keywords that might already be in the list won't cause any issues.

Customize the script before adding it to your account:

Remember, to change:

  1. YOUR_NEGATIVE_KEYWORD_LIST_NAME - This should be the exact name of the negative keyword list you want to add the non-branded negative keywords to.
  2. brandname - This should be your brand name all in one word (without spaces). For example: brandname
  3. brand name - This should be your brand name with spaces.
    For example: brand name

Branded Shopping Campaign Script

function main() {

var negativeKeywordListIterator = AdsApp.negativeKeywordLists()

.withCondition("Name = 'YOUR_NEGATIVE_KEYWORD_LIST_NAME'")

.get();

if (!negativeKeywordListIterator.hasNext()) {

Logger.log("No negative keyword list found with the specified name.");

return;

}

var negativeKeywordList = negativeKeywordListIterator.next();

var campaignIterator = AdsApp.shoppingCampaigns()

.withCondition("Name CONTAINS_IGNORE_CASE 'shopping'")

.withCondition("Name DOES_NOT_CONTAIN_IGNORE_CASE 'brand'")

.get();

var negativeKeywordsToAdd = [];

while (campaignIterator.hasNext()) {

var campaign = campaignIterator.next();

var report = AdsApp.report(

"SELECT Query " +

"FROM SEARCH_QUERY_PERFORMANCE_REPORT " +

"WHERE CampaignId = " + campaign.getId() +

" AND Query DOES_NOT_CONTAIN_IGNORE_CASE 'brandname' " +

" AND Query DOES_NOT_CONTAIN_IGNORE_CASE 'brand name'"

);

var rows = report.rows();

while (rows.hasNext()) {

var row = rows.next();

var query = row['Query'];

negativeKeywordsToAdd.push(query);

}

}

// Add the keywords to the negative keyword list

for (var i = 0; i < negativeKeywordsToAdd.length; i++) {

negativeKeywordList.addNegativeKeyword(negativeKeywordsToAdd[i]);

}

}


Zaid Ammari Headshot

About the author 

Zaid is a leading expert on data driven digital marketing; focusing on analytics and actionable insights from data. Founder of PPC Masterminds - he helps businesses build & run profitable data driven digital campaigns.

Get High Quality PPC Campaigns
That Actually Work!