4 ms·
For sure! Because this was for my own use, I need to put in some documentation for it to be useful for others. That, and pick a name :) It's all on my TODO list
by akdas 5y ago
For sure! Because this was for my own use, I need to put in some documentation for it to be useful for others. That, and pick a name :) It's all on my TODO list.
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.