I Had Removed Google Analytics and Google Services from My Website Why I Did It?
donislawdev.com
donislawdev.com
Public analytics seems interesting - have you been able to do anything particularly interesting by leveraging this capability?
I usually open source my code, I just haven't gotten around to it for this one in particular. Might be worth doing if people are interested.
> The only thing I capture is the page that was visited, when it was visited, and the domain of the referrer (to see what the source is). The tracker is meant to be used for blogs where I don't control the server, such as Github Pages, so there's a single AJAX call to my self-hosted server.
To be honest, I'm not entirely sure how I'd solve this without the 'single AJAX call' but I guess it makes sense to start there!
Curious how you implemented it - again, I'm not a rocket surgeon and this is just like a 3 second analysis of the problem space, but it's always neat to check out other people's implementations for common, shared problems
You're right: if you don't control the server, you basically can't intercept any requests without this extra AJAX call, or some similar mechanism like a tracking image served from your own server. Essentially, you need to make a request to your own server at some point!
The architecture is pretty simple:
1. Insert the AJAX request into each page, sending the page URL and the referrer in the payload. Because I found some weirdness with tools like Pocket serving my pages from some cached location, I use my static site generator (Jekyll) to embed the page URL into each page, instead of pulling it from the client side.
2. I support multi-tenancy on a single tracking server by using multiple domain names. Based on the incoming domain name, I have nginx attach an additional header to the request that says which site is being tracked. This way, I can have my personal blog and my newsletter website both tracked by the same tracking server instance.
3. Then, it's just a matter of storing the data (page URL, time of visit, referrer domain, which site) into a SQLite database.
4. And of course, I have a small web UI to view the data.
Note that I don't do anything with the IP address of the visitor. That's personal data that I don't track.