Logging Submissions to Google Sheets (Webhook + Apps Script)
This guide logs every form submission to a Google Sheet automatically, one row per submission. It uses only the free Webhooks feature and Google Apps Script (GAS), so you don't need Pro or a subscription to an external service.
What You Get
- One row per submission. Each form gets its own tab, such as "Form 973"
- Columns are added automatically to match the form's fields. Renaming a field's label keeps logging to the same column
- A token in the URL is checked, so the sheet only accepts deliveries from Form Plant
- Even if the same submission arrives twice through the automatic retry, only one row is logged
- Values are stored as text (leading zeros in phone numbers and postal codes are kept, and input that starts with "=" does not run as a formula)
- Password fields are not logged (unless Mask value when saving data is enabled for the field, the webhook sends them exactly as typed)
- The "Send test" button on the Integrations tab is logged to a separate "Test deliveries" tab
Setup
1. Create a spreadsheet and open Apps Script
- Create a new Google Sheet to log to
- Open "Extensions" → "Apps Script" from the menu
2. Paste the code and save
Delete the code that is already in the editor, paste the code below, and save (the floppy disk icon).
/**
* Receives Form Plant webhooks and appends each submission to the spreadsheet as one row.
* How to use: Form Plant manual, "Logging Submissions to Google Sheets"
*/
// Name of the tab for each form (e.g. "Form 973")
const FORM_SHEET_PREFIX = 'Form ';
// Name of the tab that logs test deliveries
const TEST_SHEET_NAME = 'Test deliveries';
// Field types that are not logged (depending on the field settings passwords arrive exactly as typed, so they are skipped)
const SKIP_TYPES = ['password'];
/**
* Run this once first. It creates and stores the token and prints it to the execution log.
* Running it again replaces the token (update the URL in Form Plant as well).
*/
function setup() {
const token = Utilities.getUuid().replace(/-/g, '');
PropertiesService.getScriptProperties().setProperty('TOKEN', token);
console.log('Token: ' + token);
console.log('Append ?token=' + token + ' to the web app URL and set it as the destination URL in Form Plant');
}
/**
* Lets you check the deployment by opening the URL in a browser (nothing is logged).
*/
function doGet() {
return ContentService.createTextOutput('The Form Plant receiver web app is running.');
}
/**
* Receives a delivery from Form Plant.
*/
function doPost(e) {
// Apps Script cannot read request headers, so the token in the URL is checked instead of the signature
const token = PropertiesService.getScriptProperties().getProperty('TOKEN');
if (!token || !e || !e.parameter || e.parameter.token !== token) {
console.warn('Token mismatch: nothing was logged');
return reply({ ok: false, error: 'invalid_token' });
}
let data;
try {
data = JSON.parse(e.postData.contents);
} catch (err) {
console.error('Could not parse the body as JSON: ' + err);
return reply({ ok: false, error: 'invalid_json' });
}
// Log one delivery at a time so that simultaneous submissions do not overwrite each other
const lock = LockService.getScriptLock();
try {
lock.waitLock(30000);
const ss = SpreadsheetApp.getActiveSpreadsheet();
if (data.event === 'submission.test') {
recordTest(ss, data);
} else if (data.event === 'submission.completed') {
recordSubmission(ss, data);
}
return reply({ ok: true });
} catch (err) {
console.error(err);
return reply({ ok: false, error: String(err) });
} finally {
lock.releaseLock();
}
}
/**
* Appends one submission as one row to the form's tab.
*/
function recordSubmission(ss, data) {
const sheet = getOrCreateSheet(ss, FORM_SHEET_PREFIX + data.form_id, [
{ key: '_submitted_at', label: 'Submitted at' },
{ key: '_submission_id', label: 'Submission ID' },
]);
const keys = getColumnKeys(sheet);
const submissionId = Number(data.submission_id) || 0;
// If the same submission arrives twice (e.g. the automatic retry), the second one is skipped
if (submissionId > 0 && hasSubmission(sheet, keys.indexOf('_submission_id'), submissionId)) {
console.log('Submission ' + submissionId + ' is already logged; skipped');
return;
}
const row = [];
row[keys.indexOf('_submitted_at')] = toDate(data.submitted_at);
row[keys.indexOf('_submission_id')] = submissionId || '';
(data.fields || []).forEach(function (field) {
if (!field || !field.key || SKIP_TYPES.indexOf(field.type) !== -1) {
return;
}
let col = keys.indexOf(field.key);
if (col === -1) {
col = addColumn(sheet, keys, field.key, field.label || field.key);
}
row[col] = asText(toCellText(field.value));
});
sheet.appendRow(keys.map(function (_, i) {
return row[i] === undefined ? '' : row[i];
}));
}
/**
* Logs a test delivery to the "Test deliveries" tab.
*/
function recordTest(ss, data) {
const sheet = getOrCreateSheet(ss, TEST_SHEET_NAME, [
{ key: '_received_at', label: 'Received at' },
{ key: '_form_id', label: 'Form ID' },
{ key: '_form_title', label: 'Form title' },
{ key: '_site_url', label: 'Site' },
]);
sheet.appendRow([new Date(), data.form_id, asText(data.form_title), asText(data.site_url)]);
}
/**
* Finds the tab, or creates it with a header row.
* Columns are identified by the note (key) on each header cell, so you can freely rename the header text.
*/
function getOrCreateSheet(ss, name, columns) {
let sheet = ss.getSheetByName(name);
if (!sheet) {
sheet = ss.insertSheet(name);
columns.forEach(function (column, i) {
const cell = sheet.getRange(1, i + 1);
cell.setValue(column.label);
cell.setNote(column.key);
});
sheet.setFrozenRows(1);
}
return sheet;
}
/**
* Returns the key of each column in row 1 (the note if present, otherwise the header text).
*/
function getColumnKeys(sheet) {
const lastCol = sheet.getLastColumn();
if (lastCol === 0) {
return [];
}
const header = sheet.getRange(1, 1, 1, lastCol);
const notes = header.getNotes()[0];
const values = header.getValues()[0];
return values.map(function (value, i) {
return notes[i] || String(value);
});
}
/**
* Adds a column on the right and writes its header and note (key).
*/
function addColumn(sheet, keys, key, label) {
const col = keys.length;
// A new tab has only 26 columns; add more when needed
if (col + 1 > sheet.getMaxColumns()) {
sheet.insertColumnsAfter(sheet.getMaxColumns(), col + 1 - sheet.getMaxColumns());
}
const cell = sheet.getRange(1, col + 1);
cell.setValue(asText(label));
cell.setNote(key);
keys.push(key);
return col;
}
/**
* Checks whether a row with the same ID exists in the submission ID column.
*/
function hasSubmission(sheet, col, submissionId) {
const lastRow = sheet.getLastRow();
if (col === -1 || lastRow < 2) {
return false;
}
return sheet.getRange(2, col + 1, lastRow - 1, 1)
.createTextFinder(String(submissionId))
.matchEntireCell(true)
.findNext() !== null;
}
/**
* Turns a value into cell text (multiple choices joined with ", ", grouped parts with spaces).
*/
function toCellText(value) {
if (value === null || value === undefined) {
return '';
}
if (Array.isArray(value)) {
return value.map(toCellText).filter(function (s) { return s !== ''; }).join(', ');
}
if (typeof value === 'object') {
return Object.keys(value).map(function (k) { return toCellText(value[k]); })
.filter(function (s) { return s !== ''; }).join(' ');
}
return String(value);
}
/**
* Stores the value as text. The leading ' keeps leading zeros and stops input that starts with
* "=" from running as a formula (the ' is not shown in the cell).
*/
function asText(text) {
return text === '' || text === null || text === undefined ? '' : "'" + text;
}
/**
* Converts Form Plant's submission time (ISO 8601) to a date value; logs it as text if it cannot be parsed.
*/
function toDate(iso) {
const date = iso ? new Date(iso) : new Date();
return isNaN(date.getTime()) ? asText(iso) : date;
}
/**
* Response to Form Plant. Apps Script always answers with a 302 whatever the result,
* so Form Plant always records the delivery as successful.
*/
function reply(body) {
return ContentService.createTextOutput(JSON.stringify(body))
.setMimeType(ContentService.MimeType.JSON);
}
3. Create the token
- In the function selector at the top of the editor, choose "setup" and click "Run"
- The first run asks for authorization. Click "Review permissions", choose your account, and allow access as prompted. If you see "Google hasn't verified this app", click "Advanced" → "Go to (project name) (unsafe)" to continue (this confirms that you are running a script you wrote with your own account)
- The "Execution log" at the bottom shows the token and how to add it to the URL. Keep it for step 5
You don't need to write the token into the code. Running setup again replaces the token,
so update the URL from step 5 when you do.
4. Deploy as a web app
-
Click "Deploy" → "New deployment" at the top right
-
Click the gear icon next to "Select type" and choose "Web app"
-
Set the following and click "Deploy"
Item Setting Execute as Me Who has access Anyone (Form Plant sends without signing in to Google) -
Copy the "Web app" URL that is shown (
https://script.google.com/macros/s/…/exec)
Open the copied URL in a browser. If it shows "The Form Plant receiver web app is running.", the deployment works.
Depending on your organization's admin settings, "Anyone" may not be available under "Who has access". In that case, ask your admin or create it with a personal Google account. Form Plant can't log to the sheet with any other setting.
5. Configure Form Plant
-
On the form edit screen, open the "Integrations" tab and click "+ Add Webhook"
-
For the destination URL, enter the URL from step 4 followed by
?token=and the token from step 3https://script.google.com/macros/s/AKfycb…/exec?token=3f9c0d… -
Check "Enable this webhook" and save the form
-
Click "Send test" and check that a row is added to the "Test deliveries" tab
-
Submit the form once for real and check that a row is added to the "Form (form ID)" tab
What Gets Logged
| Column | Content |
|---|---|
| Submitted at | When the form was submitted (shown in the spreadsheet's time zone) |
| Submission ID | The ID of the submission in Form Plant, so you can match rows with the admin screen |
| Column 3 onward | The form's fields. Each header is the label at the time the field first arrived |
- Multiple choices such as checkboxes are joined with ", ", and grouped values such as addresses are joined with spaces in one cell
- File fields contain only the file name (webhooks never send file URLs)
- The submission time is displayed in the time zone set in "File" → "Settings" → "Time zone" of the spreadsheet
Each header cell carries the field's key as a note, and columns are identified by that note. You can change the header text or reorder the columns. Don't delete the notes (if you do, the next submission creates a new column for that field on the right).
Things to Know
A "successful" delivery doesn't guarantee a new row
GAS answers with HTTP 302 (a redirect) no matter how the script ends. Form Plant therefore records the delivery as "success (302)" even when the token was wrong and nothing was logged. After setting it up, check that rows actually appear in the spreadsheet. To see why something wasn't logged, open "Executions" in the left menu of Apps Script and look at the log of each run (for example, "Token mismatch: nothing was logged").
A row may be added even when the delivery shows "failed (timeout)"
Form Plant waits up to 5 seconds for a response. If GAS is slow to start, the delivery can be recorded as "failed". The script keeps running on the GAS side, though, and the row is still added. When the automatic retry sends the same submission again 60 seconds later, no row is added if one with the same submission ID already exists, so rows are not duplicated.
If the form is set not to save submissions, the submission ID is 0. Form Plant then doesn't retry,
and the script doesn't check for duplicates either (the submission ID column is left empty).
How this relates to the signing secret
GAS cannot read request headers, so it cannot verify the signature that Form Plant adds.
This guide checks the token in the URL instead. Because the token is part of the URL, anyone who can see Form Plant's settings
screen can see it. If you think it has leaked, run setup to create a new one and update the destination URL in Form Plant.
Handling personal data
- Share the spreadsheet only with the people who need it. Don't set it to "Anyone with the link"
- The web app runs as "Me", so rows are written with the permissions of the person who created it
- Deleting a submission in Form Plant's admin screen does not delete the row in the spreadsheet. Decide how long to keep the data and when to delete it in line with your site's privacy policy
Redeploy as a new version after changing the code
Saving alone doesn't update the web app. Use "Deploy" → "Manage deployments" → the pencil icon → choose "New version" under "Version" → "Deploy". This keeps the URL (creating a new deployment changes the URL, and you would have to update Form Plant). You don't need to redeploy after only recreating the token.
Troubleshooting
| Symptom | What to check |
|---|---|
| The delivery shows "success" but no row is added | Whether ?token= in the destination URL matches the token in the execution log. Whether "Who has access" is "Anyone". Whether the run appears in "Executions" in Apps Script |
| The delivery shows "failed" with no HTTP code | Whether the destination URL starts with https://, and whether it was copied correctly |
| "failed (timeout)" but a row was added | Nothing is wrong (see above) |
| Opening the URL in a browser shows an error | Whether the deployment finished, and whether the code was saved before deploying |
| Changes to the code have no effect | Whether you redeployed as a new version |