diff --git a/modules/magniteAnalyticsAdapter.js b/modules/magniteAnalyticsAdapter.js index c6911897e84..fdd33dffc6a 100644 --- a/modules/magniteAnalyticsAdapter.js +++ b/modules/magniteAnalyticsAdapter.js @@ -653,6 +653,25 @@ magniteAdapter.onDataDeletionRequest = function () { } }; +// send a beacon to see how many times this happens +window.addEventListener("beforeunload", function () { + const pendingAuctions = Object.keys(cache.auctions).length; + const pendingEvents = Object.keys(cache.pendingEvents).length && Object.keys(cache.pendingEvents).reduce((accum, eventName) => { + accum[eventName] = cache.pendingEvents[eventName].length; + return accum; + }, {}); + + if (pendingAuctions || pendingEvents) { + const payload = { + auctions: pendingAuctions, + ...pendingEvents, + ...getTopLevelDetails(), + trigger: 'unload' + } + navigator.sendBeacon(endpoint, JSON.stringify(payload)); + } +}); + magniteAdapter.MODULE_INITIALIZED_TIME = Date.now(); magniteAdapter.referrerHostname = ''; diff --git a/modules/rubiconAnalyticsAdapter.js b/modules/rubiconAnalyticsAdapter.js index 5c106bc47a4..70427cb310b 100644 --- a/modules/rubiconAnalyticsAdapter.js +++ b/modules/rubiconAnalyticsAdapter.js @@ -653,6 +653,25 @@ magniteAdapter.onDataDeletionRequest = function () { } }; +// send a beacon to see how many times this happens +window.addEventListener("beforeunload", function () { + const pendingAuctions = Object.keys(cache.auctions).length; + const pendingEvents = Object.keys(cache.pendingEvents).length && Object.keys(cache.pendingEvents).reduce((accum, eventName) => { + accum[eventName] = cache.pendingEvents[eventName].length; + return accum; + }, {}); + + if (pendingAuctions || pendingEvents) { + const payload = { + auctions: pendingAuctions, + ...pendingEvents, + ...getTopLevelDetails(), + trigger: 'unload' + } + navigator.sendBeacon(endpoint, JSON.stringify(payload)); + } +}); + magniteAdapter.MODULE_INITIALIZED_TIME = Date.now(); magniteAdapter.referrerHostname = '';