Tracking your Users and Accounts

Updated 3 months ago by Angelo Matheou

If you have already completed the initial setup steps outlined in our guides here, then your web application is now sending real-time events (i.e. page view, sessions, clicks) to Aptrinsic along with their respective user & account information.

This article gets into some more detail around the second part, specifically, how those users and accounts are tracked or sent to your Aptrinsic subscription.

The Identify Call

The Aptrinsic javascript SDK exposes an identify() call that your developers have added to the authentication/login area of your web application.  The identify call is made during the authorization / login area of your web application and has two parameters as per this pseudo code:

aptrinsic('identify', [userObject],[accountObject]);

Note that the useObject parameter is required but the accountObject parameter is optional (i.e. when the user's account information is not available).

// required
aptrinsic('identify', {id: 'user-id'});

// optional
aptrinsic('identify', {id: 'user-id'},{id:'account-id'});

Identifying your Users (post successful login)

Here is a sample identify call that is passing some user and account info to your Aptrinsic subscription.

// Minimum Required
aptrinsic('identify', {id: 'user-id'});
// optional to include the account object
aptrinsic('identify', {id: 'user-id'},{id:'account-id'});

The value for the user and account id's must be unique across your Aptrinsic subscription.  Typical examples of an id can be a Unique Identifier coming from your database, a GUID, or the user's email address.

Default Attributes

Your Aptrinsic subscription comes loaded with a default set of user and account attributes, the User and Account Model help doc lists the current set of default attributes and their detail.  You can also check navigate to Account Settings -> Attributes to see the list of all default and custom attributes.

Custom Attributes

If you have user or account attributes that are not part of the default set, you can add them as custom attributes by navigating to Account Settings->Attributes and clicking on the New Button:

Take notice of the Attribute’s API name as this will be the name to use in your identify() call.  Remember that the attribute name should match exactly what is defined as the Attribute Name in the Account Settings->attributes page. 

// it is recommended to include the user & account along with custom attributes
aptrinsic('identify',
{
'id': 'unique-user-id', // Required for logged in app users
'email': 'useremail@address.com',
'signUpDate': 1516234662215,
'firstName': 'John',
'lastName': 'Smith',
"userHash": '', // optional transient for HMAC identification
// flat custom attributes
"plan" : "gold",
"price" : 95.5
},
{
'id':'IBM', //Required
'name':'International Business Machine',

// flat custom attributes
'Program': 'Platinum'
});

One final but important note, when sending JSON values, be sure that

  • String types are enclosed in quotes
  • Number types are NOT enclosed in quotes
  • Date types are sent as a Long Value using Epoch time in milliseconds, like here.


How did we do?