From 3214634f5cb8c5248cfed9750fc40578a23b6a92 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Fri, 31 May 2019 10:57:08 -0400 Subject: [PATCH 01/11] introduce mapAdSlotPathToElementId() --- modules/33acrossBidAdapter.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 1cf885ed6e4..294bb69276c 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -1,8 +1,7 @@ +import { registerBidder } from '../src/adapters/bidderFactory'; +import { config } from '../src/config'; import * as utils from '../src/utils'; -const { registerBidder } = require('../src/adapters/bidderFactory'); -const { config } = require('../src/config'); - const BIDDER_CODE = '33across'; const END_POINT = 'https://ssc.33across.com/api/v1/hb'; const SYNC_ENDPOINT = 'https://de.tynt.com/deb/v2?m=xch&rt=html'; @@ -37,12 +36,35 @@ function _getViewability(element, topWin, { w, h } = {}) { : 0; } +function mapAdSlotPathToElementId(path) { + if (utils.isGptPubadsDefined()) { + const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(path); + const matchingAdSlot = window.googletag.pubads().getSlots().filter(isMatchingAdSlot)[0]; + + if (matchingAdSlot) { + return matchingAdSlot.getSlotElementId(); + } + } + + return null; +} + +function getAdSlotHTMLElement(adUnitCode) { + let element = document.getElementById(adUnitCode); + + if (element === null) { + element = document.getElementById(mapAdSlotPathToElementId(adUnitCode)); + } + + return element; +} + // Infer the necessary data from valid bid for a minimal ttxRequest and create HTTP request // NOTE: At this point, TTX only accepts request for a single impression function _createServerRequest(bidRequest, gdprConsent) { const ttxRequest = {}; const params = bidRequest.params; - const element = document.getElementById(bidRequest.adUnitCode); + const element = getAdSlotHTMLElement(bidRequest.adUnitCode); const sizes = _transformSizes(bidRequest.sizes); const minSize = _getMinSize(sizes); @@ -268,9 +290,7 @@ function buildRequests(bidRequests, bidderRequest) { adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); - return bidRequests.map((req) => { - return _createServerRequest(req, gdprConsent); - }); + return bidRequests.map(req => _createServerRequest(req, gdprConsent)); } // NOTE: At this point, the response from 33exchange will only ever contain one bid i.e. the highest bid From 10588030bd50e6daa913ebe8f75f05af48767d54 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Fri, 31 May 2019 10:59:21 -0400 Subject: [PATCH 02/11] introduce getAdSlotHTMLElement(), add logging --- modules/33acrossBidAdapter.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 294bb69276c..0fb392f4500 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -53,7 +53,11 @@ function getAdSlotHTMLElement(adUnitCode) { let element = document.getElementById(adUnitCode); if (element === null) { - element = document.getElementById(mapAdSlotPathToElementId(adUnitCode)); + const id = mapAdSlotPathToElementId(adUnitCode); + + element = document.getElementById(id); + + utils.logInfo(`Trying to map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); } return element; @@ -75,7 +79,7 @@ function _createServerRequest(bidRequest, gdprConsent) { const contributeViewability = ViewabilityContributor(viewabilityAmount); if (element === null) { - utils.logWarn(`Unable to locate element with id: '${bidRequest.adUnitCode}'`); + utils.logWarn(`[33Across Adapter] Unable to locate element with id: '${bidRequest.adUnitCode}'`); } /* @@ -290,6 +294,8 @@ function buildRequests(bidRequests, bidderRequest) { adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); + util.logInfo('[33Across Adapter] buildRequests():', bidRequests); + return bidRequests.map(req => _createServerRequest(req, gdprConsent)); } From 3fc8fe98aa5ab10f6c313e4b5303119a89071e02 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Fri, 31 May 2019 11:54:50 -0400 Subject: [PATCH 03/11] introduce mapAdSlotPathToElementId() --- modules/33acrossBidAdapter.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 0fb392f4500..c120946ae84 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -31,7 +31,7 @@ function _isViewabilityMeasurable(element) { } function _getViewability(element, topWin, { w, h } = {}) { - return utils.getWindowTop().document.visibilityState === 'visible' + return topWin.document.visibilityState === 'visible' ? _getPercentInView(element, topWin, { w, h }) : 0; } @@ -290,11 +290,14 @@ function isBidRequestValid(bid) { // - the server, at this point, also doesn't need the consent string to handle gdpr compliance. So passing // value whether set or not, for the sake of future dev. function buildRequests(bidRequests, bidderRequest) { - const gdprConsent = Object.assign({ consentString: undefined, gdprApplies: false }, bidderRequest && bidderRequest.gdprConsent); + const gdprConsent = Object.assign({ + consentString: undefined, + gdprApplies: false + }, bidderRequest && bidderRequest.gdprConsent); adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); - util.logInfo('[33Across Adapter] buildRequests():', bidRequests); + utils.logInfo('[33Across Adapter] buildRequests():', bidRequests); return bidRequests.map(req => _createServerRequest(req, gdprConsent)); } From d85098020f550f8f5d287c81ea7c1a3d59b289fd Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Mon, 3 Jun 2019 14:27:27 -0400 Subject: [PATCH 04/11] update logging in ad unit path to element id mapping --- modules/33acrossBidAdapter.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index c120946ae84..9cffec14256 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -36,28 +36,29 @@ function _getViewability(element, topWin, { w, h } = {}) { : 0; } -function mapAdSlotPathToElementId(path) { +function _mapAdUnitPathToElementId(adUnitCode) { + let id = null; + if (utils.isGptPubadsDefined()) { - const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(path); - const matchingAdSlot = window.googletag.pubads().getSlots().filter(isMatchingAdSlot)[0]; + const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(adUnitCode); + const matchingAdSlot = window.googletag.pubads().getSlots().find(isMatchingAdSlot); if (matchingAdSlot) { - return matchingAdSlot.getSlotElementId(); + id = matchingAdSlot.getSlotElementId(); } } - return null; + utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); + + return id; } -function getAdSlotHTMLElement(adUnitCode) { - let element = document.getElementById(adUnitCode); +function _getAdSlotHTMLElement(adUnitCode) { + const element = document.getElementById(adUnitCode) || + document.getElementById(_mapAdUnitPathToElementId(adUnitCode)); if (element === null) { - const id = mapAdSlotPathToElementId(adUnitCode); - - element = document.getElementById(id); - - utils.logInfo(`Trying to map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); + utils.logWarn(`[33Across Adapter] Unable to locate element with id: '${adUnitCode}'`); } return element; @@ -68,7 +69,7 @@ function getAdSlotHTMLElement(adUnitCode) { function _createServerRequest(bidRequest, gdprConsent) { const ttxRequest = {}; const params = bidRequest.params; - const element = getAdSlotHTMLElement(bidRequest.adUnitCode); + const element = _getAdSlotHTMLElement(bidRequest.adUnitCode); const sizes = _transformSizes(bidRequest.sizes); const minSize = _getMinSize(sizes); @@ -78,10 +79,6 @@ function _createServerRequest(bidRequest, gdprConsent) { const contributeViewability = ViewabilityContributor(viewabilityAmount); - if (element === null) { - utils.logWarn(`[33Across Adapter] Unable to locate element with id: '${bidRequest.adUnitCode}'`); - } - /* * Infer data for the request payload */ From e14d1e107377ca66737a74a50f8ac7b0d146faeb Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Mon, 3 Jun 2019 15:57:26 -0400 Subject: [PATCH 05/11] rephrase logging, fix tests --- modules/33acrossBidAdapter.js | 2 +- test/spec/modules/33acrossBidAdapter_spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 9cffec14256..84f1d455abf 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -58,7 +58,7 @@ function _getAdSlotHTMLElement(adUnitCode) { document.getElementById(_mapAdUnitPathToElementId(adUnitCode)); if (element === null) { - utils.logWarn(`[33Across Adapter] Unable to locate element with id: '${adUnitCode}'`); + utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); } return element; diff --git a/test/spec/modules/33acrossBidAdapter_spec.js b/test/spec/modules/33acrossBidAdapter_spec.js index 1fc77a7e14d..7e1a8619c63 100644 --- a/test/spec/modules/33acrossBidAdapter_spec.js +++ b/test/spec/modules/33acrossBidAdapter_spec.js @@ -337,8 +337,8 @@ describe('33acrossBidAdapter:', function () { utils.getWindowTop.restore(); utils.getWindowSelf.restore(); - sandbox.stub(utils, 'getWindowTop').returns(win); - sandbox.stub(utils, 'getWindowSelf').returns({}); + sandbox.stub(utils, 'getWindowTop').returns({}); + sandbox.stub(utils, 'getWindowSelf').returns(win); expect(spec.buildRequests(bidRequests)).to.deep.equal([ serverRequest ]); }); From 17a2342aa7aa0e9cadf213da98277a2bc1dca8ff Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Wed, 5 Jun 2019 13:23:58 -0400 Subject: [PATCH 06/11] update adapter documentation --- modules/33acrossBidAdapter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/33acrossBidAdapter.md b/modules/33acrossBidAdapter.md index bdb2b944861..58e3b2b273a 100644 --- a/modules/33acrossBidAdapter.md +++ b/modules/33acrossBidAdapter.md @@ -16,7 +16,7 @@ Connects to 33Across's exchange for bids. ``` var adUnits = [ { - code: '33across-hb-ad-123456-1', + code: '33across-hb-ad-123456-1', // ad slot HTML element ID sizes: [ [300, 250], [728, 90] From 178ccee398fe27caf8a003dfcd2ec1dad8fbfba6 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Mon, 10 Jun 2019 15:06:32 -0400 Subject: [PATCH 07/11] remove excessive logging --- modules/33acrossBidAdapter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 84f1d455abf..62387c266aa 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -294,8 +294,6 @@ function buildRequests(bidRequests, bidderRequest) { adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); - utils.logInfo('[33Across Adapter] buildRequests():', bidRequests); - return bidRequests.map(req => _createServerRequest(req, gdprConsent)); } From bc936c080ff29e22d3b2c32eab1a711377bbbdde Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Tue, 11 Jun 2019 12:03:24 -0400 Subject: [PATCH 08/11] improve logging --- modules/33acrossBidAdapter.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 62387c266aa..18001a49823 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -45,23 +45,19 @@ function _mapAdUnitPathToElementId(adUnitCode) { if (matchingAdSlot) { id = matchingAdSlot.getSlotElementId(); + + utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); } } - utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); + utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); - return id; + return null; } function _getAdSlotHTMLElement(adUnitCode) { - const element = document.getElementById(adUnitCode) || + return document.getElementById(adUnitCode) || document.getElementById(_mapAdUnitPathToElementId(adUnitCode)); - - if (element === null) { - utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); - } - - return element; } // Infer the necessary data from valid bid for a minimal ttxRequest and create HTTP request @@ -287,10 +283,15 @@ function isBidRequestValid(bid) { // - the server, at this point, also doesn't need the consent string to handle gdpr compliance. So passing // value whether set or not, for the sake of future dev. function buildRequests(bidRequests, bidderRequest) { - const gdprConsent = Object.assign({ - consentString: undefined, - gdprApplies: false - }, bidderRequest && bidderRequest.gdprConsent); + // const gdprConsent = Object.assign({ + // consentString: undefined, + // gdprApplies: false + // }, bidderRequest && bidderRequest.gdprConsent); + const gdprConsent = { + gdprApplies: false, + consentString: undefined, // see comment about this + ...(bidderRequest && bidderRequest.gdprConsent) + }; adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); From 09bbfe70c0ad3e6874b27074b790d6e0d9edd3ca Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Tue, 11 Jun 2019 16:54:47 -0400 Subject: [PATCH 09/11] revert change --- modules/33acrossBidAdapter.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 18001a49823..a042ee0d4c2 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -283,15 +283,10 @@ function isBidRequestValid(bid) { // - the server, at this point, also doesn't need the consent string to handle gdpr compliance. So passing // value whether set or not, for the sake of future dev. function buildRequests(bidRequests, bidderRequest) { - // const gdprConsent = Object.assign({ - // consentString: undefined, - // gdprApplies: false - // }, bidderRequest && bidderRequest.gdprConsent); - const gdprConsent = { - gdprApplies: false, - consentString: undefined, // see comment about this - ...(bidderRequest && bidderRequest.gdprConsent) - }; + const gdprConsent = Object.assign({ + consentString: undefined, + gdprApplies: false + }, bidderRequest && bidderRequest.gdprConsent); adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); From 236dd54af52af692559efa8ee38112358805ee86 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Tue, 11 Jun 2019 16:58:49 -0400 Subject: [PATCH 10/11] fix return of _mapAdUnitPathToElementId() --- modules/33acrossBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index a042ee0d4c2..46ce29cd886 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -52,7 +52,7 @@ function _mapAdUnitPathToElementId(adUnitCode) { utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); - return null; + return id; } function _getAdSlotHTMLElement(adUnitCode) { From 6c097ff266c65f36c92ac1f376a1e3a31008d469 Mon Sep 17 00:00:00 2001 From: Gleb Glushtsov Date: Wed, 12 Jun 2019 11:00:53 -0400 Subject: [PATCH 11/11] improve logging of _mapAdUnitPathToElementId() --- modules/33acrossBidAdapter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index 46ce29cd886..3f7dcb50028 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -37,22 +37,22 @@ function _getViewability(element, topWin, { w, h } = {}) { } function _mapAdUnitPathToElementId(adUnitCode) { - let id = null; - if (utils.isGptPubadsDefined()) { const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(adUnitCode); const matchingAdSlot = window.googletag.pubads().getSlots().find(isMatchingAdSlot); if (matchingAdSlot) { - id = matchingAdSlot.getSlotElementId(); + const id = matchingAdSlot.getSlotElementId(); + + utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> ${id}`); - utils.logInfo(`[33Across Adapter] Map ad unit path to HTML element id: '${adUnitCode}' -> '${id}'`); + return id; } } utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); - return id; + return null; } function _getAdSlotHTMLElement(adUnitCode) {