diff --git a/libraries/gptUtils/gptUtils.js b/libraries/gptUtils/gptUtils.js index 950f28c618f..25c1de03538 100644 --- a/libraries/gptUtils/gptUtils.js +++ b/libraries/gptUtils/gptUtils.js @@ -1,5 +1,6 @@ +import { CLIENT_SECTIONS } from '../../src/fpd/oneClient.js'; import {find} from '../../src/polyfill.js'; -import {compareCodeAndSlot, isGptPubadsDefined} from '../../src/utils.js'; +import {compareCodeAndSlot, deepAccess, isGptPubadsDefined, uniques} from '../../src/utils.js'; /** * Returns filter function to match adUnitCode in slot @@ -35,3 +36,24 @@ export function getGptSlotInfoForAdUnitCode(adUnitCode) { } return {}; } + +export const taxonomies = ['IAB_AUDIENCE_1_1', 'IAB_CONTENT_2_2']; + +export function getSignals(fpd) { + const signals = Object.entries({ + [taxonomies[0]]: getSegments(fpd, ['user.data'], 4), + [taxonomies[1]]: getSegments(fpd, CLIENT_SECTIONS.map(section => `${section}.content.data`), 6) + }).map(([taxonomy, values]) => values.length ? {taxonomy, values} : null) + .filter(ob => ob); + + return signals; +} + +export function getSegments(fpd, sections, segtax) { + return sections + .flatMap(section => deepAccess(fpd, section) || []) + .filter(datum => datum.ext?.segtax === segtax) + .flatMap(datum => datum.segment?.map(seg => seg.id)) + .filter(ob => ob) + .filter(uniques) +} diff --git a/modules/dfpAdServerVideo.js b/modules/dfpAdServerVideo.js index 3d1fbfa0788..7d0c02ba78a 100644 --- a/modules/dfpAdServerVideo.js +++ b/modules/dfpAdServerVideo.js @@ -3,6 +3,7 @@ */ import { DEFAULT_DFP_PARAMS, DFP_ENDPOINT } from '../libraries/dfpUtils/dfpUtils.js'; +import { getSignals } from '../libraries/gptUtils/gptUtils.js'; import { registerVideoSupport } from '../src/adServerManager.js'; import { gdprDataHandler } from '../src/adapterManager.js'; import { getPPID } from '../src/adserver.js'; @@ -11,7 +12,6 @@ import { config } from '../src/config.js'; import { EVENTS } from '../src/constants.js'; import * as events from '../src/events.js'; import { getHook } from '../src/hook.js'; -import { getSignals } from '../src/pps.js'; import { getRefererInfo } from '../src/refererDetection.js'; import { targeting } from '../src/targeting.js'; import { diff --git a/modules/gptPreAuction.js b/modules/gptPreAuction.js index a4d4cebccea..e7e541b2161 100644 --- a/modules/gptPreAuction.js +++ b/modules/gptPreAuction.js @@ -1,41 +1,30 @@ +import { getSignals as getSignalsFn, getSegments as getSegmentsFn, taxonomies } from '../libraries/gptUtils/gptUtils.js'; +import { auctionManager } from '../src/auctionManager.js'; +import { config } from '../src/config.js'; +import { TARGETING_KEYS } from '../src/constants.js'; +import { getHook } from '../src/hook.js'; +import { find } from '../src/polyfill.js'; import { deepAccess, + deepSetValue, isAdUnitCodeMatchingSlot, isGptPubadsDefined, logInfo, + logWarn, pick, - deepSetValue, logWarn, uniques + uniques } from '../src/utils.js'; -import {config} from '../src/config.js'; -import {getHook} from '../src/hook.js'; -import {find} from '../src/polyfill.js'; -import { auctionManager } from '../src/auctionManager.js'; -import { CLIENT_SECTIONS } from '../src/fpd/oneClient.js'; -import { TARGETING_KEYS } from '../src/constants.js'; const MODULE_NAME = 'GPT Pre-Auction'; export let _currentConfig = {}; let hooksAdded = false; -export const taxonomies = ['IAB_AUDIENCE_1_1', 'IAB_CONTENT_2_2']; - export function getSegments(fpd, sections, segtax) { - return sections - .flatMap(section => deepAccess(fpd, section) || []) - .filter(datum => datum.ext?.segtax === segtax) - .flatMap(datum => datum.segment?.map(seg => seg.id)) - .filter(ob => ob) - .filter(uniques) + return getSegmentsFn(fpd, sections, segtax); } export function getSignals(fpd) { - const signals = Object.entries({ - [taxonomies[0]]: getSegments(fpd, ['user.data'], 4), - [taxonomies[1]]: getSegments(fpd, CLIENT_SECTIONS.map(section => `${section}.content.data`), 6) - }).map(([taxonomy, values]) => values.length ? {taxonomy, values} : null) - .filter(ob => ob); - - return signals; + return getSignalsFn(fpd); } export function getSignalsArrayByAuctionsIds(auctionIds, index = auctionManager.index) { @@ -212,7 +201,7 @@ export const makeBidRequestsHook = (fn, adUnits, ...args) => { return fn.call(this, adUnits, ...args); }; -const setPPSConfigForGPT = (next, targetingSet) => { +const getPpsConfigFromTargetingSet = (next, targetingSet) => { // set gpt config const auctionsIds = getAuctionsIdsFromTargeting(targetingSet); const signals = getSignalsIntersection(getSignalsArrayByAuctionsIds(auctionsIds)); @@ -233,14 +222,14 @@ const handleSetGptConfig = moduleConfig => { if (_currentConfig.enabled) { if (!hooksAdded) { getHook('makeBidRequests').before(makeBidRequestsHook); - getHook('getReadyTargetingSetForGPT').after(setPPSConfigForGPT) + getHook('targetingDone').after(getPpsConfigFromTargetingSet) hooksAdded = true; } } else { logInfo(`${MODULE_NAME}: Turning off module`); _currentConfig = {}; getHook('makeBidRequests').getHooks({hook: makeBidRequestsHook}).remove(); - getHook('getReadyTargetingSetForGPT').getHooks({hook: setPPSConfigForGPT}).remove(); + getHook('targetingDone').getHooks({hook: getPpsConfigFromTargetingSet}).remove(); hooksAdded = false; } }; diff --git a/src/targeting.js b/src/targeting.js index 36503227a9c..0d50d749bb6 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -461,15 +461,15 @@ export function newTargeting(auctionManager) { }); }); - targeting.getReadyTargetingSetForGPT(targetingSet); + targeting.targetingDone(targetingSet); // emit event events.emit(EVENTS.SET_TARGETING, targetingSet); }, 'setTargetingForGPT'); - targeting.getReadyTargetingSetForGPT = hook('sync', function (targetingSet) { + targeting.targetingDone = hook('sync', function (targetingSet) { return targetingSet; - }, 'getReadyTargetingSetForGPT'); + }, 'targetingDone'); /** * normlizes input to a `adUnit.code` array diff --git a/test/spec/modules/gptPreAuction_spec.js b/test/spec/modules/gptPreAuction_spec.js index 0031248f7ef..5889bd3094c 100644 --- a/test/spec/modules/gptPreAuction_spec.js +++ b/test/spec/modules/gptPreAuction_spec.js @@ -11,7 +11,7 @@ import { } from 'modules/gptPreAuction.js'; import { config } from 'src/config.js'; import { makeSlot } from '../integration/faker/googletag.js'; -import { taxonomies } from '../../../modules/gptPreAuction.js'; +import { taxonomies } from '../../../libraries/gptUtils/gptUtils.js'; describe('GPT pre-auction module', () => { let sandbox;