ID
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ほとんどの Google 広告エンティティは、ID を返す getId()
メソッドを公開しています。ほとんどの場合、厳密に必要なわけではありませんが、次のような場合に身分証明書が役立ちます。
- レポートの操作
- ID を使用すると、レポートの行を実際の Google 広告エンティティにリンクできます。
- 外部データ ストアとのマッピングを維持する場合
- ID ベースの情報がすでに独自のデータベースに保存されている場合があります。
- パフォーマンスの向上を求める場合
通常、ID によるデータの取得は他の方法よりも高速です。単一のエンティティを取得するコードも少し簡単になります。
let campaigns = AdsApp.campaigns()
.withIds([678678])
.get();
// vs.
let campaigns = AdsApp.campaigns()
.withCondition("Name='My Campaign'")
.get();
一意性
キャンペーン ID と広告グループ ID は一意です。2 つのキャンペーンまたは広告グループが同じ ID を共有することはありません。ただし、広告とキーワードには複合 ID があります。キーワードの一意の識別子は、広告グループ ID とキーワード ID の組み合わせです。同様に、広告の一意の識別子は、広告グループ ID と広告 ID の組み合わせです。これは、selector.withIds()
の呼び出し方法に影響します。
キャンペーンと広告グループの場合、selector.withIds()
には数値の配列を指定します。
let ids = [123123, 234234, 345345];
let campaignSelector = AdsApp.campaigns().withIds(ids);
ただし、広告とキーワードの場合は、selector.withIds()
に 2 要素の配列の配列が必要です。最初の要素は広告グループ ID です。次のスニペットは、広告グループから 3 つのキーワードを取得します。
let adGroupId = 123123;
let keywordSelector = AdsApp.keywords().withIds([
[adGroupId, 234234],
[adGroupId, 345345],
[adGroupId, 456456]
]);
広告の取得時にも同じコンストラクトが適用されます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-06-04 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-06-04 UTC。"],[[["Most Google Ads entities have a `getId()` method, which returns a unique identifier that can be useful for linking data, improving performance, and referencing external databases."],["When working with reports, IDs can connect report rows to specific Google Ads entities."],["Fetching entities by ID is often faster than using other methods like filtering by name."],["Campaign and ad group IDs are unique, while ad and keyword IDs are composite, requiring both the ad group ID and their individual ID for unique identification."],["The `selector.withIds()` method is used to fetch entities by ID, taking an array of numbers for campaigns and ad groups and an array of two-element arrays (ad group ID and entity ID) for ads and keywords."]]],[]]