Skrypt Google Ads: The best day

Tym razem dodaję skrypt, który poinformuje nas o pozytywnych wynikach na koncie.

Sprawdza liczbę konwersji z dnia poprzedniego. Jeśli okaże się, że był to najlepszy dzień w ciągu ostatnich trzydziestu, to otrzymamy e-mail.

Dlaczego warto to monitorować?

Zarządzając wieloma kontami, możemy czasem nie zauważyć pozytywnych wyników takich ja te.

Mając zautomatyzowany ten proces, możemy np. wysłać klientowi krótki e-mail:
„Dzień dobry, chcę tylko poinformować, że wczoraj konto Google Ads odnotowało największą liczbę konwersji w ciągu ostatnich trzydziestu dni”
lub po prostu wspomnieć o tym podczas rozmowy telefonicznej.

Dodanie tego typu elementów w komunikacji może pozytywnie wpłynąć na dalszą relację z klientem.


Uwagi: jest to skrypt w wersji MCC
Harmonogram: raz dziennie

Konfiguracja:
1. Utwórz etykietę i oznacz nią konta, które ma sprawdzać skrypt
2. Wprowadź treść etykiety do zmiennej LABELNAME
3. Wprowadź swój e-mail do zmiennej EMAIL


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


/*
Copyright 2019 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 HERE";
var LABELNAME = "ENTER THE LABEL HERE";
//End of the configuration

var bestDayAccounts = [];
var _30daysData = {
    date: [],
    conversions: []
};

var todaysDate = new Date();
todaysDate = new Date(todaysDate.getTime() + todaysDate.getTimezoneOffset() * 60000);

function main() {
    validateEmail(EMAIL);
    var accountSelector = AdsManagerApp.accounts()
        .withCondition("LabelNames CONTAINS '" + LABELNAME + "'");
    var accountIterator = accountSelector.get();
    while (accountIterator.hasNext()) {
        var account = accountIterator.next();
        AdsManagerApp.select(account);
        check30Days();
    }
    if (bestDayAccounts[0]) {
        sendEmails();
    }
}

function check30Days() {
    var iterator = -1;
    _30daysData.conversions = [];
    _30daysData.date = [];
    var report = AdWordsApp.report("SELECT Date, Conversions " +
        "FROM ACCOUNT_PERFORMANCE_REPORT " +
        "DURING LAST_30_DAYS ");
    var rows = report.rows();
    while (rows.hasNext()) {
        iterator++
        var row = rows.next();
        _30daysData.conversions[iterator] = row['Conversions'];
        _30daysData.date[iterator] = row['Date'];
    }
    var maxIndex = largestIndex(_30daysData.conversions);
    var maxValue = _30daysData.conversions[maxIndex];
    if (yesterdayConv() > maxValue) {
        Logger.log(AdsApp.currentAccount().getName() + " had: " + maxValue + " conversions yesterday, and that's the best performance in the last 30 days!")
        bestDayAccounts.push(AdsApp.currentAccount().getName() + " had: " + maxValue + " conversions yesterday, and that's the best performance in the last 30 days!")
    }
}

function largestIndex(array) {
    var counter = 1;
    var max = 0;

    for (counter; counter < array.length; counter++) {
        if (parseInt(array[max]) < parseInt(array[counter])) {
            max = counter;
        }
    }
    return max;
}

function yesterdayConv() {
    var stats = AdsApp.currentAccount().getStatsFor("YESTERDAY");
    return stats.getConversions();
}

function sendEmails() {
    MailApp.sendEmail(EMAIL,
        "You had the best day.",
        "Hi, \n\nThose accounts are doing well: \n\n" + bestDayAccounts.join("\n"));
}

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 enter a valid email address to run the script.')
    }
}

2 comments / Add your comment below

  1. Cześć. Przy próbie uruchomienia skryptu pokazuje błąd: ReferenceError: „AdsManagerApp” is not defined. (file Code.gs, line 29)

    Próbowałem uruchomić skrypt nie z poziomu konta MCC, stąd chyba ten błąd(?)
    Pozdrawiam, Radek

Dodaj komentarz

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