オーディエンスリスト

オーディエンスリストの一覧を取得する
オーディエンスリストをアップロードする(Googleドライブ経由)
オーディエンスリストをアップロードする(Googleスプレッドシート経由)

オーディエンスリストの一覧を取得する


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);
  }
}

オーディエンスリストをアップロードする(Googleドライブ経由)


function uploadAudienceList() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const retargetingTagId = '1A2B3C4D5E';//管理画面上でサイトリターゲティングIDを確認して指定
  const audienceListId = 1234567890;    //管理画面上でオーディエンスリスト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);
}

オーディエンスリストをアップロードする(Googleスプレッドシート経由)


function uploadAudienceList() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const retargetingTagId = '1A2B3C4D5E';//管理画面上でサイトリターゲティングIDを確認して指定
  const audienceListId = 1234567890;    //管理画面上でオーディエンスリストIDを確認して指定
  const uploadType = 'AAID';
  const compressType = 'NONE';
  const SPREAD_SHEET_ID = 'スプレッドシートID';
  const SPREAD_SHEET_NAME = 'シート1'
  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);
}