benvinegar / counterscale

Scalable web analytics you run yourself on Cloudflare
https://counterscale.dev
MIT License
1.51k stars 66 forks source link

Adding Bounce Tracking #116

Open S-Makrod opened 11 hours ago

S-Makrod commented 11 hours ago

Description

Adds tracking of bounces to collect.ts and query.ts. The implementation follows the approach outlined in the article https://notes.normally.com/cookieless-unique-visitor-counts/. I modified the existing implementation in collect.ts a bit to actually increment the Last-Modified header by one second instead of putting the current time. This is closer to the implementation in the article and allows the code to dynamically calculate the visits and determine the bounce value. Once the bounce value is determined it is written by the analytics engine.

Side note: I did not want to touch the checkVisitorSession function but maybe it would be a good idea to merge this with the getBounce function?

In query.ts I updated the queries to also return the bounce value.

In resources.stats.tsx I updated the route to display the bounce value.

I have the changes deployed at: https://bounce-tracking.counterscale-7bi.pages.dev/dashboard?site=counterscale-dev

Note

Hi Ben, I am a student from the University of Toronto and attended the guest lecture you held for CSCD01 for the Fall 2024 semester. One of the things you mentioned was that you are working on Counterscale. I got pretty interested and saw this issue which I thought I could tackle. I am new to the repository so I am not too sure if I did everything correctly and I may have missed some details but please let me know what you think when you get a chance!

Issue

This closes #47