npm.io
1.1.1 • Published 2 years ago

usertrail-js

Licence
MIT
Version
1.1.1
Deps
0
Size
15 kB
Vulns
0
Weekly
0
UserTrail

UserTrail JS

Installation

npm install usertrail-js

Usage

Import UserTrail
import UserTrail from "usertrail-js";
Create a new UserTrail client
const usertrail = new UserTrail({
  key: <Your API key>
    });
Track event
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.

// 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.

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.

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

Keywords