You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -48,40 +48,195 @@ You should make an `identify` call in the following situations:
48
48
49
49
## Soft User Registration
50
50
51
-
An anonymous user visits the site for the very first time. The home page has the analytics.js tracking snippet loaded in its header. When the page loads, this sets off the default `page` call to Segment. The Segment SDK generates and sets `anonymousId`.
51
+
An anonymous user visits the site for the very first time. The home page has the analytics.js tracking snippet loaded in its header. When the page loads, this sets off the default `page` call to Segment. The Segment SDK generates and sets `anonymousId`.
The user signs up for an email newsletter and fills out the form giving you their first and last name, as well as their email address. At this point, you will fire off an `identify` call. You won't yet assign them a user ID in this example, but you can still grab these traits about them.
You'll notice the identify call contains no `userId`. These traits will be associated to the `anonymousId` that is available in the user's cookie and `localStroage`.
64
117
65
-

<!--[No UserId in Payload](https://user-images.githubusercontent.com/78389005/214353985-599e7456-9295-4cb3-b97c-b30a9b905fcf.png)-->
66
161
67
162
68
163
## Full User Registration
69
164
70
-
An anonymous visitor registers for an account and becomes a known user. The account creation process allows you to assign a `userId` from your production database, as well as capture additional traits. For this example, the `userId` that is assigned is "123abc". This is when you'll want to fire an `identify` call with this user's newly assigned `userId` and additional traits.
165
+
An anonymous visitor registers for an account and becomes a known user. The account creation process allows you to assign a `userId` from your production database, as well as capture additional traits. For this example, the `userId` that is assigned is "123abc". This is when you'll want to fire an `identify` call with this user's newly assigned `userId` and additional traits.
71
166
72
-

167
+
```js
168
+
analytics.identify(`123abc`,{
169
+
phone:'555-555-5555',
170
+
address: {
171
+
street:'6th Street',
172
+
city:'San Fransisco',
173
+
state:'CA',
174
+
postalCode:'94103',
175
+
country:'US',
176
+
}
177
+
});
178
+
```
73
179
74
-
After you fire the `identify` call with the `userId`, you'll notice that the payload now has both a `userId`*and* an `anonymousId` attributed to the user.
180
+
<!---[Identify Call with UserId](https://user-images.githubusercontent.com/78389005/214355367-a24d55ce-4963-4da0-a67d-a8b1811ef0d0.png)--->
75
181
76
-

182
+
After you fire the `identify` call with the `userId`, you'll notice that the payload now has both a `userId`*and* an `anonymousId` attributed to the user.
<!---[Identify Payload with userId](https://user-images.githubusercontent.com/78389005/214355863-58c58cb7-f199-4bec-93b8-ab6487d6c0b3.png)--->
77
232
78
233
## Merging Identified and Anonymous user profiles
79
234
80
-
The illustration below shows a timeline with a user's interactions on a website, including sample API calls above that show Segment calls, and the user's `anonymousId` and `userId`.
235
+
<!--- The illustration below shows a timeline with a user's interactions on a website, including sample API calls above that show Segment calls, and the user's `anonymousId` and `userId`.
When the user first visits a page, Analytics.js automatically assigns the user an `anonymousId` and saves it to the user's `localStorage`. As the user interacts with the site, for example clicking around to different pages, Analytics.js includes this `anonymousId` and some [contextual information](/docs/connections/spec/common#context) with each `page` and `track` call. The contextual information might be the user's [IP address, browser, and more](/docs/connections/spec/common#context-fields-automatically-collected).
87
242
@@ -120,22 +275,22 @@ Let's go through some more scenarios to explain how an `anonymousId` is assigned
120
275
121
276
If a user clicks on an ad and is directed to a webpage, they are assigned an `anonymousId`. While this user is anonymous, they navigate to different pages and click around on the website. Say they come back two days later from the same device, sign up, and are assigned a `userId` from your database.
122
277
123
-

278
+
<!------>
124
279
125
280
For simplicity, we're assuming that the user has _not_ cleared their cookies or `localStorage`, where the original `anonymousId` is stored. If they had, they'd be assigned a new `anonymousId` when they visited the website, and the `userId` they got when they register on the website would _not_ be attached to the activities tracked with the old `anonymousId`.
126
281
127
282
#### Scenario #2 - Multi-day, multi-device, single login
128
283
129
284
In this scenario, the person uses both a web browser, and a mobile application to interact with your site. In each case, they are assigned a different `anonymousId`. In this scenario, the user signs up on the web browser, so their _web_ session is assigned a `userId`. However, because they do not log in on the mobile application, Segment cannot tie the mobile activity to this specific user. Their mobile application activity remains anonymous unless they log in on the mobile application.
Similar to the previous scenario, the user accessed both your website and mobile application, and also logged in on both. In this case, both sessions on the web and mobile app receive the user's `userId`, so Segment can tie the anonymous activity on both web and mobile to this user.
137
292
138
-

293
+
<!------>
139
294
140
295
141
296
## User profiles in warehouses
@@ -169,16 +324,16 @@ If you're tracking on the client and on the server, the `anonymousId` can be ret
169
324
```js
170
325
analytics.user().anonymousId()
171
326
```
172
-
327
+
<!---
173
328

If you're identifying on the server, then you will want to pass the user ID from the server to the client using an `identify` call with the `anonymousId`. That will allow the `userId` to be aliased with the existing `anonymousId` and stored in the cookie in localStorage. With that, all previous anonymous activity and all subsequent activity is associated to the newly generated `userId`, as well as existing `anonymousId`s.
178
335
179
-
If you're identifying on the server, then you will want to pass the user ID from the server to the client using an `identify` call with the `anonymousId`. That will allow the `userId` to be aliased with the existing `anonymousId` and stored in the cookie in localStorage. With that, all previous anonymous activity and all subsequent activity is associated to the newly generated `userId`, as well as exisiting `anonymousId`s.
180
-
181
-
There are some advantages to sending details about your users directly from your server once the user registers. Server library [Identify calls](/docs/connections/spec/identify) are invisible to the end user, making them more secure, and much more reliable. Or, if you want to send user data that is sensitive or which you don't want to expose to the client, then you can make an `identify` call from the server with all the traits you know about the user. More about [collecting data on the client or server](https://segment.com/docs/guides/how-to-guides/collect-on-client-or-server/#not-stored-in-your-database) in our documentation.
336
+
There are some advantages to sending details about your users directly from your server once the user registers. Server library [Identify calls](/docs/connections/spec/identify) are invisible to the end user, making them more secure, and much more reliable. Or, if you want to send user data that is sensitive or which you don't want to expose to the client, then you can make an `identify` call from the server with all the traits you know about the user. More about [collecting data on the client or server](https://segment.com/docs/guides/how-to-guides/collect-on-client-or-server/#not-stored-in-your-database) in Segment's documentation.
0 commit comments