Skip to content

Commit b114a97

Browse files
committed
Identity edits
1 parent befac34 commit b114a97

File tree

1 file changed

+30
-24
lines changed
  • src/connections/sources/catalog/libraries/website/javascript

1 file changed

+30
-24
lines changed

src/connections/sources/catalog/libraries/website/javascript/identity.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: Managing identity in Analytics.js
33
strat: ajs
44
---
55

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.
77

8-
## Segment ID Persistence
8+
## Segment ID persistence
99

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.
1111

1212
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.
1313

@@ -30,8 +30,8 @@ Example:
3030
ajs_anonymous_id=%2239ee7ea5-b6d8-4174-b612-04e1ef3fa952
3131
```
3232

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)
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)
3535
- [Use a call to override the anonymousID](#override-the-default-anonymous-id-with-a-call)
3636
- [Set `anonymousId` in the `options` object of a call](#override-the-anonymous-id-using-the-options-object)
3737

@@ -43,9 +43,9 @@ You can get the user's current `anonymousId` using the following call:
4343
analytics.user().anonymousId();
4444
```
4545

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.
4747

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:
4949

5050
```js
5151
analytics.instance?.user().anonymousId()
@@ -57,28 +57,28 @@ A user's `anonymousId` changes when any of the following conditions are met.
5757
5858
- The user clears their cookies _and_ `localstorage`.
5959
- 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.
6262
6363
6464
### Override the Anonymous ID from the Segment snippet
6565
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.
6767
6868
```js
6969
analytics.load('writekey');
7070
analytics.page();
7171
analytics.setAnonymousId('ABC-123-XYZ');
7272
```
7373
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.
7575
7676
> 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.
7878
7979
### Override the default Anonymous ID with a call
8080
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:
8282
8383
```js
8484
analytics.user().anonymousId('ABC-123-XYZ');
@@ -92,17 +92,19 @@ These methods behave exactly the same.
9292
9393
### Override the Anonymous ID using the options object
9494
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:
9696
9797
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.
9999
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.
101101
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.
103103
104104
#### Override anonymousId in an Identify call
105105
106+
You can override an `anonymousID` with an Identify call. For example:
107+
106108
```js
107109
analytics.identify('user_123', {
108110
name: 'Jane Kim'
@@ -113,12 +115,16 @@ analytics.identify('user_123', {
113115
114116
#### Override anonymousId on a Page call
115117
118+
You can override an `anonymousID` with a Page call. For example:
119+
116120
```js
117121
analytics.page({}, { anonymousId: 'ABC-123-XYZ' });
118122
```
119123
120124
#### Override anonymousId on a Track call
121125
126+
You can override an `anonymousID` with a Track call. For example:
127+
122128
```js
123129
analytics.track('Email Clicked', {
124130
callToAction: 'Signup'
@@ -146,7 +152,7 @@ Consider this Identify event:
146152
```js
147153
analytics.identify('12091906-01011992', {
148154
plan_id: 'Paid, Tier 2',
149-
email: 'grace@usnavy.gov'
155+
email: 'grace@example.com'
150156
});
151157
```
152158
@@ -166,7 +172,7 @@ analytics.track('Clicked Email', {
166172
);
167173
```
168174
169-
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.
170176
171177
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.
172178
@@ -180,9 +186,9 @@ Each Analytics.js method has an `options` parameter where you can pass the `cont
180186
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.
181187
182188
183-
## Clearing Traits
189+
## Clearing traits
184190
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.
186192
187193
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:
188194
@@ -195,13 +201,13 @@ analytics.group().traits({});
195201
196202
## Using analytics.user() and analytics.group()
197203
198-
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.
199205
200206
<!-- TODO: retrieves info from cookie, if they have any info - maybe link to the top section-->
201207
202208
203209
> 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.
205211
206212
Examples:
207213
@@ -228,7 +234,7 @@ analytics.ready(function() {
228234
229235
## Anonymizing IP
230236
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.
232238
233239
> info "IPv6"
234240
> At the moment, Segment doesn't support automatically collecting IPv6 addresses.

0 commit comments

Comments
 (0)