Best practice
Details to be aware of when using the Crownpeak front-end tracker for optimal usage.
Last updated
Details to be aware of when using the Crownpeak front-end tracker for optimal usage.
Last updated
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.
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 -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.
through the user.traits and user.segments properties allows for analytics based on user groups.
The 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.
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 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.
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.