Excluded Locations

Add excluded locations for a campaign

function excludeLocationTarget() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Exclude Tennessee, United States (location id = 21175) See
    // https://developers.google.com/adwords/api/docs/appendix/geotargeting
    // for list of all supported geo codes.
    // You could pass either the location code, or a TargetedLocation or
    // ExcludedLocation object from an existing campaign.
    var tennessee_id = 21175;
    campaign.excludeLocation(tennessee_id);
  }
}

Get excluded locations for a campaign

function getExcludedLocations() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    var locationIterator = campaign.targeting().excludedLocations().get();

    while (locationIterator.hasNext()) {
      var excludedLocation = locationIterator.next();
      Logger.log('Location id: ' + excludedLocation.getId().toFixed(0) +
          ', Name: ' + excludedLocation.getName() + ', Country code: ' +
          excludedLocation.getCountryCode());
    }
  }
}

发送以下问题的反馈:

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