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
@@ -461,11 +460,6 @@ The `reset` method only clears the cookies and `localStorage` created by Segment
461
460
462
461
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.
463
462
464
-
### Keepalive
465
-
466
-
You can utilize this in instances where an API call fires on a hard redirect, and are missed from getting captured in Segment. If you set this flag to true, it enables firing the event before the redirect. This is available for all events. You can read more about this in the [Github PR](https://github.com/segmentio/analytics-next/issues/768#issuecomment-1386100830){:target="_blank"}.
467
-
468
-
469
463
## Managing data flow with the Integrations object
This way, you can conditionally load integrations based on what customers opt into on your site. The example below shows how you might load only the tools that the user agreed to use.
@@ -589,6 +583,47 @@ When enabled, Analytics.js automatically retries network and server errors. With
589
583
Analytics.js stores events in `localStorage` and falls back to in-memory storage when `localStorage` is unavailable. It retries up to 10 times with an incrementally increasing back-off time between each retry. Analytics.js queues up to 100 events at a time to avoid using too much of the device's local storage. See the [destination Retries documentation](/docs/connections/destinations/#retries) to learn more.
590
584
591
585
586
+
## Headers
587
+
588
+
### Add custom headers
589
+
You can override your headers by custom
590
+
```ts
591
+
analytics.load("<YOUR_WRITE_KEY>",
592
+
{
593
+
integrations: {
594
+
'Segment.io': {
595
+
deliveryStrategy: {
596
+
config: {
597
+
headers: { 'x-api-key': 'foo' }
598
+
},
599
+
},
600
+
},
601
+
},
602
+
}
603
+
```
604
+
605
+
## Keepalive
606
+
607
+
You can utilize this in instances where an API call fires on a hard redirect, and are missed from getting captured in Segment. If you set this flag to true, it enables firing the event before the redirect.
608
+
609
+
By default, this is set to `false`. This is because there is a 64kb limit for all fetch requests with keepalive. So when sending keepalive requests, you are competing with other in-flight keepalive requests, regardless of being Segment related requests or not -- which can result in data loss in some scenarios. By default, we only use keep-alive if 1. the page is 'unloading' and 2. the user is using batching.
610
+
611
+
```ts
612
+
analytics.load("<YOUR_WRITE_KEY>",
613
+
{
614
+
integrations: {
615
+
'Segment.io': {
616
+
deliveryStrategy: {
617
+
config: {
618
+
keepalive: true
619
+
},
620
+
},
621
+
},
622
+
},
623
+
}
624
+
```
625
+
626
+
592
627
## Batching
593
628
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:
594
629
- Delivery of multiple events with fewer API calls
0 commit comments