位置情報
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
国内のターゲット キャンペーン
function targetFrance(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();
// Target France (location id = 2250) and set a bid modifier of +50%. See
// https://developers.google.com/google-ads/api/reference/data/geotargets
// for details.
campaign.addLocation(2250, 1.5);
}
キャンペーンのターゲット地域のリストを取得
function getTargetedLocations(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().targetedLocations().get();
}
キャンペーンからターゲット地域を削除
function untargetFrance(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();
// Remove targeting for France (location id = 2250). See
// https://developers.google.com/google-ads/api/reference/data/geotargets
// for details.
const targetedLocationIterator = AdsApp.targeting()
.targetedLocations()
.withIds([[campaign.getId(), 2250]]).get();
if (targetedLocationIterator.hasNext()) {
targetedLocationIterator.next().remove();
}
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-21 UTC。
[null,null,["最終更新日 2025-08-21 UTC。"],[[["\u003cp\u003eThese Google Ads scripts demonstrate how to target, retrieve, and remove location targeting for campaigns, specifically using France as an example with location ID 2250.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003etargetFrance\u003c/code\u003e applies a location target (France) and a bid modifier of +50% to a specified campaign.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egetTargetedLocations\u003c/code\u003e returns a list of all locations targeted by a given campaign.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003euntargetFrance\u003c/code\u003e removes the location target for France from a specified campaign.\u003c/p\u003e\n"]]],[],null,["# Location\n\nTarget a campaign for a country\n-------------------------------\n\n```gdscript\nfunction targetFrance(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 // Target France (location id = 2250) and set a bid modifier of +50%. See\n // https://developers.google.com/google-ads/api/reference/data/geotargets\n // for details.\n campaign.addLocation(2250, 1.5);\n}\n```\n\nGet the list of locations targeted by a campaign\n------------------------------------------------\n\n```gdscript\nfunction getTargetedLocations(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().targetedLocations().get();\n}\n```\n\nRemove a targeted location from a campaign\n------------------------------------------\n\n```gdscript\nfunction untargetFrance(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 // Remove targeting for France (location id = 2250). See\n // https://developers.google.com/google-ads/api/reference/data/geotargets\n // for details.\n const targetedLocationIterator = AdsApp.targeting()\n .targetedLocations()\n .withIds([[campaign.getId(), 2250]]).get();\n if (targetedLocationIterator.hasNext()) {\n targetedLocationIterator.next().remove();\n }\n}\n```"]]