function doPost(e) {  var data = JSON.parse(e.postData.contents);  var maindatabody = JSON.parse(data.maindatabody);  var sheetName = data.targetsheet && data.targetsheet.trim() !== "" ? data.targetsheet.trim() : "Sheet1";  var ss = SpreadsheetApp.openById("YOUR_SPREADSHEET_ID_HERE");  var sheet = ss.getSheetByName(sheetName);  if (!sheet) {    sheet = ss.insertSheet(sheetName); }  var headers = [];  var values = [];  for (var key in maindatabody) {    if (maindatabody.hasOwnProperty(key)) {  if (key === 'ct_bot_detector_event_token' || key === 'apbct_visible_fields') continue; var value = maindatabody[key]; if (!value || value === "") continue; var parts = key.split('__'); var subParts = parts.length > 1 && parts[1] ? parts[1].split('~') : parts; var header = subParts.join(' '); headers.push(header.replace(/[^a-zA-Z0-9 ]/g, '')); values.push(Array.isArray(value) ? value.join(' ') : value); } } var additionalHeaders = ["formid", "ip", "browser", "currentdate"]; var additionalValues = [data.formid, data.ip, data.browser, data.currentdate]; headers = headers.concat(additionalHeaders); values = values.concat(additionalValues); if (!sheet.getRange(1, 1, 1, headers.length).getValues()[0].some(cell => cell !== "")) { sheet.getRange(1, 1, 1, headers.length).setValues([headers]); } if (values.length === headers.length) { sheet.appendRow(values); } return ContentService .createTextOutput(JSON.stringify({ "result": "success" })) .setMimeType(ContentService.MimeType.JSON); }