A tiny utility for working with analytics ids
on the server and in the browser.
Getting Started
Installation
Install with npm:
npm install --save analytics-id
Or with yarn:
yarn add analytics-id
Examples
// generate or pull id from cookie/localStorage // call the function with string or number to set as id, otherwise pass in options
Usage
Get & Set
// ajs-C1E42A94-FCE2-4851-87DD-695F576C5368 -> cookie or localStorage // cookie or localStorage -> ajs-C1E42A94-FCE2-4851-87DD-695F576C5368
Options
These are the base options that can be passed in to both get and set functions:
For setting analytics ids, you can specify an id
field which will pass the options to setAnalyticsId()
. If you don't set the id
option, then getAnalyticsId()
will be called with the options:
const id = await
And for getting analytics ids, you can pass control if the preset tries to persist data:
console // 'a=true' const cookie = console // 'a=true'console // 'a=true; session_id=ajs-B31C9E91-D741-4146-913B-0E80199648D0'
Contributing
All contributions are super welcome! analytics-id
is MIT-licensed.