以下のセクションでは、商品グループを取得し、その入札額を更新するスクリプトの例を紹介します。
製品グループの取得
アカウント内のすべての商品グループを取得するには、 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 を使用すると、クリックやコンバージョンなどの標準メトリック値で商品グループをフィルター処理できますが、入札金額や商品グループでフィルター処理することもできます。
次の例は、パスが "All products > Sporting Goods > Winter Sports > Skiing > Skis > Refurbished > Cross-Country 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();
}
}
スキー板は再生品の状態によって分割されるため、応答には、選択したスキー製品グループと再生品の 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);
}
}