Negative Keywords

Add negative keyword to a campaign

function addNegativeKeywordToCampaign() {
  var campaignIterator = AdWordsApp.campaigns()
        .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
        .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    campaign.createNegativeKeyword('[Budget hotels]');
  }
}

Get negative keywords in a campaign

function getNegativeKeywordForCampaign() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var negativeKeywordIterator = campaign.negativeKeywords().get();
    while (negativeKeywordIterator.hasNext()) {
      var negativeKeyword = negativeKeywordIterator.next();
      Logger.log('Text: ' + negativeKeyword.getText() + ', MatchType: ' +
          negativeKeyword.getMatchType());
    }
  }
}

Add a negative keyword to an ad group

function addNegativeKeywordToAdGroup() {
  // If you have multiple ad groups with the same name, this snippet will
  // pick an arbitrary matching ad group each time. In such cases, just
  // filter on the campaign name as well:
  //
  // AdWordsApp.adGroups()
  //     .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
  //     .withCondition('CampaignName = "INSERT_CAMPAIGN_NAME_HERE"')
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    adGroup.createNegativeKeyword('[Budget hotels]');
  }
}

Get negative keywords in an ad group

function getNegativeKeywordForAdGroup() {
  // If you have multiple ad groups with the same name, this snippet will
  // pick an arbitrary matching ad group each time. In such cases, just
  // filter on the campaign name as well:
  //
  // AdWordsApp.adGroups()
  //     .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
  //     .withCondition('CampaignName = "INSERT_CAMPAIGN_NAME_HERE"')
  var adGroupIterator = AdWordsApp.adGroups()
      .withCondition('Name = "INSERT_ADGROUP_NAME_HERE"')
      .get();
  if (adGroupIterator.hasNext()) {
    var adGroup = adGroupIterator.next();
    var negativeKeywordIterator = adGroup.negativeKeywords().get();
    while (negativeKeywordIterator.hasNext()) {
      var negativeKeyword = negativeKeywordIterator.next();
      Logger.log('Text: ' + negativeKeyword.getText() + ', MatchType: ' +
          negativeKeyword.getMatchType());
    }
  }
}

发送以下问题的反馈:

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