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

Adagio*: add adagioUtils.js and remove duplicated code #11849

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
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
Loading