@nacelle/segmentation-sdk
v0.0.2
Published
## How to use
Downloads
5
Maintainers
Keywords
Readme
Nacelle Segmentation SDK
How to use
npm install @nacelle/segmentation-sdk
Localizer Initialization
import { Localizer } from '@nacelle/segmentation-sdk'
const localizer = new Localizer({
defaultLocale: 'en-US',
navigator: window.navigator,
positionOptions: {
enableHighAccuracy: true,
maximumAge: 30000,
timeout: 27000
}
})
API
getPosition
- Utilizes the browser's
navigator
API to request location services from user.
const position = await localizer.getPosition()
/**
* position =>
* { coords: { latitude: 32, longitude: -117, ... } }
* /
getLocation
- Utilizes external service to get more location details.
const location = await localizer.getLocation(32, -117)
/**
* location =>
* { address: { country_code: "us", ... }, lat: "32", lon: "-117" }
* /
getIp
- Pings Cloudflare to get some IP data.
const { ip } = await localizer.getIp()
/**
* ip =>
* "2600:8801:9300:90a:g043:c54a:fg1d:12rd"
* /
getLocale
- Utilizes the browser's
navigator
API to return browser locale preference
const locale = localizer.getLocale()
/**
* locale =>
* "en-US"
* /
getUserAgent
- Utilizes the browser's
navigator
API to return browser userAgent
const userAgent = localizer.getUserAgent()
/**
* userAgent =>
* "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.12.0"
* /