# usertrail-js

> UserTrail JS SDK

Latest version **1.1.1** (published 2023-10-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install usertrail-js
pnpm add usertrail-js
yarn add usertrail-js
bun add usertrail-js
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2023-10-13 |
| First published | 2023-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yossi Segev |
| Maintainers | yossisegev |
| Keywords | usertrail, events, logs, logging |

## Links

- npm: https://www.npmjs.com/package/usertrail-js
- Repository: https://github.com/usertrail/usertrail-js
- Issues: https://github.com/usertrail/usertrail-js/issues
- npm.io page: https://npm.io/package/usertrail-js

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.1.1 (latest) — 2023-10-13
- 1.1.0 — 2023-10-13
- 1.0.1 — 2023-10-06
- 1.0.0 — 2023-10-06

## README

<div align="center">
	<img src="https://usertrail.io/seo.jpg" alt="UserTrail"/>
	<br>
    <h1>UserTrail JS</h1>
</div>


## Installation

```sh
npm install usertrail-js
```

## Usage

### Import UserTrail

```js
import UserTrail from "usertrail-js";
```

### Create a new UserTrail client

```js
const usertrail = new UserTrail({
  key: <Your API key>
    });
```

### Track event

```js
usertrail.track({
  eventName: "User subscribed", 
  userId: "user-123-456"
});
```

### Identify user

You can set the user id on the client level. It will be sent with all events.
```js
// set user id once
usertrail.identify({
  userId: "user-123-456"
});

// send events, user id can be omitted from track()
usertrail.track({
  eventName: "Event 1",
});

usertrail.track({
  eventName: "Event 2",
});
```

or you can set the user id on the event level. It will be sent only with this event.
```js
usertrail.track({
  eventName: "User subscribed", 
  userId: "user-123-456" // will override the client user id if exists
});
```

### Updating user id
You can assign a new user id to an existing user. This will update the user data and events from the old user id to the new user id.
Useful when a user signs up, and you want to keep the events from the anonymous user.

```javascript
await usertrail.updateIdentity({
  userId: "user-id-1",
  newUserId: "user-id-2"
});
```

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