From ea68e9597d351178ccd3e2131721f0142ce6b3e1 Mon Sep 17 00:00:00 2001 From: naripok Date: Mon, 27 Mar 2023 15:46:12 -0300 Subject: [PATCH 1/9] chore: update `getAudiencesAsBidderOrtb2` implementation and test --- modules/airgridRtdProvider.js | 24 ++++++++++++++------ test/spec/modules/airgridRtdProvider_spec.js | 12 +++++++--- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 3578cc4b87e..174502d1757 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -8,7 +8,6 @@ import { config } from '../src/config.js'; import { submodule } from '../src/hook.js'; import { - mergeDeep, deepSetValue, deepAccess, } from '../src/utils.js'; @@ -85,13 +84,24 @@ function setAudiencesToAppNexusAdUnits(adUnits, audiences) { * @param {Array} audiences * @return {{}} a map from bidder code to ORTB2 config */ -export function getAudiencesAsBidderOrtb2(rtdConfig, audiences) { +export function setAudiencesAsBidderOrtb2(rtdConfig, audiences) { const bidders = deepAccess(rtdConfig, 'params.bidders'); - if (!bidders || bidders.length === 0) return {}; - const agOrtb2 = {} - deepSetValue(agOrtb2, 'ortb2.user.ext.data.airgrid', audiences || []); + if (!bidders || bidders.length === 0 || !audiences || audiences.length === 0) return; - return Object.fromEntries(bidders.map(bidder => [bidder, agOrtb2])); + const keywords = audiences.map( + (audienceId) => `perid=${audienceId}` + ).join(','); + + config.mergeBidderConfig({ + bidders: bidders, + config: { + ortb2: { + site: { + keywords, + } + } + } + }) } export function setAudiencesUsingAppNexusAuctionKeywords(audiences) { @@ -131,7 +141,7 @@ export function passAudiencesToBidders( const audiences = getMatchedAudiencesFromStorage(); if (audiences.length > 0) { setAudiencesUsingAppNexusAuctionKeywords(audiences); - mergeDeep(bidConfig?.ortb2Fragments?.bidder, getAudiencesAsBidderOrtb2(rtdConfig, audiences)); + setAudiencesAsBidderOrtb2(rtdConfig, audiences) if (adUnits) { setAudiencesToAppNexusAdUnits(adUnits, audiences); } diff --git a/test/spec/modules/airgridRtdProvider_spec.js b/test/spec/modules/airgridRtdProvider_spec.js index 5b1df6f9d4c..c587ef1a133 100644 --- a/test/spec/modules/airgridRtdProvider_spec.js +++ b/test/spec/modules/airgridRtdProvider_spec.js @@ -110,12 +110,18 @@ describe('airgrid RTD Submodule', function () { .withArgs(agRTD.AG_AUDIENCE_IDS_KEY) .returns(JSON.stringify(MATCHED_AUDIENCES)); const audiences = agRTD.getMatchedAudiencesFromStorage(); - const bidderOrtb2 = agRTD.getAudiencesAsBidderOrtb2(RTD_CONFIG.dataProviders[0], audiences); - const bidders = RTD_CONFIG.dataProviders[0].params.bidders; + agRTD.setAudiencesAsBidderOrtb2(RTD_CONFIG.dataProviders[0], audiences); + + const bidderConfig = config.getBidderConfig() + const bidders = RTD_CONFIG.dataProviders[0].params.bidders + const bidderOrtb2 = bidderConfig + Object.keys(bidderOrtb2).forEach((bidder) => { if (bidders.indexOf(bidder) === -1) return; - expect(deepAccess(bidderOrtb2[bidder], 'ortb2.user.ext.data.airgrid')).to.eql(MATCHED_AUDIENCES); + MATCHED_AUDIENCES.forEach((audience) => { + expect(deepAccess(bidderOrtb2[bidder], 'ortb2.site.keywords')).to.contain(audience); + }) }); }); From a8854399b9c138c105bf0edab0b54c1e1cd43827 Mon Sep 17 00:00:00 2001 From: naripok Date: Wed, 29 Mar 2023 16:10:51 -0300 Subject: [PATCH 2/9] chore: use provided tag insertion method --- modules/airgridRtdProvider.js | 25 ++++++++++---------- test/spec/modules/airgridRtdProvider_spec.js | 2 ++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 174502d1757..f46ff6cced4 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -13,6 +13,7 @@ import { } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { getStorageManager } from '../src/storageManager.js'; +import { loadExternalScript } from '../src/adloader.js'; const MODULE_NAME = 'realTimeData'; const SUBMODULE_NAME = 'airgrid'; @@ -24,6 +25,10 @@ export const storage = getStorageManager({ moduleName: SUBMODULE_NAME, }); +function getModuleUrl(publisherId) { + return `https://cdn.edkt.io/${publisherId}/edgekit.min.js`; +} + /** * Attach script tag to DOM * @param {Object} rtdConfig @@ -32,19 +37,13 @@ export const storage = getStorageManager({ export function attachScriptTagToDOM(rtdConfig) { var edktInitializor = (window.edktInitializor = window.edktInitializor || {}); if (!edktInitializor.invoked) { - edktInitializor.invoked = true; - edktInitializor.accountId = rtdConfig.params.accountId; - edktInitializor.publisherId = rtdConfig.params.publisherId; - edktInitializor.apiKey = rtdConfig.params.apiKey; - edktInitializor.load = function (e) { - var p = e || 'sdk'; - var n = document.createElement('script'); - n.type = 'module'; - n.async = true; - n.src = 'https://cdn.edkt.io/' + p + '/edgekit.min.js'; - document.getElementsByTagName('head')[0].appendChild(n); - }; - edktInitializor.load(edktInitializor.accountId); + const moduleSrc = getModuleUrl(rtdConfig.params.publisherId); + loadExternalScript(moduleSrc, SUBMODULE_NAME, () => { + edktInitializor.invoked = true; + edktInitializor.accountId = rtdConfig.params.accountId; + edktInitializor.publisherId = rtdConfig.params.publisherId; + edktInitializor.apiKey = rtdConfig.params.apiKey; + }); } } diff --git a/test/spec/modules/airgridRtdProvider_spec.js b/test/spec/modules/airgridRtdProvider_spec.js index c587ef1a133..ea019b8a898 100644 --- a/test/spec/modules/airgridRtdProvider_spec.js +++ b/test/spec/modules/airgridRtdProvider_spec.js @@ -2,6 +2,7 @@ import { config } from 'src/config.js'; import { deepAccess } from 'src/utils.js'; import { getAdUnits } from '../../fixtures/fixtures.js'; import * as agRTD from 'modules/airgridRtdProvider.js'; +import { loadExternalScript } from '../../../src/adloader.js'; const MATCHED_AUDIENCES = ['travel', 'sport']; const RTD_CONFIG = { @@ -40,6 +41,7 @@ describe('airgrid RTD Submodule', function () { expect(agRTD.airgridSubmodule.init(RTD_CONFIG.dataProviders[0])).to.equal( true ); + expect(loadExternalScript.called).to.be.true }); it('should attach script to DOM with correct config', function () { From b2d56bae0105553b0ea3a5d3b5883bed3ec3e4b0 Mon Sep 17 00:00:00 2001 From: naripok Date: Wed, 3 May 2023 15:45:36 -0300 Subject: [PATCH 3/9] fix: add `airgrid` to `_approvedLoadExternalJSList` --- src/adloader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adloader.js b/src/adloader.js index f0b7f7f3e8c..83667bee185 100644 --- a/src/adloader.js +++ b/src/adloader.js @@ -22,7 +22,8 @@ const _approvedLoadExternalJSList = [ 'improvedigital', 'aaxBlockmeter', 'confiant', - 'arcspan' + 'arcspan', + 'airgrid' ] /** From 320956519140611d8a2610735b278751db18c715 Mon Sep 17 00:00:00 2001 From: naripok Date: Wed, 3 May 2023 15:54:13 -0300 Subject: [PATCH 4/9] fix: use 'sdk' path if no publisherId is provided --- modules/airgridRtdProvider.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index f46ff6cced4..424dd8c53de 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -26,7 +26,8 @@ export const storage = getStorageManager({ }); function getModuleUrl(publisherId) { - return `https://cdn.edkt.io/${publisherId}/edgekit.min.js`; + const path = publisherId ?? 'sdk'; + return `https://cdn.edkt.io/${path}/edgekit.min.js`; } /** From 7798c95824de28da772fec36454d5b85e8339911 Mon Sep 17 00:00:00 2001 From: naripok Date: Fri, 5 May 2023 11:12:52 -0300 Subject: [PATCH 5/9] fix: use accountId as path param for script url --- modules/airgridRtdProvider.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 051255f8487..7162caca4db 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -26,8 +26,8 @@ export const storage = getStorageManager({ moduleName: SUBMODULE_NAME, }); -function getModuleUrl(publisherId) { - const path = publisherId ?? 'sdk'; +function getModuleUrl(accountId) { + const path = accountId ?? 'sdk'; return `https://cdn.edkt.io/${path}/edgekit.min.js`; } @@ -39,7 +39,7 @@ function getModuleUrl(publisherId) { export function attachScriptTagToDOM(rtdConfig) { var edktInitializor = (window.edktInitializor = window.edktInitializor || {}); if (!edktInitializor.invoked) { - const moduleSrc = getModuleUrl(rtdConfig.params.publisherId); + const moduleSrc = getModuleUrl(rtdConfig.params.accountId); loadExternalScript(moduleSrc, SUBMODULE_NAME, () => { edktInitializor.invoked = true; edktInitializor.accountId = rtdConfig.params.accountId; From 20a3926381f705ae6d5a14472b643214529cff35 Mon Sep 17 00:00:00 2001 From: naripok Date: Fri, 5 May 2023 12:47:27 -0300 Subject: [PATCH 6/9] fix: assign edktInitializor props before `loadExternalScript` call --- modules/airgridRtdProvider.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 7162caca4db..0eb699cff4d 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -39,12 +39,12 @@ function getModuleUrl(accountId) { export function attachScriptTagToDOM(rtdConfig) { var edktInitializor = (window.edktInitializor = window.edktInitializor || {}); if (!edktInitializor.invoked) { + edktInitializor.accountId = rtdConfig.params.accountId; + edktInitializor.publisherId = rtdConfig.params.publisherId; + edktInitializor.apiKey = rtdConfig.params.apiKey; const moduleSrc = getModuleUrl(rtdConfig.params.accountId); loadExternalScript(moduleSrc, SUBMODULE_NAME, () => { edktInitializor.invoked = true; - edktInitializor.accountId = rtdConfig.params.accountId; - edktInitializor.publisherId = rtdConfig.params.publisherId; - edktInitializor.apiKey = rtdConfig.params.apiKey; }); } } From 6cc0ac983f3ee96a761be44617c8a2a9a10c5ca3 Mon Sep 17 00:00:00 2001 From: naripok Date: Fri, 5 May 2023 12:52:04 -0300 Subject: [PATCH 7/9] fix: set `edktInitializor.invoked` before calling `loadExternalScript` --- modules/airgridRtdProvider.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 0eb699cff4d..6af53a9094a 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -42,10 +42,9 @@ export function attachScriptTagToDOM(rtdConfig) { edktInitializor.accountId = rtdConfig.params.accountId; edktInitializor.publisherId = rtdConfig.params.publisherId; edktInitializor.apiKey = rtdConfig.params.apiKey; + edktInitializor.invoked = true; const moduleSrc = getModuleUrl(rtdConfig.params.accountId); - loadExternalScript(moduleSrc, SUBMODULE_NAME, () => { - edktInitializor.invoked = true; - }); + loadExternalScript(moduleSrc, SUBMODULE_NAME); } } From b2af96037b883c1aab66df804309eb012bc82bf7 Mon Sep 17 00:00:00 2001 From: naripok Date: Mon, 15 May 2023 13:41:10 -0300 Subject: [PATCH 8/9] fix: restore method for setting `user.ext.data` feat: extend module data setting using `user.keywords` for appnexus --- modules/airgridRtdProvider.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index 6af53a9094a..f4d1b1238c8 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -10,6 +10,7 @@ import { submodule } from '../src/hook.js'; import { deepSetValue, deepAccess, + mergeDeep, } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -84,24 +85,19 @@ function setAudiencesToAppNexusAdUnits(adUnits, audiences) { * @param {Array} audiences * @return {{}} a map from bidder code to ORTB2 config */ -export function setAudiencesAsBidderOrtb2(rtdConfig, audiences) { +export function getAudiencesAsBidderOrtb2(rtdConfig, audiences) { const bidders = deepAccess(rtdConfig, 'params.bidders'); if (!bidders || bidders.length === 0 || !audiences || audiences.length === 0) return; + const agOrtb2 = {} + deepSetValue(agOrtb2, 'ortb2.user.ext.data.airgrid', audiences); + const keywords = audiences.map( (audienceId) => `perid=${audienceId}` ).join(','); + deepSetValue(agOrtb2, 'ortb2.user.keywords', keywords); - config.mergeBidderConfig({ - bidders: bidders, - config: { - ortb2: { - site: { - keywords, - } - } - } - }) + return Object.fromEntries(bidders.map(bidder => [bidder, agOrtb2])); } export function setAudiencesUsingAppNexusAuctionKeywords(audiences) { @@ -141,7 +137,7 @@ export function passAudiencesToBidders( const audiences = getMatchedAudiencesFromStorage(); if (audiences.length > 0) { setAudiencesUsingAppNexusAuctionKeywords(audiences); - setAudiencesAsBidderOrtb2(rtdConfig, audiences) + mergeDeep(bidConfig?.ortb2Fragments?.bidder, getAudiencesAsBidderOrtb2(rtdConfig, audiences)); if (adUnits) { setAudiencesToAppNexusAdUnits(adUnits, audiences); } From 7bde0ca381574e4c9929b53fbfa74ed09c4e037c Mon Sep 17 00:00:00 2001 From: naripok Date: Thu, 18 May 2023 10:37:23 -0300 Subject: [PATCH 9/9] fix: rollback changes to data setting method --- modules/airgridRtdProvider.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index f4d1b1238c8..6af53a9094a 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -10,7 +10,6 @@ import { submodule } from '../src/hook.js'; import { deepSetValue, deepAccess, - mergeDeep, } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -85,19 +84,24 @@ function setAudiencesToAppNexusAdUnits(adUnits, audiences) { * @param {Array} audiences * @return {{}} a map from bidder code to ORTB2 config */ -export function getAudiencesAsBidderOrtb2(rtdConfig, audiences) { +export function setAudiencesAsBidderOrtb2(rtdConfig, audiences) { const bidders = deepAccess(rtdConfig, 'params.bidders'); if (!bidders || bidders.length === 0 || !audiences || audiences.length === 0) return; - const agOrtb2 = {} - deepSetValue(agOrtb2, 'ortb2.user.ext.data.airgrid', audiences); - const keywords = audiences.map( (audienceId) => `perid=${audienceId}` ).join(','); - deepSetValue(agOrtb2, 'ortb2.user.keywords', keywords); - return Object.fromEntries(bidders.map(bidder => [bidder, agOrtb2])); + config.mergeBidderConfig({ + bidders: bidders, + config: { + ortb2: { + site: { + keywords, + } + } + } + }) } export function setAudiencesUsingAppNexusAuctionKeywords(audiences) { @@ -137,7 +141,7 @@ export function passAudiencesToBidders( const audiences = getMatchedAudiencesFromStorage(); if (audiences.length > 0) { setAudiencesUsingAppNexusAuctionKeywords(audiences); - mergeDeep(bidConfig?.ortb2Fragments?.bidder, getAudiencesAsBidderOrtb2(rtdConfig, audiences)); + setAudiencesAsBidderOrtb2(rtdConfig, audiences) if (adUnits) { setAudiencesToAppNexusAdUnits(adUnits, audiences); }