• Sets the userId

    The userId is used to identify the current user. It is automatically generated at the edge when initializing the SDK for the first time.

    Use this method when you want to identify the current user with an externally managed user ID. For e.g., you can use this when an anonymous user logs in.

    When an anonymous user logs in, you may also want to preserve all the user attributes tracked thus far. The option preserveUserAttributes is available for the same, which merges all the attributes from the current user.

    The setUserId method also drops a cookie to track the user ID in browser environments. The cookie is called cs-personalize-user-id.

    Call this method before or after initializing the SDK.

    Parameters

    • userId: string

      The new user ID for the current user

    • Optionaloptions: SetUserIdOptions

      Pass options to preserve user attributes

    Returns Promise<void>

    await Personalize.setUserId(newUserId, { preserveUserAttributes: true });