It All Started With An Idea

Campaign Level Budget Script

function main() {

 //update the value of monthlyBudget based on your requirement

 var monthlyBudget = 700;

 var totalCost = 0;

 var campaignsList = [];

 var campaignIterator = AdWordsApp.campaigns()

   .withCondition(‘Name IN [“samplecampaign-search”,”samplecampaign-display”]’) //you may change this depending on your requirement

   .get();

 while (campaignIterator.hasNext()) {

  var campaign = campaignIterator.next();

   //save in campaignsList the list of campaigns object.

  campaignsList.push(campaign);

  //use THIS_MONTH to get data for all days in the current month

  var stats = campaign.getStatsFor(‘THIS_MONTH’);

  var campaignCost = stats.getCost();

  totalCost += campaignCost;

 }

 Logger.log(“Combined Cost for this month: ” +totalCost);

 //if totalCost of combined 4 campaigns is equal to defined monthlyBudget, pause the 4 campaigns

 if (totalCost >= monthlyBudget){

  for (var i = 0; i < campaignsList.length; i++) {

   var campaign = campaignsList;

   Logger.log(campaign.getName())

   campaign.pause();

  }

 }

}

About the author

John M. Williams — Founder, It All Started With An Idea. Senior paid media specialist with 15+ years and $350M+ in managed ad spend across Google, Meta, LinkedIn, and Amazon. Creator of Buddy, the open-source AI Google Ads agent. Hero Conf 2025 + 2026 speaker.

More about John · LinkedIn ↗ · GitHub ↗

Working notes

More from the blog.

Read the blog  Get a free audit