Skip to content
Open
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
10 changes: 6 additions & 4 deletions modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { percentInView } from '../libraries/percentInView/percentInView.js';
import {getMinSize} from '../libraries/sizeUtils/sizeUtils.js';
import {isIframe} from '../libraries/omsUtils/index.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

// **************************** UTILS ************************** //
const BIDDER_CODE = '33across';
Expand Down Expand Up @@ -373,7 +374,7 @@ function _getProduct(bidRequest) {
// BUILD REQUESTS: BANNER
function _buildBannerORTB(bidRequest) {
const bannerAdUnit = deepAccess(bidRequest, 'mediaTypes.banner', {});
const element = _getAdSlotHTMLElement(bidRequest.adUnitCode);
const element = _getAdSlotHTMLElement(bidRequest);

const sizes = _transformSizes(bannerAdUnit.sizes);

Expand Down Expand Up @@ -478,6 +479,7 @@ function _getViewability(element, topWin, { w, h } = {}) {
: 0;
}

// TODO use utils/adUnits once that's unified in 11
function _mapAdUnitPathToElementId(adUnitCode) {
if (isGptPubadsDefined()) {
// eslint-disable-next-line no-undef
Expand All @@ -500,9 +502,9 @@ function _mapAdUnitPathToElementId(adUnitCode) {
return null;
}

function _getAdSlotHTMLElement(adUnitCode) {
return document.getElementById(adUnitCode) ||
document.getElementById(_mapAdUnitPathToElementId(adUnitCode));
function _getAdSlotHTMLElement(bidRequest) {
return getAdUnitElement(bidRequest) ||
document.getElementById(_mapAdUnitPathToElementId(bidRequest.adUnitCode));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { getGptSlotInfoForAdUnitCode } from '../libraries/gptUtils/gptUtils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { userSync } from '../src/userSync.js';
import { validateOrtbFields } from '../src/prebid.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

const BIDDER_CODE = 'adagio';
const LOG_PREFIX = 'Adagio:';
Expand Down Expand Up @@ -466,7 +467,7 @@ const OUTSTREAM_RENDERER = {
return;
}

const el = document.getElementById(bid.adUnitCode);
const el = getAdUnitElement(bid);

renderer.bootstrap(config, el, override);
},
Expand Down
1 change: 1 addition & 0 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ function getElementFromTopWindow(element, currentWindow) {
};

function getSlotPosition(divId) {
// TODO: this should use getAdUnitElement
if (!isSafeFrameWindow() && !canAccessWindowTop()) {
return '';
}
Expand Down
3 changes: 2 additions & 1 deletion modules/adnuntiusAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ajax} from '../src/ajax.js';
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
import { EVENTS } from '../src/constants.js';
import adapterManager from '../src/adapterManager.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

const URL = 'https://analytics.adnuntius.com/prebid';
const REQUEST_SENT = 1;
Expand Down Expand Up @@ -36,7 +37,7 @@ const adnAnalyticsAdapter = Object.assign(adapter({url: '', analyticsType: 'endp
cache.auctions[args.auctionId].gdprApplies = args.gdprConsent ? args.gdprConsent.gdprApplies : undefined;
cache.auctions[args.auctionId].gdprConsent = args.gdprConsent ? args.gdprConsent.consentString : undefined;

const container = document.getElementById(bidReq.adUnitCode);
const container = getAdUnitElement(bidReq);
const containerAttr = container ? container.getAttribute('data-adunitid') : undefined;
const adUnitId = containerAttr || undefined;

Expand Down
3 changes: 2 additions & 1 deletion modules/adotBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { isArray, isBoolean, isFn, isPlainObject, isStr, logError, replaceAuctionPrice } from '../src/utils.js';
import { OUTSTREAM } from '../src/video.js';
import { NATIVE_ASSETS_IDS as NATIVE_ID_MAPPING, NATIVE_ASSETS as NATIVE_PLACEMENTS } from '../libraries/braveUtils/nativeAssets.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -495,7 +496,7 @@ function buildRenderer(bid, mediaType) {
ad.renderer.push(() => {
const domContainer = container
? document.querySelector(container)
: document.getElementById(adUnitCode);
: getAdUnitElement(ad)

const player = new window.VASTPlayer(domContainer);

Expand Down
8 changes: 4 additions & 4 deletions modules/adrelevantisBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js';
import {chunk} from '../libraries/chunk/chunk.js';
import {transformSizes} from '../libraries/sizeUtils/tranformSize.js';
import {hasUserInfo, hasAppDeviceInfo, hasAppId} from '../libraries/adrelevantisUtils/bidderUtils.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -250,18 +251,17 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) {

/**
* This function hides google div container for outstream bids to remove unwanted space on page. Appnexus renderer creates a new iframe outside of google iframe to render the outstream creative.
* @param {string} elementId element id
*/
function hidedfpContainer(elementId) {
var el = document.getElementById(elementId).querySelectorAll("div[id^='google_ads']");
function hidedfpContainer(bid) {
var el = getAdUnitElement(bid).querySelectorAll("div[id^='google_ads']");
if (el[0]) {
el[0].style.setProperty('display', 'none');
}
}

function outstreamRender(bid) {
// push to render queue because ANOutstreamVideo may not be loaded yet
hidedfpContainer(bid.adUnitCode);
hidedfpContainer(bid);
bid.renderer.push(() => {
window.ANOutstreamVideo.renderAd({
tagId: bid.adResponse.tag_id,
Expand Down
15 changes: 8 additions & 7 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import {convertCamelToUnderscore, appnexusAliases} from '../libraries/appnexusUtils/anUtils.js';
import {convertTypes} from '../libraries/transformParamsUtils/convertTypes.js';
import {chunk} from '../libraries/chunk/chunk.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -1177,11 +1178,10 @@ function buildNativeRequest(params) {

/**
* This function hides google div container for outstream bids to remove unwanted space on page. Appnexus renderer creates a new iframe outside of google iframe to render the outstream creative.
* @param {string} elementId element id
*/
function hidedfpContainer(elementId) {
function hidedfpContainer(container) {
try {
const el = document.getElementById(elementId).querySelectorAll("div[id^='google_ads']");
const el = container.querySelectorAll("div[id^='google_ads']");
if (el[0]) {
el[0].style.setProperty('display', 'none');
}
Expand All @@ -1190,10 +1190,10 @@ function hidedfpContainer(elementId) {
}
}

function hideSASIframe(elementId) {
function hideSASIframe(container) {
try {
// find script tag with id 'sas_script'. This ensures it only works if you're using Smart Ad Server.
const el = document.getElementById(elementId).querySelectorAll("script[id^='sas_script']");
const el = container.querySelectorAll("script[id^='sas_script']");
if (el[0].nextSibling && el[0].nextSibling.localName === 'iframe') {
el[0].nextSibling.style.setProperty('display', 'none');
}
Expand All @@ -1203,8 +1203,9 @@ function hideSASIframe(elementId) {
}

function outstreamRender(bid, doc) {
hidedfpContainer(bid.adUnitCode);
hideSASIframe(bid.adUnitCode);
const container = getAdUnitElement(bid);
hidedfpContainer(container);
hideSASIframe(container);
// push to render queue because ANOutstreamVideo may not be loaded yet
bid.renderer.push(() => {
const win = doc?.defaultView || window;
Expand Down
3 changes: 2 additions & 1 deletion modules/bidViewabilityIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { logMessage } from '../src/utils.js';
import { config } from '../src/config.js';
import * as events from '../src/events.js';
import {EVENTS} from '../src/constants.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

const MODULE_NAME = 'bidViewabilityIO';
const CONFIG_ENABLED = 'enabled';
Expand Down Expand Up @@ -80,7 +81,7 @@ export const init = () => {
events.on(EVENTS.AD_RENDER_SUCCEEDED, ({doc, bid, id}) => {
if (isSupportedMediaType(bid)) {
const viewable = new IntersectionObserver(viewCallbackFactory(bid), getViewableOptions(bid));
const element = document.getElementById(bid.adUnitCode);
const element = getAdUnitElement(bid);
viewable.observe(element);
}
});
Expand Down
3 changes: 2 additions & 1 deletion modules/concertBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getStorageManager } from '../src/storageManager.js';
import { hasPurpose1Consent } from '../src/utils/gdpr.js';
import { getBoundingClientRect } from '../libraries/boundingClientRect/boundingClientRect.js';
import { getViewportCoordinates } from '../libraries/viewport/viewport.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -70,7 +71,7 @@ export const spec = {

payload.slots = validBidRequests.map((bidRequest) => {
eids.push(...(bidRequest.userIdAsEids || []));
const adUnitElement = document.getElementById(bidRequest.adUnitCode);
const adUnitElement = getAdUnitElement(bidRequest);
const coordinates = getOffset(adUnitElement);

const slot = {
Expand Down
5 changes: 3 additions & 2 deletions modules/connatixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
BANNER,
VIDEO,
} from '../src/mediaTypes.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

const BIDDER_CODE = 'connatix';

Expand Down Expand Up @@ -111,7 +112,7 @@ export function _getViewability(element, topWin, { w, h } = {}) {
}

export function detectViewability(bid) {
const { params, adUnitCode } = bid;
const { params } = bid;

const viewabilityContainerIdentifier = params.viewabilityContainerIdentifier;

Expand All @@ -137,7 +138,7 @@ export function detectViewability(bid) {
bidParamSizes = typeof bidParamSizes === 'undefined' && bid.mediaType && bid.mediaType.video && bid.mediaType.video.playerSize ? bid.mediaType.video.playerSize : bidParamSizes;
bidParamSizes = typeof bidParamSizes === 'undefined' && bid.mediaType && bid.mediaType.video && isNumber(bid.mediaType.video.w) && isNumber(bid.mediaType.h) ? [bid.mediaType.video.w, bid.mediaType.video.h] : bidParamSizes;
minSize = _getMinSize(bidParamSizes ?? [])
element = document.getElementById(adUnitCode);
element = getAdUnitElement(bid);
}

if (_isViewabilityMeasurable(element)) {
Expand Down
2 changes: 2 additions & 0 deletions modules/contxtfulRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ function getDivIdPosition(divId) {

let domElement;

// TODO: this should use getAdUnitElement
if (inIframe() === true) {
const ws = getWindowSelf();
const currentElement = ws.document.getElementById(divId);
Expand Down Expand Up @@ -335,6 +336,7 @@ function tryGetDivIdPosition(divIdMethod) {
return undefined;
}

// TODO unified adUnit/element association in 11
function tryMultipleDivIdPositions(adUnit) {
const divMethods = [
// ortb2\
Expand Down
3 changes: 2 additions & 1 deletion modules/cwireBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getBoundingClientRect } from "../libraries/boundingClientRect/boundingC
import { hasPurpose1Consent } from "../src/utils/gdpr.js";
import { sendBeacon } from "../src/ajax.js";
import { isAutoplayEnabled } from "../libraries/autoplayDetection/autoplay.js";
import {getAdUnitElement} from '../src/utils/adUnits.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand All @@ -35,7 +36,7 @@ export const storage = getStorageManager({ bidderCode: BIDDER_CODE });
*/
function slotDimensions(bid) {
const adUnitCode = bid.adUnitCode;
const slotEl = document.getElementById(adUnitCode);
const slotEl = getAdUnitElement(bid);

if (slotEl) {
logInfo(`Slot element found: ${adUnitCode}`);
Expand Down
1 change: 1 addition & 0 deletions modules/eplanningBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ function _mapAdUnitPathToElementId(adUnitCode) {
}

function _getAdSlotHTMLElement(adUnitCode) {
// TODO: this should use getAdUnitElement
return document.getElementById(adUnitCode) ||
document.getElementById(_mapAdUnitPathToElementId(adUnitCode));
}
Expand Down
4 changes: 2 additions & 2 deletions modules/fanBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getBidFloor } from '../libraries/currencyUtils/floor.js';
import { getStorageManager } from '../src/storageManager.js';
import { Renderer } from '../src/Renderer.js';
import { getGptSlotInfoForAdUnitCode } from '../libraries/gptUtils/gptUtils.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

const BIDDER_CODE = 'freedomadnetwork';
const BIDDER_VERSION = '0.2.0';
Expand Down Expand Up @@ -349,8 +350,7 @@ function createRenderer(bid, videoPlayerUrl) {

try {
renderer.setRender(function (bidResponse) {
const divId = document.getElementById(bid.adUnitCode) ? bid.adUnitCode : getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId;
const adUnit = document.getElementById(divId);
const adUnit = getAdUnitElement(bidResponse) ?? document.getElementById(getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId)

if (!window.createOutstreamPlayer) {
logWarn('Renderer error: outstream player is not available');
Expand Down
3 changes: 2 additions & 1 deletion modules/gamoshiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {ortbConverter} from '../libraries/ortbConverter/converter.js';
import {ortb25Translator} from '../libraries/ortb2.5Translator/translator.js';
import {getCurrencyFromBidderRequest} from '../libraries/ortb2Utils/currency.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';
const ENDPOINTS = {
'gamoshi': 'https://rtb.gamoshi.io',
'cleanmedianet': 'https://bidder.cleanmediaads.com'
Expand Down Expand Up @@ -250,7 +251,7 @@ function renderOutstream(bid) {
window['GamoshiPlayer'].renderAd({
id: unitId,
debug: window.location.href.indexOf('pbjsDebug') >= 0,
placement: document.getElementById(bid.adUnitCode),
placement: getAdUnitElement(bid),
width: bid.width,
height: bid.height,
events: {
Expand Down
3 changes: 2 additions & 1 deletion modules/h12mediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inIframe, logError, logMessage, deepAccess, getWinDimensions } from '..
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getBoundingClientRect } from '../libraries/boundingClientRect/boundingClientRect.js';
import { getViewportSize } from '../libraries/viewport/viewport.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';
const BIDDER_CODE = 'h12media';
const DEFAULT_URL = 'https://bidder.h12-media.com/prebid/';
const DEFAULT_CURRENCY = 'USD';
Expand Down Expand Up @@ -30,7 +31,7 @@ export const spec = {
pubsubid = '';
}
const pubcontainerid = bidderParams.pubcontainerid;
const adUnitElement = document.getElementById(pubcontainerid || bidRequest.adUnitCode);
const adUnitElement = pubcontainerid ? document.getElementById(pubcontainerid) : getAdUnitElement(bidRequest);
const ishidden = !isVisible(adUnitElement);
const framePos = getFramePos();
const coords = isiframe ? {
Expand Down
7 changes: 4 additions & 3 deletions modules/hypelabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDevicePixelRatio } from '../libraries/devicePixelRatio/devicePixelRa
import { ajax } from '../src/ajax.js';
import { getBoundingClientRect } from '../libraries/boundingClientRect/boundingClientRect.js';
import { getWalletPresence, getWalletProviderFlags } from '../libraries/hypelabUtils/hypelabUtils.js';
import {getAdUnitElement} from '../src/utils/adUnits.js';

export const BIDDER_CODE = 'hypelab';
export const ENDPOINT_URL = 'https://api.hypelab.com';
Expand Down Expand Up @@ -55,7 +56,7 @@ function buildRequests(validBidRequests, bidderRequest) {
winDimensions?.innerHeight || 0
),
];
const pp = getPosition(request.adUnitCode);
const pp = getPosition(request);

const payload = {
property_slug: request.params.property_slug,
Expand Down Expand Up @@ -121,8 +122,8 @@ function getBidFloor(bid, sizes) {
return floor;
}

function getPosition(id) {
const element = document.getElementById(id);
function getPosition(bidRequest) {
const element = getAdUnitElement(bidRequest);
if (!element) return null;
const rect = getBoundingClientRect(element);
return [rect.left, rect.top];
Expand Down
Loading
Loading