# anonymous-id

> get and set anonymous identifiers

Latest version **0.1.14** (published 2018-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install anonymous-id
pnpm add anonymous-id
yarn add anonymous-id
bun add anonymous-id
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.14 |
| Published | 2018-07-23 |
| First published | 2018-07-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 78.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | UserMirror, Inc. |
| Maintainers | fouad |
| Keywords | anonymous, id, analytics |

## Links

- npm: https://www.npmjs.com/package/anonymous-id
- Repository: https://github.com/usermirror/anonymous-id
- Homepage: https://github.com/usermirror/anonymous-id#readme
- Issues: https://github.com/usermirror/anonymous-id/issues
- npm.io page: https://npm.io/package/anonymous-id

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.14 (latest) — 2018-07-23
- 0.1.13 — 2018-07-14
- 0.1.12 — 2018-07-14
- 0.1.11 — 2018-07-14
- 0.1.10 — 2018-07-14
- 0.1.9 — 2018-07-14
- 0.1.8 — 2018-07-13
- 0.1.7 — 2018-07-12
- 0.1.6 — 2018-07-12
- 0.1.5 — 2018-07-12
- 0.1.4 — 2018-07-12
- 0.1.3 — 2018-07-12
- 0.1.2 — 2018-07-12
- 0.1.0 — 2018-07-12

## README

<p align="center">
  <a href="https://www.npmjs.com/package/anonymous-id"><img src="./docs/images/banner.png?cache=1" alt="anonymousId" /></a>
</p>

<p align="center">
  A tiny utility for working with anonymous ids<br/>
  on the server and in the browser.
</p>
<br/>

<p align="center">
  <a href="https://unpkg.com/anonymous-id/dist/anonymous-id.min.js">
    <img src="https://img.badgesize.io/https://unpkg.com/anonymous-id/dist/anonymous-id.min.js?compression=gzip&amp;label=anonymous--id&cache=2">
  </a>
  <a href="https://www.npmjs.com/package/anonymous-id">
    <img src="https://img.shields.io/npm/v/anonymous-id.svg?maxAge=3600&label=anonymous-id&colorB=007ec6">
  </a>
</p>
<br/>


### Getting Started

#### Installation

Install with npm:

```shell
npm install --save anonymous-id
```

Or with yarn:

```shell
yarn add anonymous-id
```

#### Examples

```javascript
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

```javascript
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:

```javascript
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:

```javascript
const id = await promptEmailFromUser()

anonymousId({ id })
```

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

```javascript
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](./license).

---
_Source: https://npm.io/package/anonymous-id · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
