Location

Target a campaign for a country

function targetCampaignByCountry() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Target France (location id = 2250) and set a bid modifier of +50%. See
    // https://developers.google.com/adwords/api/docs/appendix/geotargeting
    // for details.
    campaign.addLocation(2250, 1.5);
  }
}

Get the list of locations targeted by a campaign

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

    while (locationIterator.hasNext()) {
      var targetedLocation = locationIterator.next();
      Logger.log('Location name: ' +
          targetedLocation.getName() + ', country code: ' +
          targetedLocation.getCountryCode() + ', bid modifier: ' +
          targetedLocation.getBidModifier());
    }
  }
}

Remove a targeted location from a campaign

function removeTargetedLocationById() {
  var campaignIterator = AdWordsApp.campaigns()
      .withCondition('Name = "INSERT_CAMPAIGN_NAME_HERE"')
      .get();
  if (campaignIterator.hasNext()) {
    var campaign = campaignIterator.next();
    // Remove targeting for France (location id = 2250). See
    // https://developers.google.com/adwords/api/docs/appendix/geotargeting
    // for details.
    var targetedLocationIterator = AdWordsApp.targeting()
        .targetedLocations()
        .withIds([[campaign.getId(), 2250]]).get();
    if (targetedLocationIterator.hasNext) {
      targetedLocationIterator.next().remove();
    }
  }
}

Send feedback about...

AdWords Scripts
AdWords Scripts
Need help? Visit our support page.