Page Summary
-
Learn how to target a specific country for a campaign using its location ID and set a bid modifier.
-
Discover how to retrieve a list of all locations currently targeted by a given campaign.
-
Understand the process for removing a previously targeted location from a campaign using its location ID.
Target a campaign for a country
function targetFrance(campaignName) { const campaignIterator = AdsApp.campaigns() .withCondition(`campaign.name = "${campaignName}"`) .get(); if (!campaignIterator.hasNext()) { throw new Error(`No campaign with name "${campaignName}" found`); } const campaign = campaignIterator.next(); // Target France (location id = 2250) and set a bid modifier of +50%. See // https://developers.google.com/google-ads/api/reference/data/geotargets // for details. campaign.addLocation(2250, 1.5); }
Get the list of locations targeted by a campaign
function getTargetedLocations(campaignName) { const campaignIterator = AdsApp.campaigns() .withCondition(`campaign.name = "${campaignName}"`) .get(); if (!campaignIterator.hasNext()) { throw new Error(`No campaign with name "${campaignName}" found`); } const campaign = campaignIterator.next(); return campaign.targeting().targetedLocations().get(); }
Remove a targeted location from a campaign
function untargetFrance(campaignName) { const campaignIterator = AdsApp.campaigns() .withCondition(`campaign.name = "${campaignName}"`) .get(); if (!campaignIterator.hasNext()) { throw new Error(`No campaign with name "${campaignName}" found