After getting my blog up and running I recently decided to add Google Analytics to it, to understand what content people were most interested in. At first this was amazing as I could see which blog posts were getting the most traction, but after a while it became a bit of a pain to log into

my Google Analytics dashboard when all I wanted was to quickly see the

page view count of a blog post.

Wouldn’t it be easier to just go to my site and see the page view count displayed on each blog post? It most certainly would, and so that’s what I set out to build. Since Google Analytics has a powerful API, all I really needed to do was call that API and retrieve my information, but ideally I wouldn’t want to be making that call directly from this blog as that would mean exposing my API key and any other sensitive information to anyone who knows hows how to press F12.

TL;DR Here is the GitHub repository for the serverless function that I wrote for retrieving Google Analytics page views.

Since this blog is setup to be completely free (aside from the domain name), leveraging Netlify for the hosting, Cloudinary for images and Ghost

for the content management system, I definitely wouldn’t want to pay

for running a back-end (especially one that was simply fetching stats

from Google Analytics). And that’s where Netlify functions come in.

Netlify has a very generous free plan that allows 125k function

executions and 100 hours execution time, a quota that this blog would

never reach within 1 month, and this seemed like a perfect fit for what I

needed.

#netlify #serverless #expressjs #google-analytics #software-development #serverless-top-story #automate-page-view-capturing #netlify-analytics-serverless

How To Get Page Views From Google Analytics via a Netlify Serverless function
3.05 GEEK