Spectacle JS
Identify
User identification with Spectacle
The identify
function in Spectacle links a user's actions and pageviews to identifiable information, such as a name or email address. This function is essential for tracking user behavior in a meaningful way, allowing you to associate data with specific individuals.
Using identify
effectively
We recommend using a unique userId
from your database and including the email address as a trait. This is particularly useful if a user later changes their email address. You can pass as many user traits as needed to enrich the data.
spectacle.identify([userId], [traits]);
When calling identify()
, the userId
should be the universal identifier used in your database.
If you don't have a universal userId
, you can omit it and identify users with traits like name and email.
Parameters
- userId (String, optional): The identifier used in your database to recognize this user. If you don’t have this, you can skip it and just record traits.
- traits (Object, optional): A dictionary of traits describing the user, such as name, email, etc.
Example usage
spectacle.identify('THE_USER_ID', { email: 'john@doe.com' });
Or without a userId:
spectacle.identify({ email: 'john@doe.com' });
The identify
function should be called whenever a visitor identifies themselves by filling out a form, signing up, or logging in.
Special traits for identify
Spectacle recognizes certain special traits in the identify
call, which are displayed in the customer view within the app. Below are the special traits and an example of how to use them:
Trait | Type | Description |
---|---|---|
String | The user’s email address. | |
firstName | String | The user’s first name. |
lastName | String | The user’s last name. |
companyId | String | Unique id of the company if the user belongs to one in your internal data. |
companyName | String | The full name of the company the user belongs to. |
Example with special traits
Spectacle.identify('YOUR_USER_ID', {
email: 'john@doe.com',
firstName: 'John',
lastName: 'Doe',
comanyId: '123456789',
companyName: 'Acme Inc.',
yourCustomTrait: 'someValue'
});
Auto-reset
When a user is already identified with a userId
, passing a different userId
will automatically generate a new anonymous id as well. This is done to prevent customer journeys from getting mixed for users that have multiple accounts with you.