Audience List

Get Audience Lists
Upload Audience List From Google Drive
Upload Audience List From Google Spreadsheet

Get Audience Lists


function getAudienceLists() {
  const accountId = AdsUtilities.getCurrentAccountId();
  let audienceLists = Display.AudienceListService.get({
    accountId: accountId
  }).rval;
  if (audienceLists.totalNumEntries == 0) {
    Logger.log('AudienceList does not exist.');
    return;
  }
  for (let i = 0; i < audienceLists.values.length; i++) {
    let audienceList = audienceLists.values[i].audienceList;
    Logger.log('audienceListId-> ' + audienceList.audienceListId
      + ', audienceListName-> ' + audienceList.audienceListName
      + ', reach-> ' + audienceList.reach);
  }
}

Upload Audience List From Google Drive


function uploadAudienceList() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const retargetingTagId = '1A2B3C4D5E';//Specify the site retargeting ID
  const audienceListId = 1234567890;    //Specify the audience list ID
  const uploadType = 'AAID';
  const fileId = '11111AAAAAbbbbb_-222222BBBBBccccc';
  const compressType = 'NONE';
  const fileData = DriveApp.getFileById(fileId).getBlob().getBytes();
  let uploadList = Display.AudienceListService.uploadUserList(accountId, retargetingTagId, audienceListId, uploadType, compressType, fileData);
}

Upload Audience List From Google Spreadsheet


function uploadAudienceList() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const retargetingTagId = '1A2B3C4D5E';//Specify the site retargeting ID
  const audienceListId = 1234567890;    //Specify the audience list ID
  const uploadType = 'AAID';
  const compressType = 'NONE';
  const SPREAD_SHEET_ID = 'SpreadsheetID';
  const SPREAD_SHEET_NAME = 'Sheet1'
  let sh = SpreadsheetApp.openById(SPREAD_SHEET_ID).getSheetByName(SPREAD_SHEET_NAME);
  let ssDataArray = sh.getDataRange().getValues();
  let fileContent = '';
  ssDataArray.forEach(row => {
    fileContent += row[0] + '\n';
  });
  let blob = Utilities.newBlob(Buffer.from(fileContent, 'utf-8'));
  let uploadList = Display.AudienceListService.uploadUserList(accountId, retargetingTagId, audienceListId, uploadType, compressType, blob);
}