สถานที่ตั้งที่ยกเว้น
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เพิ่มสถานที่ตั้งที่ยกเว้นสำหรับแคมเปญ
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();
}
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 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```"]]