Userflow.js identify update

This post is mostly for developers :)

We’ve simplified how user attributes are sent to Userflow with userflow.identify() and userflow.updateUser(), and added the ability to add/subtract to/from number attributes.

This is in preparation for the release of our public REST API, which will look almost identical (just as JSON over HTTP).

The changes are fully backwards-compatible, so you don’t have to change anything in your code.

Simpler attributes

Before, we distinguished between standard attributes (such as name, email and signedUpAt) and custom traits (that were put in a nested traits object). Example of what userflow.identify looked like before:

userflow.identify(user.id, {
  name: user.name,
  email: user.email,
  signedUpAt: user.createdAt,
  traits {
    role: user.role,
    plan: user.plan
  }
})

Now there’s only one level and all attributes are just… attributes. You send whatever you want - they’re all treated the same. The word “trait” is gone. Updated example:

userflow.identify(user.id, {
  name: user.name,
  email: user.email,
  signed_up_at: user.createdAt,
  role: user.role,
  plan: user.plan
})

Notice how signed_up_at is now snake_cased. We recommend sticking to one naming scheme.

Setting an attribute only once

Say you want to track something a user did, but you only want to track it the first time. Example: We want to know which integration a user set up first. Instead of sending the name of the integration, send an object with a set_once key:

userflow.updateUser({
  integration_name: {set_once: 'My integration'}
})

The user’s integration_name attribute will get the value My integration, unless, if it’s already been set before, in which case we’ll leave it alone.

Adding/subtracting to/from number attributes

You can also increment attributes. Say you want to track how many projects a user has created, but you don’t want to recount the number of projects on every page load. Just call the following each time a project is created in your app:

userflow.updateUser({
  projects_count: {add: 1}
})

You can similarly subtract by using subtract instead of add.

See full updated userflow.identify docs.

More from Userflow