ihucos / counter.dev

Web Analytics made simple
https://counter.dev
GNU Affero General Public License v3.0
900 stars 40 forks source link

Allow adding country from proxy #102

Closed tom-b-wright closed 1 year ago

tom-b-wright commented 1 year ago

When tracking calls are proxied through a proxy before Cloudflare the visitor country is set to the proxy's location. Let's enable this overwrite so that we can have the proxy.

ihucos commented 1 year ago

It's deployed. Thank you very much. Do you want to show how you are handling this on the client side, that is passing in the country parameter. That would help other folks looking into this!

thx again

tom-b-wright commented 1 year ago

Hi Irae,

Thanks for accepting the pull request and also for deploying it so quickly.

A few words: I think GDPR consents are a nightmare from the UX perspective. A few days ago I finally spent some time to find a way to get rid of GDPR consents on my site. I read the 2 or 3 sources available on the internet about how to track page views without consent. I tried to proxy the tracking calls towards Google Analytics through my 'handmade proxy' but that was not really working out and I wasn't able to kick out the analytics script from my site. I was lucky to found your solution and it is literally perfect for my use case. I was at a point to develop something simple for myself where I can track page views and corresponding countries only, but writing the UI takes a considerable effort. The backend part is also tricky.

What I'll do is this: modify the tracking javascript code so that it sends all events to my proxy where I will detect the country in the similar way that the counter.dev server extracts it from the Cloudflare HTTP header. This country code will be added as a query argument and this enhanced request will be forwarded to the counter.dev server.

I use this tiny little proxy from the Jetty web server for my purpose. https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/proxy/ProxyServlet.html

ihucos commented 1 year ago

Gotcha 👍