Creating or Updating user profile with Identify
The identify method is used to create or update a user profile in CustomerLabs. With identify method, you can update the user traits of a user in CustomerLabs.
It is a reserved method that triggers event called Create user.
Syntax
Section titled “Syntax”properties = { // customProperties object};
_cl.identify(properties)Before jumping to identify method, let’s understand what are External IDs.
What are External IDs?
Section titled “What are External IDs?”An External ID is any identifier that is not natively generated by CustomerLabs but is used to recognize a user or group in another platform.
Examples:
- Email address stored in your CRM →
identify_by_email - Facebook FBP cookie →
facebook__fbp - Your internal customer ID →
crm_user_id - Shopify cart token →
shopify_cart_token
When the same external ID appears across multiple events, CustomerLabs merges them into a single unified profile, improving match quality when syncing to ad platforms like Meta and Google Ads.
User External IDs
Section titled “User External IDs”User External IDs are stored under the external_ids object inside customProperties.
Reserved User External ID Keys
Section titled “Reserved User External ID Keys”| Key | Description |
|---|---|
customerlabs_user_id | CustomerLabs anonymous user ID |
identify_by_email | User’s email address |
identify_by_phone | User’s phone number |
shopify_cart_token | Shopify cart token |
facebook__fbp | Facebook Browser Pixel cookie |
google_analytics__client_id | GA4 client ID |
facebook_lead_id | Facebook Instant Form lead ID |
var customProperties = { "external_ids": { "<external_id_key>": { "t": "string", "v": "<value>" } }};Building the Properties Object
Section titled “Building the Properties Object”To trigger the identify method, user_traits object and identify_by with ib: true attribute must be added to the customProperties object. external_ids object can also be added (but not mandatory) to the customProperties object.
properties = { customProperties : { user_traits : { // traits }, external_ids : { // external ids }, <identifier> : { // trait used for identify by "ib" : true } }};
_cl.identify(properties)Reserved User Traits keys
Section titled “Reserved User Traits keys”The below keys are reserved for user traits in CustomerLabs.
- First Name:
first_name - Last Name:
last_name - Email:
email - Phone:
phone - Address line 1:
address1 - Address line 2:
address2 - City:
city - State/Province:
state - Country:
country - Country Code:
country_code - Postal Code:
zip - CustomerLabs User ID:
customerlabs_user_id - Shopify Cart Token:
shopify_cart_token
Setting up the ib flag
Section titled “Setting up the ib flag”identify_by object (flagged with ib: true) that helps the system search for the user based on a specific property key to which ib is set to true and assign user traits to that user.
Syntax Rules
Section titled “Syntax Rules”- There should only be one identifier that
ibis associated with per identify method call. - The identifier with
ibshould be also added undercustomProperties. - The value of
ibshould be set totruefor the identifier when it is added tocustomProperties.
Reserved keys for ib
Section titled “Reserved keys for ib”Reserved Identify By keys are,
- Identify by Email:
identify_by_email - Identify by Phone:
identify_by_phone - CustomerLabs User ID:
customerlabs_user_id - All the reserved
user_traitsandexternal_idskeys can be used as identify by.
Example: Identify by Email
Section titled “Example: Identify by Email”var email = "johndoe@example.com";
var properties = { "customProperties": { "user_traits": { "t": "Object", "v": { "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "phone": { "t": "number", "v": "1234567890" }, "email": { "t": "string", "v": email } } }, "external_ids": { "identify_by_phone": { "t": "string", "v": "1234567890" } }, "identify_by_email": { "t": "string", "v": email, "ib": true // The system will identify the user by this email } }};_cl.identify(properties);Example: Conditional ib Assignment
Section titled “Example: Conditional ib Assignment”When either email or phone or both may be available, use conditional logic to set the primary ib correctly.
// sample variablesvar email = "johndoe@example.com";var phone = "123456789";
// identify_byvar customProperties = { "user_traits": { "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "email": { "t": "string", "v": email }, "phone": { "t": "string", "v": phone } }}
if (email && email !== "") { customProperties["identify_by_email"] = { "t": "string", "v": email, "ib": true }; if (phone && phone !== "") { customProperties["external_ids"] = { "t": "Object", "v": { "identify_by_phone": { "t": "string", "v": phone } } }; }}else if (phone && phone !== "") { customProperties["identify_by_phone"] = { "t": "string", "v": phone, "ib": true };}
if (email || phone) { _cl.identify(customProperties);}Update User
Section titled “Update User”The “Update user” event is used to update the details (user_traits) of a user during a particular session. This is useful for multi-step forms where you collect information gradually.
To trigger an update of user traits across your workflow, you can send the event name as Update user.
Syntax
Section titled “Syntax”_cl.identify("Update user", properties)Example
Section titled “Example”var properties = { "customProperties": { "user_traits": { "t": "Object", "v": { "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "phone": { "t": "number", "v": "123456789" }, "email": { "t": "string", "v": "johndoe@example.com" } } }, "identify_by_email": { "t": "string", "v": "johndoe@example.com" } }};_cl.identify("Update user", properties);