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
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -659,11 +659,11 @@ Analytics.js stores events in `localStorage` and falls back to in-memory storage
659
659
660
660
## Batching
661
661
Batching is the ability to group multiple requests or calls into one request or API call. All requests sent within the same batch have the same `receivedAt` time. With Analytics.js, you can send events to Segment in batches. Sending events in batches enables you to have:
662
-
- Delivery of multiple events with fewer API calls, using the [batch endpoint](/docs/connections/sources/catalog/libraries/server/http-api/#batch)
662
+
- Delivery of multiple events with fewer API calls
663
663
- Fewer errors if a connection is lost because an entire batch will retry at once rather than multiple calls retrying at random times.
664
664
665
665
### Setup
666
-
You can start batching by changing the parameters for `size` and `timeout` within the `load` method in the analytics object. Batching requires both parameters.
666
+
You can start batching by changing the `strategy` to `"batching"` and the parameters for `size` and `timeout` within the `load` method in the analytics object. Batching requires both parameters.
667
667
668
668
```js
669
669
analytics.load("<write_key>", {
@@ -692,7 +692,7 @@ Your total batched events can’t exceed the maximum payload size of 500 KB, wit
692
692
`timeout` is the number of milliseconds that forces all events queued for batching to be sent, regardless of the batch size, once it’s reached. For example, `timeout: 5000` sends every event in the batch to Segment once 5 seconds passes.
693
693
694
694
### Implicit and explicit batching
695
-
All batching is done implicitly and doesn’t require you to change your Analytics.js implementation.
695
+
All batching is done implicitly as it doesn’t require you to change your Analytics.js implementation. Implicit batching is a great option is you want an out of the box approach to batching as you only need to add the required parameters to your load method (mentioned above in Setup) and Analytics.js will handle the rest.
696
696
697
697
You can fire your analytics events as usual and assume they’ll be delivered the same as individual events would. This code block shows implicit batching:
// These 5 events will potentially be delivered in the same batch, depending on how far apart they're executed (based on batching config)
712
712
```
713
713
714
-
You can get explicit delivery guarantees by changing the implicit code example above to this:
714
+
If you want to guarantee which specific events are delivered together in the batch, you can set up explicit batching by using `await Promise` and changing the implicit code example above to this:
#### Will Analytics.js deliver events that are in the queue when a user closes the browser?
746
-
Analytics.js will do its best to deliver the queued events before the browser closes, but the delivery isn’t guaranteed.
746
+
Analytics.js does its best to deliver the queued events before the browser closes, but the delivery isn’t guaranteed.
747
747
748
748
Upon receiving the `beforeunload` browser event, Analytics.js attempts to flush the queue using `fetch` requests with `keepalive` set to true. Since the max size of `keepalive` payloads is limited to 64 KB, if the queue size is bigger than 64 KB at the time the browser closes, then there is a chance of losing a subset of the queued events. Reducing the batch size or timeout will alleviate this issue, but that will be a trade-off decision.
0 commit comments