DOŁĄCZ DO GRUPY
BEZPŁATNY AUDYT
SKRYPT PMAX
NEWSLETTER

Zaawansowane Google Ads

5,001 członków

Dołącz do naszej społeczności ekspertów Google Ads i zyskaj dostęp do zaawansowanych strategii, wsparcia specjalistów i inspirujących case studies.

Prywatna grupa - Tylko zatwierdzeni członkowie

Nie jesteś pewny, czy Twoje reklamy działają tak, jak powinny?

Umów się na bezpłatny audyt konta Google Ads

Profesjonalna analiza

Szybki kontakt i konkretne informacje zwrotne.

Analiza efektywności
Weryfikacja Strategii
Praktyczne rekomendacje
Propozycja współpracy

Chcesz lepiej zrozumieć działanie kampanii Performance Max?

PMax Channels Analyzer

Darmowy skrypt dla Google Ads

Analizuj wydatki i konwersje z poszczególnych kanałów w kampaniach Performance Max.

Podział na kanały
Szczegółowe statystyki
Łatwa instalacja
Automatyczne raporty

Zapisz się na newsletter i otrzymuj praktyczne porady oraz narzędzia, które usprawnią twoje konto reklamowe.

Skrypt Google Ads: Total Budget

Skrypt Total Budget to rozwiązanie, dzięki któremu ustawimy całkowity budżet dla wybranej kampanii.

Po wydaniu określonej kwoty kampania zostanie automatycznie wstrzymana.

Aplikacja ta ułatwi nam kontrolę kosztów w trakcie specjalnych akcji promocyjnych. Szczególnie przyda się, gdy mamy ustalony budżet (np. 200 zł) do wydania w określonym czasie (np. 10 dni).

Ten typ budżetu znany jest między innym z reklam na Facebooku:
https://www.facebook.com/business/help/214319341922580

Niestety opcja ta standardowo nie jest dostępna w Google Ads.

Harmonogram: co godzinę

Konfiguracja:
1. Wprowadź nazwę kampanii do zmiennej CAMPAIGN_NAME
2. Wprowadź datę rozpoczęcia kampanii do zmiennej START_DATE
3. Wprowadź kwotę budżetu do zmiennej TOTAL_BUDGET
4. Wprowadź swój e-mail do zmiennej EMAIL


