

And even better, you can link your analytics data with your own internal database. When you use a static ID, you can still recognize the user in your analytics tools, even if the user changes their email address. Segment recommends that you use static IDs instead, so the IDs never change. Segment does not recommend using simple email addresses or usernames as a User ID, as these can change over time. You can also use identifiers that you get from other tools - such as Shopify or Braze - however this approach can lead to extra complexity in your systems. These can also be UUIDs that you generate somewhere in your application. For example, if you’re using MongoDB it might be a row identifier and look something like 507f191e810c19729de860ea. Ideally, the userId could be a database ID. If you don’t have a userId, you need to include an anonymousId in your identify call in order to record identifying information about your user. Because these IDs are consistent across a customer’s lifetime, you should include a userId in identify calls as often as you can. A userId should be a robust, static, unique identifier that you recognize a user by in your own database systems. Segment recommends that you use a unique user identifier (UUID) that won’t change for your userId. It can be any pseudo-unique identifier, for example, you might use a sessionId from a backend server. If you use Segment’s server libraries, you must generate an anonymousId manually. If a user chooses to register for your site, or log in to your app, you can identify them, and still include their anonymousId in the event payload along with the new userId. When you track the anonymousId, you can attribute activities over multiple days to the same user by collecting all of the activities with that ID.

You can use the anonymousId to link events performed by the user as they navigate around your website. That anonymousId is saved in the user’s cookie, as well as localStorage, and will stick with that user until the cache is cleared or a reset call is triggered. If you’re using Segment’s browser or mobile libraries, the Segment SDK generates and sets a UUID as anonymousID at the user’s first visit to your site. Whenever possible, follow the identify call with a track event that records what caused the user to be identified. If the user clears their cookies and localStorage, all of the IDs are removed and the user gets a completely new anonymousId when they next visit the page. If a user returns to your site after the cookie expires, Analytics.js looks for an old ID in the user’s localStorage, and if one is found, sets it as the user’s ID again in a new cookie. This makes it possible to append the user’s data to all subsequent page calls or track calls for the user, so you can properly attribute those actions. If you’re using one of the Segment mobile libraries, the userId and traits are stored in the device’s memory. When you make an identify call using Segment’s Analytics.js library, Segment saves the userId to the browser cookie, and writes all the user traits in localStorage. In this instance, you would record that email address as a trait, and for the identifier (ID), you would use anonymous ID. An example of this might be, a user that visits your site and doesn’t register, but they do give you their email address through a newsletter email sign-up form. There are instances where you want to record information about a user that isn’t already known to you. The identify call specifies a customer identity that you can reference across the customer’s lifetime.

Tracking users with the identify and track calls reduces the number of Monthly Tracked Users you are billed for. When you use these calls together, you can attribute actions on your site or app to individuals, and gain a better understanding of their activities, identity, and use patterns over time. The most important calls you make with Segment are the identify and track calls.
