Skip to content

Commit

Permalink
Adagio*: add adagioUtils.js, remove duplicated code (#11849)
Browse files Browse the repository at this point in the history
  • Loading branch information
osazos committed Jun 20, 2024
1 parent 27a2d3b commit 0ee1ba7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
35 changes: 35 additions & 0 deletions libraries/adagioUtils/adagioUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
canAccessWindowTop,
generateUUID,
getWindowSelf,
getWindowTop,
isSafeFrameWindow
} from '../../src/utils.js';

/**
* Returns the best Window object to use with ADAGIO.
* @returns {Window} window.top or window.self object
*/
export function getBestWindowForAdagio() {
return (canAccessWindowTop()) ? getWindowTop() : getWindowSelf();
}

/**
* Returns the window.ADAGIO global object used to store Adagio data.
* This object is created in window.top if possible, otherwise in window.self.
*/
export const _ADAGIO = (function() {
const w = getBestWindowForAdagio();

w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || generateUUID();
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
w.ADAGIO.queue = w.ADAGIO.queue || [];
w.ADAGIO.versions = w.ADAGIO.versions || {};
w.ADAGIO.versions.pbjs = '$prebid.version$';
w.ADAGIO.windows = w.ADAGIO.windows || [];
w.ADAGIO.isSafeFrameWindow = isSafeFrameWindow();

return w.ADAGIO;
})();
18 changes: 1 addition & 17 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import {
generateUUID,
getDNT,
getWindowSelf,
getWindowTop,
isArray,
isArrayOfNums,
isFn,
isInteger,
isNumber,
isSafeFrameWindow,
isStr,
logError,
logInfo,
Expand All @@ -26,6 +24,7 @@ import { config } from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { find } from '../src/polyfill.js';
import { getGptSlotInfoForAdUnitCode } from '../libraries/gptUtils/gptUtils.js';
import { _ADAGIO } from '../libraries/adagioUtils/adagioUtils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { userSync } from '../src/userSync.js';

Expand Down Expand Up @@ -78,21 +77,6 @@ export const ORTB_VIDEO_PARAMS = {
* Returns the window.ADAGIO global object used to store Adagio data.
* This object is created in window.top if possible, otherwise in window.self.
*/
const _ADAGIO = (function() {
const w = (canAccessWindowTop()) ? getWindowTop() : getWindowSelf();

w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || generateUUID();
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
w.ADAGIO.queue = w.ADAGIO.queue || [];
w.ADAGIO.versions = w.ADAGIO.versions || {};
w.ADAGIO.versions.pbjs = '$prebid.version$';
w.ADAGIO.isSafeFrameWindow = isSafeFrameWindow();

return w.ADAGIO;
})();

function getDevice() {
const language = navigator.language ? 'language' : 'userLanguage';
return {
Expand Down
20 changes: 2 additions & 18 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isStr,
prefixLog
} from '../src/utils.js';
import { _ADAGIO, getBestWindowForAdagio } from '../libraries/adagioUtils/adagioUtils.js';
import { getGptSlotInfoForAdUnitCode } from '../libraries/gptUtils/gptUtils.js';

/**
Expand All @@ -44,23 +45,6 @@ const { logError, logWarn } = prefixLog('AdagioRtdProvider:');
// Guard to avoid storing the same bid data several times.
const guard = new Set();

/**
* Returns the window.ADAGIO global object used to store Adagio data.
* This object is created in window.top if possible, otherwise in window.self.
*/
const _ADAGIO = (function() {
const w = (canAccessWindowTop()) ? getWindowTop() : getWindowSelf();

w.ADAGIO = w.ADAGIO || {};
w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || generateUUID();
w.ADAGIO.adUnits = w.ADAGIO.adUnits || {};
w.ADAGIO.pbjsAdUnits = w.ADAGIO.pbjsAdUnits || [];
w.ADAGIO.queue = w.ADAGIO.queue || [];
w.ADAGIO.windows = w.ADAGIO.windows || [];

return w.ADAGIO;
})();

/**
* Store the sampling data.
* This data is used to determine if beacons should be sent to adagio.
Expand Down Expand Up @@ -133,7 +117,7 @@ const _FEATURES = (function() {
features.data = {};
},
get: function() {
const w = (canAccessWindowTop()) ? getWindowTop() : getWindowSelf();
const w = getBestWindowForAdagio();

if (!features.initialized) {
features.data = {
Expand Down

0 comments on commit 0ee1ba7

Please sign in to comment.