This is the legacy documentation for Google Ads scripts. Go to the current docs.

Account Labels

Stay organized with collections Save and categorize content based on your preferences.

Create an account label

function createAccountLabels() {
  var labelName = 'INSERT_LABEL_NAME_HERE';

  AdsManagerApp.createAccountLabel(labelName);
  Logger.log("Label with text = '%s' created.", labelName);
}

Apply an account label to multiple accounts

function applyAccountLabels() {
  var accountIds = ['INSERT_ACCOUNT_ID_HERE', 'INSERT_ACCOUNT_ID_HERE'];
  var labelName = 'INSERT_LABEL_NAME_HERE';

  var accounts = AdsManagerApp.accounts().withIds(accountIds).get();
  while (accounts.hasNext()) {
    var account = accounts.next();
    account.applyLabel(labelName);

    Logger.log('Label with text = "%s" applied to customer id %s.',
               labelName, account.getCustomerId());
  }
}

Remove an account label from multiple accounts

function removeLabelFromAccounts() {
  var accountIds = ['INSERT_ACCOUNT_ID_HERE', 'INSERT_ACCOUNT_ID_HERE'];
  var labelName = 'INSERT_LABEL_NAME_HERE';

  var accounts = AdsManagerApp.accounts().withIds(accountIds).get();
  while (accounts.hasNext()) {
    var account = accounts.next();
    account.removeLabel(labelName);

    Logger.log('Label with text = "%s" removed from customer id %s.',
               labelName, account.getCustomerId());
  }
}

Select an account by label name

function selectAccountsByLabelName() {
  var labelName = 'INSERT_LABEL_NAME_HERE';

  var accountIterator = AdsManagerApp.accounts()
      .withCondition("LabelNames CONTAINS '" + labelName + "'")
      .get();

  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    var accountName = account.getName() ? account.getName() : '--';
    Logger.log('%s,%s,%s,%s', account.getCustomerId(), accountName,
        account.getTimeZone(), account.getCurrencyCode());
  }
}

Select an account by label ID

function selectAccountsByLabelId() {
  var labelId = 'INSERT_LABEL_ID_HERE';
  var accountIterator = AdsManagerApp.accounts()
      .withCondition("LabelIds IN ['" + labelId + "']")
      .get();

  while (accountIterator.hasNext()) {
    var account = accountIterator.next();
    var accountName = account.getName() ? account.getName() : '--';
    Logger.log('%s,%s,%s,%s', account.getCustomerId(), accountName,
        account.getTimeZone(), account.getCurrencyCode());
  }
}

Retrieve all account labels

function getAllAccountLabels() {
  var labelIterator = AdsManagerApp.accountLabels().get();
  while (labelIterator.hasNext()) {
    var label = labelIterator.next();

    Logger.log('Label with id = %s and text = %s was found.',
               label.getId().toFixed(0), label.getName());
  }
}

Retrieve an account label by its name

function getLabelByName() {
  var labelName = 'INSERT_LABEL_NAME_HERE';

  var labelIterator = AdsManagerApp.accountLabels()
      .withCondition("Name CONTAINS '" + labelName + "'")
      .get();

  while (labelIterator.hasNext()) {
    var label = labelIterator.next();

    Logger.log('Label with id = %s and text = %s was found.',
               label.getId().toFixed(0), label.getName());
  }
}

Retrieve account labels by their IDs

function getLabelById() {
  var labelIterator = AdsManagerApp.accountLabels()
      .withIds([12345, 67890]) // Replace with label IDs here
      .get();

  while (labelIterator.hasNext()) {
    var label = labelIterator.next();

    Logger.log("Label with id = %s and text = '%s' was found.",
               label.getId().toFixed(0), label.getName());
  }
}