ตัวอย่างสคริปต์สําหรับกลุ่มผลิตภัณฑ์

ส่วนต่อไปนี้แสดงตัวอย่างของสคริปต์ที่รับกลุ่มผลิตภัณฑ์และอัปเดตราคาเสนอ

การดูกลุ่มผลิตภัณฑ์

หากต้องการรับกลุ่มผลิตภัณฑ์ทั้งหมดในบัญชี ให้ใช้เมธอด 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คุณสามารถกรองกลุ่มผลิตภัณฑ์ตามค่าเมตริกมาตรฐาน เช่น การคลิกและ Conversion แต่คุณยังสามารถกรองตามราคาเสนอและกลุ่มผลิตภัณฑ์ได้อีกด้วย

ตัวอย่างต่อไปนี้แสดงวิธีการรับกลุ่มผลิตภัณฑ์สกี ถ้าเส้นทางคือ 'ผลิตภัณฑ์ > ทั้งหมด: สินค้า > กีฬา, สกีกีฬาฤดูหนาว > , > สกี, > สกีครอสคันทรีที่ได้รับการตกแต่งใหม่ > '

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();
    }
}

เนื่องจากสกีถูกแบ่งย่อยตามสภาพที่ได้รับการตกแต่งใหม่ การตอบกลับจะรวมถึงกลุ่มผลิตภัณฑ์ Ski ที่เลือกและกลุ่มผลิตภัณฑ์ 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);
    }
}