Richard Harvey
unread,Apr 3, 2023, 9:07:44 AM4/3/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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++;
}
}
}}