If customers are able to log in to your site at any time, they may perform valuable user interactions (i.e. click and conversion events) before they've logged in. Then when they log in and complete their journey, some click and conversion events may be missing from their user profile.
There are two options to consider when implementing userToken after users log in:
Assign an authenticatedUserToken
You can assign an authenticatedUserToken once the user logs in. This should be assigned to the authenticatedUserToken parameter rather than the userToken parameter, as the latter is intended to be used for 'anonymous' users who have not yet signed in.
Keeping authenticatedUserTokenand userToken separate ensures continuity of user activity and prevents data loss during the transition from anonymous to authenticated status.
If you assign the authenticated user's ID to the userToken parameter, their initial activity as an 'anonymous' user (before they logged-in) won’t be associated with their authenticated profile. Instead, keep their initial user ID in the userToken field, and add their 'logged in' user ID in the authenticatedUserToken field.
More info on setting authenticated user tokens can be found here.
Note: The user token sent with search queries must match the userToken sent with events: https://www.algolia.com/doc/api-reference/api-parameters/userToken/#how-to-use
Use their IP address
The second way is to assign the IP address of the user to userToken parameter. This makes it so their userToken is the same throughout their entire journey, however, this also means that if the user visits your site on a different device (i.e. a different IP), they will have a different userToken.
Another consideration is to offer the login page (either as a pop up or by some other method) right away to the user so the likelihood that they log in earlier is increased.
For a full list of common userToken issues, troubleshooting topics and best practices, see our summary article here.