Script review: email alert when unusual increase in daily spendings

171 views
Skip to first unread message

Blandine C

unread,
Jun 12, 2018, 5:28:00 AM6/12/18
to AdWords Scripts Forum
Hi,

I want to be alerted when the daily budget for my whole account (say 20€) is exceeded by more than 50%, to monitor any unusual activity. 
I can't use automated rules to do this since I want to monitor the total account cost instead of the individual cost of each campaign.

I don't have any scripting experience, so I had to adapt a script I was given for another purpose. 
Could someone tell me if the following script is correct? 

var dBudget = 20;
var EMAIL = "na...@domain.com";


function main() {
 
var totalSpend = 0;
 
var camps = AdWordsApp.campaigns()
   
.withCondition("Status = ENABLED")
   
.get();
 
while(camps.hasNext()) {
   
var thisCamp = camps.next();
   
var thisSpend = thisCamp.getStatsFor("YESTERDAY").getCost();
    totalSpend
+= thisSpend;
 
}
 
Logger.log("Total Spend: €" + totalSpend);
 
if(totalSpend > (dBudget * 1.5)) {
    doSendEmail
(totalSpend);
   
Logger.log("Email warning sent.");
 
}
}
 
function doSendEmail(totalSpend) {
 
var body = "AdWords Campaigns have spent €" + totalSpend + " last day.";
 
MailApp.sendEmail(EMAIL,"Daily budget exceeded by more than 50%", body);
}

Thank you!

Anthony Madrigal

unread,
Jun 12, 2018, 2:17:53 PM6/12/18
to AdWords Scripts Forum
Hi Blandine,

The script looks like it should work fine.

Let us know if you face any issues.

Cheers,
Anthony
AdWords Scripts Team

Blandine C

unread,
Jun 13, 2018, 3:01:19 AM6/13/18
to AdWords Scripts Forum
Great, thank you!

Nils Rooijmans

unread,
Jun 15, 2018, 11:19:56 AM6/15/18
to AdWords Scripts Forum
Hi Blandine,

Sometimes overdelivery can be a good thing. For example, think about sudden spikes in user queries for your product because of a television show. You probably wouldn't want to mis out on the revenue potential because your campaign is limited by budget.

My suggestion would be to always keep a close eye on what is happening and adjust budgets when necessary.

For those interested, i decided to create a script that monitors these exact fluctuations.

The script will compare the anticipated ad spend based on your campaign daily budget settings with the actual ad spend.

It will check for overdelivery in any of three periods: yesterday, last week and last month.

In case of big differences (overdelivery by Google) it will report an alert, log the alert in the specified Google Sheet and inform you about the alert via email.

Here's the script:

A Script to receive Daily Budget Overdelivery Alerts


Hope this helps

Nils

Reply all
Reply to author
Forward
0 new messages