Skip to content

Commit

Permalink
Default to fetch keepalive (prebid#11682)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Komorski <marcinkomorski@Marcins-MacBook-Pro.local>
  • Loading branch information
2 people authored and DecayConstant committed Jul 18, 2024
1 parent a5cefef commit 94b1e11
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 94b1e11

Please sign in to comment.