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

User Lists

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

Retrieve all user lists

function getAllUserLists() {
  var userlistIt = AdsApp.userlists().get();
  while (userlistIt.hasNext()){
    var userList = userlistIt.next();
    Logger.log('Name: ' + userList.getName() +
        ' Type: ' + userList.getType() +
        ' ID: ' + userList.getId());
    Logger.log(' Desc: ' + userList.getDescription() +
        ' IsOpen: ' + userList.isOpen() +
        ' MembershipLifeSpan: ' + userList.getMembershipLifeSpan());
    Logger.log(' SizeForDisplay: ' + userList.getSizeForDisplay() +
        ' SizeRangeForDisplay: ' + userList.getSizeRangeForDisplay());
    Logger.log(' SizeForSearch: ' + userList.getSizeForSearch() +
        ' SizeRangeForSearch: ' + userList.getSizeRangeForSearch());
    Logger.log(' IsReadOnly: ' + userList.isReadOnly() +
        ' IsEligibleForSearch: ' + userList.isEligibleForSearch() +
        ' IsEligibleForDisplay: ' + userList.isEligibleForDisplay());
    Logger.log(' ');
  }
}

Get the number of members in a user list

function getUserListMemberCount() {
  var iterator = AdsApp.userlists().get();
  while (iterator.hasNext()) {
    var userlist = iterator.next();
    Logger.log('User List [' + userlist.getName() + ']  has ' +
        userlist.getSizeForDisplay() +
        ' members for Search campaigns and  ' +
        userlist.getSizeRangeForDisplay() +
        ' members for Display campaigns.');
  }
}

Open a user list

function openUserLists() {
  var iterator = AdsApp.userlists().get();
  while (iterator.hasNext()) {
    var userlist = iterator.next();
    if (userlist.isClosed()) {
       userlist.open();
    }
  }
}

Retrieve search campaigns targeted by a user list

function getSearchCampaignsTargetedByUserList() {
  var userlistIterator = AdsApp.userlists().get();
  while (userlistIterator.hasNext()) {
    var userList = userlistIterator.next();
    var campaignIterator = userList.targetedCampaigns().get();
    var campaignNames = [];

    while (campaignIterator.hasNext()) {
      var campaign = campaignIterator.next();
      campaignNames.push(campaign.getName());
    }

    Logger.log("User List [" + userList.getName() +
        "]  is targeting [ " +
        campaignNames.join(',') + "]");
  }
}