已排除地區
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
為廣告活動新增排除地區
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);
}
為廣告活動擷取排除地區
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();
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\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```"]]