Tracker Best Practices

Send all relevant activities

Whenever a user performs an action on your website that falls within the list of supported actions, you should send an activity. While in theory you may choose to send only some actions, not sending all actions can result in incomplete or wrong analytics.

Include as much information as possible

The metadata of the activity object can contain a lot of context information which can later be used to improve analytics such as adding a metadata.orderId property with the id of the order, so we can group purchased items into 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 on users behavior based on groups they fall into.

Always include the source id if available

The activity object contains the sourceId field, however 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. The source id should always be added to the activity object when it is available.

You can check when you can omit it in the action specific pages.

Store and keep sending the session id

As soon as a user lands on your website, a session id will be generated for the user. This can be done automatically via the library, or by you.

The idea is that on their next connection, we will still have their session id to identify them and use for analytics.

If you handle it yourself, you need to store it in a cookie or some equivalent storage.

If you use the library, it will be stored in local storage on their browser.

Send and update users identities on log in/log out

If the user logs in you should add their logged in id that you have in your system (such as an ecommerce id) and start sending it over. While you can also only keep using the anonymous session id, it is advised that you also send over the known logged in id so user behavior can be tracked across multiple devices.

If the user logs out you should clear the logged in id and no longer send it.

More on identities below.

Last updated