Serverless Analytics
I’m annoyed by Google’s Analytics. It works great, but it’s heavy and overkill for my needs. Not to mention that it’s very privacy-intrusive. It’s not like I don’t give Google all my data already, but perhaps you don’t make that same choice, and you shouldn’t be forced into it simply by visiting my website.
I’ve been looking for a solution that lets me see what content folks are looking at and where they’re coming from, while being extremely cheap, and easy to maintain. All while reducing the privacy impact. I toyed with building something, but got lost in the “what is the cheapest way I can leverage AWS for this” trade-space.
A couple weeks ago I found Ricardo Sueiras’s post about the serverless analytics solution he started using. It sounded good, so I tried it out. It leverages a project by Rehan van der Merwe.
I’m using that solution now, and want to document how I’ve set it up. I’ve tried to make it easy to set up for you, too… It hasn’t produced a noticeable impact in my AWS bill, and you can see the cost estimates on Rehan and Ricardo’s sites where I’ve linked above. I have fewer than 200 hits in a month, generally - so you see why “extremely cheap” is a goal.
- In AWS switch to us-east-1, create a Route53 Hosted Zone. I gave Route53 a zone to manage that’s a subdomain for an existing domain I own.
- In AWS us-east-1, create a public certificate for that Route53 zone. This is a little tricky actually. If your Hosted Zone is
example.com
, and you want your analytics to be atanalytics.example.com
, your certificate must cover at leastanalytics.example.com
and*.analytics.example.com
. git clone
my repo- Make sure NPM is already installed for you - on Debian it’s just
apt install npm
- Copy
secrets_example.ts
tosecrets.ts
and fill it in. You’ll see there are comments in there explaining what’s needed. Steps 1 and 2 will have created resources you can pullzonecert
,zoneid
, andzonename
from. Everything else you get to choose yourself. - Run
npm install
to setup prerequisites. - Run
npm run build
to build the site. - This deployment leverages AWS’s Cloud Development Kit. If you haven’t used that before run
./node_modules/aws-cdk/bin/cdk bootstrap
to bootstrap your AWS account for it. - Run
./node_modules/aws-cdk/bin/cdk deploy APPNAME
, filling in APPNAME with the value you put insecrets.ts
.
If you have multiple AWS profiles setup you may have to prepend those last two commands with AWS_PROFILE=whatever