除外した地域
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
キャンペーンの除外地域を追加
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```"]]