From 2f87c35b8ba3e2a15ce14c5994c07f19c559caa2 Mon Sep 17 00:00:00 2001 From: aman-adpushup Date: Fri, 4 Jul 2025 16:20:17 +0530 Subject: [PATCH] code for gpid gpt dependency removed --- modules/gptPreAuction.js | 56 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/modules/gptPreAuction.js b/modules/gptPreAuction.js index bf5b4a55dbb..7d3fcf1ebf3 100644 --- a/modules/gptPreAuction.js +++ b/modules/gptPreAuction.js @@ -1,47 +1,63 @@ import { deepAccess, - isAdUnitCodeMatchingSlot, - isGptPubadsDefined, logInfo, pick, deepSetValue } from '../src/utils.js'; import {config} from '../src/config.js'; import {getHook} from '../src/hook.js'; -import {find} from '../src/polyfill.js'; const MODULE_NAME = 'GPT Pre-Auction'; export let _currentConfig = {}; let hooksAdded = false; -export const appendGptSlots = adUnits => { - const { customGptSlotMatching } = _currentConfig; +window.adpushup = window.adpushup || {}; +const adp = window.adpushup; +const adpConfig = adp.config || {}; - if (!isGptPubadsDefined()) { - return; +window.adpTags = window.adpTags || {}; +const adpTags = window.adpTags; +const adpSlots = adpTags.adpSlots || {}; + +const getAdUnitPath = function(code) { + const adpSlot = adpSlots[code]; + if (!adpSlot) return null; + const {childPublisherId,isMcmEnabled=false } = adpConfig.mcm; + + let dfpNetwork = adpSlot.activeDFPNetwork; + if (isMcmEnabled) { + dfpNetwork += `,${childPublisherId}`; } + const dfpAdUnitCode = adpSlot.currentGptSlotData && adpSlot.currentGptSlotData.dfpAdunitCode; + return `/${dfpNetwork}/${dfpAdUnitCode}`; +} +export const appendGptSlots = adUnits => { + if (!adpSlots) { + return; + } const adUnitMap = adUnits.reduce((acc, adUnit) => { acc[adUnit.code] = acc[adUnit.code] || []; acc[adUnit.code].push(adUnit); return acc; }, {}); - window.googletag.pubads().getSlots().forEach(slot => { - const matchingAdUnitCode = find(Object.keys(adUnitMap), customGptSlotMatching - ? customGptSlotMatching(slot) - : isAdUnitCodeMatchingSlot(slot)); - + for (adUnit in adpSlots) { + const matchingAdUnitCode = Object.keys(adUnitMap).find((key) => key === adUnit); if (matchingAdUnitCode) { const adserver = { - name: 'gam', - adslot: sanitizeSlotPath(slot.getAdUnitPath()) + name: "gam", + adslot: sanitizeSlotPath(getAdUnitPath(adUnit)), }; adUnitMap[matchingAdUnitCode].forEach((adUnit) => { - deepSetValue(adUnit, 'ortb2Imp.ext.data.adserver', Object.assign({}, adUnit.ortb2Imp?.ext?.data?.adserver, adserver)); + deepSetValue( + adUnit, + "ortb2Imp.ext.data.adserver", + Object.assign({}, adUnit.ortb2Imp?.ext?.data?.adserver, adserver) + ); }); } - }); + } }; const sanitizeSlotPath = (path) => { @@ -62,13 +78,11 @@ const defaultPreAuction = (adUnit, adServerAdSlot) => { return context.pbadslot; } - // confirm that GPT is set up - if (!isGptPubadsDefined()) { - return; + if (!adpSlots) { + return } - // find all GPT slots with this name - var gptSlots = window.googletag.pubads().getSlots().filter(slot => slot.getAdUnitPath() === adServerAdSlot); + var gptSlots = Object.keys(adpSlots).filter(slot => getAdUnitPath(slot) === adServerAdSlot); if (gptSlots.length === 0) { return; // should never happen