How To Manage Multiple Adwords Budgets with Adwords Scripts

How To Manage Multiple Adwords Account Budgets

Managing more than one Adwords account means managing more than one budget. Clients usually have a set dollar amount they want to spend every month, and making sure you don’t overspend that can become a real stressful exercise.

At the time I developed this trick I was managing over 170 adwords accounts all with a different monthly budget. I was driving myself crazy frantically checking budgets by downloading excel docs out of adwords and comparing them to a master budget doc. It was extremely unproductive, and a waste of time.

In June 2012 my prayers were answered with the release of Adwords Scripts. Using Adwords Scripts and Google Spreadsheets, I developed a quick and easy dashboard to track monthly spend and monthly budgets of all my Adwords accounts, and automate the pausing & unpausing of Adwords accounts.

Here is how it works:
Here is your budget script, which you will paste into the accounts. Click on “Shared Library”, and then on “Create and Manage Scripts”.

Click on “create script”

Paste the script into the window.

Here is the script:
  • Make sure the Tab name of your Google Spreadsheet matches the one in the code  “var sheet = spreadsheet.getSheetByName(‘client 1)”

  • Make sure the spreadsheet url is pasted into the code “var SURL = ‘’“

  • Depending on the time frame of your report, you should schedule the script to run hourly, daily or weekly. In this case I chose daily because most of my reports include daily data.

Fill In The Red Highlighted With Your Exact Details:

// Budget Account Management
// Created By: Brennan Brooks
// Let’s set some constants
function main() {

// Locate the Spreadsheet and the sheet name

var SURL = ‘’;
var spreadsheet = getSpreadsheet(SURL);
var sheet = spreadsheet.getSheetByName(‘client 1);

// Initialize dates

var startdate = new Date(sheet.getRange(3,2).getValue());
var enddate = new Date(sheet.getRange(4,2).getValue());
var tempdate = new Date(sheet.getRange(3,2).getValue());
startdate.setTime(startdate.getTime() + (3*60*60*1000));
enddate.setTime(enddate.getTime() + (3*60*60*1000));
tempdate.setTime(tempdate.getTime() + (3*60*60*1000));
var startdateminusone = new Date();
startdateminusone.setTime(startdate.getTime() – (24 * 60 * 60 * 1000));
var today = new Date();

// Set main formulas in the Spreadsheet

sheet.getRange(2,4).setValue(Utilities.formatDate(startdateminusone, “PST”, “yyyy-MM-dd”));

// Loop through every date of the campaign and retrieve the total spent at that date

var i = 0;
while (enddate >= tempdate) {

var campaignsIterator = AdWordsApp.campaigns().get();
var spendingTotal = 0;
while (campaignsIterator.hasNext()) {
var campaign =;
var stats = campaign.getStatsFor(Utilities.formatDate(startdate, “PST”, “yyyyMMdd”),
Utilities.formatDate((tempdate), “PST”, “yyyyMMdd”));
spendingTotal = spendingTotal + stats.getCost();

// Write date, spent-this-day, spent-to-date and ideal pacing in the spreadsheet

sheet.getRange(3+i,4).setValue(Utilities.formatDate(tempdate, “PST”, “yyyy-MM-dd”));

if (today >= tempdate){
sheet.getRange(3+i,6).setValue(spendingTotal); }


tempdate.setTime(tempdate.getTime() + (24 * 60 * 60 * 1000));
i = i + 1;

// This function retrieves the Spreadsheet from the URL

function getSpreadsheet(spreadsheetUrl) {
var matches = new RegExp(‘key=([^&#]*)’).exec(spreadsheetUrl);
if (!matches || !matches[1]) {
throw ‘Invalid spreadsheet URL: ‘ + spreadsheetUrl;
var spreadsheetId = matches[1];

return SpreadsheetApp.openById(spreadsheetId);

Here is the SpreadSheet:

The Total Spend Tab

This “Total Spend” tab will detail each client’s spend and the budget which you will need to enter in Column B. 

I also added the following formulas which are automatically updated:
-Projected Over and Under Spend
-Projected Spend
-Budget Remaining
-Targeted Daily Spend/Day
-Current Daily Spend/Day
In each client’s row you need to change the E column formula tab call to the correct client’s tab in the worksheet. The red highlighted part of this example, =SUM(‘client 2’!$B$11)
The Client Tab

The Client Tab details out the daily spend. The only part of this you need to change is the budget, and the start and finish dates at the beginning of each month, otherwise the script won’t pull the correct & updated data.

Thats it! You now have a totally automated budget report that will allow you to correctly manage all of your clients budgets down to the penny. Please contact me if you have any questions, or run into any problems, @brennanbrooks.

Good Luck!