Chartbeat API + Google Spreadsheets = Historical Data Cheat

March 6th, 2013 by Ben

You know you want it. The elusive white unicorn that is historical real-time Chartbeat data. We constantly challenge our products to give you better historical context in creative ways (like replay and typical performance), but we totally get that you may just want to log snapshots of your dashboard.

Well, you’re not alone. Many of our client-partners have built their own suites of cron jobs calling the Chartbeat API’s and storing in a database at some frequency to use historical information to give more context to their real-time decisions.

But, for the average pretengineer or those of us who don’t even have enough hours in the day to make time to eat breakfast, going the extra step to get more out of your Chartbeat data isn’t something you can make time for. Adding databases and time-based job schedulers take a backseat to the rest of your life.

Enter Google Apps Scripting & Google Spreadsheets.

With a Google Apps Script & Google Spreadsheet concoction, you can easily leverage the Chartbeat API to store only the data you care about, longer than 30 days.

Google Apps Scripting is a JavaScript cloud scripting language that provides easy ways to automate tasks and most notably, write directly into Google Spreadsheets. Here’s a simple function calling the Chartbeat Historical Traffic Series API with our default response settings (active visitors today, in 5 minute intervals):

getChartbeatTraffic

You can then write directly into a Google Spreadsheet of your choice  by converting the response into rows then inserting those rows on your favorite spreadsheet:

insertData

To take it a step further, you can schedule a frequency to run it the script behind the scenes. Maybe you want to log your daily max by traffic source every night, or store your average engaged time every-day at lunch. Adding triggers to automate your script is as easy as a couple drop-downs:

triggers

As always, if you have a question or maybe just want some code we’ve already built to copy into your Google Drive right away we’re here to help. Drop us a line, shoot us an email, or visit support.chartbeat.com.

Leave a Reply