@segment/in-regions

đź”’Privacy-first location detection library for browsers in-regions is a library for roughly detecting whether or not a website user is in a given "region". without requiring a roundtrip to your server or a lookup against a GeoIP database.

Usage no npm install needed!

<script type="module">
  import segmentInRegions from 'https://cdn.skypack.dev/@segment/in-regions';
</script>

README

in-regions

đź”’Privacy-first location detection library for browsers in-regions is a library for roughly detecting whether or not a website user is in a given "region". without requiring a roundtrip to your server or a lookup against a GeoIP database.

It uses the browser's timezone (via the brilliant jstz and locale (navigator.languages) to infer a user's location. in-regions trades absolute accuracy for a cautious approach that's more lightweight and respectful of end-user privacy.

At Segment, we use in-regions to ask the question "Should we ask this user for their consent before tracking first-party data?". Because of this, we believe in casting a wider net, and are fine with trading accuracy for a more respectful approach towards consent.

Supported Regions

As we prepare for CCPA, in-regions supports "EU" and individual US states and territories (via npm package 'us') as valid regions.

Usage

npm install @segment/in-regions

Use in-regions to generate your own custom location method. Our inRegions function is a higher-order function that returns a custom function for your custom use cases.

For example, to generate a function that tests whether or not a user is in the EU:

import inRegions from '@segment/in-regions'

const inEU = inRegions(["EU"])
// => () => true/false

If you wanted to include both residents of California and EU residents (like we are!):

const inCustomRegion = inRegions(["EU", "CA"])

const isInCustomRegion = inCustomRegion() // isInCustomRegion would be 'true' if current user is in EU or CA

in-regions also wraps, and exports all methods available in in-eu:

import { isInEUTimezone, isEULocale, inEU } from '@segment/in-eu'

/*
 Only checks the browser timezone.
 Useful for checking if someone is physically present in the EU
*/

isInEUTimezone()
// => true | false

/*
 Only uses the browser's language/locale
 Useful for checking if someone speaks an european language accounting
 for locale. e.g. pt-PT (portuguese from Portugal)
*/

isEULocale()
// => true | false

inEU()
// => true | false