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

Script for all campaigns limited by budget

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I'm working inside of a large MCC and my employees would love the ability to get an email whenever a campaign in their account is limited by budget. 

 

Is there an MCC script that could show this? Even an account specific script would be great. I can hack something that already exists, but I don't have much experience writing script from scratch. Any help would be awesome.

2 Expert replyverified_user

Re: Script for all campaigns limited by budget

Top Contributor
# 2
Top Contributor

Hello Garrett B,

 

Welcome to AdWords Community.

 

That is something I would also be interested in. Let me bring @Jon_Gritton into the discussion here. I have seen him write some impressive scripts in the past. 

 

Fingers crossed, if he spends some time on it.

 

Thanks

Ratan

Join me on Google+


About Me: Community Profile | Ratan Jha INC. | Splashsys Webtech
If this or any other post solved your question, do not hesitate to accept it as the solution.
Marked as Best Answer.
Solution
Accepted by topic author Garrett B
September 2015

Re: Script for all campaigns limited by budget

Top Contributor
# 3
Top Contributor

Morning, did someone call?

 

Hi Garrett, (thanks Ratan) unless I'm mistaken you can't actually check for the "Limited by Budget" message that AdWords displays in the AWFE but what you can do is check the daily spend and compare it to the budget and then generate a warning when the spend is very close to the budget (which will usually mean the Campaign is limited).  Alternatively (or additionally) you can check the Search Lost Impression Share (Budget), though to be honest, the former method of simply comparing spend to budget is quicker and simpler and will probably do all you need in terms of giving you a list of Campaigns to check.

 

