Tracking Users

Must Read

We recommend that you get yourself acquainted with all the concepts related to Customers and Events before proceeding. Doing so will help you understand the workings of this section, better.

Identifying Users

At Antsomi, we begin tracking users as soon as you integrate our SDKs into your platform. When a user opens your mobile app, our Antsomi SDK automatically assigns a unique ID known as a UID (User ID) to them. This helps us record users in our backend system and create an anonymous profile for them. All their behavioral data and session data (including System Events, Custom Events, System User Attributes, and Custom User Attributes) are stored under this anonymous profile.

You have the option to establish a connection between a user and a customer by utilizing a unique ID known as a CID (Customer ID). If there is no existing customer associated with the CID, this action will also result in the creation of a new customer, effectively linking the user to this newly created customer profile. This process ensures that both new and existing customers are seamlessly integrated into your system. We recommend assigning a CID at any of these key moments in the user's journey:

  1. When a user signs up for your platform.

  2. When a user logs in to their account.

  3. When a user's identity becomes known, such as during specific screen views or interactions.

Assigning a CID to a user has several important implications:

  • It signifies that the user is now identified and recognized as a "Customer" in your CDP365 dashboard.

  • It initiates the creation of a new "Customer Profile" that contains all of the user's data (in case there aren't any Customer Profile associated with that CID in CDP yet).

  • Importantly, all previous anonymous profiles associated with the user are merged into this new "Customer Profile". This means that data from the user's first visit to your website to their most recent interactions can all be found in one user profile. This consolidation ensures a comprehensive view of the user's interactions with your platform.

How Customer Profiles are Merged When User is Identified (assigned a CID)

Let's assume that User A opens your mobile app a few times before signing up.

User A opens your mobile app on Device 1: Antsomi assigns them a UID and automatically creates an anonymous user profile containing all their data (Anonymous Profile 1).

User A re-opens your mobile app on Device 3: Antsomi assigns them a UID and creates another anonymous profile to record all their data (Anonymous Profile 2).

User A re-opens your mobile app on Device 7 and creates an account: On account creation, you can choose to assign the user a CID. This will lead to the creation of a new user profile.

  • As soon as the Customer Profile is created, Antsomi will run a quick check in our backend to identify all the existing anonymous user profiles of that customer that were created on their previous visits.

  • In this case, Anonymous Profile 1 and Anonymous Profile 2 will be merged with the final profile of Customer A to provide a unified view of their preferences and behavioral history.

Guidelines

Here are a few things to keep in mind when assigning a customer ID (CID) to identify your users:

  • A customer ID cannot be changed once it has been assigned.

  • While the unique customer ID (CID) can be any string that effectively distinguishes users in your system, we strongly advise utilizing hashing methods, such as MD5 or SHA256, with user-specific information like email addresses or phone numbers as input. This approach enhances security and ensures the uniqueness of the generated IDs.

On Login

You can allocate a customer identification (CID) by defining a CDPEvent object instance for the event user_sign_in with the customerPropsand invoking the track() method. Any attributes, events, or session data gathered before utilizing this API are initially linked to an automatically generated anonymous user.

  • Upon the invocation of the track() method of the event user_sign_in, all the previously stored information becomes associated with the identified customer.

  • It's essential to trigger track() promptly upon the user's login to your application or whenever you are capable of recognizing the user.

import AntsomiRnSDK from '@antsomicorp/antsomirnsdk';

const { userData, login }  = useSelector((state) => state.auth);

const event: CDPEvent = {
    en: "sign_in_user", // Event internal name
    customerProps: {
        customer_id: MD5Hash().generateMd5(userData.email ?? ''),
        name: userData.name
    }
};

await AntsomiRnSDK.track(event);

On Logout

Make sure you call resetCustomer() when the logged-in customer logs out, or you do not want to attach any future event, session, or user data with this customer until setCustomerProps() is called again.

import AntsomiRnSDK from '@antsomicorp/antsomirnsdk';

await AntsomiRnSDK.resetCustomer();

Customer Attributes

Additional details such as a name, email address, location, and more can be linked to your customer profile. Antsomi offers a convenient, all-in-one method for setting values for these customer attributes. The customerProps attribute of the class CDPEvent accepts an object, where the key corresponds to the internal code of the customer attribute in CDP365, and the value represents the data you intend to assign to it. This streamlined approach simplifies enriching your customer profiles with essential information.

For example, in the sign-in event code snippet above, you can send more attributes beside customer_id and name, like the code snippet below

import AntsomiRnSDK from '@antsomicorp/antsomirnsdk';

const { userData, login }  = useSelector((state) => state.auth);

const event: CDPEvent = {
    en: "sign_in_user", // Event internal name
    customerProps: {
        customer_id: MD5Hash().generateMd5(userData.email ?? ''),
        name: userData.name,
        email: userData?.email,
        phone: userData?.phoneNumber,
        gender: userData?.gender,
        date_of_birth: userData?.dob,
        // ... and more attributes
    }
};

await AntsomiRnSDK.track(event);

Last updated