Offline Conversion

Upload of offline conversion data from Google Drive(Specify the file id)
Upload of offline conversion data from Google Drive(Specify the file name)
Upload of offline conversion data from Google Spreadsheet(Specify spreadsheet id)

Upload of offline conversion data from Google Drive(Specify the file id)


function uploadProcessingOfOfflineConversionData() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const fileId = '11111AAAAAbbbbb_-222222BBBBBccccc';
  const fileData = DriveApp.getFileById(fileId).getBlob().getBytes();
  const offlineConversions = Display.OfflineConversionService.upload(
    accountId,
    'sampleData.csv',
    fileData
  ).rval;
}

Upload of offline conversion data from Google Drive(Specify the file name)


function uploadDataSpecifyFileName() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const fileName = 'fileName';
  const files = DriveApp.getFilesByName(fileName);
  if(files.hasNext()){
    const file = files.next();
    const fileData = file.getBlob().getBytes();
    const offlineConversions = Display.OfflineConversionService.upload(
      accountId,
      fileName,
      fileData
    ).rval;
  } else {
    Logger.log('The specified file name does not exist on Google Drive.');
  }
}

Upload of offline conversion data from Google Spreadsheet(Specify spreadsheet id)


function uploadSpreadSheetData() {
  const accountId = AdsUtilities.getCurrentAccountId();
  const SPREAD_SHEET_ID = '111112222233333AAAABBBBBCCCCC';
  const SPREAD_SHEET_NAME = 'sheetName';
  let sh = SpreadsheetApp.openById(SPREAD_SHEET_ID).getSheetByName(SPREAD_SHEET_NAME);
  let dataArray = sh.getDataRange().getValues();
  let fileContent = '';
  dataArray.forEach(row => {
    fileContent += row + '\n';
  });
  const offlineConversions = Display.OfflineConversionService.upload(
    accountId,
    'uploadSpreadSheetName',
    fileContent
  ).rval;
}