Skip to content

Commit

Permalink
#11838 send beacon fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Komorski authored and Marcin Komorski committed Sep 12, 2024
1 parent 9c16cfb commit e44eaa5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion modules/33acrossAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import adapterManager, { coppaDataHandler, gdprDataHandler, gppDataHandler, uspD
* @typedef {typeof import('../src/constants.js').EVENTS} EVENTS
*/
import { EVENTS } from '../src/constants.js';
import { sendBeacon } from '../src/ajax.js';

/** @typedef {'pending'|'available'|'targetingSet'|'rendered'|'timeout'|'rejected'|'noBid'|'error'} BidStatus */
/**
Expand Down Expand Up @@ -631,7 +632,7 @@ function setCachedBidStatus(auctionId, bidId, status) {
function sendReport(report, endpoint) {
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line
if (navigator.sendBeacon(endpoint, JSON.stringify(report))) {
if (sendBeacon(endpoint, JSON.stringify(report))) {
log.info(`Analytics report sent to ${endpoint}`, report);

return;
Expand Down
5 changes: 3 additions & 2 deletions modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {getStorageManager} from '../src/storageManager.js';
import {BANNER} from '../src/mediaTypes.js';
import {generateUUID, getParameterByName, isNumber, logError, logInfo} from '../src/utils.js';
import {hasPurpose1Consent} from '../src/utils/gdpr.js';
import { sendBeacon } from '../src/ajax.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -230,7 +231,7 @@ export const spec = {
}
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
},

onBidderError: function (error, bidderRequest) {
Expand All @@ -244,7 +245,7 @@ export const spec = {
}
// TODO FIX THIS RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
sendBeacon(EVENT_ENDPOINT, JSON.stringify(event))
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
Expand Down
9 changes: 2 additions & 7 deletions modules/sirdataRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @requires module:modules/realTimeData
*/
import adapterManager from '../src/adapterManager.js';
import { ajax } from '../src/ajax.js';
import { ajax, sendBeacon } from '../src/ajax.js';
import {
deepAccess, checkCookieSupport, deepSetValue, hasDeviceAccess, inIframe, isEmpty,
logError, logInfo, mergeDeep
Expand Down Expand Up @@ -217,12 +217,7 @@ export function postContentForSemanticAnalysis(postContentToken, actualUrl) {
if (payload && payload.length > 300 && payload.length < 300000) {
const url = `https://contextual.sirdata.io/api/v1/push/contextual?post_content_token=${postContentToken}&url=${encodeURIComponent(actualUrl)}`;

// Use the Beacon API if supported to send the payload
if ('sendBeacon' in navigator) {
// TODO FIX RULES VIOLATION
// eslint-disable-next-line prebid/no-member
navigator.sendBeacon(url, payload);
} else {
if (!sendBeacon(url, payload)) {
// Fallback to using AJAX if Beacon API is not supported
ajax(url, {}, payload, {
contentType: 'text/plain',
Expand Down

0 comments on commit e44eaa5

Please sign in to comment.