diff --git a/modules/snigelBidAdapter.js b/modules/snigelBidAdapter.js index 4e0de53ca0d..13731e2b7e1 100644 --- a/modules/snigelBidAdapter.js +++ b/modules/snigelBidAdapter.js @@ -16,6 +16,7 @@ const SESSION_ID_KEY = '_sn_session_pba'; const getConfig = config.getConfig; const storageManager = getStorageManager({bidderCode: BIDDER_CODE}); const refreshes = {}; +const placementCounters = {}; const pageViewId = generateUUID(); const pageViewStart = new Date().getTime(); let auctionCounter = 0; @@ -46,6 +47,7 @@ export const spec = { cur: getCurrencies(), test: getTestFlag(), version: 'v' + '$prebid.version$', + adapterVersion: '2.0', gpp: deepAccess(bidderRequest, 'gppConsent.gppString') || deepAccess(bidderRequest, 'ortb2.regs.gpp'), gpp_sid: deepAccess(bidderRequest, 'gppConsent.applicableSections') || deepAccess(bidderRequest, 'ortb2.regs.gpp_sid'), @@ -71,6 +73,7 @@ export const spec = { gpid: deepAccess(r, 'ortb2Imp.ext.gpid'), pbadslot: deepAccess(r, 'ortb2Imp.ext.data.pbadslot') || deepAccess(r, 'ortb2Imp.ext.gpid'), name: r.params.placement, + counter: getPlacementCounter(r.params.placement), sizes: r.sizes, floor: getPriceFloor(r, BANNER, FLOOR_MATCH_ALL_SIZES), refresh: getRefreshInformation(r.adUnitCode), @@ -182,6 +185,17 @@ function getRefreshInformation(adUnitCode) { }; } +function getPlacementCounter(placement) { + const counter = placementCounters[placement]; + if (counter === undefined) { + placementCounters[placement] = 0; + return 0; + } + + placementCounters[placement]++; + return placementCounters[placement]; +} + function mapIdToRequestId(id, bidRequest) { return bidRequest.bidderRequest.bids.filter((bid) => bid.adUnitCode === id)[0].bidId; } diff --git a/test/spec/modules/snigelBidAdapter_spec.js b/test/spec/modules/snigelBidAdapter_spec.js index 828aec9491c..69ab85ba825 100644 --- a/test/spec/modules/snigelBidAdapter_spec.js +++ b/test/spec/modules/snigelBidAdapter_spec.js @@ -181,6 +181,50 @@ describe('snigelBidAdapter', function () { expect(data.placements[2].refresh.count).to.equal(1); expect(data.placements[2].refresh.time).to.be.greaterThanOrEqual(0); }); + + it('should increment auction counter upon every request', function () { + const bidderRequest = makeBidderRequest({}); + + let request = spec.buildRequests([], bidderRequest); + expect(request).to.have.property('data'); + let data = JSON.parse(request.data); + const previousCounter = data.counter; + + request = spec.buildRequests([], bidderRequest); + expect(request).to.have.property('data'); + data = JSON.parse(request.data); + expect(data.counter).to.equal(previousCounter + 1); + }); + + it('should increment placement counter for each placement', function () { + const bidderRequest = Object.assign({}, BASE_BIDDER_REQUEST); + const topLeaderboard = makeBidRequest({adUnitCode: 'top_leaderboard', params: {placement: 'ros'}}); + const bottomLeaderboard = makeBidRequest({adUnitCode: 'bottom_leaderboard', params: {placement: 'ros'}}); + const sidebar = makeBidRequest({adUnitCode: 'sidebar', params: {placement: 'other'}}); + + let request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest); + expect(request).to.have.property('data'); + let data = JSON.parse(request.data); + const previousCounters = {}; + data.placements.forEach((placement) => { + previousCounters[placement.name] = Math.max(previousCounters[placement.name] || 0, placement.counter); + }); + + request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest); + expect(request).to.have.property('data'); + data = JSON.parse(request.data); + expect(data).to.have.property('placements'); + expect(data.placements.length).to.equal(3); + expect(data.placements[0].id).to.equal('top_leaderboard'); + expect(previousCounters).to.have.property(data.placements[0].name); + expect(data.placements[0].counter).to.equal(previousCounters[data.placements[0].name] + 1); + expect(data.placements[1].id).to.equal('bottom_leaderboard'); + expect(previousCounters).to.have.property(data.placements[1].name); + expect(data.placements[1].counter).to.equal(previousCounters[data.placements[1].name] + 2); + expect(data.placements[2].id).to.equal('sidebar'); + expect(previousCounters).to.have.property(data.placements[2].name); + expect(data.placements[2].counter).to.equal(previousCounters[data.placements[2].name] + 1); + }); }); describe('interpretResponse', function () { @@ -347,7 +391,7 @@ describe('snigelBidAdapter', function () { expect(sync.url).to.equal(`https://somesyncurl?gdpr=1&gdpr_consent=${DUMMY_GDPR_CONSENT_STRING}`); }); - it('should omit session ID if no device access', function() { + it('should omit session ID if no device access', function () { const bidderRequest = makeBidderRequest(); const unregisterRule = registerActivityControl(ACTIVITY_ACCESS_DEVICE, 'denyAccess', () => { return {allow: false, reason: 'no consent'}; @@ -373,9 +417,9 @@ describe('snigelBidAdapter', function () { }, vendor: { consents: {[spec.gvlid]: true}, - } + }, }, - } + }, }); let request = spec.buildRequests([], baseBidderRequest); expect(request).to.have.property('data'); @@ -388,25 +432,14 @@ describe('snigelBidAdapter', function () { data = JSON.parse(request.data); expect(data.gdprConsent).to.be.false; - bidderRequest = {...baseBidderRequest, ...{gdprConsent: {vendorData: {vendor: {consents: {[spec.gvlid]: false}}}}}}; + bidderRequest = { + ...baseBidderRequest, + ...{gdprConsent: {vendorData: {vendor: {consents: {[spec.gvlid]: false}}}}}, + }; request = spec.buildRequests([], bidderRequest); expect(request).to.have.property('data'); data = JSON.parse(request.data); expect(data.gdprConsent).to.be.false; }); - - it('should increment auction counter upon every request', function() { - const bidderRequest = makeBidderRequest({}); - - let request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - let data = JSON.parse(request.data); - const previousCounter = data.counter; - - request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data.counter).to.equal(previousCounter + 1); - }); }); });