ankane / ahoy

Simple, powerful, first-party analytics for Rails
MIT License
4.24k stars 377 forks source link

Country code instead of country name #470

Closed xdmx closed 3 years ago

xdmx commented 3 years ago

Thank you for this gem, something that was surprising seeing was that it's saving the full country name in the geocode, is there a specific reason for saving it that way instead of saving just the country code?

I ask because the country name is more likely to change compared to the code (for example Swaziland was renamed to Eswatini in 2018, but the SZ code stayed the same), also it'd take less space in the db.

Reports should also benefit from having the code (in a map graph). And if the full name is needed it can always be retrieved at that point.

Thoughts?

brandoncordell commented 3 years ago

Not sure if it's helpful to you but I stepped around this problem using the normalize_country gem. You can just use NormalizeCountry(visit.country, to: :alpha2).

ankane commented 3 years ago

Hey @xdmx, thanks for the suggestion. I think the full name is a nice default since you don't need to do know how country codes map to names. We could have GeocodeV2Job return country_code as well so users can override the default with a custom geocode method. I believe some geocoding services also return the country code in the country field, fwiw.