AdWords scripts provides a way to access to your AdWords account through JavaScript so that you can automate regular tasks or take the leg work out of big account alterations. With a development tool built directly into the AdWords interface, a huge tutorial document and an active forum Google has made getting started really easy.

Adwords Scripts are not just for the big players like Kenshoo or Searchforce but anyone who has some JavaScript experience and needs more sophisticated e-commerce functionality. At Search Star one of our client’s sells thousands of different products that are regularly in and out of stock. We have built the Adwords Script below to integrate a live product feed with AdWords so that users aren’t going to clicks on ads for out of stock products.

Using Google’s lightweight interface and huge library of functions we can quickly access live CSV files from external URLs or Google Drive Spreadsheets. These powerful tools enable us to perform routine activities against an account, such as updating and reporting on accounts and making it possible for us to develop custom tools that will increase conversion rates.

AdWords scripts support Google Spreadsheets and HTTP service integration giving you access to important data and take action in your account. Additionally, the ability to send email from the interface makes it possible to develop advanced reporting and data analysis solutions. If you have limited resources this a platform you should be investigating.

  • The platform clearly opens a lot of doors and here are some ideas to get you thinking;
  • You can use spreadsheet data or external data to make campaign decisions.
  • If you have a jump in inventory you can automatically increase bids or add you keywords.
You can quickly output campaign reports into a more use able format or even drop them into a web page and display them with the beautiful Google Charts API.If you have any questions about Adwords Scripts or have a challenge you want to set us feel free to contact us to talk through your problem.


 * Michael King * * Adwords Stock Level Tester - Turns Adgroups On and Off depending on the values * stored in a Google Spreadsheet * * Instructions * Schedule your ecommerce system to produce an XML or CSV stock feed, it should * look something like this * Open a Google Drive Spreadsheet and use the * =importData(“”) function to fill * your spreadsheet. * Google spreadsheets should refresh roughly every hour. Set the script below * to run as often as you like. * */
function main() {
/* Replace this variable with the URL of your Google Docs Spreadsheet */ var url = 'THE URL OF YOUR SPREADSHEET';
/* Gets the spreadsheet and the named sheet, don’t forget to change the it tothe name of your sheet */ var spreadsheet = getSpreadsheet(url); var sheet = spreadsheet.getSheetByName('Stock Levels');
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); }
/* Grabs the entire range and uses the array length to work out the number ofrows in your spreadsheet, rowIndex is now equal to the number of rows in thespreadsheet */ var range = sheet.getDataRange(); var values = range.getValues(); for (var rowIndex = 0; rowIndex < values.length; rowIndex++) { var row = values[rowIndex]; }
/* Set the for loop to run until n = rowIndex, row Index has been set to thenumber of rows in the spreadsheet */ for (var n = 1; n < rowIndex; n++) {
/* Select the relevant cells in your spreadsheet, change so match yours */ var adGroupName = sheet.getRange("A" + n + "").getValue() var StockLevel = sheet.getRange("M" + n + "").getValue()
/* If the cell StockLevel cell contains 'No' get the relivant AdGroup that matchesthe spreadsheet, you could change this to less than 1 (StockLevel < 1) */ if (StockLevel == "No") { var adGroupsIterator = AdWordsApp.adGroups() .withCondition("Name = '" + adGroupName + "'") .get();
/* Pause the Ad group */ if (!adGroupsIterator.hasNext()) { Logger.log("Ad group '" + adGroupName + "' not found."); } else { var adGroup =; adGroup.pause(); } }
/* else If the cell StockLevel cell contains 'YES' get the relivant AdGroup thatmatches the spreadsheet you could change this to more than 1 (StockLevel > 0)*/ else if (StockLevel == "Yes") { var adGroupsIterator = AdWordsApp.adGroups() .withCondition("Name = '" + adGroupName + "'") .get();
/* enable ad group */ if (!adGroupsIterator.hasNext()) { Logger.log("Ad group '" + adGroupName + "' not found."); } else { var adGroup =; adGroup.enable(); } } }}