Skip to content

Commit 5bb1ed8

Browse files
authored
clean up code snippets and clarify keepalive
1 parent 5e2768f commit 5bb1ed8

File tree

1 file changed

+20
-14
lines changed
  • src/connections/sources/catalog/libraries/website/javascript

1 file changed

+20
-14
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,9 @@ Analytics.js stores events in `localStorage` and falls back to in-memory storage
584584

585585
## Delivery strategy configuration
586586

587-
## Add custom headers
587+
The `deliveryStrategy.config` object lets you customize how data is delivered to Segment. This includes options like setting custom headers and enabling `keepalive` to capture events during hard redirects.
588+
589+
### Adding custom headers
588590

589591
You can override default headers by providing custom headers in your configuration. Use the `deliveryStrategy.config.headers` option to specify the headers, like in the following example:
590592

@@ -605,24 +607,28 @@ analytics.load("<YOUR_WRITE_KEY>", {
605607

606608
You can use the `keepalive` option to make sure that Segment captures API calls triggered during a hard redirect. When enabled, `keepalive` will try to fire events before the redirect occurs.
607609

608-
By default, `keepalive` is set to false, because all fetch requests with the `keepalive` flag are subject to a 64kb size limit. Additionally, keepalive requests share this size limit with all other in-flight `keepalive` requests, regardless of whether they're related to Segment. This competition for resources can lead to data loss in some scenarios.
610+
By default, `keepalive` is set to false, because all fetch requests with the `keepalive` flag are subject to a 64kb size limit. Additionally, `keepalive` requests share this size limit with all other in-flight `keepalive` requests, regardless of whether they're related to Segment. This competition for resources can lead to data loss in some scenarios.
611+
612+
Segment only uses `keepalive` by default if:
613+
- The browser detects that the page is unloading (like if the user closes the tab or navigates away).
614+
- You have batching enabled.
615+
616+
To enable `keepalive`, use the following configuration:
609617

610618
```ts
611-
analytics.load("<YOUR_WRITE_KEY>",
612-
{
613-
integrations: {
614-
'Segment.io': {
615-
deliveryStrategy: {
616-
config: {
617-
keepalive: true
618-
},
619-
},
620-
},
621-
},
619+
analytics.load("<YOUR_WRITE_KEY>", {
620+
integrations: {
621+
'Segment.io': {
622+
deliveryStrategy: {
623+
config: {
624+
keepalive: true
625+
}
626+
}
627+
}
622628
}
629+
});
623630
```
624631

625-
626632
## Batching
627633
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:
628634
- Delivery of multiple events with fewer API calls

0 commit comments

Comments
 (0)