Using a UUID to track site visitors
When you call a Sitecore Search API, we recommend you create and send a universal unique identifier (uuid) for each site visitor. The uuid is a unique user ID that does not contain personally identifiable information (PII) such as an email address or membership ID. Sitecore Search uses the uuid to tie a request to a visitor across multiple sessions, which allows us to serve personalized search results and generate accurate analytics.
Sitecore Search requires that you create a seven-part UUID separated by hyphens, in this format:
<part1>-<part2>-<part3>-<part4>-<part5>-<part6>-<part7>
Here's what the different parts are:
-
<part1>is a constant, your domain ID. You can see your domain ID in Search in the domain name drop down list. For example,159271561. -
<part2>through<part5>is a four-part string. There are no length requirements. For simplicity and backward compatibility, we strongly recommend that you keep these constant across all visitors in your domain. Examples of this includey-d-7-nora-b-c-d. -
<part6>is a random alphanumeric string of at least 20 characters to uniquely identify the site visitor. For example,f5tdhddqwvywv7b9g2vy. -
<part7>is the timestamp, in milliseconds, when the UUID was created. For example,1664852644904.
Here's a sample uuid: 159271561-a-b-c-d-f5tdhddqwvywv7b9g2vy-1664852644904
If your custom UUID does not follow the above format, ensure that your custom free-form ID is passed in context.user.user_id instead of context.user.uuid in your Search request.
For example, you want to create and persist a uuid in the following scenario:
-
You use cookies.
-
You want to store the UUID in a cookie.
-
You use your Search domain ID in the script to generate a UUID.
This sample code snippet shows how to generate a UUID:
This sample code snippet shows how to persist a UUID in a cookie: