Add Automated Metrics Collection with Zapier

Hey guys and gals!

I wanted to share with you all a way that I have been using to automate our metrics collection. I am using Zapier to do all of it and it has greatly simplified my life. :slight_smile:

Anyways, since Zapier allows Multi-Step" zaps I am able to make a call into our site and pull json for each of the metrics I care about and then add them straight to a Google Sheets spreadsheet using Zapier. I then usee Google Data Studio to display the results.

Zapier has a action called “Code by Zapier” that allows you to run some short NodeJS scripts that can do anything you want really. So I use it to make a get request to the JSON pages for each of the metrics I track.

It looks something like this:

fetch('https://YOUR_ROOT_SITE_HERE/admin/reports/visits.json?api_key=YOUR_API_KEY_HERE')
  .then(function(res) {
    return res.json();
  })
  .then(function(json) {
    callback(null, json.report.data[json.report.data.length - 2]);
  })
  .catch(callback);

I then am able to take the data from the response and put it into a google sheet. Pretty simple really. :slight_smile:


Here are my code samples for each metric that I pull. Each one pulls the previous day’s data.

User Visits:

fetch('https://YOUR_ROOT_SITE_HERE/admin/reports/visits.json?api_key=YOUR_API_KEY_HERE')
  .then(function(res) {
    return res.json();
  })
  .then(function(json) {
    callback(null, json.report.data[json.report.data.length - 2]);
  })
  .catch(callback);

New Sign-Ups:

fetch('https://YOUR_ROOT_SITE_HERE/admin/reports/signups.json?api_key=YOUR_API_KEY_HERE')
  .then(function(res) {
    return res.json();
  })
  .then(function(json) {
    callback(null, json.report.data[json.report.data.length - 2]);
  })
  .catch(callback);

New Topics:

fetch('https://YOUR_ROOT_SITE_HERE/admin/reports/topics.json?api_key=YOUR_API_KEY_HERE')
  .then(function(res) {
    return res.json();
  })
  .then(function(json) {
    callback(null, json.report.data[json.report.data.length - 2]);
  })
  .catch(callback);

New Posts:

fetch('https://YOUR_ROOT_SITE_HERE/admin/reports/posts.json?api_key=YOUR_API_KEY_HERE')
  .then(function(res) {
    return res.json();
  })
  .then(function(json) {
    callback(null, json.report.data[json.report.data.length - 2]);
  })
  .catch(callback);
11 Likes

Awesome!

Check out DiscourseMetrics if you’re insterested in a similar solution, but with a nice dashboard UI, weekly/monthly reports+++.

A post was split to a new topic: DiscourseMetrics.com privacy policy?

How do I achieve this with discourse behind a reverse proxy (outer NGINX)? It seems like this fetch request is not making it through to the docker container:

Or am I wrong in assuming that this has so far been tested only with the basic setup, i.e. without a reverse proxy in front of the discourse container?