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/index.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ Field | | Type | Description
76
76
`userId` | optional | String | The database ID for the user. If you don't know who the user is yet, you can omit the `userId` and just record `traits`. You can read more about identities in the [identify reference](/docs/connections/spec/identify).
77
77
`traits` | optional | Object | A dictionary of traits you know about the user, like `email` or `name`. You can read more about traits in the [identify reference](/docs/connections/spec/identify/).
78
78
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `traits` object, pass an empty object (as an '{}') before `options`._
79
-
`callback` | optional | Function | A function executed after a short timeout, giving the browser time to make outbound requests first.
79
+
`callback` | optional | Function | A function executed after a timeout of 300 ms, giving the browser time to make outbound requests first.
80
80
81
81
By default, Analytics.js caches traits in the browser's `localStorage` and attaches them to each Identify call.
82
82
@@ -126,7 +126,7 @@ Field | | Type | Description
126
126
`event`| | String | The name of the event you're tracking. You can read more about the [track method](/docs/connections/spec/track) and recommended event names.
127
127
`properties` | optional | Object | A dictionary of [properties](/docs/connections/spec/track#properties) for the event. If the event was `'Added to Cart'`, it might have properties like `price` and `productType`.
128
128
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
129
-
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
129
+
`callback` | optional | Function | A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.
130
130
131
131
The only required argument in Analytics.js is an _event name string_. You can read more about [how Segment recommends you name events](/docs/connections/spec/track#event).
For more information about choosing which events to track, event naming and more, check out [Analytics Academy](https://segment.com/academy/).
142
+
For more information about choosing which events to track, event naming, and more, check out [Analytics Academy](https://segment.com/academy/){:target="_blank"}.
143
143
144
144
The only required argument on Track calls in Analytics.js is an `event` name string. Read more about how Segment recommends [naming your events](/docs/connections/spec/track#event).
145
145
146
146
147
147
#### Track Link
148
148
149
149
`trackLink` is a helper method that attaches the `track` call as a handler to a link.
150
-
With `trackLink`, Analytics.js inserts a short timeout (300 ms) to give the `track` call more time. This is useful when a page would redirect before the `track` method could complete all requests.
150
+
With `trackLink`, Analytics.js inserts a timeout of 300 ms to give the `track` call more time. This is useful when a page would redirect before the `track` method could complete all requests.
`trackForm` is a helper method that binds a `track` call to a form submission.
177
-
The `trackForm` method inserts a short timeout (300 ms) to give the `track` call more time to complete. This is useful to prevent a page from redirecting before the `track` method could complete all requests.
177
+
The `trackForm` method inserts a timeout of 300 ms to give the `track` call more time to complete. This is useful to prevent a page from redirecting before the `track` method could complete all requests.
178
178
179
179
The `trackForm` method follows the format below.
180
180
@@ -222,7 +222,7 @@ Field | | Type | Description
222
222
`name` | optional | String | The name of the page.
223
223
`properties` | optional | Object | A dictionary of properties of the page. Note: Analytics.js collects `url`, `title`, `referrer` and `path` are automatically. This defaults to a `canonical url`, if available, and falls back to `document.location.href`.
224
224
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
225
-
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
225
+
`callback` | optional | Function | A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.
226
226
227
227
#### Default Page Properties
228
228
@@ -266,7 +266,7 @@ analytics.page('Pricing', {
266
266
267
267
The Group method associates an [identified user](/docs/connections/sources/catalog/libraries/website/javascript/#identify) with a company, organization, project, workspace, team, tribe, platoon, assemblage, cluster, troop, gang, party, society or any other collective noun you come up with for the same concept.
268
268
269
-
This is useful for <!-- Business-to-Business (B2B) -->tools like [Intercom](/docs/connections/destinations/catalog/intercom/), [Preact](/docs/connections/destinations/catalog/preact/) and [Totango](/docs/connections/destinations/catalog/totango/), as it ties the user to a **group** of other users.
269
+
This is useful for <!-- Business-to-Business (B2B) -->tools like [Intercom](/docs/connections/destinations/catalog/intercom/), [Preact](/docs/connections/destinations/catalog/preact/), and [Totango](/docs/connections/destinations/catalog/totango/), as it ties the user to a **group** of other users.
270
270
271
271
272
272
The Group method follows the format below.
@@ -281,7 +281,7 @@ Field | | Type | Description
281
281
`groupId` | | String | The Group ID to associate with the current user.
282
282
`traits` | optional | Object | A dictionary of [traits](/docs/connections/spec/group#traits) for the group. Example traits for a group include `address`, `website`, and `employees`.
283
283
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call. _Note: If you do not pass a `properties` object, pass an empty object (like '{}') before `options`_.
284
-
`callback` | optional | Function | A function that runs after a short timeout, giving the browser time to make outbound requests first.
284
+
`callback` | optional | Function | A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first.
285
285
286
286
Example `group` call:
287
287
@@ -302,7 +302,7 @@ Find more details about `group`, including the `group` payload, in [the Group Sp
302
302
303
303
The Alias method combines two unassociated user identities. Segment usually handles aliasing automatically when you call `identify` on a user, however some tools require an explicit `alias` call.
304
304
305
-
This is an advanced method, but it is required to manage user identities successfully in *some* Segment destinations like [Kissmetrics](/docs/connections/destinations/catalog/kissmetrics/#alias) and [Mixpanel](/docs/connections/destinations/catalog/mixpanel/#alias). <!-- TODO: LR Dests question: is this still true? Is there a list of the ones that require this?-->
305
+
This is an advanced method, but it's required to manage user identities successfully in *some* Segment destinations like [Kissmetrics](/docs/connections/destinations/catalog/kissmetrics/#alias) and [Mixpanel](/docs/connections/destinations/catalog/mixpanel/#alias). <!-- TODO: LR Dests question: is this still true? Is there a list of the ones that require this?-->
306
306
307
307
The Alias method follows the format below:
308
308
@@ -317,7 +317,7 @@ Field | | Type | Description
317
317
`userId` | | String | The new user ID you want to associate with the user.
318
318
`previousId` | optional | String | The previous ID that the user was recognized by. This defaults to the currently identified user's ID.
319
319
`options` | optional | Object | A dictionary of options. For example, [enable or disable specific destinations](#managing-data-flow-with-the-integrations-object) for the call.
320
-
`callback` | optional | Function | A function that is executed after a short timeout, giving the browser time to make outbound requests first.
320
+
`callback` | optional | Function | A function that is executed after a timeout of 300 ms, giving the browser time to make outbound requests first.
321
321
322
322
For more details about Alias, including the **`alias` call payload**, check out the [Segment Spec](/docs/connections/spec/alias/).
323
323
@@ -334,9 +334,9 @@ The Analytics.js utility methods help you change how Segment loads on your page.
334
334
335
335
### Ready
336
336
337
-
The `ready` method allows you to pass in a method that is called once Analytics.js finishes initializing, and once all enabled device-mode destinations load. It's like [jQuery's `ready` method](https://api.jquery.com/ready/), except for Destinations.
337
+
The `ready` method allows you to pass in a method that is called once Analytics.js finishes initializing, and once all enabled device-mode destinations load. It's like [jQuery's `ready` method](https://api.jquery.com/ready/){:target="_blank"}, except for Destinations.
338
338
339
-
The `ready` method is not invoked if any Destination throws an error (for example, for an expired API key, incorrect settings configuration, or when a Destination is blocked by the browser) during initialization.
339
+
The `ready` method isn't invoked if any Destination throws an error (for example, for an expired API key, incorrect settings configuration, or when a Destination is blocked by the browser) during initialization.
340
340
341
341
The code in the `ready` function only executes after `ready` is emitted.
342
342
@@ -378,9 +378,9 @@ analytics.debug(false);
378
378
379
379
### Emitter
380
380
381
-
The global `analytics` object emits events whenever you call `alias`, `group`, `identify`, `track` or `page`.
381
+
The global `analytics` object emits events whenever you call `alias`, `group`, `identify`, `track`, or `page`.
382
382
383
-
Use the `on` method to set listeners for these events and run your own custom code. This can be useful if you want to send data to a service for which Segment does not have a destination.
383
+
Use the `on` method to set listeners for these events and run your own custom code. This can be useful if you want to send data to a service for which Segment doesn't have a destination.
384
384
385
385
```js
386
386
analytics.on(method, callback);
@@ -411,14 +411,14 @@ This method emits events _before_ they are processed by the Segment integration,
411
411
412
412
The `timeout` method sets the length (in milliseconds) of callbacks and helper functions. This is useful if you have multiple scripts that need to fire in your callback or `trackLink`, `trackForm` helper function.
413
413
414
-
The example below sets the timeout to 500ms.
414
+
The example below sets the timeout to 500 ms.
415
415
416
416
```js
417
417
analytics.timeout(500);
418
418
```
419
419
420
420
> success "Tip"
421
-
> If you're triggering ad network conversion pixels, Segment recommends extending timeout to 500ms to account for slow load times.
421
+
> If you're triggering ad network conversion pixels, Segment recommends extending timeout to 500 ms to account for slow load times.
422
422
423
423
424
424
### Reset or Logout
@@ -429,9 +429,9 @@ Calling `reset` resets the `id`, including `anonymousId`, and clears `traits` fo
429
429
analytics.reset();
430
430
```
431
431
432
-
The `reset` method only clears the cookies and `localStorage` created by Segment. It does not clear data from other integrated tools, as those native libraries might set their own cookies to manage user tracking, sessions, and manage state. To completely clear out the user session, see the documentation provided by those tools.
432
+
The `reset` method only clears the cookies and `localStorage` created by Segment. It doesn't clear data from other integrated tools, as those native libraries might set their own cookies to manage user tracking, sessions, and manage state. To completely clear out the user session, see the documentation provided by those tools.
433
433
434
-
Segment does not share `localStorage` across subdomains. If you use Segment tracking on multiple subdomains, you must call `analytics.reset()` for each subdomain to completely clear out the user session.
434
+
Segment doesn't share `localStorage` across subdomains. If you use Segment tracking on multiple subdomains, you must call `analytics.reset()` for each subdomain to completely clear out the user session.
You don't need to include `'All': true` in this call because it is implied as the default behavior. Instead, only list the destinations that you want to exclude, with a `false` flag for each.
476
+
You don't need to include `'All': true` in this call because it's implied as the default behavior. Instead, only list the destinations that you want to exclude, with a `false` flag for each.
477
477
478
478
Destination flags are **case sensitive** and match [the destination's name in the docs](/docs/connections/destinations/) (for example, "AdLearn Open Platform", "awe.sm", "Mailchimp", etc). If a Destination has more than one acceptable name, this appears in the documentation for that destination.
479
479
@@ -488,7 +488,7 @@ Destination flags are **case sensitive** and match [the destination's name in th
488
488
489
489
You can modify the `.load` method in Analytics.js (the second line of the snippet) to take a second argument. If you pass an object with an `integrations` dictionary (matching the format [above](#selecting-destinations-with-the-integrations-object)), then Segment only loads the integrations in that dictionary that are marked as enabled with the boolean value `true`.
490
490
491
-
You can only call `.load` on page load, or reload (refresh). If you modify the `.load` method between page loads, it does not have any effect until the page is reloaded.
491
+
You can only call `.load` on page load, or reload (refresh). If you modify the `.load` method between page loads, it doesn't have any effect until the page is reloaded.
492
492
493
493
For example:
494
494
@@ -570,7 +570,7 @@ Upon receiving the `beforeunload` browser event, Analytics.js attempts to flush
570
570
No. Batching is only supported as part of Analytics.js 2.0.
571
571
572
572
#### Can other destinations receive batched events?
573
-
No, this batching only impacts events sent to Segment. Once the batch reaches Segment, it is split up and follows the normal path of an event.
573
+
No, this batching only impacts events sent to Segment. Once the batch reaches Segment, it's split up and follows the normal path of an event.
574
574
575
575
#### Will batching impact billing or throughput?
576
576
No, batching won't impact billing or throughput.
@@ -732,13 +732,13 @@ Analytics.js tracks across subdomains out of the box; all Segment destinations f
732
732
733
733
## Analytics.js Performance
734
734
735
-
The Analytics.js library and all Destination libraries are loaded with the [HTML script `async` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async). This also means that Segment fires methods asynchronously, so you should adjust your code accordingly if you require that events be sent from the browser in a specific order.
735
+
The Analytics.js library and all Destination libraries are loaded with the [HTML script `async` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-async){:target="_blank"}. This also means that Segment fires methods asynchronously, so you should adjust your code accordingly if you require that events be sent from the browser in a specific order.
736
736
737
-
While many tools require access to the DOM or cookies, for the Zendesk, Salesforce, and Mailchimp destinations, Segment does not need to load a native JavaScript library. Instead, Segment's servers send data to the end-tools.
737
+
While many tools require access to the DOM or cookies, for the Zendesk, Salesforce, and Mailchimp destinations, Segment doesn't need to load a native JavaScript library. Instead, Segment's servers send data to the end-tools.
738
738
739
739
Segment loads the libraries required for your **enabled** Destinations. When you disable a destination, the custom version of Analytics.js loaded on your site stops requesting that library.
740
740
741
-
Using Analytics.js does not offer a large performance benefit, but is more performant than installing each of the destinations individually. And as more destinations move to accept data directly from Segment, you'll receive more performance benefits automatically.
741
+
Using Analytics.js doesn't offer a large performance benefit, but is more performant than installing each of the destinations individually. And as more destinations move to accept data directly from Segment, you'll receive more performance benefits automatically.
742
742
743
743
One option, if you don't want to use any bundled third-party tools, is to use the browserify'd [analytics-node](https://github.com/segmentio/analytics-node) package. <!-- TODO LR note: WTF does "browserified" mean-->
744
744
@@ -757,7 +757,7 @@ Analytics.js uses `localstorage` cookies if you have retries enabled, to keep tr
757
757
- The `reclaimStart` and `reclaimEnd` cookies determine if a tab takes over the queue from another tab.
758
758
- The `inProgress` and `queue` cookies track events in progress, and events queued for retry.
759
759
760
-
For more information, visit the [Segment localstorage-retry library](https://github.com/segmentio/localstorage-retry).
760
+
For more information, visit the [Segment localstorage-retry library](https://github.com/segmentio/localstorage-retry){:target="_blank"}.
761
761
762
762
You can set the `debug` cookie to `analytics.js` to log debug messages from Analytics.js to the console.
0 commit comments