Skip to content

Commit

Permalink
PB9: fix yukta analytics methods (#11475)
Browse files Browse the repository at this point in the history
* Update yuktamediaAnalyticsAdapter.js

* Update yuktamediaAnalyticsAdapter.js

* Update yuktamediaAnalyticsAdapter.js
  • Loading branch information
patmmccann authored May 14, 2024
1 parent d0c4ee1 commit 183515d
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions modules/yuktamediaAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {buildUrl, generateUUID, getWindowLocation, logError, logInfo, parseSizesInput, parseUrl} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
import {ajax, fetch} from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import adapterManager from '../src/adapterManager.js';
import { EVENTS, STATUS } from '../src/constants.js';
Expand Down Expand Up @@ -51,10 +51,6 @@ function getParameterByName(param) {
return vars[param] ? vars[param] : '';
}

function isNavigatorSendBeaconSupported() {
return ('navigator' in window) && ('sendBeacon' in window.navigator);
}

function updateSessionId() {
if (isSessionIdTimeoutExpired()) {
let newSessionId = generateUUID();
Expand Down Expand Up @@ -89,11 +85,14 @@ function send(data, status) {
hostname: 'analytics-prebid.yuktamedia.com',
pathname: '/api/bids'
});
if (isNavigatorSendBeaconSupported()) {
window.navigator.sendBeacon(yuktamediaAnalyticsRequestUrl, JSON.stringify(data));
} else {
fetch(yuktamediaAnalyticsRequestUrl, {
body: JSON.stringify(data),
keepalive: true,
withCredentials: true,
method: 'POST'
}).catch((_e) => {
ajax(yuktamediaAnalyticsRequestUrl, undefined, JSON.stringify(data), { method: 'POST', contentType: 'text/plain' });
}
});
}

var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoint' }), {
Expand Down

0 comments on commit 183515d

Please sign in to comment.