Bulk Update Ad Group Labels with an AdWords Script

June 17, 2014

Bulk Update Ad Group Labels with an AdWords Script

AdWords Labels! They’re so useful! At least they are once you’ve got them applied.

You can use them to segment ad groups by product types, or tag recently changed bids, or see how a multi-ad-group ad test is going with ease… but for some reason, two years after their announcement, you still can’t bulk edit labels. You can’t even see them in Editor. You’ve got to manually add them in the online interface.

You could use comments in Editor instead of labels, but it’s hard to make this work if you’re in a team: comments aren’t shared automatically. Also you can’t see totals, and there isn’t an easy way to get a time series.

There is, however, an alternative: AdWords Scripts can read data from Google Doc spreadsheets, and they can create and apply labels – so all you need to do is have a bulk sheet in a Google Doc and let a Script do the hard work.

Here’s how to do that to apply labels to ad groups.

The Google Doc

Just go to Google Drive, create a spreadsheet, and fill it in a bit like this:

Leave the ‘Notes’ column blank – it isn’t for your notes, it’s where the Script will say if it’s applied the label, or if there’s been a problem.

The AdWords Script

In your AdWords account go to ‘Bulk operations’, then ‘Scripts’, then click the red ‘+ SCRIPT’ button. Name it something sensible (like ‘Ad Group Labeller’) and copy and paste in this code:

function main() {
// Applies labels to specified ad groups, based on a Google Doc Spreadsheet.
// From https://white.net/blog/bulk-update-ad-group-labels-adwords-script/
//Change this to your spreadsheet's URL!
var spreadsheetUrl = "https://docs.google.com/spreadsheets/d/YOUR-URL-HERE";
var inputSheet = SpreadsheetApp.openByUrl(spreadsheetUrl).getActiveSheet(); //The sheet in the Google Doc
var i = 2; //Integer for the loop
var numberOfLabels = inputSheet.getLastRow() //Number of rows in the sheet, which is the number of ad groups that want to be labelled
while (i <= numberOfLabels) //This loops through all the rows
if (inputSheet.getRange("D"+i).getValue() == "") //If there are no notes for the current row
var labelCampaignName = inputSheet.getRange("A" + i).getValue();
var labelAdGroupName = inputSheet.getRange("B" + i).getValue();
var labelText =inputSheet.getRange("C" + i).getValue();
var printToSpreadsheet = "-"
//This is a variable that records what will be noted in the spreadsheet for each ad group (whether the label has been added, or there was an error)
var adGroupIterator = AdWordsApp.adGroups() //Finds the ad groups with the specified name and campaign name
.withCondition("CampaignName = '" + labelCampaignName + "'")
.withCondition("Name = '" + labelAdGroupName +"'")
if (adGroupIterator.hasNext()) //If there is an ad group then the label will be applied
var adGroup = adGroupIterator.next();
AdWordsApp.createLabel(labelText); //Creates the label - if the label already exists then there may be an error, but the Script will continue
adGroup.applyLabel(labelText); //Applies the label to the group
printToSpreadsheet = "Done";
//This means the ad group iterator was empty, so there wasn't an ad group of the right name (or a campaign of the right name).
printToSpreadsheet = "Ad group not found"; //An error message will be recorded in the spreadsheet.
inputSheet.getRange("D" + i).setValue(printToSpreadsheet); //Writes into the Notes column in the spreadsheet
Logger.log("Label " + labelText + " applied to '" + labelAdGroupName + "' in '"+ labelCampaignName +"':" + printToSpreadsheet); //Also writes into the Log
}//End 'if there are notes'
i = i+1;
}//End while loop

Remember to change the spreadsheet URL, so that it looks at the right spreadsheet!

You need to click the ‘Authorise now’ button before the Script can run (don’t worry – it won’t make changes aside from adding labels). Then you can click ‘Run script now’ and see if it works.

The Results

Check your ad groups – they should be labelled!

Also check the Notes column in your Google Doc:

Here you see there’s been a problem with the last ad group – it looks like I’ve mistyped the ad group name. So I can either add a row to the bottom of the spreadsheet with the correct ad group name, or I could apply the label manually.

If the Script timed out then there would be rows without anything in the Notes column: in that case you can just try running the Script again.

And next time you want to label a bunch of groups, you can replace the contents of the Doc with the new set of groups to label and run the Script again – without any more messing with code.

Note – You’re Likely to See Errors in the Summary

When you run this Script there’s likely to be errors saying “You’re already using this label name”. That’s because AdWords needs you to create a label before applying it to something, and I haven’t worked out an efficient way to check if a label exists: so the Script just tries to create a new label every time, and if it already exists then there’s an error message which is just ignored. If anyone has a better idea how to handle this, please comment!

On the other hand, you won’t see errors in the summary if ad groups haven’t been found: you need to check the Google Doc for that.


PPC Hero also have a Script for applying labels to keywords, but it applies the same label to a list of keywords (and the label text is hard-coded, so you’d need to change the code manually to make different labels), and it doesn’t have a way of coping if the Script times out. Also it goes through all keywords and then checks if they match one in the list – I’m not sure if this is more efficient in general than my ‘grab the data lots of times’ approach, but I suspect it’s not as good if you only want to label a few keywords in a large account.

Update: Here are the scripts for labelling ads and keywords

So, does this Script work for you? Are there other similar Scripts I haven’t found yet? Have you found a more efficient way to work with labels? If you’ve got any comments then write in below…

Image credit: Tagged by JD Hancock

By Tamsin Mehew PPC Share:

3 thoughts on “Bulk Update Ad Group Labels with an AdWords Script

  1. Mary Geller says:

    Thank al lot for sharing this Google Doc and Ad Words Script.
    They have helped me.
    I have also found this Video and it is very useful. You might like to check this for PPM.


  2. Abhishek Chachan says:


    It was really very helpful.Thank you for sharing this.
    Can you provide script for Labelling Campaign Name, Keywords and Ads as well?

  3. Tamsin Mehew says:

    Hi Abhishek,

    Glad you found it useful! I’ve written scripts for keywords and ads – you can find them at https://white.net/blog/label-keywords-ads-bulk-adwords-script/

Leave a Reply

Your email address will not be published. Required fields are marked *