benvinegar / counterscale

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

prevent tracking localhost #57

Open kandros opened 5 months ago

kandros commented 5 months ago

fixes #50

I opted for skipping sending the request instead of rejecting it in collectRequestHandler Does it cover your usecase @benvinegar?

benvinegar commented 5 months ago

First off, thank you for picking up an issue and contributing. 🙏

Does it cover your usecase @benvinegar?

Some thoughts that come to mind:

You're welcome to try adding that; if you do, I'd look at prior art from other analytics tracking scripts and see what other folks do. For example, Plausible had a ticket around this and has since made it possible to track local scripts.

All of this makes the issue more complicated than at first blush (my fault for not clarifying more).

xuelink commented 5 months ago

@kandros I think updating it with this condition, gonna fix all possible localhost scenarios

if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(window.location.hostname)) {
    console.warn("[counterscale] localhost detected, datapoints will not be collected");
    return;
}