Serverless Function for Google Analytics
A simple serverless function, using Express.js, that retrieves Google Analytics Page View results, and can be deployed to Netlify.
The solution is inspired by this Netlify blog post.
The app is hosted at
/.netlify/functions/server. Examples of
how to access the Express.js endpoints:
* curl https://netlify-express.netlify.com/.netlify/functions/server/getViews * curl https://netlify-express.netlify.com/.netlify/functions/server/getViewsByPagePath?pagePath=/securing-traefik-dashboard-with-azure-ad/
In order to run locally, rename the file
.env and fill in the required secrets, which you can obtain by following this blog post.
Deploying to Netlify
You can use the Netlify Deployment button to deploy the function to your Netlify account. After deploying your function you will need to set the environment variables so that the function works correctly.