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.
What you need
- The free Counter app for Android.
- A Google account, for Google Sheets and Apps Script.
- An internet connection on the phone when you count.
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
- Click Deploy > New deployment and choose the type Web app.
- Set Execute as to Me and Who has access to Anyone.
- 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:
- Changes: one row for every change.
- Reaches the value or Is a multiple of: one row at the milestones only.
- Every day at: one snapshot row a day, whatever the value is.
As the action choose Webhook and fill in:
- URL: the web app URL from Step 3.
- HTTP method: POST.
- Payload template: the JSON below.
{
"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:
- Check that the deployment access is Anyone, not "Anyone with a Google account".
- If you edited the script after deploying, publish it again from Deploy > Manage deployments with a new version. The URL stays the same.
- Make sure the phone is online: the webhook is sent at the moment of the count, and counts made offline are not sent later.
"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
- A daily snapshot of a habit counter, charted in Sheets over months.
- A stock sheet that several phones write to, one row per movement.
- A log of every visitor counted at the door, with the time of each entry.
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