Coaches CornerCoaches Corner KPIs

Connect your form

Five minutes, once. Your form keeps working exactly as it does now.

This is the real script, with a placeholder where your own private address would be. In your own workspace it arrives with the address already filled in — there is nothing to edit.

Connect your check-in form
Your Google Form, posting straight in

There is no Google account to connect and nothing to authorise. You paste a short script into the response sheet your form already writes to, and it posts each check-in here as it is submitted. The script sends four things — who submitted, the name they gave, the date, and Google's own id for the response. It does not send their answers. Your clients' weight, measurements and everything they write to you stay in your form, where they already are.

  1. 1
    Open your check-in form's response sheet
    In Google Forms, open the Responses tab and click the green Sheets icon. That opens the spreadsheet your answers already go into.
  2. 2
    Open Extensions → Apps Script
    From that spreadsheet's menu. A code editor opens in a new tab with an empty function in it.
  3. 3
    Replace everything there with the code below
    Select all of it, paste this over the top, and save. Your dashboard address is already in it — there is nothing to fill in.
  4. 4
    Add the trigger that runs it
    In the Apps Script editor, click the clock icon (Triggers) in the left sidebar, then Add Trigger. Choose sendCheckInToDashboard, pick 'From spreadsheet' and 'On form submit', and save. Google will ask you to allow the script — it is your own script, running in your own account.
  5. 5
    Submit a test check-in
    Fill in your own form once. It should appear on the Check-ins tab within a few seconds. If it does not, the Apps Script editor's Executions tab says why.
/**
 * Sends each check-in to your dashboard when someone submits this form.
 *
 * It sends FOUR things: who submitted, the name they gave, the date, and
 * Google's own id for the response. It does NOT send their answers — those
 * stay in this form and in this sheet, where they already are.
 */
function sendCheckInToDashboard(e) {
  var URL = "https://kpi.coachescorner.io/api/integrations/checkin/your-private-address-appears-here";

  try {
    var answers = {};
    var items = (e && e.response) ? e.response.getItemResponses() : [];
    for (var i = 0; i < items.length; i++) {
      var title = String(items[i].getItem().getTitle() || "").trim().toLowerCase();
      answers[title] = items[i].getResponse();
    }

    var email = pick_(answers, ["email address", "email", "e-mail", "your email"]);
    if (!email && e && e.response && e.response.getRespondentEmail) {
      email = e.response.getRespondentEmail();
    }
    if (!email) {
      console.warn("No email on this response - nothing sent.");
      return;
    }

    var date = isoDate_(pick_(answers, ["check in date", "check-in date", "checkin date", "date"]));
    if (!date && e && e.response && e.response.getTimestamp) {
      date = isoDate_(e.response.getTimestamp());
    }

    var payload = {
      email: String(email).trim(),
      name: pick_(answers, ["full name", "name", "your name"]) || null,
      date: date,
      responseId: (e && e.response && e.response.getId) ? e.response.getId() : null
    };

    var res = UrlFetchApp.fetch(URL, {
      method: "post",
      contentType: "application/json",
      payload: JSON.stringify(payload),
      muteHttpExceptions: true
    });

    if (res.getResponseCode() >= 300) {
      console.error("Dashboard refused the check-in: " + res.getContentText());
    }
  } catch (err) {
    // Never throw: a failure here must not stop the client's form from
    // saving their check-in. The answers are safe in the sheet either way.
    console.error("Could not send check-in: " + err);
  }
}

/** First answer whose question title matches one of these, or "". */
function pick_(answers, titles) {
  for (var i = 0; i < titles.length; i++) {
    var v = answers[titles[i]];
    if (v) return v;
  }
  return "";
}

/** A Date or a string into YYYY-MM-DD, or null. Never a locale-formatted date. */
function isoDate_(value) {
  if (!value) return null;
  var d = (value instanceof Date) ? value : new Date(value);
  if (isNaN(d.getTime())) return null;
  return Utilities.formatDate(d, Session.getScriptTimeZone(), "yyyy-MM-dd");
}