Properties Object Syntax
Before we trigger an event to CustomerLabs, we need to define the properties that is associated with the event.
Properties are the data that is sent to CustomerLabs along with the event in a structured format. There are 2 properties,
- Custom Properties
- Product Properties
Properties Syntax
Section titled “Properties Syntax”The following is the syntax for a property,
"<property_name>" : { "t": "<data_type>", "v": "<value>"}Properties Data Types
Section titled “Properties Data Types”The following data types are supported for properties,
string– Text valuesnumber– Numeric values (supports integers and float)boolean– True or False valuesarray– List (array) of valuesobject– Key-Value pairs collection
Best Practices
Section titled “Best Practices”- Use
snake_casefor property names (words split by underscores) - Avoid spaces in property names
- Use descriptive, human-readable names
- Keep the property names consistent across all events
- Avoid special characters
Custom Properties
Section titled “Custom Properties”Custom Properties are the data that contains,
- Event Properties – Page URL, currency, value, transaction id, etc.
- User Traits – first name, last name, email, phone, etc.
- Group Traits – Company name, company website, etc.
- External IDs – External IDs are any unique identifier that is associated with the user assigned from any other platform. (e.g. Customer ID, Facebook Click ID, etc.)
- Identify By – Identify By instructs the system to search the database using the identifier the
identify_byis assigned to.
var customProperties = { // event properties, user_traits : { // user traits }, group_traits : { // group traits }, external_ids : { // external ids }};Event Properties
Section titled “Event Properties”Any properties that is associated with the event tracked are considered as “event properties”. These are directly stored under customProperties object.
Reserved Event Properties keys are,
- Page URL:
page_url - Currency:
currency - Value:
value - Transaction ID:
transaction_id - Order ID:
order_id
Example 1
Section titled “Example 1”// sample variablesvar totalPrice = 699;var currency = "USD";
// custom propertiesvar customProperties = { "currency": { "t": "string", "v": currency }, "content_type": { "t": "string", "v": "product_group" }, "value": { "t": "number", "v": totalPrice }, "total_items": { "t": "number", "v": 2 }, "payment_method": { "t": "string", "v": "Credit Card" }, "coupon": { "t": "string", "v": "SUMMER20" }, "transaction_id": { "t": "string", "v": "ORD-123456789" } };Example 2
Section titled “Example 2”// sample variablesvar source = "web";var formId = "form-123456789";
// custom propertiesvar customProperties = { "source": { "t": "string", "v": source }, "form_id": { "t": "string", "v": formId }, "form_name": { "t": "string", "v": "Sample Form" }, "page_url": { "t": "string", "v": "https://www.example.com" } };External IDs
Section titled “External IDs”External IDs are any unique identifier that is associated with the user assigned from any other platform or used to identify the user in another platform.
It acts as a common identifier between CustomerLabs and the other platform. For example, Customer ID, Facebook Click ID, etc.
Reserved External ID keys are,
- CustomerLabs User ID:
customerlabs_user_id - Identify by Email:
identify_by_email - Identify by Phone:
identify_by_phone - Shopify Cart Token:
shopify_cart_token - Facebook FBP:
facebook__fbp - GA4 client id:
google_analytics__client_id - Facebook Lead id (instant forms):
facebook_lead_id
This external id can be used to associate the unified user events with other platforms.
// sample variablesvar cluid = "cl123456789";var email = "johndoe@example.com";
// external idsvar customProperties = { external_ids : { "customerlabs_user_id": { "t": "string", "v": cluid }, "identify_by_email": { "t": "string", "v": email }, "identify_by_phone": { "t": "string", "v": "123456789" }, "facebook__fbp": { "t": "string", "v": "fb.1.1111111111111.1111111111111" }, "crm_user_id": { "t": "string", "v": "crm_123456789" } }}User Traits
Section titled “User Traits”User Traits are the data that is related to the user. Unlike event properties, user traits are stored inside customProperties under a separate object called user_traits.
To add all user_traits to a user’s profile in CustomerLabs, identify method should be used.
After this, all the user_traits of that particular user will be available in the 360-degree profile in CustomerLabs.
Reserved User Traits keys are,
- 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 - Facebook Lead id (instant forms):
facebook_lead_id
// sample variablesvar email = "johndoe@example.com";var phone = "1234567890";
// user traitsvar 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 } }}Identify By
Section titled “Identify By”When an identify method is called, it is important to assign all the tracked user traits to a particular user. The identify_by attribute helps the system to search for the user based on that identifier ib is associated with and assign all the properties inside user_traits to that particular user.
Syntax Rules
Section titled “Syntax Rules”- There should only be one identifier that
ibis associated with peridentifymethod call. - The identifier with
ibshould be also added undercustomProperties. - The value of
ibshould be set totruefor the identifier when it is added tocustomProperties.
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.
// sample variablesvar email = "johndoe@example.com";
// identify_byvar customProperties = { "user_traits": { "first_name": { "t": "string", "v": "John" }, "last_name": { "t": "string", "v": "Doe" }, "email": { "t": "string", "v": email } }, "identify_by_email": { "t": "string", "v": email "ib": true }}
_cl.identify(customProperties);Example 2
Section titled “Example 2”// 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);}Group External IDs
Section titled “Group External IDs”Group / Account External IDs are the data that is related to the group (Company / Account). For example, Company name, Company website, Account ID, etc.
It acts as a common identifier between CustomerLabs and the other platform. For example, Company name, Company website, etc.
Reserved External ID keys are,
- Identify by Company Name:
identify_by_company - Identify by Company Website:
identify_by_website - Company Name:
company_name - Company Website:
company_website
This external id can be used to associate the events associated with a group / account with other platforms.
var customProperties = { "group_external_ids": { "identify_by_company": { "t": "string", "v": "ABC Corporation" }, "identify_by_website": { "t": "string", "v": "www.example.com" } }}Group Traits
Section titled “Group Traits”Group Traits are the data that is related to the group (Company / Account). For example, Company Name, Company Website, etc.
Reserved Group Traits keys are,
- Company Name:
company_name - Company Website:
company_website
// sample variablesvar companyWebsite = "www.example.com";var companyName = "ABC Corporation";
// group traitsvar customProperties = { group_traits : { "company_name": { "t": "string", "v": companyName }, "company_website": { "t": "string", "v": companyWebsite }, "comapny_location": { "t": "string", "v": "New York" }, "no_of_employees": { "t": "string", "v": "1-20" } }}Identify Group By
Section titled “Identify Group By”When an group method is called, it is important to assign all the tracked group traits to a particular group. The identify_group_by attribute helps the system to search for the group based on that identifier igb is associated with and assign all the properties inside group_traits to that particular group.
Syntax Rules
Section titled “Syntax Rules”- There should only be one identifier that
igbis associated with pergroupmethod call. - The identifier with
igbshould be also directly added undercustomProperties. - The value of
igbshould be set totruefor the identifier when it is added tocustomProperties.
Reserved Identify Group By keys are,
identify_by_websiteidentify_by_company- All reserved
group_traitskeys can be used asigb.
// sample variablesvar companyWebsite = "www.example.com";
// identify_byvar customProperties = { "group_traits": { "company_name": { "t": "string", "v": "ABC Corporation" }, "company_website": { "t": "string", "v": companyWebsite } }, "identify_by_website": { "t": "string", "v": companyWebsite, "igb": true }, "external_ids": { "t": "Object", "v": { "identify_by_company": { "t": "string", "v": "ABC Corporation" } } }}
_cl.group(customProperties);Product Properties
Section titled “Product Properties”Product Properties are the data that is related to the products. For example, Product ID, Product Name, Product Price, etc.
The product properties are sent as an array of objects – [{product 1}, {product 2}, ...]
Reserved Product Properties keys are,
- Product ID:
product_id - Product Name:
product_name - Product Quantity:
product_quantity - Product Price:
product_price - Product Category:
product_category - Product Brand:
product_brand - Product Variant:
product_variant - Product Variant ID:
variant_id - Product Coupon:
product_coupon - Product Image:
product_image - Product Index:
product_index - Product Position:
product_position - Product Discount:
product_discount
Example 1
Section titled “Example 1”var productProperties = [ // sample product 1 { "product_id": { "t": "string", "v": "PRD-1-ID" }, "product_name": { "t": "string", "v": "Sample Product 1" }, "product_quantity": { "t": "number", "v": 1 }, "product_price": { "t": "number", "v": 100 } }, // sample product 2 { "product_id": { "t": "string", "v": "PRD-2-ID" }, "product_name": { "t": "string", "v": "Sample Product 2" }, "product_quantity": { "t": "number", "v": 1 }, "product_price": { "t": "number", "v": 49 } }]Example 2
Section titled “Example 2”This example shows how to convert the items array from a variable to the required format and store it in the productProperties variable.
var items = [ { item_id: "item id 1", item_name: "item name 1", price: 79.99, quantity: 1 }, { item_id: "item id 2", item_name: "item name 2", price: 109.99, quantity: 1 }]
function productsConversion(productsArr) {
var products = [];
for (var i = 0; i < productsArr.length; i++) { var productsStructure = {};
for (var key in productsArr[i]) { switch (key) {
case "item_name": productsStructure["product_name"] = { t: "string", v: productsArr[i][key] }; break;
case "item_id": productsStructure["product_id"] = { t: "string", v: String(productsArr[i][key]) }; break;
case "price": productsStructure["product_price"] = { t: "number", v: productsArr[i][key] }; break;
case "quantity": productsStructure["product_quantity"] = { t: "number", v: productsArr[i][key] }; break;
default: if (productsArr[i][key] && typeof productsArr[i][key] !== "object") { var isNum = /^\d+$/.test(productsArr[i][key]); var type = Number.isFinite(productsArr[i][key]) || isNum ? "number" : typeof productsArr[i][key];
productsStructure["product_" + key] = { t: type, v: productsArr[i][key] }; } } }
products.push(productsStructure); }
return products;}
var productProperties = productsConversion(items);Next Steps
Section titled “Next Steps”Now that we have covered the building the properties for the events, let’s move on to setting up the events triggers to CustomerLabs.