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 2025-08-20 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 2025-08-20 UTC."],[[["\u003cp\u003eThese Google Ads scripts demonstrate how to target, retrieve, and remove location targeting for campaigns, specifically using France as an example with location ID 2250.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003etargetFrance\u003c/code\u003e applies a location target (France) and a bid modifier of +50% to a specified campaign.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetTargetedLocations\u003c/code\u003e returns a list of all locations targeted by a given campaign.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003euntargetFrance\u003c/code\u003e removes the location target for France from a specified campaign.\u003c/p\u003e\n"]]],[],null,["# Location\n\nTarget a campaign for a country\n-------------------------------\n\n```gdscript\nfunction targetFrance(campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name \"${campaignName}\" found`);\n }\n\n const campaign = campaignIterator.next();\n // Target France (location id = 2250) and set a bid modifier of +50%. See\n // https://developers.google.com/google-ads/api/reference/data/geotargets\n // for details.\n campaign.addLocation(2250, 1.5);\n}\n```\n\nGet the list of locations targeted by a campaign\n------------------------------------------------\n\n```gdscript\nfunction getTargetedLocations(campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name \"${campaignName}\" found`);\n }\n\n const campaign = campaignIterator.next();\n return campaign.targeting().targetedLocations().get();\n}\n```\n\nRemove a targeted location from a campaign\n------------------------------------------\n\n```gdscript\nfunction untargetFrance(campaignName) {\n const campaignIterator = AdsApp.campaigns()\n .withCondition(`campaign.name = \"${campaignName}\"`)\n .get();\n if (!campaignIterator.hasNext()) {\n throw new Error(`No campaign with name \"${campaignName}\" found`);\n }\n\n const campaign = campaignIterator.next();\n // Remove targeting for France (location id = 2250). See\n // https://developers.google.com/google-ads/api/reference/data/geotargets\n // for details.\n const targetedLocationIterator = AdsApp.targeting()\n .targetedLocations()\n .withIds([[campaign.getId(), 2250]]).get();\n if (targetedLocationIterator.hasNext()) {\n targetedLocationIterator.next().remove();\n }\n}\n```"]]