Negative Keyword Lists

Construct a new negative keyword list and add it to a campaign

function addNegativeKeywordListToCampaign() {
  var NEGATIVE_KEYWORD_LIST_NAME = 'INSERT_LIST_NAME_HERE';
  var CAMPAIGN_NAME = 'INSERT_CAMPAIGN_NAME_HERE';

  var negativeKeywordListOperator =
      AdWordsApp.newNegativeKeywordListBuilder()
          .withName(NEGATIVE_KEYWORD_LIST_NAME)
          .build();

  if (negativeKeywordListOperator.isSuccessful()) {
    var negativeKeywordList = negativeKeywordListOperation.getResult();
    negativeKeywordList.addKeywords(
        'broad match keyword',
        '"phrase match keyword"',
        '[exact match keyword]'
    );

    var campaign = AdWordsApp.campaigns()
        .withCondition('Name = "' + CAMPAIGN_NAME + '"')
        .get();
    campaign.addNegativeKeywordList(negativeKeywordList);
  } else {
    Logger.log('Could not add Negative Keyword List.');
  }
}

Remove all the shared negative keywords in an negative keyword list

function removeAllNegativeKeywordsFromList() {
  var NEGATIVE_KEYWORD_LIST_NAME = 'INSERT_LIST_NAME_HERE';

  var negativeKeywordListIterator =
      AdWordsApp.negativeKeywordLists()
          .withCondition('Name = "' + NEGATIVE_KEYWORD_LIST_NAME + '"')
          .get();

  if (negativeKeywordListIterator.totalNumEntities() == 1) {
    var negativeKeywordList = negativeKeywordListIterator.next();
    var sharedNegativeKeywordIterator =
        negativeKeywordList.negativeKeywords().get();

    var sharedNegativeKeywords = [];

    while (sharedNegativeKeywordIterator.hasNext()) {
      sharedNegativeKeywords.push(sharedNegativeKeywordIterator.next());
    }

    for (var i = 0; i < sharedNegativeKeywords.length(); i++) {
      sharedNegativeKeywords[i].remove();
    }
  }
}

发送以下问题的反馈:

此网页
AdWords Scripts
AdWords Scripts
需要帮助?请访问我们的支持页面