Analytics Storage Utils
Stand alone storage utilities used in analytics
By default, @analytics/storage-utils
will persist values in browser in this order:
localStorage
- If no
localStorage
, use cookies
- If no
cookies
, use global
window
If you want to specify which storage mechanism to use, use the options
parameter.
setItem
Set a value.
import { setItem } from '@analytics/storage-utils'
setItem('key', 'value')
setItem('key', 'otherValue', 'localStorage')
setItem('keyTwo', 'cookieVal', 'cookie')
setItem('keyThree', 'xyz', 'global')
getItem
Get a value.
import { getItem } from '@analytics/storage-utils'
const value = getItem('key')
const getLSValue = getItem('key', 'localStorage')
const getLSValue = getItem('key', 'cookie')
const getLSValue = getItem('key', 'global')
const valueObj = getItem('otherKey', '*')
removeItem
Remote a value.
import { removeItem } from '@analytics/storage-utils'
removeItem('key')
removeItem('key', 'localStorage')
removeItem('keyTwo', 'cookie')
removeItem('keyThree', 'global')