• Platform
    • The Osano Platform Overview

      Get an overview of the simple, all-in-one data privacy platform

    • header__icon-1
      Cookie Consent

      Manage consent for data privacy laws in 50+ countries

    • user-square
      Subject Rights Management

      Streamline and automate the DSAR workflow

    • assessments primary 200
      Assessments

      Efficiently manage assessment workflows using custom or pre-built templates

    • Unified Consent primary 200
      Unified Consent & Preference Hub

      Streamline consent, utilize non-cookie data, and enhance customer trust

    • data mapping primary 200
      Data Mapping

      Automate and visualize data store discovery and classification

    • shield-tick
      Vendor Privacy Risk Management

      Ensure your customers’ data is in good hands

    • Features & Integrations

      Key Features & Integrations

    • Privacy Templates
    • GDPR Representative
    • Consult Privacy Team
    • Regulatory Guidance
    • Integrations
  • Solutions
    • By Regulation
    • CPRA

      Discover how Osano supports CPRA compliance

    • CCPA

      Learn about the CCPA and how Osano can help

    • GDPR

      Achieve compliance with one of the world’s most comprehensive data privacy laws

    • By Organization Type
    • Icon (10)
      Start-Up

      Don’t let data privacy compliance get in the way of growth

    • Icon (11)
      Mid-Sized

      Preserve your competitive edge

    • Icon (12)
      Enterprise

      Manage data privacy at scale

    • By Use Case
    • Path
      Consent Management

      Manage consent without the complexity

    • Icon (14)
      DSAR Automation

      Never miss a DSAR deadline again

    • Icon (16)
      Privacy Program Management

      Build and grow an end-to-end privacy program

    • Icon (15)
      Vendor Risk Management

      Regain insight and control over your customers’ data

  • Resources
    • Resources

      Key resources on all things data privacy

    • book-open-01
      Articles

      Expert insights on all things privacy

    • Icon (25)
      Resource Center

      Key resources to further your data privacy education

    • hand a heart icon primary 200
      Customer Stories

      Meet some of the 5,000+ leaders using Osano to transform their privacy programs

    • globe icon primary 200
      U.S. Data Privacy Laws

      A guide to data privacy in the U.S.

    • code icon primary 200
      Product Updates

      What's the latest from Osano?

    • Become a Privacy Insider

      Data privacy is complex but you're not alone

    • envelope icon primary 200
      The Newsletter

      Join our weekly newsletter with over 35,000 subscribers

    • Icon (17)
      The Podcast

      Global experts share insights and compelling personal stories about the critical importance of data privacy

    • book-open-01
      The Book

      Osano CEO, Arlo Gilbert, covers the history of data privacy and how companies can start a privacy program

    • Icon (30)
      Events

      Upcoming webinars and in-person events designed for privacy professionals

    Latest Blog post

    Two professionals discussing

    It’s Time for Privacy Pros to Make a Strategic Shift

    The importance of effective data privacy can no longer be ignored.

    Read Now
  • Company
    • Vector
      About Us

      The Osano story

    • Icon (25)
      Careers

      Become an Osanian and help us build the future of privacy!

    • Icon (26)
      Contact

      We’re eager to hear from you

    • 
      Our Pledge

      No fines, no penalties

    • Icon (27)
      Data Licensing

      Add Osano data privacy ratings and recommendations to your application

    • Icon (28)
      Osano Swag Store

      Increase Trust. Stay Compliant. Get Cool Swag.

    • Icon (29)
      Press & Media

      Inquiries and Osano in the news

    • Icon (30)
      Partners & Resellers

      Interested in partnering with us?

  • Pricing
  • Sign In Book a Demo

Location Services

How to geolocate users with Cookie Consent

Architecture

Cookie Consent contains three modules named Popup, Law and Location.

  • Popup can be used on it’s own regardless of it’s location, and contains any and all functionality for displaying a popup on screen.
  • Law accepts the popup options and a country code. Using the country code it modifies the popup options, enabling/disabling certain functionality in order to comply with the law specified by that country
  • Location is simply a tool for getting the two letter country code that the user is in.

Together, these modules: get the country code, apply the law specific to that country, and display the popup (if necessary)

In code form, a service looks like this:

