下列各節會顯示取得產品群組並更新其出價金額的指令碼範例。
取得產品群組
若要取得帳戶中的所有產品群組,請使用 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;
}
}
}
}
另一個選項是依購物廣告活動或購物廣告群組來取得產品群組。 若要依廣告群組取得產品群組,請先呼叫 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,您可以依標準度量值 (例如點選數和成交數) 來篩選產品群組,但也可以依出價金額和產品群組進行篩選。
下列範例顯示如果路徑為「所有產品 > 、運動用品 > 、冬季運動 > 、滑雪 > 板、 > 翻新 > 越野滑雪板」,如何取得滑雪板產品群組。
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);
}
}