How To Use AdWords Scripts Efficiently In Agencies And Enterprise SEM

I’m a big fan of all the things you can automate using AdWords Scripts — from calculating account-level Quality Score, to creating ads from a spreadsheet, to optimizing keywords using data from the Search Terms report. When using scripts to manage a single account, it’s well worth the effort to install and tweak them because of the amount of time you’ll save down the road.

But when it comes to managing enterprise-level AdWords, or managing multiple accounts as an agency, the truth is that a lot of the time saved ends up wasted in the minutiae of keeping everything organized and running. AdWords Scripts were not built with multi-account management in mind. Luckily, there are a few ways to address these shortcomings.

What follows are my five tips for making Scripts more efficient when you’re managing multiple (or very large) AdWords accounts. The first three are tricks to more easily manage scripts across multiple accounts.

1. How To Update A Script Once & Have The Changes Apply To All Accounts

Until Google introduces a way to run scripts from MCC accounts, we’re forced to add the same code in each account where we want to use it. While it’s not ideal, I can live with the inconvenience of adding the same script to multiple accounts — but the real waste of time starts when you fix a bug or make some improvement to the code.

These code changes don’t automatically propagate to the other accounts, so unless you go back and update the code in each account manually, your hard work to improve a script won’t benefit all of the other accounts you’re working on. That’s a problem….

So, what’s the solution for keeping a script synched across many accounts? Move the main functionality out of the code you put into AdWords and host it somewhere else. Then, serve up this remotely hosted code every time an account needs it.

There are a few options for where to keep the code: Russ Savage explains how to host your script for free on Google Drive. I prefer to host my remote scripts on Amazon S3, where I can take advantage of automatic versioning so that I can easily request an older version of the script if I happen to break something while making changes.

Run An AdWords Script Remotely

Here’s a code sample that shows how to request a piece of code from Amazon S3 or another web server.

Put this in AdWords:

function main() {
var fileToFetch = "";
   var scriptFile = UrlFetchApp.fetch(fileToFetch);
   var scriptText = scriptFile.getContentText();
   SETTINGS.className = "remoteScript";
   var script = eval('new '+SETTINGS.className+'();');


Put this in your remotely hosted file,

function remoteScript() {
this.main = function() {
     Logger.log("Hello World");

2. How To Change Settings Of A Script Without Changing The Code

Once you have your script hosted remotely so it can be called on the fly by any account that needs it, you may find yourself still logging into each account to change the settings. For example, many reporting scripts might be useful to run daily, weekly and monthly, and changing this involves changing some code.

Including settings that you might want to change in the main code is not ideal since it forces you to maintain many versions of the same script or tweak them every time you want to change even the smallest thing. When managing multiple accounts, managing many versions of the same script can quickly get out of hand, leading to errors like unintended changes in an account, running outdated scripts which don’t include your latest improvements, and wasting your time by making you manually go into accounts to make changes.

So, what are some ways to let one script run with different settings for each account you manage? I do this by keeping the script completely generic and putting all settings in a Google Sheet. The script looks at the Google Sheet every time it runs to get my settings, and then it uses those to finish what it’s supposed to do.

Not only does this allow me to use exactly the same script code in every account, it also lets me keep settings for all accounts in a central place. Now, when I want to change the date range or another setting for a script, I no longer need to go to that account to make the change but instead I just change the settings in the spreadsheet.

Get AdWords Script Settings From Spreadsheet

Here’s some code you can use to read in the settings from a Google Sheet. Just set the first row in the sheet to the names of the variables used in the script and then put the values for those variables on a new line:

var SETTINGS = new Object();
SETTINGS.taskSheet = SpreadsheetApp.openByUrl
(“htt://url_of_my_google_sheet”).getSheetByName("My Tab With Tasks");
var rows = SETTINGS.taskSheet.getDataRange();
var numRows = rows.getNumRows();
var numCols = rows.getNumColumns();
var values = rows.getValues();

// Read Header Rows
var headerNames = new Array();
var row = values[0];
for(var i = 0; i < numCols; i++) {
 headerNames[i] = "" + row[i];

// Read Data Rows With Settings And Run Script If Needed
for(var i = 1; i<numRows; i++) {
 var row = values[i];
 for(var j = 0; j < headerNames.length; j++) {
   var headerName = headerNames[j];
   var value = row[j];
   SETTINGS[headerName] = value;


Now, your script can reference SETTINGS.variableNameFromColumnHeader and get the setting from the Google Sheet.

3. How To Run More Than 150 Instances Of Scripts

AdWords limits every user to authorize up to 150 scripts. That’s usually more than enough if you’re managing one account, but if your username is for an MCC where you have 15 accounts, now your 150 scripts are shared, and you really only have 10 scripts per account you manage.

The workaround for this one is simple, but a bit annoying. I simply create a new login for each account I manage. I use that unique login to add scripts to the account so that I can maintain my full allotment of 150 scripts per account.

The next two tips are useful even if you’re only managing a single AdWords account, but it’s a large one or you’re looking to make tons of changes…

4. Prevent Scripts From Timing Out When Making Many Changes

This is a tip I got from the Google Developers site, and I experienced the difference it can make firsthand so I thought it was worth sharing here. Scripts will run much more quickly if you avoid switching between reading and writing from AdWords.

Even though scripts don’t have an explicit capability to submit changes in batch, they are optimized on Google’s end to do batch changes when possible. They will hold off on making changes to an account as long as possible and then make all the changes in bulk, which is much faster. When you switch from a command that make a change to a command that reads from AdWords, they process all pending changes in bulk.

So, if you alternate between reading and writing, your script will be much slower than if you do 100 write operations in sequence before doing another read.

Here’s an example: when you are updating bids, you might be iterating through every keyword to first ask for the keyword metrics, then calculating a new bid and then submitting the new bid. That will be very slow and, in my experience, I’ve done fewer than 300 bid changes during the 30 minute maximum time a script can run.

A better way is to read in all the keyword data first and calculate the new bids, storing the new bids in a variable. Only once all the calculations are done should the script submit the new bids, one right after the other. Doing it that way, I’ve processed thousands of bid changes and not even hit the 30 minute execution limit.

5. Get Around The 250,000 Entity Limit In Scripts

Building on the previous example, your script would still fail to complete if you were trying to make bid changes for an account that has more than 250,000 keywords because each script can at most process 250,000 entities using iterators like A simple workaround is to do as much of the work as possible using reports instead of iterators.

A report has no problem fetching all the metrics for millions of keywords in a matter of seconds. The 250,000 limit does not apply when iterating through all the rows of a report, so now it’s possible to calculate bid changes for every keyword. Only when that’s done do you start to send the new bids into AdWords, again doing them sequentially, avoiding switching between reading and writing. So long as you have fewer than 250,000 bids to change, you should be alright.

Those are five ways to make Scripts more useful for agencies, advertisers with very large accounts, and others who need to work on multiple accounts. Happy scripting!