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.
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.
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);