identify

Identify your users.

Every time your user loads a page, you'll want to call identify to tell Sift who your current user is.

You'll want to use a unique ID for your user from your database.

Sift.identify(userId);

Calling identify will tell the widget who your current user is. You can then track page views or events, and use this data to ask for feedback based on what your user does or doesn't do inside your app.

If you do not provide a user ID, the user will be assigned a random one.

identify method definition:

Sift.identify([userId], [traits], [options], [callback]);

identify accepts the following arguments:

Argument

Type

Description

userId
required

String

Unique identifier for the user in your database.

traits
optional

Object

Free-form dictionary of traits for the user, like email or name.

options
optional

Object

Free-form dictionary of options.

  • Note: If you don't pass a properties object, you should pass an empty object {} before options*

callback
optional

Function

Function executed after a brief timeout (allowing the browser time to make requests).

Example user IDs

You can use any string which uniquely identifies the user of your application, such as a database ID, an email, or a username:

Sift.identify('123') // the user's ID from your database
Sift.identify('[email protected]') // the user's email

🚧

Casting your user's ID

identify only accepts strings in the userID argument. Make sure to cast your user's ID to a string before calling this function.

Traits

identify takes a second optional argument of a JSON key/value pair of traits that you'd like to associate with the given user.

Traits could be demographics like age or gender, specific to an account like company, or even whether your user has been shown a particular A/B test.

You can send us whatever traits you like and use them to send different feedback to different segments of your users.

Sift.identify('123', {
  name: 'Josh Smith',
  email: '[email protected]',
  company: {
    name: 'Sift',
  },
});

Any updates sent in the traits will merge with the existing traits we store for your user. Updated values will overwrite existing values.

For example:

Sift.identify('123', {
  name: 'Josh Smith',
  email: '[email protected]',
});

The user's name and email will be set.

Now, let's imagine your user just changed their email address and you want to relay that information to us. If we send an update to just the email:

Sift.identify('123', {
  email: '[email protected]',
});

The user's stored traits in Sift will now look like this:

{
  "email": "[email protected]",
  "name": "Josh Smith"
}

You can see that while email was overwritten, it has been merged in with the existing name trait.