Skrypt Google Ads: Merchant Center Issues Checker

Optymalizacja kampanii zakupowych w Google Ads to nie tylko odpowiednia struktura konta, weryfikacja wyszukiwanych haseł czy zarządzanie stawkami.

Równie ważna jest jakość pliku produktów w Merchant Center. Istotne jest, aby systematycznie weryfikować, czy nasze konto ma asortyment z błędami.

Informacje te znajdziemy na karcie diagnostyka w zakładce produkty.

Najczęściej wygląda to tak:

W całym procesie chodzi o to, aby sprawdzać, czy możemy naprawić aktualne błędy.
Działania te mogą pozytywnie wpłynąć na skuteczność naszych reklam.

Poniższy skrypt Google Ads automatycznie odczyta dane o wszystkich problemach na wskazanym koncie Merchant Center i wyśle je w wiadomości e-mail.

Dzięki temu będziemy na bieżąco informowani o stanie naszych produktów.

Konfiguracja:
1. Wprowadź ID twojego Merchant Center do zmiennej MERCHANT_ID
2. Wprowadź swój e-mail do zmiennej EMAIL
3. W zaawansowanych ustawieniach włącz „Shopping content„:
https://developers.google.com/google-ads/scripts/docs/features/advanced-apis

Harmonogram: raz dziennie


Po więcej na temat Skryptów zapraszam na grupę FB o automatyzacji:
https://www.facebook.com/groups/skrypty.google.ads



/*

Copyright 2020 Krzysztof Bycina, www.LiveAds.pl
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/

// --------------------------------------- Configuration:

var EMAIL = ['ENTER YOUR EMAIL ID HERE'];
var MERCHANT_ID = 'ENTER YOUR MERCHANT ID HERE';

// --------------------------------------- End of the configuration



function main() {
  
    validateEmail(EMAIL);
    validateMerchantID(MERCHANT_ID);
  
    var emailData = [];
    var allIssues = countIssues(MERCHANT_ID);

    Logger.log("Total issues found: " + allIssues.numberOfIssues);


    //Move the data to an array:
    for (var key in allIssues) {
        if (key !== "numberOfIssues") {
            Logger.log(key + ": " + allIssues[key]);
            emailData.push([key + ":", allIssues[key]]);
        }
    }

    //Sort in descending Order
    emailData.sort(function(a, b) {
        return b[1] - a[1];
    });


    //Prepare the data for the email
    emailData.forEach(function(issue, index){
     emailData[index] = issue.join(" ");
    });
  
    sendEmails(emailData, allIssues.numberOfIssues);
}




function countIssues(merchantId) {
  
    var issuesData = {
        numberOfIssues: 0
    };

    var pageToken;
    var pageNum = 1;
    var maxResults = 250;

    do {
        var products = ShoppingContent.Productstatuses.list(merchantId, {
            pageToken: pageToken,
            maxResults: maxResults
        });

        if (products.resources) {
            for (var i = 0; i < products.resources.length; i++) {
                if (products.resources[i].itemLevelIssues) {
                    ++issuesData.numberOfIssues
                    var theIssue = products.resources[i].itemLevelIssues[0].description;

                    if (!issuesData[theIssue]) {
                        issuesData[theIssue] = 1;
                    } else {
                        ++issuesData[theIssue];
                    }
                }
            }
        }
        pageToken = products.nextPageToken;
        pageNum++;
    } while (pageToken);
    return issuesData;
}



function validateEmail(email) {
    var key = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    if (key.test(email) === false) {
        throw new Error('You must eneter a valid email address to run the script.');
    }
}

function validateMerchantID(theID) {
    if (isNaN(theID)) {
        throw new Error('You must eneter a valid Merchant Center ID to run the script.');
    }
}

function sendEmails(data, numberOfIssues) {
    if (data[0]) {
        MailApp.sendEmail(EMAIL.join(','), 'Total number of issues in your Merchant Center account: ' + numberOfIssues,
            'Hi, \n\nPlease, see the list of issues: \n\n' + data.join("\n"));
    }
}




2 comments / Add your comment below

  1. Również na pewno będę chciał to przetestować dla e-commerce które prowadzę. Wpis naprawdę bardzo przydatny.

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *