Forum Discussion

GeeG's avatar
GeeG
Helper
2 years ago

integrate geo-localisation to website

Does anyone know whether it is possible in the community to integrate geo-localisation when the website is loaded?

Then the user's location should be recognised and a layer should be displayed.
The content of the community is targeted for the German market. If someone lives in Switzerland, for example, the community will detect this and display the layer (pop-up).

  • Well, you can do that via IP geolocation, but it will require some third party service (wouldn't want to implement that myself in FreeMarker) like https://ip-api.com or similar where you can send the user's IP and get back geolocation data. You would most likely implement that in an endpoint on Khoros then use Javascript to call that endpoint and get the result back. But of course this can be circumvented via VPNs. Another option is to use browser geolocation but that requires the user to give permission in the browser first (which most probably won't do).

    An alternative approach (especially when it's only about Germany/Switzerland) could be to use the preferred browser language, although this depends entirely on what the user prefers, e.g. english speaking people living in switzerland would probably have their systems set to english and thus the preferred browser language would be english as well... but German people would probably have it as "de" or "de-DE" and Swiss people as "de-CH", you can simply check that by running

     

    var userLang = navigator.language || navigator.userLanguage;

     


    and then display a banner or not, this is relatively easy to do, but of course also the least reliable approach.