Skip to content

Commit 3b6bdf7

Browse files
Paul BoocockMitch Pierias
authored andcommitted
Allow alternative Access-Control-Allow-Credentials values (close snowplow#808)
Co-authored-by: Mitch Pierias <mitchell.pierias@dominos.com.au>
1 parent ea0a687 commit 3b6bdf7

8 files changed

Lines changed: 46 additions & 4 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker-core",
5+
"comment": "Allow alternative Access-Control-Allow-Credentials values (#808)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker-core"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-tracker",
5+
"comment": "Allow alternative Access-Control-Allow-Credentials values (#808)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-tracker"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/javascript-tracker",
5+
"comment": "Allow alternative Access-Control-Allow-Credentials values (#808)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/javascript-tracker"
10+
}

libraries/browser-tracker-core/src/tracker/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ export function Tracker(
262262
trackerConfiguration.maxLocalStorageQueueSize ?? 1000,
263263
trackerConfiguration.connectionTimeout ?? 5000,
264264
configAnonymousServerTracking,
265-
trackerConfiguration.customHeaders ?? {}
265+
trackerConfiguration.customHeaders ?? {},
266+
trackerConfiguration.withCredentials ?? true
266267
),
267268
// Whether pageViewId should be regenerated after each trackPageView. Affect web_page context
268269
preservePageViewId = false,

libraries/browser-tracker-core/src/tracker/out_queue.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface OutQueue {
5757
* @param maxLocalStorageQueueSize - Maximum number of queued events we will attempt to store in local storage
5858
* @param connectionTimeout - Defines how long to wait before aborting the request
5959
* @param anonymousTracking - Defines whether to set the SP-Anonymous header for anonymous tracking on GET and POST
60+
* @param customHeaders - Allows custom headers to be defined and passed on XMLHttpRequest requests
61+
* @param withCredentials - Sets the value of the withCredentials flag on XMLHttpRequest (GET and POST) requests
6062
* @returns object OutQueueManager instance
6163
*/
6264
export function OutQueueManager(
@@ -71,7 +73,8 @@ export function OutQueueManager(
7173
maxLocalStorageQueueSize: number,
7274
connectionTimeout: number,
7375
anonymousTracking: boolean,
74-
customHeaders: Record<string, string>
76+
customHeaders: Record<string, string>,
77+
withCredentials: boolean
7578
): OutQueue {
7679
type PostEvent = {
7780
evt: Record<string, unknown>;
@@ -405,7 +408,7 @@ export function OutQueueManager(
405408
} else {
406409
xhr.open('GET', url, !sync);
407410
}
408-
xhr.withCredentials = true;
411+
xhr.withCredentials = withCredentials;
409412
if (anonymousTracking) {
410413
xhr.setRequestHeader('SP-Anonymous', '*');
411414
}

libraries/browser-tracker-core/src/tracker/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ export type TrackerConfiguration = {
9292
* @defaultValue 63072000 (2 years)
9393
*/
9494
cookieLifetime?: number;
95+
/**
96+
* Sets the value of the withCredentials flag
97+
* on XMLHttpRequest (GET and POST) requests
98+
* @defaultValue true
99+
*/
100+
withCredentials?: boolean;
95101
/**
96102
* How long until a session expires
97103
* @defaultValue 1800 (30 minutes)

libraries/browser-tracker-core/test/out_queue.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('OutQueueManager', () => {
5151
maxQueueSize,
5252
5000,
5353
false,
54-
{}
54+
{},
55+
true
5556
);
5657
});
5758

trackers/browser-tracker/docs/browser-tracker.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ export type TrackerConfiguration = {
311311
cookieSameSite?: CookieSameSite;
312312
cookieSecure?: boolean;
313313
cookieLifetime?: number;
314+
withCredentials?: boolean;
314315
sessionCookieTimeout?: number;
315316
appId?: string;
316317
platform?: Platform;

0 commit comments

Comments
 (0)