{ url: <string> //The location of the service API isScript: <boolean>, //Whether to use a script tag or a XMLHttpRequest data: <object>, //Useful if the service requires post data headers: <array>, //Useful for setting service specific header callback: <function(done, response)>, //A handler for understanding the response }

The callback provides a done callback. If you need to make additional requests, call done with the country code when you’re finished. Otherwise, just return the country code

Example:
{ url: '//example-service/script.js', isScript: true, callback: function (done, response) { // We just downloaded the 'script.js' which defined a third party object. if (!window.MyService) { done(new Error('The JavaScript file failed to download and define MyService')); } MyService.locateMe(function(response){ done({code: response.countryCode}); }, function(err){ done(new Error(err)); }); }, }

Services

In order to find the location, Cookie Consent uses third-party location services. These third-party services usually provide an API that can be accessed over the internet.

To integrate a new service, you need to define the service location, the type of request (XMLHttpRequest vs <script>) and how the tool should interpret the response.

To do this, define a new service like so:

cookieconsent.initialise({ ...popupOptions, location: { serviceDefinitions: { mynewservice: function(options) { return { url: '//example-service.com/json', callback: function(done, response) { // This function must parse the 'response' and return the country code, or fail. // If this function doesn't fail correctly, then the next service will not run. // Therefore, it's generally best to add a <em>try {...} catch () {...}</em> block try { var json = JSON.parse(response); if (json.countryCode) { return {code: json.countryCode} } throw 'Could not find a country code in the response'; } catch (err) { return new Error('Invalid response (' + err + ')'); } }, }; }, }, services: [ 'mynewservice' ] } });

Above, you can see that we first define our service, then we use it by adding it to the services array. We can add it simply by passing the name of it as a string.
Some service definitions may be more complicated though, and require configuration.

To do this, you can pass an object instead:
services: [ { name:'mynewservice', mySpecialOption: 'some value', KEY: 'uUCGtoyeiH5gsm3Wn2cp9D1Z1deHcpBG8ySA4hYBcQd20Z4C6AwGKqln7mtEfGN' } ]

Then, when defining your service, the options are passed through like so:

mynewservice: function(options) { // `options.mySpecialValue` and `options.KEY` now exist return { url: '//someurl.com?apiKey='+options.KEY // ...serviceDefinition }; }

As well as passing an object with options into the ‘services’ array, you can also pass a function that returns an object, just because.

Notes

Above, we integrated options.KEY with the url by simply appending the two string. If you’re lazy, there is an option called interpolateUrl which will automatically interpolate a string with the values of an object. Use it like so:

serviceDefinitions: { mynewservice: function(options) { return { url: '//example-service.com/json?key={api_key}&someValue=1&callback={callback}', isScript: true, // use this flag to tell the tool to download // the resource as a script tag (using JSONP) callback: function(done, response) { // handle response }, }; }, }, services: [ { name: 'mynewservice', interpolateUrl: { api_key: 'uUCGtoyeiH5gsm3Wn2cp9D1Z1deHcpBG8ySA4hYBcQd20Z4C6AwGKqln7mtEfGN' } } ]

The {callback} string can be used in the URL to automatically write the JSONP callback. It is appended with Date.now() to prevent global namespace collisions.

What's New at Osano

Introducing Osano Privacy Legal Templates

Now, with Osano Privacy Legal Templates you can get started faster by leveraging templates generated by our global team of privacy experts.

Learn more

Introducing DSAR email intake

Capture data subject rights requests with the convenience of email and the efficiency of a dedicated intake form.

Learn more

New reworked DSAR and discovery

We've reworked and redesigned Osano Subject Rights Management and Data Discovery, unifying them into a single, seamless experience and creating automation to save you time.

Learn more

Stay GDPR compliant under new French ruling

Privacy regulators at the CNIL in France recently declared that Google Analytics violates GDPR. Osano’s new block list feature can disable Google Analytics in France to keep you compliant while allowing you to use Google Analytics in regions where it is still legal.

LEARN MORE

New in May 2022: DSAR conditional fields, 28 new integrations, and more!

Customize DSAR forms with conditional fields, serve consent banners in additional languages, use 28 new integrations for Data Discovery, and more! Check out our latest product announcement blog for demos, links, and more information.

LEARN WHAT’S NEW IN MAY

View more product updates

Osano product & engineering teams have been hard at work. View the full list of all product updates.

View Product Updates