Skip to content

Commit b96a0c2

Browse files
authored
Merge pull request #7682 from segmentio/Analytics.js-edits-2
More Analytics.js cleanup
2 parents adac18a + 7f4b4e4 commit b96a0c2

File tree

6 files changed

+108
-99
lines changed

6 files changed

+108
-99
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ Analytics.js doesn't automatically collect IPv6 addresses. If IPv6 is available
99

1010
## Is there a size limit on requests?
1111

12-
Yes, the limit is 32KB per event message. Events with a payload larger than 32KB are not accepted by Analytics.js. Segment servers return a 400 response with the error message: `Exceed payload limit`.
12+
Yes, the limit is 32 KB per event message. Events with a payload larger than 32 KB are not accepted by Analytics.js. Segment servers return a 400 response with the error message: `Exceed payload limit`.
1313

1414
## If Analytics.js fails to load, are callbacks not fired?
1515

16-
In the event that Analytics.js does not load, callbacks passed into your API calls do not fire. This is as designed, because the purpose of callbacks are to provide an estimate that the event was delivered and if the library never loads, the events won't be delivered.
16+
In the event that Analytics.js does not load, callbacks passed into your API calls do not fire. This is by design, because the purpose of a callback is to provide an indication that the event was delivered. If the library never loads, the events won't be delivered.
1717

1818
## Is there an updated version of the Segment snippet?
1919
Segment released an updated version of the Analytics.js snippet, which introduces several enhancements and fixes that might improve your setup. For a full list of version updates, see the Analytics.js snippet's [Releases](https://github.com/segmentio/snippet/releases){:target="_blank”}.
2020

21-
You can find the latest version of the Segment snippet in your JavaScript source's Overview tab or in the [Quickstart: Analytics.js](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2a-add-the-segment-snippet) documentation.
21+
You can find the latest version of the Segment snippet in your JavaScript source's **Overview** tab or in the [Quickstart: Analytics.js](/docs/connections/sources/catalog/libraries/website/javascript/quickstart/#step-2a-add-the-segment-snippet) documentation.
2222

2323
While there is no deadline to upgrade your snippet to the latest version, upgrading lets you use the latest improvements in the Segment library.
2424

@@ -27,16 +27,16 @@ While there is no deadline to upgrade your snippet to the latest version, upgrad
2727

2828
In May 2018, Segment began collecting client-side performance metrics in Analytics.js. This includes metrics like:
2929

30-
- When client side integrations are initialized and when they fail
31-
- When messages are sent to client side integrations and when they fail
30+
- When client-side integrations are initialized and when they fail
31+
- When messages are sent to client-side integrations and when they fail
3232

33-
Segment added these metrics to proactively identify and resolve issues with individual client-side integrations. These metrics are connected to alerts that notify Segment's on-call engineers to take action on these quickly.
33+
Segment added these metrics to proactively identify and resolve issues with individual client-side integrations. These metrics trigger alerts that notify Segment's on-call engineers to take action promptly.
3434

3535
There should be no noticeable impact to your data flow. You may notice Analytics.js make an extra network request in the network tab to carry the metrics data to Segment's servers. This extra network request is not made frequently, since the data is sampled and batched every 30 seconds.
3636

3737
## How are properties with `null` and `undefined` values treated?
3838

39-
Segment treats property values set to `null` as null values and drops events set to`undefined`.
39+
Segment treats property values set to `null` as null values and drops events set to `undefined`.
4040

4141
For example:
4242

@@ -48,6 +48,7 @@ console.log(JSON.stringify({ x: undefined, y: 6 }));
4848
// expected output: "{"y":6}"
4949
```
5050
Segment uses the [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify){:target="blank"} method under the hood.
51+
5152
## Can I overwrite the context fields?
5253

5354
Yes. This can be useful if some of these fields contain information you don't want to collect.
@@ -65,7 +66,7 @@ analytics.track("Receipt Viewed", {}, {
6566
```
6667
This works for any [context field](/docs/connections/spec/common/#context) that Segment automatically collects.
6768

68-
When working with Page calls, you can overwrite context fields by following the above instructions. However, because the `context.page` fields are also available in the `properties` parameter for page calls, you must also prevent the same fields in the `properties` parameter from being included in your Page call. Use the code in the following example to overwrite `url` available in context field `page.url` and properties parameter:
69+
When working with Page calls, you can overwrite context fields by following the above instructions. However, because the `context.page` fields are also available in the `properties` parameter for Page calls, you must also prevent the same fields in the `properties` parameter from being included in your Page call. Use the code in the following example to overwrite `url` available in context field `page.url` and properties parameter:
6970

7071
```js
7172
analytics.page("Receipt Page", {
@@ -79,7 +80,7 @@ analytics.page("Receipt Page", {
7980

8081
## Can I add context fields that do not already exist?
8182

82-
Yes. You can add context fields by passing them into the options object as the third argument of the event call. For example, the analytics.js library does not automatically collect location information, but you can add it to the context object. To add location information into the context object, pass it into the third argument as in the following example:
83+
Yes. You can add context fields by passing them into the options object as the third argument of the event call. For example, the Analytics.js library does not automatically collect location information, but you can add it to the context object. To add location information into the context object, pass it into the third argument as in the following example:
8384

8485
```js
8586
analytics.track("Order Completed", {}, {
@@ -97,7 +98,7 @@ Some destinations accept properties only. As a result, custom context fields you
9798

9899
## What is the impact of exposing the source's write keys?
99100

100-
Segment's library architecture requires you to expose the write key for client-side tracking to work. Other major tools, like Google Analytics, Mixpanel, Kissmetrics, Hubspot, and Marketo, also require you to expose your write key.
101+
Segment's library architecture requires you to expose the write key for client-side tracking to work. Other major tools, like Google Analytics, Mixpanel, Kissmetrics, HubSpot, and Marketo, also require you to expose your write key.
101102

102103
If you see any unusual behavior associated with your write key, generate a new key immediately. To generate a new key, navigate to **Connections > Sources** and select your source. On the **Settings** tab, go to the **API Keys** section and click **Generate New Key**.
103104

@@ -126,7 +127,7 @@ You'll also need to modify the Segment script with your `nonce` tag, which shoul
126127
127128
## How is the referrer value set?
128129

129-
The Analytics.js library sets the `context.page.referrer` value from the [`window.document.referrer` property](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer){:target="_blank"} set in the browser. If you notice unexpected referrer values reaching Segment, check how this value is being set on your website.
130+
The Analytics.js library sets the `context.page.referrer` value from the [`window.document.referrer` property](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer){:target="_blank"} set in the browser. If you notice unexpected referrer values reaching Segment, check how this value is set on your website.
130131

131132
## Are there any rate limits in place for the CDN settings endpoint?
132133

@@ -142,4 +143,4 @@ If you need this functionality, you have a couple of options:
142143
**Use a third-party API**: Alternatively, you can use third-party services like Geolocation API to convert IP addresses to geolocation data. Afterward, you can pass this information as a trait in Identify calls or as a property in Track calls to Segment. This allows you to manage geolocation data according to your specific needs, though it will likely require engineering resources.
143144

144145
## Why is my payload populating incorrectly?
145-
Payload parameters aren't populated in a guaranteed order. Your payload should still be ingested as long as all necessary parameters are included.
146+
Payload parameters aren't populated in a guaranteed order. Your payload will still be ingested as long as all necessary parameters are included.

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 `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 `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 `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)