Skip to content

Commit

Permalink
Default to fetch keepalive (#11682)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Komorski <[email protected]>
  • Loading branch information
mkomorski and Marcin Komorski committed Jun 4, 2024
1 parent 6478666 commit 82ce88e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/genericAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function defaultHandler({url, method, batchSize, ajax = ajaxBuilder()}) {
const serialize = method === 'GET' ? (data) => ({data: JSON.stringify(data)}) : (data) => JSON.stringify(data);

return function (events) {
ajax(url, callbacks, serialize(extract(events)), {method})
ajax(url, callbacks, serialize(extract(events)), {method, keepalive: true})
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export function toFetchRequest(url, data, options = {}) {
// but we're not in a secure context
rqOpts.browsingTopics = true;
}
if (options.keepalive) {
rqOpts.keepalive = true;
}
return dep.makeRequest(url, rqOpts);
}

Expand Down
4 changes: 2 additions & 2 deletions test/spec/modules/genericAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('Generic analytics', () => {
handler([payload, {}]);
sinon.assert.calledWith(ajax, url, sinon.match.any,
sinon.match(data => sinon.match(payload).test(parse(data))),
{method}
{method, keepalive: true}
);
});

Expand All @@ -275,7 +275,7 @@ describe('Generic analytics', () => {
handler(payload);
sinon.assert.calledWith(ajax, url, sinon.match.any,
sinon.match(data => sinon.match(payload).test(parse(data))),
{method}
{method, keepalive: true}
);
});
});
Expand Down

0 comments on commit 82ce88e

Please sign in to comment.