4 ms·
Why all the trouble with hashes - can't you just do it on the client and not having to store any data at all? "For tracking unique page views" if(!sessionSt
by unilynx 7y ago
Why all the trouble with hashes - can't you just do it on the client and not having to store any data at all?
"For tracking unique page views"
if(!sessionStorage[location.href]) {
sessionStorage[location.href]=1;
navigator.sendBeacon("/unique-pagehit?" + encodeURIComponent(location.href));
}
"For tracking unique site views"
if(!sessionStorage["Hi!"]) {
sessionStorage["Hi!"]=1;
navigator.sendBeacon("/unique-sitehit");
}
"For tracking previous requests"
I'm not sure I fully understand what is being measured (is it session-only?). For the duration someone watched a page, you can use sendBeacon in onBeforeUnload. To detect a bounce, set a Math.random() in a session variable, send it at the start of the page, and have every page load send the previously stored random variable. Then count the unique random keys you received on the server - those are the bounces.
I know, in practice you'll need to trim sessionStorage, sanitize URLs, use something less-colliding than Math.random, dealing with new tabs, some polyfills and other robustness, etc... but I don't yet see why the tracking mentioned needs any user ids or hashing at all.
- JackWritesCode 7y agoGreat idea but we can't use sessionStorage under PECR, which is why we made this move. Plus we got rid of anything being stored on the user's machine.
- draw_down 7y ago> can't you just This is how you know you're about to make a really good point. Heck, I could code this up in a weekend!!
- ricardobeat 7y agoThis client-based scheme would be totally vulnerable to spamming / general messing about. Doing it in the server requires an actual request, and should still allow them to filter out attempts at gaming the system.