Send every survey response to Google Sheets
Get one row per survey response in your own Google Sheet, with a small script in the sheet or through Zapier or Make.
In this article
Varly has no direct Google Sheets connection: the Every survey response notification sends each response to a webhook, and the webhook adds the row.
What you get
One row per response (one visitor who answered), not per question. With recipe A, the columns are:
- Answered at: when the visitor gave their first answer.
- Survey: the name of the survey.
- Finished: whether the visitor answered up to the end.
- Page, Device and Country: for example
/products/blue-shoe,mobileandNL. - Response ID: a code for this response, so it never gets two rows.
- One column per question, added the first time someone answers it. Several choices are separated by a semicolon.
A row arrives within about an hour: Varly waits at least 10 minutes after the first answer, so the visitor can finish, then sends it at the next hourly check.
Varly only sends responses that come in after you add the webhook. For older ones, click Download answers (CSV) on the survey's results page, and open it as a separate tab or file (its columns differ). See Read your survey results.
Recipe A: a script in your sheet
No other service needed: Google runs a small script in your sheet as a web app.
- Create a sheet. Open a new Google Sheet, such as "Survey responses".
- Open the script editor. Click Extensions → Apps Script. Replace the code there with the script below.
- Make up a secret. Replace
CHANGE-MEwith at least 30 random letters and numbers; you need it in step 7. Click the save icon. - Deploy it. Click Deploy → New deployment. Click the gear next to Select type and choose Web app. Set Execute as to Me and Who has access to Anyone, then click Deploy.
- Allow it. Authorize the script with your account, so it can write to your sheet. If Google says it hasn't verified the app, click Advanced and go on: it's your own script.
- Copy the address. Copy the Web app URL, ending in
/exec. - Add the secret to the address. Add
?key=and your secret:https://script.google.com/macros/s/…/exec?key=YourLongRandomSecret. - Add it in Varly. In Settings → Notifications, paste the full address under Slack or webhook URL. Under Notify me when, untick all but Every survey response. Click Add destination.
- Check it. Click Send a test message next to the destination. A Responses tab with the column names appears in your sheet. If not, check that the secret in the address and the script are exactly the same.
Recipe A doesn't use the Signing secret Varly shows after you add the webhook.
The script:
// Varly: every survey response as a row in this sheet.
// Change CHANGE-ME into your own long random text (at least 30 letters and numbers).
const SECRET = 'CHANGE-ME';
const TAB = 'Responses';
const FIXED = ['Answered at', 'Survey', 'Finished', 'Page', 'Device', 'Country', 'Response ID'];
function doPost(e) {
const key = e && e.parameter ? e.parameter.key : '';
if (SECRET === 'CHANGE-ME' || SECRET.length < 30 || key !== SECRET) return reply('Not allowed');
let message;
try {
message = JSON.parse(e.postData.contents);
} catch (err) {
return reply('Not JSON');
}
const sheet = responsesTab();
if (message.event === 'survey.response') addResponse(sheet, message.data);
return reply('OK');
}
function responsesTab() {
const book = SpreadsheetApp.getActiveSpreadsheet();
const sheet = book.getSheetByName(TAB) || book.insertSheet(TAB);
if (sheet.getLastRow() === 0) {
sheet.appendRow(FIXED);
sheet.setFrozenRows(1);
}
return sheet;
}
function addResponse(sheet, data) {
const idColumn = FIXED.indexOf('Response ID') + 1;
const rows = sheet.getLastRow() - 1;
if (rows > 0) {
const ids = sheet.getRange(2, idColumn, rows, 1).getValues();
if (ids.some((r) => r[0] === data.responseId)) return; // already in the sheet
}
const headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
const row = [
new Date(data.answeredAt),
data.survey.name,
data.finished ? 'Yes' : 'No',
data.page,
data.device,
data.country,
data.responseId,
];
for (const a of data.answers) {
let column = headers.indexOf(a.prompt);
if (column === -1) {
headers.push(a.prompt);
column = headers.length - 1;
sheet.getRange(1, column + 1).setValue(a.prompt);
}
while (row.length < headers.length) row.push('');
const text = a.answer.join('; ');
row[column] = row[column] ? row[column] + '; ' + text : text;
}
// Text that starts with = + - or @ is kept as text, never run as a formula.
sheet.appendRow(row.map((v) => (typeof v === 'string' && /^[=+\-@]/.test(v) ? "'" + v : v)));
}
function reply(text) {
return ContentService.createTextOutput(text);
}
What the secret in the address does
Varly signs every message in a header (see Notifications for developers), but a Google web app can't read headers. The secret in the address does that job: the script only adds rows when the address has the right secret.
So the full address is a password: anyone who has it can add rows. Don't share it, and keep the secret long. If it leaks, change the secret, deploy a new version (see below), then remove the destination in Varly and add it again with the new address.
If you change the script later
Click Deploy → Manage deployments, click the pencil icon, choose New version under Version and click Deploy. The address stays the same.
Recipe B: Zapier or Make
- Catch the webhook. In Zapier, create a Zap with the trigger Webhooks by Zapier → Catch Hook. In Make, start a scenario with Webhooks → Custom webhook. Copy the address it shows.
- Add it in Varly. Go to Settings → Notifications, paste the address under Slack or webhook URL, untick all but Every survey response and click Add destination.
- Send a real response. Send a test message has no survey fields. For a full sample, answer your own survey on your site, wait up to an hour, and let Zapier or Make pick it up.
- Prepare the sheet. Make a Google Sheet with a header row: Answered at, Survey, Finished, Page, Device, Country, Response ID, Answers.
- Add the row. Add the action Google Sheets → Create Spreadsheet Row in Zapier, or Google Sheets → Add a Row in Make, and pick your sheet.
- Map the fields. Fill each column from these fields:
| Column | Field |
|---|---|
| Answered at | data.answeredAt |
| Survey | data.survey.name |
| Finished | data.finished |
| Page | data.page |
| Device | data.device |
| Country | data.country |
| Response ID | data.responseId |
| Answers | data.answers: each entry has prompt (the question) and answer (a list) |
data.answers only has the answered questions, in survey order, so with follow-up or skipped questions the third entry isn't always the third question. Put prompts and answers together in one column, or use recipe A, which gives each question its own column.
With other notifications on the same webhook, add a filter step that only goes on when event is survey.response.
Good to know
- Timing. Varly checks once an hour and sends each response at least 10 minutes after the visitor's first answer. Up to 200 responses per hour go to one address; the rest follow an hour later.
- When the sheet doesn't answer. Varly tries that response again at the next hourly check; the ones after it wait. After two failures, Varly skips it and goes on. It looks back at most 7 days. Skipped responses stay in Varly and the CSV download.
- Never twice. Varly never sends a delivered response again. The recipe A script also skips a response ID already in the sheet.
- Changed answers. The row has the answers as they were when Varly sent it; later changes don't reach the sheet. The results page in Varly always has the latest answers.
- Personal data. The row has what visitors wrote, the page, the device type and the country. No name, IP address or visitor ID, unless they typed it. An email question puts those addresses in your sheet, so share the sheet only with people who should see the answers.
- Deleting data. The sheet is your own copy. When Varly deletes answers (after the period in Privacy and GDPR, or when you delete the site), your rows stay. If a visitor asks you to delete what they wrote, also delete their row.
Stop sending responses
In Settings → Notifications, click Edit next to the destination, untick Every survey response and click Save, or click Remove. Rows already in your sheet stay.
For recipe A, you can also archive the deployment in Apps Script (Deploy → Manage deployments). The address then stops working.
Common problems
The Responses tab doesn't appear after the test message. The secrets in the address and script differ, CHANGE-ME is still in the script, or the secret is shorter than 30 characters. Fix the script, deploy a new version and click Send a test message again.
The test message arrives, but no responses. Check that Every survey response is ticked and the survey is live. Responses come within about an hour.
Still stuck? Email support@varly.ai and we'll help you out.
Related articles
- Get notifications in Slack, Zapier or MakeGet a message in Slack or any webhook when a test is ready, a variant may be broken, something suddenly gets worse, surveys get answers or data stops.
- Read your survey resultsSee how many visitors saw, started and finished a survey, where they stop, what they chose and wrote, and let Oran list the key findings and tag the answers.
- Create a surveyStart from scratch or from a template, write your questions and add follow-up questions that only appear when they matter.
- Privacy and GDPR: what Varly stores and for how longWhat Varly collects about visitors, what it never stores, retention periods, and sample privacy policy text.