Collecting Country and Device Data

Today I'll implement the country and device data collection.

Country Data

Time to move on with the country data.

Last time I explored all the different options available. The Cloudflare approach doesn't work, so I have to pick another approach.

The easiest is probably resolving it from the browser timezone, but that's not accurate at all and I'm just not comfortable churning out shit, so I'm doing it properly. Shouldn't take too much time.

I will go with the second option (on the server) and I'll be using IP2Location. They have a go sdk, nice docs, the Country binary is only 2.6 MB, and the license is pretty generous, requiring only attribution.

That was pretty easy and seems to work pretty well. I'll stick with the Country db for now to reduce the image size and simplify the build. In the future, I'd want to get the bigger db (about 50MB) to support cities.

Device Data

For the device data, I'll just use ai to spit out a simple script that figures it out from the userAgent. There are libraries for this providing more advanced stuff, but I just don't think it matters that much, especially considering how heavy they are.

I'll group these by visitors.

The backend is done and working. Next time I'll display them.