Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anonymous-id

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anonymous-id

get and set anonymous identifiers

  • 0.1.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

anonymousId

A tiny utility for working with anonymous ids
on the server and in the browser.



Getting Started

Installation

Install with npm:

npm install --save anonymous-id

Or with yarn:

yarn add anonymous-id
Examples
import anonymousId from 'anonymous-id'

anonymousId() // generate or pull id from cookie/localStorage

anonymousId('exampleId') // call the function with string or number to set as id, otherwise pass in options

Usage

Get & Set
import { get, set } from 'anonymous-id'

set({ key: 'my_anon_id' }) // ajs-C1E42A94-FCE2-4851-87DD-695F576C5368 -> cookie or localStorage

get({ key: 'my_anon_id' }) // 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:

anonymousId({
  debug: true, // log operations to stdout
  preset: String, // prefix/generateId/stores to use
  cookie: String, // cookie string to use (browser default is document.cookie)
  localStorage: Object // Storage object to use (browser default is window.localStorage)
})

For setting anonymous ids, you can specify an id field which will pass the options to setAnonymousId(). If you don't set the id option, then getAnonymousId() will be called with the options:

const id = await promptEmailFromUser()

anonymousId({ id })

And for getting anonymous ids, you can pass control if the preset tries to persist data:

console.log(document.cookie) // 'a=true'

const { cookie } = anonymousId({ persist: false })

console.log(document.cookie) // 'a=true'
console.log(cookie) // 'a=true; ajs_anonymous_id=ajs-B31C9E91-D741-4146-913B-0E80199648D0'

Contributing

All contributions are super welcome! anonymous-id is MIT-licensed.

Keywords

FAQs

Package last updated on 23 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc