Google 広告スクリプトを使用すると、ショッピング キャンペーンをある程度管理できます。スクリプトを使用して、既存のショッピング キャンペーンを操作したり、商品グループの階層を作成して管理したり、ショッピング レポートを実行したりできます。ただし、スクリプトを使用してショッピング キャンペーンを作成したり、キャンペーン単位でショッピング プロパティ(キャンペーンの優先順位、在庫フィルタなど)を設定したり、Merchant Center アカウントをリンクしたりすることはできません。
ショッピング キャンペーンと広告グループを取得する
ショッピング キャンペーンは、shoppingCampaigns コレクション
から取得できます。AdsApp通常どおり、スクリプトを使用して取得できます。
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 広告スクリプトを使用すると、取得できます。商品広告は、ads()
メソッドを使用してShoppingAdGroup。ShoppingAdGroup の newAdBuilder() メソッドを使用して、新しい商品広告を作成できます。
商品グループの階層を反復処理する
ShoppingAdGroup の
rootProductGroup メソッドを使用して、商品グループの階層のルートにアクセスできます。次に、
子商品グループを反復処理し、
商品グループの階層をたどるには、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);
}
}
特定の商品グループを選択する
AdsApp、ShoppingCampaign、または
ShoppingAdGroup インスタンスの
productGroups メソッドを使用して、商品グループの階層で特定の商品グループを選択できます。入札単価管理の目的で特定の商品グループを選択する場合、この方法の方が商品グループの階層全体をたどるよりも簡単です。次のコード
スニペットは、過去 1 か月間にクリック数が 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();
同様に、remove メソッドを使用して
ProductGroup、サブディビジョンを削除できます。これにより、削除される商品グループの下にある商品グループの階層全体も削除されます。
スクリプトは、各商品グループの作成後に商品グループの階層が一貫した状態になるようにします。そのため、商品グループの階層構造を更新する際に、「その他すべて」に対応する商品グループを作成または削除する必要はありません。
「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 広告スクリプトを使用すると、
newAdGroupBuilder メソッドを使用して、新しいショッピング広告グループを作成できます。ShoppingCampaign
ShoppingAdGroupを作成したら、そのcreateRootProductGroup
メソッドを使用して、新しい商品グループの階層を作成できます。
レポート
Google 広告スクリプトは、product_group_view レポートと
shopping_performance_view レポートをサポートしており、
ショッピング キャンペーンのパフォーマンスをトラッキングできます。レポートについて詳しくは、
レポートに関するガイドをご覧ください。