Skip to content

Add analytics.instance.user().id(xxx) [DOC-1101] #7592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

stayseesong
Copy link
Contributor

Proposed changes

Merge timing

Related issues (optional)

@stayseesong stayseesong requested a review from a team as a code owner April 30, 2025 18:36
@stayseesong stayseesong requested a review from rchinn1 April 30, 2025 18:36
@stayseesong stayseesong added the content-update updates to content that are not new features, includes grammar fixes, added notes label Apr 30, 2025
Copy link
Contributor

@rchinn1 rchinn1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Left a few minor suggestions for your review

@@ -312,8 +312,10 @@ The Segment ID cookie is set with a one year expiration. However, there are some
- If you invoke any call before you set an `anonymousId`, Segment automatically sets the `anonymousId` first. This means if you explicitly set an `anonymousId`, you might give the user two `anonymousId`s or overwrite an existing one.
- If you fetch the `anonymousId` using `analytics.user().anonymousId()` before one is set, Segment generates and sets an `anonymousId` rather than returning `null`.
- If you call `analytics.identify()` with a `userId` that is different from the currently cached `userId`, this can overwrite the existing one and cause attribution problems.
- If you call `analytics.identify(xxx)` or `analytics.instance.user().id(xxx)`(On the NPM package, use `analytics.instance.user().id(xxx)`) with a `userId` that is different from the currently cached `userId`, this can overwrite the existing one and cause attribution problems.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- If you call `analytics.identify(xxx)` or `analytics.instance.user().id(xxx)`(On the NPM package, use `analytics.instance.user().id(xxx)`) with a `userId` that is different from the currently cached `userId`, this can overwrite the existing one and cause attribution problems.
- If you call `analytics.identify(xxx)` or `analytics.instance.user().id(xxx)`(In the NPM package, use `analytics.instance.user().id(xxx)`) with a `userId` that is different from the currently cached `userId`, this can overwrite the existing one and cause attribution problems.

| `callback` | optional | Function | A function executed after a timeout of 300 ms, giving the browser time to make outbound requests first. |


If you want to set the `userId` without sending an identify call, you can use `analytics.user().id('123')`. On the NPM package, use `analytics.instance.user().id(xxx)`. This method updates the stored `userId` locally without triggering a network request. This is helpful if you want to associate a user ID silently, without sending additional data to Segment or connected destinations. Be cautious when changing the `userId` mid-session to avoid double-counting users or splitting their identity history.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you want to set the `userId` without sending an identify call, you can use `analytics.user().id('123')`. On the NPM package, use `analytics.instance.user().id(xxx)`. This method updates the stored `userId` locally without triggering a network request. This is helpful if you want to associate a user ID silently, without sending additional data to Segment or connected destinations. Be cautious when changing the `userId` mid-session to avoid double-counting users or splitting their identity history.
If you want to set the `userId` without sending an identify call, you can use `analytics.user().id('123')`. In the NPM package, use `analytics.instance.user().id(xxx)`. This method updates the stored `userId` locally without triggering a network request. This is helpful if you want to associate a user ID silently, without sending additional data to Segment or connected destinations. Be cautious when changing the `userId` mid-session to avoid double-counting users or splitting their identity history.

@@ -182,7 +182,7 @@ Check to see if you changed how you call `analytics.reset()`. This utility metho

#### Overwriting an existing identity

Segment's analytics libraries include methods that allow you to overwrite both the `userId` (using `identify(xxx)`) and `anonymousId` (using `analytics.user().anonymousId(xxx)`). Using these methods on a user whose tracking information already includes an ID can cause the user to be counted more than once.
Segments analytics libraries include methods that allow you to overwrite both the `userId` (using `identify(xxx)` or `analytics.instance.user().id(xxx)`) and `anonymousId` (using `analytics.user().anonymousId(xxx)`).Using these methods on a user whose tracking information already includes an ID can cause the user to be counted more than once.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Segment’s analytics libraries include methods that allow you to overwrite both the `userId` (using `identify(xxx)` or `analytics.instance.user().id(xxx)`) and `anonymousId` (using `analytics.user().anonymousId(xxx)`).Using these methods on a user whose tracking information already includes an ID can cause the user to be counted more than once.
Segment’s analytics libraries include methods that allow you to overwrite both the `userId` (using `identify(xxx)` or `analytics.instance.user().id(xxx)`) and `anonymousId` (using `analytics.user().anonymousId(xxx)`). Using these methods on a user whose tracking information already includes an ID can cause the user to be counted more than once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content-update updates to content that are not new features, includes grammar fixes, added notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants