Apps Script (advanced level) posted on 16th Oct 2017

Github pageviews

You can get things like number of stars and watchers etc from the GitHub REST API repository data, but pageviews are not tracked there. It is possible to get pageviews from another part of the API,  but only the last 14 days. If you want to track pageviews over time, you can try to do it with an Apps Script trigger that records the moving pageview count in a sheet. 
I already have all the components I need to mash this up pretty quickly, and they are all covered elsewhere on this site 

I’ll need the cUseful, cGoa and cGitJson libraries.

  • 1EbLSESpiGkI3PYmJqWh3-rmLkYKAtCNPi1L2YCtMgo2Ut8xMThfJ41Ex
  • 1v_l4xN3ICa0lAW315NQEzAHPSoNiFdWHsMEwj2qA5t9cgZ5VWci2Qxv2
  • 1_4RfsIW57fdzWh7T38O9IfGdTRgYbOSyC5PvsOm3a4GU1sxllw8blEUl

Credentials an authentication

Follow the steps for setting up Github authentication in Apps Script as described in Step by Step – Apps Script Oauth2 authentication with Github and Github service for Goa examples

As a reminder, my one off credentials setup looks like this using the credentials from the github console.

And my one off webApp to kick off the authentication process is

Run the oneoff script, publish doGet, run it once, copy the redirect url to the github console and we’re good to go. All that can be deleted if you want.

Tracking Sheet

My tracking sheet will look like this, and be updated daily by a triggered script. Each repo will have a row for each day that pageview stats were found.

Open the tracking sheet, or create it

Get a git handle

Where SETTINGS for me are. Set up your equivalent GitHub settings here

Get all your repos

Get all the pageViews for each repo

Create fiddler items records for each pageview observation

Update the fiddler by replacing or inserting observations

Write out the updated fiddler


You can trigger this to run as often as you want, but at least once every two weeks. Even with a few hundred repos, it’s pretty quick so every night is probably just fine. Now you can summarize and chart by summing each unique repo.

For more on drive SDK see Using Drive SDK

For help and more information join our community,  follow the blog or follow me on Twitter