Excluded Locations
Stay organized with collections
Save and categorize content based on your preferences.
Add excluded locations for a campaign
function excludeTennessee(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();
// Exclude Tennessee, United States (location id = 21175) See
// https://developers.google.com/google-ads/api/reference/data/geotargets
// for list of all supported geo codes.
// You could pass either the location code, or a TargetedLocation or
// ExcludedLocation object from an existing campaign.
const tennesseeId = 21175;
campaign.excludeLocation(tennesseeId);
}
Get excluded locations for a campaign
function getExcludedLocations(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().excludedLocations().get();
}
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."],[[["This script demonstrates how to add or retrieve excluded locations for Google Ads campaigns using the Google Ads scripts."],["`excludeTennessee` function adds Tennessee as an excluded location for a specific campaign by its name."],["`getExcludedLocations` function retrieves and returns all excluded locations for a given campaign."],["Both functions utilize campaign iterators to locate the target campaign and leverage campaign targeting methods to manage excluded locations."]]],[]]