Question
How is the anonymousId generated in Segment?
Product
Twilio Segment
Environment
Segment Console
Answer
How the
anonymousId is generated depends on the Segment libraries you are using:
-
Browser or mobile libraries: The Segment SDK automatically generates and sets a UUID as the
anonymousIdduring the user's first visit to your site. ThisanonymousIdis saved in the user's cookie andlocalStorage, and will stick with that user until the cache is cleared or aresetcall is triggered. -
Server libraries: You must generate the
anonymousIdmanually. It can be any pseudo-unique identifier; for example, you might use asessionIdfrom a backend server.
You can use the
anonymousId to link events performed by the user as they navigate around your website. When you track the anonymousId, you can attribute activities over multiple days to the same user by collecting all activities with that ID. 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 their new userId.
Additional Information
Review the Segment product documentation for Best Practices for Identifying Users.