Identify users
Identifying users enables you to build the full picture of how a person uses your product across different sessions and devices.
Collecting user properties also is crucial for running Workflows and Segmentation where you want to send emails, personalise copy, and target users better.
To identify a user, call the identify
method:
import UserFlux from '@userflux/browser-js'
await UserFlux.identify({
properties: { email: 'johndoe@gmail.com', name: 'John' },
userId: '<USER_ID>' // replace <USER_ID> with your user's unique identifier
})
How identify works
In UserFlux, there are two types of users: Known and Anonymous.
If you have not identified a user yet but are tracking their traffic on your website, this will automatically create an Anonymous user unique to that device.
Identifying a user with a user ID allows you to build up your user base, collect information about your users, as well as stitch any Anonymous users to their associated Known user profile.
Linking
Known and Anonymous users are a one-to-many relationship. That is, one Known user can be linked to many Anonymous users.
When you call identify with a user ID, UserFlux will associate the auto-generated Anonymous user to the Known user.
Merging properties
When an Anonymous user is linked to a Known user for the first time, or when an existing linked Anonymous users properties are updated, that information will be merged with the primary Known user profile.
This means the Known user profile will have the most up to date information on any:
Properties defined by you
Device information
Location information
Computed Properties
Computed Properties are only calculated for Known users, however when evaluating the Computed Property, UserFlux will take in to account any linked Anonymous user data.
This is useful when using Computed Properties for things such as event roll ups, where you want to aggregate behavioural data from a user.
Workflow Checks
Having users linked to their Anonymous users is also a helpful data point when crafting user Workflow's.
For example, a classic Workflow for an ecommerce site would be an Abandoned Cart Email. If a anonymous website viewer has previously been linked to a known account, the next time they start a checkout but don't provide any contact details, you will still be able to send them a follow up email.
Best practices
Identify users as soon as possible
You should set a user ID once they have created an account, logged in, or is otherwise identified in your product.
Set user properties as soon as you collect the information
Whenever you receive new data from a user, such as age, email, mobile number, you should call identify
with this information as soon as possible.
Use unique strings for user IDs
If two users have the same user ID, their data is merged and they are considered one user in UserFlux.
User IDs are case-sensitive
If you set a user ID in a different case, UserFlux tracks two separate profiles for the same user.
Don't set the user ID if there isn't one
For example, if you set the user ID to the string None
for multiple users, UserFlux doesn't recognize those users as separate users. Instead, it assumes all those users are actually the same user, and it groups all events for those users together under that None
user ID.
You can always set the user ID later.
Don't assign a user ID that might change
User IDs are fixed forever: you shouldn't, for example, set a user's email address as their user ID—email addresses change.
Reset after logout
If a user logs out on your frontend, you should call reset()
to unlink any future events made on that device with that user.
This is important if your users are sharing a computer, as otherwise all of those users are grouped together into a single user due to shared cookies between sessions.
await UserFlux.reset()
Last updated