diff --git a/modules/sspBCBidAdapter.js b/modules/sspBCBidAdapter.js index b4caf1db1d0..c8f3c138ce4 100644 --- a/modules/sspBCBidAdapter.js +++ b/modules/sspBCBidAdapter.js @@ -9,11 +9,13 @@ const BIDDER_URL = 'https://ssp.wp.pl/bidder/'; const SYNC_URL = 'https://ssp.wp.pl/bidder/usersync'; const NOTIFY_URL = 'https://ssp.wp.pl/bidder/notify'; const TMAX = 450; -const BIDDER_VERSION = '5.2'; +const BIDDER_VERSION = '5.3'; const W = window; const { navigator } = W; const oneCodeDetection = {}; +const adUnitsCalled = {}; const adSizesCalled = {}; +const pageView = {}; var consentApiVersion; /** @@ -70,6 +72,7 @@ const cookieSupport = () => { }; const applyClientHints = ortbRequest => { + const { location } = document; const { connection = {}, deviceMemory, userAgentData = {} } = navigator; const viewport = W.visualViewport || false; const segments = []; @@ -85,6 +88,16 @@ const applyClientHints = ortbRequest => { 'CH-isMobile': userAgentData.mobile, }; + /** + Check / generate page view id + Should be generated dureing first call to applyClientHints(), + and re-generated if pathname has changed + */ + if (!pageView.id || location.pathname !== pageView.path) { + pageView.path = location.pathname; + pageView.id = Math.floor(1E20 * Math.random()); + } + Object.keys(hints).forEach(key => { const hint = hints[key]; @@ -100,6 +113,14 @@ const applyClientHints = ortbRequest => { id: '12', name: 'NetInfo', segment: segments, + }, { + id: '7', + name: 'pvid', + segment: [ + { + value: `${pageView.id}` + } + ] }]; ortbRequest.user = Object.assign(ortbRequest.user, { data }); @@ -129,6 +150,7 @@ const setOnAny = (collection, key) => collection.reduce((prev, next) => prev || */ const sendNotification = payload => { ajax(NOTIFY_URL, null, JSON.stringify(payload), { + contentType: 'application/json', withCredentials: false, method: 'POST', crossOrigin: true @@ -267,8 +289,14 @@ const mapImpression = slot => { send this info as ext.pbsize */ const slotSize = slot.sizes.length ? slot.sizes.reduce((prev, next) => prev[0] * prev[1] <= next[0] * next[1] ? next : prev).join('x') : '1x1'; - adSizesCalled[slotSize] = adSizesCalled[slotSize] ? adSizesCalled[slotSize] += 1 : 1; - ext.data = Object.assign({ pbsize: `${slotSize}_${adSizesCalled[slotSize]}` }, ext.data); + + if (!adUnitsCalled[adUnitCode]) { + // this is a new adunit - assign & save pbsize + adSizesCalled[slotSize] = adSizesCalled[slotSize] ? adSizesCalled[slotSize] += 1 : 1; + adUnitsCalled[adUnitCode] = `${slotSize}_${adSizesCalled[slotSize]}` + } + + ext.data = Object.assign({ pbsize: adUnitsCalled[adUnitCode] }, ext.data); const imp = { id: id && siteId ? id : 'bidid-' + bidId, @@ -325,6 +353,9 @@ const parseNative = nativeData => { case 0: result.title = asset.title.text; break; + case 1: + result.cta = asset.data.value; + break; case 2: result.icon = { url: asset.img.url, diff --git a/test/spec/modules/sspBCBidAdapter_spec.js b/test/spec/modules/sspBCBidAdapter_spec.js index 75a269c93f7..d9f3ca84a3a 100644 --- a/test/spec/modules/sspBCBidAdapter_spec.js +++ b/test/spec/modules/sspBCBidAdapter_spec.js @@ -518,6 +518,33 @@ describe('SSPBC adapter', function () { expect(payload.user).to.be.an('object').and.to.have.property('[ortb_extensions.consent]', bidRequest.gdprConsent.consentString); }); + it('should send net info and pvid', function () { + expect(payload.user).to.be.an('object').and.to.have.property('data').that.is.an('array'); + + const userData = payload.user.data; + expect(userData.length).to.equal(2); + + const netInfo = userData[0]; + expect(netInfo.id).to.equal('12'); + expect(netInfo.name).to.equal('NetInfo'); + expect(netInfo).to.have.property('segment').that.is.an('array'); + + const pvid = userData[1]; + expect(pvid.id).to.equal('7'); + expect(pvid.name).to.equal('pvid'); + expect(pvid).to.have.property('segment').that.is.an('array'); + expect(pvid.segment[0]).to.have.property('value'); + }); + + it('pvid should be constant on a single page view', function () { + const userData1 = payload.user.data; + const userData2 = payloadNative.user.data; + const pvid1 = userData1[1]; + const pvid2 = userData2[1]; + + expect(pvid1.segment[0].value).to.equal(pvid2.segment[0].value); + }); + it('should build correct native payload', function () { const nativeAssets = payloadNative.imp && payloadNative.imp[0].native.request; @@ -543,13 +570,16 @@ describe('SSPBC adapter', function () { expect(videoAssets).to.have.property('api').that.is.an('array'); }); - it('should create auxilary placement identifier (size_numUsed)', function () { + it('should create auxilary placement identifier (size_numUsed), that is constant for a given adUnit', function () { const extAssets1 = payload.imp && payload.imp[0].ext.data; const extAssets2 = payloadSingle.imp && payloadSingle.imp[0].ext.data; - // note that payload comes from first, and payloadSingle from second auction in the test run + /* + note that payload comes from first, and payloadSingle from second auction in the test run + also, since both have same adUnitName, value of pbsize property should be the same + */ expect(extAssets1).to.have.property('pbsize').that.equals('750x200_1') - expect(extAssets2).to.have.property('pbsize').that.equals('750x200_2') + expect(extAssets2).to.have.property('pbsize').that.equals('750x200_1') }); });