ショッピング キャンペーン

ショッピング キャンペーンの管理の一部には、Google 広告スクリプトを使用できます。スクリプトを使用すると、既存のショッピング キャンペーンの操作、商品グループ階層の作成と管理、ショッピング レポートの作成を行うことができます。ただし、スクリプトを使用してショッピング キャンペーンの作成、ショッピング プロパティをキャンペーン単位(キャンペーンの優先順位、商品フィルタなど)で設定すること、Merchant Center アカウントをリンクすることはできません。

ショッピング キャンペーンと広告グループの取得

ショッピング キャンペーンは、AdsApp オブジェクトの shoppingCampaigns コレクションを通じて利用できます。これらは通常どおり、スクリプトを使用して取得できます。

const campaignName = "My first shopping campaign";

const campaignIterator = AdsApp.shoppingCampaigns()
    .withCondition(`campaign.name = "${campaignName}"`)
    .get();

for (const campaign of campaignIterator) {
  ...
}

キャンペーンを取得したら、同様の方法でその広告グループを取得できます。この方法は、キャンペーンとその広告グループの両方を管理する必要がある場合にのみ推奨されます。

const adGroupIterator = campaign.adGroups()
    .withCondition(`ad_group.name = "${adGroupName}"`)
    .get();

for (const adGroup of adGroupIterator) {
    ...
}

特定の広告グループのみを対象とする場合は、AdsApp.shoppingAdGroups() メソッドを使用して、最初にキャンペーンを取得せずに広告グループを取得できます。

const adGroupIterator = AdsApp.shoppingAdGroups()
    .withCondition(`campaign.name = "${campaignName}"`)
    .withCondition(`ad_group.name = "${adGroupName}"`)
    .get();

for (const adGroup of adGroupIterator) {
    ...
}

商品広告

Google 広告スクリプトでは、ShoppingAdGroupads() メソッドを使用して商品広告取得できます。新しい商品広告を作成するには、ShoppingAdGroupnewAdBuilder() メソッドを使用します。

商品グループ階層を反復処理

商品グループ階層のルートにアクセスするには、ShoppingAdGrouprootProductGroup メソッドを使用します。その後、children メソッドを使用して、子商品グループを反復処理し、商品グループ階層を走査できます。各ノードは ProductGroup オブジェクトであり、getDimension メソッドを使用すると、商品グループの実際のタイプを特定できます。対応するキャスト方法(asBrand など)を使用して、より具体的な型(ProductBrand など)にキャストすることもできます。次のコード スニペットは、商品グループ階層を再帰的に走査する方法を示しています。

walkTree(shoppingAdGroup.rootProductGroup(), 1);

function walkTree(root, level) {
  // Logger.log(root.getDimension());
  let description = "";
  switch (root.getDimension()) {
    case "ROOT":
      description = "Root";
      break;

    case "CATEGORY":
      description = root.asCategory().getName();
      break;

    case "BRAND":
      description = root.asBrand().getName();
      break;

    // Handle more types here.
    ...
  }

  if (root.isOtherCase()) {
    description = "Other";
  }

  const padding = new Array(level + 1).join('-');
  console.log("%s, %s, %s, %s, %s, %s",
             padding,
             description,
             root.getDimension(),
             root.getMaxCpc(),
             root.isOtherCase(),
             root.getId().toFixed());
  const children = root.children().get();
  for (const child of children) {
    walkTree(child, level + 1);
  }
}

特定の商品グループを選択する

AdsAppShoppingCampaignShoppingAdGroup のいずれかのインスタンスの productGroups メソッドを使用して、商品グループ階層内の特定の商品グループを選択できます。この方法は、入札単価管理のために特定の商品グループを選択するときに、商品グループ階層全体を走査するよりも簡単です。次のコード スニペットは、先月のクリック数が 5 回を上回り、クリック率が 0.01 を上回った商品グループをすべて選択し、入札単価を 0.01 だけ引き上げる方法を示しています。

function main() {
  const productGroups = AdsApp.productGroups()
      .withCondition("metrics.clicks > 5")
      .withCondition("metrics.ctr > 0.01")
      .forDateRange("LAST_MONTH")
      .get();
  for (const productGroup of productGroups) {
    productGroup.setMaxCpc(productGroup.getMaxCpc() + 0.01);
  }
}

商品グループの階層を更新する

既存の商品グループに子商品グループを追加するには、newChild メソッドを使用します。これにより、ProductGroupBuilderSpace オブジェクトが作成されます。このオブジェクトを使用して、適切な商品グループを作成できます。次のコード スニペットでは、ルートの下に「cardcow」ブランドの下位区分を追加した後、新品と再生品向けにさらに細分化しています。

const root = shoppingAdGroup.rootProductGroup();

// Add a brand product group for a "cardcow" under root.
const brandProductGroup = root.newChild()
    .brandBuilder()
    .withName("cardcow")
    .withBid(1.2)
    .build()
    .getResult();

// Add new conditions for New and Refurbished cardcow brand items.
const newItems = brandProductGroup.newChild()
    .conditionBuilder()
    .withCondition("New")
    .withBid(1.5)
    .build()
    .getResult();

// Refurbished items will use the bid from "cardcow" product group.
const refurbishedItems = brandProductGroup.newChild()
    .conditionBuilder()
    .withCondition("Refurbished")
    .build()
    .getResult();

同様に、ProductGroupremove メソッドを使用して下位区分を削除できます。これにより、削除する商品グループの下にある商品グループ階層全体も削除されます。

スクリプトを使用すると、各商品グループの作成後も商品グループ階層が一貫した状態を維持できます。商品グループの階層構造を更新する際に、「その他」に対応する商品グループを作成または削除する必要はありません。

「Everything else」商品グループ

ショッピングの商品グループ階層の各レベルには、商品グループ階層で作成したカスタム条件に一致しない商品を処理するために、「その他」の商品グループが含まれています。isOtherCase メソッドを使用すると、追加した通常の商品グループと「その他」の商品グループを区別できます。

次のコード スニペットは、ルート商品グループ階層の「その他」商品グループを取得し、その入札単価を出力します。

const root = shoppingAdGroup.rootProductGroup();

const childProductGroups = root.children().get();
let everythingElseProductGroupFound = false;

for (const childProductGroup of childProductGroups) {
  if (childProductGroup.isOtherCase()) {
    console.log("'Everything else' product group found. Type of the " +
               "product group is %s and bid is %s.",
               childProductGroup.getDimension(),
               childProductGroup.getMaxCpc());
    everythingElseProductGroupFound = true;
    break;
  }
}
if (!everythingElseProductGroupFound) {
  console.log("No 'Everything else' product group found under root " +
             "product group.");
}

リーフ商品グループを分割すると、スクリプトは「その他」の商品グループを自動的に作成し、商品グループ階層を有効なままにします。「その他」の商品グループは、親商品グループの入札単価を継承します。

新しいショッピング広告グループを作成する

Google 広告スクリプトでは、ShoppingCampaignnewAdGroupBuilder メソッドを使って新しいショッピング広告グループを作成できます。ShoppingAdGroup を作成したら、その createRootProductGroup メソッドを使用して新しい商品グループ階層を作成できます。

レポート

Google 広告スクリプトでは、ショッピング キャンペーンのパフォーマンスのトラッキングに役立つ product_group_view レポートと shopping_performance_view レポートがサポートされています。レポートの詳細については、レポートガイドをご覧ください。