RvR

Primary Navigation

Oops, now it's even later than yesterday's start! 😅

Small change about yesterday's rather dire conclusion: Turns out that the analytics actually is working. Maybe it just takes some time to warm up? But I was able to see the page views in approximate real time (it maybe takes 30 seconds for google to see the result). This is overall pretty cool.

Guide to Yesterday

I introduced analytics to the blog yesterday. So how did I do it?

Look at Fresh

I first started off with the deno blog to see if they could help me out. I found this article titled How to use Google Analytics in Deno Deploy which sounds like exactly what I want. But it's almost a year old and the interwebs moves fast. They say:

Note that the module currently supports the classic Universal Analytics, though we are investigating moving to GA4.

And now it's 2023 and this is out of date. Google wants me to use the new thing, so that's what I did. Fortunately I look at the PRs for fresh quite frequently, and I happened to stumble upon this one.

Great, so I'll just "borrow" their code again. (Thanks guys!)

Create a Google Analytics (GA) Account

Just go here and create an account. It's all fairly straightforward.

Create Middleware

Create a _middleware.ts file where you want the analytics to be enabled. (I picked the routes folder, since I want all my routes to be tracked.) The source is borrowed from the PR mentioned above. I guess they'll add a GA module to fresh at some point.

Configure Deno Deploy

Don't be a newb and replace the line

const GA4_MEASUREMENT_ID = Deno.env.get("GA4_MEASUREMENT_ID");

with your actual key! You want to use an environment variable. The deploy docs have a great section about this.

Today's Result

Oops, I guess that's what I get for putting things off. Check back tomorrow for something more exciting!

Plan for Tomorrow

Cool, I've sorted out a basic version of history. I've gotten analytics setup. Now it's probably time to start adding some structure to the page. Where's the 'about me' or 'portfolio' or even a proper home page?

Next Post Previous Post Navigation