Quickstart: Using JS Library

Recommended steps to send data using implement JavaScript (JS) Library functions

Pre-requisites

  1. Before following the below steps, make sure JavaScript client library is embedded in your application. You can do so by following the steps here.

Step 1. Identify Account and User

Identify Account and User using the analytics.login function.

Note: If you're not sure what Ids to set as Account Id and User Id, discuss this with your customer success manager or your onboarding manager for recommendations.

// Use analytics.login("user_id", "account_id"); to login.
analytics.login("User 123", "Account 123");
// Behind the scene memory object will look like
{
"account_id": "Account 123",
"user_id": "User 123",
"type": "track",
"event": "User Login"
}

Above function set user_id = User 123 and account_id = Account 123 in analytics object. This will store everything in object memory but not in local storage or cookies.

Step 2. Send Features (aka product telemetry /product )

Features are also knows as product telemetry or product adoption or product usage data. Usually hundreds to many thousands of events per day.

// Before calling feature function, please call login function once
// So that you able to set account_id and user_id for feature function
// analytics.login("user_id", "account_id");
// Use analytics.feature("feature_id", "module_id", "product_id"); to send feature data.
// Function Call
analytics.feature("Feature", "Module", "Product");
// Example 1
analytics.feature("Salary Processed", "HR", "CRM");
// Example 2
analytics.feature("Weekly Report", "Report", "CRM");
// Example 3
analytics.feature("Ticket Raised", "Ticket", "Support");
// Behind the scene memory object will look like
{
"account_id": "Account 456",
"user_id": "User 123",
"type": "feature",
"feature_id": "Feature",
"module_id": "Module",
"product_id": "Product"
}

Npte that before calling the feature function, you need to call the login function once per page load so that it set account_id and user_id once. Feature function send feature name, module name and product name with account_id and user_id to our servers.

Step 3. Set Account properties (optional)

// Use analytics.account("account_id", traits = {}); to send account data.
analytics.account("Account 456", { "name": "Acme Corp." });
// Behind the scene memory object will look like
{
"account_id": "Account 456",
"user_id": "User 123",
"type": "account",
"traits": {
"name": "Acme Corp."
}
}

Above function set account_id = Account 456 and traits = { "name": "Acme Corp." } but user_id remain same as User 123 in analytics object. Again this will store everything in object memory but not in local storage or cookie.

Step 4. Update User properties (Optional)

// Use analytics.identify("user_id", traits = {}); to send user data.
analytics.identify("User 123",
{
first_name: "John",
last_name: "Kerry",
});
// Behind the scene memory object will look like
{
"account_id": "Account 456",
"user_id": "User 123",
"type": "user",
"traits": {
"first_name": "John",
"last_name": "Kerry",
"email": "[email protected]"
}
}

Above function set traits = { first_name: "John", last_name: "Kerry", email: "[email protected]"} but user_id and account_id remain same as User 123 and Account 456 in analytics object. Again this will store everything in object memory but not in local storage or cookie.

Step 5. User Logout (Optional)

// Use analytics.logout(); to logout.
analytics.logout();
// Behind the scene memory object will look like
{
"account_id": null,
"user_id": null
}

Above function set user_id = null and account_id = null in analytics object. This will store everything in object memory but not in local storage or cookies.

Note: If you choose to the call logout function it will clear the identity record created by the login function above. Hence a another login function call is mandatory next time this user logs in.