Custom Geolocation Integration

OneTrust Cookie Compliance 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.

Cloudflare Support

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.

Note

This variable must be set before the OneTrust script executes.

<script type="text/javascript">
  // uncomment for customGeolocation        
  // 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, instead there is a default rule group that is configured in the admin console.