Best practice
Details to be aware of when using the Crownpeak front-end tracker for optimal usage.
Send all relevant activities
Whenever a user performs an action on your platform that falls within the list of supported actions, you should send an activity. While in theory you may choose to send only some actions, failing to track all actions can lead to incomplete or inaccurate analytics.
Include as much information as possible
The metadata of the activity object can contain valuable contextual information that enhances analytics.
For example:
Adding a
metadata.orderId
property with the order ID allows you to group purchased items -into specific orders.Adding the
segments
property to the activity object allows for analytics based on different tags such mobile vs desktop, or Chrome vs Safari.Adding information around the user through the user.traits and user.segments properties allows for analytics based on user groups.
Always include the source ID if available
The activity object contains the sourceId
field. The field is not mandatory as it's not necessary for every type of action. However, this doesn't mean that you should omit it. You should always add the source ID to the activity object if it is available.
Store and keep sending the session ID
As soon as a user lands on your platform, a session ID is generated for the user. This can be done automatically via the library, or by you. The next time the user connects, the session ID allows us to identify them.
If you handle it yourself, you need to store the session ID in a cookie or equivalent storage.
If you use the library, the session ID will be stored in local storage on the user's browser.
Send and update users identities on log in/log out
When the user logs in you should add their logged in ID that you have in your system (such as an ecommerce ID) to the information sent in the activity object. While you can also only keep using the anonymous session ID, we recommend that you also send over the known logged in ID. This allows for the user behavior tp be tracked across multiple devices.
When the user logs out, you should clear the logged in ID and no longer send it. You should also generate a new session ID. This is done automatically when using the SDK.
Last updated