Log a counter to Google Sheets

Send every count to a spreadsheet row: counter name, value, unit and time. The Counter app for Android fires a webhook, and a few lines of Apps Script write the row. No Zapier, no other service in between.

Guide for the Counter app on Android. Needs a Google account and about ten minutes.

What you need

Step 1: Create the sheet

Create a new Google Sheet and type four headers in the first row: Time, Counter, Value, Unit.

Step 2: Add the script

In the sheet, open Extensions > Apps Script, delete what is there and paste this:

function doPost(e) {
  var data = JSON.parse(e.postData.contents);
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
  sheet.appendRow([new Date(Number(data.time)), data.counter, data.value, data.unit]);
  return ContentService.createTextOutput('ok');
}

It reads the JSON that Counter sends and appends one row to the first tab of the spreadsheet.

Step 3: Deploy it as a web app

  1. Click Deploy > New deployment and choose the type Web app.
  2. Set Execute as to Me and Who has access to Anyone.
  3. Authorize the script when Google asks, then copy the Web app URL. It ends in /exec.

Step 4: Add the webhook rule in Counter

Open the counter and add a rule under What it does on its own. Pick the event:

As the action choose Webhook and fill in:

{
  "counter": "${counter.title}",
  "value": ${counter.value},
  "unit": "${counter.unit}",
  "time": ${timestamp}
}

Counter replaces the ${...} variables with live data when it sends. ${timestamp} is the time of the count in milliseconds, which the script turns into a date.

Step 5: Test it

Tap + on the counter. A new row appears in the sheet within a few seconds. If it does not:

Keep the URL private: anyone who has it can add rows. For an extra check, add "key": "a-word-you-choose" to the body and make the script return early when data.key is not that word.

Things you can build

Only need the numbers once in a while? The history of a single counter can also be exported as CSV from its statistics, with no setup. For the full list of webhook options (authentication, retries, timeout), see the FAQ.

Start logging your counts

Free download. No account required. Unlimited counters.

Get it on Google Play