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
Copy file name to clipboardExpand all lines: src/connections/sources/catalog/libraries/website/javascript/identity.md
+30-24Lines changed: 30 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,11 @@ title: Managing identity in Analytics.js
3
3
strat: ajs
4
4
---
5
5
6
-
This page explains how Analytics.js identifies users, and passes userID and anonymousID data, and how to override and change this information.
6
+
This page explains how Analytics.js identifies users, passes `userID` and `anonymousID` data, and how to override and change this information.
7
7
8
-
## Segment ID Persistence
8
+
## Segment ID persistence
9
9
10
-
To ensure high fidelity, first-party customer data, Segment writes the user's IDs to the user's local storage, and uses that as the Segment ID on the cookie whenever possible. Local Storage is meant for storing this type of first-party customer information.
10
+
To ensure high fidelity, first-party customer data, Segment writes the user's IDs to the user's local storage, and uses that as the Segment ID on the cookie whenever possible. Local storage is meant for storing this type of first-party customer information.
11
11
12
12
If a user returns to your site after the cookie expires, Analytics.js looks for an old ID in the user's `localStorage`, and if one is found, sets it as the user's ID again in the new cookie. If a user clears their cookies _and_`localstorage`, all of the IDs are removed, and the user gets a completely new `anonymousID` when they next visit the page.
You can override the default-generated anonymousID in code using the methods described below:
34
-
-[Set anonymousId from the Segment snippet](#override-the-anonymous-id-from-the-segment-snippet) (before the `ready` method returns)
33
+
You can override the default-generated `anonymousID` in code using the methods described below:
34
+
-[Set anonymousId from the Segment snippet](#override-the-anonymous-id-from-the-segment-snippet) (before the Ready method returns)
35
35
-[Use a call to override the anonymousID](#override-the-default-anonymous-id-with-a-call)
36
36
-[Set `anonymousId` in the `options` object of a call](#override-the-anonymous-id-using-the-options-object)
37
37
@@ -43,9 +43,9 @@ You can get the user's current `anonymousId` using the following call:
43
43
analytics.user().anonymousId();
44
44
```
45
45
46
-
If the user's `anonymousId` is `null` (meaning not set) when you call this function, Analytics.js automatically generated and sets a new `anonymousId` for the user.
46
+
If the user's `anonymousId` is `null` (meaning not set) when you call this function, Analytics.js automatically generates and sets a new `anonymousId` for the user.
47
47
48
-
If you are using the npm library, the previous call returns a promise for `user()`. As a workaround, you'll need to grab the user's current `anonymousId` in the following way:
48
+
If you're using the npm library, the previous call returns a promise for `user()`. As a workaround, you'll need to grab the user's current `anonymousId` in the following way:
49
49
50
50
```js
51
51
analytics.instance?.user().anonymousId()
@@ -57,28 +57,28 @@ A user's `anonymousId` changes when any of the following conditions are met.
57
57
58
58
- The user clears their cookies _and_ `localstorage`.
59
59
- Your site or app calls [`analytics.reset()`](/docs/connections/sources/catalog/libraries/website/javascript/#reset-or-logout) during in the user's browser session.
60
-
- Your site or app calls `analytics.identify()` with a userId that is different from the current userId.
61
-
- Your site or app is setting `ajs_user_id` to an empty string or calling `analytics.user().id('')` before calling `analytics.identify()`. This sequence of events will result in a new anonymousId being set when `analytics.identify()` is called.
60
+
- Your site or app calls `analytics.identify()` with a `userId` that is different from the current `userId`.
61
+
- Your site or app is setting `ajs_user_id` to an empty string or calling `analytics.user().id('')` before calling `analytics.identify()`. This sequence of events will result in a new `anonymousId` being set when `analytics.identify()` is called.
62
62
63
63
64
64
### Override the Anonymous ID from the Segment snippet
65
65
66
-
You can also set the `anonymousId` immediately inside your Segment snippet, even before the `ready` method returns.
66
+
You can also set the `anonymousId` immediately inside your Segment snippet, even before the Ready method returns.
67
67
68
68
```js
69
69
analytics.load('writekey');
70
70
analytics.page();
71
71
analytics.setAnonymousId('ABC-123-XYZ');
72
72
```
73
73
74
-
Use this method if you are queueing calls before `ready` returns and they require a custom `anonymousId`. Keep in mind that setting the `anonymousId` in Analytics.js does not overwrite the anonymous tracking IDs for any destinations you're using.
74
+
Use this method if you are queueing calls before Ready returns and they require a custom `anonymousId`. Keep in mind that setting the `anonymousId` in Analytics.js does not overwrite the anonymous tracking IDs for any destinations you're using.
75
75
76
76
> info ""
77
-
> Device-mode destinations that load their code on your site _might_ also set their own anonymous ID for the user that is separate and different from the Segment generated one. Some destinations use the Segment `anonymousId`. Read the documentation for each Destination to find out if a Destination sets its own ID.
77
+
> Device-mode destinations that load their code on your site _might_ also set their own anonymous ID for the user that is separate and different from the Segment generated one. Some destinations use the Segment `anonymousId`. Read the documentation for each destination to find out if a destination sets its own ID.
78
78
79
79
### Override the default Anonymous ID with a call
80
80
81
-
If the default generated UUID does not meet your needs, you can override it`anonymousId` for the current user using either of the following methods.
81
+
If the default generated UUID does not meet your needs, you can override the`anonymousId` for the current user with either of the following methods:
82
82
83
83
```js
84
84
analytics.user().anonymousId('ABC-123-XYZ');
@@ -92,17 +92,19 @@ These methods behave exactly the same.
92
92
93
93
### Override the Anonymous ID using the options object
94
94
95
-
Or in the `options` object of [`identify`](/docs/connections/spec/identify/), [`page`](/docs/connections/spec/page/), or [`track`](/docs/connections/spec/track/) calls, like this:
95
+
You can override the `anonymousID`in the `options` object of [Identify](/docs/connections/spec/identify/), [Page](/docs/connections/spec/page/), or [Track](/docs/connections/spec/track/) calls, like this:
96
96
97
97
98
-
Set the anonymousId in the Options object using the format in the following examples.
98
+
Set the `anonymousId` in the `options` object using the format in the following examples.
99
99
100
-
The custom anonymousId persists when you use these methods, even if you do not explicitly specify the anonymousId in the calls.
100
+
The custom `anonymousId` persists when you use these methods, even if you do not explicitly specify the `anonymousId` in the calls.
101
101
102
-
For example, after the Track call below sets the anonId, any later track calls from this user will have the anonymousId of `ABC-123-XYZ`, even if it is not explicitly specified in the track call.
102
+
For example, after a Track call sets the `anonymousID` to `ABC-123-XYZ`, any additional Track calls from this user will have the same `anonymousId`, even if it's not explicitly specified in the Track call.
103
103
104
104
#### Override anonymousId in an Identify call
105
105
106
+
You can override an `anonymousID` with an Identify call. For example:
This appends the `plan_id` trait to this Track event. This does _not_ add the name or email, since those traits were not added to the `context` object. You must do this for every following event you want these traits to appear on, as the `traits` object does not persist between calls.
175
+
This appends the `plan_id` trait to the Track event. This does _not_ add the name or email, since those traits were not added to the `context` object. You must do this for every following event you want these traits to appear on, as the `traits` object does not persist between calls.
170
176
171
177
By default, non-Identify events (like Track or Page) **don't automatically collect user traits** from previous Identify calls. To include traits from an `identify()` event in later events, you'll need to add them manually to the `context.traits` object within the `options` parameter.
172
178
@@ -180,9 +186,9 @@ Each Analytics.js method has an `options` parameter where you can pass the `cont
180
186
Adding traits to events is especially useful if you're using [Actions destinations](/docs/connections/destinations/actions/), since it makes those traits available for mapping in the destination’s configuration.
181
187
182
188
183
-
## Clearing Traits
189
+
## Clearing traits
184
190
185
-
You can pass an empty object to the `traits` object to clear _all_ cached traits for a User or Group.
191
+
You can pass an empty object to the `traits` object to clear _all_ cached traits for a user or group.
186
192
187
193
Traits are cached by default when you call the Identify and Group methods. You can clear the `traits` object for the user or group by passing `traits` an empty object:
You can use the `user` or `group` method as soon as the Analytics.js library loads, to return information about the currently identified user or group. This information is retrieved from the user's cookie.
204
+
You can use the User or Group method as soon as the Analytics.js library loads, to return information about the currently identified user or group. This information is retrieved from the user's cookie.
199
205
200
206
<!-- TODO: retrieves info from cookie, if they have any info - maybe link to the top section-->
201
207
202
208
203
209
> success ""
204
-
> **Tip:** You can wrap any reference to `user()` or `group()` in a [ready function block](/docs/connections/sources/catalog/libraries/website/javascript#ready) to ensure that Analytics.js has fully loaded so these methods are available.
210
+
> You can wrap any reference to `user()` or `group()` in a [ready function block](/docs/connections/sources/catalog/libraries/website/javascript#ready) to ensure that Analytics.js has fully loaded so these methods are available.
205
211
206
212
Examples:
207
213
@@ -228,7 +234,7 @@ analytics.ready(function() {
228
234
229
235
## Anonymizing IP
230
236
231
-
Segment automatically collects the user's IP address for device-based (iOS, Android, Analytics.js and Xamarin) events.
237
+
Segment automatically collects the user's IP address for device-based (iOS, Android, Analytics.js, and Xamarin) events.
232
238
233
239
> info "IPv6"
234
240
> At the moment, Segment doesn't support automatically collecting IPv6 addresses.
0 commit comments