製品グループのスクリプトの例
次のセクションでは、商品グループを取得し、入札金額を更新するスクリプトの例を示します。
製品グループの取得
アカウント内のすべての製品グループを取得するには、 AdsApp.productGroups() メソッドを 使用します。
function main() {
var productGroups = AdsApp.productGroups().get();
while (productGroups.hasNext()) {
var productGroup = productGroups.next();
switch (productGroup.getDimension()) {
case "ROOT": {
break;
}
case "CATEGORY": {
var category = productGroup.getValue();
break;
}
case "CHANNEL": {
var channel = productGroup.getValue();
break;
}
case "CHANNEL_EXCLUSIVITY": {
var channelExclusivity = productGroup.getValue();
break;
}
case "BRAND": {
var brand = productGroup.getValue();
break;
}
case "CONDITION": {
var condition = productGroup.getValue();
break;
}
case "CUSTOM_LABEL": {
// It's only necessary to cast the product group to a CustomLabel product
// group if you need to get the label's name (i.e., CustomLabel0).
var customLabel = productGroup.asCustomLabel();
var labelType = customLabel.getType();
var labelValue = customLabel.getValue();
break;
}
case "ITEM_ID": {
var id = productGroup.getValue();
break;
}
case "PRODUCT_TYPE": {
// It's only necessary to cast the product group to a ProductType product
// group if you need to get the type's name (i.e., PRODUCT_TYPE_1).
var productType = productGroup.asProductType();
var typeName = productType.getType();
var typeValue = productType.getValue());
break;
}
}
}
}
もう 1 つのオプションは、ショッピング キャンペーンまたはショッピング広告グループで製品グループを取得することです。 広告グループ別に製品グループを取得するには、まず AdsApp.shoppingAdGroups() メソッドを呼び出してから、 AdGroup.productGroups() メソッドを呼び出します。 キャンペーンの場合は、 同様に AdsApp.shoppingCampaigns() メソッドと Campaign.productGroups() メソッドを呼び出します。
function main() {
var shoppingAdGroups = AdsApp.shoppingAdGroups()
.get();
while (shoppingAdGroups.hasNext()) {
var adGroup = shoppingAdGroups.next();
var productGroups = adGroup.productGroups().get();
while (productGroups.hasNext()) {
var productGroup = productGroups.next();
switch (productGroup.getDimension()) {
case "ROOT": {
break;
}
case "CATEGORY": {
var category = productGroup.getValue();
break;
}
case "CHANNEL": {
var channel = productGroup.getValue();
break;
}
case "CHANNEL_EXCLUSIVITY": {
var channelExclusivity = productGroup.getValue();
break;
}
case "BRAND": {
var brand = productGroup.getValue();
break;
}
case "CONDITION": {
var condition = productGroup.getValue();
break;
}
case "CUSTOM_LABEL": {
// It's only necessary to cast the product group to a CustomLabel product
// group if you need to get the label's name (i.e., CustomLabel0).
var customLabel = productGroup.asCustomLabel();
var labelType = customLabel.getType();
var labelValue = customLabel.getValue();
break;
}
case "ITEM_ID": {
var id = productGroup.getValue();
break;
}
case "PRODUCT_TYPE": {
// It's only necessary to cast the product group to a ProductType product
// group if you need to get the type's name (i.e., PRODUCT_TYPE_1).
var productType = productGroup.asProductType();
var typeName = productType.getType();
var typeValue = productType.getValue());
break;
}
}
}
}
}
条件の適用
製品グループの一覧をフィルター処理するには、 withCondition メソッドを使用します。 を使用 withCondition
すると、クリックやコンバージョンなどの標準メトリック値で製品グループをフィルター処理できますが、入札金額や商品グループでフィルター処理することもできます。
次の例は、パスが "すべての製品>スポーツ用品>ウィンタースポーツ>スキー改装クロス>カントリースキー" である場合に Skis > 製品グループを取得する方法を>示しています。
function main() {
var shoppingAdGroup = AdsApp.shoppingAdGroups().withIds(["123456789"]).get().next();
var productGroups = shoppingAdGroup.productGroups()
.withCondition("ProductGroup = skis")
.get();
while (productGroups.hasNext()) {
var group = productGroups.next();
}
}
スキーは再生済み条件によって分割されるため、応答には、選択した Skis 製品グループと、改装済みの OtherCase 製品グループが含まれます。
dimension CATEGORY
value Skis
cpc null
parent 4578503857653096
dimension CONDITION
value OtherCase
cpc 1
parent 4578503857653099
製品グループの入札を更新する
通常、パフォーマンスが悪い場合は入札単価を引き上げ、パフォーマンスが良い場合は入札を減らす必要があります。 この例では、パフォーマンスが低下している商品グループを取得し、入札金額を増やす方法を示します。 (この例では、クリック数とコンバージョン率を使用してパフォーマンスの低いグループを特定しますが、適切なメトリックとしきい値を使用する必要があります)。
function main() {
var shoppingAdGroup = AdsApp.shoppingAdGroups().withIds(["123456789"]).get().next();
var productGroups = shoppingAdGroup.productGroups()
.withCondition("Clicks < 30")
.withCondition("ClickConversionRate < .25")
.forDateRange("LAST_MONTH")
.get();
var groupsToUpdate = [];
while (productGroups.hasNext()) {
groupsToUpdate.push(productGroups.next());
}
for (var group of groupsToUpdate) {
group.setMaxCpc(.35);
}
}