Adding Negative Keywords to Negative Keyword List (negativeKeywordList.createNegativeKeyword)

208 views
Skip to first unread message

Richard Harvey

unread,
Apr 3, 2023, 9:07:44 AM4/3/23
to Google Ads Scripts Forum
I've got a script almost working, to identify any search terms beginning with 'free', and add them to the negatives list. 
I've provided the script, and commented each section, as below..... 


The problem is with the section "//Iterate through the search terms array and add to the negs list" 
This is the error that I'm getting: "TypeError: negativeKeywordList.createNegativeKeyword is not a function" 

Please can somebody help with the last bit?





function main() {

 
//Make report of search terms ------------------------------
var report = AdsApp.report(
   "SELECT Query" +
   " FROM SEARCH_QUERY_PERFORMANCE_REPORT " +
   " WHERE Impressions > 10" +
   " DURING LAST_7_DAYS");
var rows = report.rows();

 
//Make empty array to hold new negatives ------------------------------
  var newNegslist =[];

 
//Iterate through search term report rows, check if starts with free, push into array ------------------------------
  while(rows.hasNext()) {
  var row = rows.next();
let searchTerm = (row['Query'])
if (searchTerm.startsWith("free")) {
newNegslist.push(searchTerm)
  }
}
 
  Logger.log('Search terms starting with FREE: \n' + newNegslist)
 
 
//If there are new negs to add, find the negs list ------------------------------
if (newNegslist.length > 0) {
   
  var negativeKeywordListSelector = AdsApp.negativeKeywordLists()
   .withCondition("Name CONTAINS 'Starting_With_Free_Script'");
 
var negativeKeywordListIterator = negativeKeywordListSelector.get();

while (negativeKeywordListIterator.hasNext()) {
  var negativeKeywordList = negativeKeywordListIterator.next();
 
Logger.log('Working in the negatives list')  

 
//Iterate through the search terms array and add to the negs list ------------------------------
  let i = 0; while (i < newNegslist.length) {
    Logger.log('adding neg: ' + newNegslist[i]);
   
   negativeKeywordList.createNegativeKeyword( "["+ newNegslist[i] +"]" );
    i++;
   
}
 
}
}}

Google Ads Scripts Forum

unread,
Apr 5, 2023, 3:41:37 AM4/5/23
to Google Ads Scripts Forum
Reposting the last inquiry (https://groups.google.com/g/adwords-scripts/c/6z2oyjIYDAM) from the forum as it wasn't routed to our support queue.

Regards,
Google Ads Scripts Team

Google Ads Scripts Forum

unread,
Apr 5, 2023, 5:52:46 AM4/5/23
to Google Ads Scripts Forum
Hi,

Thank you for reaching out to the Google Ads Scripts Team. Please excuse us for only getting back now as your message failed to be routed to our support queue.

As per our documentation on AdsApp.​NegativeKeywordList, since you've used the selector and iterator which accesses negative keyword lists, I'm afraid the method createNegativeKeyword could not be used with said entity. You can, however, use the method addNegativeKeyword() which adds a negative keyword to the list. For more context according to the documentation on the method, Match type for the new shared negative keyword is specified as follows:
  • negativeKeywordList.addNegativeKeyword("shoes") - broad match.
  • negativeKeywordList.addNegativeKeyword("\"shoes\"") - phrase match.
  • negativeKeywordList.addNegativeKeyword("[leather shoes]") - exact match.

Let us know if you'd need further assistance or have any clarifications.

Best regards,
Google Ads Scripts Team
Reply all
Reply to author
Forward
0 new messages