Script to send email alerts when daily budget cap is reached?

963 views
Skip to first unread message

Richard Lee

unread,
Aug 6, 2018, 5:20:31 PM8/6/18
to AdWords Scripts Forum
Hi Everyone!

So I am trying to find a way to get an email if my daily budget caps are reached. I know you can set alerts in Adwords but those require a specific budget amount but I want something that changes dynamically even when I change the budget. (I have way too many campaigns to manually set budget alerts for each campaign).

Does anyone have something similar that could help me? I am trying to write my own but running into syntax issues so any working examples would be awesome.


Message has been deleted

Vincent Racaza (AdWords Scripts Team)

unread,
Aug 7, 2018, 3:08:04 AM8/7/18
to AdWords Scripts Forum
Hi Richard,

For creating a script that will send notification through email when a campaign's current cost reached the daily budget, you may refer to the following instructions below for creating this script. 
1.)  First, you need to create a campaign iterator to get all the campaigns.
2.) Then, you may use getBudget method to get the budget of the campaign and getCost method to get the current cost of campaign.
3.) You need to create a validation that will verify if the cost exceeds the daily budget.
4.) You may use the MailApp.sendEmail method inside the condition to send an email notification.

Please refer to the sample scripts below where provided suggestion is implemented.

function main() {
 
var campaignSelector = AdWordsApp
     
.campaigns();

 
var campaignIterator = campaignSelector.get();
 
while (campaignIterator.hasNext()) {
   
var campaign = campaignIterator.next();
   
   
if(campaign.getStatsFor('TODAY').getCost() > campaign.getBudget()){
     
MailApp.sendEmail("INSERT_YOUR_RECIPIENT_HERE",
                 
"INSERT_EMAIL_SUBJECT_HERE",
                 
"INSERT_YOUR_MESSAGE_HERE");
   
}
 
}
}
The above script will also send an email even if you change the campaign budget as long as the condition is met. You can modify the script based on your goal such as sending one email only for one script execution.

You can test the sample script by clicking the Preview button. Please let me know if you encounter any issue.

Regards,
Vincent
AdWords Scripts Team
Reply all
Reply to author
Forward
0 new messages