產品群組的腳本範例
下列各節示範取得產品群組並更新其報價金額的腳本範例。
取得產品群組
若要取得帳戶中的所有產品群組,請使用 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
,您可以依點擊和轉換等標準計量值來篩選產品群組,但您也可以依報價金額和產品群組進行篩選。
下列範例示範如何取得 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 會依[已修改的條件] 細分,因此回應會包含選取的 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);
}
}