Custom Geolocation Integration
OneTrust Cookie Consent leverages a geolocation service that, paired with the configurable Geolocation Rules in the application, allows flexibility in which banner and preference center are displayed to users when navigating to your website. This is done by leveraging CloudFlare to perform a reverse IP lookup that will return the general location of the user (approximately at the city level). The location is not stored and is only used to determine the applicable Geolocation Rule.
This is not a required step for Cookie Consent implementation. This should only be leveraged if you prefer utilizing your own geolocation service over OneTrust's out-of-the-box geolocation service.
The Cookie Consent script already performs the geolocation lookup and in general, you will not need to override this value. This article is applicable to those that are looking to override the general location of the user manually. For example, if you already use a geolocation service for other functions on your website and want to be certain that whatever location is returned is consistent across the site visitor's browsing experience, you can integrate your banner script with your existing service.
How It Works
The banner script calls a geolocation service to return the country, state and region values of the user accessing the website. These values are then passed into the functions determining which Geolocation Rule is being followed. The following variables reference the stored values:
-
stateCode
-
countryCode
-
regionCode
For custom geolocation integrations, an additional variable is added into the banner script that includes the three geolocation values. When a custom geolocation service is used, uncomment this section to initialize the OneTrust.geolocationResponse array with the values provided by your geolocation service.
This variable has to be set before the OneTrust script executes.
Example
This following is an example featuring hard-coded the location values. If you are using your own geolocation service, these values should be sourced from that service.
<script type="text/javascript">
var OneTrust = {
geolocationResponse: {
stateCode: 'KA',
countryCode: 'IN',
regionCode: 'EU', // Optional parameter
}
};
</script>
A boolean check is then used to evaluate the OneTrust.geolocationResponse variable and utilize the geolocation values from your geolocation service instead of calling OneTrust's service. If any invalid codes are passed, the geolocationResponse value will not be used and there is a fallback to the rule group that is configured in the admin console.