Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various modules: Send beacon wrapping fix #12236

Merged
merged 3 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions 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 @@ -629,9 +630,7 @@ function setCachedBidStatus(auctionId, bidId, status) {
* @param {string} endpoint URL
*/
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
9 changes: 3 additions & 6 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 @@ -228,9 +229,7 @@ export const spec = {
bid: bid
}
}
// 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 @@ -242,9 +241,7 @@ export const spec = {
bidderRequest: bidderRequest
}
}
// 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