Setting up geolocation-based personalization
Set up your channel to use Acoustic Personalization geolocation services to display personalized content based on the location of the visitor to the channel.
Overview
Acoustic Personalization Geolocation service enables you to fetch the geographical location (latitude and longitude) of a visitor to your channel. It requires user consent to use the browser location services. If the visitor does not allow the location services to be used, personalization will not occur.
Geolocation services can be used to display a more targeted personalized content to the visitor of your channel. For example, you may choose to display certain offers to the visitors from Florida based on a local event, while you want the rest of your visitors to see a different content on your channel. In this scenario, you can use Acoustic Personalization geolocation services to show the event-specific personalized content to your channel visitors from Florida.
Prerequisites
- Acoustic Personalization uses Geolocation API to get the visitor location. This API let you discover, with the user's consent, the user's location. The Geolocation API only works on secure contexts (HTTPS). If your site is hosted on a non-secure origin (such as HTTP), any requests for the user's location will not work.
- This code snippet is relevant for Personalization Library version 1.2.0 or later.
Configuring Geolocation
- Copy the following code snippet and paste it, preferably into the HEAD tag
of the index.html page of your Single-Page Application or Multi-Page
Application.
<script> if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(success,error); } function success(position) { window.geoposition = {}; geoposition.lat = position.coords.latitude; geoposition.lon = position.coords.longitude; } function error() { console.log('Cannot get location'); } </script>
References
For information about creating and using geolocation-based rules for personalization, see the topic Using geolocation for personalization