We would like to geolocate visitor IP addresses, and for US-based addresses render a portion of the page to display state-specific options. I actually have the PHP working well to pull the 2-letter state value from a Geocoding API, but am wondering the best way to plug that into Craft PRO.
I'm assuming the logic should look something like this in the end:
- Check user for geo-cookie.
- If not present, geolocate the user with their 2-letter abbreviation and set the geo-cookie.
- If present, read the geo-cookie.
- With that value in hand, render page elements accordingly, using the 2-letter abbreviation as a filter. If the user has no 2-letter value (perhaps an international user), present some fall-back "default" content in those areas of the page. (And yes, I am well aware that these services aren't 100% accurate but some providers are fairly close and we can live with that.)
I have found Khalwat's cookie plugin for Craft, which looks like it should suit nicely. But as a newbie to both Craft and Twig, how do I now bring it all together?
OR should we just adapt Craft PRO's localization options for this instead, since it's built in? And if so, how would we pass the 2-letter value along to use that?