AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Ads
4.4K members online now
4.4K members online now
Dive into advanced features like Remarketing, Flexible Bid Strategies, AdWords Editor, and AdWords Scripts
Guide Me
star_border
Reply

Script to email when daily account cost hits £X

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi

 

I would like to set up a script so that an email alert is sent to a couple of different email addresses when my daily account cost exceeds a specific value in GBP e.g. £1000

 

I have searched forums/Google already and found similar scripts but they work at campaign level rather than total account level.

 

I have also found scripts that alert when the total account daily cost exceeds 120% of budget. This is useful, and I'm aware of the daily budget overspend rule, but again this is not exactly what I'm looking for - I'd like something that triggers on account cost in GBP, not a percentage of budget.

 

We are experimenting with campaign budgets at present and that's the reason for the enquiry. I don't want my ads to stop running when we hit £X - just for the email to be sent so that I know to check my AdWords account.

 

Any help would be much appreciated.

 

Thanks

Chris

 

 

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Chris M
January 2016

Re: Script to email when daily account cost hits £X

Top Contributor
# 2
Top Contributor

Hello, Chris.

 

This should probably work fine. It can be prettified a bit, but I've tested it and it works.

 

function main() {
  
  var account = MccApp.accounts().withIds(['replace_with_your_account_ID']).get().next(); //
  MccApp.select(account);
  //the lines above this one is are not necessary when run from a particular AdWords account and not an MCC
  
  var setLimit = 15; //daily spend limit, replace with yours
  var regularCampaigns = AdWordsApp.campaigns().withCondition("Status = ENABLED").get();
  var shoppingCampaigns = AdWordsApp.shoppingCampaigns().withCondition("Status = ENABLED").get();
  var currentCost = 0;
  
  
  while (regularCampaigns.hasNext()) {
    currentRegularCampaign = regularCampaigns.next();
    currentRegularStats = currentRegularCampaign.getStatsFor('TODAY');
    currentRegularCost = currentRegularStats.getCost();
    currentCost = currentCost + currentRegularCost;
    Logger.log(currentRegularCampaign.getName()+": "+currentRegularCost); //optional, you may delete it
  }
  
  while (shoppingCampaigns.hasNext()) {
    currentShoppingCampaign = shoppingCampaigns.next();
    currentShoppingStats = currentShoppingCampaign.getStatsFor('TODAY');
    currentShoppingCost = currentShoppingStats.getCost();
    currentCost = currentCost + currentShoppingCost;
    Logger.log(currentShoppingCampaign.getName()+": "+currentShoppingCost); //optional, you may delete it
  }
  
  Logger.log("Total: "+currentCost); //optional, you may delete it
  
  if (currentCost >= setLimit) {
  
  MailApp.sendEmail(
          "email1@example.com, email2@example.com, email3@example.com", //list of e-mail addresses
          "AW Script: Check Account Costs for "+AdWordsApp.currentAccount().getName(), //feel free to replace text between quotation marks
          "Daily account costs have exceeded the set limit of "+setLimit+" and are currently at "+currentCost+"."
          );
  }
  
}

Please note that it won't work with AdWords express or video campaigns. Hope it helps, though.

 

 

Calin Sandici, AdWords Top Contributor | Find me on: Google+ | Twitter | LinkedIn | myBlog
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Chris M
January 2016

Re: Script to email when daily account cost hits £X

Top Contributor
# 2
Top Contributor

Hello, Chris.

 

This should probably work fine. It can be prettified a bit, but I've tested it and it works.

 

function main() {
  
  var account = MccApp.accounts().withIds(['replace_with_your_account_ID']).get().next(); //
  MccApp.select(account);
  //the lines above this one is are not necessary when run from a particular AdWords account and not an MCC
  
  var setLimit = 15; //daily spend limit, replace with yours
  var regularCampaigns = AdWordsApp.campaigns().withCondition("Status = ENABLED").get();
  var shoppingCampaigns = AdWordsApp.shoppingCampaigns().withCondition("Status = ENABLED").get();
  var currentCost = 0;
  
  
  while (regularCampaigns.hasNext()) {
    currentRegularCampaign = regularCampaigns.next();
    currentRegularStats = currentRegularCampaign.getStatsFor('TODAY');
    currentRegularCost = currentRegularStats.getCost();
    currentCost = currentCost + currentRegularCost;
    Logger.log(currentRegularCampaign.getName()+": "+currentRegularCost); //optional, you may delete it
  }
  
  while (shoppingCampaigns.hasNext()) {
    currentShoppingCampaign = shoppingCampaigns.next();
    currentShoppingStats = currentShoppingCampaign.getStatsFor('TODAY');
    currentShoppingCost = currentShoppingStats.getCost();
    currentCost = currentCost + currentShoppingCost;
    Logger.log(currentShoppingCampaign.getName()+": "+currentShoppingCost); //optional, you may delete it
  }
  
  Logger.log("Total: "+currentCost); //optional, you may delete it
  
  if (currentCost >= setLimit) {
  
  MailApp.sendEmail(
          "email1@example.com, email2@example.com, email3@example.com", //list of e-mail addresses
          "AW Script: Check Account Costs for "+AdWordsApp.currentAccount().getName(), //feel free to replace text between quotation marks
          "Daily account costs have exceeded the set limit of "+setLimit+" and are currently at "+currentCost+"."
          );
  }
  
}

Please note that it won't work with AdWords express or video campaigns. Hope it helps, though.

 

 

Calin Sandici, AdWords Top Contributor | Find me on: Google+ | Twitter | LinkedIn | myBlog
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: Script to email when daily account cost hits £X

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Perfect - thanks very much.

Chris

Re: Script to email when daily account cost hits £X

Top Contributor
# 4
Top Contributor
You're welcome, Chris. I'm glad it helped.
Calin Sandici, AdWords Top Contributor | Find me on: Google+ | Twitter | LinkedIn | myBlog
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.