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' });
The identify
function should be called whenever a visitor identifies themselves by filling out a form, signing up, or logging in.
Special properties for identify
Spectacle recognizes certain special properties in the identify
call, which are displayed in the customer view within the app. Below are the special properties 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 properties
Spectacle.identify('YOUR_USER_ID', {
email: 'john@doe.com',
firstName: 'John',
lastName: 'Doe',
comanyId: '123456789',
companyName: 'Acme Inc.',
yourCustomTrait: 'someValue'
});
Using identify()
on an OAuth page
If your site uses an OAuth integration (e.g., sign in/up with Google, Facebook, Twitch), follow these steps:
- The visitor arrives at your site (Site A).
- They click to log in using an OAuth connector and are redirected to the OAuth provider (Site B).
- After successful authentication, they are redirected back to your site (Site A).
- At this point, call
identify()
on Site A.