The script below should give you a good head start, and will generate a separate email for each Account that contains limited Campaigns.  Replace the email at the top with yours, then PREVIEW the script to make sure it does what you want.  Once happy, remove the comment (//) before the line that sends the email (almost at the end of the script) to allow emails to be sent, and schedule the script to run about 2am each day.

 

You may want to alter the CLOSEPER figure to suit your opinion of "close" to budget.  It's currently 0.8 which means any Campaign spending more than 80% of the budget will generate a warning.  You might also want to alter the time period to check for the average spend over 7 days, rather than just "YESTERDAY".  You could work out a way to combine all the messages into a single email.  I'll leave these challenges to you!

 

Obviously, this is an MCC script so will only work when run at the MCC level.

 

Jon

 

var RECEMAIL = "youremail@gmail.com"; //enter the recipients email address
var CLOSEPER = 0.8; // enter what you consider "close" to daily budget, e.g. 0.8 = 80% of budget

function main() {
//get all the accounts in the MCC
var accounts = MccApp.accounts().get();
//iterate through the accounts & run the campaign checker
while(accounts.hasNext()) {
var thisAccount = accounts.next();
var accountName = thisAccount.getName();
MccApp.select(thisAccount);
checkCampaigns(accountName);
}
}

function checkCampaigns(accountName) {
var campaigns = AdWordsApp.campaigns()
.withCondition('Status = ENABLED')
.get();
//initialise the email body as empty
var campList = "";
while(campaigns.hasNext()) {
var thisCampaign = campaigns.next();
var stats = thisCampaign.getStatsFor("YESTERDAY");
var budget = thisCampaign.getBudget();
var spend = stats.getCost();
var name = thisCampaign.getName();

if(spend > (budget * CLOSEPER)) {
Logger.log("Campaign: " + name + " Budget: " + budget + " Spend: " + spend);
campList += "Campaign: " + name + " Budget: " + budget + " Spend: " + spend + "\n";
}
}

if(campList.length !=0) { //only if there are limited Campaigns, send email
var campList="These Campaigns are close to their Daily Budget \n";
sendEmail(RECEMAIL,campList,accountName);
}
}

function sendEmail(email, body, accountName) {
var subject = "Account '" + accountName + "' - Campaigns close to Budget";
Logger.log("Sending email, subject: " + subject);
//remove the comment "//" below when testing completed
//MailApp.sendEmail(email,subject, body);
}

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Script for all campaigns limited by budget

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭
Jon! I can't tell you how much this means to me and my team! Not only have you given us a great solution, but you've given me a nice little guided challenge to improve my scripting. This is fantastic, you are fantastic, and thanks to Ratan as well for the assist.

This is an amazing community.

Re: Script for all campaigns limited by budget

Top Contributor
# 5
Top Contributor

Thanks Garrett, threads like these are why we enjoy helping others, thank you for coming back and your kind comments.

 

Please do come back again with any other questions you may have and we'll try to keep the same level of service going Smiley Happy

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Script for all campaigns limited by budget

Top Contributor
# 6
Top Contributor
Thank you so much Jon.

Thanks
Ratan

About Me: Community Profile | Ratan Jha INC. | Splashsys Webtech
If this or any other post solved your question, do not hesitate to accept it as the solution.

Re: Script for all campaigns limited by budget

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Just wanted to let you and future searchers I made some minor modifications to your script.

I'm at an agency and we group our accounts by label, so I wanted each manager to only get their accounts.

I also wanted to make sure each manager only got one email per day, though it'll change to one per week later.

And I made the subject line a little variable so the managers could get an idea if anything changed at a glance.

 

 

var emailAddress = "your@emailaddress.com"; //address to get the email
var percentOfBudget = 0.8; // a value of 0.8 would return anything within 80% of the budget
var cmName = "Your name" // Name as it appears on the label
var accountList = ""; // Empty eventual email
var n = 0; // An iterator for the subject line of the email

 

function main () {
  var accounts = MccApp.accounts().withCondition("LabelNames CONTAINS '" + cmName + "'").get();
  while(accounts.hasNext()) {
    var thisAccount = accounts.next();
    var accountName = thisAccount.getName();
    MccApp.select(thisAccount);
    checkCampaigns(accountName);
  }
  if(accountList.length !=0) { //only if there are limited Campaigns, send email
    sendEmail(emailAddress,accountList,accountName);
}

 

function checkCampaigns(accountName) {
  var campaigns = AdWordsApp.campaigns()
    .withCondition('Status = ENABLED')
    .get();
  var campList = "";
  while(campaigns.hasNext()) {
    var thisCampaign = campaigns.next();
    var stats = thisCampaign.getStatsFor("YESTERDAY");
    var budget = thisCampaign.getBudget();
    var spend = stats.getCost();
    var name = thisCampaign.getName();

    if(spend > (budget * percentOfBudget)) {
      Logger.log("Account: " + accountName + " Campaign: " + name + " Budget: " + budget + " Spend: " + spend)
      campList += "Account: " + accountName + " Campaign: " + name + " Budget: " + budget + " Spend: " + spend + "\n";
      n = n + 1;
    }
  }

  if (campList.length !=0) {
    accountList += campList + "\n" + "\n";
  }

}

 

function sendEmail(email, body, accountName) {
  var subject = "Hey " + cmName + ", " + n + " campaigns are at " + (percentOfBudget * 100) + "% of budget.";
  Logger.log("Sending email, subject: " + subject);
  Logger.log(accountList)
//remove the comment "//" below when testing completed
  MailApp.sendEmail(email,subject, body);
}
}

Re: Script for all campaigns limited by budget

Top Contributor
# 8
Top Contributor

Hi Garrett, thanks for letting me know.

 

I'm presuming you're running this script more than once, for each manager.  You could modify the script to iterate through associated emails and labelnames then run it only once.

 

Just as an aside, Labels are a great complement to Scripts as they can allow your Scripts to operate on a very specific set of elements that couldn't be chosen directly and/or simply.  In the past I've run scripts in pairs - one that labels elements, then one that runs an hour later and acts upon elements with those labels.  Splitting like this has two advantages - #1, in large Accounts the scripts don't time out, #2 - you can focus on the purpose of each script individually.  However, you could do it all in one if the circumstances were right.

 

Jon

AdWords Top Contributor Google+ Profile | Partner Profile | AdWords Audits

Re: Script for all campaigns limited by budget

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭
Hi @Garrett B

Can you help me with this script on Campaign level?

Re: Script for all campaigns limited by budget

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭
How can we modify this to get results saved in google docs and then send email to the each child account manager separately. ? Please suggest?