How to avoid overspending Daily Budget per campaign

122 views
Skip to first unread message

primrose furniture

unread,
Dec 16, 2019, 5:19:29 AM12/16/19
to Google Ads Scripts Forum
I'm running 6 campaigns with different daily budgets per campaign. I want to get rid of overspending my daily budget. As of now, It's consuming my daily budget doubled the pre-set amount. I know google will spend our daily budget 2X times of the average when there's high traffic and not more than the monthly budget. somehow, my client won't like to go along with what Google is supposed to. I've tested Automated Rules which could not deliver a satisfying result for me. I'm currently thinking of testing a JS Google Ads Script for each campaign to control my daily budget. I'll be glad if someone can share a well-written and customizable JS script with me to test out. Thanx in advance.

Google Ads Scripts Forum Advisor

unread,
Dec 16, 2019, 2:54:21 PM12/16/19
to adwords-scripts+apn2wqcmdqf79mhq...@googlegroups.com, adwords-scripts+apn2wqcmdqf79mhq...@googlegroups.co, adwords...@googlegroups.com
Hello,

Assuming the campaign type is supported by scripts, one common approach is to run an hourly script that checks the current cost of a campaign and compares it with the campaign's daily budget. If the campaign has exceeded the budget, or a preset threshold, then the campaign is paused. The script should also check if it is the first hour of the day, and if it is, then all paused campaigns should be enabled. It may a good idea to use labels, just in case the campaign is paused for another reason other than this particular budget requirement. Please see the script below:

function main() {
  
  //Check the hour of day (0 is the first hour, in this case)
  var hourOfDay = Utilities.formatDate(new Date(), AdsApp.currentAccount().getTimeZone(), 'H');
  
  var labelName = 'Budget pause';
  
  //Check if the label exists, and if not, create the label, 'Budget pause'
  if(!AdsApp.labels().withCondition("Name = '" + labelName + "'").get().totalNumEntities())
    AdsApp.createLabel(labelName);
  
  var campaigns = AdsApp.campaigns().withCondition("Name CONTAINS 'CampaignName'").get(); //Customize your conditions
  
  //Remove labels and enabled campaigns that were paused yeseterday
  if(hourOfDay == 0) {
    var pausedCampaigns = AdsApp.campaigns().withCondition("LabelNames CONTAINS '" + labelName + "'").get();
    while(pausedCampaigns.hasNext()) {
      var campaign = pausedCampaigns.next();
      campaign.enable();
      campaign.removeLabel(labelName);
    }
  }
  
  //Check if campaigns have exceeded budget and pause those campaigns
  while(campaigns.hasNext()) {
    var campaign = campaigns.next();
    var cost = campaign.getStatsFor("TODAY").getCost();
    var budget = campaign.getBudget().getAmount();
        
    if(cost > budget) {
      campaign.pause();
      campaign.applyLabel(labelName);
    }
  }
}

Regards,
Matt
Google Ads Scripts Team

ref:_00D1U1174p._5001UOEcQi:ref
Reply all
Reply to author
Forward
0 new messages