Working with identities
Track user identities with session IDs, e-commerce IDs, segments, and traits using SDK, GTM, or REST API, ensuring accurate tracking, personalization, and GDPR compliance.
Last updated
Track user identities with session IDs, e-commerce IDs, segments, and traits using SDK, GTM, or REST API, ensuring accurate tracking, personalization, and GDPR compliance.
Last updated
To send an event, you have to provide at least one identifier: the session ID. When a visitor arrives at your website or app, they may initially be anonymous until they log in. During their visit, you can generate an anonymous session ID to track their journey. Store the session ID locally (in a cookie or local storage) and include it with every event using the user.identities.sessionId
field.
In the sections below, we go into detail about how to implement identities with each .
If you are using the Javascript SDK, a random session ID is created for the visitor and automatically stored in local storage as attraqtsessionid
. This session ID is then attached to any event sent through the library.
The SDK only stores the session ID in local storage. You will need to re-add any additional identities each time a page is loaded.
Once the shopper logs in, you know exactly who they are through the ID you have for them in your system, for example an e-commerce ID. The e-commerce ID can then be added to subsequent events along with the already existing session ID.
Use addUserIdentity
to add a different identity, e.g. the e-commerce ID:
Use the setUserIdentities
method to add multiple identities at once or to overwrite any pre-existing identities added with addUserIdentity
:
The following sequence demonstrates how the SDK handles user identities and ensure accurate tracking throughout a user's journey on your platform:
User arrives on your platform: The SDK assigns a default session ID and stores it in local storage.
User performs actions: The SDK attaches the session ID to any activity event you send out through the SDK.
User logs in: You retrieve the user's e-commerce ID from the login and attach it to all subsequent events.
User performs more actions: The SDK attaches both the newly added e-commerce ID as well as the already existing session ID to any activity event you send out. On the first activity sent this way, we attribute the session ID to the e-commerce ID, so all previous actions are now assigned to the same user.
Apart from identities, the SDK can also handle segments and traits. Segments constitute labels to qualify groups of users sharing common traits or behaviors, such as "Frequent buyer" or "Prospect". Traits constitute various qualifying values related to the user in question, including profile, and preference data, age, gender, likes, etc.
Use the addUserSegment
method to set a user segment. For example:
Use the setUserSegments
method to set multiple segments at once and overwrite any pre-existing ones set by addUserSegment
. For example:
Use the addUserTrait
method to add a trait for the user. For example:
Use the setUserTraits
method to set multiple traits for the user at once and overwrite any pre-existing ones set by addUserTrait
. For example:
Traits are information you know about your users and that you want to use in our platform. You must only send information relevant to the platform usage and avoid sending personal information.
If a user logs out, you shouldn't continue to attribute any future events to the same user until they log in again. To clear all user information (and generate a new session id) use the clearUser
method:
In order to be compliant with GDPR policies, you must allow your users to opt-out of saving cookies and having their information tracked. You should not be tracking any information on such users, and should refrain from sending any events.
When using the SDK to send activity events and the user decides to opt-out, call the following method:
If the user decides to opt-in again, use the following method:
If you would like to set the complete user object, you can override any pre-existing configuration through the setUser
method:
You can also attach the user object as part of the activity object every time you send an activity, for example:
To add segments or traits, include them in the User information section.
If you are using the REST API to send events, you can attach the user object as part of the activity object every time you send an activity. For example:
If you are using our , identities are added as key-value pairs in the Identities section.