以下部分展示了获取产品组并更新其出价金额的脚本示例。
获取产品组
要获取帐户中的所有产品组,请使用 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();
}
}
由于 Skis 按翻新状况细分,因此响应包括所选 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);
}
}