Google Forms

Set up yourself · 10 min

Every Google Form response becomes a lead in the project

Your Google Forms lead URL

Your lead URL appears here when you open this page from the LeedsApp app: open the project, then Lead integrations and Google Forms.

The script

Apps Script
// LeedsApp: sends every Google Form response to LeedsApp as a lead.
// Paste your LeedsApp lead URL between the quotes below.
const LEEDSAPP_URL = 'PASTE_YOUR_LEEDSAPP_LEAD_URL_HERE';

function sendToLeedsApp(e) {
  const answers = {};
  e.response.getItemResponses().forEach(function (item) {
    const value = item.getResponse();
    answers[item.getItem().getTitle()] = Array.isArray(value) ? value.join(', ') : String(value);
  });

  // Finds the first answer whose question title matches the pattern.
  function pick(pattern) {
    const title = Object.keys(answers).find(function (t) { return pattern.test(t); });
    return title ? answers[title].trim() : '';
  }

  const lead = {
    name: pick(/name/i),
    phone: pick(/phone|mobile|whatsapp/i),
    email: e.response.getRespondentEmail() || pick(/e-?mail/i),
    city: pick(/city|town|location/i),
    responseId: e.response.getId(),
    formTitle: e.source.getTitle(),
    answers: answers
  };

  const res = UrlFetchApp.fetch(LEEDSAPP_URL, {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(lead),
    muteHttpExceptions: true
  });
  console.log('LeedsApp replied ' + res.getResponseCode());
}
Open this page from the LeedsApp app to fill in your lead URL.

Set it up in Google Forms

1
Open the form's script editorOpen your form in Google Forms (edit view). Click the ⋮ (More) button at the top right and choose Apps Script. A new tab opens with an empty script.
2
Paste the LeedsApp scriptDelete everything in the editor and paste the script below. Your lead URL is already filled in. Click Save (the disk icon).
3
Add a triggerIn the left bar click Triggers (the alarm-clock icon), then + Add Trigger at the bottom right.
4
Run it on form submitChoose function sendToLeedsApp, event source From form, event type On form submit. Click Save.
5
Allow accessGoogle asks for permission. Pick your account, click Advanced, then Go to (project name) (unsafe). If you see checkboxes, tick Select all. Then click Allow (or Continue). If no window opens, allow pop-ups for script.google.com and save the trigger again.
6
Send a test responseFill in your form once, for example Ravi Kumar, 9876543210, ravi@example.com, Chennai. In the script tab open Executions and click the latest sendToLeedsApp run: its log should say LeedsApp replied 200.

What LeedsApp saves

Google Forms sendsSaved on the lead asQuestion with "name" in its titleNameQuestion with "phone", "mobile" or "WhatsApp"Mobile numberCollected email, or question with "email"EmailQuestion with "city", "town" or "location"CityEvery other questionNotes
Lead source: Google Forms. The script finds the answers by the words in your question titles, so keep words like Name, Phone and City in them. Each response is sent once; the same response sent again is saved once.

If leads don't arrive

  • Nothing arrives: check the trigger is From form · On form submit and the function is sendToLeedsApp. A function named onFormSubmit does nothing by itself.
  • Open Executions in the script. A red failed run shows the error; a missing run means the trigger is not saved.
  • No phone on the lead: rename the question to include the word Phone or Mobile.
  • If you copy the form, the copy needs its own trigger.

Need help? Write to support@leedsapp.com