Po więcej na temat Google Ads dla e-commerce zapraszam na moją grupę FB:
https://www.facebook.com/groups/zaawansowane.google.ads


Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//Updated on 19.03.2020: Small code structure improvements
/*
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 TOTAL_BUDGET = 200; // TOTAL BUDGET
var START_DATE = "20200101"; // Enter the start date in this format: YYYYMMDD e.g. 20200101
var CAMPAIGN_NAME = "ENTER YOUR CAMPAIGN NAME HERE";
var EMAIL = "ENTER YOUR EMAIL HERE";
// --------------------------------------- End of the configuration
function main() {
validateEmail(EMAIL);
checkSpend();
}
function checkSpend() {
var todaysDate = Utilities.formatDate(new Date(), AdsApp.currentAccount().getTimeZone(), "yyyyMMdd");
var campaigns = AdsApp
.campaigns()
.withCondition('Status = ENABLED')
.withCondition("Name = '" + CAMPAIGN_NAME + "'")
.get()
while (campaigns.hasNext()) {
var theCampaign = campaigns.next();
var stats = theCampaign.getStatsFor("" + START_DATE + "", todaysDate);
}
var currentCost = stats.getCost().toFixed(2);
//Is the budget exceeded?
if (currentCost >= TOTAL_BUDGET) {
sendEmails(currentCost);
//Pause the campaign
theCampaign.pause();
} else {
Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is less than your total budget: " + TOTAL_BUDGET);
Logger.log("No action has been taken.");
}
}
function sendEmails(currentCost) {
MailApp.sendEmail(EMAIL, CAMPAIGN_NAME + ' exceeded your total budget.',
"Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET);
Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET);
Logger.log("The campaign has been pasued.");
}
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.');
}
}
//Updated on 19.03.2020: Small code structure improvements /* 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 TOTAL_BUDGET = 200; // TOTAL BUDGET var START_DATE = "20200101"; // Enter the start date in this format: YYYYMMDD e.g. 20200101 var CAMPAIGN_NAME = "ENTER YOUR CAMPAIGN NAME HERE"; var EMAIL = "ENTER YOUR EMAIL HERE"; // --------------------------------------- End of the configuration function main() { validateEmail(EMAIL); checkSpend(); } function checkSpend() { var todaysDate = Utilities.formatDate(new Date(), AdsApp.currentAccount().getTimeZone(), "yyyyMMdd"); var campaigns = AdsApp .campaigns() .withCondition('Status = ENABLED') .withCondition("Name = '" + CAMPAIGN_NAME + "'") .get() while (campaigns.hasNext()) { var theCampaign = campaigns.next(); var stats = theCampaign.getStatsFor("" + START_DATE + "", todaysDate); } var currentCost = stats.getCost().toFixed(2); //Is the budget exceeded? if (currentCost >= TOTAL_BUDGET) { sendEmails(currentCost); //Pause the campaign theCampaign.pause(); } else { Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is less than your total budget: " + TOTAL_BUDGET); Logger.log("No action has been taken."); } } function sendEmails(currentCost) { MailApp.sendEmail(EMAIL, CAMPAIGN_NAME + ' exceeded your total budget.', "Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET); Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET); Logger.log("The campaign has been pasued."); } 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.'); } }
//Updated on 19.03.2020: Small code structure improvements

/*

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 TOTAL_BUDGET = 200; // TOTAL BUDGET
var START_DATE = "20200101"; // Enter the start date in this format: YYYYMMDD e.g. 20200101
var CAMPAIGN_NAME = "ENTER YOUR CAMPAIGN NAME HERE";
var EMAIL = "ENTER YOUR EMAIL HERE";

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



function main() {

    validateEmail(EMAIL);
    checkSpend();

}


function checkSpend() {

    var todaysDate = Utilities.formatDate(new Date(), AdsApp.currentAccount().getTimeZone(), "yyyyMMdd");

    var campaigns = AdsApp
        .campaigns()
        .withCondition('Status = ENABLED')
        .withCondition("Name = '" + CAMPAIGN_NAME + "'")
        .get()

    while (campaigns.hasNext()) {
        var theCampaign = campaigns.next();
        var stats = theCampaign.getStatsFor("" + START_DATE + "", todaysDate);
    }
    var currentCost = stats.getCost().toFixed(2);

    //Is the budget exceeded?
    if (currentCost >= TOTAL_BUDGET) {
        sendEmails(currentCost);

        //Pause the campaign
        theCampaign.pause();

    } else {
        Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is less than your total budget: " + TOTAL_BUDGET);
        Logger.log("No action has been taken.");
    }
}

function sendEmails(currentCost) {
    MailApp.sendEmail(EMAIL, CAMPAIGN_NAME + ' exceeded your total budget.',
        "Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET);

    Logger.log("Your campaign: " + CAMPAIGN_NAME + " spend " + currentCost + " which is more than your total budget: " + TOTAL_BUDGET);
    Logger.log("The campaign has been pasued.");
}

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.');
    }
}

7 comments / Add your comment below

    1. Ponawiam zapytanie kolegi 🙂 ewentualnie czy jest opcja żeby wybrać więcej niż jedna kampanie coś na zasadzie budżetu wspólnego? nie tworząc przy tym osobnego skryptu dla każdej z kampanii osobno?

  1. Jak powinien wyglądać mail, który zostanie wysłany przez skryp (np tytuł), wczoraj przetestowałem kod i kampania została wstrzymana, ale nie widzę żadnej wiadomości

Dodaj komentarz

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