Località escluse
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Aggiungi le località escluse di una campagna
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);
}
Ottieni le località escluse di una campagna
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();
}
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-21 UTC.
[null,null,["Ultimo aggiornamento 2025-08-21 UTC."],[[["\u003cp\u003eThis script demonstrates how to add or retrieve excluded locations for Google Ads campaigns using the Google Ads scripts.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eexcludeTennessee\u003c/code\u003e function adds Tennessee as an excluded location for a specific campaign by its name.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetExcludedLocations\u003c/code\u003e function retrieves and returns all excluded locations for a given campaign.\u003c/p\u003e\n"],["\u003cp\u003eBoth functions utilize campaign iterators to locate the target campaign and leverage campaign targeting methods to manage excluded locations.\u003c/p\u003e\n"]]],[],null,["# Excluded Locations\n\nAdd excluded locations for a campaign\n-------------------------------------\n\n```gdscript\nfunction excludeTennessee(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 // Exclude Tennessee, United States (location id = 21175) See\n // https://developers.google.com/google-ads/api/reference/data/geotargets\n // for list of all supported geo codes.\n // You could pass either the location code, or a TargetedLocation or\n // ExcludedLocation object from an existing campaign.\n const tennesseeId = 21175;\n campaign.excludeLocation(tennesseeId);\n}\n```\n\nGet excluded locations for a campaign\n-------------------------------------\n\n```gdscript\nfunction getExcludedLocations(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().excludedLocations().get();\n}\n```"]]