Location
Stay organized with collections
Save and categorize content based on your preferences.
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`);
}
const campaign = campaignIterator.next();
// Remove targeting for France (location id = 2250). See
// https://developers.google.com/google-ads/api/reference/data/geotargets
// for details.
const targetedLocationIterator = AdsApp.targeting()
.targetedLocations()
.withIds([[campaign.getId(), 2250]]).get();
if (targetedLocationIterator.hasNext()) {
targetedLocationIterator.next().remove();
}
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-03-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-03-14 UTC."],[[["These Google Ads scripts demonstrate how to target, retrieve, and remove location targeting for campaigns, specifically using France as an example with location ID 2250."],["`targetFrance` applies a location target (France) and a bid modifier of +50% to a specified campaign."],["`getTargetedLocations` returns a list of all locations targeted by a given campaign."],["`untargetFrance` removes the location target for France from a specified campaign."]]],[]]