Skip to content

Commit dda1684

Browse files
author
markzegarelli
authored
Add content to explain the a.js delay loadfeature (#3905)
1 parent 610b267 commit dda1684

File tree

2 files changed

+36
-6
lines changed
  • .github/styles/Vocab/Docs
  • src/connections/sources/catalog/libraries/website/javascript

2 files changed

+36
-6
lines changed

.github/styles/Vocab/Docs/accept.txt

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Javascript
8181
Jebbit
8282
Jimo
8383
Jivox
84+
jQuery
8485
Kable
8586
Kameleoon
8687
Kissmetrics

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

+35-6
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ analytics.track(event, [properties], [options], [callback]);
121121

122122
The `track` call has the following fields:
123123

124-
Field | | Type | Description
125-
----- | | ---- | -----------
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-
`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-
`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 timeout of 300 ms, giving the browser time to make outbound requests first.
124+
| Field | Type | Description |
125+
| ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
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+
| `properties` | Object | Optional. 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+
| `options` | Object | Optional. 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` | Function | Optional. A function that runs after a timeout of 300 ms, giving the browser time to make outbound requests first. |
130130

131131
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).
132132

@@ -326,12 +326,41 @@ For more details about Alias, including the **`alias` call payload**, check out
326326

327327
The Analytics.js utility methods help you change how Segment loads on your page. They include:
328328

329+
- [Load](#load)
329330
- [Ready](#ready)
330331
- [Debug](#debug)
331332
- [On (Emitter)](#emitter)
332333
- [Timeout](#extending-timeout)
333334
- [Reset (Logout)](#reset-or-logout)
334335

336+
### Load
337+
338+
> info ""
339+
> The `load` method is available when you load analytics.js through the [NPM package](https://www.npmjs.com/package/@segment/analytics-next){:target="_blank"}.
340+
341+
You can load a buffered version of analytics.js that requires you call `load` explicitly to before analytics.js initiates any network activity. This is useful if you want to, for example, wait for user consent before you fetch tracking destinations or send buffered events to Segment.
342+
343+
> warning ""
344+
> Call `load` one time only.
345+
346+
```js
347+
export const analytics = new AnalyticsBrowser()
348+
349+
analytics.identify("hello world")
350+
351+
if (userConsentsToBeingTracked) {
352+
analytics.load({ writeKey: '<YOUR_WRITE_KEY>' }) // destinations loaded, enqueued events are flushed
353+
}
354+
```
355+
356+
You can also use `load` if you fetch some settings asynchronously.
357+
```js
358+
const analytics = new AnalyticsBrowser()
359+
fetchWriteKey().then(writeKey => analytics.load({ writeKey }))
360+
361+
analytics.identify("hello world")
362+
```
363+
335364
### Ready
336365

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

0 commit comments

Comments
 (0)