From 93d99a345a93bd5d06cfc35dd4445f7b0b74a707 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 14:17:37 +0300 Subject: [PATCH 01/14] EX-2588 Refactor tests for sovrn bid adapter --- test/spec/modules/sovrnBidAdapter_spec.js | 555 ++++++++++------------ 1 file changed, 241 insertions(+), 314 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 729c48c28f4..ac8cc9fbadc 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -5,7 +5,7 @@ import * as utils from 'src/utils.js' const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$`; -const adUnitBidRequest = { +const baseBidRequest = { 'bidder': 'sovrn', 'params': { 'tagid': 403370 @@ -19,7 +19,7 @@ const adUnitBidRequest = { 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', } -const bidderRequest = { +const baseBidderRequest = { refererInfo: { referer: 'http://example.com/page.html', } @@ -28,28 +28,35 @@ const bidderRequest = { describe('sovrnBidAdapter', function() { describe('isBidRequestValid', function () { it('should return true when required params found', function () { - expect(spec.isBidRequestValid(adUnitBidRequest)).to.equal(true); + expect(spec.isBidRequestValid(baseBidRequest)).to.equal(true); }); it('should return false when tagid not passed correctly', function () { - const bid = {...adUnitBidRequest} - const params = adUnitBidRequest.params - bid.params = {...params} - bid.params.tagid = 'ABCD' - expect(spec.isBidRequestValid(bid)).to.equal(false) + const bidRequest = { + ...baseBidRequest, + 'params': { + ...baseBidRequest.params, + 'tagid': 'ABCD' + }, + }; + + expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); it('should return false when require params are not passed', function () { - const bid = {...adUnitBidRequest} - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); + const bidRequest = { + ...baseBidRequest, + 'params': {} + } + + expect(spec.isBidRequestValid(bidRequest)).to.equal(false); }); }); describe('buildRequests', function () { describe('basic bid parameters', function() { - const bidRequests = [adUnitBidRequest]; - const request = spec.buildRequests(bidRequests, bidderRequest); + const request = spec.buildRequests([baseBidRequest], baseBidderRequest); + const payload = JSON.parse(request.data); it('sends bid request to our endpoint via POST', function () { expect(request.method).to.equal('POST'); @@ -60,15 +67,21 @@ describe('sovrnBidAdapter', function() { }); it('sets the proper banner object', function() { - const payload = JSON.parse(request.data) - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) - expect(payload.imp[0].banner.w).to.equal(1) - expect(payload.imp[0].banner.h).to.equal(1) + const impression = payload.imp[0] + + expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) + expect(impression.banner.w).to.equal(1) + expect(impression.banner.h).to.equal(1) }) - it('includes the ad unit code int the request', function() { - const payload = JSON.parse(request.data); - expect(payload.imp[0].adunitcode).to.equal('adunit-code') + it('gets correct site info', function() { + expect(payload.site.page).to.equal('http://example.com/page.html'); + expect(payload.site.domain).to.equal('example.com'); + }); + + it('includes the ad unit code in the request', function() { + const impression = payload.imp[0] + expect(impression.adunitcode).to.equal('adunit-code') }) it('converts tagid to string', function () { @@ -77,109 +90,76 @@ describe('sovrnBidAdapter', function() { }) it('accepts a single array as a size', function() { - const singleSize = [{ - 'bidder': 'sovrn', + const singleSizeBidRequest = { + ...baseBidRequest, 'params': { - 'tagid': '403370', 'iv': 'vet' }, - 'adUnitCode': 'adunit-code', - 'sizes': [300, 250], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }] - const request = spec.buildRequests(singleSize, bidderRequest) + 'sizes': [300, 250] + } + const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) + const payload = JSON.parse(request.data) - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]) - expect(payload.imp[0].banner.w).to.equal(1) - expect(payload.imp[0].banner.h).to.equal(1) + const impression = payload.imp[0] + + expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}]) + expect(impression.banner.w).to.equal(1) + expect(impression.banner.h).to.equal(1) }) it('sends \'iv\' as query param if present', function () { - const ivBidRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': '403370', - 'iv': 'vet' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }]; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', + const ivBidRequest = { + ...baseBidRequest, + params: { + iv: 'vet' } - }; - const request = spec.buildRequests(ivBidRequests, bidderRequest); + } + const request = spec.buildRequests([ivBidRequest], baseBidderRequest) expect(request.url).to.contain('iv=vet') }); it('sends gdpr info if exists', function () { - let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; const bidderRequest = { + ...baseBidderRequest, 'bidderCode': 'sovrn', 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, - gdprConsent: { - consentString: consentString, - gdprApplies: true + 'gdprConsent': { + 'consentString': 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', + 'gdprApplies': true }, - refererInfo: { - referer: 'http://example.com/page.html', - } + 'bids': [baseBidRequest] }; - bidderRequest.bids = [adUnitBidRequest]; - const data = JSON.parse(spec.buildRequests([adUnitBidRequest], bidderRequest).data); + const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(data.regs.ext.gdpr).to.exist.and.to.be.a('number'); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.exist.and.to.be.a('string'); - expect(data.user.ext.consent).to.equal(consentString); - }); + expect(regs.ext.gdpr).to.exist.and.to.be.a('number') + expect(regs.ext.gdpr).to.equal(1) + expect(user.ext.consent).to.exist.and.to.be.a('string') + expect(user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString) + }) it('should send us_privacy if bidderRequest has a value for uspConsent', function () { - const uspString = '1NYN'; const bidderRequest = { + ...baseBidderRequest, 'bidderCode': 'sovrn', 'auctionId': '1d1a030790a475', 'bidderRequestId': '22edbae2733bf6', 'timeout': 3000, - uspConsent: uspString, - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - bidderRequest.bids = [adUnitBidRequest]; + 'uspConsent': '1NYN', + 'bids': [baseBidRequest] + } - const data = JSON.parse(spec.buildRequests([adUnitBidRequest], bidderRequest).data); + const data = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(data.regs.ext['us_privacy']).to.equal(uspString); - }); + expect(data.regs.ext['us_privacy']).to.equal(bidderRequest.uspConsent) + }) it('should add schain if present', function() { - const schainRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': 403370 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', + const schainRequest = { + ...baseBidRequest, 'schain': { 'ver': '1.0', 'complete': 1, @@ -192,100 +172,89 @@ describe('sovrnBidAdapter', function() { } ] } - }].concat(adUnitBidRequest); - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - const data = JSON.parse(spec.buildRequests(schainRequests, bidderRequest).data); + } + const schainRequests = [schainRequest, baseBidRequest] + + const data = JSON.parse(spec.buildRequests(schainRequests, baseBidderRequest).data) expect(data.source.ext.schain.nodes.length).to.equal(1) - }); + }) - it('should add ids to the bid request', function() { - const criteoIdRequest = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': 403370 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userId': { - 'criteoId': 'A_CRITEO_ID', - 'tdid': 'SOMESORTOFID', + it('should add eds to the bid request', function() { + const criteoIdRequest = { + ...baseBidRequest, + userId: { + criteoId: 'A_CRITEO_ID', + tdid: 'SOMESORTOFID', } - }].concat(adUnitBidRequest); - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - - const data = JSON.parse(spec.buildRequests(criteoIdRequest, bidderRequest).data); - expect(data.user.ext.eids[0].source).to.equal('criteo.com') - expect(data.user.ext.eids[0].uids[0].id).to.equal('A_CRITEO_ID') - expect(data.user.ext.eids[0].uids[0].atype).to.equal(1) - expect(data.user.ext.eids[1].source).to.equal('adserver.org') - expect(data.user.ext.eids[1].uids[0].id).to.equal('SOMESORTOFID') - expect(data.user.ext.eids[1].uids[0].ext.rtiPartner).to.equal('TDID') - expect(data.user.ext.eids[1].uids[0].atype).to.equal(1) - expect(data.user.ext.tpid[0].source).to.equal('criteo.com') - expect(data.user.ext.tpid[0].uid).to.equal('A_CRITEO_ID') - expect(data.user.ext.prebid_criteoid).to.equal('A_CRITEO_ID') - }); + } + const criteoIdRequests = [criteoIdRequest, baseBidRequest] + + const ext = JSON.parse(spec.buildRequests(criteoIdRequests, baseBidderRequest).data).user.ext + const firstEID = ext.eids[0] + const secondEID = ext.eids[1] + + expect(firstEID.source).to.equal('criteo.com') + expect(firstEID.uids[0].id).to.equal('A_CRITEO_ID') + expect(firstEID.uids[0].atype).to.equal(1) + expect(secondEID.source).to.equal('adserver.org') + expect(secondEID.uids[0].id).to.equal('SOMESORTOFID') + expect(secondEID.uids[0].ext.rtiPartner).to.equal('TDID') + expect(secondEID.uids[0].atype).to.equal(1) + expect(ext.tpid[0].source).to.equal('criteo.com') + expect(ext.tpid[0].uid).to.equal('A_CRITEO_ID') + expect(ext.prebid_criteoid).to.equal('A_CRITEO_ID') + }) it('should ignore empty segments', function() { - const request = spec.buildRequests([adUnitBidRequest], bidderRequest) + const request = spec.buildRequests([baseBidRequest], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].ext).to.be.undefined }) it('should pass the segments param value as trimmed deal ids array', function() { - const segmentsRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'segments': ' test1,test2 ' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }] - const request = spec.buildRequests(segmentsRequests, bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].ext.deals[0]).to.equal('test1') - expect(payload.imp[0].ext.deals[1]).to.equal('test2') + const segmentsRequest = { + ...baseBidRequest, + params: { + segments: ' test1,test2 ' + } + } + const request = spec.buildRequests([segmentsRequest], baseBidderRequest) + const deals = JSON.parse(request.data).imp[0].ext.deals + + expect(deals[0]).to.equal('test1') + expect(deals[1]).to.equal('test2') }) it('should use the floor provided from the floor module if present', function() { - const floorBid = {...adUnitBidRequest, getFloor: () => ({currency: 'USD', floor: 1.10})} - floorBid.params = { - tagid: 1234, - bidfloor: 2.00 + const floorBid = { + ...baseBidRequest, + getFloor: () => ({currency: 'USD', floor: 1.10}), + params: { + tagid: 1234, + bidfloor: 2.00 + } } - const request = spec.buildRequests([floorBid], bidderRequest) + + const request = spec.buildRequests([floorBid], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].bidfloor).to.equal(1.10) }) it('should use the floor from the param if there is no floor from the floor module', function() { - const floorBid = {...adUnitBidRequest, getFloor: () => ({})} + const floorBid = { + ...baseBidRequest, + getFloor: () => ({}) + } floorBid.params = { tagid: 1234, bidfloor: 2.00 } - const request = spec.buildRequests([floorBid], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].bidfloor).to.equal(2.00) + + const request = spec.buildRequests([floorBid], baseBidderRequest) + const impression = JSON.parse(request.data).imp[0] + + expect(impression.bidfloor).to.equal(2.00) }) describe('First Party Data', function () { let sandbox @@ -307,48 +276,59 @@ describe('sovrnBidAdapter', function() { data: 'some user data' } } - }; - return utils.deepAccess(cfg, key); - }); - const request = spec.buildRequests([adUnitBidRequest], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.user.data).to.equal('some user data') - expect(payload.site.keywords).to.equal('test keyword') - expect(payload.site.page).to.equal('http://example.com/page.html') - expect(payload.site.domain).to.equal('example.com') + } + return utils.deepAccess(cfg, key) + }) + + const request = spec.buildRequests([baseBidRequest], baseBidderRequest) + const { user, site } = JSON.parse(request.data) + + expect(user.data).to.equal('some user data') + expect(site.keywords).to.equal('test keyword') + expect(site.page).to.equal('http://example.com/page.html') + expect(site.domain).to.equal('example.com') }) it('should append impression first party data', function () { - const fpdBid = {...adUnitBidRequest} - fpdBid.ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' + const fpdBidRequest = { + ...baseBidRequest, + ortb2Imp: { + ext: { + data: { + pbadslot: 'homepage-top-rect', + adUnitSpecificAttribute: '123' + } } } } - const request = spec.buildRequests([fpdBid], bidderRequest) + + const request = spec.buildRequests([fpdBidRequest], baseBidderRequest) const payload = JSON.parse(request.data) + expect(payload.imp[0].ext.data.pbadslot).to.equal('homepage-top-rect') expect(payload.imp[0].ext.data.adUnitSpecificAttribute).to.equal('123') }) it('should not overwrite deals when impression fpd is present', function() { - const fpdBid = {...adUnitBidRequest} - fpdBid.params = {...adUnitBidRequest.params} - fpdBid.params.segments = 'seg1, seg2' - fpdBid.ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' + const fpdBid = { + ...baseBidRequest, + params: { + segments: 'seg1, seg2' + }, + ortb2Imp: { + ext: { + data: { + pbadslot: 'homepage-top-rect', + adUnitSpecificAttribute: '123' + } } } } - const request = spec.buildRequests([fpdBid], bidderRequest) - const payload = JSON.parse(request.data) - expect(payload.imp[0].ext.data.pbadslot).to.equal('homepage-top-rect') - expect(payload.imp[0].ext.data.adUnitSpecificAttribute).to.equal('123') - expect(payload.imp[0].ext.deals).to.deep.equal(['seg1', 'seg2']) + + const request = spec.buildRequests([fpdBid], baseBidderRequest) + const impression = JSON.parse(request.data).imp[0] + + expect(impression.ext.data.pbadslot).to.equal('homepage-top-rect') + expect(impression.ext.data.adUnitSpecificAttribute).to.equal('123') + expect(impression.ext.deals).to.deep.equal(['seg1', 'seg2']) }) }) }); @@ -376,7 +356,7 @@ describe('sovrnBidAdapter', function() { }); it('should get the correct bid response', function () { - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -389,15 +369,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(`>`), 'ttl': 60000, 'meta': { advertiserDomains: [] } - }]; + }; - let result = spec.interpretResponse(response); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + const result = spec.interpretResponse(response); + + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) }); it('crid should default to the bid id if not on the response', function () { delete response.body.seatbid[0].bid[0].crid; - let expectedResponse = [{ + + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -410,16 +392,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 90, 'meta': { advertiserDomains: [] } - }]; + } + + const result = spec.interpretResponse(response); - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -432,16 +415,17 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 90, 'meta': { advertiserDomains: [] } - }]; + } - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); + const result = spec.interpretResponse(response) + + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when ttl is set', function () { - response.body.seatbid[0].bid[0].ext = { 'ttl': 480 }; + response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } - let expectedResponse = [{ + const expectedResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, 'width': 728, @@ -454,28 +438,31 @@ describe('sovrnBidAdapter', function() { 'ad': decodeURIComponent(``), 'ttl': 480, 'meta': { advertiserDomains: [] } - }]; + } - let result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); + const result = spec.interpretResponse(response) + + expect(result[0]).to.deep.equal(expectedResponse) + }) it('handles empty bid response', function () { - let response = { + const response = { body: { 'id': '37386aade21a71', 'seatbid': [] } }; - let result = spec.interpretResponse(response); + + const result = spec.interpretResponse(response) + expect(result.length).to.equal(0); }); }); describe('getUserSyncs ', function() { - let syncOptions = { iframeEnabled: true, pixelEnabled: false }; - let iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; - let serverResponse = [ + const syncOptions = { iframeEnabled: true, pixelEnabled: false }; + const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; + const serverResponse = [ { 'body': { 'id': '546956d68c757f', @@ -524,14 +511,14 @@ describe('sovrnBidAdapter', function() { ]; it('should return if iid present on server response & iframe syncs enabled', function() { - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': 'https://ap.lijit.com/beacon?informer=13487408', - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': 'https://ap.lijit.com/beacon?informer=13487408', + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include gdpr consent string if present', function() { @@ -539,26 +526,26 @@ describe('sovrnBidAdapter', function() { gdprApplies: 1, consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, ''); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include us privacy string if present', function() { const uspString = '1NYN'; - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, - } - ]; + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, + } + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, uspString); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement); }); it('should include all privacy strings if present', function() { @@ -567,57 +554,35 @@ describe('sovrnBidAdapter', function() { consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' } const uspString = '1NYN'; - const expectedReturnStatement = [ - { - 'type': 'iframe', - 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, - } - ]; - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString); - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement[0]); + const expectedReturnStatement = { + 'type': 'iframe', + 'url': `https://ap.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&informer=13487408`, + } + + const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString) + + expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) }); it('should not return if iid missing on server response', function() { const returnStatement = spec.getUserSyncs(syncOptions, []); + expect(returnStatement).to.be.empty; }); it('should not return if iframe syncs disabled', function() { const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse); + expect(returnStatement).to.be.empty; }); it('should include pixel syncs', function() { - let pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true }; - const resp2 = { + const pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true } + + const otherResponce = { + ...serverResponse, 'body': { - 'id': '546956d68c757f-2', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'a_448326_16c2ada014224bee815a90d2248322f5-2', - 'impid': '2a3826aae345f4', - 'price': 1.0099999904632568, - 'nurl': 'http://localhost/rtb/impression?bannerid=220958&campaignid=3890&rtb_tid=15588614-75d2-40ab-b27e-13d2127b3c2e&rpid=1295&seatid=seat1&zoneid=448326&cb=26900712&tid=a_448326_16c2ada014224bee815a90d2248322f5', - 'adm': 'yo a creative', - 'crid': 'cridprebidrtb', - 'w': 160, - 'h': 600 - }, - { - 'id': 'a_430392_beac4c1515da4576acf6cb9c5340b40c-2', - 'impid': '3cf96fd26ed4c5', - 'price': 1.0099999904632568, - 'nurl': 'http://localhost/rtb/impression?bannerid=220957&campaignid=3890&rtb_tid=5bc0e68b-3492-448d-a6f9-26fa3fd0b646&rpid=1295&seatid=seat1&zoneid=430392&cb=62735099&tid=a_430392_beac4c1515da4576acf6cb9c5340b40c', - 'adm': 'yo a creative', - 'crid': 'cridprebidrtb', - 'w': 300, - 'h': 250 - }, - ] - } - ], + ...serverResponse.body, 'ext': { 'iid': 13487408, sync: { @@ -631,10 +596,11 @@ describe('sovrnBidAdapter', function() { ] } } - }, - 'headers': {} + } } - const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, resp2]); + + const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, otherResponce]) + expect(returnStatement.length).to.equal(4); expect(returnStatement).to.deep.include.members([ { type: 'image', url: 'http://idprovider1.com' }, @@ -642,45 +608,6 @@ describe('sovrnBidAdapter', function() { { type: 'image', url: 'http://idprovider3.com' }, { type: 'image', url: 'http://idprovider4.com' } ]); - }); - }); - - describe('prebid 3 upgrade', function() { - const bidRequests = [{ - 'bidder': 'sovrn', - 'params': { - 'tagid': '403370' - }, - 'adUnitCode': 'adunit-code', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }]; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html', - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - it('gets sizes from mediaTypes.banner', function() { - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) - expect(payload.imp[0].banner.w).to.equal(1) - expect(payload.imp[0].banner.h).to.equal(1) - }) - - it('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html'); - expect(payload.site.domain).to.equal('example.com'); }) }) }) From 80ee34effa6f30730f6e0e4505868b2e4a2126e0 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 14:46:01 +0300 Subject: [PATCH 02/14] EX-2588 Remove duplicated object initialization --- test/spec/modules/sovrnBidAdapter_spec.js | 65 +++++++---------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index ac8cc9fbadc..1b2e426a0e0 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -335,6 +335,20 @@ describe('sovrnBidAdapter', function() { describe('interpretResponse', function () { let response; + const baseResponse = { + 'requestId': '263c448586f5a1', + 'cpm': 0.45882675, + 'width': 728, + 'height': 90, + 'creativeId': 'creativelycreatedcreativecreative', + 'dealId': null, + 'currency': 'USD', + 'netRevenue': true, + 'mediaType': 'banner', + 'ad': decodeURIComponent(``), + 'ttl': 90, + 'meta': { advertiserDomains: [] } + } beforeEach(function () { response = { body: { @@ -357,18 +371,9 @@ describe('sovrnBidAdapter', function() { it('should get the correct bid response', function () { const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', + ...baseResponse, 'ad': decodeURIComponent(`>`), 'ttl': 60000, - 'meta': { advertiserDomains: [] } }; const result = spec.interpretResponse(response); @@ -380,18 +385,9 @@ describe('sovrnBidAdapter', function() { delete response.body.seatbid[0].bid[0].crid; const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, + ...baseResponse, 'creativeId': response.body.seatbid[0].bid[0].id, - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', 'ad': decodeURIComponent(``), - 'ttl': 90, - 'meta': { advertiserDomains: [] } } const result = spec.interpretResponse(response); @@ -402,42 +398,17 @@ describe('sovrnBidAdapter', function() { it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; - const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': 'baking', - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': decodeURIComponent(``), - 'ttl': 90, - 'meta': { advertiserDomains: [] } - } - const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(expectedResponse); + expect(result[0]).to.deep.equal(baseResponse); }); it('should get correct bid response when ttl is set', function () { response.body.seatbid[0].bid[0].ext = { 'ttl': 480 } const expectedResponse = { - 'requestId': '263c448586f5a1', - 'cpm': 0.45882675, - 'width': 728, - 'height': 90, - 'creativeId': 'creativelycreatedcreativecreative', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': decodeURIComponent(``), + ...baseResponse, 'ttl': 480, - 'meta': { advertiserDomains: [] } } const result = spec.interpretResponse(response) From 6ac964c1c539189db00c452adc58da735cd38545 Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Tue, 14 Sep 2021 17:22:11 +0300 Subject: [PATCH 03/14] EX-2588 Fix interpretResponse test --- test/spec/modules/sovrnBidAdapter_spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 1b2e426a0e0..3f62ec5bbc3 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -397,10 +397,14 @@ describe('sovrnBidAdapter', function() { it('should get correct bid response when dealId is passed', function () { response.body.seatbid[0].bid[0].dealid = 'baking'; + const expectedResponse = { + ...baseResponse, + 'dealId': 'baking', + } const result = spec.interpretResponse(response) - expect(result[0]).to.deep.equal(baseResponse); + expect(result[0]).to.deep.equal(expectedResponse); }); it('should get correct bid response when ttl is set', function () { From b0ef0c1a5462d5b9406b8fe2e788b03d9899932e Mon Sep 17 00:00:00 2001 From: Mikhalovich Date: Wed, 15 Sep 2021 10:42:46 +0300 Subject: [PATCH 04/14] EX-2588 Return prebid 3 upgrage test in sovrn's tests --- test/spec/modules/sovrnBidAdapter_spec.js | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 3f62ec5bbc3..6fd5eecfb78 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -585,4 +585,34 @@ describe('sovrnBidAdapter', function() { ]); }) }) + + describe('prebid 3 upgrade', function() { + const bidRequest = { + ...baseBidRequest, + 'params': { + 'tagid': '403370' + }, + 'mediaTypes': { + 'banner': { + 'sizes': [ + [300, 250], + [300, 600] + ] + } + }, + }; + const request = spec.buildRequests([bidRequest], baseBidderRequest); + const payload = JSON.parse(request.data); + + it('gets sizes from mediaTypes.banner', function() { + expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) + expect(payload.imp[0].banner.w).to.equal(1) + expect(payload.imp[0].banner.h).to.equal(1) + }) + + it('gets correct site info', function() { + expect(payload.site.page).to.equal('http://example.com/page.html'); + expect(payload.site.domain).to.equal('example.com'); + }) + }) }) From 13234668d0e96d5befb44bde4db0192d289093ad Mon Sep 17 00:00:00 2001 From: jessoventes <82361050+jessoventes@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:51:21 +0530 Subject: [PATCH 05/14] Ventes Bid Adapter: fix web support and code maintenance (#7766) * Ventes Avenues initial changes * Ventes Avenues initial changes * Support Web Placments * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placments From 412be43f4a862cabafa4a9ebbbcc6c78029ee368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mar=C3=ADn?= Date: Tue, 7 Dec 2021 21:39:05 +0100 Subject: [PATCH 06/14] Index Exchange adapter: Webpack v5 complain about named export from JSON modules (#7774) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Webpack v5 complain about named export from JSON modules * Index Exchange Adapter: fix "Should not import the named export 'EVENTS'.'AUCTION_DEBUG' (imported as 'EVENTS') from default-exporting module (only default export is available soon)"" Co-authored-by: Javier Marín From 8f68d5ed9612d4cae3b371ea7a5e417c9ec712b5 Mon Sep 17 00:00:00 2001 From: Chris Pabst Date: Mon, 10 Jan 2022 12:36:51 -0700 Subject: [PATCH 07/14] Revert "Merge pull request #37 from sovrn/unmerged-changes" This reverts commit 8b42386c6a1d501443fde760f270a6d2d5303dd0, reversing changes made to 0b24b9c0255f74d69adbcb0ef7cabb1f15d745c3. --- .babelrc.js | 11 +- .circleci/config.yml | 2 +- .devcontainer/Dockerfile | 11 - .devcontainer/devcontainer.json | 27 - .devcontainer/postCreate.sh | 6 - README.md | 9 +- allowedModules.js | 3 +- browsers.json | 51 +- gulpfile.js | 170 +- integrationExamples/gpt/adloox.html | 27 +- integrationExamples/gpt/afpExample.html | 242 --- integrationExamples/gpt/afpGamExample.html | 152 -- .../gpt/akamaidap_segments_example.html | 132 -- .../gpt/imRtdProvider_example.html | 115 -- integrationExamples/gpt/userId_example.html | 1 - .../gpt/weboramaRtdProvider_example.html | 135 -- .../noadserver/basic_noadserver.html | 106 -- karma.conf.maker.js | 4 +- modules/.submodules.json | 57 +- modules/33acrossBidAdapter.js | 324 ++-- modules/a4gBidAdapter.js | 6 +- modules/ablidaBidAdapter.js | 4 +- modules/adWMGBidAdapter.js | 8 +- modules/adagioAnalyticsAdapter.js | 8 +- modules/adagioBidAdapter.js | 169 +- modules/adbookpspBidAdapter.js | 147 +- modules/addefendBidAdapter.js | 1 - modules/adfBidAdapter.js | 71 +- modules/adgenerationBidAdapter.js | 60 +- modules/adhashBidAdapter.js | 105 -- modules/adhashBidAdapter.md | 2 +- modules/adheseBidAdapter.js | 9 +- modules/adkernelAdnAnalyticsAdapter.js | 12 +- modules/adkernelAdnBidAdapter.js | 46 +- modules/adkernelBidAdapter.js | 287 ++-- modules/adlivetechBidAdapter.md | 61 - modules/adlooxAdServerVideo.js | 56 +- modules/adlooxAnalyticsAdapter.js | 90 +- modules/adlooxAnalyticsAdapter.md | 17 +- modules/adlooxRtdProvider.js | 393 ----- modules/adlooxRtdProvider.md | 105 -- modules/admanBidAdapter.js | 180 --- modules/admixerBidAdapter.js | 25 +- modules/admixerIdSystem.js | 8 +- modules/adnowBidAdapter.js | 8 +- modules/adnuntiusBidAdapter.js | 18 +- modules/adoceanBidAdapter.js | 20 +- modules/adomikAnalyticsAdapter.js | 50 +- modules/adpartnerBidAdapter.js | 215 --- modules/adpartnerBidAdapter.md | 14 +- modules/adplusBidAdapter.js | 203 --- modules/adplusBidAdapter.md | 39 - modules/adpod.js | 87 +- modules/adprimeBidAdapter.js | 8 +- modules/adqueryBidAdapter.js | 204 --- modules/adqueryBidAdapter.md | 32 - modules/adqueryIdSystem.js | 103 -- modules/adqueryIdSystem.md | 35 - modules/adrelevantisBidAdapter.js | 57 +- modules/adriverBidAdapter.js | 26 +- modules/adtargetBidAdapter.js | 48 +- modules/adtelligentBidAdapter.js | 61 +- modules/adtrueBidAdapter.js | 70 +- modules/aduptechBidAdapter.js | 20 +- modules/advangelistsBidAdapter.js | 398 ----- modules/advangelistsBidAdapter.md | 15 +- modules/adxcgAnalyticsAdapter.js | 10 +- modules/adxcgBidAdapter.js | 670 ++++---- modules/adxcgBidAdapter.md | 43 +- modules/adxpremiumAnalyticsAdapter.js | 34 +- modules/adyoulikeBidAdapter.js | 49 +- modules/afpBidAdapter.js | 166 -- modules/afpBidAdapter.md | 348 ----- modules/airgridRtdProvider.js | 2 +- modules/ajaBidAdapter.js | 55 +- modules/akamaiDAPIdSystem.js | 18 +- modules/akamaiDapRtdProvider.js | 474 ------ modules/akamaiDapRtdProvider.md | 47 - modules/aniviewBidAdapter.js | 6 +- modules/aolBidAdapter.js | 29 +- modules/apacdexBidAdapter.js | 32 +- modules/apstreamBidAdapter.js | 10 +- modules/asoBidAdapter.js | 60 +- modules/astraoneBidAdapter.js | 4 +- modules/atsAnalyticsAdapter.js | 170 +- modules/atsAnalyticsAdapter.md | 1 - modules/audiencerunBidAdapter.js | 30 +- modules/automatadBidAdapter.js | 4 +- modules/axonixBidAdapter.js | 14 +- modules/beachfrontBidAdapter.js | 89 +- modules/beopBidAdapter.js | 52 +- modules/betweenBidAdapter.js | 42 +- modules/bidViewability.js | 6 +- modules/bidViewabilityIO.js | 20 +- modules/bidglassBidAdapter.js | 16 +- modules/bidscubeBidAdapter.js | 6 +- modules/bizzclickBidAdapter.js | 20 +- modules/bliinkBidAdapter.js | 336 ---- modules/bliinkBidAdapter.md | 94 -- modules/bluebillywigBidAdapter.js | 60 +- modules/boldwinBidAdapter.js | 8 +- modules/braveBidAdapter.js | 10 +- modules/bridgewellBidAdapter.js | 10 +- modules/brightMountainMediaBidAdapter.js | 20 +- modules/brightcomBidAdapter.js | 36 +- modules/britepoolIdSystem.js | 14 +- modules/browsiRtdProvider.js | 138 +- modules/bucksenseBidAdapter.js | 18 +- modules/buzzoolaBidAdapter.js | 8 +- modules/byDataAnalyticsAdapter.js | 311 ---- modules/byDataAnalyticsAdapter.md | 34 - modules/ccxBidAdapter.js | 76 +- modules/cleanioRtdProvider.js | 192 --- modules/cleanioRtdProvider.md | 59 - modules/cleanmedianetBidAdapter.js | 18 +- modules/clickforceBidAdapter.js | 8 +- modules/codefuelBidAdapter.js | 181 --- modules/codefuelBidAdapter.md | 111 -- modules/cointrafficBidAdapter.js | 8 +- modules/coinzillaBidAdapter.js | 4 +- modules/colossussspBidAdapter.js | 35 +- modules/colossussspBidAdapter.md | 16 +- modules/compassBidAdapter.js | 208 --- modules/compassBidAdapter.md | 79 - modules/concertAnalyticsAdapter.js | 6 +- modules/concertBidAdapter.js | 33 +- modules/connectIdSystem.js | 104 -- modules/connectIdSystem.md | 33 - modules/connectadBidAdapter.js | 26 +- modules/consentManagement.js | 65 +- modules/consentManagementUsp.js | 28 +- modules/consumableBidAdapter.js | 6 +- modules/contentexchangeBidAdapter.js | 10 +- modules/conversantBidAdapter.js | 63 +- modules/cpmstarBidAdapter.js | 17 +- modules/craftBidAdapter.js | 28 +- modules/criteoBidAdapter.js | 52 +- modules/criteoIdSystem.js | 84 +- modules/currency.js | 40 +- modules/cwireBidAdapter.js | 275 ---- modules/cwireBidAdapter.md | 43 - modules/dailyhuntBidAdapter.js | 435 ------ modules/dailyhuntBidAdapter.md | 4 - modules/datablocksBidAdapter.js | 30 +- modules/dchain.js | 149 -- modules/dchain.md | 45 - modules/deepintentBidAdapter.js | 141 +- modules/deepintentBidAdapter.md | 37 +- modules/deltaprojectsBidAdapter.js | 252 --- modules/deltaprojectsBidAdapter.md | 32 - modules/dgkeywordRtdProvider.js | 21 +- modules/districtmDMXBidAdapter.js | 30 +- modules/dmdIdSystem.js | 10 +- modules/docereeBidAdapter.js | 29 +- modules/docereeBidAdapter.md | 2 - modules/dspxBidAdapter.js | 12 +- modules/ebdrBidAdapter.js | 18 +- modules/emx_digitalBidAdapter.js | 56 +- modules/engageyaBidAdapter.js | 171 -- modules/enrichmentFpdModule.js | 78 +- modules/eplanningAnalyticsAdapter.js | 4 +- modules/eplanningBidAdapter.js | 20 +- modules/etargetBidAdapter.js | 8 +- modules/express.js | 19 +- modules/fabrickIdSystem.js | 12 +- modules/feedadBidAdapter.js | 14 +- modules/feedadBidAdapter.md | 6 +- modules/fintezaAnalyticsAdapter.js | 8 +- modules/flocIdSystem.js | 10 +- modules/fluctBidAdapter.js | 126 -- modules/freewheel-sspBidAdapter.js | 18 +- modules/futureads.md | 48 - modules/gamoshiBidAdapter.js | 44 +- modules/gdprEnforcement.js | 27 +- modules/getintentBidAdapter.js | 7 +- modules/gjirafaBidAdapter.js | 13 +- modules/glimpseBidAdapter.js | 258 +-- modules/glimpseBidAdapter.md | 85 +- modules/gmosspBidAdapter.js | 34 +- modules/gnetBidAdapter.js | 10 +- modules/goldbachBidAdapter.js | 1176 -------------- modules/goldbachBidAdapter.md | 151 -- modules/googleAnalyticsAdapter.js | 12 +- modules/gothamadsBidAdapter.js | 18 +- modules/gptPreAuction.js | 82 +- modules/gridBidAdapter.js | 95 +- modules/gridBidAdapter.md | 11 - modules/gridNMBidAdapter.js | 277 +--- modules/growadvertisingBidAdapter.js | 15 +- modules/gumgumBidAdapter.js | 54 +- modules/h12mediaBidAdapter.js | 24 +- modules/haloIdSystem.js | 16 +- modules/hybridBidAdapter.js | 14 +- modules/iasRtdProvider.js | 128 +- modules/id5IdSystem.js | 48 +- modules/id5IdSystem.md | 12 +- modules/idImportLibrary.js | 119 +- modules/idImportLibrary.md | 4 - modules/idxIdSystem.js | 6 +- modules/imRtdProvider.js | 228 --- modules/imRtdProvider.md | 41 - modules/impactifyBidAdapter.js | 37 +- modules/improvedigitalBidAdapter.js | 116 +- modules/imuIdSystem.js | 12 +- modules/inmarBidAdapter.js | 4 +- modules/innityBidAdapter.js | 6 +- modules/inskinBidAdapter.js | 20 +- modules/inskinBidAdapter.md | 9 +- modules/insticatorBidAdapter.js | 281 ---- modules/insticatorBidAdapter.md | 53 - modules/instreamTracking.js | 18 +- modules/integr8BidAdapter.js | 21 +- modules/intentIqIdSystem.js | 14 +- modules/interactiveOffersBidAdapter.js | 10 +- modules/intersectionRtdProvider.js | 114 -- modules/invibesBidAdapter.js | 138 +- modules/invibesBidAdapter.md | 3 +- modules/invisiblyAnalyticsAdapter.js | 10 +- modules/ipromBidAdapter.js | 79 - modules/iqmBidAdapter.js | 38 +- modules/iqzoneBidAdapter.js | 176 --- modules/iqzoneBidAdapter.md | 80 - modules/ixBidAdapter.js | 593 ++----- modules/jixieBidAdapter.js | 22 +- modules/justpremiumBidAdapter.js | 11 +- modules/kargoBidAdapter.js | 29 +- modules/kargoBidAdapter.md | 20 - modules/kinessoIdSystem.js | 18 +- modules/koblerBidAdapter.js | 24 +- modules/konduitAnalyticsAdapter.js | 8 +- modules/konduitWrapper.js | 28 +- modules/krushmediaBidAdapter.js | 8 +- modules/kubientBidAdapter.js | 10 +- modules/limelightDigitalBidAdapter.js | 32 +- modules/liveIntentIdSystem.js | 9 +- modules/livewrappedAnalyticsAdapter.js | 96 +- modules/livewrappedBidAdapter.js | 22 +- modules/liveyieldAnalyticsAdapter.js | 26 +- modules/lockerdomeBidAdapter.js | 4 +- modules/loganBidAdapter.js | 8 +- modules/loglyliftBidAdapter.js | 79 - modules/loglyliftBidAdapter.md | 55 - modules/lotamePanoramaIdSystem.js | 112 +- modules/lunamediahbBidAdapter.js | 4 +- modules/luponmediaBidAdapter.js | 570 ------- modules/madvertiseBidAdapter.js | 6 +- modules/malltvBidAdapter.js | 15 +- modules/marsmediaBidAdapter.js | 52 +- modules/mathildeadsBidAdapter.js | 10 +- modules/mediaforceBidAdapter.js | 22 +- modules/mediakeysBidAdapter.js | 497 +----- modules/mediakeysBidAdapter.md | 108 -- modules/medianetAnalyticsAdapter.js | 173 +- modules/medianetBidAdapter.js | 71 +- modules/medianetRtdProvider.js | 14 +- modules/mediasquareBidAdapter.js | 10 +- modules/merkleIdSystem.js | 63 +- modules/mgidBidAdapter.js | 617 -------- modules/microadBidAdapter.js | 6 +- modules/missenaBidAdapter.js | 89 -- modules/multibid/index.js | 28 +- modules/mwOpenLinkIdSystem.js | 14 +- modules/mytargetBidAdapter.js | 112 -- modules/nativoBidAdapter.js | 92 +- modules/nativoBidAdapter.md | 1 + modules/naveggIdSystem.js | 90 -- modules/naveggIdSystem.md | 22 - modules/nextMillenniumBidAdapter.js | 65 +- modules/nextrollBidAdapter.js | 375 ----- modules/nobidBidAdapter.js | 23 +- modules/novatiqIdSystem.js | 16 +- modules/oguryBidAdapter.js | 57 +- modules/oneVideoBidAdapter.js | 40 +- modules/onetagBidAdapter.js | 19 +- modules/onomagicBidAdapter.js | 32 +- modules/ooloAnalyticsAdapter.js | 26 +- modules/openwebBidAdapter.js | 52 +- modules/openxAnalyticsAdapter.js | 66 +- modules/openxBidAdapter.js | 121 +- modules/operaadsBidAdapter.js | 201 ++- modules/operaadsBidAdapter.md | 25 +- modules/optimeraRtdProvider.js | 27 +- modules/optoutBidAdapter.js | 6 +- modules/orbidderBidAdapter.js | 6 +- modules/otmBidAdapter.js | 146 -- modules/otmBidAdapter.md | 53 +- modules/outbrainBidAdapter.js | 31 +- modules/ozoneBidAdapter.js | 337 ++-- modules/padsquadBidAdapter.js | 8 +- modules/parrableIdSystem.js | 34 +- modules/pixfutureBidAdapter.js | 70 +- modules/pixfutureBidAdapter.md | 127 -- modules/playwireBidAdapter.md | 61 - modules/prebidServerBidAdapter/index.js | 256 +-- modules/prebidmanagerAnalyticsAdapter.js | 14 +- modules/priceFloors.js | 98 +- modules/proxistoreBidAdapter.js | 16 +- modules/pubCommonId.js | 22 +- modules/pubProvidedIdSystem.js | 6 +- modules/pubgeniusBidAdapter.js | 2 +- modules/publinkIdSystem.js | 144 -- modules/publinkIdSystem.md | 33 - modules/pubmaticAnalyticsAdapter.js | 48 +- modules/pubmaticBidAdapter.js | 241 ++- modules/pubmaticBidAdapter.md | 2 +- modules/pubperfAnalyticsAdapter.js | 6 +- modules/pubwiseAnalyticsAdapter.js | 12 +- modules/pubwiseBidAdapter.js | 46 +- modules/pubxBidAdapter.js | 4 +- modules/pubxaiAnalyticsAdapter.js | 31 +- modules/pulsepointBidAdapter.js | 34 +- modules/pxyzBidAdapter.js | 14 +- modules/quantcastBidAdapter.js | 32 +- modules/radsBidAdapter.js | 10 +- modules/realvuAnalyticsAdapter.js | 12 +- modules/reconciliationRtdProvider.js | 12 +- modules/relaidoBidAdapter.js | 217 ++- modules/resetdigitalBidAdapter.js | 7 +- modules/revcontentBidAdapter.js | 18 +- modules/rhythmoneBidAdapter.js | 33 +- modules/richaudienceBidAdapter.js | 24 +- modules/riseBidAdapter.js | 136 +- modules/riseBidAdapter.md | 4 +- modules/roxotAnalyticsAdapter.js | 28 +- modules/rtbhouseBidAdapter.js | 32 +- modules/rtbsapeBidAdapter.js | 7 +- modules/rtdModule/index.js | 76 +- modules/rubiconAnalyticsAdapter.js | 166 +- modules/rubiconBidAdapter.js | 200 ++- modules/saambaaBidAdapter.js | 420 ----- modules/saambaaBidAdapter.md | 133 +- modules/scaleableAnalyticsAdapter.js | 4 +- modules/seedingAllianceBidAdapter.js | 231 --- modules/seedtagBidAdapter.js | 26 +- modules/sharedIdSystem.js | 50 +- modules/sharethroughAnalyticsAdapter.js | 16 +- modules/sharethroughBidAdapter.js | 416 ++--- modules/sharethroughBidAdapter.md | 68 +- modules/showheroes-bsBidAdapter.js | 61 +- modules/sigmoidAnalyticsAdapter.js | 9 +- modules/sirdataRtdProvider.js | 68 +- modules/sizeMappingV2.js | 78 +- modules/slimcutBidAdapter.js | 121 -- modules/smaatoBidAdapter.js | 98 +- modules/smartadserverBidAdapter.js | 14 +- modules/smartxBidAdapter.js | 195 +-- modules/smartxBidAdapter.md | 8 +- modules/smartyadsBidAdapter.js | 37 +- modules/smartyadsBidAdapter.md | 12 +- modules/smilewantedBidAdapter.js | 12 +- modules/sonobiAnalyticsAdapter.js | 46 +- modules/sonobiBidAdapter.js | 8 - modules/sortableAnalyticsAdapter.js | 10 +- modules/sortableBidAdapter.js | 57 +- modules/sovrnAnalyticsAdapter.js | 10 +- modules/sovrnBidAdapter.js | 44 +- modules/spotxBidAdapter.js | 180 +-- modules/sspBCBidAdapter.js | 270 +--- modules/sspBCBidAdapter.md | 2 +- modules/staqAnalyticsAdapter.js | 18 +- modules/stroeerCoreBidAdapter.js | 32 +- modules/sublimeBidAdapter.js | 81 +- modules/synacormediaBidAdapter.js | 41 +- modules/talkadsBidAdapter.js | 129 -- modules/talkadsBidAdapter.md | 60 - modules/tapadIdSystem.js | 6 +- modules/tappxBidAdapter.js | 189 +-- modules/tappxBidAdapter.md | 4 +- modules/targetVideoBidAdapter.js | 187 --- modules/targetVideoBidAdapter.md | 34 - modules/teadsBidAdapter.js | 42 +- modules/telariaBidAdapter.js | 38 +- modules/temedyaBidAdapter.js | 8 +- modules/terceptAnalyticsAdapter.js | 8 +- modules/theAdxBidAdapter.js | 32 +- modules/timeoutRtdProvider.js | 181 --- modules/timeoutRtdProvider.md | 151 -- modules/tpmnBidAdapter.js | 6 +- modules/trionBidAdapter.js | 30 +- modules/tripleliftBidAdapter.js | 76 +- modules/truereachBidAdapter.js | 8 +- modules/trustxBidAdapter.js | 705 +++++---- modules/trustxBidAdapter.md | 51 +- modules/turktelekomBidAdapter.md | 49 + modules/ucfunnelBidAdapter.js | 6 +- modules/uid2IdSystem.js | 12 +- modules/underdogmediaBidAdapter.js | 8 +- modules/undertoneBidAdapter.js | 23 +- modules/undertoneBidAdapter.md | 6 +- modules/unicornBidAdapter.js | 30 +- modules/unifiedIdSystem.js | 8 +- modules/unrulyBidAdapter.js | 32 +- modules/userId/eids.js | 62 +- modules/userId/eids.md | 23 +- modules/userId/index.js | 99 +- modules/userId/userId.md | 23 - modules/validationFpdModule/config.js | 26 +- modules/validationFpdModule/index.js | 31 +- modules/vdoaiBidAdapter.js | 4 +- modules/ventes.md | 71 - modules/ventesBidAdapter.js | 410 ----- modules/ventesBidAdapter.md | 93 -- modules/verizonMediaIdSystem.js | 10 +- modules/vidazooBidAdapter.js | 10 +- modules/videobyteBidAdapter.js | 63 +- modules/videobyteBidAdapter.md | 49 - modules/videoreachBidAdapter.js | 14 +- modules/vidoomyBidAdapter.js | 144 +- modules/viewdeosDXBidAdapter.js | 34 +- modules/visxBidAdapter.js | 396 ++--- modules/visxBidAdapter.md | 10 +- modules/voxBidAdapter.js | 14 +- modules/vrtcalBidAdapter.js | 14 +- modules/vuukleBidAdapter.js | 4 +- modules/waardexBidAdapter.js | 52 +- modules/weboramaBidAdapter.md | 27 + modules/weboramaRtdProvider.js | 389 ----- modules/weboramaRtdProvider.md | 87 -- modules/welectBidAdapter.js | 106 -- modules/winrBidAdapter.js | 54 +- modules/wipesBidAdapter.js | 4 +- modules/yahoosspBidAdapter.js | 641 -------- modules/yahoosspBidAdapter.md | 795 ---------- modules/yieldlabBidAdapter.js | 120 +- modules/yieldlabBidAdapter.md | 124 +- modules/yieldliftBidAdapter.js | 18 +- modules/yieldmoBidAdapter.js | 154 +- modules/yieldmoSyntheticInventoryModule.js | 46 - modules/yieldmoSyntheticInventoryModule.md | 68 - modules/yieldoneAnalyticsAdapter.js | 12 +- modules/yieldoneBidAdapter.js | 134 +- modules/yuktamediaAnalyticsAdapter.js | 30 +- modules/zeotapIdPlusIdSystem.js | 4 +- modules/zetaBidAdapter.js | 12 +- modules/zetaSspBidAdapter.md | 34 +- modules/zeta_global_sspAnalyticsAdapter.js | 97 -- modules/zeta_global_sspAnalyticsAdapter.md | 24 - modules/zeta_global_sspBidAdapter.js | 123 +- package.json | 7 +- plugins/pbjsGlobals.js | 29 +- src/AnalyticsAdapter.js | 12 +- src/Renderer.js | 18 +- src/adapterManager.js | 112 +- src/adapters/bidderFactory.js | 12 +- src/adloader.js | 12 +- src/ajax.js | 17 +- src/auction.js | 76 +- src/bidfactory.js | 4 +- src/config.js | 151 +- src/constants.json | 2 - src/cpmBucketManager.js | 4 +- src/hook.js | 6 +- src/prebid.js | 188 +-- src/secureCreatives.js | 18 +- src/storageManager.js | 10 +- src/targeting.js | 100 +- src/userSync.js | 57 +- src/utils.js | 61 +- src/videoCache.js | 4 +- test/.eslintrc.js | 3 +- test/helpers/prebidGlobal.js | 1 - test/spec/config_spec.js | 342 ---- test/spec/integration/faker/googletag.js | 11 - test/spec/modules/33acrossBidAdapter_spec.js | 378 +---- test/spec/modules/adbookpspBidAdapter_spec.js | 20 +- test/spec/modules/adfBidAdapter_spec.js | 157 +- .../modules/adgenerationBidAdapter_spec.js | 171 +- test/spec/modules/adhashBidAdapter_spec.js | 155 -- test/spec/modules/adheseBidAdapter_spec.js | 28 +- .../modules/adlooxAnalyticsAdapter_spec.js | 14 +- test/spec/modules/adlooxRtdProvider_spec.js | 313 ---- test/spec/modules/admanBidAdapter_spec.js | 187 --- test/spec/modules/admixerBidAdapter_spec.js | 6 +- test/spec/modules/adnuntiusBidAdapter_spec.js | 103 -- .../modules/adomikAnalyticsAdapter_spec.js | 14 +- test/spec/modules/adpartnerBidAdapter_spec.js | 336 ---- test/spec/modules/adplusBidAdapter_spec.js | 213 --- test/spec/modules/adqueryBidAdapter_spec.js | 185 --- test/spec/modules/adqueryIdSystem_spec.js | 74 - .../modules/adtelligentBidAdapter_spec.js | 1 - .../modules/advangelistsBidAdapter_spec.js | 139 -- test/spec/modules/adxcgBidAdapter_spec.js | 1391 +++++++---------- test/spec/modules/adyoulikeBidAdapter_spec.js | 75 - test/spec/modules/afpBidAdapter_spec.js | 306 ---- test/spec/modules/ajaBidAdapter_spec.js | 58 +- .../spec/modules/akamaiDapRtdProvider_spec.js | 246 --- test/spec/modules/appnexusBidAdapter_spec.js | 67 +- test/spec/modules/atsAnalyticsAdapter_spec.js | 86 +- .../spec/modules/beachfrontBidAdapter_spec.js | 66 +- test/spec/modules/beopBidAdapter_spec.js | 15 +- test/spec/modules/betweenBidAdapter_spec.js | 136 +- test/spec/modules/bidViewabilityIO_spec.js | 4 +- test/spec/modules/bidViewability_spec.js | 8 +- test/spec/modules/bliinkBidAdapter_spec.js | 612 -------- test/spec/modules/browsiRtdProvider_spec.js | 69 +- .../modules/byDataAnalyticsAdapter_spec.js | 139 -- test/spec/modules/cleanioRtdProvider_spec.js | 188 --- test/spec/modules/codefuelBidAdapter_spec.js | 316 ---- .../modules/colossussspBidAdapter_spec.js | 38 +- test/spec/modules/compassBidAdapter_spec.js | 398 ----- test/spec/modules/connectIdSystem_spec.js | 189 --- test/spec/modules/consentManagement_spec.js | 20 - test/spec/modules/criteoBidAdapter_spec.js | 38 - test/spec/modules/criteoIdSystem_spec.js | 84 +- test/spec/modules/cwireBidAdapter_spec.js | 248 --- test/spec/modules/dailyhuntBidAdapter_spec.js | 404 ----- .../spec/modules/datablocksBidAdapter_spec.js | 6 +- test/spec/modules/dchain_spec.js | 329 ---- .../spec/modules/deepintentBidAdapter_spec.js | 156 +- .../modules/deltaprojectsBidAdapter_spec.js | 399 ----- test/spec/modules/docereeBidAdapter_spec.js | 10 +- test/spec/modules/eids_spec.js | 15 - .../modules/emx_digitalBidAdapter_spec.js | 10 - test/spec/modules/engageyaBidAdapter_spec.js | 422 ----- test/spec/modules/enrichmentFpdModule_spec.js | 20 +- test/spec/modules/eplanningBidAdapter_spec.js | 22 +- test/spec/modules/feedadBidAdapter_spec.js | 15 - .../modules/fintezaAnalyticsAdapter_spec.js | 12 +- test/spec/modules/fluctBidAdapter_spec.js | 213 --- .../modules/freewheel-sspBidAdapter_spec.js | 19 - test/spec/modules/glimpseBidAdapter_spec.js | 521 +++--- test/spec/modules/goldbachBidAdapter_spec.js | 1359 ---------------- test/spec/modules/gptPreAuction_spec.js | 241 +-- test/spec/modules/gridBidAdapter_spec.js | 186 +-- test/spec/modules/gridNMBidAdapter_spec.js | 168 +- test/spec/modules/gumgumBidAdapter_spec.js | 67 +- test/spec/modules/iasRtdProvider_spec.js | 124 +- test/spec/modules/idImportLibrary_spec.js | 207 +-- test/spec/modules/imRtdProvider_spec.js | 176 --- test/spec/modules/impactifyBidAdapter_spec.js | 16 +- .../modules/improvedigitalBidAdapter_spec.js | 46 +- test/spec/modules/inskinBidAdapter_spec.js | 11 +- .../spec/modules/insticatorBidAdapter_spec.js | 416 ----- .../modules/intersectionRtdProvider_spec.js | 141 -- test/spec/modules/invibesBidAdapter_spec.js | 264 +--- test/spec/modules/ipromBidAdapter_spec.js | 195 --- test/spec/modules/iqzoneBidAdapter_spec.js | 371 ----- test/spec/modules/ixBidAdapter_spec.js | 542 ++----- test/spec/modules/jixieBidAdapter_spec.js | 24 +- .../modules/justpremiumBidAdapter_spec.js | 27 +- test/spec/modules/kargoBidAdapter_spec.js | 2 +- test/spec/modules/konduitWrapper_spec.js | 1 + .../limelightDigitalBidAdapter_spec.js | 263 +--- .../livewrappedAnalyticsAdapter_spec.js | 117 +- .../modules/livewrappedBidAdapter_spec.js | 31 - test/spec/modules/loglyliftBidAdapter_spec.js | 172 -- .../modules/lotamePanoramaIdSystem_spec.js | 227 --- .../spec/modules/luponmediaBidAdapter_spec.js | 412 ----- test/spec/modules/mediakeysBidAdapter_spec.js | 457 +----- .../modules/medianetAnalyticsAdapter_spec.js | 46 +- test/spec/modules/medianetBidAdapter_spec.js | 63 +- .../modules/mediasquareBidAdapter_spec.js | 8 +- test/spec/modules/merkleIdSystem_spec.js | 230 --- test/spec/modules/mgidBidAdapter_spec.js | 826 ---------- test/spec/modules/missenaBidAdapter_spec.js | 134 -- test/spec/modules/multibid_spec.js | 62 +- test/spec/modules/mytargetBidAdapter_spec.js | 199 --- test/spec/modules/nativoBidAdapter_spec.js | 102 +- test/spec/modules/naveggIdSystem_spec.js | 21 - .../modules/nextMillenniumBidAdapter_spec.js | 39 +- test/spec/modules/nextrollBidAdapter_spec.js | 290 ---- test/spec/modules/nobidBidAdapter_spec.js | 66 +- test/spec/modules/oguryBidAdapter_spec.js | 208 +-- test/spec/modules/onetagBidAdapter_spec.js | 7 +- test/spec/modules/openxBidAdapter_spec.js | 103 +- test/spec/modules/operaadsBidAdapter_spec.js | 59 +- test/spec/modules/optimeraRtdProvider_spec.js | 15 +- test/spec/modules/otmBidAdapter_spec.js | 67 - test/spec/modules/outbrainBidAdapter_spec.js | 18 - test/spec/modules/ozoneBidAdapter_spec.js | 74 +- .../modules/prebidServerBidAdapter_spec.js | 76 +- test/spec/modules/priceFloors_spec.js | 79 - test/spec/modules/pubgeniusBidAdapter_spec.js | 6 +- test/spec/modules/publinkIdSystem_spec.js | 169 -- .../modules/pubmaticAnalyticsAdapter_spec.js | 14 +- test/spec/modules/pubmaticBidAdapter_spec.js | 310 +--- .../modules/pubxaiAnalyticsAdapter_spec.js | 11 - .../spec/modules/pulsepointBidAdapter_spec.js | 26 +- test/spec/modules/realTimeDataModule_spec.js | 195 +-- test/spec/modules/relaidoBidAdapter_spec.js | 167 +- .../modules/richaudienceBidAdapter_spec.js | 44 +- test/spec/modules/riseBidAdapter_spec.js | 2 +- test/spec/modules/rtbhouseBidAdapter_spec.js | 20 - .../modules/rubiconAnalyticsAdapter_spec.js | 203 +-- test/spec/modules/rubiconAnalyticsSchema.json | 7 +- test/spec/modules/rubiconBidAdapter_spec.js | 74 +- .../modules/seedingAllianceAdapter_spec.js | 186 --- test/spec/modules/seedtagBidAdapter_spec.js | 3 - test/spec/modules/sharedIdSystem_spec.js | 58 +- .../modules/sharethroughBidAdapter_spec.js | 1087 +++++++------ .../modules/showheroes-bsBidAdapter_spec.js | 2 - test/spec/modules/slimcutBidAdapter_spec.js | 200 --- test/spec/modules/smaatoBidAdapter_spec.js | 61 - test/spec/modules/smartxBidAdapter_spec.js | 70 +- test/spec/modules/smartyadsBidAdapter_spec.js | 25 +- test/spec/modules/sonobiBidAdapter_spec.js | 36 +- test/spec/modules/sortableBidAdapter_spec.js | 11 - test/spec/modules/spotxBidAdapter_spec.js | 36 - test/spec/modules/sspBCBidAdapter_spec.js | 302 +--- test/spec/modules/sublimeBidAdapter_spec.js | 285 +--- .../modules/synacormediaBidAdapter_spec.js | 70 - test/spec/modules/talkadsBidAdapter_spec.js | 231 --- test/spec/modules/tappxBidAdapter_spec.js | 98 +- .../modules/targetVideoBidAdapter_spec.js | 96 -- test/spec/modules/teadsBidAdapter_spec.js | 87 -- test/spec/modules/timeoutRtdProvider_spec.js | 339 ---- .../spec/modules/tripleliftBidAdapter_spec.js | 130 -- test/spec/modules/trustxBidAdapter_spec.js | 549 +++---- test/spec/modules/undertoneBidAdapter_spec.js | 52 - test/spec/modules/unicornBidAdapter_spec.js | 8 +- test/spec/modules/userId_spec.js | 138 +- test/spec/modules/validationFpdModule_spec.js | 82 - test/spec/modules/ventesBidAdapter_spec.js | 845 ---------- test/spec/modules/videobyteBidAdapter_spec.js | 4 +- test/spec/modules/vidoomyBidAdapter_spec.js | 45 +- test/spec/modules/visxBidAdapter_spec.js | 631 ++------ test/spec/modules/vrtcalBidAdapter_spec.js | 14 +- test/spec/modules/weboramaRtdProvider_spec.js | 482 ------ test/spec/modules/welectBidAdapter_spec.js | 211 --- test/spec/modules/yahoosspBidAdapter_spec.js | 1359 ---------------- test/spec/modules/yieldlabBidAdapter_spec.js | 147 +- test/spec/modules/yieldmoBidAdapter_spec.js | 70 +- .../yieldmoSyntheticInventoryModule_spec.js | 89 -- test/spec/modules/yieldoneBidAdapter_spec.js | 352 +---- .../zeta_global_sspAnalyticsAdapter_spec.js | 427 ----- .../modules/zeta_global_sspBidAdapter_spec.js | 78 +- test/spec/unit/core/adapterManager_spec.js | 62 +- test/spec/unit/core/bidderFactory_spec.js | 86 +- test/spec/unit/core/targeting_spec.js | 124 +- test/spec/unit/pbjs_api_spec.js | 47 +- test/spec/unit/secureCreatives_spec.js | 79 +- test/spec/userSync_spec.js | 32 +- test/spec/utils_spec.js | 38 - test/test_deps.js | 3 - test/test_index.js | 4 +- wdio.conf.js | 2 +- 636 files changed, 10557 insertions(+), 54872 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/devcontainer.json delete mode 100644 .devcontainer/postCreate.sh delete mode 100644 integrationExamples/gpt/afpExample.html delete mode 100644 integrationExamples/gpt/afpGamExample.html delete mode 100644 integrationExamples/gpt/akamaidap_segments_example.html delete mode 100644 integrationExamples/gpt/imRtdProvider_example.html delete mode 100644 integrationExamples/gpt/weboramaRtdProvider_example.html delete mode 100755 integrationExamples/noadserver/basic_noadserver.html delete mode 100644 modules/adhashBidAdapter.js delete mode 100644 modules/adlivetechBidAdapter.md delete mode 100644 modules/adlooxRtdProvider.js delete mode 100644 modules/adlooxRtdProvider.md delete mode 100644 modules/admanBidAdapter.js delete mode 100644 modules/adpartnerBidAdapter.js delete mode 100644 modules/adplusBidAdapter.js delete mode 100644 modules/adplusBidAdapter.md delete mode 100644 modules/adqueryBidAdapter.js delete mode 100644 modules/adqueryBidAdapter.md delete mode 100644 modules/adqueryIdSystem.js delete mode 100644 modules/adqueryIdSystem.md delete mode 100755 modules/advangelistsBidAdapter.js delete mode 100644 modules/afpBidAdapter.js delete mode 100644 modules/afpBidAdapter.md delete mode 100644 modules/akamaiDapRtdProvider.js delete mode 100644 modules/akamaiDapRtdProvider.md delete mode 100644 modules/bliinkBidAdapter.js delete mode 100644 modules/bliinkBidAdapter.md delete mode 100644 modules/byDataAnalyticsAdapter.js delete mode 100644 modules/byDataAnalyticsAdapter.md delete mode 100644 modules/cleanioRtdProvider.js delete mode 100644 modules/cleanioRtdProvider.md delete mode 100644 modules/codefuelBidAdapter.js delete mode 100644 modules/codefuelBidAdapter.md delete mode 100644 modules/compassBidAdapter.js delete mode 100644 modules/compassBidAdapter.md delete mode 100644 modules/connectIdSystem.js delete mode 100644 modules/connectIdSystem.md delete mode 100644 modules/cwireBidAdapter.js delete mode 100644 modules/cwireBidAdapter.md delete mode 100644 modules/dailyhuntBidAdapter.js delete mode 100644 modules/dchain.js delete mode 100644 modules/dchain.md delete mode 100644 modules/deltaprojectsBidAdapter.js delete mode 100644 modules/deltaprojectsBidAdapter.md delete mode 100644 modules/engageyaBidAdapter.js delete mode 100644 modules/fluctBidAdapter.js delete mode 100644 modules/futureads.md delete mode 100644 modules/goldbachBidAdapter.js delete mode 100644 modules/goldbachBidAdapter.md delete mode 100644 modules/imRtdProvider.js delete mode 100644 modules/imRtdProvider.md delete mode 100644 modules/insticatorBidAdapter.js delete mode 100644 modules/insticatorBidAdapter.md delete mode 100644 modules/intersectionRtdProvider.js delete mode 100644 modules/ipromBidAdapter.js delete mode 100644 modules/iqzoneBidAdapter.js delete mode 100644 modules/iqzoneBidAdapter.md delete mode 100644 modules/loglyliftBidAdapter.js delete mode 100644 modules/loglyliftBidAdapter.md delete mode 100755 modules/luponmediaBidAdapter.js delete mode 100644 modules/mgidBidAdapter.js delete mode 100644 modules/missenaBidAdapter.js delete mode 100644 modules/mytargetBidAdapter.js delete mode 100644 modules/naveggIdSystem.js delete mode 100644 modules/naveggIdSystem.md delete mode 100644 modules/nextrollBidAdapter.js delete mode 100644 modules/otmBidAdapter.js delete mode 100644 modules/playwireBidAdapter.md delete mode 100644 modules/publinkIdSystem.js delete mode 100644 modules/publinkIdSystem.md delete mode 100644 modules/saambaaBidAdapter.js delete mode 100755 modules/seedingAllianceBidAdapter.js delete mode 100644 modules/slimcutBidAdapter.js delete mode 100644 modules/talkadsBidAdapter.js delete mode 100644 modules/talkadsBidAdapter.md delete mode 100644 modules/targetVideoBidAdapter.js delete mode 100644 modules/targetVideoBidAdapter.md delete mode 100644 modules/timeoutRtdProvider.js delete mode 100644 modules/timeoutRtdProvider.md create mode 100644 modules/turktelekomBidAdapter.md delete mode 100644 modules/ventes.md delete mode 100644 modules/ventesBidAdapter.js delete mode 100644 modules/ventesBidAdapter.md create mode 100644 modules/weboramaBidAdapter.md delete mode 100644 modules/weboramaRtdProvider.js delete mode 100644 modules/weboramaRtdProvider.md delete mode 100644 modules/welectBidAdapter.js delete mode 100644 modules/yahoosspBidAdapter.js delete mode 100644 modules/yahoosspBidAdapter.md delete mode 100644 modules/yieldmoSyntheticInventoryModule.js delete mode 100644 modules/yieldmoSyntheticInventoryModule.md delete mode 100644 modules/zeta_global_sspAnalyticsAdapter.js delete mode 100644 modules/zeta_global_sspAnalyticsAdapter.md delete mode 100644 test/spec/modules/adhashBidAdapter_spec.js delete mode 100644 test/spec/modules/adlooxRtdProvider_spec.js delete mode 100644 test/spec/modules/admanBidAdapter_spec.js delete mode 100644 test/spec/modules/adpartnerBidAdapter_spec.js delete mode 100644 test/spec/modules/adplusBidAdapter_spec.js delete mode 100644 test/spec/modules/adqueryBidAdapter_spec.js delete mode 100644 test/spec/modules/adqueryIdSystem_spec.js delete mode 100755 test/spec/modules/advangelistsBidAdapter_spec.js delete mode 100644 test/spec/modules/afpBidAdapter_spec.js delete mode 100644 test/spec/modules/akamaiDapRtdProvider_spec.js delete mode 100644 test/spec/modules/bliinkBidAdapter_spec.js delete mode 100644 test/spec/modules/byDataAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/cleanioRtdProvider_spec.js delete mode 100644 test/spec/modules/codefuelBidAdapter_spec.js delete mode 100644 test/spec/modules/compassBidAdapter_spec.js delete mode 100644 test/spec/modules/connectIdSystem_spec.js delete mode 100644 test/spec/modules/cwireBidAdapter_spec.js delete mode 100644 test/spec/modules/dailyhuntBidAdapter_spec.js delete mode 100644 test/spec/modules/dchain_spec.js delete mode 100644 test/spec/modules/deltaprojectsBidAdapter_spec.js delete mode 100644 test/spec/modules/engageyaBidAdapter_spec.js delete mode 100644 test/spec/modules/fluctBidAdapter_spec.js delete mode 100644 test/spec/modules/goldbachBidAdapter_spec.js delete mode 100644 test/spec/modules/imRtdProvider_spec.js delete mode 100644 test/spec/modules/insticatorBidAdapter_spec.js delete mode 100644 test/spec/modules/intersectionRtdProvider_spec.js delete mode 100644 test/spec/modules/ipromBidAdapter_spec.js delete mode 100644 test/spec/modules/iqzoneBidAdapter_spec.js delete mode 100644 test/spec/modules/loglyliftBidAdapter_spec.js delete mode 100755 test/spec/modules/luponmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/merkleIdSystem_spec.js delete mode 100644 test/spec/modules/mgidBidAdapter_spec.js delete mode 100644 test/spec/modules/missenaBidAdapter_spec.js delete mode 100644 test/spec/modules/mytargetBidAdapter_spec.js delete mode 100644 test/spec/modules/naveggIdSystem_spec.js delete mode 100644 test/spec/modules/nextrollBidAdapter_spec.js delete mode 100644 test/spec/modules/otmBidAdapter_spec.js delete mode 100644 test/spec/modules/publinkIdSystem_spec.js delete mode 100755 test/spec/modules/seedingAllianceAdapter_spec.js delete mode 100644 test/spec/modules/slimcutBidAdapter_spec.js delete mode 100644 test/spec/modules/talkadsBidAdapter_spec.js delete mode 100644 test/spec/modules/targetVideoBidAdapter_spec.js delete mode 100644 test/spec/modules/timeoutRtdProvider_spec.js delete mode 100644 test/spec/modules/ventesBidAdapter_spec.js delete mode 100644 test/spec/modules/weboramaRtdProvider_spec.js delete mode 100644 test/spec/modules/welectBidAdapter_spec.js delete mode 100644 test/spec/modules/yahoosspBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldmoSyntheticInventoryModule_spec.js delete mode 100644 test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js delete mode 100644 test/test_deps.js diff --git a/.babelrc.js b/.babelrc.js index 43303f59a8b..74d26caf0fd 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -14,7 +14,16 @@ module.exports = { [ useLocal('@babel/preset-env'), { - "useBuiltIns": "entry" + "targets": { + "browsers": [ + "chrome >= 75", + "safari >=10", + "edge >= 70", + "ff >= 70", + "ie >= 11", + "ios >= 11" + ] + } } ] ], diff --git a/.circleci/config.yml b/.circleci/config.yml index 404026d9446..ea5fb916a91 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -52,7 +52,7 @@ aliases: - &unit_test_steps - checkout - restore_cache: *restore_dep_cache - - run: npm ci + - run: npm install - save_cache: *save_dep_cache - run: *install - run: *setup_browserstack diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index cfb29ebdfa9..00000000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,11 +0,0 @@ -ARG VARIANT="12" -FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT} - -# [Optional] Uncomment this section to install additional OS packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends - -RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - -RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list -RUN apt update -RUN apt install -y google-chrome-stable xvfb diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index 0176b8317b3..00000000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,27 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/main/containers/javascript-node -{ - "name": "Ubuntu", - - "build": { - "dockerfile": "Dockerfile", - "args": { "VARIANT": "12" } - }, - - "postCreateCommand": "bash .devcontainer/postCreate.sh", - - // Set *default* container specific settings.json values on container create. - "settings": {}, - - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "nickdodd79.gulptasks" - ], - - // 9999 is web server, 9876 is karma - "forwardPorts": [9876, 9999], - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "node" -} diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh deleted file mode 100644 index 7e14a2d200d..00000000000 --- a/.devcontainer/postCreate.sh +++ /dev/null @@ -1,6 +0,0 @@ -echo "Post Create Starting" - -nvm install -nvm use -npm install gulp-cli -g -npm ci diff --git a/README.md b/README.md index bc0e64afa06..a220dd69f66 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://circleci.com/gh/prebid/Prebid.js.svg?style=svg)](https://circleci.com/gh/prebid/Prebid.js) [![Percentage of issues still open](http://isitmaintained.com/badge/open/prebid/Prebid.js.svg)](http://isitmaintained.com/project/prebid/Prebid.js "Percentage of issues still open") +[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/prebid/Prebid.js.svg)](http://isitmaintained.com/project/prebid/Prebid.js "Average time to resolve an issue") [![Code Climate](https://codeclimate.com/github/prebid/Prebid.js/badges/gpa.svg)](https://codeclimate.com/github/prebid/Prebid.js) [![Coverage Status](https://coveralls.io/repos/github/prebid/Prebid.js/badge.svg)](https://coveralls.io/github/prebid/Prebid.js) [![devDependencies Status](https://david-dm.org/prebid/Prebid.js/dev-status.svg)](https://david-dm.org/prebid/Prebid.js?type=dev) @@ -59,8 +60,6 @@ module.exports = { loader: 'babel-loader', // presets and plugins for Prebid.js must be manually specified separate from your other babel rule. // this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+) - // as of Prebid 6, babelrc.js only targets modern browsers. One can change the targets and build for - // older browsers if they prefer, but integration tests on ie11 were removed in Prebid.js 6.0 options: require('prebid.js/.babelrc.js') } } @@ -153,7 +152,7 @@ Building with just these adapters will result in a smaller bundle which should a **Build standalone prebid.js** -- Clone the repo, run `npm ci` +- Clone the repo, run `npm install` - Then run the build: $ gulp build --modules=openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter @@ -274,7 +273,7 @@ As you make code changes, the bundles will be rebuilt and the page reloaded auto ## Contribute -Many SSPs, bidders, and publishers have contributed to this project. [Hundreds of bidders](https://github.com/prebid/Prebid.js/tree/master/modules) are supported by Prebid.js. +Many SSPs, bidders, and publishers have contributed to this project. [Hundreds of bidders](https://github.com/prebid/Prebid.js/tree/master/src/adapters) are supported by Prebid.js. For guidelines, see [Contributing](./CONTRIBUTING.md). @@ -316,7 +315,7 @@ For instructions on writing tests for Prebid.js, see [Testing Prebid.js](http:// ### Supported Browsers -Prebid.js is supported on IE11 and modern browsers until 5.x. 6.x+ transpiles to target >0.25%; not Opera Mini; not IE11. +Prebid.js is supported on IE11 and modern browsers. ### Governance Review our governance model [here](https://github.com/prebid/Prebid.js/tree/master/governance.md). diff --git a/allowedModules.js b/allowedModules.js index 81920cdc15f..2d23b35c501 100644 --- a/allowedModules.js +++ b/allowedModules.js @@ -5,8 +5,7 @@ const sharedWhiteList = [ 'core-js-pure/features/set', // ie11 supports Set but not Set#values 'core-js-pure/features/string/includes', // no ie11 'core-js-pure/features/number/is-integer', // no ie11, - 'core-js-pure/features/array/from', // no ie11 - 'core-js-pure/web/url-search-params' // no ie11 + 'core-js-pure/features/array/from' // no ie11 ]; module.exports = { diff --git a/browsers.json b/browsers.json index bd6bd5772d6..4f2ea456f68 100644 --- a/browsers.json +++ b/browsers.json @@ -1,51 +1,74 @@ { - "bs_edge_latest_windows_10": { + "bs_edge_17_windows_10": { "base": "BrowserStack", "os_version": "10", "browser": "edge", - "browser_version": "latest", + "browser_version": "17.0", "device": null, "os": "Windows" }, - "bs_chrome_latest_windows_10": { + "bs_edge_90_windows_10": { + "base": "BrowserStack", + "os_version": "10", + "browser": "edge", + "browser_version": "90.0", + "device": null, + "os": "Windows" + }, + "bs_ie_11_windows_10": { + "base": "BrowserStack", + "os_version": "10", + "browser": "ie", + "browser_version": "11.0", + "device": null, + "os": "Windows" + }, + "bs_chrome_90_windows_10": { "base": "BrowserStack", "os_version": "10", "browser": "chrome", - "browser_version": "latest", + "browser_version": "90.0", "device": null, "os": "Windows" }, - "bs_chrome_87_windows_10": { + "bs_chrome_79_windows_10": { "base": "BrowserStack", "os_version": "10", "browser": "chrome", - "browser_version": "87.0", + "browser_version": "79.0", + "device": null, + "os": "Windows" + }, + "bs_firefox_88_windows_10": { + "base": "BrowserStack", + "os_version": "10", + "browser": "firefox", + "browser_version": "88.0", "device": null, "os": "Windows" }, - "bs_firefox_latest_windows_10": { + "bs_firefox_72_windows_10": { "base": "BrowserStack", "os_version": "10", "browser": "firefox", - "browser_version": "latest", + "browser_version": "72.0", "device": null, "os": "Windows" }, - "bs_safari_latest_mac_bigsur": { + "bs_safari_14_mac_bigsur": { "base": "BrowserStack", "os_version": "Big Sur", "browser": "safari", - "browser_version": "latest", + "browser_version": "14.0", "device": null, "os": "OS X" }, - "bs_safari_15_catalina": { + "bs_safari_12_mac_mojave": { "base": "BrowserStack", - "os_version": "Catalina", + "os_version": "Mojave", "browser": "safari", - "browser_version": "13.1", + "browser_version": "12.0", "device": null, "os": "OS X" } - } diff --git a/gulpfile.js b/gulpfile.js index 6ecfee1b672..8609177a8b9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -76,7 +76,6 @@ function lint(done) { 'modules/**/*.js', 'test/**/*.js', 'plugins/**/*.js', - '!plugins/**/node_modules/**', './*.js' ], { base: './' }) .pipe(gulpif(argv.nolintfix, eslint(), eslint({ fix: true }))) @@ -115,6 +114,38 @@ function viewReview(done) { viewReview.displayName = 'view-review'; +// Watch Task with Live Reload +function watch(done) { + var mainWatcher = gulp.watch([ + 'src/**/*.js', + 'modules/**/*.js', + 'test/spec/**/*.js', + '!test/spec/loaders/**/*.js' + ]); + var loaderWatcher = gulp.watch([ + 'loaders/**/*.js', + 'test/spec/loaders/**/*.js' + ]); + + connect.server({ + https: argv.https, + port: port, + host: FAKE_SERVER_HOST, + root: './', + livereload: true + }); + + mainWatcher.on('all', gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test))); + loaderWatcher.on('all', gulp.series(lint)); + done(); +}; + +function makeModuleList(modules) { + return modules.map(module => { + return '"' + module + '"' + }); +} + function makeDevpackPkg() { var cloned = _.cloneDeep(webpackConfig); cloned.devtool = 'source-map'; @@ -126,6 +157,7 @@ function makeDevpackPkg() { return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js')) .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) + .pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules))) .pipe(gulp.dest('build/dev')) .pipe(connect.reload()); } @@ -143,6 +175,7 @@ function makeWebpackPkg() { .pipe(helpers.nameModules(externalModules)) .pipe(webpackStream(cloned, webpack)) .pipe(terser()) + .pipe(replace(/('|")v\$prebid\.modulesList\$('|")/g, makeModuleList(externalModules))) .pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid }))) .pipe(gulp.dest('build/dist')); } @@ -221,68 +254,60 @@ function bundle(dev, moduleArr) { // If --browsers is given, browsers can be chosen explicitly. e.g. --browsers=chrome,firefox,ie9 // If --notest is given, it will immediately skip the test task (useful for developing changes with `gulp serve --notest`) -function testTaskMaker(options = {}) { - ['watch', 'e2e', 'file', 'browserstack', 'notest'].forEach(opt => { - options[opt] = options[opt] || argv[opt]; - }) +function test(done) { + if (argv.notest) { + done(); + } else if (argv.e2e) { + let wdioCmd = path.join(__dirname, 'node_modules/.bin/wdio'); + let wdioConf = path.join(__dirname, 'wdio.conf.js'); + let wdioOpts; + + if (argv.file) { + wdioOpts = [ + wdioConf, + `--spec`, + `${argv.file}` + ] + } else { + wdioOpts = [ + wdioConf + ]; + } - return function test(done) { - if (options.notest) { - done(); - } else if (options.e2e) { - let wdioCmd = path.join(__dirname, 'node_modules/.bin/wdio'); - let wdioConf = path.join(__dirname, 'wdio.conf.js'); - let wdioOpts; - - if (options.file) { - wdioOpts = [ - wdioConf, - `--spec`, - `${options.file}` - ] - } else { - wdioOpts = [ - wdioConf - ]; - } + // run fake-server + const fakeServer = spawn('node', ['./test/fake-server/index.js', `--port=${FAKE_SERVER_PORT}`]); + fakeServer.stdout.on('data', (data) => { + console.log(`stdout: ${data}`); + }); + fakeServer.stderr.on('data', (data) => { + console.log(`stderr: ${data}`); + }); - // run fake-server - const fakeServer = spawn('node', ['./test/fake-server/index.js', `--port=${FAKE_SERVER_PORT}`]); - fakeServer.stdout.on('data', (data) => { - console.log(`stdout: ${data}`); - }); - fakeServer.stderr.on('data', (data) => { - console.log(`stderr: ${data}`); + execa(wdioCmd, wdioOpts, { stdio: 'inherit' }) + .then(stdout => { + // kill fake server + fakeServer.kill('SIGINT'); + done(); + process.exit(0); + }) + .catch(err => { + // kill fake server + fakeServer.kill('SIGINT'); + done(new Error(`Tests failed with error: ${err}`)); + process.exit(1); }); + } else { + var karmaConf = karmaConfMaker(false, argv.browserstack, argv.watch, argv.file); - execa(wdioCmd, wdioOpts, { stdio: 'inherit' }) - .then(stdout => { - // kill fake server - fakeServer.kill('SIGINT'); - done(); - process.exit(0); - }) - .catch(err => { - // kill fake server - fakeServer.kill('SIGINT'); - done(new Error(`Tests failed with error: ${err}`)); - process.exit(1); - }); - } else { - var karmaConf = karmaConfMaker(false, options.browserstack, options.watch, options.file); - - var browserOverride = helpers.parseBrowserArgs(argv); - if (browserOverride.length > 0) { - karmaConf.browsers = browserOverride; - } - - new KarmaServer(karmaConf, newKarmaCallback(done)).start(); + var browserOverride = helpers.parseBrowserArgs(argv); + if (browserOverride.length > 0) { + karmaConf.browsers = browserOverride; } + + new KarmaServer(karmaConf, newKarmaCallback(done)).start(); } } -const test = testTaskMaker(); - function newKarmaCallback(done) { return function (exitCode) { if (exitCode) { @@ -359,35 +384,6 @@ function startFakeServer() { }); } -// Watch Task with Live Reload -function watchTaskMaker(options = {}) { - if (options.livereload == null) { - options.livereload = true; - } - options.alsoWatch = options.alsoWatch || []; - - return function watch(done) { - var mainWatcher = gulp.watch([ - 'src/**/*.js', - 'modules/**/*.js', - ].concat(options.alsoWatch)); - - connect.server({ - https: argv.https, - port: port, - host: FAKE_SERVER_HOST, - root: './', - livereload: options.livereload - }); - - mainWatcher.on('all', options.task()); - done(); - } -} - -const watch = watchTaskMaker({alsoWatch: ['test/**/*.js'], task: () => gulp.series(clean, gulp.parallel(lint, 'build-bundle-dev', test))}); -const watchFast = watchTaskMaker({livereload: false, task: () => gulp.series('build-bundle-dev')}); - // support tasks gulp.task(lint); gulp.task(watch); @@ -400,8 +396,7 @@ gulp.task('build-bundle-dev', gulp.series(makeDevpackPkg, gulpBundle.bind(null, gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, gulpBundle.bind(null, false))); // public tasks (dependencies are needed for each task since they can be ran on their own) -gulp.task('test-only', test); -gulp.task('test', gulp.series(clean, lint, 'test-only')); +gulp.task('test', gulp.series(clean, lint, test)); gulp.task('test-coverage', gulp.series(clean, testCoverage)); gulp.task(viewCoverage); @@ -412,8 +407,7 @@ gulp.task('build', gulp.series(clean, 'build-bundle-prod')); gulp.task('build-postbid', gulp.series(escapePostbidConfig, buildPostbid)); gulp.task('serve', gulp.series(clean, lint, gulp.parallel('build-bundle-dev', watch, test))); -gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast))); -gulp.task('serve-and-test', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast, testTaskMaker({watch: true})))); +gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', watch))); gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer)); gulp.task('default', gulp.series(clean, makeWebpackPkg)); diff --git a/integrationExamples/gpt/adloox.html b/integrationExamples/gpt/adloox.html index e8920cf2ee1..2a772bb7ce2 100644 --- a/integrationExamples/gpt/adloox.html +++ b/integrationExamples/gpt/adloox.html @@ -64,11 +64,9 @@ playerSize: [ 640, 480 ] } }, - ortb2Imp: { - ext: { - data: { - pbadslot: '/19968336/prebid_cache_video_adunit' - } + fpd: { + context: { + pbAdSlot: '/19968336/prebid_cache_video_adunit' } }, bids: [ @@ -108,8 +106,7 @@ pbjs.initAdserverSet = true; googletag.cmd.push(function() { - const adUnitCodes = adUnits.map(adUnit => adUnit.code); - pbjs.setTargetingForGPTAsync(adUnitCodes); + pbjs.setTargetingForGPTAsync && pbjs.setTargetingForGPTAsync(adUnits); googletag.pubads().refresh(); }); @@ -138,24 +135,12 @@ } // optionally wrap with googletag to have gpt-pre-auction - // automatically populate Prebid Ad Slot (pbadslot) + // automatically populate Prebid Ad Slot (pbAdSlot) // https://docs.prebid.org/dev-docs/modules/gpt-pre-auction.html - // alternatively remove wrapping and set AdUnit.ortb2Imp.ext.data.pbadslot + // alternatively remove wrapping and set AdUnit.fpd.context.pbAdSlot googletag.cmd.push(function() { pbjs.que.push(function() { pbjs.setConfig({ - realTimeData: { - auctionDelay: AUCTION_DELAY, - dataProviders: [ - { - name: 'adloox', - params: { // optional, defaults shown - thresholds: [ 50, 60, 70, 80, 90 ], - slotinpath: false - } - } - ] - }, instreamTracking: { enabled: true }, diff --git a/integrationExamples/gpt/afpExample.html b/integrationExamples/gpt/afpExample.html deleted file mode 100644 index a1e6e800d69..00000000000 --- a/integrationExamples/gpt/afpExample.html +++ /dev/null @@ -1,242 +0,0 @@ - - - - - Prebid.js Banner Example - - - - -

In-image

-
-
- -
- -
- -

In-image Max

-
-
- -
- -
- -

In-content Banner

-
-
- -
- -

In-content Stories

-
-
- -
- -

Action Scroller

-
-
- -
- -

Action Scroller Light

-
-
- -
- -

Just Banner

-
-
- -
- -

In-content Video

-
-
- -
- - - - - diff --git a/integrationExamples/gpt/afpGamExample.html b/integrationExamples/gpt/afpGamExample.html deleted file mode 100644 index 64cb169893c..00000000000 --- a/integrationExamples/gpt/afpGamExample.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - Prebid.js Banner Example - - - - - -

In-image

-
-
- -
-
- -
-
- -

In-content Video

-
-
-
- -
-
- -

Action Scroller

-
-
-
- -
-
- - diff --git a/integrationExamples/gpt/akamaidap_segments_example.html b/integrationExamples/gpt/akamaidap_segments_example.html deleted file mode 100644 index e85ac8e1337..00000000000 --- a/integrationExamples/gpt/akamaidap_segments_example.html +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - -

Prebid.js Test

-
Div-1
-
- -
-
Segments Sent to Bidding Adapter
-
- - diff --git a/integrationExamples/gpt/imRtdProvider_example.html b/integrationExamples/gpt/imRtdProvider_example.html deleted file mode 100644 index b98f053047b..00000000000 --- a/integrationExamples/gpt/imRtdProvider_example.html +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - -

IM RTD Prebid

- -
- -
- -Intimate Merger Universal Identifier: -
- -Intimate Merger Real-Time Data: -
- - diff --git a/integrationExamples/gpt/userId_example.html b/integrationExamples/gpt/userId_example.html index 653dd9c59f3..dfea06d17d0 100644 --- a/integrationExamples/gpt/userId_example.html +++ b/integrationExamples/gpt/userId_example.html @@ -154,7 +154,6 @@ { "name": "merkleId", "params": { - "endpoint": "https://test_endpoint/", "vendor": "sdfg", "sv_cid": "dfg", "sv_pubid": "xcv", diff --git a/integrationExamples/gpt/weboramaRtdProvider_example.html b/integrationExamples/gpt/weboramaRtdProvider_example.html deleted file mode 100644 index 66e4a57d2a6..00000000000 --- a/integrationExamples/gpt/weboramaRtdProvider_example.html +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - - - - - - - - -
-

-test webo ctx using prebid.js -

-
-

Basic Prebid.js Example

-
Div-1
-
- -
- - - diff --git a/integrationExamples/noadserver/basic_noadserver.html b/integrationExamples/noadserver/basic_noadserver.html deleted file mode 100755 index ebc0e842775..00000000000 --- a/integrationExamples/noadserver/basic_noadserver.html +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - -

Ad Serverless Test Page

- -
-
-
- - diff --git a/karma.conf.maker.js b/karma.conf.maker.js index be51947dae8..cf5999ba85e 100644 --- a/karma.conf.maker.js +++ b/karma.conf.maker.js @@ -111,7 +111,7 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) { var webpackConfig = newWebpackConfig(codeCoverage); var plugins = newPluginsArray(browserstack); - var files = file ? ['test/test_deps.js', file] : ['test/test_index.js']; + var files = file ? ['test/helpers/prebidGlobal.js', file] : ['test/test_index.js']; // This file opens the /debug.html tab automatically. // It has no real value unless you're running --watch, and intend to do some debugging in the browser. if (watchMode) { @@ -166,7 +166,7 @@ module.exports = function(codeCoverage, browserstack, watchMode, file) { browserNoActivityTimeout: 3e5, // default 10000 captureTimeout: 3e5, // default 60000, browserDisconnectTolerance: 3, - concurrency: 6, + concurrency: 5, plugins: plugins } diff --git a/modules/.submodules.json b/modules/.submodules.json index 2e77873dc78..1e52b02a358 100644 --- a/modules/.submodules.json +++ b/modules/.submodules.json @@ -1,42 +1,37 @@ { "userId": [ - "admixerIdSystem", - "adtelligentIdSystem", - "akamaiDAPIdSystem", - "amxIdSystem", - "britepoolIdSystem", - "connectIdSystem", - "criteoIdSystem", - "deepintentDpesIdSystem", - "dmdIdSystem", - "fabrickIdSystem", - "flocIdSystem", - "haloIdSystem", + "unifiedIdSystem", + "pubCommonIdSystem", "id5IdSystem", - "identityLinkIdSystem", - "idxIdSystem", - "imuIdSystem", - "intentIqIdSystem", - "kinessoIdSystem", + "parrableIdSystem", + "britepoolIdSystem", "liveIntentIdSystem", - "lotamePanoramaIdSystem", + "lotamePanoramaId", "merkleIdSystem", - "mwOpenLinkIdSystem", - "naveggIdSystem", + "criteoIdSystem", "netIdSystem", + "identityLinkIdSystem", + "sharedIdSystem", + "intentIqIdSystem", + "zeotapIdPlusIdSystem", + "haloIdSystem", + "quantcastIdSystem", + "deepintentDpesIdSystem", "nextrollIdSystem", - "novatiqIdSystem", - "parrableIdSystem", + "idxIdSystem", + "fabrickIdSystem", + "verizonMediaIdSystem", "pubProvidedIdSystem", - "publinkIdSystem", - "quantcastIdSystem", - "sharedIdSystem", + "mwOpenLinkIdSystem", "tapadIdSystem", + "novatiqIdSystem", "uid2IdSystem", - "unifiedIdSystem", - "verizonMediaIdSystem", - "zeotapIdPlusIdSystem", - "adqueryIdSystem" + "admixerIdSystem", + "dmdIdSystem", + "akamaiDAPId", + "flocIdSystem", + "amxIdSystem", + "imuIdSystem" ], "adpod": [ "freeWheelAdserverVideo", @@ -53,9 +48,7 @@ "optimeraRtdProvider", "permutiveRtdProvider", "reconciliationRtdProvider", - "sirdataRtdProvider", - "timeoutRtdProvider", - "weboramaRtdProvider" + "sirdataRtdProvider" ], "fpdModule": [ "enrichmentFpdModule", diff --git a/modules/33acrossBidAdapter.js b/modules/33acrossBidAdapter.js index af67bb2bf48..4b8028d97fd 100644 --- a/modules/33acrossBidAdapter.js +++ b/modules/33acrossBidAdapter.js @@ -1,20 +1,8 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; -import { - deepAccess, - uniques, - isArray, - getWindowTop, - isGptPubadsDefined, - isSlotMatchingAdUnitCode, - logInfo, - logWarn, - getWindowSelf, - mergeDeep, -} from '../src/utils.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; - -// **************************** UTILS *************************** // +import * as utils from '../src/utils.js'; +import {BANNER, VIDEO} from '../src/mediaTypes.js'; + const BIDDER_CODE = '33across'; const END_POINT = 'https://ssc.33across.com/api/v1/hb'; const SYNC_ENDPOINT = 'https://ssc-cms.33across.com/ps/?m=xch&rt=html&ru=deb'; @@ -51,14 +39,6 @@ const adapterState = { const NON_MEASURABLE = 'nm'; -function getTTXConfig() { - const ttxSettings = Object.assign({}, - config.getConfig('ttxSettings') - ); - - return ttxSettings; -} - // **************************** VALIDATION *************************** // function isBidRequestValid(bid) { return ( @@ -81,7 +61,7 @@ function _validateBasic(bid) { } function _validateGUID(bid) { - const siteID = deepAccess(bid, 'params.siteId', '') || ''; + const siteID = utils.deepAccess(bid, 'params.siteId', '') || ''; if (siteID.trim().match(GUID_PATTERN) === null) { return false; } @@ -90,8 +70,7 @@ function _validateGUID(bid) { } function _validateBanner(bid) { - const banner = deepAccess(bid, 'mediaTypes.banner'); - + const banner = utils.deepAccess(bid, 'mediaTypes.banner'); // If there's no banner no need to validate against banner rules if (banner === undefined) { return true; @@ -105,8 +84,8 @@ function _validateBanner(bid) { } function _validateVideo(bid) { - const videoAdUnit = deepAccess(bid, 'mediaTypes.video'); - const videoBidderParams = deepAccess(bid, 'params.video', {}); + const videoAdUnit = utils.deepAccess(bid, 'mediaTypes.video'); + const videoBidderParams = utils.deepAccess(bid, 'params.video', {}); // If there's no video no need to validate against video rules if (videoAdUnit === undefined) { @@ -158,125 +137,91 @@ function _validateVideo(bid) { // NOTE: With regards to gdrp consent data, the server will independently // infer the gdpr applicability therefore, setting the default value to false function buildRequests(bidRequests, bidderRequest) { - const { - ttxSettings, - gdprConsent, - uspConsent, - pageUrl - } = _buildRequestParams(bidRequests, bidderRequest); - - const groupedRequests = _buildRequestGroups(ttxSettings, bidRequests); - - const serverRequests = []; - - for (const key in groupedRequests) { - serverRequests.push( - _createServerRequest({ - bidRequests: groupedRequests[key], - gdprConsent, - uspConsent, - pageUrl, - ttxSettings - }) - ) - } - - return serverRequests; -} - -function _buildRequestParams(bidRequests, bidderRequest) { - const ttxSettings = getTTXConfig(); - const gdprConsent = Object.assign({ consentString: undefined, gdprApplies: false }, bidderRequest && bidderRequest.gdprConsent); const uspConsent = bidderRequest && bidderRequest.uspConsent; - const pageUrl = (bidderRequest && bidderRequest.refererInfo) ? (bidderRequest.refererInfo.referer) : (undefined); - adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(uniques); - - return { - ttxSettings, - gdprConsent, - uspConsent, - pageUrl - } -} - -function _buildRequestGroups(ttxSettings, bidRequests) { - const bidRequestsComplete = bidRequests.map(_inferProduct); - const enableSRAMode = ttxSettings && ttxSettings.enableSRAMode; - const keyFunc = (enableSRAMode === true) ? _getSRAKey : _getMRAKey; + adapterState.uniqueSiteIds = bidRequests.map(req => req.params.siteId).filter(utils.uniques); - return _groupBidRequests(bidRequestsComplete, keyFunc); -} - -function _groupBidRequests(bidRequests, keyFunc) { - const groupedRequests = {}; - - bidRequests.forEach((req) => { - const key = keyFunc(req); - - groupedRequests[key] = groupedRequests[key] || []; - groupedRequests[key].push(req); - }); - - return groupedRequests; -} - -function _getSRAKey(bidRequest) { - return `${bidRequest.params.siteId}:${bidRequest.params.productId}`; -} - -function _getMRAKey(bidRequest) { - return `${bidRequest.bidId}`; + return bidRequests.map(bidRequest => _createServerRequest( + { + bidRequest, + gdprConsent, + uspConsent, + pageUrl + }) + ); } // Infer the necessary data from valid bid for a minimal ttxRequest and create HTTP request -function _createServerRequest({ bidRequests, gdprConsent = {}, uspConsent, pageUrl, ttxSettings }) { +// NOTE: At this point, TTX only accepts request for a single impression +function _createServerRequest({bidRequest, gdprConsent = {}, uspConsent, pageUrl}) { const ttxRequest = {}; - const { siteId, test } = bidRequests[0].params; + const params = bidRequest.params; /* * Infer data for the request payload */ - ttxRequest.imp = []; + ttxRequest.imp = [{}]; - bidRequests.forEach((req) => { - ttxRequest.imp.push(_buildImpORTB(req)); - }); + if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { + ttxRequest.imp[0].banner = { + ..._buildBannerORTB(bidRequest) + } + } + + if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { + ttxRequest.imp[0].video = _buildVideoORTB(bidRequest); + } + + ttxRequest.imp[0].ext = { + ttx: { + prod: _getProduct(bidRequest) + } + }; - ttxRequest.site = { id: siteId }; + ttxRequest.site = { id: params.siteId }; if (pageUrl) { ttxRequest.site.page = pageUrl; } - ttxRequest.id = bidRequests[0].auctionId; + // Go ahead send the bidId in request to 33exchange so it's kept track of in the bid response and + // therefore in ad targetting process + ttxRequest.id = bidRequest.bidId; if (gdprConsent.consentString) { - ttxRequest.user = setExtensions(ttxRequest.user, { - 'consent': gdprConsent.consentString - }); + ttxRequest.user = setExtension( + ttxRequest.user, + 'consent', + gdprConsent.consentString + ) } - if (Array.isArray(bidRequests[0].userIdAsEids) && bidRequests[0].userIdAsEids.length > 0) { - ttxRequest.user = setExtensions(ttxRequest.user, { - 'eids': bidRequests[0].userIdAsEids - }); + if (Array.isArray(bidRequest.userIdAsEids) && bidRequest.userIdAsEids.length > 0) { + ttxRequest.user = setExtension( + ttxRequest.user, + 'eids', + bidRequest.userIdAsEids + ) } - ttxRequest.regs = setExtensions(ttxRequest.regs, { - 'gdpr': Number(gdprConsent.gdprApplies) - }); + ttxRequest.regs = setExtension( + ttxRequest.regs, + 'gdpr', + Number(gdprConsent.gdprApplies) + ); if (uspConsent) { - ttxRequest.regs = setExtensions(ttxRequest.regs, { - 'us_privacy': uspConsent - }); + ttxRequest.regs = setExtension( + ttxRequest.regs, + 'us_privacy', + uspConsent + ) } ttxRequest.ext = { @@ -289,14 +234,16 @@ function _createServerRequest({ bidRequests, gdprConsent = {}, uspConsent, pageU } }; - if (bidRequests[0].schain) { - ttxRequest.source = setExtensions(ttxRequest.source, { - 'schain': bidRequests[0].schain - }); + if (bidRequest.schain) { + ttxRequest.source = setExtension( + ttxRequest.source, + 'schain', + bidRequest.schain + ) } // Finally, set the openRTB 'test' param if this is to be a test bid - if (test === 1) { + if (params.test === 1) { ttxRequest.test = 1; } @@ -309,7 +256,8 @@ function _createServerRequest({ bidRequests, gdprConsent = {}, uspConsent, pageU }; // Allow the ability to configure the HB endpoint for testing purposes. - const url = (ttxSettings && ttxSettings.url) || `${END_POINT}?guid=${siteId}`; + const ttxSettings = config.getConfig('ttxSettings'); + const url = (ttxSettings && ttxSettings.url) || `${END_POINT}?guid=${params.siteId}`; // Return the server request return { @@ -321,39 +269,17 @@ function _createServerRequest({ bidRequests, gdprConsent = {}, uspConsent, pageU } // BUILD REQUESTS: SET EXTENSIONS -function setExtensions(obj = {}, extFields) { - return mergeDeep({}, obj, { - 'ext': extFields +function setExtension(obj = {}, key, value) { + return Object.assign({}, obj, { + ext: Object.assign({}, obj.ext, { + [key]: value + }) }); } -// BUILD REQUESTS: IMP -function _buildImpORTB(bidRequest) { - const imp = { - id: bidRequest.bidId, - ext: { - ttx: { - prod: deepAccess(bidRequest, 'params.productId') - } - } - }; - - if (deepAccess(bidRequest, 'mediaTypes.banner')) { - imp.banner = { - ..._buildBannerORTB(bidRequest) - } - } - - if (deepAccess(bidRequest, 'mediaTypes.video')) { - imp.video = _buildVideoORTB(bidRequest); - } - - return imp; -} - // BUILD REQUESTS: SIZE INFERENCE function _transformSizes(sizes) { - if (isArray(sizes) && sizes.length === 2 && !isArray(sizes[0])) { + if (utils.isArray(sizes) && sizes.length === 2 && !utils.isArray(sizes[0])) { return [ _getSize(sizes) ]; } @@ -368,14 +294,6 @@ function _getSize(size) { } // BUILD REQUESTS: PRODUCT INFERENCE -function _inferProduct(bidRequest) { - return mergeDeep({}, bidRequest, { - params: { - productId: _getProduct(bidRequest) - } - }); -} - function _getProduct(bidRequest) { const { params, mediaTypes } = bidRequest; @@ -390,7 +308,7 @@ function _getProduct(bidRequest) { // BUILD REQUESTS: BANNER function _buildBannerORTB(bidRequest) { - const bannerAdUnit = deepAccess(bidRequest, 'mediaTypes.banner', {}); + const bannerAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.banner', {}); const element = _getAdSlotHTMLElement(bidRequest.adUnitCode); const sizes = _transformSizes(bannerAdUnit.sizes); @@ -422,7 +340,7 @@ function _buildBannerORTB(bidRequest) { const minSize = _getMinSize(sizes); const viewabilityAmount = _isViewabilityMeasurable(element) - ? _getViewability(element, getWindowTop(), minSize) + ? _getViewability(element, utils.getWindowTop(), minSize) : NON_MEASURABLE; const ext = contributeViewability(viewabilityAmount); @@ -436,8 +354,8 @@ function _buildBannerORTB(bidRequest) { // BUILD REQUESTS: VIDEO // eslint-disable-next-line no-unused-vars function _buildVideoORTB(bidRequest) { - const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {}); - const videoBidderParams = deepAccess(bidRequest, 'params.video', {}); + const videoAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); + const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {}); const videoParams = { ...videoAdUnit, @@ -446,7 +364,7 @@ function _buildVideoORTB(bidRequest) { const video = {} - const { w, h } = _getSize(videoParams.playerSize[0]); + const {w, h} = _getSize(videoParams.playerSize[0]); video.w = w; video.h = h; @@ -467,11 +385,11 @@ function _buildVideoORTB(bidRequest) { if (product === PRODUCT.INSTREAM) { video.startdelay = video.startdelay || 0; video.placement = 1; - } + }; // bidfloors if (typeof bidRequest.getFloor === 'function') { - const bidfloors = _getBidFloors(bidRequest, { w: video.w, h: video.h }, VIDEO); + const bidfloors = _getBidFloors(bidRequest, {w: video.w, h: video.h}, VIDEO); if (bidfloors) { Object.assign(video, { @@ -483,7 +401,6 @@ function _buildVideoORTB(bidRequest) { }); } } - return video; } @@ -512,23 +429,23 @@ function _getViewability(element, topWin, { w, h } = {}) { } function _mapAdUnitPathToElementId(adUnitCode) { - if (isGptPubadsDefined()) { + if (utils.isGptPubadsDefined()) { // eslint-disable-next-line no-undef const adSlots = googletag.pubads().getSlots(); - const isMatchingAdSlot = isSlotMatchingAdUnitCode(adUnitCode); + const isMatchingAdSlot = utils.isSlotMatchingAdUnitCode(adUnitCode); for (let i = 0; i < adSlots.length; i++) { if (isMatchingAdSlot(adSlots[i])) { const id = adSlots[i].getSlotElementId(); - 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; } } } - logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); + utils.logWarn(`[33Across Adapter] Unable to locate element for ad unit code: '${adUnitCode}'`); return null; } @@ -629,68 +546,61 @@ function contributeViewability(viewabilityAmount) { function _isIframe() { try { - return getWindowSelf() !== getWindowTop(); + return utils.getWindowSelf() !== utils.getWindowTop(); } catch (e) { return true; } } // **************************** INTERPRET RESPONSE ******************************** // +// NOTE: At this point, the response from 33exchange will only ever contain one bid +// i.e. the highest bid function interpretResponse(serverResponse, bidRequest) { - const { seatbid, cur = 'USD' } = serverResponse.body; - - if (!isArray(seatbid)) { - return []; - } - - // Pick seats with valid bids and convert them into an Array of responses - // in format expected by Prebid Core - return seatbid - .filter((seat) => ( - isArray(seat.bid) && - seat.bid.length > 0 - )) - .reduce((acc, seat) => { - return acc.concat( - seat.bid.map((bid) => _createBidResponse(bid, cur)) - ); - }, []); + const bidResponses = []; + + // If there are bids, look at the first bid of the first seatbid (see NOTE above for assumption about ttx) + if (serverResponse.body.seatbid.length > 0 && serverResponse.body.seatbid[0].bid.length > 0) { + bidResponses.push(_createBidResponse(serverResponse.body)); + } + + return bidResponses; } -function _createBidResponse(bid, cur) { +// All this assumes that only one bid is ever returned by ttx +function _createBidResponse(response) { const isADomainPresent = - bid.adomain && bid.adomain.length; - const bidResponse = { - requestId: bid.impid, + response.seatbid[0].bid[0].adomain && response.seatbid[0].bid[0].adomain.length; + const bid = { + requestId: response.id, bidderCode: BIDDER_CODE, - cpm: bid.price, - width: bid.w, - height: bid.h, - ad: bid.adm, - ttl: bid.ttl || 60, - creativeId: bid.crid, - mediaType: deepAccess(bid, 'ext.ttx.mediaType', BANNER), - currency: cur, + cpm: response.seatbid[0].bid[0].price, + width: response.seatbid[0].bid[0].w, + height: response.seatbid[0].bid[0].h, + ad: response.seatbid[0].bid[0].adm, + ttl: response.seatbid[0].bid[0].ttl || 60, + creativeId: response.seatbid[0].bid[0].crid, + mediaType: utils.deepAccess(response.seatbid[0].bid[0], 'ext.ttx.mediaType', BANNER), + currency: response.cur, netRevenue: true } if (isADomainPresent) { - bidResponse.meta = { - advertiserDomains: bid.adomain + bid.meta = { + advertiserDomains: response.seatbid[0].bid[0].adomain }; } - if (bidResponse.mediaType === VIDEO) { - const vastType = deepAccess(bid, 'ext.ttx.vastType', 'xml'); + if (bid.mediaType === VIDEO) { + const vastType = utils.deepAccess(response.seatbid[0].bid[0], 'ext.ttx.vastType', 'xml'); if (vastType === 'xml') { - bidResponse.vastXml = bidResponse.ad; + bid.vastXml = bid.ad; } else { - bidResponse.vastUrl = bidResponse.ad; + bid.vastUrl = bid.ad; } } - return bidResponse; + return bid; } // **************************** USER SYNC *************************** // diff --git a/modules/a4gBidAdapter.js b/modules/a4gBidAdapter.js index 03f9d6fd726..01c59616dc0 100644 --- a/modules/a4gBidAdapter.js +++ b/modules/a4gBidAdapter.js @@ -1,5 +1,5 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { _each } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const A4G_BIDDER_CODE = 'a4g'; const A4G_CURRENCY = 'USD'; @@ -28,7 +28,7 @@ export const spec = { const sizeParams = []; const zoneIds = []; - _each(validBidRequests, function(bid) { + utils._each(validBidRequests, function(bid) { if (!deliveryUrl && typeof bid.params.deliveryUrl === 'string') { deliveryUrl = bid.params.deliveryUrl; } @@ -66,7 +66,7 @@ export const spec = { interpretResponse: function(serverResponses, request) { const bidResponses = []; - _each(serverResponses.body, function(response) { + utils._each(serverResponses.body, function(response) { if (response.cpm > 0) { const bidResponse = { requestId: response.id, diff --git a/modules/ablidaBidAdapter.js b/modules/ablidaBidAdapter.js index cb4f4ef2724..2400952367f 100644 --- a/modules/ablidaBidAdapter.js +++ b/modules/ablidaBidAdapter.js @@ -1,4 +1,4 @@ -import { triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; @@ -79,7 +79,7 @@ export const spec = { }, onBidWon: function (bid) { if (!bid['nurl']) { return; } - triggerPixel(bid['nurl']); + utils.triggerPixel(bid['nurl']); } }; diff --git a/modules/adWMGBidAdapter.js b/modules/adWMGBidAdapter.js index 7bf6c703a55..a3d78a69d91 100644 --- a/modules/adWMGBidAdapter.js +++ b/modules/adWMGBidAdapter.js @@ -1,6 +1,6 @@ 'use strict'; -import { tryAppendQueryString } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -128,11 +128,11 @@ export const spec = { }, getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { if (gdprConsent && SYNC_ENDPOINT.indexOf('gdpr') === -1) { - SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); } if (gdprConsent && typeof gdprConsent.consentString === 'string' && SYNC_ENDPOINT.indexOf('gdpr_consent') === -1) { - SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'gdpr_consent', gdprConsent.consentString); + SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'gdpr_consent', gdprConsent.consentString); } if (SYNC_ENDPOINT.slice(-1) === '&') { @@ -140,7 +140,7 @@ export const spec = { } /* if (uspConsent) { - SYNC_ENDPOINT = tryAppendQueryString(SYNC_ENDPOINT, 'us_privacy', uspConsent); + SYNC_ENDPOINT = utils.tryAppendQueryString(SYNC_ENDPOINT, 'us_privacy', uspConsent); } */ let syncs = []; if (syncOptions.iframeEnabled) { diff --git a/modules/adagioAnalyticsAdapter.js b/modules/adagioAnalyticsAdapter.js index f929f7e660b..fd7a742d9e7 100644 --- a/modules/adagioAnalyticsAdapter.js +++ b/modules/adagioAnalyticsAdapter.js @@ -5,7 +5,7 @@ import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; -import { getWindowTop } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const emptyUrl = ''; const analyticsType = 'endpoint'; @@ -13,12 +13,12 @@ const events = Object.keys(CONSTANTS.EVENTS).map(key => CONSTANTS.EVENTS[key]); const VERSION = '2.0.0'; const adagioEnqueue = function adagioEnqueue(action, data) { - getWindowTop().ADAGIO.queue.push({ action, data, ts: Date.now() }); + utils.getWindowTop().ADAGIO.queue.push({ action, data, ts: Date.now() }); } function canAccessTopWindow() { try { - if (getWindowTop().location.href) { + if (utils.getWindowTop().location.href) { return true; } } catch (error) { @@ -41,7 +41,7 @@ adagioAdapter.enableAnalytics = config => { return; } - const w = getWindowTop(); + const w = utils.getWindowTop(); w.ADAGIO = w.ADAGIO || {}; w.ADAGIO.queue = w.ADAGIO.queue || []; diff --git a/modules/adagioBidAdapter.js b/modules/adagioBidAdapter.js index b000772f214..ffa955290be 100644 --- a/modules/adagioBidAdapter.js +++ b/modules/adagioBidAdapter.js @@ -1,8 +1,5 @@ import find from 'core-js-pure/features/array/find.js'; -import { - isInteger, isArray, deepAccess, mergeDeep, logWarn, logInfo, logError, getWindowTop, getWindowSelf, generateUUID, _map, - getDNT, parseUrl, getUniqueIdentifierStr, isNumber, cleanObj, isFn, inIframe, deepClone, getGptSlotInfoForAdUnitCode -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { loadExternalScript } from '../src/adloader.js'; @@ -34,22 +31,22 @@ const DEFAULT_FLOOR = 0.1; // https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf export const ORTB_VIDEO_PARAMS = { 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), - 'minduration': (value) => isInteger(value), - 'maxduration': (value) => isInteger(value), + 'minduration': (value) => utils.isInteger(value), + 'maxduration': (value) => utils.isInteger(value), 'protocols': (value) => Array.isArray(value) && value.every(v => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].indexOf(v) !== -1), - 'w': (value) => isInteger(value), - 'h': (value) => isInteger(value), - 'startdelay': (value) => isInteger(value), + 'w': (value) => utils.isInteger(value), + 'h': (value) => utils.isInteger(value), + 'startdelay': (value) => utils.isInteger(value), 'placement': (value) => Array.isArray(value) && value.every(v => [1, 2, 3, 4, 5].indexOf(v) !== -1), 'linearity': (value) => [1, 2].indexOf(value) !== -1, 'skip': (value) => [0, 1].indexOf(value) !== -1, - 'skipmin': (value) => isInteger(value), - 'skipafter': (value) => isInteger(value), - 'sequence': (value) => isInteger(value), + 'skipmin': (value) => utils.isInteger(value), + 'skipafter': (value) => utils.isInteger(value), + 'sequence': (value) => utils.isInteger(value), 'battr': (value) => Array.isArray(value) && value.every(v => Array.from({length: 17}, (_, i) => i + 1).indexOf(v) !== -1), - 'maxextended': (value) => isInteger(value), - 'minbitrate': (value) => isInteger(value), - 'maxbitrate': (value) => isInteger(value), + 'maxextended': (value) => utils.isInteger(value), + 'minbitrate': (value) => utils.isInteger(value), + 'maxbitrate': (value) => utils.isInteger(value), 'boxingallowed': (value) => [0, 1].indexOf(value) !== -1, 'playbackmethod': (value) => Array.isArray(value) && value.every(v => [1, 2, 3, 4, 5, 6].indexOf(v) !== -1), 'playbackend': (value) => [1, 2, 3].indexOf(value) !== -1, @@ -91,7 +88,7 @@ export const GlobalExchange = (function() { return value; } }); - let random = deepAccess(adagioStorage, 'session.rnd'); + let random = utils.deepAccess(adagioStorage, 'session.rnd'); let newSession = false; if (internal.isNewSession(adagioStorage)) { @@ -106,7 +103,7 @@ export const GlobalExchange = (function() { } } - mergeDeep(exchangeData, adagioStorage, data); + utils.mergeDeep(exchangeData, adagioStorage, data); internal.enqueue({ action: 'session', @@ -124,14 +121,14 @@ export const GlobalExchange = (function() { export function adagioScriptFromLocalStorageCb(ls) { try { if (!ls) { - logWarn(`${LOG_PREFIX} script not found.`); + utils.logWarn(`${LOG_PREFIX} script not found.`); return; } const hashRgx = /^(\/\/ hash: (.+)\n)(.+\n)$/; if (!hashRgx.test(ls)) { - logWarn(`${LOG_PREFIX} no hash found.`); + utils.logWarn(`${LOG_PREFIX} no hash found.`); storage.removeDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY); } else { const r = ls.match(hashRgx); @@ -139,15 +136,15 @@ export function adagioScriptFromLocalStorageCb(ls) { const content = r[3]; if (verify(content, hash, ADAGIO_PUBKEY, ADAGIO_PUBKEY_E)) { - logInfo(`${LOG_PREFIX} start script.`); + utils.logInfo(`${LOG_PREFIX} start script.`); Function(ls)(); // eslint-disable-line no-new-func } else { - logWarn(`${LOG_PREFIX} invalid script found.`); + utils.logWarn(`${LOG_PREFIX} invalid script found.`); storage.removeDataFromLocalStorage(ADAGIO_LOCALSTORAGE_KEY); } } } catch (err) { - logError(LOG_PREFIX, err); + utils.logError(LOG_PREFIX, err); } } @@ -170,7 +167,7 @@ export function getAdagioScript() { // This key is removed only if localStorage is not accessible. window.localStorage.removeItem('adagio'); } catch (e) { - logInfo(`${LOG_PREFIX} unable to clear Adagio scripts from localstorage.`); + utils.logInfo(`${LOG_PREFIX} unable to clear Adagio scripts from localstorage.`); } } }); @@ -178,7 +175,7 @@ export function getAdagioScript() { function canAccessTopWindow() { try { - if (getWindowTop().location.href) { + if (utils.getWindowTop().location.href) { return true; } } catch (error) { @@ -187,17 +184,17 @@ function canAccessTopWindow() { } function getCurrentWindow() { - return currentWindow || getWindowSelf(); + return currentWindow || utils.getWindowSelf(); } function isSafeFrameWindow() { - const ws = getWindowSelf(); + const ws = utils.getWindowSelf(); return !!(ws.$sf && ws.$sf.ext); } function initAdagio() { if (canAccessTopWindow()) { - currentWindow = (canAccessTopWindow()) ? getWindowTop() : getWindowSelf(); + currentWindow = (canAccessTopWindow()) ? utils.getWindowTop() : utils.getWindowSelf(); } const w = internal.getCurrentWindow(); @@ -214,7 +211,7 @@ function initAdagio() { try { GlobalExchange.prepareExchangeData(storageData); } catch (e) { - logError(LOG_PREFIX, e); + utils.logError(LOG_PREFIX, e); } }); @@ -233,7 +230,7 @@ function getPageviewId() { const w = internal.getCurrentWindow(); w.ADAGIO = w.ADAGIO || {}; - w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || generateUUID(); + w.ADAGIO.pageviewId = w.ADAGIO.pageviewId || utils.generateUUID(); return w.ADAGIO.pageviewId; }; @@ -243,7 +240,7 @@ function getDevice() { return { userAgent: navigator.userAgent, language: navigator[language], - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, geo: {}, js: 1 }; @@ -257,12 +254,12 @@ function getSite(bidderRequest) { const { refererInfo } = bidderRequest; if (canAccessTopWindow()) { - const wt = getWindowTop(); + const wt = utils.getWindowTop(); domain = wt.location.hostname; page = wt.location.href; referrer = wt.document.referrer || ''; } else if (refererInfo.reachedTop) { - const url = parseUrl(refererInfo.referer); + const url = utils.parseUrl(refererInfo.referer); domain = url.hostname; page = refererInfo.referer; } else if (refererInfo.stack && refererInfo.stack.length && refererInfo.stack[0]) { @@ -270,7 +267,7 @@ function getSite(bidderRequest) { // will be considered as "localhost" by the parseUrl function. // As the isBidRequestValid returns false when it does not reach the referer // this should never called. - const url = parseUrl(refererInfo.stack[0]); + const url = utils.parseUrl(refererInfo.stack[0]); domain = url.hostname; } @@ -283,9 +280,9 @@ function getSite(bidderRequest) { function getElementFromTopWindow(element, currentWindow) { try { - if (getWindowTop() === currentWindow) { + if (utils.getWindowTop() === currentWindow) { if (!element.getAttribute('id')) { - element.setAttribute('id', `adg-${getUniqueIdentifierStr()}`); + element.setAttribute('id', `adg-${utils.getUniqueIdentifierStr()}`); } return element; } else { @@ -300,26 +297,26 @@ function getElementFromTopWindow(element, currentWindow) { return getElementFromTopWindow(frame, currentWindow.parent); } } catch (err) { - logWarn(`${LOG_PREFIX}`, err); + utils.logWarn(`${LOG_PREFIX}`, err); return false; } }; function autoDetectAdUnitElementIdFromGpt(adUnitCode) { - const autoDetectedAdUnit = getGptSlotInfoForAdUnitCode(adUnitCode); + const autoDetectedAdUnit = utils.getGptSlotInfoForAdUnitCode(adUnitCode); - if (autoDetectedAdUnit.divId) { + if (autoDetectedAdUnit && autoDetectedAdUnit.divId) { return autoDetectedAdUnit.divId; } }; function isRendererPreferredFromPublisher(bidRequest) { // renderer defined at adUnit level - const adUnitRenderer = deepAccess(bidRequest, 'renderer'); + const adUnitRenderer = utils.deepAccess(bidRequest, 'renderer'); const hasValidAdUnitRenderer = !!(adUnitRenderer && adUnitRenderer.url && adUnitRenderer.render); // renderer defined at adUnit.mediaTypes level - const mediaTypeRenderer = deepAccess(bidRequest, 'mediaTypes.video.renderer'); + const mediaTypeRenderer = utils.deepAccess(bidRequest, 'mediaTypes.video.renderer'); const hasValidMediaTypeRenderer = !!(mediaTypeRenderer && mediaTypeRenderer.url && mediaTypeRenderer.render); return !!( @@ -335,10 +332,10 @@ function isRendererPreferredFromPublisher(bidRequest) { */ function isNewSession(adagioStorage) { const now = Date.now(); - const { lastActivityTime, vwSmplg } = deepAccess(adagioStorage, 'session', {}); + const { lastActivityTime, vwSmplg } = utils.deepAccess(adagioStorage, 'session', {}); return ( - !isNumber(lastActivityTime) || - !isNumber(vwSmplg) || + !utils.isNumber(lastActivityTime) || + !utils.isNumber(vwSmplg) || (now - lastActivityTime) > MAX_SESS_DURATION ) } @@ -347,7 +344,7 @@ function setPlayerName(bidRequest) { const playerName = (internal.isRendererPreferredFromPublisher(bidRequest)) ? 'other' : 'adagio'; if (playerName === 'other') { - logWarn(`${LOG_PREFIX} renderer.backupOnly has not been set. Adagio recommends to use its own player to get expected behavior.`); + utils.logWarn(`${LOG_PREFIX} renderer.backupOnly has not been set. Adagio recommends to use its own player to get expected behavior.`); } return playerName; @@ -368,7 +365,7 @@ export const internal = { }; function _getGdprConsent(bidderRequest) { - if (!deepAccess(bidderRequest, 'gdprConsent')) { + if (!utils.deepAccess(bidderRequest, 'gdprConsent')) { return false; } @@ -379,7 +376,7 @@ function _getGdprConsent(bidderRequest) { allowAuctionWithoutConsent } = bidderRequest.gdprConsent; - return cleanObj({ + return utils.cleanObj({ apiVersion, consentString, consentRequired: gdprApplies ? 1 : 0, @@ -394,22 +391,22 @@ function _getCoppa() { } function _getUspConsent(bidderRequest) { - return (deepAccess(bidderRequest, 'uspConsent')) ? { uspConsent: bidderRequest.uspConsent } : false; + return (utils.deepAccess(bidderRequest, 'uspConsent')) ? { uspConsent: bidderRequest.uspConsent } : false; } function _getSchain(bidRequest) { - return deepAccess(bidRequest, 'schain'); + return utils.deepAccess(bidRequest, 'schain'); } function _getEids(bidRequest) { - if (deepAccess(bidRequest, 'userId')) { + if (utils.deepAccess(bidRequest, 'userId')) { return createEidsArray(bidRequest.userId); } } function _buildVideoBidRequest(bidRequest) { - const videoAdUnitParams = deepAccess(bidRequest, 'mediaTypes.video', {}); - const videoBidderParams = deepAccess(bidRequest, 'params.video', {}); + const videoAdUnitParams = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); + const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {}); const computedParams = {}; // Special case for playerSize. @@ -439,7 +436,7 @@ function _buildVideoBidRequest(bidRequest) { bidRequest.mediaTypes.video[paramName] = videoParams[paramName]; } else { delete bidRequest.mediaTypes.video[paramName]; - logWarn(`${LOG_PREFIX} The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); + utils.logWarn(`${LOG_PREFIX} The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); } } }); @@ -450,14 +447,14 @@ function _renderer(bid) { if (typeof window.ADAGIO.outstreamPlayer === 'function') { window.ADAGIO.outstreamPlayer(bid); } else { - logError(`${LOG_PREFIX} Adagio outstream player is not defined`); + utils.logError(`${LOG_PREFIX} Adagio outstream player is not defined`); } }); } function _parseNativeBidResponse(bid) { if (!bid.admNative || !Array.isArray(bid.admNative.assets)) { - logError(`${LOG_PREFIX} Invalid native response`); + utils.logError(`${LOG_PREFIX} Invalid native response`); return; } @@ -562,7 +559,7 @@ function _parseNativeBidResponse(bid) { } function _getFloors(bidRequest) { - if (!isFn(bidRequest.getFloor)) { + if (!utils.isFn(bidRequest.getFloor)) { return false; } @@ -575,9 +572,9 @@ function _getFloors(bidRequest) { size: [] }); - floors.push(cleanObj({ + floors.push(utils.cleanObj({ mt: mediaType, - s: isArray(size) ? `${size[0]}x${size[1]}` : undefined, + s: utils.isArray(size) ? `${size[0]}x${size[1]}` : undefined, f: (!isNaN(info.floor) && info.currency === CURRENCY) ? info.floor : DEFAULT_FLOOR })); } @@ -587,7 +584,7 @@ function _getFloors(bidRequest) { const sizeProp = mediaType === VIDEO ? 'playerSize' : 'sizes'; if (bidRequest.mediaTypes[mediaType][sizeProp] && bidRequest.mediaTypes[mediaType][sizeProp].length) { - if (isArray(bidRequest.mediaTypes[mediaType][sizeProp][0])) { + if (utils.isArray(bidRequest.mediaTypes[mediaType][sizeProp][0])) { bidRequest.mediaTypes[mediaType][sizeProp].forEach(size => { getAndPush(mediaType, [size[0], size[1]]); }); @@ -624,7 +621,7 @@ export function setExtraParam(bid, paramName) { const adgGlobalConf = config.getConfig('adagio') || {}; const ortb2Conf = config.getConfig('ortb2'); - const detected = adgGlobalConf[paramName] || deepAccess(ortb2Conf, `site.ext.data.${paramName}`, null); + const detected = adgGlobalConf[paramName] || utils.deepAccess(ortb2Conf, `site.ext.data.${paramName}`, null); if (detected) { bid.params[paramName] = detected; } @@ -647,7 +644,7 @@ function autoFillParams(bid) { bid.params.placement = bid.adUnitCode; } - bid.params.adUnitElementId = deepAccess(bid, 'ortb2Imp.ext.data.elementId', null) || bid.params.adUnitElementId; + bid.params.adUnitElementId = utils.deepAccess(bid, 'ortb2Imp.ext.data.elementId', null) || bid.params.adUnitElementId; if (!bid.params.adUnitElementId) { if (adgGlobalConf.useAdUnitCodeAsAdUnitElementId === true || bid.params.useAdUnitCodeAsAdUnitElementId === true) { @@ -670,7 +667,7 @@ function getPageDimensions() { } // the page dimension can be computed on window.top only. - const wt = getWindowTop(); + const wt = utils.getWindowTop(); const body = wt.document.querySelector('body'); if (!body) { @@ -695,17 +692,17 @@ function getViewPortDimensions() { const viewportDims = { w: 0, h: 0 }; if (isSafeFrameWindow()) { - const ws = getWindowSelf(); + const ws = utils.getWindowSelf(); if (typeof ws.$sf.ext.geom !== 'function') { - logWarn(LOG_PREFIX, 'Unable to compute from safeframe api.'); + utils.logWarn(LOG_PREFIX, 'Unable to compute from safeframe api.'); return ''; } const sfGeom = ws.$sf.ext.geom(); if (!sfGeom || !sfGeom.win) { - logWarn(LOG_PREFIX, 'Unable to compute from safeframe api. Missing `geom().win` property'); + utils.logWarn(LOG_PREFIX, 'Unable to compute from safeframe api. Missing `geom().win` property'); return ''; } @@ -713,7 +710,7 @@ function getViewPortDimensions() { viewportDims.h = Math.round(sfGeom.h); } else { // window.top based computing - const wt = getWindowTop(); + const wt = utils.getWindowTop(); viewportDims.w = wt.innerWidth; viewportDims.h = wt.innerHeight; } @@ -733,17 +730,17 @@ function getSlotPosition(adUnitElementId) { const position = { x: 0, y: 0 }; if (isSafeFrameWindow()) { - const ws = getWindowSelf(); + const ws = utils.getWindowSelf(); if (typeof ws.$sf.ext.geom !== 'function') { - logWarn(LOG_PREFIX, 'Unable to compute from safeframe api.'); + utils.logWarn(LOG_PREFIX, 'Unable to compute from safeframe api.'); return ''; } const sfGeom = ws.$sf.ext.geom(); if (!sfGeom || !sfGeom.self) { - logWarn(LOG_PREFIX, 'Unable to compute from safeframe api. Missing `geom().self` property'); + utils.logWarn(LOG_PREFIX, 'Unable to compute from safeframe api. Missing `geom().self` property'); return ''; } @@ -751,13 +748,13 @@ function getSlotPosition(adUnitElementId) { position.y = Math.round(sfGeom.l); } else if (canAccessTopWindow()) { // window.top based computing - const wt = getWindowTop(); + const wt = utils.getWindowTop(); const d = wt.document; let domElement; - if (inIframe() === true) { - const ws = getWindowSelf(); + if (utils.inIframe() === true) { + const ws = utils.getWindowSelf(); const currentElement = ws.document.getElementById(adUnitElementId); domElement = internal.getElementFromTopWindow(currentElement, ws); } else { @@ -816,7 +813,7 @@ function getDomLoadingDuration() { let domLoadingDuration = -1; let performance; - performance = (canAccessTopWindow()) ? getWindowTop().performance : getWindowSelf().performance; + performance = (canAccessTopWindow()) ? utils.getWindowTop().performance : utils.getWindowSelf().performance; if (performance && performance.timing && performance.timing.navigationStart > 0) { const val = performance.timing.domLoading - performance.timing.navigationStart; @@ -874,13 +871,13 @@ export const spec = { autoFillParams(bid); if (!internal.getRefererInfo().reachedTop) { - logWarn(`${LOG_PREFIX} the main page url is unreachabled.`); + utils.logWarn(`${LOG_PREFIX} the main page url is unreachabled.`); // internal.enqueue(debugData()); return false; } if (!(bid.params.organizationId && bid.params.site && bid.params.placement)) { - logWarn(`${LOG_PREFIX} at least one required param is missing.`); + utils.logWarn(`${LOG_PREFIX} at least one required param is missing.`); // internal.enqueue(debugData()); return false; } @@ -899,7 +896,7 @@ export const spec = { const schain = _getSchain(validBidRequests[0]); const eids = _getEids(validBidRequests[0]) || []; - const adUnits = _map(validBidRequests, (bidRequest) => { + const adUnits = utils._map(validBidRequests, (bidRequest) => { const globalFeatures = GlobalExchange.getOrSetGlobalFeatures(); const features = { ...globalFeatures, @@ -928,7 +925,7 @@ export const spec = { // Handle priceFloors module bidRequest.floors = _getFloors(bidRequest); - if (deepAccess(bidRequest, 'mediaTypes.video')) { + if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { _buildVideoBidRequest(bidRequest); } @@ -939,7 +936,7 @@ export const spec = { // Group ad units by organizationId const groupedAdUnits = adUnits.reduce((groupedAdUnits, adUnit) => { - const adUnitCopy = deepClone(adUnit); + const adUnitCopy = utils.deepClone(adUnit); adUnitCopy.params.organizationId = adUnitCopy.params.organizationId.toString(); // remove useless props @@ -953,12 +950,12 @@ export const spec = { }, {}); // Build one request per organizationId - const requests = _map(Object.keys(groupedAdUnits), organizationId => { + const requests = utils._map(Object.keys(groupedAdUnits), organizationId => { return { method: 'POST', url: ENDPOINT, data: { - id: generateUUID(), + id: utils.generateUUID(), organizationId: organizationId, secure: secure, device: device, @@ -1004,12 +1001,12 @@ export const spec = { const bidReq = (find(bidRequest.data.adUnits, bid => bid.bidId === bidObj.requestId)); if (bidReq) { - bidObj.meta = deepAccess(bidObj, 'meta', {}); + bidObj.meta = utils.deepAccess(bidObj, 'meta', {}); bidObj.meta.mediaType = bidObj.mediaType; bidObj.meta.advertiserDomains = (Array.isArray(bidObj.aDomain) && bidObj.aDomain.length) ? bidObj.aDomain : []; if (bidObj.mediaType === VIDEO) { - const mediaTypeContext = deepAccess(bidReq, 'mediaTypes.video.context'); + const mediaTypeContext = utils.deepAccess(bidReq, 'mediaTypes.video.context'); // Adagio SSP returns a `vastXml` only. No `vastUrl` nor `videoCacheKey`. if (!bidObj.vastUrl && bidObj.vastXml) { bidObj.vastUrl = 'data:text/xml;charset=utf-8;base64,' + btoa(bidObj.vastXml.replace(/\\"/g, '"')); @@ -1021,8 +1018,8 @@ export const spec = { adUnitCode: bidObj.adUnitCode, url: bidObj.urlRenderer || RENDERER_URL, config: { - ...deepAccess(bidReq, 'mediaTypes.video'), - ...deepAccess(bidObj, 'outstream', {}) + ...utils.deepAccess(bidReq, 'mediaTypes.video'), + ...utils.deepAccess(bidObj, 'outstream', {}) } }); @@ -1046,7 +1043,7 @@ export const spec = { } } } catch (err) { - logError(err); + utils.logError(err); } return bidResponses; }, @@ -1080,7 +1077,7 @@ export const spec = { if (isOrtb) { autoFillParams(adagioBid); - adagioBid.params.auctionId = deepAccess(adagioBidderRequest, 'auctionId'); + adagioBid.params.auctionId = utils.deepAccess(adagioBidderRequest, 'auctionId'); const globalFeatures = GlobalExchange.getOrSetGlobalFeatures(); adagioBid.params.features = { @@ -1093,7 +1090,7 @@ export const spec = { adagioBid.params.prebidVersion = '$prebid.version$'; adagioBid.params.data = GlobalExchange.getExchangeData(); - if (deepAccess(adagioBid, 'mediaTypes.video.context') === OUTSTREAM) { + if (utils.deepAccess(adagioBid, 'mediaTypes.video.context') === OUTSTREAM) { adagioBid.params.playerName = setPlayerName(adagioBid); } diff --git a/modules/adbookpspBidAdapter.js b/modules/adbookpspBidAdapter.js index 1b93d4fe1c6..d3f3ba295b9 100644 --- a/modules/adbookpspBidAdapter.js +++ b/modules/adbookpspBidAdapter.js @@ -3,10 +3,7 @@ import find from 'core-js-pure/features/array/find'; import { config } from '../src/config.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; -import { - isPlainObject, deepSetValue, deepAccess, logWarn, inIframe, isNumber, logError, isArray, uniques, - flatten, triggerPixel, isStr, isEmptyStr, generateUUID -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; /** @@ -153,7 +150,7 @@ function buildDevice() { const deviceConfig = common.getConfig('device'); - if (isPlainObject(deviceConfig)) { + if (utils.isPlainObject(deviceConfig)) { return { ...device, ...deviceConfig }; } @@ -166,12 +163,12 @@ function buildRegs(bidderRequest) { }; if (bidderRequest.gdprConsent) { - deepSetValue( + utils.deepSetValue( regs, 'ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0 ); - deepSetValue( + utils.deepSetValue( regs, 'ext.gdprConsentString', bidderRequest.gdprConsent.consentString || '' @@ -179,7 +176,7 @@ function buildRegs(bidderRequest) { } if (bidderRequest.uspConsent) { - deepSetValue(regs, 'ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(regs, 'ext.us_privacy', bidderRequest.uspConsent); } return regs; @@ -190,10 +187,10 @@ function buildSource(bidRequests, bidderRequest) { fd: 1, tid: bidderRequest.auctionId, }; - const schain = deepAccess(bidRequests, '0.schain'); + const schain = utils.deepAccess(bidRequests, '0.schain'); if (schain) { - deepSetValue(source, 'ext.schain', schain); + utils.deepSetValue(source, 'ext.schain', schain); } return source; @@ -235,7 +232,7 @@ function buildMediaTypeObject(mediaType, bidRequest) { case VIDEO: return buildVideoObject(bidRequest); default: - logWarn(`${BIDDER_CODE}: Unsupported media type ${mediaType}!`); + utils.logWarn(`${BIDDER_CODE}: Unsupported media type ${mediaType}!`); } } @@ -249,7 +246,7 @@ function buildBannerObject(bidRequest) { return { pos: 0, - topframe: inIframe() ? 0 : 1, + topframe: utils.inIframe() ? 0 : 1, format, w, h, @@ -264,8 +261,8 @@ function buildVideoObject(bidRequest) { }; for (const param of VIDEO_PARAMS) { - const paramsValue = deepAccess(bidRequest, `params.video.${param}`); - const mediaTypeValue = deepAccess( + const paramsValue = utils.deepAccess(bidRequest, `params.video.${param}`); + const mediaTypeValue = utils.deepAccess( bidRequest, `mediaTypes.video.${param}` ); @@ -279,10 +276,10 @@ function buildVideoObject(bidRequest) { } function getVideoSize(bidRequest) { - const playerSize = deepAccess(bidRequest, 'mediaTypes.video.playerSize', [[]]); - const { w, h } = deepAccess(bidRequest, 'mediaTypes.video', {}); + const playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize', [[]]); + const { w, h } = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); - if (isNumber(w) && isNumber(h)) { + if (utils.isNumber(w) && utils.isNumber(h)) { return { w, h }; } @@ -299,11 +296,11 @@ function buildImpExt(validBidRequest) { const ext = {}; if (placementId) { - deepSetValue(ext, 'adbook.placementId', placementId); + utils.deepSetValue(ext, 'adbook.placementId', placementId); } if (effectiverOrgId) { - deepSetValue(ext, 'adbook.orgId', effectiverOrgId); + utils.deepSetValue(ext, 'adbook.orgId', effectiverOrgId); } return ext; @@ -317,19 +314,20 @@ function interpretResponse(bidResponse, bidderRequest) { const bidderRequestBody = safeJSONparse(bidderRequest.data); if ( - deepAccess(bidderRequestBody, 'id') != - deepAccess(bidResponse, 'body.id') + utils.deepAccess(bidderRequestBody, 'id') != + utils.deepAccess(bidResponse, 'body.id') ) { - logError( + utils.logError( `${BIDDER_CODE}: Bid response id does not match bidder request id` ); return []; } - const referrer = deepAccess(bidderRequestBody, 'site.ref', ''); - const incomingBids = deepAccess(bidResponse, 'body.seatbid', []) - .filter((seat) => isArray(seat.bid)) + const referrer = utils.deepAccess(bidderRequestBody, 'site.ref', ''); + const incomingBids = utils + .deepAccess(bidResponse, 'body.seatbid', []) + .filter((seat) => utils.isArray(seat.bid)) .reduce((bids, seat) => bids.concat(seat.bid), []) .filter(validateBid(bidderRequestBody)); const targetingMap = buildTargetingMap(incomingBids); @@ -363,21 +361,21 @@ function impBidsToPrebidBids( } const impToPrebidBid = - (bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid, bidIndex) => { + (bidderRequestBody, bidResponseCurrency, referrer, targetingMap) => (bid) => { try { const bidRequest = findBidRequest(bidderRequestBody, bid); if (!bidRequest) { - logError(`${BIDDER_CODE}: Could not match bid to bid request`); + utils.logError(`${BIDDER_CODE}: Could not match bid to bid request`); return null; } - const categories = deepAccess(bid, 'cat', []); + const categories = utils.deepAccess(bid, 'cat', []); const mediaType = getMediaType(bid.adm); let prebidBid = { ad: bid.adm, adId: bid.adid, - adserverTargeting: targetingMap[bidIndex], + adserverTargeting: targetingMap[bid.impid], adUnitCode: bidRequest.tagid, bidderRequestId: bidderRequestBody.id, bidId: bid.id, @@ -385,7 +383,7 @@ const impToPrebidBid = creativeId: bid.crid || bid.id, currency: bidResponseCurrency || getBidderConfig('defaultCurrency'), height: bid.h, - lineItemId: deepAccess(bid, 'ext.liid'), + lineItemId: utils.deepAccess(bid, 'ext.liid'), mediaType, meta: { advertiserDomains: bid.adomain, @@ -408,12 +406,9 @@ const impToPrebidBid = }; } - if (deepAccess(bid, 'ext.pa_win') === true) { - prebidBid.auctionWinner = true; - } return prebidBid; } catch (error) { - logError(`${BIDDER_CODE}: Error while building bid`, error); + utils.logError(`${BIDDER_CODE}: Error while building bid`, error); return null; } @@ -428,47 +423,33 @@ function getVideoSpecificParams(bidRequest, bid) { } function buildTargetingMap(bids) { - const impIds = bids.map(({ impid }) => impid).filter(uniques); + const impIds = bids.map(({ impid }) => impid).filter(utils.uniques); const values = impIds.reduce((result, id) => { result[id] = { lineItemIds: [], - orderIds: [], dealIds: [], adIds: [], - adAndOrderIndexes: [] }; return result; }, {}); - bids.forEach((bid, bidIndex) => { - let impId = bid.impid; - values[impId].lineItemIds.push(bid.ext.liid); - values[impId].dealIds.push(bid.dealid); - values[impId].adIds.push(bid.adid); - - if (deepAccess(bid, 'ext.ordid')) { - values[impId].orderIds.push(bid.ext.ordid); - bid.ext.ordid.split(TARGETING_VALUE_SEPARATOR).forEach((ordid, ordIndex) => { - let adIdIndex = values[impId].adIds.indexOf(bid.adid); - values[impId].adAndOrderIndexes.push(adIdIndex + '_' + ordIndex) - }) - } + bids.forEach((bid) => { + values[bid.impid].lineItemIds.push(bid.ext.liid); + values[bid.impid].dealIds.push(bid.dealid); + values[bid.impid].adIds.push(bid.adid); }); const targetingMap = {}; - bids.forEach((bid, bidIndex) => { - let id = bid.impid; - - targetingMap[bidIndex] = { + for (const id of impIds) { + targetingMap[id] = { hb_liid_adbookpsp: values[id].lineItemIds.join(TARGETING_VALUE_SEPARATOR), hb_deal_adbookpsp: values[id].dealIds.join(TARGETING_VALUE_SEPARATOR), - hb_ad_ord_adbookpsp: values[id].adAndOrderIndexes.join(TARGETING_VALUE_SEPARATOR), hb_adid_c_adbookpsp: values[id].adIds.join(TARGETING_VALUE_SEPARATOR), - hb_ordid_adbookpsp: values[id].orderIds.join(TARGETING_VALUE_SEPARATOR), }; - }) + } + return targetingMap; } @@ -478,12 +459,12 @@ function buildTargetingMap(bids) { function hasRequiredParams(bidRequest) { const value = - deepAccess(bidRequest, 'params.placementId') != null || - deepAccess(bidRequest, 'params.orgId') != null || + utils.deepAccess(bidRequest, 'params.placementId') != null || + utils.deepAccess(bidRequest, 'params.orgId') != null || getBidderConfig('orgId') != null; if (!value) { - logError(`${BIDDER_CODE}: missing orgId and placementId parameter`); + utils.logError(`${BIDDER_CODE}: missing orgId and placementId parameter`); } return value; @@ -491,7 +472,7 @@ function hasRequiredParams(bidRequest) { function isValidBannerRequest(bidRequest) { const value = validateSizes( - deepAccess(bidRequest, 'mediaTypes.banner.sizes', []) + utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes', []) ); return value; @@ -499,28 +480,28 @@ function isValidBannerRequest(bidRequest) { function isValidVideoRequest(bidRequest) { const value = - isArray(deepAccess(bidRequest, 'mediaTypes.video.mimes')) && + utils.isArray(utils.deepAccess(bidRequest, 'mediaTypes.video.mimes')) && validateVideoSizes(bidRequest); return value; } function validateSize(size) { - return isArray(size) && size.length === 2 && size.every(isNumber); + return utils.isArray(size) && size.length === 2 && size.every(utils.isNumber); } function validateSizes(sizes) { - return isArray(sizes) && sizes.length > 0 && sizes.every(validateSize); + return utils.isArray(sizes) && sizes.length > 0 && sizes.every(validateSize); } function validateVideoSizes(bidRequest) { - const { w, h } = deepAccess(bidRequest, 'mediaTypes.video', {}); + const { w, h } = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); return ( validateSizes( - deepAccess(bidRequest, 'mediaTypes.video.playerSize') + utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') ) || - (isNumber(w) && isNumber(h)) + (utils.isNumber(w) && utils.isNumber(h)) ); } @@ -537,7 +518,7 @@ function validateBid(bidderRequestBody) { const value = validators.every((validator) => validator(bid, bidRequest)); if (!value) { - logWarn(`${BIDDER_CODE}: Invalid bid`, bid); + utils.logWarn(`${BIDDER_CODE}: Invalid bid`, bid); } return value; @@ -545,13 +526,13 @@ function validateBid(bidderRequestBody) { } const commonBidValidators = [ - (bid) => isPlainObject(bid), + (bid) => utils.isPlainObject(bid), (bid) => isNonEmptyStr(bid.adid), (bid) => isNonEmptyStr(bid.adm), (bid) => isNonEmptyStr(bid.id), (bid) => isNonEmptyStr(bid.impid), - (bid) => isNonEmptyStr(deepAccess(bid, 'ext.liid')), - (bid) => isNumber(bid.price), + (bid) => isNonEmptyStr(utils.deepAccess(bid, 'ext.liid')), + (bid) => utils.isNumber(bid.price), ]; const bannerBidValidators = [ @@ -565,12 +546,12 @@ function validateBannerDimension(dimension) { return bannerHasSingleSize(bidRequest); } - return isNumber(bid[dimension]); + return utils.isNumber(bid[dimension]); }; } function bannerHasSingleSize(bidRequest) { - return deepAccess(bidRequest, 'banner.format', []).length === 1; + return utils.deepAccess(bidRequest, 'banner.format', []).length === 1; } /** @@ -581,9 +562,9 @@ export const storage = getStorageManager(); function getUserSyncs(syncOptions, responses, gdprConsent, uspConsent) { return responses - .map((response) => deepAccess(response, 'body.ext.sync')) - .filter(isArray) - .reduce(flatten, []) + .map((response) => utils.deepAccess(response, 'body.ext.sync')) + .filter(utils.isArray) + .reduce(utils.flatten, []) .filter(validateSync(syncOptions)) .map(applyConsents(gdprConsent, uspConsent)); } @@ -663,11 +644,11 @@ function onBidWon(bid) { const wurl = buildWinUrl(bid); if (wurl !== null) { - triggerPixel(wurl); + utils.triggerPixel(wurl); } - if (isStr(bid.nurl)) { - triggerPixel(bid.nurl); + if (utils.isStr(bid.nurl)) { + utils.triggerPixel(bid.nurl); } } @@ -681,7 +662,7 @@ function buildWinUrl(bid) { return url.toString(); } catch (_) { - logError( + utils.logError( `${BIDDER_CODE}: Could not build win tracking URL with %s`, getBidderConfig('winTrackingUrl') ); @@ -705,7 +686,7 @@ function getMediaType(adm) { const markup = safeJSONparse(adm.replace(/\\/g, '')); - if (markup && isPlainObject(markup.native)) { + if (markup && utils.isPlainObject(markup.native)) { return NATIVE; } @@ -721,7 +702,7 @@ function safeJSONparse(...args) { } function isNonEmptyStr(value) { - return isStr(value) && !isEmptyStr(value); + return utils.isStr(value) && !utils.isEmptyStr(value); } function findBidRequest(bidderRequest, bid) { @@ -801,7 +782,7 @@ const getUrlBuilder = function (url) { export const common = { generateUUID: function () { - return generateUUID(); + return utils.generateUUID(); }, getConfig: function (property) { return config.getConfig(property); diff --git a/modules/addefendBidAdapter.js b/modules/addefendBidAdapter.js index dcc453ef35a..18cafe829b5 100644 --- a/modules/addefendBidAdapter.js +++ b/modules/addefendBidAdapter.js @@ -19,7 +19,6 @@ export const spec = { v: $$PREBID_GLOBAL$$.version, auctionId: false, pageId: false, - gdpr_applies: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? bidderRequest.gdprConsent.gdprApplies : 'true', gdpr_consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString ? bidderRequest.gdprConsent.consentString : '', referer: bidderRequest.refererInfo.referer, bids: [], diff --git a/modules/adfBidAdapter.js b/modules/adfBidAdapter.js index f0425a174ff..43dcdcd1604 100644 --- a/modules/adfBidAdapter.js +++ b/modules/adfBidAdapter.js @@ -7,7 +7,7 @@ import { import { NATIVE, BANNER, VIDEO } from '../src/mediaTypes.js'; -import { mergeDeep, _map, deepAccess, parseSizesInput, deepSetValue } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; @@ -58,11 +58,7 @@ export const spec = { aliases: BIDDER_ALIAS, gvlid: GVLID, supportedMediaTypes: [ NATIVE, BANNER, VIDEO ], - isBidRequestValid: (bid) => { - const params = bid.params || {}; - const { mid, inv, mname } = params; - return !!(mid || (inv && mname)); - }, + isBidRequestValid: bid => !!bid.params.mid, buildRequests: (validBidRequests, bidderRequest) => { let app, site; @@ -72,12 +68,12 @@ export const spec = { if (typeof getConfig('app') === 'object') { app = getConfig('app') || {}; if (commonFpd.app) { - mergeDeep(app, commonFpd.app); + utils.mergeDeep(app, commonFpd.app); } } else { site = getConfig('site') || {}; if (commonFpd.site) { - mergeDeep(site, commonFpd.site); + utils.mergeDeep(site, commonFpd.site); } if (!site.page) { @@ -103,27 +99,12 @@ export const spec = { const imp = validBidRequests.map((bid, id) => { bid.netRevenue = pt; - const floorInfo = bid.getFloor ? bid.getFloor({ - currency: currency || 'USD' - }) : {}; - const bidfloor = floorInfo.floor; - const bidfloorcur = floorInfo.currency; - const { mid, inv, mname } = bid.params; - const imp = { id: id + 1, - tagid: mid, - bidfloor, - bidfloorcur, - ext: { - bidder: { - inv, - mname - } - } + tagid: bid.params.mid }; - const assets = _map(bid.nativeParams, (bidParams, key) => { + const assets = utils._map(bid.nativeParams, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -164,12 +145,15 @@ export const spec = { assets } }; + + bid.mediaType = NATIVE; + return imp; } - const bannerParams = deepAccess(bid, 'mediaTypes.banner'); + const bannerParams = utils.deepAccess(bid, 'mediaTypes.banner'); if (bannerParams && bannerParams.sizes) { - const sizes = parseSizesInput(bannerParams.sizes); + const sizes = utils.parseSizesInput(bannerParams.sizes); const format = sizes.map(size => { const [ width, height ] = size.split('x'); const w = parseInt(width, 10); @@ -180,14 +164,18 @@ export const spec = { imp.banner = { format }; + bid.mediaType = BANNER; + + return imp; } - const videoParams = deepAccess(bid, 'mediaTypes.video'); + const videoParams = utils.deepAccess(bid, 'mediaTypes.video'); if (videoParams) { imp.video = videoParams; - } + bid.mediaType = VIDEO; - return imp; + return imp; + } }); const request = { @@ -206,21 +194,21 @@ export const spec = { request.is_debug = !!test; request.test = 1; } - if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) { - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); + if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) { + utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); } if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (eids) { - deepSetValue(request, 'user.ext.eids', eids); + utils.deepSetValue(request, 'user.ext.eids', eids); } if (schain) { - deepSetValue(request, 'source.ext.schain', schain); + utils.deepSetValue(request, 'source.ext.schain', schain); } return { @@ -247,7 +235,6 @@ export const spec = { return bids.map((bid, id) => { const bidResponse = bidResponses[id]; if (bidResponse) { - const mediaType = deepAccess(bidResponse, 'ext.prebid.type'); const result = { requestId: bid.bidId, cpm: bidResponse.price, @@ -255,12 +242,12 @@ export const spec = { ttl: 360, netRevenue: bid.netRevenue === 'net', currency: cur, - mediaType, + mediaType: bid.mediaType, width: bidResponse.w, height: bidResponse.h, dealId: bidResponse.dealid, meta: { - mediaType, + mediaType: bid.mediaType, advertiserDomains: bidResponse.adomain } }; @@ -268,10 +255,10 @@ export const spec = { if (bidResponse.native) { result.native = parseNative(bidResponse); } else { - result[ mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm; + result[ bid.mediaType === VIDEO ? 'vastXml' : 'ad' ] = bidResponse.adm; } - if (!bid.renderer && mediaType === VIDEO && deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { + if (!bid.renderer && bid.mediaType === VIDEO && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { result.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL, adUnitCode: bid.adUnitCode}); result.renderer.setRender(renderer); } @@ -305,7 +292,7 @@ function parseNative(bid) { function setOnAny(collection, key) { for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); + result = utils.deepAccess(collection[i], key); if (result) { return result; } diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index 4dd320d3f24..f43fd284bad 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,4 +1,4 @@ -import {tryAppendQueryString, getBidIdParameter} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; @@ -25,7 +25,7 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { - const ADGENE_PREBID_VERSION = '1.2.0'; + const ADGENE_PREBID_VERSION = '1.1.0'; let serverRequests = []; for (let i = 0, len = validBidRequests.length; i < len; i++) { const validReq = validBidRequests[i]; @@ -33,23 +33,23 @@ export const spec = { const URL = 'https://d.socdm.com/adsv/v1'; const url = validReq.params.debug ? DEBUG_URL : URL; let data = ``; - data = tryAppendQueryString(data, 'posall', 'SSPLOC'); - const id = getBidIdParameter('id', validReq.params); - data = tryAppendQueryString(data, 'id', id); - data = tryAppendQueryString(data, 'sdktype', '0'); - data = tryAppendQueryString(data, 'hb', 'true'); - data = tryAppendQueryString(data, 't', 'json3'); - data = tryAppendQueryString(data, 'transactionid', validReq.transactionId); - data = tryAppendQueryString(data, 'sizes', getSizes(validReq)); - data = tryAppendQueryString(data, 'currency', getCurrencyType()); - data = tryAppendQueryString(data, 'pbver', '$prebid.version$'); - data = tryAppendQueryString(data, 'sdkname', 'prebidjs'); - data = tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); + data = utils.tryAppendQueryString(data, 'posall', 'SSPLOC'); + const id = utils.getBidIdParameter('id', validReq.params); + data = utils.tryAppendQueryString(data, 'id', id); + data = utils.tryAppendQueryString(data, 'sdktype', '0'); + data = utils.tryAppendQueryString(data, 'hb', 'true'); + data = utils.tryAppendQueryString(data, 't', 'json3'); + data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId); + data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq)); + data = utils.tryAppendQueryString(data, 'currency', getCurrencyType()); + data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$'); + data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs'); + data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); // native以外にvideo等の対応が入った場合は要修正 if (!validReq.mediaTypes || !validReq.mediaTypes.native) { - data = tryAppendQueryString(data, 'imark', '1'); + data = utils.tryAppendQueryString(data, 'imark', '1'); } - data = tryAppendQueryString(data, 'tp', bidderRequest.refererInfo.referer); + data = utils.tryAppendQueryString(data, 'tp', bidderRequest.refererInfo.referer); // remove the trailing "&" if (data.lastIndexOf('&') === data.length - 1) { data = data.substring(0, data.length - 1); @@ -118,25 +118,13 @@ export const spec = { function createAd(body, bidRequest) { let ad = body.ad; if (body.vastxml && body.vastxml.length > 0) { - if (isUpperBillboard(body)) { - const marginTop = bidRequest.params.marginTop ? bidRequest.params.marginTop : '0'; - ad = `${createADGBrowserMTag()}${insertVASTMethodForADGBrowserM(body.vastxml, marginTop)}`; - } else { - ad = `
${createAPVTag()}${insertVASTMethodForAPV(bidRequest.bidId, body.vastxml)}`; - } + ad = `
${createAPVTag()}${insertVASTMethod(bidRequest.bidId, body.vastxml)}`; } ad = appendChildToBody(ad, body.beacon); if (removeWrapper(ad)) return removeWrapper(ad); return ad; } -function isUpperBillboard(body) { - if (body.location_params && body.location_params.option && body.location_params.option.ad_type) { - return body.location_params.option.ad_type === 'upper_billboard'; - } - return false; -} - function isNative(body) { if (!body) return false; return body.native_ad && body.native_ad.assets.length > 0; @@ -202,12 +190,7 @@ function createAPVTag() { return apvScript.outerHTML; } -function createADGBrowserMTag() { - const ADGBrowserMURL = 'https://i.socdm.com/sdk/js/adg-browser-m.js'; - return ``; -} - -function insertVASTMethodForAPV(targetId, vastXml) { +function insertVASTMethod(targetId, vastXml) { let apvVideoAdParam = { s: targetId }; @@ -217,13 +200,6 @@ function insertVASTMethodForAPV(targetId, vastXml) { return script.outerHTML; } -function insertVASTMethodForADGBrowserM(vastXml, marginTop) { - const script = document.createElement(`script`); - script.type = 'text/javascript'; - script.innerHTML = `window.ADGBrowserM.init({vastXml: '${vastXml.replace(/\r?\n/g, '')}', marginTop: '${marginTop}'});`; - return script.outerHTML; -} - /** * * @param ad diff --git a/modules/adhashBidAdapter.js b/modules/adhashBidAdapter.js deleted file mode 100644 index 6a8c98650c0..00000000000 --- a/modules/adhashBidAdapter.js +++ /dev/null @@ -1,105 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import includes from 'core-js-pure/features/array/includes.js'; -import { BANNER } from '../src/mediaTypes.js'; - -const VERSION = '1.0'; - -export const spec = { - code: 'adhash', - url: 'https://bidder.adhash.com/rtb?version=' + VERSION + '&prebid=true', - supportedMediaTypes: [ BANNER ], - - isBidRequestValid: (bid) => { - try { - const { publisherId, platformURL } = bid.params; - return ( - includes(Object.keys(bid.mediaTypes), BANNER) && - typeof publisherId === 'string' && - publisherId.length === 42 && - typeof platformURL === 'string' && - platformURL.length >= 13 - ); - } catch (error) { - return false; - } - }, - - buildRequests: (validBidRequests, bidderRequest) => { - const { gdprConsent } = bidderRequest; - const { url } = spec; - const bidRequests = []; - let referrer = ''; - if (bidderRequest && bidderRequest.refererInfo) { - referrer = bidderRequest.refererInfo.referer; - } - for (var i = 0; i < validBidRequests.length; i++) { - var index = Math.floor(Math.random() * validBidRequests[i].sizes.length); - var size = validBidRequests[i].sizes[index].join('x'); - bidRequests.push({ - method: 'POST', - url: url + '&publisher=' + validBidRequests[i].params.publisherId, - bidRequest: validBidRequests[i], - data: { - timezone: new Date().getTimezoneOffset() / 60, - location: referrer, - publisherId: validBidRequests[i].params.publisherId, - size: { - screenWidth: window.screen.width, - screenHeight: window.screen.height - }, - navigator: { - platform: window.navigator.platform, - language: window.navigator.language, - userAgent: window.navigator.userAgent - }, - creatives: [{ - size: size, - position: validBidRequests[i].adUnitCode - }], - blockedCreatives: [], - currentTimestamp: new Date().getTime(), - recentAds: [], - GDPR: gdprConsent - }, - options: { - withCredentials: false, - crossOrigin: true - }, - }); - } - return bidRequests; - }, - - interpretResponse: (serverResponse, request) => { - const responseBody = serverResponse ? serverResponse.body : {}; - - if (!responseBody.creatives || responseBody.creatives.length === 0) { - return []; - } - - const publisherURL = JSON.stringify(request.bidRequest.params.platformURL); - const oneTimeId = request.bidRequest.adUnitCode + Math.random().toFixed(16).replace('0.', '.'); - const bidderResponse = JSON.stringify({ responseText: JSON.stringify(responseBody) }); - const requestData = JSON.stringify(request.data); - - return [{ - requestId: request.bidRequest.bidId, - cpm: responseBody.creatives[0].costEUR, - ad: - `
- - `, - width: request.bidRequest.sizes[0][0], - height: request.bidRequest.sizes[0][1], - creativeId: request.bidRequest.adUnitCode, - netRevenue: true, - currency: 'EUR', - ttl: 60, - meta: { - advertiserDomains: responseBody.advertiserDomains ? [responseBody.advertiserDomains] : [] - } - }]; - } -}; - -registerBidder(spec); diff --git a/modules/adhashBidAdapter.md b/modules/adhashBidAdapter.md index 4ee6ed3dc83..c1093e0ccd7 100644 --- a/modules/adhashBidAdapter.md +++ b/modules/adhashBidAdapter.md @@ -34,7 +34,7 @@ Please note that a number of AdHash functionalities are not supported in the Pre bidder: 'adhash', params: { publisherId: '0x1234567890123456789012345678901234567890', - platformURL: 'https://adhash.org/p/example/' + platformURL: 'https://adhash.org/p/struma/' } } ] diff --git a/modules/adheseBidAdapter.js b/modules/adheseBidAdapter.js index 145b5605bc2..88f3e0e0e4f 100644 --- a/modules/adheseBidAdapter.js +++ b/modules/adheseBidAdapter.js @@ -2,7 +2,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import { config } from '../src/config.js'; const BIDDER_CODE = 'adhese'; const GVLID = 553; @@ -21,15 +20,11 @@ export const spec = { if (validBidRequests.length === 0) { return null; } - const { gdprConsent, refererInfo } = bidderRequest; - const adheseConfig = config.getConfig('adhese'); const gdprParams = (gdprConsent && gdprConsent.consentString) ? { xt: [gdprConsent.consentString] } : {}; const refererParams = (refererInfo && refererInfo.referer) ? { xf: [base64urlEncode(refererInfo.referer)] } : {}; - const globalCustomParams = (adheseConfig && adheseConfig.globalTargets) ? cleanTargets(adheseConfig.globalTargets) : {}; - const commonParams = { ...globalCustomParams, ...gdprParams, ...refererParams }; - const vastContentAsUrl = !(adheseConfig && adheseConfig.vastContentAsUrl == false); + const commonParams = { ...gdprParams, ...refererParams }; const slots = validBidRequests.map(bid => ({ slotname: bidToSlotName(bid), @@ -39,7 +34,7 @@ export const spec = { const payload = { slots: slots, parameters: commonParams, - vastContentAsUrl: vastContentAsUrl, + vastContentAsUrl: true, user: { ext: { eids: getEids(validBidRequests), diff --git a/modules/adkernelAdnAnalyticsAdapter.js b/modules/adkernelAdnAnalyticsAdapter.js index 2b4e67736f3..23501f7dd63 100644 --- a/modules/adkernelAdnAnalyticsAdapter.js +++ b/modules/adkernelAdnAnalyticsAdapter.js @@ -1,7 +1,7 @@ import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; -import { logError, parseUrl, _each } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; import {config} from '../src/config.js'; @@ -90,7 +90,7 @@ analyticsAdapter.originEnableAnalytics = analyticsAdapter.enableAnalytics; analyticsAdapter.enableAnalytics = (config) => { if (!config.options.pubId) { - logError('PubId is not defined. Analytics won\'t work'); + utils.logError('PubId is not defined. Analytics won\'t work'); return; } analyticsAdapter.context = { @@ -215,7 +215,7 @@ export function getUmtSource(pageUrl, referrer) { if (se) { return asUtm(se, ORGANIC, ORGANIC); } - let parsedUrl = parseUrl(pageUrl); + let parsedUrl = utils.parseUrl(pageUrl); let [refHost, refPath] = getReferrer(referrer); if (refHost && refHost !== parsedUrl.hostname) { return asUtm(refHost, REFERRAL, REFERRAL, '', refPath); @@ -242,17 +242,17 @@ export function getUmtSource(pageUrl, referrer) { } function getReferrer(referrer) { - let ref = parseUrl(referrer); + let ref = utils.parseUrl(referrer); return [ref.hostname, ref.pathname]; } function getUTM(pageUrl) { - let urlParameters = parseUrl(pageUrl).search; + let urlParameters = utils.parseUrl(pageUrl).search; if (!urlParameters['utm_campaign'] || !urlParameters['utm_source']) { return; } let utmArgs = []; - _each(UTM_TAGS, (utmTagName) => { + utils._each(UTM_TAGS, (utmTagName) => { let utmValue = urlParameters[utmTagName] || ''; utmArgs.push(utmValue); }); diff --git a/modules/adkernelAdnBidAdapter.js b/modules/adkernelAdnBidAdapter.js index 39f7b9fd2b2..dc56ed6abbb 100644 --- a/modules/adkernelAdnBidAdapter.js +++ b/modules/adkernelAdnBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, parseSizesInput, isArray, deepSetValue, parseUrl, isStr, isNumber, logInfo } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; @@ -19,12 +19,12 @@ function buildImp(bidRequest) { tagid: bidRequest.adUnitCode }; let mediaType; - let bannerReq = deepAccess(bidRequest, `mediaTypes.banner`); - let videoReq = deepAccess(bidRequest, `mediaTypes.video`); + let bannerReq = utils.deepAccess(bidRequest, `mediaTypes.banner`); + let videoReq = utils.deepAccess(bidRequest, `mediaTypes.video`); if (bannerReq) { let sizes = canonicalizeSizesArray(bannerReq.sizes); imp.banner = { - format: parseSizesInput(sizes) + format: utils.parseSizesInput(sizes) }; mediaType = BANNER; } else if (videoReq) { @@ -51,7 +51,7 @@ function buildImp(bidRequest) { * @return Array[Array[Number]] */ function canonicalizeSizesArray(sizes) { - if (sizes.length === 2 && !isArray(sizes[0])) { + if (sizes.length === 2 && !utils.isArray(sizes[0])) { return [sizes]; } return sizes; @@ -67,23 +67,23 @@ function buildRequestParams(tags, bidderRequest) { }; if (gdprConsent) { if (gdprConsent.gdprApplies !== undefined) { - deepSetValue(req, 'user.gdpr', ~~gdprConsent.gdprApplies); + utils.deepSetValue(req, 'user.gdpr', ~~gdprConsent.gdprApplies); } if (gdprConsent.consentString !== undefined) { - deepSetValue(req, 'user.consent', gdprConsent.consentString); + utils.deepSetValue(req, 'user.consent', gdprConsent.consentString); } } if (uspConsent) { - deepSetValue(req, 'user.us_privacy', uspConsent); + utils.deepSetValue(req, 'user.us_privacy', uspConsent); } if (config.getConfig('coppa')) { - deepSetValue(req, 'user.coppa', 1); + utils.deepSetValue(req, 'user.coppa', 1); } return req; } function buildSite(refInfo) { - let loc = parseUrl(refInfo.referer); + let loc = utils.parseUrl(refInfo.referer); let result = { page: `${loc.protocol}://${loc.hostname}${loc.pathname}`, secure: ~~(loc.protocol === 'https') @@ -126,23 +126,23 @@ function buildBid(tag) { } function fillBidMeta(bid, tag) { - if (isStr(tag.agencyName)) { - deepSetValue(bid, 'meta.agencyName', tag.agencyName); + if (utils.isStr(tag.agencyName)) { + utils.deepSetValue(bid, 'meta.agencyName', tag.agencyName); } - if (isNumber(tag.advertiserId)) { - deepSetValue(bid, 'meta.advertiserId', tag.advertiserId); + if (utils.isNumber(tag.advertiserId)) { + utils.deepSetValue(bid, 'meta.advertiserId', tag.advertiserId); } - if (isStr(tag.advertiserName)) { - deepSetValue(bid, 'meta.advertiserName', tag.advertiserName); + if (utils.isStr(tag.advertiserName)) { + utils.deepSetValue(bid, 'meta.advertiserName', tag.advertiserName); } - if (isArray(tag.advertiserDomains)) { - deepSetValue(bid, 'meta.advertiserDomains', tag.advertiserDomains); + if (utils.isArray(tag.advertiserDomains)) { + utils.deepSetValue(bid, 'meta.advertiserDomains', tag.advertiserDomains); } - if (isStr(tag.primaryCatId)) { - deepSetValue(bid, 'meta.primaryCatId', tag.primaryCatId); + if (utils.isStr(tag.primaryCatId)) { + utils.deepSetValue(bid, 'meta.primaryCatId', tag.primaryCatId); } - if (isArray(tag.secondaryCatIds)) { - deepSetValue(bid, 'meta.secondaryCatIds', tag.secondaryCatIds); + if (utils.isArray(tag.secondaryCatIds)) { + utils.deepSetValue(bid, 'meta.secondaryCatIds', tag.secondaryCatIds); } } @@ -204,7 +204,7 @@ export const spec = { return []; } if (response.debug) { - logInfo(`ADKERNEL DEBUG:\n${response.debug}`); + utils.logInfo(`ADKERNEL DEBUG:\n${response.debug}`); } return response.tags.map(buildBid); }, diff --git a/modules/adkernelBidAdapter.js b/modules/adkernelBidAdapter.js index c23eca2f96a..5cfb44f7127 100644 --- a/modules/adkernelBidAdapter.js +++ b/modules/adkernelBidAdapter.js @@ -1,7 +1,4 @@ -import { - isStr, isArray, isPlainObject, deepSetValue, isNumber, deepAccess, getAdUnitSizes, parseGPTSingleSizeArrayToRtbSize, - cleanObj, contains, getDNT, parseUrl, createTrackPixelHtml, _each, isArrayOfNums, mergeDeep, isEmpty, inIframe -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import find from 'core-js-pure/features/array/find.js'; @@ -73,12 +70,7 @@ export const spec = { {code: 'converge', gvlid: 248}, {code: 'adomega'}, {code: 'denakop'}, - {code: 'rtbanalytica'}, - {code: 'unibots'}, - {code: 'catapultx'}, - {code: 'ergadx'}, - {code: 'turktelekom'}, - {code: 'felixads'} + {code: 'rtbanalytica'} ], supportedMediaTypes: [BANNER, VIDEO, NATIVE], @@ -104,16 +96,17 @@ export const spec = { * @returns {ServerRequest[]} */ buildRequests: function (bidRequests, bidderRequest) { - let impGroups = groupImpressionsByHostZone(bidRequests, bidderRequest.refererInfo); + let impDispatch = dispatchImps(bidRequests, bidderRequest.refererInfo); let requests = []; let schain = bidRequests[0].schain; - _each(impGroups, impGroup => { - let {host, zoneId, imps} = impGroup; - const request = buildRtbRequest(imps, bidderRequest, schain); - requests.push({ - method: 'POST', - url: `https://${host}/hb?zone=${zoneId}&v=${VERSION}`, - data: JSON.stringify(request) + Object.keys(impDispatch).forEach(host => { + Object.keys(impDispatch[host]).forEach(zoneId => { + const request = buildRtbRequest(impDispatch[host][zoneId], bidderRequest, schain); + requests.push({ + method: 'POST', + url: `https://${host}/hb?zone=${zoneId}&v=${VERSION}`, + data: JSON.stringify(request) + }); }); }); return requests; @@ -160,24 +153,24 @@ export const spec = { prBid.mediaType = NATIVE; prBid.native = buildNativeAd(JSON.parse(rtbBid.adm)); } - if (isStr(rtbBid.dealid)) { + if (utils.isStr(rtbBid.dealid)) { prBid.dealId = rtbBid.dealid; } - if (isArray(rtbBid.adomain)) { - deepSetValue(prBid, 'meta.advertiserDomains', rtbBid.adomain); + if (utils.isArray(rtbBid.adomain)) { + utils.deepSetValue(prBid, 'meta.advertiserDomains', rtbBid.adomain); } - if (isArray(rtbBid.cat)) { - deepSetValue(prBid, 'meta.secondaryCatIds', rtbBid.cat); + if (utils.isArray(rtbBid.cat)) { + utils.deepSetValue(prBid, 'meta.secondaryCatIds', rtbBid.cat); } - if (isPlainObject(rtbBid.ext)) { - if (isNumber(rtbBid.ext.advertiser_id)) { - deepSetValue(prBid, 'meta.advertiserId', rtbBid.ext.advertiser_id); + if (utils.isPlainObject(rtbBid.ext)) { + if (utils.isNumber(rtbBid.ext.advertiser_id)) { + utils.deepSetValue(prBid, 'meta.advertiserId', rtbBid.ext.advertiser_id); } - if (isStr(rtbBid.ext.advertiser_name)) { - deepSetValue(prBid, 'meta.advertiserName', rtbBid.ext.advertiser_name); + if (utils.isStr(rtbBid.ext.advertiser_name)) { + utils.deepSetValue(prBid, 'meta.advertiserName', rtbBid.ext.advertiser_name); } - if (isStr(rtbBid.ext.agency_name)) { - deepSetValue(prBid, 'meta.agencyName', rtbBid.ext.agency_name); + if (utils.isStr(rtbBid.ext.agency_name)) { + utils.deepSetValue(prBid, 'meta.agencyName', rtbBid.ext.agency_name); } } @@ -209,19 +202,17 @@ registerBidder(spec); * @param bidRequests {BidRequest[]} * @param refererInfo {refererInfo} */ -function groupImpressionsByHostZone(bidRequests, refererInfo) { +function dispatchImps(bidRequests, refererInfo) { let secure = (refererInfo && refererInfo.referer.indexOf('https:') === 0); - return Object.values( - bidRequests.map(bidRequest => buildImp(bidRequest, secure)) - .reduce((acc, curr, index) => { - let bidRequest = bidRequests[index]; - let {zoneId, host} = bidRequest.params; - let key = `${host}_${zoneId}`; - acc[key] = acc[key] || {host: host, zoneId: zoneId, imps: []}; - acc[key].imps.push(curr); - return acc; - }, {}) - ); + return bidRequests.map(bidRequest => buildImp(bidRequest, secure)) + .reduce((acc, curr, index) => { + let bidRequest = bidRequests[index]; + let {zoneId, host} = bidRequest.params; + acc[host] = acc[host] || {}; + acc[host][zoneId] = acc[host][zoneId] || []; + acc[host][zoneId].push(curr); + return acc; + }, {}); } function getBidFloor(bid, mediaType, sizes) { @@ -249,19 +240,19 @@ function buildImp(bidRequest, secure) { var mediaType; var sizes = []; - if (deepAccess(bidRequest, 'mediaTypes.banner')) { - sizes = getAdUnitSizes(bidRequest); + if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { + sizes = utils.getAdUnitSizes(bidRequest); imp.banner = { - format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)), + format: sizes.map(wh => utils.parseGPTSingleSizeArrayToRtbSize(wh)), topframe: 0 }; mediaType = BANNER; - } else if (deepAccess(bidRequest, 'mediaTypes.video')) { - let video = deepAccess(bidRequest, 'mediaTypes.video'); + } else if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { + let video = utils.deepAccess(bidRequest, 'mediaTypes.video'); imp.video = {}; if (video.playerSize) { sizes = video.playerSize[0]; - imp.video = Object.assign(imp.video, parseGPTSingleSizeArrayToRtbSize(sizes) || {}); + imp.video = Object.assign(imp.video, utils.parseGPTSingleSizeArrayToRtbSize(sizes) || {}); } if (bidRequest.params.video) { Object.keys(bidRequest.params.video) @@ -269,7 +260,7 @@ function buildImp(bidRequest, secure) { .forEach(key => imp.video[key] = bidRequest.params.video[key]); } mediaType = VIDEO; - } else if (deepAccess(bidRequest, 'mediaTypes.native')) { + } else if (utils.deepAccess(bidRequest, 'mediaTypes.native')) { let nativeRequest = buildNativeRequest(bidRequest.mediaTypes.native); imp.native = { ver: '1.1', @@ -307,7 +298,7 @@ function buildNativeRequest(nativeReq) { if (desc.assetType === 'img') { assetRoot[desc.assetType] = buildImageAsset(desc, v); } else if (desc.assetType === 'data') { - assetRoot.data = cleanObj({type: desc.type, len: v.len}); + assetRoot.data = utils.cleanObj({type: desc.type, len: v.len}); } else if (desc.assetType === 'title') { assetRoot.title = {len: v.len || 90}; } else { @@ -331,7 +322,7 @@ function buildImageAsset(desc, val) { img.wmin = val.aspect_ratios[0].min_width; img.hmin = val.aspect_ratios[0].min_height; } - return cleanObj(img); + return utils.cleanObj(img); } /** @@ -344,9 +335,9 @@ function isSyncMethodAllowed(syncRule, bidderCode) { if (!syncRule) { return false; } - let bidders = isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; + let bidders = utils.isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; let rule = syncRule.filter === 'include'; - return contains(bidders, bidderCode) === rule; + return utils.contains(bidders, bidderCode) === rule; } /** @@ -367,141 +358,56 @@ function getAllowedSyncMethod(bidderCode) { } /** - * Create device object from fpd and host-collected data - * @param fpd {Object} - * @returns {{device: Object}} - */ -function makeDevice(fpd) { - let device = mergeDeep({ - 'ip': 'caller', - 'ipv6': 'caller', - 'ua': 'caller', - 'js': 1, - 'language': getLanguage() - }, fpd.device || {}); - if (getDNT()) { - device.dnt = 1; - } - return {device: device}; -} - -/** - * Create site or app description object - * @param bidderRequest {BidderRequest} - * @param fpd {Object} - * @returns {{site: Object}|{app: Object}} - */ -function makeSiteOrApp(bidderRequest, fpd) { - let {refererInfo} = bidderRequest; - let appConfig = config.getConfig('app'); - if (isEmpty(appConfig)) { - return {site: createSite(refererInfo, fpd)} - } else { - return {app: appConfig}; - } -} - -/** - * Create user description object + * Builds complete rtb request + * @param imps {Object} Collection of rtb impressions * @param bidderRequest {BidderRequest} - * @param fpd {Object} - * @returns {{user: Object} | undefined} + * @param schain {Object=} Supply chain config + * @return {Object} Complete rtb request */ -function makeUser(bidderRequest, fpd) { - let {gdprConsent} = bidderRequest; - let user = fpd.user || {}; - if (gdprConsent && gdprConsent.consentString !== undefined) { - deepSetValue(user, 'ext.consent', gdprConsent.consentString); - } - let eids = getExtendedUserIds(bidderRequest); - if (eids) { - deepSetValue(user, 'ext.eids', eids); +function buildRtbRequest(imps, bidderRequest, schain) { + let {bidderCode, gdprConsent, auctionId, refererInfo, timeout, uspConsent} = bidderRequest; + let coppa = config.getConfig('coppa'); + let req = { + 'id': auctionId, + 'imp': imps, + 'site': createSite(refererInfo), + 'at': 1, + 'device': { + 'ip': 'caller', + 'ipv6': 'caller', + 'ua': 'caller', + 'js': 1, + 'language': getLanguage() + }, + 'tmax': parseInt(timeout) + }; + if (utils.getDNT()) { + req.device.dnt = 1; } - if (!isEmpty(user)) { return {user: user}; } -} - -/** - * Create privacy regulations object - * @param bidderRequest {BidderRequest} - * @returns {{regs: Object} | undefined} - */ -function makeRegulations(bidderRequest) { - let {gdprConsent, uspConsent} = bidderRequest; - let regs = {}; if (gdprConsent) { if (gdprConsent.gdprApplies !== undefined) { - deepSetValue(regs, 'regs.ext.gdpr', ~~gdprConsent.gdprApplies); + utils.deepSetValue(req, 'regs.ext.gdpr', ~~gdprConsent.gdprApplies); + } + if (gdprConsent.consentString !== undefined) { + utils.deepSetValue(req, 'user.ext.consent', gdprConsent.consentString); } } if (uspConsent) { - deepSetValue(regs, 'regs.ext.us_privacy', uspConsent); - } - if (config.getConfig('coppa')) { - deepSetValue(regs, 'regs.coppa', 1); - } - if (!isEmpty(regs)) { - return regs; + utils.deepSetValue(req, 'regs.ext.us_privacy', uspConsent); } -} - -/** - * Create top-level request object - * @param bidderRequest {BidderRequest} - * @param imps {Object} Impressions - * @param fpd {Object} First party data - * @returns - */ -function makeBaseRequest(bidderRequest, imps, fpd) { - let {auctionId, timeout} = bidderRequest; - let request = { - 'id': auctionId, - 'imp': imps, - 'at': 1, - 'tmax': parseInt(timeout) - }; - if (!isEmpty(fpd.bcat)) { - request.bcat = fpd.bcat; - } - if (!isEmpty(fpd.badv)) { - request.badv = fpd.badv; + if (coppa) { + utils.deepSetValue(req, 'regs.coppa', 1); } - return request; -} - -/** - * Initialize sync capabilities - * @param bidderRequest {BidderRequest} - */ -function makeSyncInfo(bidderRequest) { - let {bidderCode} = bidderRequest; let syncMethod = getAllowedSyncMethod(bidderCode); if (syncMethod) { - let res = {}; - deepSetValue(res, 'ext.adk_usersync', syncMethod); - return res; + utils.deepSetValue(req, 'ext.adk_usersync', syncMethod); } -} - -/** - * Builds complete rtb request - * @param imps {Object} Collection of rtb impressions - * @param bidderRequest {BidderRequest} - * @param schain {Object=} Supply chain config - * @return {Object} Complete rtb request - */ -function buildRtbRequest(imps, bidderRequest, schain) { - let fpd = config.getConfig('ortb2') || {}; - - let req = mergeDeep( - makeBaseRequest(bidderRequest, imps, fpd), - makeDevice(fpd), - makeSiteOrApp(bidderRequest, fpd), - makeUser(bidderRequest, fpd), - makeRegulations(bidderRequest), - makeSyncInfo(bidderRequest) - ); if (schain) { - deepSetValue(req, 'source.ext.schain', schain); + utils.deepSetValue(req, 'source.ext.schain', schain); + } + let eids = getExtendedUserIds(bidderRequest); + if (eids) { + utils.deepSetValue(req, 'user.ext.eids', eids); } return req; } @@ -518,24 +424,25 @@ function getLanguage() { /** * Creates site description object */ -function createSite(refInfo, fpd) { - let url = parseUrl(refInfo.referer); +function createSite(refInfo) { + let url = utils.parseUrl(refInfo.referer); let site = { 'domain': url.hostname, 'page': `${url.protocol}://${url.hostname}${url.pathname}` }; - mergeDeep(site, fpd.site); - if (!inIframe() && document.referrer) { + if (self === top && document.referrer) { site.ref = document.referrer; - } else { - delete site.ref; + } + let keywords = document.getElementsByTagName('meta')['keywords']; + if (keywords && keywords.content) { + site.keywords = keywords.content; } return site; } function getExtendedUserIds(bidderRequest) { - let eids = deepAccess(bidderRequest, 'bids.0.userIdAsEids'); - if (isArray(eids)) { + let eids = utils.deepAccess(bidderRequest, 'bids.0.userIdAsEids'); + if (utils.isArray(eids)) { return eids; } } @@ -547,7 +454,7 @@ function getExtendedUserIds(bidderRequest) { function formatAdMarkup(bid) { let adm = bid.adm; if ('nurl' in bid) { - adm += createTrackPixelHtml(`${bid.nurl}&px=1`); + adm += utils.createTrackPixelHtml(`${bid.nurl}&px=1`); } return adm; } @@ -557,8 +464,8 @@ function formatAdMarkup(bid) { */ function validateNativeAdUnit(adUnit) { return validateNativeImageSize(adUnit.image) && validateNativeImageSize(adUnit.icon) && - !deepAccess(adUnit, 'privacyLink.required') && // not supported yet - !deepAccess(adUnit, 'privacyIcon.required'); // not supported yet + !utils.deepAccess(adUnit, 'privacyLink.required') && // not supported yet + !utils.deepAccess(adUnit, 'privacyIcon.required'); // not supported yet } /** @@ -569,9 +476,9 @@ function validateNativeImageSize(img) { return true; } if (img.sizes) { - return isArrayOfNums(img.sizes, 2); + return utils.isArrayOfNums(img.sizes, 2); } - if (isArray(img.aspect_ratios)) { + if (utils.isArray(img.aspect_ratios)) { return img.aspect_ratios.length > 0 && img.aspect_ratios[0].min_height && img.aspect_ratios[0].min_width; } return true; @@ -588,14 +495,14 @@ function buildNativeAd(nativeResp) { javascriptTrackers: jstracker ? [jstracker] : undefined, privacyLink: privacy, }; - _each(assets, asset => { + utils._each(assets, asset => { let assetName = NATIVE_MODEL[asset.id].name; let assetType = NATIVE_MODEL[asset.id].assetType; - nativeAd[assetName] = asset[assetType].text || asset[assetType].value || cleanObj({ + nativeAd[assetName] = asset[assetType].text || asset[assetType].value || utils.cleanObj({ url: asset[assetType].url, width: asset[assetType].w, height: asset[assetType].h }); }); - return cleanObj(nativeAd); + return utils.cleanObj(nativeAd); } diff --git a/modules/adlivetechBidAdapter.md b/modules/adlivetechBidAdapter.md deleted file mode 100644 index 612e669ea1a..00000000000 --- a/modules/adlivetechBidAdapter.md +++ /dev/null @@ -1,61 +0,0 @@ -# Overview - -Module Name: Adlivetech Bidder Adapter -Module Type: Bidder Adapter -Maintainer: grid-tech@themediagrid.com - -# Description - -Module that connects to Grid demand source to fetch bids. -The adapter is GDPR compliant and supports banner and video (instream and outstream). - -# Test Parameters -``` - var adUnits = [ - { - code: 'test-div', - sizes: [[300, 250]], - bids: [ - { - bidder: "adlivetech", - params: { - uid: '1', - bidFloor: 0.5 - } - } - ] - },{ - code: 'test-div', - sizes: [[728, 90]], - bids: [ - { - bidder: "adlivetech", - params: { - uid: 2, - keywords: { - brandsafety: ['disaster'], - topic: ['stress', 'fear'] - } - } - } - ] - }, - { - code: 'test-div', - sizes: [[728, 90]], - mediaTypes: { video: { - context: 'instream', - playerSize: [728, 90], - mimes: ['video/mp4'] - }, - bids: [ - { - bidder: "adlivetech", - params: { - uid: 11 - } - } - ] - } - ]; -``` diff --git a/modules/adlooxAdServerVideo.js b/modules/adlooxAdServerVideo.js index bd715cb34f3..2a61e59b714 100644 --- a/modules/adlooxAdServerVideo.js +++ b/modules/adlooxAdServerVideo.js @@ -9,50 +9,50 @@ import { registerVideoSupport } from '../src/adServerManager.js'; import { command as analyticsCommand, COMMAND } from './adlooxAnalyticsAdapter.js'; import { ajax } from '../src/ajax.js'; -import CONSTANTS from '../src/constants.json'; +import { EVENTS } from '../src/constants.json'; import { targeting } from '../src/targeting.js'; -import { logInfo, isFn, logError, isPlainObject, isStr, isBoolean, deepSetValue, deepClone, timestamp, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const MODULE = 'adlooxAdserverVideo'; const URL_VAST = 'https://j.adlooxtracking.com/ads/vast/tag.php'; export function buildVideoUrl(options, callback) { - logInfo(MODULE, 'buildVideoUrl', options); + utils.logInfo(MODULE, 'buildVideoUrl', options); - if (!isFn(callback)) { - logError(MODULE, 'invalid callback'); + if (!utils.isFn(callback)) { + utils.logError(MODULE, 'invalid callback'); return false; } - if (!isPlainObject(options)) { - logError(MODULE, 'missing options'); + if (!utils.isPlainObject(options)) { + utils.logError(MODULE, 'missing options'); return false; } - if (!(options.url_vast === undefined || isStr(options.url_vast))) { - logError(MODULE, 'invalid url_vast options value'); + if (!(options.url_vast === undefined || utils.isStr(options.url_vast))) { + utils.logError(MODULE, 'invalid url_vast options value'); return false; } - if (!(isPlainObject(options.adUnit) || isPlainObject(options.bid))) { - logError(MODULE, "requires either 'adUnit' or 'bid' options value"); + if (!(utils.isPlainObject(options.adUnit) || utils.isPlainObject(options.bid))) { + utils.logError(MODULE, "requires either 'adUnit' or 'bid' options value"); return false; } - if (!isStr(options.url)) { - logError(MODULE, 'invalid url options value'); + if (!utils.isStr(options.url)) { + utils.logError(MODULE, 'invalid url options value'); return false; } - if (!(options.wrap === undefined || isBoolean(options.wrap))) { - logError(MODULE, 'invalid wrap options value'); + if (!(options.wrap === undefined || utils.isBoolean(options.wrap))) { + utils.logError(MODULE, 'invalid wrap options value'); return false; } - if (!(options.blob === undefined || isBoolean(options.blob))) { - logError(MODULE, 'invalid blob options value'); + if (!(options.blob === undefined || utils.isBoolean(options.blob))) { + utils.logError(MODULE, 'invalid blob options value'); return false; } // same logic used in modules/dfpAdServerVideo.js options.bid = options.bid || targeting.getWinningBids(options.adUnit.code)[0]; - deepSetValue(options.bid, 'ext.adloox.video.adserver', true); + utils.deepSetValue(options.bid, 'ext.adloox.video.adserver', true); if (options.wrap !== false) { VASTWrapper(options, callback); @@ -70,11 +70,11 @@ registerVideoSupport('adloox', { function track(options, callback) { callback(options.url); - const bid = deepClone(options.bid); + const bid = utils.deepClone(options.bid); bid.ext.adloox.video.adserver = false; analyticsCommand(COMMAND.TRACK, { - eventType: CONSTANTS.EVENTS.BID_WON, + eventType: EVENTS.BID_WON, args: bid }); } @@ -85,13 +85,13 @@ function VASTWrapper(options, callback) { function process(result) { function getAd(xml) { if (!xml || xml.documentElement.tagName != 'VAST') { - logError(MODULE, 'not a VAST tag, using non-wrapped tracking'); + utils.logError(MODULE, 'not a VAST tag, using non-wrapped tracking'); return; } const ads = xml.querySelectorAll('Ad'); if (!ads.length) { - logError(MODULE, 'no VAST ads, using non-wrapped tracking'); + utils.logError(MODULE, 'no VAST ads, using non-wrapped tracking'); return; } @@ -132,7 +132,7 @@ function VASTWrapper(options, callback) { options.url = toBlob(chain[0]); - const epoch = timestamp() - new Date().getTimezoneOffset() * 60 * 1000; + const epoch = utils.timestamp() - new Date().getTimezoneOffset() * 60 * 1000; const expires0 = options.bid.ttl * 1000 - (epoch - options.bid.responseTimestamp); const expires = Math.max(30 * 1000, expires0); setTimeout(function() { urls.forEach(u => URL.revokeObjectURL(u)) }, expires); @@ -154,7 +154,7 @@ function VASTWrapper(options, callback) { const wrapper = getWrapper(ad); if (wrapper) { if (chain.length > 5) { - logWarn(MODULE, `got wrapped tag at depth ${chain.length}, not continuing`); + utils.logWarn(MODULE, `got wrapped tag at depth ${chain.length}, not continuing`); blobify(); return track(options, callback); } @@ -191,7 +191,7 @@ function VASTWrapper(options, callback) { if (duration != 15) args.push([ 'duration', duration ]); if (skip) args.push([ 'skip', skip ]); - logInfo(MODULE, `processed VAST tag chain of depth ${chain.depth}, running callback`); + utils.logInfo(MODULE, `processed VAST tag chain of depth ${chain.depth}, running callback`); analyticsCommand(COMMAND.URL, { url: (options.url_vast || URL_VAST) + '?', @@ -202,7 +202,7 @@ function VASTWrapper(options, callback) { } function fetch(url, withoutcredentials) { - logInfo(MODULE, `fetching VAST ${url}`); + utils.logInfo(MODULE, `fetching VAST ${url}`); ajax(url, { success: function(responseText, q) { @@ -210,10 +210,10 @@ function VASTWrapper(options, callback) { }, error: function(statusText, q) { if (!withoutcredentials) { - logWarn(MODULE, `unable to download (${statusText}), suspected CORS withCredentials problem, retrying without`); + utils.logWarn(MODULE, `unable to download (${statusText}), suspected CORS withCredentials problem, retrying without`); return fetch(url, true); } - logError(MODULE, `failed to fetch (${statusText}), using non-wrapped tracking`); + utils.logError(MODULE, `failed to fetch (${statusText}), using non-wrapped tracking`); process(); } }, undefined, { withCredentials: !withoutcredentials }); diff --git a/modules/adlooxAnalyticsAdapter.js b/modules/adlooxAnalyticsAdapter.js index 781b8db830a..cfd01b4434a 100644 --- a/modules/adlooxAnalyticsAdapter.js +++ b/modules/adlooxAnalyticsAdapter.js @@ -9,12 +9,9 @@ import adapter from '../src/AnalyticsAdapter.js'; import { loadExternalScript } from '../src/adloader.js'; import { auctionManager } from '../src/auctionManager.js'; import { AUCTION_COMPLETED } from '../src/auction.js'; -import CONSTANTS from '../src/constants.json'; +import { EVENTS } from '../src/constants.json'; import find from 'core-js-pure/features/array/find.js'; -import { - deepAccess, logInfo, isPlainObject, logError, isStr, isNumber, getGptSlotInfoForAdUnitCode, - isFn, mergeDeep, logMessage, insertElement, logWarn, getUniqueIdentifierStr, parseUrl -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; const MODULE = 'adlooxAnalyticsAdapter'; @@ -46,15 +43,14 @@ MACRO['targetelt'] = function(b, c) { MACRO['creatype'] = function(b, c) { return b.mediaType == 'video' ? ADLOOX_MEDIATYPE.VIDEO : ADLOOX_MEDIATYPE.DISPLAY; }; -MACRO['pbadslot'] = function(b, c) { +MACRO['pbAdSlot'] = function(b, c) { const adUnit = find(auctionManager.getAdUnits(), a => b.adUnitCode === a.code); - return deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot') || getGptSlotInfoForAdUnitCode(b.adUnitCode).gptSlot || b.adUnitCode; + return utils.deepAccess(adUnit, 'fpd.context.pbAdSlot') || utils.getGptSlotInfoForAdUnitCode(b.adUnitCode).gptSlot || b.adUnitCode; }; -MACRO['pbAdSlot'] = MACRO['pbadslot']; // legacy const PARAMS_DEFAULT = { 'id1': function(b) { return b.adUnitCode }, - 'id2': '%%pbadslot%%', + 'id2': '%%pbAdSlot%%', 'id3': function(b) { return b.bidder }, 'id4': function(b) { return b.adId }, 'id5': function(b) { return b.dealId }, @@ -69,7 +65,7 @@ let analyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoint' }), { track({ eventType, args }) { if (!analyticsAdapter[`handle_${eventType}`]) return; - logInfo(MODULE, 'track', eventType, args); + utils.logInfo(MODULE, 'track', eventType, args); analyticsAdapter[`handle_${eventType}`](args); } @@ -81,45 +77,45 @@ analyticsAdapter.originEnableAnalytics = analyticsAdapter.enableAnalytics; analyticsAdapter.enableAnalytics = function(config) { analyticsAdapter.context = null; - logInfo(MODULE, 'config', config); + utils.logInfo(MODULE, 'config', config); - if (!isPlainObject(config.options)) { - logError(MODULE, 'missing options'); + if (!utils.isPlainObject(config.options)) { + utils.logError(MODULE, 'missing options'); return; } - if (!(config.options.js === undefined || isStr(config.options.js))) { - logError(MODULE, 'invalid js options value'); + if (!(config.options.js === undefined || utils.isStr(config.options.js))) { + utils.logError(MODULE, 'invalid js options value'); return; } - if (!(config.options.toselector === undefined || isFn(config.options.toselector))) { - logError(MODULE, 'invalid toselector options value'); + if (!(config.options.toselector === undefined || utils.isFn(config.options.toselector))) { + utils.logError(MODULE, 'invalid toselector options value'); return; } - if (!isStr(config.options.client)) { - logError(MODULE, 'invalid client options value'); + if (!utils.isStr(config.options.client)) { + utils.logError(MODULE, 'invalid client options value'); return; } - if (!isNumber(config.options.clientid)) { - logError(MODULE, 'invalid clientid options value'); + if (!utils.isNumber(config.options.clientid)) { + utils.logError(MODULE, 'invalid clientid options value'); return; } - if (!isNumber(config.options.tagid)) { - logError(MODULE, 'invalid tagid options value'); + if (!utils.isNumber(config.options.tagid)) { + utils.logError(MODULE, 'invalid tagid options value'); return; } - if (!isNumber(config.options.platformid)) { - logError(MODULE, 'invalid platformid options value'); + if (!utils.isNumber(config.options.platformid)) { + utils.logError(MODULE, 'invalid platformid options value'); return; } - if (!(config.options.params === undefined || isPlainObject(config.options.params))) { - logError(MODULE, 'invalid params options value'); + if (!(config.options.params === undefined || utils.isPlainObject(config.options.params))) { + utils.logError(MODULE, 'invalid params options value'); return; } analyticsAdapter.context = { js: config.options.js || URL_JS, toselector: config.options.toselector || function(bid) { - let code = getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId || bid.adUnitCode; + let code = utils.getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId || bid.adUnitCode; // https://mathiasbynens.be/notes/css-escapes code = code.replace(/^\d/, '\\3$& '); return `#${code}` @@ -131,7 +127,7 @@ analyticsAdapter.enableAnalytics = function(config) { params: [] }; - config.options.params = mergeDeep({}, PARAMS_DEFAULT, config.options.params || {}); + config.options.params = utils.mergeDeep({}, PARAMS_DEFAULT, config.options.params || {}); Object .keys(config.options.params) .forEach(k => { @@ -183,15 +179,15 @@ analyticsAdapter.url = function(url, args, bid) { let n = args.length; while (n-- > 0) { - if (isFn(args[n][1])) { + if (utils.isFn(args[n][1])) { try { args[n][1] = args[n][1](bid); } catch (_) { - logError(MODULE, 'macro', args[n][0], _.message); + utils.logError(MODULE, 'macro', args[n][0], _.message); args[n][1] = `ERROR: ${_.message}`; } } - if (isStr(args[n][1])) { + if (utils.isStr(args[n][1])) { args[n][1] = macros(args[n][1]); } } @@ -199,24 +195,24 @@ analyticsAdapter.url = function(url, args, bid) { return url + a2qs(args); } -analyticsAdapter[`handle_${CONSTANTS.EVENTS.AUCTION_END}`] = function(auctionDetails) { +analyticsAdapter[`handle_${EVENTS.AUCTION_END}`] = function(auctionDetails) { if (!(auctionDetails.auctionStatus == AUCTION_COMPLETED && auctionDetails.bidsReceived.length > 0)) return; - analyticsAdapter[`handle_${CONSTANTS.EVENTS.AUCTION_END}`] = NOOP; + analyticsAdapter[`handle_${EVENTS.AUCTION_END}`] = NOOP; - logMessage(MODULE, 'preloading verification JS'); + utils.logMessage(MODULE, 'preloading verification JS'); - const uri = parseUrl(analyticsAdapter.url(`${analyticsAdapter.context.js}#`)); + const uri = utils.parseUrl(analyticsAdapter.url(`${analyticsAdapter.context.js}#`)); const link = document.createElement('link'); link.setAttribute('href', `${uri.protocol}://${uri.host}${uri.pathname}`); link.setAttribute('rel', 'preload'); link.setAttribute('as', 'script'); - insertElement(link); + utils.insertElement(link); } -analyticsAdapter[`handle_${CONSTANTS.EVENTS.BID_WON}`] = function(bid) { - if (deepAccess(bid, 'ext.adloox.video.adserver')) { - logMessage(MODULE, `measuring '${bid.mediaType}' ad unit code '${bid.adUnitCode}' via Ad Server module`); +analyticsAdapter[`handle_${EVENTS.BID_WON}`] = function(bid) { + if (utils.deepAccess(bid, 'ext.adloox.video.adserver')) { + utils.logMessage(MODULE, `measuring '${bid.mediaType}' ad unit code '${bid.adUnitCode}' via Ad Server module`); return; } @@ -226,11 +222,11 @@ analyticsAdapter[`handle_${CONSTANTS.EVENTS.BID_WON}`] = function(bid) { el = document.querySelector(sl); } catch (_) { } if (!el) { - logWarn(MODULE, `unable to find ad unit code '${bid.adUnitCode}' slot using selector '${sl}' (use options.toselector to change), ignoring`); + utils.logWarn(MODULE, `unable to find ad unit code '${bid.adUnitCode}' slot using selector '${sl}' (use options.toselector to change), ignoring`); return; } - logMessage(MODULE, `measuring '${bid.mediaType}' unit at '${bid.adUnitCode}'`); + utils.logMessage(MODULE, `measuring '${bid.mediaType}' unit at '${bid.adUnitCode}'`); const params = analyticsAdapter.context.params.concat([ [ 'tagid', '%%tagid%%' ], @@ -255,12 +251,11 @@ export default analyticsAdapter; const COMMAND_QUEUE = {}; export const COMMAND = { CONFIG: 'config', - TOSELECTOR: 'toselector', URL: 'url', TRACK: 'track' }; export function command(cmd, data, callback0) { - const cid = getUniqueIdentifierStr(); + const cid = utils.getUniqueIdentifierStr(); const callback = function() { delete COMMAND_QUEUE[cid]; if (callback0) callback0.apply(null, arguments); @@ -271,7 +266,7 @@ export function command(cmd, data, callback0) { function commandProcess(cid) { const { cmd, data, callback } = COMMAND_QUEUE[cid]; - logInfo(MODULE, 'command', cmd, data); + utils.logInfo(MODULE, 'command', cmd, data); switch (cmd) { case COMMAND.CONFIG: @@ -283,9 +278,6 @@ function commandProcess(cid) { }; callback(response); break; - case COMMAND.TOSELECTOR: - callback(analyticsAdapter.context.toselector(data.bid)); - break; case COMMAND.URL: if (data.ids) data.args = data.args.concat(analyticsAdapter.context.params.filter(p => /^id([1-9]|10)$/.test(p[0]))); // not >10 callback(analyticsAdapter.url(data.url, data.args, data.bid)); @@ -295,7 +287,7 @@ function commandProcess(cid) { callback(); // drain queue break; default: - logWarn(MODULE, 'command unknown', cmd); + utils.logWarn(MODULE, 'command unknown', cmd); // do not callback as arguments are unknown and to aid debugging } } diff --git a/modules/adlooxAnalyticsAdapter.md b/modules/adlooxAnalyticsAdapter.md index c4618a2e3aa..d4d53a81b3c 100644 --- a/modules/adlooxAnalyticsAdapter.md +++ b/modules/adlooxAnalyticsAdapter.md @@ -2,11 +2,11 @@ Module Name: Adloox Analytics Adapter Module Type: Analytics Adapter - Maintainer: contact@adloox.com + Maintainer: technique@adloox.com # Description -Analytics adapter for adloox.com. Contact contact@adloox.com for information. +Analytics adapter for adloox.com. Contact adops@adloox.com for information. This module can be used to track: @@ -34,7 +34,7 @@ When tracking video you have two options: To view an [example of an Adloox integration](../integrationExamples/gpt/adloox.html): - gulp serve --nolint --notest --modules=gptPreAuction,categoryTranslation,dfpAdServerVideo,rtdModule,instreamTracking,rubiconBidAdapter,spotxBidAdapter,adlooxAnalyticsAdapter,adlooxAdServerVideo,adlooxRtdProvider + gulp serve --nolint --notest --modules=gptPreAuction,categoryTranslation,dfpAdServerVideo,instreamTracking,rubiconBidAdapter,spotxBidAdapter,adlooxAnalyticsAdapter,adlooxAdServerVideo **N.B.** `categoryTranslation` is required by `dfpAdServerVideo` that otherwise causes a JavaScript console warning @@ -44,8 +44,6 @@ Now point your browser at: http://localhost:9999/integrationExamples/gpt/adloox. The example is published publically at: https://storage.googleapis.com/adloox-ads-js-test/prebid.html?pbjs_debug=true -**N.B.** this will show a [CORS error](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors) for the request `https://p.adlooxtracking.com/q?...` that is safe to ignore on the public example page; it is related to the [RTD integration](./adlooxRtdProvider.md) which requires pre-registration of your sites - It is recommended you use [Google Chrome's 'Local Overrides' located in the Developer Tools panel](https://www.trysmudford.com/blog/chrome-local-overrides/) to explore the example without the inconvience of having to run your own web server. #### Pre-built `prebid.js` @@ -63,7 +61,7 @@ You should be able to use this during the QA process of your own internal testin The main Prebid.js documentation is a bit opaque on this but you can use the following to test only Adloox's modules: gulp lint - gulp test-coverage --file 'test/spec/modules/adloox{AnalyticsAdapter,AdServerVideo,RtdProvider}_spec.js' + gulp test-coverage --file 'test/spec/modules/adloox{AnalyticsAdapter,AdServerVideo}_spec.js' gulp view-coverage # Integration @@ -105,8 +103,8 @@ For example, you have a number of reporting breakdown slots available in the for platformid: 0, tagid: 0, params: { - id1: function(b) { return b.adUnitCode }, // do not change when using the Adloox RTD Provider - id2: '%%pbadslot%%', // do not change when using the Adloox RTD Provider + id1: function(b) { return b.adUnitCode }, + id2: '%%pbAdSlot%%', id3: function(b) { return b.bidder }, id4: function(b) { return b.adId }, id5: function(b) { return b.dealId }, @@ -125,8 +123,7 @@ For example, you have a number of reporting breakdown slots available in the for The following macros are available - * `%%pbadslot%%`: [Prebid Ad Slot](https://docs.prebid.org/features/pbAdSlot.html) returns [`AdUnit.code`](https://docs.prebid.org/features/pbAdSlot.html) if set otherwise returns [`AdUnit.code`](https://docs.prebid.org/dev-docs/adunit-reference.html#adunit) - * it is recommended you read the [Prebid Ad Slot section in the Adloox RTD Provider documentation](./adlooxRtdProvider.md#prebid-ad-slot) + * `%%pbAdSlot%%`: [Prebid Ad Slot](https://docs.prebid.org/features/pbAdSlot.html) returns [`AdUnit.code`](https://docs.prebid.org/features/pbAdSlot.html) if set otherwise returns [`AdUnit.code`](https://docs.prebid.org/dev-docs/adunit-reference.html#adunit) ### Functions diff --git a/modules/adlooxRtdProvider.js b/modules/adlooxRtdProvider.js deleted file mode 100644 index 34d1428ea1d..00000000000 --- a/modules/adlooxRtdProvider.js +++ /dev/null @@ -1,393 +0,0 @@ -/** - * This module adds the Adloox provider to the real time data module - * This module adds the [Adloox]{@link https://www.adloox.com/} provider to the real time data module - * The {@link module:modules/realTimeData} module is required - * The module will fetch segments from Adloox's server - * @module modules/adlooxRtdProvider - * @requires module:modules/realTimeData - * @requires module:modules/adlooxAnalyticsAdapter - */ - -/* eslint standard/no-callback-literal: "off" */ -/* eslint prebid/validate-imports: "off" */ - -import { command as analyticsCommand, COMMAND } from './adlooxAnalyticsAdapter.js'; -import { config as _config } from '../src/config.js'; -import { submodule } from '../src/hook.js'; -import { ajax } from '../src/ajax.js'; -import { getGlobal } from '../src/prebidGlobal.js'; -import { - getAdUnitSizes, logInfo, isPlainObject, logError, isStr, isInteger, isArray, isBoolean, mergeDeep, deepAccess, - _each, deepSetValue, logWarn, getGptSlotInfoForAdUnitCode -} from '../src/utils.js'; -import includes from 'core-js-pure/features/array/includes.js'; - -const MODULE_NAME = 'adloox'; -const MODULE = `${MODULE_NAME}RtdProvider`; - -const API_ORIGIN = 'https://p.adlooxtracking.com'; -const SEGMENT_HISTORIC = { 'a': 'aud', 'd': 'dis', 'v': 'vid' }; -const SEGMENT_HISTORIC_VALUES = Object.keys(SEGMENT_HISTORIC).map(k => SEGMENT_HISTORIC[k]); - -const ADSERVER_TARGETING_PREFIX = 'adl_'; - -const CREATIVE_WIDTH_MIN = 20; -const CREATIVE_HEIGHT_MIN = 20; -const CREATIVE_AREA_MIN = CREATIVE_WIDTH_MIN * CREATIVE_HEIGHT_MIN; -// try to avoid using IntersectionObserver as it has unbounded (observed multi-second) latency -let intersectionObserver = window == top ? false : undefined; -const intersectionObserverElements = []; -// .map/.findIndex are safe here as they are only used for intersectionObserver -function atf(adUnit, cb) { - analyticsCommand(COMMAND.TOSELECTOR, { bid: { adUnitCode: adUnit.code } }, function(selector) { - const element = document.querySelector(selector); - if (!element) return cb(null); - - if (window.getComputedStyle(element)['display'] == 'none') return cb(NaN); - - try { - // short circuit for cross-origin - if (intersectionObserver) throw false; - - // Google's advice is to collapse slots on no fill but - // we have to cater to clients that grow slots on fill - const rect = (function(rect) { - const sizes = getAdUnitSizes(adUnit); - - if (sizes.length == 0) return false; - // interstitial (0x0, 1x1) - if (sizes.length == 1 && (sizes[0][0] * sizes[0][1]) <= 1) return true; - // try to catch premium slots (coord=0,0) as they will likely bounce into view - if (rect.top <= -window.pageYOffset && rect.left <= -window.pageXOffset && rect.top == rect.bottom) return true; - - // pick the smallest creative size as many publishers will just leave the element unbounded in the vertical - let width = Infinity; - let height = Infinity; - for (let i = 0; i < sizes.length; i++) { - const area = sizes[i][0] * sizes[i][1]; - if (area < CREATIVE_AREA_MIN) continue; - if (area < (width * height)) { - width = sizes[i][0]; - height = sizes[i][1]; - } - } - // we also scale the smallest size to the size of the slot as publishers resize units depending on viewport - const scale = Math.min(1, (rect.right - rect.left) / width); - - return { - left: rect.left, - right: rect.left + Math.max(CREATIVE_WIDTH_MIN, scale * width), - top: rect.top, - bottom: rect.top + Math.max(CREATIVE_HEIGHT_MIN, scale * height) - }; - })(element.getBoundingClientRect()); - - if (rect === false) return cb(NaN); - if (rect === true) return cb(1); - - const W = rect.right - rect.left; - const H = rect.bottom - rect.top; - - if (W * H < CREATIVE_AREA_MIN) return cb(NaN); - - let el; - let win = window; - while (1) { - // https://stackoverflow.com/a/8876069 - const vw = Math.max(win.document.documentElement.clientWidth || 0, win.innerWidth || 0); - const vh = Math.max(win.document.documentElement.clientHeight || 0, win.innerHeight || 0); - - // cut to viewport - rect.left = Math.min(Math.max(rect.left, 0), vw); - rect.right = Math.min(Math.max(rect.right, 0), vw); - rect.top = Math.min(Math.max(rect.top, 0), vh); - rect.bottom = Math.min(Math.max(rect.bottom, 0), vh); - - if (win == top) return cb(((rect.right - rect.left) * (rect.bottom - rect.top)) / (W * H)); - el = win.frameElement; - if (!el) throw false; // cross-origin - win = win.parent; - - // transpose to frame element - const frameElementRect = el.getBoundingClientRect(); - rect.left += frameElementRect.left; - rect.right = Math.min(rect.right + frameElementRect.left, frameElementRect.right); - rect.top += frameElementRect.top; - rect.bottom = Math.min(rect.bottom + frameElementRect.top, frameElementRect.bottom); - } - } catch (_) { - if (intersectionObserver === undefined) { - try { - intersectionObserver = new IntersectionObserver(function(entries) { - entries.forEach(entry => { - const ratio = entry.intersectionRect.width * entry.intersectionRect.height < CREATIVE_AREA_MIN ? NaN : entry.intersectionRatio; - const idx = intersectionObserverElements.findIndex(x => x.element == entry.target); - intersectionObserverElements[idx].cb.forEach(cb => cb(ratio)); - intersectionObserverElements.splice(idx, 1); - intersectionObserver.unobserve(entry.target); - }); - }); - } catch (_) { - intersectionObserver = false; - } - } - if (!intersectionObserver) return cb(null); - const idx = intersectionObserverElements.findIndex(x => x.element == element); - if (idx == -1) { - intersectionObserverElements.push({ element, cb: [ cb ] }); - intersectionObserver.observe(element); - } else { - intersectionObserverElements[idx].cb.push(cb); - } - } - }); -} - -function init(config, userConsent) { - logInfo(MODULE, 'init', config, userConsent); - - if (!isPlainObject(config)) { - logError(MODULE, 'missing config'); - return false; - } - if (config.params === undefined) config.params = {}; - if (!(isPlainObject(config.params))) { - logError(MODULE, 'invalid params'); - return false; - } - if (!(config.params.api_origin === undefined || isStr(config.params.api_origin))) { - logError(MODULE, 'invalid api_origin params value'); - return false; - } - if (!(config.params.imps === undefined || (isInteger(config.params.imps) && config.params.imps > 0))) { - logError(MODULE, 'invalid imps params value'); - return false; - } - if (!(config.params.freqcap_ip === undefined || (isInteger(config.params.freqcap_ip) && config.params.freqcap_ip >= 0))) { - logError(MODULE, 'invalid freqcap_ip params value'); - return false; - } - if (!(config.params.freqcap_ipua === undefined || (isInteger(config.params.freqcap_ipua) && config.params.freqcap_ipua >= 0))) { - logError(MODULE, 'invalid freqcap_ipua params value'); - return false; - } - if (!(config.params.thresholds === undefined || (isArray(config.params.thresholds) && config.params.thresholds.every(x => isInteger(x) && x > 0 && x <= 100)))) { - logError(MODULE, 'invalid thresholds params value'); - return false; - } - if (!(config.params.slotinpath === undefined || isBoolean(config.params.slotinpath))) { - logError(MODULE, 'invalid slotinpath params value'); - return false; - } - // legacy/deprecated configuration code path - if (!(config.params.params === undefined || (isPlainObject(config.params.params) && isInteger(config.params.params.clientid) && isInteger(config.params.params.tagid) && isInteger(config.params.params.platformid)))) { - logError(MODULE, 'invalid subsection params block'); - return false; - } - - config.params.thresholds = config.params.thresholds || [ 50, 60, 70, 80, 90 ]; - - function analyticsConfigCallback(data) { - config = mergeDeep(config.params, data); - } - if (config.params.params) { - logWarn(MODULE, `legacy/deprecated configuration (please migrate to ${MODULE_NAME}AnalyticsAdapter)`); - analyticsConfigCallback(config.params.params); - } else { - analyticsCommand(COMMAND.CONFIG, null, analyticsConfigCallback); - } - - return true; -} - -function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { - // gptPreAuction runs *after* RTD so pbadslot may not be populated... (╯°□°)╯ ┻━┻ - const adUnits = (reqBidsConfigObj.adUnits || getGlobal().adUnits).map(adUnit => { - let path = deepAccess(adUnit, 'ortb2Imp.ext.data.pbadslot'); - if (!path) path = getGptSlotInfoForAdUnitCode(adUnit.code).gptSlot; - return { - path: path, - unit: adUnit - }; - }).filter(adUnit => !!adUnit.path); - - let response = {}; - function setSegments() { - function val(v, k) { - if (!((SEGMENT_HISTORIC[k] || k == 'atf') && v >= 0)) return v; - return config.params.thresholds.filter(t => t <= v); - } - - const ortb2 = _config.getConfig('ortb2') || {}; - const dataSite = _config.getConfig('ortb2.site.ext.data') || {}; - const dataUser = _config.getConfig('ortb2.user.ext.data') || {}; - - _each(response, (v0, k0) => { - if (k0 == '_') return; - const k = SEGMENT_HISTORIC[k0] || k0; - const v = val(v0, k0); - deepSetValue(k == k0 ? dataUser : dataSite, `${MODULE_NAME}_rtd.${k}`, v); - }); - deepSetValue(dataSite, `${MODULE_NAME}_rtd.ok`, true); - - deepSetValue(ortb2, 'site.ext.data', dataSite); - deepSetValue(ortb2, 'user.ext.data', dataUser); - _config.setConfig({ ortb2 }); - - adUnits.forEach((adUnit, i) => { - _each(response['_'][i], (v0, k0) => { - const k = SEGMENT_HISTORIC[k0] || k0; - const v = val(v0, k0); - deepSetValue(adUnit.unit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd.${k}`, v); - }); - }); - }; - - // mergeDeep does not handle merging deep arrays... (╯°□°)╯ ┻━┻ - function mergeDeep(target, ...sources) { - function emptyValue(v) { - if (isPlainObject(v)) { - return {}; - } else if (isArray(v)) { - return []; - } else { - return undefined; - } - } - - if (!sources.length) return target; - const source = sources.shift(); - - if (isPlainObject(target) && isPlainObject(source)) { - Object.keys(source).forEach(key => { - if (!(key in target)) target[key] = emptyValue(source[key]); - target[key] = target[key] !== undefined ? mergeDeep(target[key], source[key]) : source[key]; - }); - } else if (isArray(target) && isArray(source)) { - source.forEach((v, i) => { - if (!(i in target)) target[i] = emptyValue(v); - target[i] = target[i] !== undefined ? mergeDeep(target[i], v) : v; - }); - } else { - target = source; - } - - return mergeDeep(target, ...sources); - } - - let semaphore = 1; - function semaphoreInc(inc) { - if (semaphore == 0) return; - semaphore += inc; - if (semaphore == 0) { - setSegments() - callback(); - } - } - - const args = [ - [ 'v', `pbjs-${getGlobal().version}` ], - [ 'c', config.params.clientid ], - [ 'p', config.params.platformid ], - [ 't', config.params.tagid ], - [ 'imp', config.params.imps ], - [ 'fc_ip', config.params.freqcap_ip ], - [ 'fc_ipua', config.params.freqcap_ipua ], - [ 'pn', document.location.pathname ] - ]; - - if (!adUnits.length) { - logWarn(MODULE, 'no suitable adUnits (missing pbadslot?)'); - } - const atfQueue = []; - adUnits.map((adUnit, i) => { - const ref = [ adUnit.path ]; - if (!config.params.slotinpath) ref.push(adUnit.unit.code); - args.push(['s', ref.join('\t')]); - - semaphoreInc(1); - atfQueue.push(function() { - atf(adUnit.unit, function(x) { - let viewable = document.visibilityState === undefined || document.visibilityState == 'visible'; - try { viewable = viewable && top.document.hasFocus() } catch (_) {} - logInfo(MODULE, `atf code=${adUnit.unit.code} has area=${x}, viewable=${viewable}`); - const atfList = []; atfList[i] = { atf: parseInt(x * 100) }; - response = mergeDeep(response, { _: atfList }); - semaphoreInc(-1); - }); - }); - }); - function atfCb() { - atfQueue.forEach(x => x()); - } - if (document.readyState == 'loading') { - document.addEventListener('DOMContentLoaded', atfCb, false); - } else { - atfCb(); - } - - analyticsCommand(COMMAND.URL, { - url: (config.params.api_origin || API_ORIGIN) + '/q?', - args: args - }, function(url) { - ajax(url, { - success: function(responseText, q) { - try { - if (q.getResponseHeader('content-type') == 'application/json') { - response = mergeDeep(response, JSON.parse(responseText)); - } else { - throw false; - } - } catch (_) { - logError(MODULE, 'unexpected response'); - } - semaphoreInc(-1); - }, - error: function(statusText, q) { - logError(MODULE, 'request failed'); - semaphoreInc(-1); - } - }); - }); -} - -function getTargetingData(adUnitArray, config, userConsent) { - function targetingNormalise(v) { - if (isArray(v) && v.length == 0) return undefined; - if (isBoolean(v)) v = ~~v; - if (!v) return undefined; // empty string and zero - return v; - } - - const dataSite = _config.getConfig(`ortb2.site.ext.data.${MODULE_NAME}_rtd`) || {}; - if (!dataSite.ok) return {}; - - const dataUser = _config.getConfig(`ortb2.user.ext.data.${MODULE_NAME}_rtd`) || {}; - return getGlobal().adUnits.filter(adUnit => includes(adUnitArray, adUnit.code)).reduce((a, adUnit) => { - a[adUnit.code] = {}; - - _each(dataSite, (v0, k) => { - if (includes(SEGMENT_HISTORIC_VALUES, k)) return; // ignore site average viewability - const v = targetingNormalise(v0); - if (v) a[adUnit.code][ADSERVER_TARGETING_PREFIX + k] = v; - }); - - const adUnitSegments = deepAccess(adUnit, `ortb2Imp.ext.data.${MODULE_NAME}_rtd`, {}); - _each(Object.assign({}, dataUser, adUnitSegments), (v0, k) => { - const v = targetingNormalise(v0); - if (v) a[adUnit.code][ADSERVER_TARGETING_PREFIX + k] = v; - }); - - return a; - }, {}); -} - -export const subModuleObj = { - name: MODULE_NAME, - init, - getBidRequestData, - getTargetingData, - atf // used by adlooxRtdProvider_spec.js -}; - -submodule('realTimeData', subModuleObj); diff --git a/modules/adlooxRtdProvider.md b/modules/adlooxRtdProvider.md deleted file mode 100644 index 6c75fbc2d8b..00000000000 --- a/modules/adlooxRtdProvider.md +++ /dev/null @@ -1,105 +0,0 @@ -# Overview - - Module Name: Adloox RTD Provider - Module Type: RTD Provider - Maintainer: contact@adloox.com - -# Description - -RTD provider for adloox.com. Contact contact@adloox.com for information. - -This provider fetches segments and populates the [First Party Data](https://docs.prebid.org/features/firstPartyData.html) attributes, some examples of the segments as described by the Adloox 'Google Publisher Tag Targeting Guidelines' and where they are placed are: - - * Page segments are placed into `ortb2.site.ext.data.adloox_rtd`: - * **`ok`:** boolean (use to capture if our module successfully ran) - * Device segments are placed into `ortb2.user.ext.data.adloox_rtd`: - * **`ivt`:** boolean - * **`ua_old`:** boolean - * **`ip`:** list of strings describing classification of IP (eg. `rfc-special`, `iab-dc`, ...) - * AdUnit segments are placed into `AdUnit.ortb2Imp.ext.data.adloox_rtd`: - * **`{dis,vid,aud}`:** an list of integers describing the likelihood the AdUnit will be visible - * **`atf`:** an list of integers describing the percentage of pixels visible at auction - * measured only once at pre-auction - * usable when the publisher uses the strategy of collapsing ad slots on no-fill - * using the reverse strategy, growing ad slots on fill, invalidates the measurement the position of all content (including the slots) changes post-auction - * works best when your page loads your ad slots have their actual size rendered (ie. not zero height) - * uses the smallest ad unit (above a threshold area of 20x20) supplied by the [publisher to Prebid.js](https://docs.prebid.org/dev-docs/examples/basic-example.html) and measures viewability as if that size to be used - * when used in cross-origin (unfriendly) IFRAME environments the ad slot is directly measured as is (ignoring publisher provided sizes) due to limitations in using [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) - -**N.B.** this provider does not offer or utilise any user orientated data - -These segments are also sent to your ad server but are translated using the following rules: - - * prepended the segment name with `adl_` - * segments are filtered out when their value is either: - * empty string ("") - * zero (`0`) - * boolean `false` - * empty list/array - -For example: - - * `ortb2.site.ext.data.adloox_rtd.ok` is translated to `adl_ok` - * `ortb2.user.ext.data.adloox_rtd.ivt` is translated to `adl_ivt` - * `AdUnit.ortb2Imp.ext.data.adloox_rtd.dis` is translated to `adl_dis` - -## Example - -To view an example of an Adloox integration look at the example provided in the [Adloox Analytics Adapter documentation](./adlooxAnalyticsAdapter.md#example). - -# Integration - -To use this, you *must* also integrate the [Adloox Analytics Adapter](./adlooxAnalyticsAdapter.md) as shown below: - - pbjs.setConfig({ - ... - - realTimeData: { - auctionDelay: 100, // see below for guidance - dataProviders: [ - { - name: 'adloox', - params: { // optional, defaults shown - thresholds: [ 50, 60, 70, 80, 90 ], - slotinpath: false - } - } - ] - }, - - ... - }); - pbjs.enableAnalytics({ - provider: 'adloox', - options: { - client: 'adlooxtest', - clientid: 127, - platformid: 0, - tagid: 0 - } - }); - -You may optionally pass a subsection `params` in the `params` block to the Adloox RTD Provider, these will be passed through to the segment handler as is and as described by the integration guidelines. - -**N.B.** If you pass `params` to the Adloox Analytics Adapter, `id1` (`AdUnit.code`) and `id2` (`%%pbadslot%%`) *must* describe a stable identifier otherwise no usable segments will be served and so they *must not* be changed; if `id1` for your inventory could contain a non-stable random number please consult with us before continuing - -Though our segment technology is fast (less than 10ms) the time it takes for the users device to connect to our service and fetch the segments may not be. For this reason we recommend setting `auctionDelay` no lower than 100ms and if possible you should explore using user-agent sourced information such as [NetworkInformation.{rtt,downlink,...}](https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation) to dynamically tune this for each user. - -## Prebid Ad Slot - -To create reliable segments, a stable description for slots on your inventory needs to be supplied which is typically solved by using the [Prebid Ad Slot](https://docs.prebid.org/features/pbAdSlot.html). - -You may use one of two ways to do achieve this: - - * for display inventory [using GPT](https://developers.google.com/publisher-tag/guides/get-started) you may configure Prebid.js to automatically use the [full ad unit path](https://developers.google.com/publisher-tag/reference#googletag.Slot_getAdUnitPath) - 1. include the [`gptPreAuction` module](https://docs.prebid.org/dev-docs/modules/gpt-pre-auction.html) - 1. wrap both `pbjs.setConfig({...})` and `pbjs.enableAnalytics({...})` with `googletag.cmd.push(function() { ... })` - * set `pbadslot` in the [first party data](https://docs.prebid.org/dev-docs/adunit-reference.html#first-party-data) variable `AdUnit.ortb2Imp.ext.data.pbadslot` for all your ad units - -## Timeouts - -It is strongly recommended you increase any [failsafe timeout](https://docs.prebid.org/dev-docs/faq.html#when-starting-out-what-should-my-timeouts-be) you use by at least the value you supply to `auctionDelay` above. - -Adloox recommends you use the following (based on [examples provided on the Prebid.js website](https://docs.prebid.org/dev-docs/examples/basic-example.html)) - - FAILSAFE_TIMEOUT = AUCTION_DELAY + (3 * PREBID_TIMEOUT) diff --git a/modules/admanBidAdapter.js b/modules/admanBidAdapter.js deleted file mode 100644 index 666e9aea309..00000000000 --- a/modules/admanBidAdapter.js +++ /dev/null @@ -1,180 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import { isFn, deepAccess, logMessage } from '../src/utils.js'; -import {config} from '../src/config.js'; - -const BIDDER_CODE = 'adman'; -const AD_URL = 'https://pub.admanmedia.com/?c=o&m=multi'; -const URL_SYNC = 'https://pub.admanmedia.com'; - -function isBidResponseValid(bid) { - if (!bid.requestId || !bid.cpm || !bid.creativeId || - !bid.ttl || !bid.currency) { - return false; - } - switch (bid['mediaType']) { - case BANNER: - return Boolean(bid.width && bid.height && bid.ad); - case VIDEO: - return Boolean(bid.vastUrl); - case NATIVE: - return Boolean(bid.native && bid.native.title && bid.native.image && bid.native.impressionTrackers); - default: - return false; - } -} - -function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); - } - - try { - const bidFloor = bid.getFloor({ - currency: 'USD', - mediaType: '*', - size: '*', - }); - return bidFloor.floor; - } catch (_) { - return 0 - } -} - -function getUserId(eids, id, source, uidExt) { - if (id) { - var uid = { id }; - if (uidExt) { - uid.ext = uidExt; - } - eids.push({ - source, - uids: [ uid ] - }); - } -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO, NATIVE], - - isBidRequestValid: (bid) => { - return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placementId)); - }, - - buildRequests: (validBidRequests = [], bidderRequest) => { - let winTop = window; - let location; - try { - location = new URL(bidderRequest.refererInfo.referer) - winTop = window.top; - } catch (e) { - location = winTop.location; - logMessage(e); - }; - let placements = []; - let request = { - 'deviceWidth': winTop.screen.width, - 'deviceHeight': winTop.screen.height, - 'language': (navigator && navigator.language) ? navigator.language : '', - 'secure': 1, - 'host': location.host, - 'page': location.pathname, - 'placements': placements - }; - request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0]) - if (bidderRequest) { - if (bidderRequest.uspConsent) { - request.ccpa = bidderRequest.uspConsent; - } - if (bidderRequest.gdprConsent) { - request.gdpr = bidderRequest.gdprConsent - } - } - const len = validBidRequests.length; - - for (let i = 0; i < len; i++) { - let bid = validBidRequests[i]; - let traff = bid.params.traffic || BANNER - const placement = { - placementId: bid.params.placementId, - bidId: bid.bidId, - sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [], - traffic: traff, - eids: [], - bidFloor: getBidFloor(bid) - } - if (bid.schain) { - placement.schain = bid.schain; - } - if (bid.userId) { - getUserId(placement.eids, bid.userId.uid2 && bid.userId.uid2.id, 'uidapi.com'); - getUserId(placement.eids, bid.userId.lotamePanoramaId, 'lotame.com'); - } - if (traff === VIDEO) { - placement.playerSize = bid.mediaTypes[VIDEO].playerSize; - placement.minduration = bid.mediaTypes[VIDEO].minduration; - placement.maxduration = bid.mediaTypes[VIDEO].maxduration; - placement.mimes = bid.mediaTypes[VIDEO].mimes; - placement.protocols = bid.mediaTypes[VIDEO].protocols; - placement.startdelay = bid.mediaTypes[VIDEO].startdelay; - placement.placement = bid.mediaTypes[VIDEO].placement; - placement.skip = bid.mediaTypes[VIDEO].skip; - placement.skipafter = bid.mediaTypes[VIDEO].skipafter; - placement.minbitrate = bid.mediaTypes[VIDEO].minbitrate; - placement.maxbitrate = bid.mediaTypes[VIDEO].maxbitrate; - placement.delivery = bid.mediaTypes[VIDEO].delivery; - placement.playbackmethod = bid.mediaTypes[VIDEO].playbackmethod; - placement.api = bid.mediaTypes[VIDEO].api; - placement.linearity = bid.mediaTypes[VIDEO].linearity; - } - placements.push(placement); - } - return { - method: 'POST', - url: AD_URL, - data: request - }; - }, - - interpretResponse: (serverResponse) => { - let response = []; - serverResponse = serverResponse.body; - for (let i = 0; i < serverResponse.length; i++) { - let resItem = serverResponse[i]; - if (isBidResponseValid(resItem)) { - const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; - resItem.meta = { ...resItem.meta, advertiserDomains }; - - response.push(resItem); - } - } - return response; - }, - - getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { - let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image'; - let syncUrl = URL_SYNC + `/${syncType}?pbjs=1`; - if (gdprConsent && gdprConsent.consentString) { - if (typeof gdprConsent.gdprApplies === 'boolean') { - syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; - } else { - syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; - } - } - if (uspConsent && uspConsent.consentString) { - syncUrl += `&ccpa_consent=${uspConsent.consentString}`; - } - - const coppa = config.getConfig('coppa') ? 1 : 0; - syncUrl += `&coppa=${coppa}`; - - return [{ - type: syncType, - url: syncUrl - }]; - } - -}; - -registerBidder(spec); diff --git a/modules/admixerBidAdapter.js b/modules/admixerBidAdapter.js index dfb76a03804..5c01152200e 100644 --- a/modules/admixerBidAdapter.js +++ b/modules/admixerBidAdapter.js @@ -1,15 +1,14 @@ -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; -import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js'; const BIDDER_CODE = 'admixer'; -const ALIASES = ['go2net', 'adblender', 'adsyield', 'futureads']; +const ALIASES = ['go2net', 'adblender', 'adsyield']; const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx'; export const spec = { code: BIDDER_CODE, aliases: ALIASES, - supportedMediaTypes: [BANNER, VIDEO, NATIVE], + supportedMediaTypes: ['banner', 'video'], /** * Determines whether or not the given bid request is valid. */ @@ -20,20 +19,9 @@ export const spec = { * Make a server request from the list of BidRequests. */ buildRequests: function (validRequest, bidderRequest) { - let w; - let docRef; - do { - w = w ? w.parent : window; - try { - docRef = w.document.referrer; - } catch (e) { - break; - } - } while (w !== window.top); const payload = { imps: [], ortb2: config.getConfig('ortb2'), - docReferrer: docRef, }; let endpointUrl; if (bidderRequest) { @@ -58,10 +46,11 @@ export const spec = { Object.keys(bid).forEach(key => imp[key] = bid[key]); payload.imps.push(imp); }); + const payloadString = JSON.stringify(payload); return { - method: 'POST', + method: 'GET', url: endpointUrl || ENDPOINT_URL, - data: payload, + data: `data=${payloadString}`, }; }, /** @@ -73,7 +62,7 @@ export const spec = { const {body: {ads = []} = {}} = serverResponse; ads.forEach((ad) => bidResponses.push(ad)); } catch (e) { - logError(e); + utils.logError(e); } return bidResponses; }, diff --git a/modules/admixerIdSystem.js b/modules/admixerIdSystem.js index 49ffe4f4680..c963f1e5b88 100644 --- a/modules/admixerIdSystem.js +++ b/modules/admixerIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logError, logInfo } from '../src/utils.js' +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -43,13 +43,13 @@ export const admixerIdSubmodule = { getId(config, consentData) { const {e, p, pid} = (config && config.params) || {}; if (!pid || typeof pid !== 'string') { - logError('admixerId submodule requires partner id to be defined'); + utils.logError('admixerId submodule requires partner id to be defined'); return; } const gdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const consentString = gdpr ? consentData.consentString : ''; if (gdpr && !consentString) { - logInfo('Consent string is required to call admixer id.'); + utils.logInfo('Consent string is required to call admixer id.'); return; } const url = `https://inv-nets.admixer.net/cntcm.aspx?ssp=${pid}${e ? `&e=${e}` : ''}${p ? `&p=${p}` : ''}${consentString ? `&cs=${consentString}` : ''}`; @@ -83,7 +83,7 @@ function retrieveVisitorId(url, callback) { } }, error: error => { - logInfo(`admixerId: fetch encountered an error`, error); + utils.logInfo(`admixerId: fetch encountered an error`, error); callback(); } }, undefined, { method: 'GET', withCredentials: true }); diff --git a/modules/adnowBidAdapter.js b/modules/adnowBidAdapter.js index badf57ed5c9..7412db8d7b6 100644 --- a/modules/adnowBidAdapter.js +++ b/modules/adnowBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { NATIVE, BANNER } from '../src/mediaTypes.js'; -import { parseSizesInput, deepAccess, parseQueryStringParameters } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const BIDDER_CODE = 'adnow'; @@ -61,13 +61,13 @@ export const spec = { }; if (mediaType === BANNER) { - data.sizes = parseSizesInput( + data.sizes = utils.parseSizesInput( req.mediaTypes && req.mediaTypes.banner && req.mediaTypes.banner.sizes ).join('|') } else { data.width = data.height = 200; - let sizes = deepAccess(req, 'mediaTypes.native.image.sizes', []); + let sizes = utils.deepAccess(req, 'mediaTypes.native.image.sizes', []); if (sizes.length > 0) { const size = Array.isArray(sizes[0]) ? sizes[0] : sizes; @@ -81,7 +81,7 @@ export const spec = { return { method: 'GET', url: ENDPOINT, - data: parseQueryStringParameters(data), + data: utils.parseQueryStringParameters(data), options: { withCredentials: false, crossOrigin: true diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index f05cd9f9f32..68c3e9caffd 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; -import { isStr, deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -9,12 +9,12 @@ const ENDPOINT_URL = 'https://ads.adnuntius.delivery/i'; const GVLID = 855; const checkSegment = function (segment) { - if (isStr(segment)) return segment; + if (utils.isStr(segment)) return segment; if (segment.id) return segment.id } const getSegmentsFromOrtb = function (ortb2) { - const userData = deepAccess(ortb2, 'user.data'); + const userData = utils.deepAccess(ortb2, 'user.data'); let segments = []; if (userData) { userData.forEach(userdat => { @@ -37,8 +37,7 @@ const handleMeta = function () { } const getUsi = function (meta, ortb2, bidderRequest) { - let usi = (meta !== null && meta.usi) ? meta.usi : false; - if (ortb2 && ortb2.user && ortb2.user.id) { usi = ortb2.user.id } + const usi = (meta !== null) ? meta.usi : false; return usi } @@ -56,21 +55,19 @@ export const spec = { const requests = []; const request = []; const ortb2 = config.getConfig('ortb2'); - const bidderConfig = config.getConfig(); - const adnMeta = handleMeta() const usi = getUsi(adnMeta, ortb2, bidderRequest) const segments = getSegmentsFromOrtb(ortb2); const tzo = new Date().getTimezoneOffset(); - const gdprApplies = deepAccess(bidderRequest, 'gdprConsent.gdprApplies'); - const consentString = deepAccess(bidderRequest, 'gdprConsent.consentString'); + const gdprApplies = utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies'); + const consentString = utils.deepAccess(bidderRequest, 'gdprConsent.consentString'); request.push('tzo=' + tzo) request.push('format=json') if (gdprApplies !== undefined) request.push('consentString=' + consentString); if (segments.length > 0) request.push('segments=' + segments.join(',')); if (usi) request.push('userId=' + usi); - if (bidderConfig.useCookie === false) request.push('noCookies=true') + for (var i = 0; i < validBidRequests.length; i++) { const bid = validBidRequests[i] const network = bid.params.network || 'network'; @@ -115,7 +112,6 @@ export const spec = { height: Number(ad.creativeHeight), creativeId: ad.creativeId, currency: (ad.bid) ? ad.bid.currency : 'EUR', - dealId: ad.dealId || '', meta: { advertiserDomains: (ad.destinationUrls.destination) ? [ad.destinationUrls.destination.split('/')[2]] : [] diff --git a/modules/adoceanBidAdapter.js b/modules/adoceanBidAdapter.js index 0c23f5e3d8a..7ce9c7ae8f2 100644 --- a/modules/adoceanBidAdapter.js +++ b/modules/adoceanBidAdapter.js @@ -1,11 +1,11 @@ -import { _each, parseSizesInput, isStr, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'adocean'; function buildEndpointUrl(emiter, payloadMap) { const payload = []; - _each(payloadMap, function(v, k) { + utils._each(payloadMap, function(v, k) { payload.push(k + '=' + encodeURIComponent(v)); }); @@ -26,12 +26,12 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) { const bidIdMap = {}; - _each(masterBidRequests, function(bid, slaveId) { + utils._each(masterBidRequests, function(bid, slaveId) { if (!emiter) { emiter = bid.params.emiter; } - const slaveSizes = parseSizesInput(bid.mediaTypes.banner.sizes).join('_'); + const slaveSizes = utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('_'); const rawSlaveId = bid.params.slaveId.replace('adocean', ''); payload.aosspsizes.push(rawSlaveId + '~' + slaveSizes); @@ -95,7 +95,7 @@ export const spec = { isBidRequestValid: function(bid) { const requiredParams = ['slaveId', 'masterId', 'emiter']; - if (requiredParams.some(name => !isStr(bid.params[name]) || !bid.params[name].length)) { + if (requiredParams.some(name => !utils.isStr(bid.params[name]) || !bid.params[name].length)) { return false; } @@ -106,12 +106,12 @@ export const spec = { const bidRequestsByMaster = {}; let requests = []; - _each(validBidRequests, function(bidRequest) { + utils._each(validBidRequests, function(bidRequest) { assignToMaster(bidRequest, bidRequestsByMaster); }); - _each(bidRequestsByMaster, function(masterRequests, masterId) { - _each(masterRequests, function(instanceRequests) { + utils._each(bidRequestsByMaster, function(masterRequests, masterId) { + utils._each(masterRequests, function(instanceRequests) { requests.push(buildRequest(instanceRequests, masterId, bidderRequest.gdprConsent)); }); }); @@ -122,8 +122,8 @@ export const spec = { interpretResponse: function(serverResponse, bidRequest) { let bids = []; - if (isArray(serverResponse.body)) { - _each(serverResponse.body, function(placementResponse) { + if (utils.isArray(serverResponse.body)) { + utils._each(serverResponse.body, function(placementResponse) { interpretResponse(placementResponse, bidRequest, bids); }); } diff --git a/modules/adomikAnalyticsAdapter.js b/modules/adomikAnalyticsAdapter.js index e81f6e50054..5bbee86df54 100644 --- a/modules/adomikAnalyticsAdapter.js +++ b/modules/adomikAnalyticsAdapter.js @@ -12,9 +12,6 @@ const bidRequested = CONSTANTS.EVENTS.BID_REQUESTED; const bidResponse = CONSTANTS.EVENTS.BID_RESPONSE; const bidWon = CONSTANTS.EVENTS.BID_WON; const bidTimeout = CONSTANTS.EVENTS.BID_TIMEOUT; -const ua = navigator.userAgent; - -var _sampled = true; let adomikAdapter = Object.assign(adapter({}), { @@ -50,7 +47,7 @@ let adomikAdapter = Object.assign(adapter({}), type: 'request', event: { bidder: bid.bidder.toUpperCase(), - placementCode: bid.adUnitCode + placementCode: bid.placementCode } }); }); @@ -70,20 +67,13 @@ adomikAdapter.initializeBucketEvents = function() { adomikAdapter.bucketEvents = []; } -adomikAdapter.maxPartLength = function () { - return (ua.includes(' MSIE ')) ? 1600 : 60000; -}; - adomikAdapter.sendTypedEvent = function() { const groupedTypedEvents = adomikAdapter.buildTypedEvents(); const bulkEvents = { - testId: adomikAdapter.currentContext.testId, - testValue: adomikAdapter.currentContext.testValue, uid: adomikAdapter.currentContext.uid, ahbaid: adomikAdapter.currentContext.id, hostname: window.location.hostname, - sampling: adomikAdapter.currentContext.sampling, eventsByPlacementCode: groupedTypedEvents.map(function(typedEventsByType) { let sizes = []; const eventKeys = ['request', 'response', 'winner']; @@ -118,10 +108,9 @@ adomikAdapter.sendTypedEvent = function() { // Encode object in base64 const encodedBuf = window.btoa(stringBulkEvents); - // Create final url and split it (+endpoint length) + // Create final url and split it in 1600 characters max (+endpoint length) const encodedUri = encodeURIComponent(encodedBuf); - const maxLength = adomikAdapter.maxPartLength(); - const splittedUrl = encodedUri.match(new RegExp(`.{1,${maxLength}}`, 'g')); + const splittedUrl = encodedUri.match(/.{1,1600}/g); splittedUrl.forEach((split, i) => { const partUrl = `${split}&id=${adomikAdapter.currentContext.id}&part=${i}&on=${splittedUrl.length - 1}`; @@ -131,10 +120,8 @@ adomikAdapter.sendTypedEvent = function() { }; adomikAdapter.sendWonEvent = function (wonEvent) { - let keyValues = { testId: adomikAdapter.currentContext.testId, testValue: adomikAdapter.currentContext.testValue } - wonEvent = {...wonEvent, ...keyValues} const stringWonEvent = JSON.stringify(wonEvent) - logInfo('Won event sent to adomik prebid analytic ' + stringWonEvent); + logInfo('Won event sent to adomik prebid analytic ' + wonEvent); // Encode object in base64 const encodedBuf = window.btoa(stringWonEvent); @@ -206,28 +193,17 @@ adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics; adomikAdapter.enableAnalytics = function (config) { adomikAdapter.currentContext = {}; - const initOptions = config.options; - _sampled = typeof config === 'undefined' || - typeof config.sampling === 'undefined' || - Math.random() < parseFloat(config.sampling); - - if (_sampled) { - if (initOptions) { - adomikAdapter.currentContext = { - uid: initOptions.id, - url: initOptions.url, - testId: initOptions.testId, - testValue: initOptions.testValue, - id: '', - timeouted: false, - sampling: config.sampling - } - logInfo('Adomik Analytics enabled with config', initOptions); - adomikAdapter.adapterEnableAnalytics(config); + const initOptions = config.options; + if (initOptions) { + adomikAdapter.currentContext = { + uid: initOptions.id, + url: initOptions.url, + id: '', + timeouted: false, } - } else { - logInfo('Adomik Analytics ignored for sampling', config.sampling); + logInfo('Adomik Analytics enabled with config', initOptions); + adomikAdapter.adapterEnableAnalytics(config); } }; diff --git a/modules/adpartnerBidAdapter.js b/modules/adpartnerBidAdapter.js deleted file mode 100644 index e8d8a43aa1b..00000000000 --- a/modules/adpartnerBidAdapter.js +++ /dev/null @@ -1,215 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { buildUrl } from '../src/utils.js' -import {ajax} from '../src/ajax.js'; - -const BIDDER_CODE = 'adpartner'; -export const ENDPOINT_PROTOCOL = 'https'; -export const ENDPOINT_DOMAIN = 'a4p.adpartner.pro'; -export const ENDPOINT_PATH = '/hb/bid'; - -export const spec = { - code: BIDDER_CODE, - - isBidRequestValid: function (bidRequest) { - return !!parseInt(bidRequest.params.unitId) || !!parseInt(bidRequest.params.partnerId); - }, - - buildRequests: function (validBidRequests, bidderRequest) { - let referer = window.location.href; - try { - referer = typeof bidderRequest.refererInfo === 'undefined' - ? window.top.location.href - : bidderRequest.refererInfo.referer; - } catch (e) {} - - let bidRequests = []; - let beaconParams = { - tag: [], - partner: [], - sizes: [], - referer: '' - }; - - validBidRequests.forEach(function(validBidRequest) { - let bidRequestObject = { - adUnitCode: validBidRequest.adUnitCode, - sizes: validBidRequest.sizes, - bidId: validBidRequest.bidId, - referer: referer - }; - - if (parseInt(validBidRequest.params.unitId)) { - bidRequestObject.unitId = parseInt(validBidRequest.params.unitId); - beaconParams.tag.push(validBidRequest.params.unitId); - } - - if (parseInt(validBidRequest.params.partnerId)) { - bidRequestObject.unitId = 0; - bidRequestObject.partnerId = parseInt(validBidRequest.params.partnerId); - beaconParams.partner.push(validBidRequest.params.partnerId); - } - - bidRequests.push(bidRequestObject); - - beaconParams.sizes.push(spec.joinSizesToString(validBidRequest.sizes)); - beaconParams.referer = encodeURIComponent(referer); - }); - - if (beaconParams.partner.length > 0) { - beaconParams.partner = beaconParams.partner.join(','); - } else { - delete beaconParams.partner; - } - - beaconParams.tag = beaconParams.tag.join(','); - beaconParams.sizes = beaconParams.sizes.join(','); - - let adPartnerRequestUrl = buildUrl({ - protocol: ENDPOINT_PROTOCOL, - hostname: ENDPOINT_DOMAIN, - pathname: ENDPOINT_PATH, - search: beaconParams - }); - - return { - method: 'POST', - url: adPartnerRequestUrl, - data: JSON.stringify(bidRequests) - }; - }, - - joinSizesToString: function(sizes) { - let res = []; - sizes.forEach(function(size) { - res.push(size.join('x')); - }); - - return res.join('|'); - }, - - interpretResponse: function (serverResponse, bidRequest) { - const validBids = JSON.parse(bidRequest.data); - - if (typeof serverResponse.body === 'undefined') { - return []; - } - - return validBids - .map(bid => ({ - bid: bid, - ad: serverResponse.body[bid.adUnitCode] - })) - .filter(item => item.ad) - .map(item => spec.adResponse(item.bid, item.ad)); - }, - - adResponse: function(bid, ad) { - const bidObject = { - requestId: bid.bidId, - ad: ad.ad, - cpm: ad.cpm, - width: ad.width, - height: ad.height, - ttl: 60, - creativeId: ad.creativeId, - netRevenue: ad.netRevenue, - currency: ad.currency, - winNotification: ad.winNotification - } - - bidObject.meta = {}; - if (ad.adomain && ad.adomain.length > 0) { - bidObject.meta.advertiserDomains = ad.adomain; - } - - return bidObject; - }, - - onBidWon: function(data) { - data.winNotification.forEach(function(unitWon) { - let adPartnerBidWonUrl = buildUrl({ - protocol: ENDPOINT_PROTOCOL, - hostname: ENDPOINT_DOMAIN, - pathname: unitWon.path - }); - - if (unitWon.method === 'POST') { - spec.postRequest(adPartnerBidWonUrl, JSON.stringify(unitWon.data)); - } - }); - - return true; - }, - - postRequest(endpoint, data) { - ajax(endpoint, null, data, {method: 'POST'}); - }, - - getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { - const syncs = []; - - if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { - return syncs; - } - - let appendGdprParams = function (url, gdprParams) { - if (gdprParams === null) { - return url; - } - - return url + (url.indexOf('?') >= 0 ? '&' : '?') + gdprParams; - }; - - let gdprParams = null; - if (gdprConsent) { - if (typeof gdprConsent.gdprApplies === 'boolean') { - gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; - } else { - gdprParams = `gdpr_consent=${gdprConsent.consentString}`; - } - } - - serverResponses.forEach(resp => { - if (resp.body) { - Object.keys(resp.body).map(function(key, index) { - let respObject = resp.body[key]; - if (respObject['syncs'] !== undefined && - Array.isArray(respObject.syncs) && - respObject.syncs.length > 0) { - if (syncOptions.iframeEnabled) { - respObject.syncs.filter(function (syncIframeObject) { - if (syncIframeObject['type'] !== undefined && - syncIframeObject['link'] !== undefined && - syncIframeObject.type === 'iframe') { return true; } - return false; - }).forEach(function (syncIframeObject) { - syncs.push({ - type: 'iframe', - url: appendGdprParams(syncIframeObject.link, gdprParams) - }); - }); - } - if (syncOptions.pixelEnabled) { - respObject.syncs.filter(function (syncImageObject) { - if (syncImageObject['type'] !== undefined && - syncImageObject['link'] !== undefined && - syncImageObject.type === 'image') { return true; } - return false; - }).forEach(function (syncImageObject) { - syncs.push({ - type: 'image', - url: appendGdprParams(syncImageObject.link, gdprParams) - }); - }); - } - } - }); - } - }); - - return syncs; - }, - -} - -registerBidder(spec); diff --git a/modules/adpartnerBidAdapter.md b/modules/adpartnerBidAdapter.md index 2dc1c31c4c3..ad105c43a8a 100644 --- a/modules/adpartnerBidAdapter.md +++ b/modules/adpartnerBidAdapter.md @@ -23,19 +23,7 @@ About us : https://adpartner.pro { bidder: "adpartner", params: { - unitId: 6698 - } - } - ] - }, - { - code: 'div-adpartner-example-2', - sizes: [[300, 250]], - bids: [ - { - bidder: "adpartner", - params: { - partnerId: 6698 + unitId: 5809 } } ] diff --git a/modules/adplusBidAdapter.js b/modules/adplusBidAdapter.js deleted file mode 100644 index c001781a792..00000000000 --- a/modules/adplusBidAdapter.js +++ /dev/null @@ -1,203 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js'; -import { BANNER } from '../src/mediaTypes.js'; -import { getStorageManager } from '../src/storageManager.js'; - -// #region Constants -export const BIDDER_CODE = 'adplus'; -export const ADPLUS_ENDPOINT = 'https://ssp.ad-plus.com.tr/server/headerBidding'; -export const DGID_CODE = 'adplus_dg_id'; -export const SESSION_CODE = 'adplus_s_id'; -export const storage = getStorageManager(undefined, BIDDER_CODE); -const COOKIE_EXP = 1000 * 60 * 60 * 24; // 1 day -// #endregion - -// #region Helpers -export function isValidUuid (uuid) { - return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test( - uuid - ); -} - -function getSessionId() { - let sid = storage.cookiesAreEnabled() && storage.getCookie(SESSION_CODE); - - if ( - !sid || !isValidUuid(sid) - ) { - sid = utils.generateUUID(); - setSessionId(sid); - } - - return sid; -} - -function setSessionId(sid) { - if (storage.cookiesAreEnabled()) { - const expires = new Date(Date.now() + COOKIE_EXP).toISOString(); - - storage.setCookie(SESSION_CODE, sid, expires); - } -} -// #endregion - -// #region Bid request validation -function isBidRequestValid(bid) { - if (!bid) { - utils.logError(BIDDER_CODE, 'bid, can not be empty', bid); - return false; - } - - if (!bid.params) { - utils.logError(BIDDER_CODE, 'bid.params is required.'); - return false; - } - - if (!bid.params.adUnitId || typeof bid.params.adUnitId !== 'string') { - utils.logError( - BIDDER_CODE, - 'bid.params.adUnitId is missing or has wrong type.' - ); - return false; - } - - if (!bid.params.inventoryId || typeof bid.params.inventoryId !== 'string') { - utils.logError( - BIDDER_CODE, - 'bid.params.inventoryId is missing or has wrong type.' - ); - return false; - } - - if ( - !bid.mediaTypes || - !bid.mediaTypes[BANNER] || - !utils.isArray(bid.mediaTypes[BANNER].sizes) || - bid.mediaTypes[BANNER].sizes.length <= 0 || - !utils.isArrayOfNums(bid.mediaTypes[BANNER].sizes[0]) - ) { - utils.logError(BIDDER_CODE, 'Wrong or missing size parameters.'); - return false; - } - - return true; -} -// #endregion - -// #region Building the bid requests -/** - * - * @param {object} bid - * @returns - */ -function createBidRequest(bid) { - // Developer Params - const { - inventoryId, - adUnitId, - extraData, - yearOfBirth, - gender, - categories, - latitude, - longitude, - sdkVersion, - } = bid.params; - - return { - method: 'GET', - url: ADPLUS_ENDPOINT, - data: utils.cleanObj({ - bidId: bid.bidId, - inventoryId, - adUnitId, - adUnitWidth: bid.mediaTypes[BANNER].sizes[0][0], - adUnitHeight: bid.mediaTypes[BANNER].sizes[0][1], - extraData, - yearOfBirth, - gender, - categories, - latitude, - longitude, - sdkVersion: sdkVersion || '1', - session: getSessionId(), - interstitial: 0, - token: typeof window.top === 'object' && window.top[DGID_CODE] ? window.top[DGID_CODE] : undefined, - secure: window.location.protocol === 'https:' ? 1 : 0, - screenWidth: screen.width, - screenHeight: screen.height, - language: window.navigator.language || 'en-US', - pageUrl: window.location.href, - domain: window.location.hostname, - referrer: window.location.referrer, - }), - }; -} - -function buildRequests(validBidRequests, bidderRequest) { - return validBidRequests.map((req) => createBidRequest(req)); -} -// #endregion - -// #region Interpreting Responses -/** - * - * @param {HeaderBiddingResponse} responseData - * @param { object } bidParams - * @returns - */ -function createAdResponse(responseData, bidParams) { - return { - requestId: responseData.requestID, - cpm: responseData.cpm, - currency: responseData.currency, - width: responseData.width, - height: responseData.height, - creativeId: responseData.creativeID, - dealId: responseData.dealID, - netRevenue: responseData.netRevenue, - ttl: responseData.ttl, - ad: responseData.ad, - mediaType: responseData.mediaType, - meta: { - advertiserDomains: responseData.advertiserDomains, - primaryCatId: utils.isArray(responseData.categoryIDs) && responseData.categoryIDs.length > 0 - ? responseData.categoryIDs[0] : undefined, - secondaryCatIds: responseData.categoryIDs, - }, - }; -} - -function interpretResponse(response, request) { - // In case of empty response - if ( - response.body == null || - !utils.isArray(response.body) || - response.body.length === 0 - ) { - return []; - } - const bids = response.body.map((bid) => createAdResponse(bid)); - return bids; -} -// #endregion - -// #region Bidder -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - isBidRequestValid, - buildRequests, - interpretResponse, - onTimeout(timeoutData) { - utils.logError('Adplus adapter timed out for the auction.', timeoutData); - }, - onBidWon(bid) { - utils.logInfo( - `Adplus adapter won the auction. Bid id: ${bid.bidId}, Ad Unit Id: ${bid.adUnitId}, Inventory Id: ${bid.inventoryId}` - ); - }, -}; - -registerBidder(spec); -// #endregion diff --git a/modules/adplusBidAdapter.md b/modules/adplusBidAdapter.md deleted file mode 100644 index dce9e4a312f..00000000000 --- a/modules/adplusBidAdapter.md +++ /dev/null @@ -1,39 +0,0 @@ -# Overview - -Module Name: AdPlus Bidder Adapter - -Module Type: Bidder Adapter - -Maintainer: adplus.destek@yaani.com.tr - -# Description - -AdPlus Prebid.js Bidder Adapter. Only banner formats are supported. - -About us : https://ssp.ad-plus.com.tr/ - -# Test Parameters - -```javascript -var adUnits = [ - { - code: "div-adplus", - mediaTypes: { - banner: { - sizes: [ - [300, 250], - ], - }, - }, - bids: [ - { - bidder: "adplus", - params: { - inventoryId: "-1", - adUnitId: "-3", - }, - }, - ], - }, -]; -``` diff --git a/modules/adpod.js b/modules/adpod.js index ddceed1c344..57baf5b5fc6 100644 --- a/modules/adpod.js +++ b/modules/adpod.js @@ -12,10 +12,7 @@ * module that designed to support adpod video type ads. This import process allows this module to effectively act as a sub-module. */ -import { - generateUUID, deepAccess, logWarn, logInfo, isArrayOfNums, isArray, isNumber, logError, groupBy, compareOn, - isPlainObject -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { addBidToAuction, doCallbacksIfTimedout, AUCTION_IN_PROGRESS, callPrebidCache, getPriceByGranularity, getPriceGranularity } from '../src/auction.js'; import { checkAdUnitSetup } from '../src/prebid.js'; import { checkVideoBidSetup } from '../src/video.js'; @@ -48,7 +45,7 @@ function createBidCacheRegistry() { registry[auctionId] = {}; registry[auctionId].bidStorage = new Set(); registry[auctionId].queueDispatcher = createDispatcher(queueTimeDelay); - registry[auctionId].initialCacheKey = generateUUID(); + registry[auctionId].initialCacheKey = utils.generateUUID(); } return { @@ -71,7 +68,7 @@ function createBidCacheRegistry() { setupInitialCacheKey: function (bid) { if (!registry[bid.auctionId]) { registry[bid.auctionId] = {}; - registry[bid.auctionId].initialCacheKey = generateUUID(); + registry[bid.auctionId].initialCacheKey = utils.generateUUID(); } }, getInitialCacheKey: function (bid) { @@ -118,9 +115,9 @@ function createDispatcher(timeoutDuration) { function getPricePartForAdpodKey(bid) { let pricePart let prioritizeDeals = config.getConfig('adpod.prioritizeDeals'); - if (prioritizeDeals && deepAccess(bid, 'video.dealTier')) { + if (prioritizeDeals && utils.deepAccess(bid, 'video.dealTier')) { const adpodDealPrefix = config.getConfig(`adpod.dealTier.${bid.bidderCode}.prefix`); - pricePart = (adpodDealPrefix) ? adpodDealPrefix + deepAccess(bid, 'video.dealTier') : deepAccess(bid, 'video.dealTier'); + pricePart = (adpodDealPrefix) ? adpodDealPrefix + utils.deepAccess(bid, 'video.dealTier') : utils.deepAccess(bid, 'video.dealTier'); } else { const granularity = getPriceGranularity(bid.mediaType); pricePart = getPriceByGranularity(granularity)(bid); @@ -135,12 +132,12 @@ function getPricePartForAdpodKey(bid) { */ function attachPriceIndustryDurationKeyToBid(bid, brandCategoryExclusion) { let initialCacheKey = bidCacheRegistry.getInitialCacheKey(bid); - let duration = deepAccess(bid, 'video.durationBucket'); + let duration = utils.deepAccess(bid, 'video.durationBucket'); const pricePart = getPricePartForAdpodKey(bid); let pcd; if (brandCategoryExclusion) { - let category = deepAccess(bid, 'meta.adServerCatId'); + let category = utils.deepAccess(bid, 'meta.adServerCatId'); pcd = `${pricePart}_${category}_${duration}s`; } else { pcd = `${pricePart}_${duration}s`; @@ -171,7 +168,7 @@ function updateBidQueue(auctionInstance, bidResponse, afterBidAdded) { let killQueue = !!(auctionInstance.getAuctionStatus() !== AUCTION_IN_PROGRESS); callDispatcher(auctionInstance, bidListArr, afterBidAdded, killQueue); } else { - logWarn('Attempted to cache a bid from an unknown auction. Bid:', bidResponse); + utils.logWarn('Attempted to cache a bid from an unknown auction. Bid:', bidResponse); } } @@ -199,7 +196,7 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { store(bidList, function (error, cacheIds) { if (error) { - logWarn(`Failed to save to the video cache: ${error}. Video bid(s) must be discarded.`); + utils.logWarn(`Failed to save to the video cache: ${error}. Video bid(s) must be discarded.`); for (let i = 0; i < bidList.length; i++) { doCallbacksIfTimedout(auctionInstance, bidList[i]); } @@ -209,7 +206,7 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { if (cacheIds[i].uuid !== '') { addBidToAuction(auctionInstance, bidList[i]); } else { - logInfo(`Detected a bid was not cached because the custom key was already registered. Attempted to use key: ${bidList[i].customCacheKey}. Bid was: `, bidList[i]); + utils.logInfo(`Detected a bid was not cached because the custom key was already registered. Attempted to use key: ${bidList[i].customCacheKey}. Bid was: `, bidList[i]); } afterBidAdded(); } @@ -226,12 +223,12 @@ function firePrebidCacheCall(auctionInstance, bidList, afterBidAdded) { * @param {Object} bidderRequest copy of bid's associated bidderRequest object */ export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAdded, bidderRequest) { - let videoConfig = deepAccess(bidderRequest, 'mediaTypes.video'); + let videoConfig = utils.deepAccess(bidderRequest, 'mediaTypes.video'); if (videoConfig && videoConfig.context === ADPOD) { let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion'); - let adServerCatId = deepAccess(bidResponse, 'meta.adServerCatId'); + let adServerCatId = utils.deepAccess(bidResponse, 'meta.adServerCatId'); if (!adServerCatId && brandCategoryExclusion) { - logWarn('Detected a bid without meta.adServerCatId while setConfig({adpod.brandCategoryExclusion}) was enabled. This bid has been rejected:', bidResponse) + utils.logWarn('Detected a bid without meta.adServerCatId while setConfig({adpod.brandCategoryExclusion}) was enabled. This bid has been rejected:', bidResponse) afterBidAdded(); } else { if (config.getConfig('adpod.deferCaching') === false) { @@ -263,12 +260,12 @@ export function callPrebidCacheHook(fn, auctionInstance, bidResponse, afterBidAd */ export function checkAdUnitSetupHook(fn, adUnits) { let goodAdUnits = adUnits.filter(adUnit => { - let mediaTypes = deepAccess(adUnit, 'mediaTypes'); - let videoConfig = deepAccess(mediaTypes, 'video'); + let mediaTypes = utils.deepAccess(adUnit, 'mediaTypes'); + let videoConfig = utils.deepAccess(mediaTypes, 'video'); if (videoConfig && videoConfig.context === ADPOD) { // run check to see if other mediaTypes are defined (ie multi-format); reject adUnit if so if (Object.keys(mediaTypes).length > 1) { - logWarn(`Detected more than one mediaType in adUnitCode: ${adUnit.code} while attempting to define an 'adpod' video adUnit. 'adpod' adUnits cannot be mixed with other mediaTypes. This adUnit will be removed from the auction.`); + utils.logWarn(`Detected more than one mediaType in adUnitCode: ${adUnit.code} while attempting to define an 'adpod' video adUnit. 'adpod' adUnits cannot be mixed with other mediaTypes. This adUnit will be removed from the auction.`); return false; } @@ -277,20 +274,20 @@ export function checkAdUnitSetupHook(fn, adUnits) { let playerSize = !!( ( videoConfig.playerSize && ( - isArrayOfNums(videoConfig.playerSize, 2) || ( - isArray(videoConfig.playerSize) && videoConfig.playerSize.every(sz => isArrayOfNums(sz, 2)) + utils.isArrayOfNums(videoConfig.playerSize, 2) || ( + utils.isArray(videoConfig.playerSize) && videoConfig.playerSize.every(sz => utils.isArrayOfNums(sz, 2)) ) ) ) || (videoConfig.sizeConfig) ); - let adPodDurationSec = !!(videoConfig.adPodDurationSec && isNumber(videoConfig.adPodDurationSec) && videoConfig.adPodDurationSec > 0); - let durationRangeSec = !!(videoConfig.durationRangeSec && isArrayOfNums(videoConfig.durationRangeSec) && videoConfig.durationRangeSec.every(range => range > 0)); + let adPodDurationSec = !!(videoConfig.adPodDurationSec && utils.isNumber(videoConfig.adPodDurationSec) && videoConfig.adPodDurationSec > 0); + let durationRangeSec = !!(videoConfig.durationRangeSec && utils.isArrayOfNums(videoConfig.durationRangeSec) && videoConfig.durationRangeSec.every(range => range > 0)); if (!playerSize || !adPodDurationSec || !durationRangeSec) { errMsg += (!playerSize) ? '\nmediaTypes.video.playerSize' : ''; errMsg += (!adPodDurationSec) ? '\nmediaTypes.video.adPodDurationSec' : ''; errMsg += (!durationRangeSec) ? '\nmediaTypes.video.durationRangeSec' : ''; - logWarn(errMsg); + utils.logWarn(errMsg); return false; } } @@ -316,8 +313,8 @@ export function checkAdUnitSetupHook(fn, adUnits) { */ function checkBidDuration(bidderRequest, bidResponse) { const buffer = 2; - let bidDuration = deepAccess(bidResponse, 'video.durationSeconds'); - let videoConfig = deepAccess(bidderRequest, 'mediaTypes.video'); + let bidDuration = utils.deepAccess(bidResponse, 'video.durationSeconds'); + let videoConfig = utils.deepAccess(bidderRequest, 'mediaTypes.video'); let adUnitRanges = videoConfig.durationRangeSec; adUnitRanges.sort((a, b) => a - b); // ensure the ranges are sorted in numeric order @@ -327,14 +324,14 @@ function checkBidDuration(bidderRequest, bidResponse) { let nextHighestRange = find(adUnitRanges, range => (range + buffer) >= bidDuration); bidResponse.video.durationBucket = nextHighestRange; } else { - logWarn(`Detected a bid with a duration value outside the accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Rejecting bid: `, bidResponse); + utils.logWarn(`Detected a bid with a duration value outside the accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Rejecting bid: `, bidResponse); return false; } } else { if (find(adUnitRanges, range => range === bidDuration)) { bidResponse.video.durationBucket = bidDuration; } else { - logWarn(`Detected a bid with a duration value not part of the list of accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Exact match durations must be used for this adUnit. Rejecting bid: `, bidResponse); + utils.logWarn(`Detected a bid with a duration value not part of the list of accepted ranges specified in adUnit.mediaTypes.video.durationRangeSec. Exact match durations must be used for this adUnit. Rejecting bid: `, bidResponse); return false; } } @@ -355,16 +352,16 @@ export function checkVideoBidSetupHook(fn, bid, bidRequest, videoMediaType, cont if (context === ADPOD) { let result = true; let brandCategoryExclusion = config.getConfig('adpod.brandCategoryExclusion'); - if (brandCategoryExclusion && !deepAccess(bid, 'meta.primaryCatId')) { + if (brandCategoryExclusion && !utils.deepAccess(bid, 'meta.primaryCatId')) { result = false; } - if (deepAccess(bid, 'video')) { - if (!deepAccess(bid, 'video.context') || bid.video.context !== ADPOD) { + if (utils.deepAccess(bid, 'video')) { + if (!utils.deepAccess(bid, 'video.context') || bid.video.context !== ADPOD) { result = false; } - if (!deepAccess(bid, 'video.durationSeconds') || bid.video.durationSeconds <= 0) { + if (!utils.deepAccess(bid, 'video.durationSeconds') || bid.video.durationSeconds <= 0) { result = false; } else { let isBidGood = checkBidDuration(bidRequest, bid); @@ -373,7 +370,7 @@ export function checkVideoBidSetupHook(fn, bid, bidRequest, videoMediaType, cont } if (!config.getConfig('cache.url') && bid.vastXml && !bid.vastUrl) { - logError(` + utils.logError(` This bid contains only vastXml and will not work when a prebid cache url is not specified. Try enabling prebid cache with pbjs.setConfig({ cache: {url: "..."} }); `); @@ -395,7 +392,7 @@ export function adpodSetConfig(config) { if (typeof config.bidQueueTimeDelay === 'number' && config.bidQueueTimeDelay > 0) { queueTimeDelay = config.bidQueueTimeDelay; } else { - logWarn(`Detected invalid value for adpod.bidQueueTimeDelay in setConfig; must be a positive number. Using default: ${queueTimeDelay}`) + utils.logWarn(`Detected invalid value for adpod.bidQueueTimeDelay in setConfig; must be a positive number. Using default: ${queueTimeDelay}`) } } @@ -403,7 +400,7 @@ export function adpodSetConfig(config) { if (typeof config.bidQueueSizeLimit === 'number' && config.bidQueueSizeLimit > 0) { queueSizeLimit = config.bidQueueSizeLimit; } else { - logWarn(`Detected invalid value for adpod.bidQueueSizeLimit in setConfig; must be a positive number. Using default: ${queueSizeLimit}`) + utils.logWarn(`Detected invalid value for adpod.bidQueueSizeLimit in setConfig; must be a positive number. Using default: ${queueSizeLimit}`) } } } @@ -467,7 +464,7 @@ export function sortByPricePerSecond(a, b) { */ export function getTargeting({ codes, callback } = {}) { if (!callback) { - logError('No callback function was defined in the getTargeting call. Aborting getTargeting().'); + utils.logError('No callback function was defined in the getTargeting call. Aborting getTargeting().'); return; } codes = codes || []; @@ -483,7 +480,7 @@ export function getTargeting({ codes, callback } = {}) { let prioritizeDeals = config.getConfig('adpod.prioritizeDeals'); if (prioritizeDeals) { let [otherBids, highPriorityDealBids] = bids.reduce((partitions, bid) => { - let bidDealTier = deepAccess(bid, 'video.dealTier'); + let bidDealTier = utils.deepAccess(bid, 'video.dealTier'); let minDealTier = config.getConfig(`adpod.dealTier.${bid.bidderCode}.minDealTier`); if (minDealTier && bidDealTier) { if (bidDealTier >= minDealTier) { @@ -509,7 +506,7 @@ export function getTargeting({ codes, callback } = {}) { if (deferCachingEnabled === false) { adPodAdUnits.forEach((adUnit) => { let adPodTargeting = []; - let adPodDurationSeconds = deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); + let adPodDurationSeconds = utils.deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); bids .filter((bid) => bid.adUnitCode === adUnit.code) @@ -533,7 +530,7 @@ export function getTargeting({ codes, callback } = {}) { } else { let bidsToCache = []; adPodAdUnits.forEach((adUnit) => { - let adPodDurationSeconds = deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); + let adPodDurationSeconds = utils.deepAccess(adUnit, 'mediaTypes.video.adPodDurationSec'); bids .filter((bid) => bid.adUnitCode === adUnit.code) @@ -549,7 +546,7 @@ export function getTargeting({ codes, callback } = {}) { if (error) { callback(error, null); } else { - let groupedBids = groupBy(bidsSuccessfullyCached, 'adUnitCode'); + let groupedBids = utils.groupBy(bidsSuccessfullyCached, 'adUnitCode'); Object.keys(groupedBids).forEach((adUnitCode) => { let adPodTargeting = []; @@ -581,7 +578,7 @@ export function getTargeting({ codes, callback } = {}) { */ function getAdPodAdUnits(codes) { return auctionManager.getAdUnits() - .filter((adUnit) => deepAccess(adUnit, 'mediaTypes.video.context') === ADPOD) + .filter((adUnit) => utils.deepAccess(adUnit, 'mediaTypes.video.context') === ADPOD) .filter((adUnit) => (codes.length > 0) ? codes.indexOf(adUnit.code) != -1 : true); } @@ -593,10 +590,10 @@ function getAdPodAdUnits(codes) { function getExclusiveBids(bidsReceived) { let bids = bidsReceived .map((bid) => Object.assign({}, bid, { [TARGETING_KEY_PB_CAT_DUR]: bid.adserverTargeting[TARGETING_KEY_PB_CAT_DUR] })); - bids = groupBy(bids, TARGETING_KEY_PB_CAT_DUR); + bids = utils.groupBy(bids, TARGETING_KEY_PB_CAT_DUR); let filteredBids = []; Object.keys(bids).forEach((targetingKey) => { - bids[targetingKey].sort(compareOn('responseTimestamp')); + bids[targetingKey].sort(utils.compareOn('responseTimestamp')); filteredBids.push(bids[targetingKey][0]); }); return filteredBids; @@ -622,8 +619,8 @@ const sharedMethods = { Object.freeze(sharedMethods); module('adpod', function shareAdpodUtilities(...args) { - if (!isPlainObject(args[0])) { - logError('Adpod module needs plain object to share methods with submodule'); + if (!utils.isPlainObject(args[0])) { + utils.logError('Adpod module needs plain object to share methods with submodule'); return; } function addMethods(object, func) { diff --git a/modules/adprimeBidAdapter.js b/modules/adprimeBidAdapter.js index 2b5a7e15af2..ef370301184 100644 --- a/modules/adprimeBidAdapter.js +++ b/modules/adprimeBidAdapter.js @@ -1,6 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import { isFn, deepAccess, logMessage } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'adprime'; const AD_URL = 'https://delta.adprime.com/pbjs'; @@ -24,8 +24,8 @@ function isBidResponseValid(bid) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); } try { @@ -56,7 +56,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let placements = []; let request = { diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js deleted file mode 100644 index ce31f64d705..00000000000 --- a/modules/adqueryBidAdapter.js +++ /dev/null @@ -1,204 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER} from '../src/mediaTypes.js'; -import { logInfo, buildUrl, triggerPixel } from '../src/utils.js'; -import { getStorageManager } from '../src/storageManager.js'; - -const ADQUERY_GVLID = 902; -const ADQUERY_BIDDER_CODE = 'adquery'; -const ADQUERY_BIDDER_DOMAIN_PROTOCOL = 'https'; -const ADQUERY_BIDDER_DOMAIN = 'bidder.adquery.io'; -const ADQUERY_USER_SYNC_DOMAIN = ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUERY_BIDDER_DOMAIN + '/prebid/userSync?1=1'; -const ADQUERY_DEFAULT_CURRENCY = 'PLN'; -const ADQUERY_NET_REVENUE = true; -const ADQUERY_TTL = 360; -const storage = getStorageManager(ADQUERY_GVLID); - -/** @type {BidderSpec} */ -export const spec = { - code: ADQUERY_BIDDER_CODE, - gvlid: ADQUERY_GVLID, - supportedMediaTypes: [BANNER], - - /** f - * @param {object} bid - * @return {boolean} - */ - isBidRequestValid: (bid) => { - return !!(bid && bid.params && bid.params.placementId) - }, - - /** - * @param {BidRequest[]} bidRequests - * @param {*} bidderRequest - * @return {ServerRequest} - */ - buildRequests: (bidRequests, bidderRequest) => { - const requests = []; - for (let i = 0, len = bidRequests.length; i < len; i++) { - const request = { - method: 'POST', - url: ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUERY_BIDDER_DOMAIN + '/prebid/bid', - data: buildRequest(bidRequests[i], bidderRequest), - options: { - withCredentials: false, - crossOrigin: true - } - }; - requests.push(request); - } - return requests; - }, - - /** - * @param {*} response - * @param {ServerRequest} request - * @return {Bid[]} - */ - interpretResponse: (response, request) => { - logInfo(request); - logInfo(response); - - const res = response && response.body && response.body.data; - let bidResponses = []; - - if (!res) { - return []; - } - - const bidResponse = { - requestId: res.requestId, - cpm: res.cpm, - width: res.mediaType.width, - height: res.mediaType.height, - creativeId: res.creationId, - dealId: res.dealid || '', - currency: res.currency || ADQUERY_DEFAULT_CURRENCY, - netRevenue: ADQUERY_NET_REVENUE, - ttl: ADQUERY_TTL, - referrer: '', - ad: '' + res.tag, - mediaType: res.mediaType.name || 'banner', - meta: { - advertiserDomains: res.adDomains && res.adDomains.length ? res.adDomains : [], - mediaType: res.mediaType.name || 'banner', - } - }; - bidResponses.push(bidResponse); - logInfo('bidResponses', bidResponses); - - return bidResponses; - }, - - /** - * @param {TimedOutBid} timeoutData - */ - onTimeout: (timeoutData) => { - if (timeoutData == null) { - return; - } - logInfo('onTimeout ', timeoutData); - let params = { - bidder: timeoutData.bidder, - bId: timeoutData.bidId, - adUnitCode: timeoutData.adUnitCode, - timeout: timeoutData.timeout, - auctionId: timeoutData.auctionId, - }; - let adqueryRequestUrl = buildUrl({ - protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, - hostname: ADQUERY_BIDDER_DOMAIN, - pathname: '/prebid/eventTimeout', - search: params - }); - triggerPixel(adqueryRequestUrl); - }, - - /** - * @param {Bid} bid - */ - onBidWon: (bid) => { - logInfo('onBidWon', bid); - const bidString = JSON.stringify(bid); - const encodedBuf = window.btoa(bidString); - - let params = { - q: encodedBuf, - }; - let adqueryRequestUrl = buildUrl({ - protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, - hostname: ADQUERY_BIDDER_DOMAIN, - pathname: '/prebid/eventBidWon', - search: params - }); - triggerPixel(adqueryRequestUrl); - }, - - /** - * @param {Bid} bid - */ - onSetTargeting: (bid) => { - logInfo('onSetTargeting', bid); - - let params = { - bidder: bid.bidder, - width: bid.width, - height: bid.height, - bid: bid.adId, - mediaType: bid.mediaType, - cpm: bid.cpm, - requestId: bid.requestId, - adUnitCode: bid.adUnitCode - }; - - let adqueryRequestUrl = buildUrl({ - protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL, - hostname: ADQUERY_BIDDER_DOMAIN, - pathname: '/prebid/eventSetTargeting', - search: params - }); - triggerPixel(adqueryRequestUrl); - }, - getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { - let syncUrl = ADQUERY_USER_SYNC_DOMAIN; - if (gdprConsent && gdprConsent.consentString) { - if (typeof gdprConsent.gdprApplies === 'boolean') { - syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; - } else { - syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; - } - } - if (uspConsent && uspConsent.consentString) { - syncUrl += `&ccpa_consent=${uspConsent.consentString}`; - } - return [{ - type: 'image', - url: syncUrl - }]; - } - -}; -function buildRequest(validBidRequests, bidderRequest) { - let qid = Math.random().toString(36).substring(2) + Date.now().toString(36); - let bid = validBidRequests; - - if (storage.getDataFromLocalStorage('qid')) { - qid = storage.getDataFromLocalStorage('qid'); - } else { - storage.setDataInLocalStorage('qid', qid); - } - - return { - placementCode: bid.params.placementId, - auctionId: bid.auctionId, - qid: qid, - type: bid.params.type, - adUnitCode: bid.adUnitCode, - bidId: bid.bidId, - bidder: bid.bidder, - bidderRequestId: bid.bidderRequestId, - bidRequestsCount: bid.bidRequestsCount, - bidderRequestsCount: bid.bidderRequestsCount, - }; -} - -registerBidder(spec); diff --git a/modules/adqueryBidAdapter.md b/modules/adqueryBidAdapter.md deleted file mode 100644 index e8b68e30406..00000000000 --- a/modules/adqueryBidAdapter.md +++ /dev/null @@ -1,32 +0,0 @@ -# Overview - -Module Name: Adquery Bidder Adapter -Module Type: Bidder Adapter -Maintainer: prebid@adquery.com - -# Description - -Module that connects to Adquery's demand sources. - -# Test Parameters -``` - var adUnits = [ - { - code: 'banner-adquery-div', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - bids: [ - { - bidder: 'adquery', - params: { - placementId: '6d93f2a0e5f0fe2cc3a6e9e3ade964b43b07f897', - type: 'banner300x250' - } - } - ] - } - ]; -``` diff --git a/modules/adqueryIdSystem.js b/modules/adqueryIdSystem.js deleted file mode 100644 index 5357c1a1ffd..00000000000 --- a/modules/adqueryIdSystem.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * This module adds Adquery QID to the User ID module - * The {@link module:modules/userId} module is required - * @module modules/adqueryIdSystem - * @requires module:modules/userId - */ - -import {ajax} from '../src/ajax.js'; -import {getStorageManager} from '../src/storageManager.js'; -import {submodule} from '../src/hook.js'; -import * as utils from '../src/utils.js'; - -const MODULE_NAME = 'qid'; -const AU_GVLID = 902; - -export const storage = getStorageManager(AU_GVLID, 'qid'); - -/** - * Param or default. - * @param {String} param - * @param {String} defaultVal - */ -function paramOrDefault(param, defaultVal, arg) { - if (utils.isFn(param)) { - return param(arg); - } else if (utils.isStr(param)) { - return param; - } - return defaultVal; -} - -/** @type {Submodule} */ -export const adqueryIdSubmodule = { - /** - * used to link submodule with config - * @type {string} - */ - name: MODULE_NAME, - - /** - * IAB TCF Vendor ID - * @type {string} - */ - gvlid: AU_GVLID, - - /** - * decode the stored id value for passing to bid requests - * @function - * @param {{value:string}} value - * @returns {{qid:Object}} - */ - decode(value) { - let qid = storage.getDataFromLocalStorage('qid'); - if (utils.isStr(qid)) { - return {qid: qid}; - } - return (value && typeof value['qid'] === 'string') ? { 'qid': value['qid'] } : undefined; - }, - /** - * performs action to obtain id and return a value in the callback's response argument - * @function - * @param {SubmoduleConfig} [config] - * @returns {IdResponse|undefined} - */ - getId(config) { - if (!utils.isPlainObject(config.params)) { - config.params = {}; - } - const url = paramOrDefault(config.params.url, - `https://bidder.adquery.io/prebid/qid`, - config.params.urlArg); - - const resp = function (callback) { - let qid = storage.getDataFromLocalStorage('qid'); - if (utils.isStr(qid)) { - const responseObj = {qid: qid}; - callback(responseObj); - } else { - const callbacks = { - success: response => { - let responseObj; - if (response) { - try { - responseObj = JSON.parse(response); - } catch (error) { - utils.logError(error); - } - } - callback(responseObj); - }, - error: error => { - utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); - callback(); - } - }; - ajax(url, callbacks, undefined, {method: 'GET'}); - } - }; - return {callback: resp}; - } -}; - -submodule('userId', adqueryIdSubmodule); diff --git a/modules/adqueryIdSystem.md b/modules/adqueryIdSystem.md deleted file mode 100644 index 3a49ffbe4da..00000000000 --- a/modules/adqueryIdSystem.md +++ /dev/null @@ -1,35 +0,0 @@ -# Adquery QID - -Adquery QID Module. For assistance setting up your module please contact us at [prebid@adquery.io](prebid@adquery.io). - -### Prebid Params - -Individual params may be set for the Adquery ID Submodule. At least one identifier must be set in the params. - -``` -pbjs.setConfig({ - usersync: { - userIds: [{ - name: 'qid', - storage: { - name: 'qid', - type: 'html5' - } - }] - } -}); -``` -## Parameter Descriptions for the `usersync` Configuration Section -The below parameters apply only to the Adquery User ID Module integration. - -| Param under usersync.userIds[] | Scope | Type | Description | Example | -| --- | --- | --- | --- | --- | -| name | Required | String | ID value for the Adquery ID module - `"qid"` | `"qid"` | -| storage | Required | Object | The publisher must specify the local storage in which to store the results of the call to get the user ID. | | -| storage.type | Required | String | This is where the results of the user ID will be stored. The recommended method is `localStorage` by specifying `html5`. | `"html5"` | -| storage.name | Required | String | The name of the html5 local storage where the user ID will be stored. | `"qid"` | -| storage.expires | Optional | Integer | How long (in days) the user ID information will be stored. | `365` | -| value | Optional | Object | Used only if the page has a separate mechanism for storing the Adquery ID. The value is an object containing the values to be sent to the adapters. In this scenario, no URL is called and nothing is added to local storage | `{"qid": "2abf9f001fcd81241b67"}` | -| params | Optional | Object | Used to store params for the id system | -| params.url | Optional | String | Set an alternate GET url for qid with this parameter | -| params.urlArg | Optional | Object | Optional url parameter for params.url | diff --git a/modules/adrelevantisBidAdapter.js b/modules/adrelevantisBidAdapter.js index 649031d1e3b..b6832cfeb0d 100644 --- a/modules/adrelevantisBidAdapter.js +++ b/modules/adrelevantisBidAdapter.js @@ -1,8 +1,5 @@ import { Renderer } from '../src/Renderer.js'; -import { - logError, convertTypes, convertCamelToUnderscore, isArray, deepClone, logWarn, logMessage, getBidRequest, deepAccess, - isStr, createTrackPixelHtml, isEmpty, transformBidderParamKeywords, chunk, isArrayOfNums -} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; @@ -148,7 +145,7 @@ export const spec = { if (!serverResponse || serverResponse.error) { let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`; if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - logError(errorMessage); + utils.logError(errorMessage); return bids; } @@ -169,9 +166,9 @@ export const spec = { }, transformBidParams: function(params, isOpenRtb) { - params = convertTypes({ + params = utils.convertTypes({ 'placementId': 'number', - 'keywords': transformBidderParamKeywords + 'keywords': utils.transformBidderParamKeywords }, params); if (isOpenRtb) { @@ -183,7 +180,7 @@ export const spec = { } Object.keys(params).forEach(paramKey => { - let convertedKey = convertCamelToUnderscore(paramKey); + let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { params[convertedKey] = params[paramKey]; delete params[paramKey]; @@ -196,7 +193,7 @@ export const spec = { } function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); + return !!(utils.isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -209,9 +206,9 @@ function formatRequest(payload, bidderRequest) { let request = []; if (payload.tags.length > MAX_IMPS_PER_REQUEST) { - const clonedPayload = deepClone(payload); + const clonedPayload = utils.deepClone(payload); - chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { + utils.chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { clonedPayload.tags = tags; const payloadString = JSON.stringify(clonedPayload); request.push({ @@ -246,14 +243,14 @@ function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } renderer.setEventHandlers({ - impression: () => logMessage('AdRelevantis outstream video impression event'), - loaded: () => logMessage('AdRelevantis outstream video loaded event'), + impression: () => utils.logMessage('AdRelevantis outstream video impression event'), + loaded: () => utils.logMessage('AdRelevantis outstream video loaded event'), ended: () => { - logMessage('AdRelevantis outstream renderer video event'); + utils.logMessage('AdRelevantis outstream renderer video event'); document.querySelector(`#${adUnitCode}`).style.display = 'none'; } }); @@ -298,7 +295,7 @@ function handleOutstreamRendererEvents(bid, id, eventName) { * @return Bid */ function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); + const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { requestId: serverBid.uuid, cpm: rtbBid.cpm, @@ -327,7 +324,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { ttl: 3600 }); - const videoContext = deepAccess(bidRequest, 'mediaTypes.video.context'); + const videoContext = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); switch (videoContext) { case OUTSTREAM: bid.adResponse = serverBid; @@ -337,7 +334,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (rtbBid.renderer_url) { const videoBid = find(bidderRequest.bids, bid => bid.bidId === serverBid.uuid); - const rendererOptions = deepAccess(videoBid, 'renderer.options'); + const rendererOptions = utils.deepAccess(videoBid, 'renderer.options'); bid.renderer = newRenderer(bid.adUnitCode, rtbBid, rendererOptions); } break; @@ -357,7 +354,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { if (jsTrackers == undefined) { jsTrackers = jsTrackerDisarmed; - } else if (isStr(jsTrackers)) { + } else if (utils.isStr(jsTrackers)) { jsTrackers = [jsTrackers, jsTrackerDisarmed]; } else { jsTrackers.push(jsTrackerDisarmed); @@ -405,10 +402,10 @@ function newBid(serverBid, rtbBid, bidderRequest) { }); try { const url = rtbBid.rtb.trackers[0].impression_urls[0]; - const tracker = createTrackPixelHtml(url); + const tracker = utils.createTrackPixelHtml(url); bid.ad += tracker; } catch (error) { - logError('Error appending tracking pixel', error); + utils.logError('Error appending tracking pixel', error); } } @@ -452,8 +449,8 @@ function bidToTag(bid) { if (bid.params.externalImpId) { tag.external_imp_id = bid.params.externalImpId; } - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); + if (!utils.isEmpty(bid.params.keywords)) { + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); @@ -464,7 +461,7 @@ function bidToTag(bid) { tag.category = bid.params.category; } - if (bid.mediaType === NATIVE || deepAccess(bid, `mediaTypes.${NATIVE}`)) { + if (bid.mediaType === NATIVE || utils.deepAccess(bid, `mediaTypes.${NATIVE}`)) { tag.ad_types.push(NATIVE); if (tag.sizes.length === 0) { tag.sizes = transformSizes([1, 1]); @@ -476,8 +473,8 @@ function bidToTag(bid) { } } - const videoMediaType = deepAccess(bid, `mediaTypes.${VIDEO}`); - const context = deepAccess(bid, 'mediaTypes.video.context'); + const videoMediaType = utils.deepAccess(bid, `mediaTypes.${VIDEO}`); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); tag.hb_source = 1; if (bid.mediaType === VIDEO || videoMediaType) { @@ -502,7 +499,7 @@ function bidToTag(bid) { } if ( - (isEmpty(bid.mediaType) && isEmpty(bid.mediaTypes)) || + (utils.isEmpty(bid.mediaType) && utils.isEmpty(bid.mediaTypes)) || (bid.mediaType === BANNER || (bid.mediaTypes && bid.mediaTypes[BANNER])) ) { tag.ad_types.push(BANNER); @@ -516,8 +513,8 @@ function transformSizes(requestSizes) { let sizes = []; let sizeObj = {}; - if (isArray(requestSizes) && requestSizes.length === 2 && - !isArray(requestSizes[0])) { + if (utils.isArray(requestSizes) && requestSizes.length === 2 && + !utils.isArray(requestSizes[0])) { sizeObj.width = parseInt(requestSizes[0], 10); sizeObj.height = parseInt(requestSizes[1], 10); sizes.push(sizeObj); @@ -578,7 +575,7 @@ function buildNativeRequest(params) { const isImageAsset = !!(requestKey === NATIVE_MAPPING.image.serverName || requestKey === NATIVE_MAPPING.icon.serverName); if (isImageAsset && request[requestKey].sizes) { let sizes = request[requestKey].sizes; - if (isArrayOfNums(sizes) || (isArray(sizes) && sizes.length > 0 && sizes.every(sz => isArrayOfNums(sz)))) { + if (utils.isArrayOfNums(sizes) || (utils.isArray(sizes) && sizes.length > 0 && sizes.every(sz => utils.isArrayOfNums(sz)))) { request[requestKey].sizes = transformSizes(request[requestKey].sizes); } } diff --git a/modules/adriverBidAdapter.js b/modules/adriverBidAdapter.js index 67e039e4692..d5a777f6111 100644 --- a/modules/adriverBidAdapter.js +++ b/modules/adriverBidAdapter.js @@ -1,5 +1,5 @@ // ADRIVER BID ADAPTER for Prebid 1.13 -import { logInfo, getWindowLocation, getBidIdParameter, _each } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'adriver'; @@ -21,12 +21,12 @@ export const spec = { }, buildRequests: function (validBidRequests, bidderRequest) { - logInfo('validBidRequests', validBidRequests); + utils.logInfo('validBidRequests', validBidRequests); - let win = getWindowLocation(); + let win = utils.getWindowLocation(); let customID = Math.round(Math.random() * 999999999) + '-' + Math.round(new Date() / 1000) + '-1-46-'; - let siteId = getBidIdParameter('siteid', validBidRequests[0].params) + ''; - let currency = getBidIdParameter('currency', validBidRequests[0].params); + let siteId = utils.getBidIdParameter('siteid', validBidRequests[0].params) + ''; + let currency = utils.getBidIdParameter('currency', validBidRequests[0].params); currency = 'RUB'; let timeout = null; @@ -58,8 +58,8 @@ export const spec = { 'imp': [] }; - _each(validBidRequests, (bid) => { - _each(bid.sizes, (sizes) => { + utils._each(validBidRequests, (bid) => { + utils._each(bid.sizes, (sizes) => { let width; let height; let par; @@ -67,7 +67,7 @@ export const spec = { let floorAndCurrency = _getFloor(bid, currency, sizes); let bidFloor = floorAndCurrency.floor; - let dealId = getBidIdParameter('dealid', bid.params); + let dealId = utils.getBidIdParameter('dealid', bid.params); if (typeof sizes[0] === 'number' && typeof sizes[1] === 'number') { width = sizes[0]; height = sizes[1]; @@ -93,7 +93,7 @@ export const spec = { }] }; } - logInfo('par', par); + utils.logInfo('par', par); payload.imp.push(par); }); }); @@ -108,11 +108,11 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { - logInfo('serverResponse.body.seatbid', serverResponse.body.seatbid); + utils.logInfo('serverResponse.body.seatbid', serverResponse.body.seatbid); const bidResponses = []; let nurl = 0; - _each(serverResponse.body.seatbid, (seatbid) => { - logInfo('_each', seatbid); + utils._each(serverResponse.body.seatbid, (seatbid) => { + utils.logInfo('_each', seatbid); var bid = seatbid.bid[0]; if (bid.nurl !== undefined) { nurl = bid.nurl.split('://'); @@ -135,7 +135,7 @@ export const spec = { }, ad: '' }; - logInfo('bidResponse', bidResponse); + utils.logInfo('bidResponse', bidResponse); bidResponses.push(bidResponse); } }); diff --git a/modules/adtargetBidAdapter.js b/modules/adtargetBidAdapter.js index 0ad0177815a..1779ba94371 100644 --- a/modules/adtargetBidAdapter.js +++ b/modules/adtargetBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, chunk, _map, flatten, logError, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -13,7 +13,7 @@ export const spec = { code: BIDDER_CODE, supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - return !!deepAccess(bid, 'params.aid'); + return !!utils.deepAccess(bid, 'params.aid'); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -42,9 +42,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - isArray(serverResponses) && serverResponses.forEach((response) => { + utils.isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (isArray(response.body)) { + if (utils.isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -59,10 +59,10 @@ export const spec = { buildRequests: function (bidRequests, adapterRequest) { const adapterSettings = config.getConfig(adapterRequest.bidderCode) - const chunkSize = deepAccess(adapterSettings, 'chunkSize', 10); + const chunkSize = utils.deepAccess(adapterSettings, 'chunkSize', 10); const { tag, bids } = bidToTag(bidRequests, adapterRequest); - const bidChunks = chunk(bids, chunkSize); - return _map(bidChunks, (bids) => { + const bidChunks = utils.chunk(bids, chunkSize); + return utils._map(bidChunks, (bids) => { return { data: Object.assign({}, tag, { BidRequests: bids }), adapterRequest, @@ -75,12 +75,12 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!isArray(serverResponse)) { + if (!utils.isArray(serverResponse)) { return parseResponse(serverResponse, adapterRequest); } serverResponse.forEach(serverBidResponse => { - bids = flatten(bids, parseResponse(serverBidResponse, adapterRequest)); + bids = utils.flatten(bids, parseResponse(serverBidResponse, adapterRequest)); }); return bids; @@ -88,14 +88,14 @@ export const spec = { }; function parseResponse(serverResponse, adapterRequest) { - const isInvalidValidResp = !serverResponse || !isArray(serverResponse.bids); + const isInvalidValidResp = !serverResponse || !utils.isArray(serverResponse.bids); const bids = []; if (isInvalidValidResp) { const extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : ''; const errorMessage = `in response for ${adapterRequest.bidderCode} adapter ${extMessage}`; - logError(errorMessage); + utils.logError(errorMessage); return bids; } @@ -117,23 +117,23 @@ function parseResponse(serverResponse, adapterRequest) { function bidToTag(bidRequests, adapterRequest) { const tag = { - Domain: deepAccess(adapterRequest, 'refererInfo.referer') + Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer') }; if (config.getConfig('coppa') === true) { tag.Coppa = 1; } - if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { + if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { tag.GDPR = 1; - tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString'); + tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString'); } - if (deepAccess(adapterRequest, 'uspConsent')) { - tag.USP = deepAccess(adapterRequest, 'uspConsent'); + if (utils.deepAccess(adapterRequest, 'uspConsent')) { + tag.USP = utils.deepAccess(adapterRequest, 'uspConsent'); } - if (deepAccess(bidRequests[0], 'schain')) { - tag.Schain = deepAccess(bidRequests[0], 'schain'); + if (utils.deepAccess(bidRequests[0], 'schain')) { + tag.Schain = utils.deepAccess(bidRequests[0], 'schain'); } - if (deepAccess(bidRequests[0], 'userId')) { - tag.UserIds = deepAccess(bidRequests[0], 'userId'); + if (utils.deepAccess(bidRequests[0], 'userId')) { + tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); } const bids = [] @@ -147,19 +147,19 @@ function bidToTag(bidRequests, adapterRequest) { } function prepareBidRequests(bidReq) { - const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; - const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes'); + const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; + const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes'); const bidReqParams = { 'CallbackId': bidReq.bidId, 'Aid': bidReq.params.aid, 'AdType': mediaType, - 'Sizes': parseSizesInput(sizes).join(',') + 'Sizes': utils.parseSizesInput(sizes).join(',') }; return bidReqParams; } function getMediaType(bidderRequest) { - return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; + return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; } function createBid(bidResponse, bidRequest) { diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index 44a9c90d438..e1c6dc1ca35 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, chunk, _map, flatten, convertTypes, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -20,7 +20,6 @@ const HOST_GETTERS = { onefiftytwomedia: () => 'ghb.ads.152media.com', mediafuse: () => 'ghb.hbmp.mediafuse.com', bidsxchange: () => 'ghb.hbd.bidsxchange.com', - streamkey: () => 'ghb.hb.streamkey.net', } const getUri = function (bidderCode) { let bidderWithoutSuffix = bidderCode.split('_')[0]; @@ -36,7 +35,7 @@ const syncsCache = {}; export const spec = { code: BIDDER_CODE, gvlid: 410, - aliases: ['onefiftytwomedia', 'selectmedia', 'appaloosa', 'bidsxchange', 'streamkey', + aliases: ['onefiftytwomedia', 'selectmedia', 'appaloosa', 'bidsxchange', { code: 'navelix', gvlid: 380 }, { code: 'mediafuse', @@ -45,7 +44,7 @@ export const spec = { ], supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - return !!deepAccess(bid, 'params.aid'); + return !!utils.deepAccess(bid, 'params.aid'); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -74,9 +73,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - isArray(serverResponses) && serverResponses.forEach((response) => { + utils.isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (isArray(response.body)) { + if (utils.isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -95,10 +94,10 @@ export const spec = { */ buildRequests: function (bidRequests, adapterRequest) { const adapterSettings = config.getConfig(adapterRequest.bidderCode) - const chunkSize = deepAccess(adapterSettings, 'chunkSize', 10); + const chunkSize = utils.deepAccess(adapterSettings, 'chunkSize', 10); const { tag, bids } = bidToTag(bidRequests, adapterRequest); - const bidChunks = chunk(bids, chunkSize); - return _map(bidChunks, (bids) => { + const bidChunks = utils.chunk(bids, chunkSize); + return utils._map(bidChunks, (bids) => { return { data: Object.assign({}, tag, { BidRequests: bids }), adapterRequest, @@ -118,26 +117,26 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!isArray(serverResponse)) { + if (!utils.isArray(serverResponse)) { return parseRTBResponse(serverResponse, adapterRequest); } serverResponse.forEach(serverBidResponse => { - bids = flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); + bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); }); return bids; }, transformBidParams(params) { - return convertTypes({ + return utils.convertTypes({ 'aid': 'number', }, params); } }; function parseRTBResponse(serverResponse, adapterRequest) { - const isEmptyResponse = !serverResponse || !isArray(serverResponse.bids); + const isEmptyResponse = !serverResponse || !utils.isArray(serverResponse.bids); const bids = []; if (isEmptyResponse) { @@ -162,26 +161,26 @@ function parseRTBResponse(serverResponse, adapterRequest) { function bidToTag(bidRequests, adapterRequest) { // start publisher env const tag = { - Domain: deepAccess(adapterRequest, 'refererInfo.referer') + Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer') }; if (config.getConfig('coppa') === true) { tag.Coppa = 1; } - if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { + if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { tag.GDPR = 1; - tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString'); + tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString'); } - if (deepAccess(adapterRequest, 'uspConsent')) { - tag.USP = deepAccess(adapterRequest, 'uspConsent'); + if (utils.deepAccess(adapterRequest, 'uspConsent')) { + tag.USP = utils.deepAccess(adapterRequest, 'uspConsent'); } - if (deepAccess(bidRequests[0], 'schain')) { - tag.Schain = deepAccess(bidRequests[0], 'schain'); + if (utils.deepAccess(bidRequests[0], 'schain')) { + tag.Schain = utils.deepAccess(bidRequests[0], 'schain'); } - if (deepAccess(bidRequests[0], 'userId')) { - tag.UserIds = deepAccess(bidRequests[0], 'userId'); + if (utils.deepAccess(bidRequests[0], 'userId')) { + tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); } - if (deepAccess(bidRequests[0], 'userIdAsEids')) { - tag.UserEids = deepAccess(bidRequests[0], 'userIdAsEids'); + if (utils.deepAccess(bidRequests[0], 'userIdAsEids')) { + tag.UserEids = utils.deepAccess(bidRequests[0], 'userIdAsEids'); } if (window.adtDmp && window.adtDmp.ready) { tag.DMPId = window.adtDmp.getUID(); @@ -204,13 +203,13 @@ function bidToTag(bidRequests, adapterRequest) { * @returns {object} */ function prepareBidRequests(bidReq) { - const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; - const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes'); + const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; + const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes'); const bidReqParams = { 'CallbackId': bidReq.bidId, 'Aid': bidReq.params.aid, 'AdType': mediaType, - 'Sizes': parseSizesInput(sizes).join(',') + 'Sizes': utils.parseSizesInput(sizes).join(',') }; bidReqParams.PlacementId = bidReq.adUnitCode; @@ -221,9 +220,9 @@ function prepareBidRequests(bidReq) { bidReqParams.PlacementId = bidReq.params.vpb_placement_id; } if (mediaType === VIDEO) { - const context = deepAccess(bidReq, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidReq, 'mediaTypes.video.context'); if (context === ADPOD) { - bidReqParams.Adpod = deepAccess(bidReq, 'mediaTypes.video'); + bidReqParams.Adpod = utils.deepAccess(bidReq, 'mediaTypes.video'); } } return bidReqParams; @@ -235,7 +234,7 @@ function prepareBidRequests(bidReq) { * @returns {object} */ function getMediaType(bidderRequest) { - return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; + return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; } /** @@ -246,7 +245,7 @@ function getMediaType(bidderRequest) { */ function createBid(bidResponse, bidRequest) { const mediaType = getMediaType(bidRequest) - const context = deepAccess(bidRequest, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); const bid = { requestId: bidResponse.requestId, creativeId: bidResponse.cmpId, diff --git a/modules/adtrueBidAdapter.js b/modules/adtrueBidAdapter.js index df848fba823..96f1ceb12f0 100644 --- a/modules/adtrueBidAdapter.js +++ b/modules/adtrueBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, isArray, inIframe, isNumber, isStr, deepClone, deepSetValue, logError, deepAccess, isBoolean } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; @@ -190,22 +190,22 @@ function _checkParamDataType(key, value, datatype) { var functionToExecute; switch (datatype) { case DATA_TYPES.BOOLEAN: - functionToExecute = isBoolean; + functionToExecute = utils.isBoolean; break; case DATA_TYPES.NUMBER: - functionToExecute = isNumber; + functionToExecute = utils.isNumber; break; case DATA_TYPES.STRING: - functionToExecute = isStr; + functionToExecute = utils.isStr; break; case DATA_TYPES.ARRAY: - functionToExecute = isArray; + functionToExecute = utils.isArray; break; } if (functionToExecute(value)) { return value; } - logWarn(LOG_WARN_PREFIX + errMsg); + utils.logWarn(LOG_WARN_PREFIX + errMsg); return UNDEFINED; } @@ -216,7 +216,7 @@ function _parseNativeResponse(bid, newBid) { try { adm = JSON.parse(bid.adm.replace(/\\/g, '')); } catch (ex) { - // logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); + // utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); return; } if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) { @@ -274,13 +274,13 @@ function _createBannerRequest(bid) { var sizes = bid.mediaTypes.banner.sizes; var format = []; var bannerObj; - if (sizes !== UNDEFINED && isArray(sizes)) { + if (sizes !== UNDEFINED && utils.isArray(sizes)) { bannerObj = {}; if (!bid.params.width && !bid.params.height) { if (sizes.length === 0) { // i.e. since bid.params does not have width or height, and length of sizes is 0, need to ignore this banner imp bannerObj = UNDEFINED; - logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); return bannerObj; } else { bannerObj.w = parseInt(sizes[0][0], 10); @@ -303,9 +303,9 @@ function _createBannerRequest(bid) { } } bannerObj.pos = 0; - bannerObj.topframe = inIframe() ? 0 : 1; + bannerObj.topframe = utils.inIframe() ? 0 : 1; } else { - logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); bannerObj = UNDEFINED; } return bannerObj; @@ -323,10 +323,10 @@ function _createVideoRequest(bid) { } } // read playersize and assign to h and w. - if (isArray(bid.mediaTypes.video.playerSize[0])) { + if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0][0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[0][1], 10); - } else if (isNumber(bid.mediaTypes.video.playerSize[0])) { + } else if (utils.isNumber(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[1], 10); } @@ -337,7 +337,7 @@ function _createVideoRequest(bid) { } } else { videoObj = UNDEFINED; - logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); } return videoObj; } @@ -355,7 +355,7 @@ function _checkMediaType(adm, newBid) { newBid.mediaType = NATIVE; } } catch (e) { - logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); } } } @@ -401,9 +401,9 @@ function _createImpressionObject(bid, conf) { pos: 0, w: bid.params.width, h: bid.params.height, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 }; - if (isArray(sizes) && sizes.length > 1) { + if (utils.isArray(sizes) && sizes.length > 1) { sizes = sizes.splice(1, sizes.length - 1); sizes.forEach(size => { format.push({ @@ -428,19 +428,19 @@ export const spec = { isBidRequestValid: function (bid) { if (bid && bid.params) { if (!bid.params.zoneId) { - logWarn(LOG_WARN_PREFIX + 'Error: missing zoneId'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: missing zoneId'); return false; } if (!bid.params.publisherId) { - logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId'); return false; } - if (!isStr(bid.params.publisherId)) { - logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric'); + if (!utils.isStr(bid.params.publisherId)) { + utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric'); return false; } - if (!isStr(bid.params.zoneId)) { - logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric'); + if (!utils.isStr(bid.params.zoneId)) { + utils.logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric'); return false; } return true; @@ -458,7 +458,7 @@ export const spec = { let bidCurrency = ''; let bid; validBidRequests.forEach(originalBid => { - bid = deepClone(originalBid); + bid = utils.deepClone(originalBid); _parseAdSlot(bid); conf.zoneId = conf.zoneId || bid.params.zoneId; @@ -468,7 +468,7 @@ export const spec = { if (bidCurrency === '') { bidCurrency = bid.params.currency || UNDEFINED; } else if (bid.params.hasOwnProperty('currency') && bidCurrency !== bid.params.currency) { - logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); + utils.logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); } bid.params.currency = bidCurrency; @@ -502,28 +502,28 @@ export const spec = { if (typeof config.getConfig('device') === 'object') { payload.device = Object.assign(payload.device, config.getConfig('device')); } - deepSetValue(payload, 'source.tid', conf.transactionId); + utils.deepSetValue(payload, 'source.tid', conf.transactionId); // test bids if (window.location.href.indexOf('adtrueTest=true') !== -1) { payload.test = 1; } // adding schain object if (validBidRequests[0].schain) { - deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } // Attaching GDPR Consent Params if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // coppa compliance if (config.getConfig('coppa') === true) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } return { @@ -539,12 +539,12 @@ export const spec = { let parsedRequest = JSON.parse(bidderRequest.data); let parsedReferrer = parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : ''; try { - if (serverResponses.body && serverResponses.body.seatbid && isArray(serverResponses.body.seatbid)) { + if (serverResponses.body && serverResponses.body.seatbid && utils.isArray(serverResponses.body.seatbid)) { // Supporting multiple bid responses for same adSize respCur = serverResponses.body.cur || respCur; serverResponses.body.seatbid.forEach(seatbidder => { seatbidder.bid && - isArray(seatbidder.bid) && + utils.isArray(seatbidder.bid) && seatbidder.bid.forEach(bid => { let newBid = { requestId: bid.impid, @@ -598,7 +598,7 @@ export const spec = { }); } } catch (error) { - logError(error); + utils.logError(error); } return bidResponses; }, @@ -607,7 +607,7 @@ export const spec = { return []; } return responses.reduce((accum, rsp) => { - let cookieSyncs = deepAccess(rsp, 'body.ext.cookie_sync'); + let cookieSyncs = utils.deepAccess(rsp, 'body.ext.cookie_sync'); if (cookieSyncs) { let cookieSyncObjects = cookieSyncs.map(cookieSync => { return { diff --git a/modules/aduptechBidAdapter.js b/modules/aduptechBidAdapter.js index 1186e0410ab..b70f7cf3ce6 100644 --- a/modules/aduptechBidAdapter.js +++ b/modules/aduptechBidAdapter.js @@ -1,7 +1,7 @@ -import { deepAccess, getWindowTop, getWindowSelf, getAdUnitSizes } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js' +import * as utils from '../src/utils.js'; export const BIDDER_CODE = 'aduptech'; export const ENDPOINT_URL_PUBLISHER_PLACEHOLDER = '{PUBLISHER}'; @@ -37,7 +37,7 @@ export const internal = { * @returns {string} */ extractPageUrl: (bidderRequest) => { - if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.canonicalUrl')) { + if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl')) { return bidderRequest.refererInfo.canonicalUrl; } @@ -46,9 +46,9 @@ export const internal = { } try { - return getWindowTop().location.href; + return utils.getWindowTop().location.href; } catch (e) { - return getWindowSelf().location.href; + return utils.getWindowSelf().location.href; } }, @@ -59,14 +59,14 @@ export const internal = { * @returns {string} */ extractReferrer: (bidderRequest) => { - if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) { + if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } try { - return getWindowTop().document.referrer; + return utils.getWindowTop().document.referrer; } catch (e) { - return getWindowSelf().document.referrer; + return utils.getWindowSelf().document.referrer; } }, @@ -77,7 +77,7 @@ export const internal = { * @returns {null|Object.} */ extractBannerConfig: (bidRequest) => { - const sizes = getAdUnitSizes(bidRequest); + const sizes = utils.getAdUnitSizes(bidRequest); if (Array.isArray(sizes) && sizes.length > 0) { return { sizes: sizes }; } @@ -92,7 +92,7 @@ export const internal = { * @returns {null|Object.} */ extractNativeConfig: (bidRequest) => { - if (bidRequest && deepAccess(bidRequest, 'mediaTypes.native')) { + if (bidRequest && utils.deepAccess(bidRequest, 'mediaTypes.native')) { return bidRequest.mediaTypes.native; } @@ -267,7 +267,7 @@ export const spec = { const bidResponses = []; // stop here on invalid or empty data - if (!response || !deepAccess(response, 'body.bids') || response.body.bids.length === 0) { + if (!response || !utils.deepAccess(response, 'body.bids') || response.body.bids.length === 0) { return bidResponses; } diff --git a/modules/advangelistsBidAdapter.js b/modules/advangelistsBidAdapter.js deleted file mode 100755 index 854c65b1f22..00000000000 --- a/modules/advangelistsBidAdapter.js +++ /dev/null @@ -1,398 +0,0 @@ -import { isEmpty, deepAccess, isFn, parseSizesInput, generateUUID, parseUrl } from '../src/utils.js'; -import { config } from '../src/config.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { VIDEO, BANNER } from '../src/mediaTypes.js'; -import find from 'core-js-pure/features/array/find.js'; -import includes from 'core-js-pure/features/array/includes.js'; - -const ADAPTER_VERSION = '1.0'; -const BIDDER_CODE = 'advangelists'; - -export const VIDEO_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid=';// 0cf8d6d643e13d86a5b6374148a4afac'; -export const BANNER_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid=';// 0cf8d6d643e13d86a5b6374148a4afac'; -export const OUTSTREAM_SRC = 'https://player-cdn.beachfrontmedia.com/playerapi/loader/outstream.js'; -export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration', 'skip', 'playerSize', 'context']; -export const DEFAULT_MIMES = ['video/mp4', 'application/javascript']; - -let pubid = ''; - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], - - isBidRequestValid(bidRequest) { - if (typeof bidRequest != 'undefined') { - if (bidRequest.bidder !== BIDDER_CODE && typeof bidRequest.params === 'undefined') { return false; } - if (bidRequest === '' || bidRequest.params.placement === '' || bidRequest.params.pubid === '') { return false; } - return true; - } else { return false; } - }, - - buildRequests(bids, bidderRequest) { - let requests = []; - let videoBids = bids.filter(bid => isVideoBidValid(bid)); - let bannerBids = bids.filter(bid => isBannerBidValid(bid)); - videoBids.forEach(bid => { - pubid = getVideoBidParam(bid, 'pubid'); - requests.push({ - method: 'POST', - url: VIDEO_ENDPOINT + pubid, - data: createVideoRequestData(bid, bidderRequest), - bidRequest: bid - }); - }); - - bannerBids.forEach(bid => { - pubid = getBannerBidParam(bid, 'pubid'); - requests.push({ - method: 'POST', - url: BANNER_ENDPOINT + pubid, - data: createBannerRequestData(bid, bidderRequest), - bidRequest: bid - }); - }); - return requests; - }, - - interpretResponse(serverResponse, {bidRequest}) { - let response = serverResponse.body; - if (response !== null && isEmpty(response) == false) { - if (isVideoBid(bidRequest)) { - let bidResponse = { - requestId: response.id, - bidderCode: BIDDER_CODE, - cpm: response.seatbid[0].bid[0].price, - width: response.seatbid[0].bid[0].w, - height: response.seatbid[0].bid[0].h, - ttl: response.seatbid[0].bid[0].ttl || 60, - creativeId: response.seatbid[0].bid[0].crid, - meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain }, - currency: response.cur, - mediaType: VIDEO, - netRevenue: true - } - - if (response.seatbid[0].bid[0].adm) { - bidResponse.vastXml = response.seatbid[0].bid[0].adm; - bidResponse.adResponse = { - content: response.seatbid[0].bid[0].adm - }; - } else { - bidResponse.vastUrl = response.seatbid[0].bid[0].nurl; - } - - return bidResponse; - } else { - return { - requestId: response.id, - bidderCode: BIDDER_CODE, - cpm: response.seatbid[0].bid[0].price, - width: response.seatbid[0].bid[0].w, - height: response.seatbid[0].bid[0].h, - ad: response.seatbid[0].bid[0].adm, - ttl: response.seatbid[0].bid[0].ttl || 60, - creativeId: response.seatbid[0].bid[0].crid, - currency: response.cur, - meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain }, - mediaType: BANNER, - netRevenue: true - } - } - } - } -}; - -function isBannerBid(bid) { - return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); -} - -function isVideoBid(bid) { - return deepAccess(bid, 'mediaTypes.video'); -} - -function getBannerBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {}; - return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); -} - -function getVideoBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'video', size: '*' }) : {}; - return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); -} - -function isVideoBidValid(bid) { - return isVideoBid(bid) && getVideoBidParam(bid, 'pubid') && getVideoBidParam(bid, 'placement'); -} - -function isBannerBidValid(bid) { - return isBannerBid(bid) && getBannerBidParam(bid, 'pubid') && getBannerBidParam(bid, 'placement'); -} - -function getVideoBidParam(bid, key) { - return deepAccess(bid, 'params.video.' + key) || deepAccess(bid, 'params.' + key); -} - -function getBannerBidParam(bid, key) { - return deepAccess(bid, 'params.banner.' + key) || deepAccess(bid, 'params.' + key); -} - -function isMobile() { - return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent); -} - -function isConnectedTV() { - return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(navigator.userAgent); -} - -function getDoNotTrack() { - return navigator.doNotTrack === '1' || window.doNotTrack === '1' || navigator.msDoNoTrack === '1' || navigator.doNotTrack === 'yes'; -} - -function findAndFillParam(o, key, value) { - try { - if (typeof value === 'function') { - o[key] = value(); - } else { - o[key] = value; - } - } catch (ex) {} -} - -function getOsVersion() { - let clientStrings = [ - { s: 'Android', r: /Android/ }, - { s: 'iOS', r: /(iPhone|iPad|iPod)/ }, - { s: 'Mac OS X', r: /Mac OS X/ }, - { s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ }, - { s: 'Linux', r: /(Linux|X11)/ }, - { s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ }, - { s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ }, - { s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ }, - { s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ }, - { s: 'Windows Vista', r: /Windows NT 6.0/ }, - { s: 'Windows Server 2003', r: /Windows NT 5.2/ }, - { s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ }, - { s: 'UNIX', r: /UNIX/ }, - { s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ } - ]; - let cs = find(clientStrings, cs => cs.r.test(navigator.userAgent)); - return cs ? cs.s : 'unknown'; -} - -function getFirstSize(sizes) { - return (sizes && sizes.length) ? sizes[0] : { w: undefined, h: undefined }; -} - -function parseSizes(sizes) { - return parseSizesInput(sizes).map(size => { - let [ width, height ] = size.split('x'); - return { - w: parseInt(width, 10) || undefined, - h: parseInt(height, 10) || undefined - }; - }); -} - -function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); -} - -function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); -} - -function getTopWindowReferrer() { - try { - return window.top.document.referrer; - } catch (e) { - return ''; - } -} - -function getVideoTargetingParams(bid) { - const result = {}; - const excludeProps = ['playerSize', 'context', 'w', 'h']; - Object.keys(Object(bid.mediaTypes.video)) - .filter(key => !includes(excludeProps, key)) - .forEach(key => { - result[ key ] = bid.mediaTypes.video[ key ]; - }); - Object.keys(Object(bid.params.video)) - .filter(key => includes(VIDEO_TARGETING, key)) - .forEach(key => { - result[ key ] = bid.params.video[ key ]; - }); - return result; -} - -function createVideoRequestData(bid, bidderRequest) { - let topLocation = getTopWindowLocation(bidderRequest); - let topReferrer = getTopWindowReferrer(); - - let sizes = getVideoSizes(bid); - let firstSize = getFirstSize(sizes); - let bidfloor = (getVideoBidFloor(bid) == null || typeof getVideoBidFloor(bid) == 'undefined') ? 2 : getVideoBidFloor(bid); - let video = getVideoTargetingParams(bid); - const o = { - 'device': { - 'langauge': (global.navigator.language).split('-')[0], - 'dnt': (global.navigator.doNotTrack === 1 ? 1 : 0), - 'devicetype': isMobile() ? 4 : isConnectedTV() ? 3 : 2, - 'js': 1, - 'os': getOsVersion() - }, - 'at': 2, - 'site': {}, - 'tmax': 3000, - 'cur': ['USD'], - 'id': bid.bidId, - 'imp': [], - 'regs': { - 'ext': { - } - }, - 'user': { - 'ext': { - } - } - }; - - o.site['page'] = topLocation.href; - o.site['domain'] = topLocation.hostname; - o.site['search'] = topLocation.search; - o.site['domain'] = topLocation.hostname; - o.site['ref'] = topReferrer; - o.site['mobile'] = isMobile() ? 1 : 0; - const secure = topLocation.protocol.indexOf('https') === 0 ? 1 : 0; - - o.device['dnt'] = getDoNotTrack() ? 1 : 0; - - findAndFillParam(o.site, 'name', function() { - return global.top.document.title; - }); - - findAndFillParam(o.device, 'h', function() { - return global.screen.height; - }); - findAndFillParam(o.device, 'w', function() { - return global.screen.width; - }); - - let placement = getVideoBidParam(bid, 'placement'); - - for (let j = 0; j < sizes.length; j++) { - o.imp.push({ - 'id': '' + j, - 'displaymanager': '' + BIDDER_CODE, - 'displaymanagerver': '' + ADAPTER_VERSION, - 'tagId': placement, - 'bidfloor': bidfloor, - 'bidfloorcur': 'USD', - 'secure': secure, - 'video': Object.assign({ - 'id': generateUUID(), - 'pos': 0, - 'w': firstSize.w, - 'h': firstSize.h, - 'mimes': DEFAULT_MIMES - }, video) - - }); - } - - if (bidderRequest && bidderRequest.gdprConsent) { - let { gdprApplies, consentString } = bidderRequest.gdprConsent; - o.regs.ext = {'gdpr': gdprApplies ? 1 : 0}; - o.user.ext = {'consent': consentString}; - } - - return o; -} - -function getTopWindowLocation(bidderRequest) { - let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); -} - -function createBannerRequestData(bid, bidderRequest) { - let topLocation = getTopWindowLocation(bidderRequest); - let topReferrer = getTopWindowReferrer(); - - let sizes = getBannerSizes(bid); - let bidfloor = (getBannerBidFloor(bid) == null || typeof getBannerBidFloor(bid) == 'undefined') ? 2 : getBannerBidFloor(bid); - - const o = { - 'device': { - 'langauge': (global.navigator.language).split('-')[0], - 'dnt': (global.navigator.doNotTrack === 1 ? 1 : 0), - 'devicetype': isMobile() ? 4 : isConnectedTV() ? 3 : 2, - 'js': 1 - }, - 'at': 2, - 'site': {}, - 'tmax': 3000, - 'cur': ['USD'], - 'id': bid.bidId, - 'imp': [], - 'regs': { - 'ext': { - } - }, - 'user': { - 'ext': { - } - } - }; - - o.site['page'] = topLocation.href; - o.site['domain'] = topLocation.hostname; - o.site['search'] = topLocation.search; - o.site['domain'] = topLocation.hostname; - o.site['ref'] = topReferrer; - o.site['mobile'] = isMobile() ? 1 : 0; - const secure = topLocation.protocol.indexOf('https') === 0 ? 1 : 0; - - o.device['dnt'] = getDoNotTrack() ? 1 : 0; - - findAndFillParam(o.site, 'name', function() { - return global.top.document.title; - }); - - findAndFillParam(o.device, 'h', function() { - return global.screen.height; - }); - findAndFillParam(o.device, 'w', function() { - return global.screen.width; - }); - - let placement = getBannerBidParam(bid, 'placement'); - for (let j = 0; j < sizes.length; j++) { - let size = sizes[j]; - - o.imp.push({ - 'id': '' + j, - 'displaymanager': '' + BIDDER_CODE, - 'displaymanagerver': '' + ADAPTER_VERSION, - 'tagId': placement, - 'bidfloor': bidfloor, - 'bidfloorcur': 'USD', - 'secure': secure, - 'banner': { - 'id': generateUUID(), - 'pos': 0, - 'w': size['w'], - 'h': size['h'] - } - }); - } - - if (bidderRequest && bidderRequest.gdprConsent) { - let { gdprApplies, consentString } = bidderRequest.gdprConsent; - o.regs.ext = {'gdpr': gdprApplies ? 1 : 0}; - o.user.ext = {'consent': consentString}; - } - - return o; -} - -registerBidder(spec); diff --git a/modules/advangelistsBidAdapter.md b/modules/advangelistsBidAdapter.md index 04537ff677d..1765241eaf3 100755 --- a/modules/advangelistsBidAdapter.md +++ b/modules/advangelistsBidAdapter.md @@ -42,11 +42,7 @@ var videoAdUnit = { mediaTypes: { video: { playerSize : [[320, 480]], - context: 'instream', - skip: 1, - mimes : ['video/mp4', 'application/javascript'], - playbackmethod : [2,6], - maxduration: 30 + context: 'instream' } }, bids: [ @@ -54,7 +50,14 @@ var videoAdUnit = { bidder: 'advangelists', params: { pubid: '8537f00948fc37cc03c5f0f88e198a76', - placement: 1234 + placement: 1234, + video: { + id: 123, + skip: 1, + mimes : ['video/mp4', 'application/javascript'], + playbackmethod : [2,6], + maxduration: 30 + } } } ] diff --git a/modules/adxcgAnalyticsAdapter.js b/modules/adxcgAnalyticsAdapter.js index 5cd04ce13cd..9f514c545a1 100644 --- a/modules/adxcgAnalyticsAdapter.js +++ b/modules/adxcgAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { parseSizesInput, uniques, buildUrl, logError } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; /** * Analytics adapter from adxcg.com @@ -32,7 +32,7 @@ var adxcgAnalyticsAdapter = Object.assign(adapter( case CONSTANTS.EVENTS.BID_ADJUSTMENT: break; case CONSTANTS.EVENTS.BID_TIMEOUT: - adxcgAnalyticsAdapter.context.events.bidTimeout = args.map(item => item.bidder).filter(uniques); + adxcgAnalyticsAdapter.context.events.bidTimeout = args.map(item => item.bidder).filter(utils.uniques); break; case CONSTANTS.EVENTS.BIDDER_DONE: break; @@ -67,7 +67,7 @@ function mapBidRequested (bidRequests) { adUnitCode: bid.adUnitCode, bidId: bid.bidId, start: bid.startTime, - sizes: parseSizesInput(bid.sizes).toString(), + sizes: utils.parseSizesInput(bid.sizes).toString(), params: bid.params }; }), @@ -112,7 +112,7 @@ function mapBidWon (bidResponse) { } function send (data) { - let adxcgAnalyticsRequestUrl = buildUrl({ + let adxcgAnalyticsRequestUrl = utils.buildUrl({ protocol: 'https', hostname: adxcgAnalyticsAdapter.context.host, pathname: '/pbrx/v2', @@ -143,7 +143,7 @@ adxcgAnalyticsAdapter.context = {}; adxcgAnalyticsAdapter.originEnableAnalytics = adxcgAnalyticsAdapter.enableAnalytics; adxcgAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.publisherId) { - logError('PublisherId option is not defined. Analytics won\'t work'); + utils.logError('PublisherId option is not defined. Analytics won\'t work'); return; } diff --git a/modules/adxcgBidAdapter.js b/modules/adxcgBidAdapter.js index 81872100cd1..e10eeaa3302 100644 --- a/modules/adxcgBidAdapter.js +++ b/modules/adxcgBidAdapter.js @@ -1,362 +1,410 @@ -// jshint esversion: 6, es3: false, node: true -'use strict'; - -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {NATIVE, BANNER, VIDEO} from '../src/mediaTypes.js'; -import { - mergeDeep, - _map, - deepAccess, - getDNT, - parseSizesInput, - deepSetValue, - isStr, - isArray, - isPlainObject, - parseUrl, - replaceAuctionPrice, triggerPixel -} from '../src/utils.js'; -import {config} from '../src/config.js'; - -const { getConfig } = config; - -const BIDDER_CODE = 'adxcg'; -const SECURE_BID_URL = 'https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'; - -const NATIVE_ASSET_IDS = { 0: 'title', 2: 'icon', 3: 'image', 5: 'sponsoredBy', 4: 'body', 1: 'cta' }; -const NATIVE_PARAMS = { - title: { - id: 0, - name: 'title' - }, - icon: { - id: 2, - type: 1, - name: 'img' - }, - image: { - id: 3, - type: 3, - name: 'img' - }, - sponsoredBy: { - id: 5, - name: 'data', - type: 1 - }, - body: { - id: 4, - name: 'data', - type: 2 - }, - cta: { - id: 1, - type: 12, - name: 'data' - } -}; +import {config} from '../src/config.js' +import * as utils from '../src/utils.js' +import {registerBidder} from '../src/adapters/bidderFactory.js' +import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js' +import includes from 'core-js-pure/features/array/includes.js' + +/** + * Adapter for requesting bids from adxcg.net + * updated to latest prebid repo on 2017.10.20 + * updated for gdpr compliance on 2018.05.22 -requires gdpr compliance module + * updated to pass aditional auction and impression level parameters. added pass for video targeting parameters + * updated to fix native support for image width/height and icon 2019.03.17 + * updated support for userid - pubcid,ttid 2019.05.28 + * updated to support prebid 3.0 - remove non https, move to banner.xx.sizes, remove utils.getTopWindowLocation,remove utils.getTopWindowUrl(),remove utils.getTopWindowReferrer() + * updated to support prebid 4.0 - standardized video params, updated video validation, add onBidWon, onTimeOut, use standardized getFloor + */ + +const BIDDER_CODE = 'adxcg' +const SUPPORTED_AD_TYPES = [BANNER, VIDEO, NATIVE] +const SOURCE = 'pbjs10' +const VIDEO_TARGETING = ['id', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks'] +const USER_PARAMS_AUCTION = ['forcedDspIds', 'forcedCampaignIds', 'forcedCreativeIds', 'gender', 'dnt', 'language'] +const USER_PARAMS_BID = ['lineparam1', 'lineparam2', 'lineparam3'] +const BIDADAPTERVERSION = 'r20210330PB40' +const DEFAULT_MIN_FLOOR = 0; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [ NATIVE, BANNER, VIDEO ], - isBidRequestValid: (bid) => { - const params = bid.params || {}; - const { adzoneid } = params; - return !!(adzoneid); - }, - buildRequests: (validBidRequests, bidderRequest) => { - let app, site; - - const commonFpd = getConfig('ortb2') || {}; - let { user } = commonFpd; + supportedMediaTypes: SUPPORTED_AD_TYPES, + + /** + * Determines whether or not the given bid request is valid. + * + * @param {object} bid The bid params to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function (bid) { + if (!bid || !bid.params) { + utils.logWarn(BIDDER_CODE + ': Missing bid parameters'); + return false + } - if (typeof getConfig('app') === 'object') { - app = getConfig('app') || {}; - if (commonFpd.app) { - mergeDeep(app, commonFpd.app); - } - } else { - site = getConfig('site') || {}; - if (commonFpd.site) { - mergeDeep(site, commonFpd.site); - } + if (!utils.isStr(bid.params.adzoneid)) { + utils.logWarn(BIDDER_CODE + ': adzoneid must be specified as a string'); + return false + } - if (!site.page) { - site.page = bidderRequest.refererInfo.referer; - site.domain = parseUrl(bidderRequest.refererInfo.referer).hostname; + if (isBannerRequest(bid)) { + const banneroAdUnit = utils.deepAccess(bid, 'mediaTypes.banner'); + if (!banneroAdUnit.sizes) { + utils.logWarn(BIDDER_CODE + ': banner sizes must be specified'); + return false; } } - const device = getConfig('device') || {}; - device.w = device.w || window.innerWidth; - device.h = device.h || window.innerHeight; - device.ua = device.ua || navigator.userAgent; - device.dnt = getDNT() ? 1 : 0; - device.language = (navigator && navigator.language) ? navigator.language.split('-')[0] : ''; - - const tid = validBidRequests[0].transactionId; - const test = setOnAny(validBidRequests, 'params.test'); - const currency = getConfig('currency.adServerCurrency'); - const cur = currency && [ currency ]; - const eids = setOnAny(validBidRequests, 'userIdAsEids'); - const schain = setOnAny(validBidRequests, 'schain'); - - const imp = validBidRequests.map((bid, id) => { - const floorInfo = bid.getFloor ? bid.getFloor({ - currency: currency || 'USD' - }) : {}; - const bidfloor = floorInfo.floor; - const bidfloorcur = floorInfo.currency; - const { adzoneid } = bid.params; - - const imp = { - id: id + 1, - tagid: adzoneid, - secure: 1, - bidfloor, - bidfloorcur, - ext: { - } - }; - - const assets = _map(bid.nativeParams, (bidParams, key) => { - const props = NATIVE_PARAMS[key]; - const asset = { - required: bidParams.required & 1, - }; - if (props) { - asset.id = props.id; - let wmin, hmin, w, h; - let aRatios = bidParams.aspect_ratios; - - if (aRatios && aRatios[0]) { - aRatios = aRatios[0]; - wmin = aRatios.min_width || 0; - hmin = aRatios.ratio_height * wmin / aRatios.ratio_width | 0; - } - - if (bidParams.sizes) { - const sizes = flatten(bidParams.sizes); - w = sizes[0]; - h = sizes[1]; - } + if (isVideoRequest(bid)) { + // prebid 4.0 use standardized Video parameters + const videoAdUnit = utils.deepAccess(bid, 'mediaTypes.video'); - asset[props.name] = { - len: bidParams.len, - type: props.type, - wmin, - hmin, - w, - h - }; - - return asset; - } - }).filter(Boolean); - - if (assets.length) { - imp.native = { - request: JSON.stringify({assets: assets}) - }; + if (!Array.isArray(videoAdUnit.playerSize)) { + utils.logWarn(BIDDER_CODE + ': video playerSize must be an array of integers'); + return false; } - const bannerParams = deepAccess(bid, 'mediaTypes.banner'); - - if (bannerParams && bannerParams.sizes) { - const sizes = parseSizesInput(bannerParams.sizes); - const format = sizes.map(size => { - const [ width, height ] = size.split('x'); - const w = parseInt(width, 10); - const h = parseInt(height, 10); - return { w, h }; - }); + if (!videoAdUnit.context) { + utils.logWarn(BIDDER_CODE + ': video context must be specified'); + return false; + } - imp.banner = { - format - }; + if (!Array.isArray(videoAdUnit.mimes) || videoAdUnit.mimes.length === 0) { + utils.logWarn(BIDDER_CODE + ': video mimes must be an array of strings'); + return false; } - const videoParams = deepAccess(bid, 'mediaTypes.video'); - if (videoParams) { - imp.video = videoParams; + if (!Array.isArray(videoAdUnit.protocols) || videoAdUnit.protocols.length === 0) { + utils.logWarn(BIDDER_CODE + ': video protocols must be an array of integers'); + return false; } + } - return imp; - }); + return true + }, - const request = { - id: bidderRequest.auctionId, - site, - app, - user, - geo: { utcoffset: new Date().getTimezoneOffset() }, - device, - source: { tid, fd: 1 }, - ext: { - prebid: { - channel: { - name: 'pbjs', - version: '$prebid.version$' - } - } - }, - cur, - imp + /** + * Make a server request from the list of BidRequests. + * + * an array of validBidRequests + * Info describing the request to the server. + */ + buildRequests: function (validBidRequests, bidderRequest) { + let dt = new Date(); + let ratio = window.devicePixelRatio || 1; + let iobavailable = window && window.IntersectionObserver && window.IntersectionObserverEntry && window.IntersectionObserverEntry.prototype && 'intersectionRatio' in window.IntersectionObserverEntry.prototype + + let bt = config.getConfig('bidderTimeout'); + if (window.PREBID_TIMEOUT) { + bt = Math.min(window.PREBID_TIMEOUT, bt); + } + + let referrer = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + let page = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); + + // add common parameters + let beaconParams = { + renderformat: 'javascript', + ver: BIDADAPTERVERSION, + secure: '1', + source: SOURCE, + uw: window.screen.width, + uh: window.screen.height, + dpr: ratio, + bt: bt, + isinframe: utils.inIframe(), + cookies: utils.checkCookieSupport() ? '1' : '0', + tz: dt.getTimezoneOffset(), + dt: utils.timestamp(), + iob: iobavailable ? '1' : '0', + pbjs: '$prebid.version$', + rndid: Math.floor(Math.random() * (999999 - 100000 + 1)) + 100000, + ref: encodeURIComponent(referrer), + url: encodeURIComponent(page) }; - if (test) { - request.is_debug = !!test; - request.test = 1; + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) { + beaconParams.gdpr = bidderRequest.gdprConsent.gdprApplies ? '1' : '0'; + beaconParams.gdpr_consent = bidderRequest.gdprConsent.consentString; + } + + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.pubcid'))) { + beaconParams.pubcid = validBidRequests[0].userId.pubcid; } - if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies') !== undefined) { - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); + + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.tdid'))) { + beaconParams.tdid = validBidRequests[0].userId.tdid; } - if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.id5id.uid'))) { + beaconParams.id5id = validBidRequests[0].userId.id5id.uid; } - if (eids) { - deepSetValue(request, 'user.ext.eids', eids); + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.idl_env'))) { + beaconParams.idl_env = validBidRequests[0].userId.idl_env; } - if (schain) { - deepSetValue(request, 'source.ext.schain', schain); + let biddercustom = config.getConfig(BIDDER_CODE); + if (biddercustom) { + Object.keys(biddercustom) + .filter(param => includes(USER_PARAMS_AUCTION, param)) + .forEach(param => beaconParams[param] = encodeURIComponent(biddercustom[param])) } + // per impression parameters + let adZoneIds = []; + let prebidBidIds = []; + let sizes = []; + let bidfloors = []; + + validBidRequests.forEach((bid, index) => { + adZoneIds.push(utils.getBidIdParameter('adzoneid', bid.params)); + prebidBidIds.push(bid.bidId); + + let bidfloor = getFloor(bid); + bidfloors.push(bidfloor); + + // copy all custom parameters impression level parameters not supported above + let customBidParams = utils.getBidIdParameter('custom', bid.params) || {} + if (customBidParams) { + Object.keys(customBidParams) + .filter(param => includes(USER_PARAMS_BID, param)) + .forEach(param => beaconParams[param + '.' + index] = encodeURIComponent(customBidParams[param])) + } + + if (isBannerRequest(bid)) { + sizes.push(utils.parseSizesInput(bid.mediaTypes.banner.sizes).join('|')); + } + + if (isNativeRequest(bid)) { + sizes.push('0x0'); + } + + if (isVideoRequest(bid)) { + if (bid.params.video) { + Object.keys(bid.params.video) + .filter(param => includes(VIDEO_TARGETING, param)) + .forEach(param => beaconParams['video.' + param + '.' + index] = encodeURIComponent(bid.params.video[param])) + } + // copy video standarized params + beaconParams['video.context' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.context'); + sizes.push(utils.parseSizesInput(bid.mediaTypes.video.playerSize).join('|')); + beaconParams['video.mimes' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.mimes').join(','); + beaconParams['video.protocols' + '.' + index] = utils.deepAccess(bid, 'mediaTypes.video.protocols').join(','); + } + }) + + beaconParams.adzoneid = adZoneIds.join(','); + beaconParams.format = sizes.join(','); + beaconParams.prebidBidIds = prebidBidIds.join(','); + beaconParams.bidfloors = bidfloors.join(','); + + let adxcgRequestUrl = utils.buildUrl({ + protocol: 'https', + hostname: 'hbps.adxcg.net', + pathname: '/get/adi', + search: beaconParams + }); + + utils.logMessage(`calling adi adxcg`); return { - method: 'POST', - url: SECURE_BID_URL, - data: JSON.stringify(request), - options: { - contentType: 'application/json' - }, - bids: validBidRequests + contentType: 'text/plain', + method: 'GET', + url: adxcgRequestUrl, + withCredentials: true }; }, - interpretResponse: function(serverResponse, { bids }) { - if (!serverResponse.body) { - return; - } - const { seatbid, cur } = serverResponse.body; - - const bidResponses = flatten(seatbid.map(seat => seat.bid)).reduce((result, bid) => { - result[bid.impid - 1] = bid; - return result; - }, []); - - return bids.map((bid, id) => { - const bidResponse = bidResponses[id]; - if (bidResponse) { - const mediaType = deepAccess(bidResponse, 'ext.crType'); - const result = { - requestId: bid.bidId, - cpm: bidResponse.price, - creativeId: bidResponse.crid, - ttl: bidResponse.ttl ? bidResponse.ttl : 300, - netRevenue: bid.netRevenue === 'net', - currency: cur, - burl: bid.burl || '', - mediaType: mediaType, - width: bidResponse.w, - height: bidResponse.h, - dealId: bidResponse.dealid, - }; - - deepSetValue(result, 'meta.mediaType', mediaType); - if (isArray(bidResponse.adomain)) { - deepSetValue(result, 'meta.advertiserDomains', bidResponse.adomain); - } + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {bidRequests[]} An array of bids which were nested inside the server. + */ + interpretResponse: + function (serverResponse) { + utils.logMessage(`interpretResponse adxcg`); + let bidsAll = []; + + if (!serverResponse || !serverResponse.body || !utils.isArray(serverResponse.body.seatbid) || !serverResponse.body.seatbid.length) { + utils.logWarn(BIDDER_CODE + ': empty bid response'); + return bidsAll; + } + + serverResponse.body.seatbid.forEach((bids) => { + bids.bid.forEach((serverResponseOneItem) => { + let bid = {} + // parse general fields + bid.requestId = serverResponseOneItem.impid; + bid.cpm = serverResponseOneItem.price; + bid.creativeId = parseInt(serverResponseOneItem.crid); + bid.currency = serverResponseOneItem.currency ? serverResponseOneItem.currency : 'USD'; + bid.netRevenue = serverResponseOneItem.netRevenue ? serverResponseOneItem.netRevenue : true; + bid.ttl = serverResponseOneItem.ttl ? serverResponseOneItem.ttl : 300; + bid.width = serverResponseOneItem.w; + bid.height = serverResponseOneItem.h; + bid.burl = serverResponseOneItem.burl || ''; + + if (serverResponseOneItem.dealid != null && serverResponseOneItem.dealid.trim().length > 0) { + bid.dealId = serverResponseOneItem.dealid; + } - if (isPlainObject(bidResponse.ext)) { - if (isStr(bidResponse.ext.mediaType)) { - deepSetValue(result, 'meta.mediaType', mediaType); + if (serverResponseOneItem.ext.crType === 'banner') { + bid.ad = serverResponseOneItem.adm; + } else if (serverResponseOneItem.ext.crType === 'video') { + bid.vastUrl = serverResponseOneItem.nurl; + bid.vastXml = serverResponseOneItem.adm; + bid.mediaType = 'video'; + } else if (serverResponseOneItem.ext.crType === 'native') { + bid.mediaType = 'native'; + bid.native = parseNative(JSON.parse(serverResponseOneItem.adm)); + } else { + utils.logWarn(BIDDER_CODE + ': unknown or undefined crType'); } - if (isStr(bidResponse.ext.advertiser_id)) { - deepSetValue(result, 'meta.advertiserId', bidResponse.ext.advertiser_id); + + // prebid 4.0 meta taxonomy + if (utils.isArray(serverResponseOneItem.adomain)) { + utils.deepSetValue(bid, 'meta.advertiserDomains', serverResponseOneItem.adomain); } - if (isStr(bidResponse.ext.advertiser_name)) { - deepSetValue(result, 'meta.advertiserName', bidResponse.ext.advertiser_name); + if (utils.isArray(serverResponseOneItem.cat)) { + utils.deepSetValue(bid, 'meta.secondaryCatIds', serverResponseOneItem.cat); } - if (isStr(bidResponse.ext.agency_name)) { - deepSetValue(result, 'meta.agencyName', bidResponse.ext.agency_name); + if (utils.isPlainObject(serverResponseOneItem.ext)) { + if (utils.isStr(serverResponseOneItem.ext.advertiser_id)) { + utils.deepSetValue(bid, 'meta.mediaType', serverResponseOneItem.ext.mediaType); + } + if (utils.isStr(serverResponseOneItem.ext.advertiser_id)) { + utils.deepSetValue(bid, 'meta.advertiserId', serverResponseOneItem.ext.advertiser_id); + } + if (utils.isStr(serverResponseOneItem.ext.advertiser_name)) { + utils.deepSetValue(bid, 'meta.advertiserName', serverResponseOneItem.ext.advertiser_name); + } + if (utils.isStr(serverResponseOneItem.ext.agency_name)) { + utils.deepSetValue(bid, 'meta.agencyName', serverResponseOneItem.ext.agency_name); + } } - } - if (mediaType === BANNER) { - result.ad = bidResponse.adm; - } else if (mediaType === NATIVE) { - result.native = parseNative(bidResponse); - result.width = 0; - result.height = 0; - } else if (mediaType === VIDEO) { - result.vastUrl = bidResponse.nurl; - result.vastXml = bidResponse.adm; - } + bidsAll.push(bid) + }) + }) + return bidsAll + }, - return result; - } - }).filter(Boolean); + onBidWon: (bid) => { + if (bid.burl) { + utils.triggerPixel(utils.replaceAuctionPrice(bid.burl, bid.originalCpm)); + } }, - getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => { - const syncs = []; - let syncUrl = config.getConfig('adxcg.usersyncUrl'); - - let query = []; - if (syncOptions.pixelEnabled && syncUrl) { - if (gdprConsent) { - query.push('gdpr=' + (gdprConsent.gdprApplies & 1)); - query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '')); - } - if (uspConsent) { - query.push('us_privacy=' + encodeURIComponent(uspConsent)); - } - syncs.push({ - type: 'image', - url: syncUrl + (query.length ? '?' + query.join('&') : '') - }); + onTimeout(timeoutData) { + if (timeoutData == null) { + return; } - return syncs; + + let beaconParams = { + A: timeoutData.bidder, + bid: timeoutData.bidId, + a: timeoutData.adUnitCode, + cn: timeoutData.timeout, + aud: timeoutData.auctionId, + }; + let adxcgRequestUrl = utils.buildUrl({ + protocol: 'https', + hostname: 'hbps.adxcg.net', + pathname: '/event/timeout.gif', + search: beaconParams + }); + utils.logWarn(BIDDER_CODE + ': onTimeout called'); + utils.triggerPixel(adxcgRequestUrl); }, - onBidWon: (bid) => { - // for native requests we put the nurl as an imp tracker, otherwise if the auction takes place on prebid server - // the server JS adapter puts the nurl in the adm as a tracking pixel and removes the attribute - if (bid.nurl) { - triggerPixel(replaceAuctionPrice(bid.nurl, bid.originalCpm)) + + getUserSyncs: function (syncOptions, serverResponses, gdprConsent) { + let params = ''; + if (gdprConsent && 'gdprApplies' in gdprConsent) { + if (gdprConsent.consentString) { + if (typeof gdprConsent.gdprApplies === 'boolean') { + params += `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + params += `?gdpr=0&gdpr_consent=${gdprConsent.consentString}`; + } + } + } + + if (syncOptions.iframeEnabled) { + return [{ + type: 'iframe', + url: 'https://cdn.adxcg.net/pb-sync.html' + params + }]; } } -}; +} -registerBidder(spec); +function isVideoRequest(bid) { + return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video'); +} -function parseNative(bid) { - const { assets, link, imptrackers, jstracker } = JSON.parse(bid.adm); - const result = { - clickUrl: link.url, - clickTrackers: link.clicktrackers || undefined, - impressionTrackers: imptrackers || undefined, - javascriptTrackers: jstracker ? [ jstracker ] : undefined - }; - assets.forEach(asset => { - const kind = NATIVE_ASSET_IDS[asset.id]; - const content = kind && asset[NATIVE_PARAMS[kind].name]; - if (content) { - result[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h }; - } - }); - return result; +function isBannerRequest(bid) { + return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner'); } -function setOnAny(collection, key) { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); - if (result) { - return result; - } +function isNativeRequest(bid) { + return bid.mediaType === 'native' || !!utils.deepAccess(bid, 'mediaTypes.native'); +} + +function getFloor(bid) { + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.floor', DEFAULT_MIN_FLOOR); + } + + try { + const floor = bid.getFloor({ + currency: 'EUR', + mediaType: '*', + size: '*', + bidRequest: bid + }); + return floor.floor; + } catch (e) { + utils.logWarn(BIDDER_CODE + ': call to getFloor failed:' + e.message); + return DEFAULT_MIN_FLOOR; } } -function flatten(arr) { - return [].concat(...arr); +function parseNative(nativeResponse) { + let bidNative = {}; + bidNative = { + clickUrl: nativeResponse.link.url, + impressionTrackers: nativeResponse.imptrackers, + clickTrackers: nativeResponse.clktrackers, + javascriptTrackers: nativeResponse.jstrackers + }; + + nativeResponse.assets.forEach(asset => { + if (asset.title && asset.title.text) { + bidNative.title = asset.title.text; + } + + if (asset.img && asset.img.url) { + bidNative.image = { + url: asset.img.url, + height: asset.img.h, + width: asset.img.w + }; + } + + if (asset.icon && asset.icon.url) { + bidNative.icon = { + url: asset.icon.url, + height: asset.icon.h, + width: asset.icon.w + }; + } + + if (asset.data && asset.data.label === 'DESC' && asset.data.value) { + bidNative.body = asset.data.value; + } + + if (asset.data && asset.data.label === 'SPONSORED' && asset.data.value) { + bidNative.sponsoredBy = asset.data.value; + } + }) + return bidNative; } + +registerBidder(spec) diff --git a/modules/adxcgBidAdapter.md b/modules/adxcgBidAdapter.md index 1e4ef9cd6f9..8eccdb11dee 100644 --- a/modules/adxcgBidAdapter.md +++ b/modules/adxcgBidAdapter.md @@ -34,34 +34,31 @@ Module that connects to an Adxcg.com zone to fetch bids. code: 'native-ad-div', mediaTypes: { native: { - image: { + image: { sendId: false, - required: false, - sizes: [127, 83] + required: true, + sizes: [80, 80] }, icon: { - sizes: [80, 80], - required: false, + sendId: true, + }, + brand: { sendId: true, }, title: { sendId: false, - required: false, + required: true, len: 75 }, body: { sendId: false, - required: false, + required: true, len: 200 }, - cta: { - sendId: false, - required: false, - len: 75 - }, sponsoredBy: { sendId: false, - required: false + required: false, + len: 20 } } }, @@ -76,19 +73,21 @@ Module that connects to an Adxcg.com zone to fetch bids. code: 'video-div', mediaTypes: { video: { - playerSize: [640, 480], - context: 'instream', - mimes: ['video/mp4'], - protocols: [2, 3, 5, 6, 8], - playback_method: ['auto_play_sound_off'], - maxduration: 100, - skip: 1 - } + playerSize: [640, 480], + context: 'instream', + mimes: ['video/mp4'], + protocols: [5, 6, 8], + playback_method: ['auto_play_sound_off'] + } }, bids: [{ bidder: 'adxcg', params: { - adzoneid: '20' + adzoneid: '20', + video: { + maxduration: 100, + skippable: true + } } }] } diff --git a/modules/adxpremiumAnalyticsAdapter.js b/modules/adxpremiumAnalyticsAdapter.js index 3e30de14052..f11e3b8d4e5 100644 --- a/modules/adxpremiumAnalyticsAdapter.js +++ b/modules/adxpremiumAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { logError, logInfo, deepClone } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const analyticsType = 'endpoint'; @@ -95,7 +95,7 @@ function auctionInit(args) { completeObject.auction_id = args.auctionId; completeObject.publisher_id = adxpremiumAnalyticsAdapter.initOptions.pubId; - try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.referer.split('?')[0]); } catch (e) { logError('AdxPremium Analytics - ' + e.message); } + try { completeObject.referer = encodeURI(args.bidderRequests[0].refererInfo.referer.split('?')[0]); } catch (e) { utils.logError('AdxPremium Analytics - ' + e.message); } if (args.adUnitCodes && args.adUnitCodes.length > 0) { elementIds = args.adUnitCodes; } @@ -140,20 +140,20 @@ function bidWon(args) { if (requestDelivered) { if (completeObject.events[eventIndex]) { // do the upgrade - logInfo('AdxPremium Analytics - Upgrading request'); + utils.logInfo('AdxPremium Analytics - Upgrading request'); completeObject.events[eventIndex].is_winning = true; completeObject.events[eventIndex].is_upgrade = true; - upgradedObject = deepClone(completeObject); + upgradedObject = utils.deepClone(completeObject); upgradedObject.events = [completeObject.events[eventIndex]]; sendEvent(upgradedObject); // send upgrade } else { - logInfo('AdxPremium Analytics - CANNOT FIND INDEX FOR REQUEST ' + args.requestId); + utils.logInfo('AdxPremium Analytics - CANNOT FIND INDEX FOR REQUEST ' + args.requestId); } } else { completeObject.events[eventIndex].is_winning = true; } } else { - logInfo('AdxPremium Analytics - Response not found, creating new one.'); + utils.logInfo('AdxPremium Analytics - Response not found, creating new one.'); let tmpObject = { type: 'RESPONSE', bidder_code: args.bidderCode, @@ -167,14 +167,14 @@ function bidWon(args) { is_winning: true, is_lost: true }; - let lostObject = deepClone(completeObject); + let lostObject = utils.deepClone(completeObject); lostObject.events = [tmpObject]; sendEvent(lostObject); // send lost object } } function bidTimeout(args) { - let timeoutObject = deepClone(completeObject); + let timeoutObject = utils.deepClone(completeObject); timeoutObject.events = []; let usedRequestIds = []; @@ -191,12 +191,12 @@ function bidTimeout(args) { if (timeoutObject.events.length > 0) { sendEvent(timeoutObject); // send timeouted - logInfo('AdxPremium Analytics - Sending timeouted requests'); + utils.logInfo('AdxPremium Analytics - Sending timeouted requests'); } } function auctionEnd(args) { - logInfo('AdxPremium Analytics - Auction Ended at ' + Date.now()); + utils.logInfo('AdxPremium Analytics - Auction Ended at ' + Date.now()); if (timeoutBased) { setTimeout(function () { requestSent = true; sendEvent(completeObject); }, 3500); } else { sendEventFallback(); } } @@ -212,22 +212,22 @@ function deviceType() { } function clearSlot(elementId) { - if (includes(elementIds, elementId)) { elementIds.splice(elementIds.indexOf(elementId), 1); logInfo('AdxPremium Analytics - Done with: ' + elementId); } + if (includes(elementIds, elementId)) { elementIds.splice(elementIds.indexOf(elementId), 1); utils.logInfo('AdxPremium Analytics - Done with: ' + elementId); } if (elementIds.length == 0 && !requestSent && !timeoutBased) { requestSent = true; sendEvent(completeObject); - logInfo('AdxPremium Analytics - Everything ready'); + utils.logInfo('AdxPremium Analytics - Everything ready'); } } export function testSend() { sendEvent(completeObject); - logInfo('AdxPremium Analytics - Sending without any conditions, used for testing'); + utils.logInfo('AdxPremium Analytics - Sending without any conditions, used for testing'); } function sendEventFallback() { setTimeout(function () { - if (!requestSent) { requestSent = true; sendEvent(completeObject); logInfo('AdxPremium Analytics - Sending event using fallback method.'); } + if (!requestSent) { requestSent = true; sendEvent(completeObject); utils.logInfo('AdxPremium Analytics - Sending event using fallback method.'); } }, 2000); } @@ -241,11 +241,11 @@ function sendEvent(completeObject) { if (adxpremiumAnalyticsAdapter.initOptions.sid) { ajaxEndpoint = 'https://' + adxpremiumAnalyticsAdapter.initOptions.sid + '.adxpremium.services/graphql' } - ajax(ajaxEndpoint, function () { logInfo('AdxPremium Analytics - Sending complete events at ' + Date.now()) }, dataToSend, { + ajax(ajaxEndpoint, function () { utils.logInfo('AdxPremium Analytics - Sending complete events at ' + Date.now()) }, dataToSend, { contentType: 'application/json', method: 'POST' }); - } catch (err) { logError('AdxPremium Analytics - Sending event error: ' + err); } + } catch (err) { utils.logError('AdxPremium Analytics - Sending event error: ' + err); } } // save the base class function @@ -256,7 +256,7 @@ adxpremiumAnalyticsAdapter.enableAnalytics = function (config) { adxpremiumAnalyticsAdapter.initOptions = config.options; if (!config.options.pubId) { - logError('AdxPremium Analytics - Publisher ID (pubId) option is not defined. Analytics won\'t work'); + utils.logError('AdxPremium Analytics - Publisher ID (pubId) option is not defined. Analytics won\'t work'); return; } diff --git a/modules/adyoulikeBidAdapter.js b/modules/adyoulikeBidAdapter.js index 155e8ca3c7a..38731fdc91c 100644 --- a/modules/adyoulikeBidAdapter.js +++ b/modules/adyoulikeBidAdapter.js @@ -1,7 +1,6 @@ -import { deepAccess, buildUrl, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; -import { createEidsArray } from './userId/eids.js'; import find from 'core-js-pure/features/array/find.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; @@ -98,21 +97,17 @@ export const spec = { PageRefreshed: getPageRefreshed() }; - if (bidderRequest.gdprConsent) { + if (bidderRequest && bidderRequest.gdprConsent) { payload.gdprConsent = { consentString: bidderRequest.gdprConsent.consentString, consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies : null }; } - if (bidderRequest.uspConsent) { + if (bidderRequest && bidderRequest.uspConsent) { payload.uspConsent = bidderRequest.uspConsent; } - if (deepAccess(bidderRequest, 'userId')) { - payload.userId = createEidsArray(bidderRequest.userId); - } - const data = JSON.stringify(payload); const options = { withCredentials: true @@ -180,13 +175,11 @@ function getCanonicalUrl() { /* Get mediatype from bidRequest */ function getMediatype(bidRequest) { - if (deepAccess(bidRequest, 'mediaTypes.banner')) { - return BANNER; - } - if (deepAccess(bidRequest, 'mediaTypes.video')) { + if (utils.deepAccess(bidRequest, 'mediaTypes.video')) { return VIDEO; - } - if (deepAccess(bidRequest, 'mediaTypes.native')) { + } else if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { + return BANNER; + } else if (utils.deepAccess(bidRequest, 'mediaTypes.native')) { return NATIVE; } } @@ -217,7 +210,7 @@ function getPageRefreshed() { /* Create endpoint url */ function createEndpoint(bidRequests, bidderRequest) { let host = getHostname(bidRequests); - return buildUrl({ + return utils.buildUrl({ protocol: 'https', host: `${DEFAULT_DC}${host}.omnitagjs.com`, pathname: '/hb-api/prebid/v1', @@ -267,7 +260,7 @@ function getSizeArray(bid) { } } - return parseSizesInput(inputSize); + return utils.parseSizesInput(inputSize); } /* Get parsed size from request size */ @@ -347,9 +340,9 @@ function getTrackers(eventsArray, jsTrackers) { function getVideoAd(response) { var adJson = {}; - if (typeof response.Ad === 'string' && response.Ad.indexOf('\/\*PREBID\*\/') > 0) { + if (typeof response.Ad === 'string') { adJson = JSON.parse(response.Ad.match(/\/\*PREBID\*\/(.*)\/\*PREBID\*\//)[1]); - return deepAccess(adJson, 'Content.MainVideo.Vast'); + return utils.deepAccess(adJson, 'Content.MainVideo.Vast'); } } @@ -411,7 +404,7 @@ function getNativeAssets(response, nativeConfig) { imgSize[1] = response.Height || 250; } - const url = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Thumbnail.Image'), imgSize[0], imgSize[1]); + const url = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Thumbnail.Image'), imgSize[0], imgSize[1]); if (url) { native[key] = { url, @@ -429,7 +422,7 @@ function getNativeAssets(response, nativeConfig) { iconSize[1] = 50; } - const icurl = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Sponsor.Logo.Resource'), iconSize[0], iconSize[1]); + const icurl = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Sponsor.Logo.Resource'), iconSize[0], iconSize[1]); if (url) { native[key] = { @@ -440,10 +433,10 @@ function getNativeAssets(response, nativeConfig) { } break; case 'privacyIcon': - native[key] = getImageUrl(adJson, deepAccess(adJson, 'Content.Preview.Credit.Logo.Resource'), 25, 25); + native[key] = getImageUrl(adJson, utils.deepAccess(adJson, 'Content.Preview.Credit.Logo.Resource'), 25, 25); break; case 'privacyLink': - native[key] = deepAccess(adJson, 'Content.Preview.Credit.Url'); + native[key] = utils.deepAccess(adJson, 'Content.Preview.Credit.Url'); break; } }); @@ -480,15 +473,13 @@ function createBid(response, bidRequests) { meta: response.Meta || { advertiserDomains: [] } }; - // retreive video response if present - const vast64 = response.Vast || getVideoAd(response); - if (vast64) { - bid.vastXml = window.atob(vast64); - bid.mediaType = 'video'; - } else if (request.Native) { - // format Native response if Native was requested + if (request && request.Native) { bid.native = getNativeAssets(response, request.Native); bid.mediaType = 'native'; + } else if (request && request.Video) { + const vast64 = response.Vast || getVideoAd(response); + bid.vastXml = vast64 ? window.atob(vast64) : ''; + bid.mediaType = 'video'; } else { bid.width = response.Width; bid.height = response.Height; diff --git a/modules/afpBidAdapter.js b/modules/afpBidAdapter.js deleted file mode 100644 index 68941ff17c9..00000000000 --- a/modules/afpBidAdapter.js +++ /dev/null @@ -1,166 +0,0 @@ -import includes from 'core-js-pure/features/array/includes.js' -import { registerBidder } from '../src/adapters/bidderFactory.js' -import { Renderer } from '../src/Renderer.js' -import { BANNER, VIDEO } from '../src/mediaTypes.js' - -export const IS_DEV = location.hostname === 'localhost' -export const BIDDER_CODE = 'afp' -export const SSP_ENDPOINT = 'https://ssp.afp.ai/api/prebid' -export const REQUEST_METHOD = 'POST' -export const TEST_PAGE_URL = 'https://rtbinsight.ru/smiert-bolshikh-dannykh-kto-na-novienkogo/' -const SDK_PATH = 'https://cdn.afp.ai/ssp/sdk.js?auto_initialization=false&deploy_to_parent_window=true' -const TTL = 60 -export const IN_IMAGE_BANNER_TYPE = 'In-image' -export const IN_IMAGE_MAX_BANNER_TYPE = 'In-image Max' -export const IN_CONTENT_BANNER_TYPE = 'In-content Banner' -export const IN_CONTENT_VIDEO_TYPE = 'In-content Video' -export const OUT_CONTENT_VIDEO_TYPE = 'Out-content Video' -export const IN_CONTENT_STORY_TYPE = 'In-content Stories' -export const ACTION_SCROLLER_TYPE = 'Action Scroller' -export const ACTION_SCROLLER_LIGHT_TYPE = 'Action Scroller Light' -export const JUST_BANNER_TYPE = 'Just Banner' - -export const mediaTypeByPlaceType = { - [IN_IMAGE_BANNER_TYPE]: BANNER, - [IN_IMAGE_MAX_BANNER_TYPE]: BANNER, - [IN_CONTENT_BANNER_TYPE]: BANNER, - [IN_CONTENT_STORY_TYPE]: BANNER, - [ACTION_SCROLLER_TYPE]: BANNER, - [ACTION_SCROLLER_LIGHT_TYPE]: BANNER, - [JUST_BANNER_TYPE]: BANNER, - [IN_CONTENT_VIDEO_TYPE]: VIDEO, - [OUT_CONTENT_VIDEO_TYPE]: VIDEO, -} - -const wrapAd = (dataToCreatePlace) => { - return ` - - - - - - - - - - ` -} - -const bidRequestMap = {} - -const createRenderer = (bid, dataToCreatePlace) => { - const renderer = new Renderer({ - targetId: bid.adUnitCode, - url: SDK_PATH, - callback() { - renderer.loaded = true - window.afp.createPlaceByData(dataToCreatePlace) - } - }) - - return renderer -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], - isBidRequestValid({mediaTypes, params}) { - if (typeof params !== 'object' || typeof mediaTypes !== 'object') { - return false - } - - const {placeId, placeType, imageUrl, imageWidth, imageHeight} = params - const media = mediaTypes[mediaTypeByPlaceType[placeType]] - - if (placeId && media) { - if (mediaTypeByPlaceType[placeType] === VIDEO) { - if (!media.playerSize) { - return false - } - } else if (mediaTypeByPlaceType[placeType] === BANNER) { - if (!media.sizes) { - return false - } - } - if (includes([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], placeType)) { - if (imageUrl && imageWidth && imageHeight) { - return true - } - } else { - return true - } - } - return false - }, - buildRequests(validBidRequests, {refererInfo, gdprConsent}) { - const payload = { - pageUrl: IS_DEV ? TEST_PAGE_URL : refererInfo.referer, - gdprConsent: gdprConsent, - bidRequests: validBidRequests.map(validBidRequest => { - const {bidId, transactionId, sizes, params: { - placeId, placeType, imageUrl, imageWidth, imageHeight - }} = validBidRequest - bidRequestMap[bidId] = validBidRequest - const bidRequest = { - bidId, - transactionId, - sizes, - placeId, - } - if (includes([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], placeType)) { - Object.assign(bidRequest, { - imageUrl, - imageWidth: Math.floor(imageWidth), - imageHeight: Math.floor(imageHeight), - }) - } - return bidRequest - }) - } - - return { - method: REQUEST_METHOD, - url: SSP_ENDPOINT, - data: payload, - options: { - contentType: 'application/json' - } - } - }, - interpretResponse(serverResponse) { - let bids = serverResponse.body && serverResponse.body.bids - bids = Array.isArray(bids) ? bids : [] - - return bids.map(({bidId, cpm, width, height, creativeId, currency, netRevenue, adSettings, placeSettings}, index) => { - const bid = { - requestId: bidId, - cpm, - width, - height, - creativeId, - currency, - netRevenue, - meta: { - mediaType: mediaTypeByPlaceType[placeSettings.placeType], - }, - ttl: TTL - } - - const bidRequest = bidRequestMap[bidId] - const placeContainer = bidRequest.params.placeContainer - const dataToCreatePlace = { adSettings, placeSettings, placeContainer, isPrebid: true } - - if (mediaTypeByPlaceType[placeSettings.placeType] === BANNER) { - bid.ad = wrapAd(dataToCreatePlace) - } else if (mediaTypeByPlaceType[placeSettings.placeType] === VIDEO) { - bid.vastXml = adSettings.content - bid.renderer = createRenderer(bid, dataToCreatePlace) - } - return bid - }) - } -} - -registerBidder(spec); diff --git a/modules/afpBidAdapter.md b/modules/afpBidAdapter.md deleted file mode 100644 index 75ebf2bce48..00000000000 --- a/modules/afpBidAdapter.md +++ /dev/null @@ -1,348 +0,0 @@ -# Overview - - -**Module Name**: AFP Bidder Adapter -**Module Type**: Bidder Adapter -**Maintainer**: devops@astraone.io - -# Description - -You can use this adapter to get a bid from AFP. -Please reach out to your AFP account team before using this plugin to get placeId. -The code below returns a demo ad. - -About us: https://afp.ai - -# Test Parameters -```js -var adUnits = [{ - code: 'iib-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "In-image", - placeId: "613221112871613d1517d181", // id from personal account - placeContainer: '#iib-container', - imageUrl: "https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png", - imageWidth: 1000, - imageHeight: 524, - } - }] -}]; - -var adUnits = [{ - code: 'iimb-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "In-image Max", - placeId: "6139ae472871613d1517dedd", // id from personal account - placeContainer: '#iimb-container', - imageUrl: "https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png", - imageWidth: 1000, - imageHeight: 524, - } - }] -}]; - -var adUnits = [{ - code: 'icb-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "In-content Banner", - placeId: "6139ae082871613d1517dec0", // id from personal account - placeContainer: '#icb-container', - } - }] -}]; - -var adUnits = [{ - code: 'ics-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "In-content Stories", - placeId: "6139ae292871613d1517ded3", // id from personal account - placeContainer: '#ics-container', - } - }] -}]; - -var adUnits = [{ - code: 'as-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "Action Scroller", - placeId: "6139adc12871613d1517deb0", // id from personal account - placeContainer: '#as-container', - } - }] -}]; - -var adUnits = [{ - code: 'asl-target', - mediaTypes: { - banner: { - sizes: [[0, 0]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "Action Scroller Light", - placeId: "6139adda2871613d1517deb8", // id from personal account - placeContainer: '#asl-container', - } - }] -}]; - -var adUnits = [{ - code: 'jb-target', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "Just Banner", - placeId: "6139ae832871613d1517dee9", // id from personal account - placeContainer: '#jb-container', - } - }] -}]; - -var adUnits = [{ - code: 'icv-target', - mediaTypes: { - video: { - playerSize: [[480, 320]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "In-content Video", - placeId: "6139ae182871613d1517deca", // id from personal account - placeContainer: '#icv-container', - } - }] -}]; - -var adUnits = [{ - code: 'ocv-target', - mediaTypes: { - video: { - playerSize: [[480, 320]], - } - }, - bids: [{ - bidder: "afp", - params: { - placeType: "Out-content Video", - placeId: "6139ae5b2871613d1517dee2", // id from personal account - placeContainer: '#ocv-container', // only the "body" tag is used as a container - } - }] -}]; -``` - -# Example page - -```html - - - - - Prebid.js In-image Example - - - - -

In-image

-
-
- -
- -
- -

Just Banner

-
-
- -
- - - -``` -# Example page with GPT - -```html - - - - - Prebid.js In-image Example - - - - - -

In-image

-
-
- -
-
- -
-
- - -``` diff --git a/modules/airgridRtdProvider.js b/modules/airgridRtdProvider.js index f5403cca3eb..8d212204da8 100644 --- a/modules/airgridRtdProvider.js +++ b/modules/airgridRtdProvider.js @@ -33,7 +33,7 @@ export function attachScriptTagToDOM(rtdConfig) { edktInitializor.load = function(e) { var p = e || 'sdk'; var n = document.createElement('script'); - n.type = 'module'; + n.type = 'text/javascript'; n.async = true; n.src = 'https://cdn.edkt.io/' + p + '/edgekit.min.js'; document.getElementsByTagName('head')[0].appendChild(n); diff --git a/modules/ajaBidAdapter.js b/modules/ajaBidAdapter.js index a9364a7a05f..7b55ee7780a 100644 --- a/modules/ajaBidAdapter.js +++ b/modules/ajaBidAdapter.js @@ -1,5 +1,5 @@ -import { getBidIdParameter, tryAppendQueryString, createTrackPixelHtml, logError, logWarn } from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js'; @@ -16,48 +16,23 @@ export const spec = { code: BIDDER_CODE, supportedMediaTypes: [VIDEO, BANNER, NATIVE], - /** - * Determines whether or not the given bid has all the params needed to make a valid request. - * - * @param {BidRequest} bidRequest - * @returns {boolean} - */ - isBidRequestValid: function(bidRequest) { - return !!(bidRequest.params.asi); + isBidRequestValid: function(bid) { + return !!(bid.params.asi); }, - /** - * Build the request to the Server which requests Bids for the given array of Requests. - * Each BidRequest in the argument array is guaranteed to have passed the isBidRequestValid() test. - * - * @param {BidRequest[]} validBidRequests - * @param {*} bidderRequest - * @returns {ServerRequest|ServerRequest[]} - */ buildRequests: function(validBidRequests, bidderRequest) { const bidRequests = []; - const pageUrl = (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) || undefined; - for (let i = 0, len = validBidRequests.length; i < len; i++) { - const bidRequest = validBidRequests[i]; + const bid = validBidRequests[i]; let queryString = ''; - - const asi = getBidIdParameter('asi', bidRequest.params); - queryString = tryAppendQueryString(queryString, 'asi', asi); - queryString = tryAppendQueryString(queryString, 'skt', SDK_TYPE); - queryString = tryAppendQueryString(queryString, 'tid', bidRequest.transactionId) - queryString = tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId); - queryString = tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$'); - - if (pageUrl) { - queryString = tryAppendQueryString(queryString, 'page_url', pageUrl); - } - - const eids = bidRequest.userIdAsEids; - if (eids && eids.length) { - queryString = tryAppendQueryString(queryString, 'eids', JSON.stringify({ - 'eids': eids, - })) + const asi = utils.getBidIdParameter('asi', bid.params); + queryString = utils.tryAppendQueryString(queryString, 'asi', asi); + queryString = utils.tryAppendQueryString(queryString, 'skt', SDK_TYPE); + queryString = utils.tryAppendQueryString(queryString, 'prebid_id', bid.bidId); + queryString = utils.tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$'); + + if (bidderRequest && bidderRequest.refererInfo) { + queryString = utils.tryAppendQueryString(queryString, 'page_url', bidderRequest.refererInfo.referer); } bidRequests.push({ @@ -114,11 +89,11 @@ export const spec = { }); try { bannerAd.imps.forEach(impTracker => { - const tracker = createTrackPixelHtml(impTracker); + const tracker = utils.createTrackPixelHtml(impTracker); bid.ad += tracker; }); } catch (error) { - logError('Error appending tracking pixel', error); + utils.logError('Error appending tracking pixel', error); } Array.prototype.push.apply(bid.meta.advertiserDomains, bannerAd.adomain) @@ -207,7 +182,7 @@ function newRenderer(bidderResponse) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on newRenderer', err); + utils.logWarn('Prebid Error calling setRender on newRenderer', err); } return renderer; diff --git a/modules/akamaiDAPIdSystem.js b/modules/akamaiDAPIdSystem.js index 5e3a607d5fd..a78d65b40a9 100644 --- a/modules/akamaiDAPIdSystem.js +++ b/modules/akamaiDAPIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logMessage, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -29,7 +29,7 @@ export const akamaiDAPIdSubmodule = { * @returns {{dapId:string}} */ decode(value) { - logMessage('akamaiDAPId [decode] value=', value); + utils.logMessage('akamaiDAPId [decode] value=', value); return { dapId: value }; }, @@ -43,23 +43,23 @@ export const akamaiDAPIdSubmodule = { getId(config, consentData) { const configParams = (config && config.params); if (!configParams) { - logError('User ID - akamaiDAPId submodule requires a valid configParams'); + utils.logError('User ID - akamaiDAPId submodule requires a valid configParams'); return; } else if (typeof configParams.apiHostname !== 'string') { - logError('User ID - akamaiDAPId submodule requires a valid configParams.apiHostname'); + utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.apiHostname'); return; } else if (typeof configParams.domain !== 'string') { - logError('User ID - akamaiDAPId submodule requires a valid configParams.domain'); + utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.domain'); return; } else if (typeof configParams.type !== 'string') { - logError('User ID - akamaiDAPId submodule requires a valid configParams.type'); + utils.logError('User ID - akamaiDAPId submodule requires a valid configParams.type'); return; } const hasGdpr = (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) ? 1 : 0; const gdprConsentString = hasGdpr ? consentData.consentString : ''; const uspConsent = uspDataHandler.getConsentData(); if (hasGdpr && (!gdprConsentString || gdprConsentString === '')) { - logError('User ID - akamaiDAPId submodule requires consent string to call API'); + utils.logError('User ID - akamaiDAPId submodule requires consent string to call API'); return; } // XXX: retrieve first-party data here if needed @@ -99,14 +99,14 @@ export const akamaiDAPIdSubmodule = { storage.setDataInLocalStorage(STORAGE_KEY, token); }, error: error => { - logError('akamaiDAPId [getId:ajax.error] failed to retrieve ' + tokenName, error); + utils.logError('akamaiDAPId [getId:ajax.error] failed to retrieve ' + tokenName, error); } }; ajax(url, cb, JSON.stringify(postData), { contentType: 'application/json' }); let token = storage.getDataFromLocalStorage(STORAGE_KEY); - logMessage('akamaiDAPId [getId] returning', token); + utils.logMessage('akamaiDAPId [getId] returning', token); return { id: token }; } diff --git a/modules/akamaiDapRtdProvider.js b/modules/akamaiDapRtdProvider.js deleted file mode 100644 index d143a53fbf4..00000000000 --- a/modules/akamaiDapRtdProvider.js +++ /dev/null @@ -1,474 +0,0 @@ -/** - * This module adds the Akamai DAP RTD provider to the real time data module - * The {@link module:modules/realTimeData} module is required - * The module will fetch real-time data from DAP - * @module modules/akamaiDapRtdProvider - * @requires module:modules/realTimeData - */ -import {ajax} from '../src/ajax.js'; -import {config} from '../src/config.js'; -import {getStorageManager} from '../src/storageManager.js'; -import {submodule} from '../src/hook.js'; -import {isPlainObject, mergeDeep, logMessage, logInfo, logError} from '../src/utils.js'; - -const MODULE_NAME = 'realTimeData'; -const SUBMODULE_NAME = 'dap'; - -export const SEGMENTS_STORAGE_KEY = 'akamaiDapSegments'; -export const storage = getStorageManager(null, SUBMODULE_NAME); - -/** - * Lazy merge objects. - * @param {String} target - * @param {String} source - */ -function mergeLazy(target, source) { - if (!isPlainObject(target)) { - target = {}; - } - if (!isPlainObject(source)) { - source = {}; - } - return mergeDeep(target, source); -} - -/** - * Add real-time data & merge segments. - * @param {Object} bidConfig - * @param {Object} rtd - * @param {Object} rtdConfig - */ -export function addRealTimeData(rtd) { - logInfo('DEBUG(addRealTimeData) - ENTER'); - if (isPlainObject(rtd.ortb2)) { - let ortb2 = config.getConfig('ortb2') || {}; - logMessage('DEBUG(addRealTimeData): merging original: ', ortb2); - logMessage('DEBUG(addRealTimeData): merging in: ', rtd.ortb2); - config.setConfig({ortb2: mergeLazy(ortb2, rtd.ortb2)}); - } - logInfo('DEBUG(addRealTimeData) - EXIT'); -} - -/** - * Real-time data retrieval from Audigent - * @param {Object} reqBidsConfigObj - * @param {function} onDone - * @param {Object} rtdConfi - * @param {Object} userConsent - */ -export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) { - logInfo('DEBUG(getRealTimeData) - ENTER'); - logMessage(' - apiHostname: ' + rtdConfig.params.apiHostname); - logMessage(' - apiVersion: ' + rtdConfig.params.apiVersion); - let jsonData = storage.getDataFromLocalStorage(SEGMENTS_STORAGE_KEY); - if (jsonData) { - let data = JSON.parse(jsonData); - if (data.rtd) { - addRealTimeData(data.rtd); - onDone(); - logInfo('DEBUG(getRealTimeData) - 1'); - // Don't return - ensure the data is always fresh. - } - } - - if (rtdConfig && isPlainObject(rtdConfig.params)) { - let config = { - api_hostname: rtdConfig.params.apiHostname, - api_version: rtdConfig.params.apiVersion, - domain: rtdConfig.params.domain, - segtax: rtdConfig.params.segtax - }; - let identity = { - type: rtdConfig.params.identityType - }; - let token = dapUtils.dapGetToken(config, identity, rtdConfig.params.tokenTtl); - if (token !== null) { - let membership = dapUtils.dapGetMembership(config, token); - let udSegment = dapUtils.dapMembershipToRtbSegment(membership, config); - logMessage('DEBUG(getRealTimeData) - token: ' + token + ', user.data.segment: ', udSegment); - let data = { - rtd: { - ortb2: { - user: { - data: [ - udSegment - ] - }, - site: { - ext: { - data: { - dapSAID: membership.said - } - } - } - } - } - }; - storage.setDataInLocalStorage(SEGMENTS_STORAGE_KEY, JSON.stringify(data)); - onDone(); - } - } -} - -/** - * Module init - * @param {Object} provider - * @param {Object} userConsent - * @return {boolean} - */ -function init(provider, userConsent) { - return true; -} - -/** @type {RtdSubmodule} */ -export const akamaiDapRtdSubmodule = { - name: SUBMODULE_NAME, - getBidRequestData: getRealTimeData, - init: init -}; - -submodule(MODULE_NAME, akamaiDapRtdSubmodule); - -export const dapUtils = { - - dapGetToken: function(config, identity, ttl) { - let now = Math.round(Date.now() / 1000.0); // in seconds - let storageName = 'async_dap_token'; - let token = null; - - if (ttl == 0) { - localStorage.removeItem(storageName); - } - - let item = JSON.parse(localStorage.getItem(storageName)); - if (item == null) { - item = { - expires_at: now - 1, - token: null - }; - } else { - token = item.token; - } - - if (now > item.expires_at) { - dapUtils.dapLog('Token missing or expired, fetching a new one...'); - // Trigger a refresh - let configAsync = {...config}; - dapUtils.dapTokenize(configAsync, identity, - function(token, status, xhr) { - item.expires_at = now + ttl; - item.token = token; - localStorage.setItem(storageName, JSON.stringify(item)); - dapUtils.dapLog('Successfully updated and stored token; expires in ' + ttl + ' seconds'); - let deviceId100 = xhr.getResponseHeader('Akamai-DAP-100'); - if (deviceId100 != null) { - localStorage.setItem('dap_deviceId100', deviceId100); - dapUtils.dapLog('Successfully stored DAP 100 Device ID: ' + deviceId100); - } - }, - function(xhr, status, error) { - logError('ERROR(' + error + '): failed to retrieve token! ' + status); - } - ); - } - - return token; - }, - - dapGetMembership: function(config, token) { - let now = Math.round(Date.now() / 1000.0); // in seconds - let storageName = 'async_dap_membership'; - let maxTtl = 3600; // if the cached membership is older than this, return null - let membership = null; - let item = JSON.parse(localStorage.getItem(storageName)); - if (item == null || (now - item.expires_at) > maxTtl) { - item = { - expires_at: now - 1, - said: null, - cohorts: null, - attributes: null - }; - } else { - membership = { - said: item.said, - cohorts: item.cohorts, - attributes: null - }; - } - - // Always refresh the cached membership. - let configAsync = {...config}; - dapUtils.dapMembership(configAsync, token, - function(membership, status, xhr) { - item.expires_at = now + maxTtl; - item.said = membership.said; - item.cohorts = membership.cohorts; - localStorage.setItem(storageName, JSON.stringify(item)); - dapUtils.dapLog('Successfully updated and stored membership:'); - dapUtils.dapLog(item); - }, - function(xhr, status, error) { - logError('ERROR(' + error + '): failed to retrieve membership! ' + status); - } - ); - - return membership; - }, - - /** - * DESCRIPTION - * - * Convert a DAP membership response to an OpenRTB2 segment object suitable - * for insertion into user.data.segment or site.data.segment. - */ - dapMembershipToRtbSegment: function(membership, config) { - let segment = { - name: 'dap.akamai.com', - ext: { - 'segtax': config.segtax - }, - segment: [] - }; - if (membership != null) { - for (const i of membership.cohorts) { - segment.segment.push({ id: i }); - } - } - return segment; - }, - - dapLog: function(args) { - let css = ''; - css += 'display: inline-block;'; - css += 'color: #fff;'; - css += 'background: #F28B20;'; - css += 'padding: 1px 4px;'; - css += 'border-radius: 3px'; - - logInfo('%cDAP Client', css, args); - }, - - /******************************************************************************* - * - * V2 (And Beyond) API - * - ******************************************************************************/ - - /** - * SYNOPSIS - * - * dapTokenize( config, identity ); - * - * DESCRIPTION - * - * Tokenize an identity into a secure, privacy safe pseudonymiziation. - * - * PARAMETERS - * - * config: an array of system configuration parameters - * - * identity: an array of identity parameters passed to the tokenizing system - * - * EXAMPLE - * - * config = { - * api_hostname: "prebid.dap.akadns.net", // required - * domain: "prebid.org", // required - * api_version: "x1", // optional, default "x1" - * }; - * - * token = null; - * identity_email = { - * type: "email", - * identity: "obiwan@jedi.com" - * attributes: { cohorts: [ "100:1641013200", "101:1641013200", "102":3:1641013200" ] }, - * }; - * dap_x1_tokenize( config, identity_email, - * function( response, status, xhr ) { token = response; }, - * function( xhr, status, error ) { ; } // handle error - * - * token = null; - * identity_signature = { type: "signature:1.0.0" }; - * dap_x1_tokenize( config, identity_signature, - * function( response, status, xhr } { token = response; }, - * function( xhr, status, error ) { ; } // handle error - */ - dapTokenize: function(config, identity, onSuccess = null, onError = null) { - if (onError == null) { - onError = function(xhr, status, error) {}; - } - - if (config == null || typeof (config) == typeof (undefined)) { - onError(null, 'Invalid config object', 'ClientError'); - return; - } - - if (typeof (config.domain) != 'string') { - onError(null, 'Invalid config.domain: must be a string', 'ClientError'); - return; - } - - if (config.domain.length <= 0) { - onError(null, 'Invalid config.domain: must have non-zero length', 'ClientError'); - return; - } - - if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) { - config.api_version = 'x1'; - } - - if (typeof (config.api_version) != 'string') { - onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError'); - return; - } - - if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) { - onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError'); - return; - } - - if (identity == null || typeof (identity) == typeof (undefined)) { - onError(null, 'Invalid identity object', 'ClientError'); - return; - } - - if (!('type' in identity) || typeof (identity.type) != 'string' || identity.type.length <= 0) { - onError(null, "Identity must contain a valid 'type' field", 'ClientError'); - return; - } - - let apiParams = { - 'type': identity.type, - }; - - if (typeof (identity.identity) != typeof (undefined)) { - apiParams.identity = identity.identity; - } - if (typeof (identity.attributes) != typeof (undefined)) { - apiParams.attributes = identity.attributes; - } - - let method; - let body; - let path; - switch (config.api_version) { - case 'x1': - case 'x1-dev': - method = 'POST'; - path = '/data-activation/' + config.api_version + '/domain/' + config.domain + '/identity/tokenize'; - body = JSON.stringify(apiParams); - break; - default: - onError(null, 'Invalid api_version: ' + config.api_version, 'ClientError'); - return; - } - - let url = 'https://' + config.api_hostname + path; - let cb = { - success: (response, request) => { - let token = null; - switch (config.api_version) { - case 'x1': - case 'x1-dev': - token = request.getResponseHeader('Akamai-DAP-Token'); - break; - } - onSuccess(token, request.status, request); - }, - error: (request, error) => { - onError(request, request.statusText, error); - } - }; - - ajax(url, cb, body, { - method: method, - customHeaders: { - 'Content-Type': 'application/json', - 'Pragma': 'akamai-x-cache-on' - } - }); - }, - - /** - * SYNOPSIS - * - * dapMembership( config, token, onSuccess, onError ); - * - * DESCRIPTION - * - * Return the audience segment membership along with a new Secure Advertising - * ID for this token. - * - * PARAMETERS - * - * config: an array of system configuration parameters - * - * token: the token previously returned from the tokenize API - * - * EXAMPLE - * - * config = { - * api_hostname: 'api.dap.akadns.net', - * }; - * - * // token from dap_x1_tokenize - * - * dapMembership( config, token, - * function( membership, status, xhr ) { - * // Run auction with membership.segments and membership.said - * }, - * function( xhr, status, error ) { - * // error - * } ); - * - */ - dapMembership: function(config, token, onSuccess = null, onError = null) { - if (onError == null) { - onError = function(xhr, status, error) {}; - } - - if (config == null || typeof (config) == typeof (undefined)) { - onError(null, 'Invalid config object', 'ClientError'); - return; - } - - if (!('api_version' in config) || (typeof (config.api_version) == 'string' && config.api_version.length == 0)) { - config.api_version = 'x1'; - } - - if (typeof (config.api_version) != 'string') { - onError(null, "Invalid api_version: must be a string like 'x1', etc.", 'ClientError'); - return; - } - - if (!(('api_hostname') in config) || typeof (config.api_hostname) != 'string' || config.api_hostname.length == 0) { - onError(null, 'Invalid api_hostname: must be a non-empty string', 'ClientError'); - return; - } - - if (token == null || typeof (token) != 'string') { - onError(null, 'Invalid token: must be a non-null string', 'ClientError'); - return; - } - let path = '/data-activation/' + - config.api_version + - '/token/' + token + - '/membership'; - - let url = 'https://' + config.api_hostname + path; - - let cb = { - success: (response, request) => { - onSuccess(JSON.parse(response), request.status, request); - }, - error: (error, request) => { - onError(request, request.status, error); - } - }; - - ajax(url, cb, undefined, { - method: 'GET', - customHeaders: {} - }); - } -} diff --git a/modules/akamaiDapRtdProvider.md b/modules/akamaiDapRtdProvider.md deleted file mode 100644 index ade11b88602..00000000000 --- a/modules/akamaiDapRtdProvider.md +++ /dev/null @@ -1,47 +0,0 @@ -### Overview - - Akamai DAP Real time data Provider automatically invokes the DAP APIs and submit audience segments and the SAID to the bid-stream. - -### Integration - - 1) Build the akamaiDapRTD module into the Prebid.js package with: - - ``` - gulp build --modules=akamaiDapRtdProvider,... - ``` - - 2) Use `setConfig` to instruct Prebid.js to initilaize the akamaiDapRtdProvider module, as specified below. - -### Configuration - -``` - pbjs.setConfig({ - realTimeData: { - dataProviders: [ - { - name: "dap", - waitForIt: true, - params: { - apiHostname: '', - apiVersion: "x1", - domain: 'your-domain.com', - identityType: 'email' | 'mobile' | ... | 'dap-signature:1.0.0', - segtax: , - tokenTtl: 5, - } - } - ] - } - }); - ``` - -Please reach out to your Akamai account representative(Prebid@akamai.com) to get provisioned on the DAP platform. - - -### Testing -To view an example of available segments returned by dap: -``` -‘gulp serve --modules=rtdModule,akamaiDapRtdProvider,appnexusBidAdapter,sovrnBidAdapter’ -``` -and then point your browser at: -"http://localhost:9999/integrationExamples/gpt/akamaidap_segments_example.html" diff --git a/modules/aniviewBidAdapter.js b/modules/aniviewBidAdapter.js index 53249e92a77..83a1ab20bb4 100644 --- a/modules/aniviewBidAdapter.js +++ b/modules/aniviewBidAdapter.js @@ -1,7 +1,7 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'aniview'; const GVLID = 780; @@ -224,7 +224,7 @@ function interpretResponse(serverResponse, bidRequest) { }); bidResponse.vastUrl = window.URL.createObjectURL(blob); } catch (ex) { - logError('Aniview Debug create vastXml error:\n\n' + ex); + utils.logError('Aniview Debug create vastXml error:\n\n' + ex); } bidResponse.vastXml = xmlStr; if (bidRequest.bidRequest && bidRequest.bidRequest.mediaTypes && bidRequest.bidRequest.mediaTypes.video && bidRequest.bidRequest.mediaTypes.video.context === 'outstream') { @@ -309,7 +309,7 @@ function getUserSyncs(syncOptions, serverResponses) { export const spec = { code: BIDDER_CODE, gvlid: GVLID, - aliases: ['avantisvideo', 'selectmediavideo', 'vidcrunch', 'openwebvideo', 'didnavideo'], + aliases: ['avantisvideo', 'selectmediavideo', 'vidcrunch', 'openwebvideo'], supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid, buildRequests, diff --git a/modules/aolBidAdapter.js b/modules/aolBidAdapter.js index c9f64ab66b0..4ab6f53ebdc 100644 --- a/modules/aolBidAdapter.js +++ b/modules/aolBidAdapter.js @@ -1,4 +1,4 @@ -import { isInteger, logError, isEmpty, logWarn, getUniqueIdentifierStr, _each, deepSetValue } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -38,8 +38,7 @@ const SUPPORTED_USER_ID_SOURCES = [ 'liveintent.com', 'quantcast.com', 'verizonmedia.com', - 'liveramp.com', - 'yahoo.com' + 'liveramp.com' ]; const pubapiTemplate = template`${'host'}/pubapi/3.0/${'network'}/${'placement'}/${'pageid'}/${'sizeid'}/ADTECH;v=2;cmd=bid;cors=yes;alias=${'alias'};misc=${'misc'};${'dynamicParams'}`; @@ -65,7 +64,7 @@ function template(strings, ...keys) { let dict = values[values.length - 1] || {}; let result = [strings[0]]; keys.forEach(function (key, i) { - let value = isInteger(key) ? values[key] : dict[key]; + let value = utils.isInteger(key) ? values[key] : dict[key]; result.push(value, strings[i + 1]); }); return result.join(''); @@ -148,7 +147,7 @@ export const spec = { }, interpretResponse({ body }, bidRequest) { if (!body) { - logError('Empty bid response', bidRequest.bidderCode, body); + utils.logError('Empty bid response', bidRequest.bidderCode, body); } else { let bid = this._parseBidResponse(body, bidRequest); @@ -158,7 +157,7 @@ export const spec = { } }, getUserSyncs(options, serverResponses) { - const bidResponse = !isEmpty(serverResponses) && serverResponses[0].body; + const bidResponse = !utils.isEmpty(serverResponses) && serverResponses[0].body; if (bidResponse && bidResponse.ext && bidResponse.ext.pixels) { return this.parsePixelItems(bidResponse.ext.pixels); @@ -216,7 +215,7 @@ export const spec = { let server; if (!MP_SERVER_MAP.hasOwnProperty(regionParam)) { - logWarn(`Unknown region '${regionParam}' for AOL bidder.`); + utils.logWarn(`Unknown region '${regionParam}' for AOL bidder.`); regionParam = 'us'; // Default region. } @@ -235,7 +234,7 @@ export const spec = { placement: parseInt(params.placement), pageid: params.pageId || 0, sizeid: params.sizeId || 0, - alias: params.alias || getUniqueIdentifierStr(), + alias: params.alias || utils.getUniqueIdentifierStr(), misc: new Date().getTime(), // cache busting dynamicParams: this.formatMarketplaceDynamicParams(params, consentData) })); @@ -274,7 +273,7 @@ export const spec = { Object.assign(queryParams, this.formatConsentData(consentData)); let paramsFormatted = ''; - _each(queryParams, (value, key) => { + utils._each(queryParams, (value, key) => { paramsFormatted += `${key}=${encodeURIComponent(value)};`; }); @@ -288,7 +287,7 @@ export const spec = { Object.assign(params, this.formatConsentData(consentData)); let paramsFormatted = ''; - _each(params, (value, key) => { + utils._each(params, (value, key) => { paramsFormatted += `&${key}=${encodeURIComponent(value)}`; }); @@ -301,14 +300,14 @@ export const spec = { }; if (this.isEUConsentRequired(consentData)) { - deepSetValue(openRtbObject, 'regs.ext.gdpr', NUMERIC_VALUES.TRUE); + utils.deepSetValue(openRtbObject, 'regs.ext.gdpr', NUMERIC_VALUES.TRUE); if (consentData.gdpr.consentString) { - deepSetValue(openRtbObject, 'user.ext.consent', consentData.gdpr.consentString); + utils.deepSetValue(openRtbObject, 'user.ext.consent', consentData.gdpr.consentString); } } if (consentData.uspConsent) { - deepSetValue(openRtbObject, 'regs.ext.us_privacy', consentData.uspConsent); + utils.deepSetValue(openRtbObject, 'regs.ext.us_privacy', consentData.uspConsent); } if (typeof bid.userId === 'object') { @@ -329,7 +328,7 @@ export const spec = { formatKeyValues(keyValues) { let keyValuesHash = {}; - _each(keyValues, (value, key) => { + utils._each(keyValues, (value, key) => { keyValuesHash[`kv${key}`] = value; }); @@ -395,7 +394,7 @@ export const spec = { cpm = bidData.price; if (cpm === null || isNaN(cpm)) { - logError('Invalid price in bid response', AOL_BIDDERS_CODES.AOL, bidData); + utils.logError('Invalid price in bid response', AOL_BIDDERS_CODES.AOL, bidData); return; } } diff --git a/modules/apacdexBidAdapter.js b/modules/apacdexBidAdapter.js index 421eb99b4c1..6c1c350b800 100644 --- a/modules/apacdexBidAdapter.js +++ b/modules/apacdexBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isPlainObject, isArray, replaceAuctionPrice, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'apacdex'; @@ -32,16 +32,16 @@ export const spec = { if (!bid.params.siteId && !bid.params.placementId) { return false; } - if (!deepAccess(bid, 'mediaTypes.banner') && !deepAccess(bid, 'mediaTypes.video')) { + if (!utils.deepAccess(bid, 'mediaTypes.banner') && !utils.deepAccess(bid, 'mediaTypes.video')) { return false; } - if (deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video - if (!deepAccess(bid, 'mediaTypes.banner.sizes')) { + if (utils.deepAccess(bid, 'mediaTypes.banner')) { // Not support multi type bids, favor banner over video + if (!utils.deepAccess(bid, 'mediaTypes.banner.sizes')) { // sizes at the banner is required. return false; } - } else if (deepAccess(bid, 'mediaTypes.video')) { - if (!deepAccess(bid, 'mediaTypes.video.playerSize')) { + } else if (utils.deepAccess(bid, 'mediaTypes.video')) { + if (!utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { // playerSize is required for instream adUnits. return false; } @@ -170,12 +170,12 @@ export const spec = { }, interpretResponse: function (serverResponse, bidRequest) { const serverBody = serverResponse.body; - if (!serverBody || !isPlainObject(serverBody)) { + if (!serverBody || !utils.isPlainObject(serverBody)) { return []; } const serverBids = serverBody.bids; - if (!serverBids || !isArray(serverBids)) { + if (!serverBids || !utils.isArray(serverBids)) { return []; } @@ -197,12 +197,12 @@ export const spec = { bidResponse.dealId = dealId; } if (bid.vastXml) { - bidResponse.vastXml = replaceAuctionPrice(bid.vastXml, bid.cpm); + bidResponse.vastXml = utils.replaceAuctionPrice(bid.vastXml, bid.cpm); } else { - bidResponse.ad = replaceAuctionPrice(bid.ad, bid.cpm); + bidResponse.ad = utils.replaceAuctionPrice(bid.ad, bid.cpm); } bidResponse.meta = {}; - if (bid.meta && bid.meta.advertiserDomains && isArray(bid.meta.advertiserDomains)) { + if (bid.meta && bid.meta.advertiserDomains && utils.isArray(bid.meta.advertiserDomains)) { bidResponse.meta.advertiserDomains = bid.meta.advertiserDomains; } bidResponses.push(bidResponse); @@ -285,7 +285,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { if (config.getConfig('pageUrl')) { return config.getConfig('pageUrl'); } - if (deepAccess(bidderRequest, 'refererInfo.referer')) { + if (utils.deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -303,7 +303,7 @@ function _extractTopWindowUrlFromBidderRequest(bidderRequest) { * @returns {string} */ function _extractTopWindowReferrerFromBidderRequest(bidderRequest) { - if (bidderRequest && deepAccess(bidderRequest, 'refererInfo.referer')) { + if (bidderRequest && utils.deepAccess(bidderRequest, 'refererInfo.referer')) { return bidderRequest.refererInfo.referer; } @@ -340,7 +340,7 @@ export function getDomain(pageUrl) { * @returns {boolean} */ export function validateGeoObject(geo) { - if (!isPlainObject(geo)) { + if (!utils.isPlainObject(geo)) { return false; } if (!geo.lat) { @@ -362,7 +362,7 @@ export function validateGeoObject(geo) { * @returns {float||null} */ function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return (bid.params.floorPrice) ? bid.params.floorPrice : null; } @@ -371,7 +371,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/apstreamBidAdapter.js b/modules/apstreamBidAdapter.js index f2d4189f237..4fb89b9c720 100644 --- a/modules/apstreamBidAdapter.js +++ b/modules/apstreamBidAdapter.js @@ -1,6 +1,6 @@ -import { generateUUID, deepAccess, createTrackPixelHtml, getDNT } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; const CONSTANTS = { @@ -221,7 +221,7 @@ var dsuModule = (function() { } function generateDsu() { - var dsuId = generateUUID(); + var dsuId = utils.generateUUID(); var loc = location(); var dsuIdSuffix = hashWithKey(dsuId + loc.toString()); @@ -303,7 +303,7 @@ function getConsentStringFromPrebid(gdprConsentConfig) { } function getIabConsentString(bidderRequest) { - if (deepAccess(bidderRequest, 'gdprConsent')) { + if (utils.deepAccess(bidderRequest, 'gdprConsent')) { return getConsentStringFromPrebid(bidderRequest.gdprConsent); } @@ -318,7 +318,7 @@ function injectPixels(ad, pixels, scripts) { let trackedAd = ad; if (pixels) { pixels.forEach(pixel => { - const tracker = createTrackPixelHtml(pixel); + const tracker = utils.createTrackPixelHtml(pixel); trackedAd += tracker; }); } @@ -420,7 +420,7 @@ function buildRequests(bidRequests, bidderRequest) { med: encodeURIComponent(window.location.href), auid: bidderRequest.auctionId, ref: document.referrer, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, sr: getScreenParams() }; diff --git a/modules/asoBidAdapter.js b/modules/asoBidAdapter.js index bf45b9ee48f..8f06b8ed856 100644 --- a/modules/asoBidAdapter.js +++ b/modules/asoBidAdapter.js @@ -1,5 +1,5 @@ -import { _each, deepAccess, logWarn, tryAppendQueryString, inIframe, getWindowTop, parseUrl, parseSizesInput, isFn, getDNT, deepSetValue } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; @@ -22,16 +22,16 @@ export const spec = { buildRequests: (validBidRequests, bidderRequest) => { let serverRequests = []; - _each(validBidRequests, bidRequest => { + utils._each(validBidRequests, bidRequest => { const payload = createBasePayload(bidRequest, bidderRequest); - const bannerParams = deepAccess(bidRequest, 'mediaTypes.banner'); - const videoParams = deepAccess(bidRequest, 'mediaTypes.video'); + const bannerParams = utils.deepAccess(bidRequest, 'mediaTypes.banner'); + const videoParams = utils.deepAccess(bidRequest, 'mediaTypes.video'); let imp; if (bannerParams && videoParams) { - logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') + utils.logWarn('Please note, multiple mediaTypes are not supported. The only banner will be used.') } if (bannerParams) { @@ -93,7 +93,7 @@ export const spec = { bid.ad = serverBid.adm; } else if (bid.mediaType === VIDEO) { bid.vastXml = serverBid.adm; - if (deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { + if (utils.deepAccess(bidRequest, 'mediaTypes.video.context') === 'outstream') { bid.adResponse = { content: bid.vastXml, }; @@ -112,25 +112,25 @@ export const spec = { if (serverResponses && serverResponses.length !== 0) { let query = ''; if (gdprConsent) { - query = tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); - query = tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); + query = utils.tryAppendQueryString(query, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + query = utils.tryAppendQueryString(query, 'consents_str', gdprConsent.consentString); const consentsIds = getConsentsIds(gdprConsent); if (consentsIds) { - query = tryAppendQueryString(query, 'consents', consentsIds); + query = utils.tryAppendQueryString(query, 'consents', consentsIds); } } if (uspConsent) { - query = tryAppendQueryString(query, 'us_privacy', uspConsent); + query = utils.tryAppendQueryString(query, 'us_privacy', uspConsent); } - _each(serverResponses, resp => { - const userSyncs = deepAccess(resp, 'body.ext.user_syncs'); + utils._each(serverResponses, resp => { + const userSyncs = utils.deepAccess(resp, 'body.ext.user_syncs'); if (!userSyncs) { return; } - _each(userSyncs, us => { + utils._each(userSyncs, us => { urls.push({ type: us.type, url: us.url + (query ? '?' + query : '') @@ -159,7 +159,7 @@ function createRenderer(bid, url) { id: bid.bidId, url: url, loaded: false, - config: deepAccess(bid, 'renderer.options'), + config: utils.deepAccess(bid, 'renderer.options'), adUnitCode: bid.adUnitCode }); renderer.setRender(outstreamRender); @@ -172,16 +172,16 @@ function getUrlsInfo(bidderRequest) { const {refererInfo} = bidderRequest; - if (inIframe()) { + if (utils.inIframe()) { page = refererInfo.referer; } else { - const w = getWindowTop(); + const w = utils.getWindowTop(); page = w.location.href; referrer = w.document.referrer || ''; } page = config.getConfig('pageUrl') || page; - const url = parseUrl(page); + const url = utils.parseUrl(page); const domain = url.hostname; return { @@ -192,7 +192,7 @@ function getUrlsInfo(bidderRequest) { } function getSize(paramSizes) { - const parsedSizes = parseSizesInput(paramSizes); + const parsedSizes = utils.parseSizesInput(paramSizes); const sizes = parsedSizes.map(size => { const [width, height] = size.split('x'); const w = parseInt(width, 10); @@ -204,7 +204,7 @@ function getSize(paramSizes) { } function getBidFloor(bidRequest, size) { - if (!isFn(bidRequest.getFloor)) { + if (!utils.isFn(bidRequest.getFloor)) { return null; } @@ -245,7 +245,7 @@ function createBannerImp(bidRequest, bannerParams) { imp.banner = { w: size.w, h: size.h, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 } return imp; @@ -284,7 +284,7 @@ function getEnpoint(bidRequest) { } function getConsentsIds(gdprConsent) { - const consents = deepAccess(gdprConsent, 'vendorData.purpose.consents', []); + const consents = utils.deepAccess(gdprConsent, 'vendorData.purpose.consents', []); let consentsIds = []; Object.keys(consents).forEach(function (key) { @@ -310,7 +310,7 @@ function createBasePayload(bidRequest, bidderRequest) { ref: urlsInfo.referrer }, device: { - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, h: window.innerHeight, w: window.innerWidth, }, @@ -320,29 +320,29 @@ function createBasePayload(bidRequest, bidderRequest) { }; if (bidRequest.params.attr) { - deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); + utils.deepSetValue(payload, 'site.ext.attr', bidRequest.params.attr); } if (bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); const consentsIds = getConsentsIds(bidderRequest.gdprConsent); if (consentsIds) { - deepSetValue(payload, 'user.ext.consents', consentsIds); + utils.deepSetValue(payload, 'user.ext.consents', consentsIds); } - deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); + utils.deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1); } if (bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa')) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } - const eids = deepAccess(bidRequest, 'userIdAsEids'); + const eids = utils.deepAccess(bidRequest, 'userIdAsEids'); if (eids && eids.length) { - deepSetValue(payload, 'user.ext.eids', eids); + utils.deepSetValue(payload, 'user.ext.eids', eids); } return payload; diff --git a/modules/astraoneBidAdapter.js b/modules/astraoneBidAdapter.js index c233e665499..2fec3892d27 100644 --- a/modules/astraoneBidAdapter.js +++ b/modules/astraoneBidAdapter.js @@ -1,4 +1,4 @@ -import { _map } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER } from '../src/mediaTypes.js' @@ -7,7 +7,7 @@ const SSP_ENDPOINT = 'https://ssp.astraone.io/auction/prebid'; const TTL = 60; function buildBidRequests(validBidRequests) { - return _map(validBidRequests, function(validBidRequest) { + return utils._map(validBidRequests, function(validBidRequest) { const params = validBidRequest.params; const bidRequest = { bidId: validBidRequest.bidId, diff --git a/modules/atsAnalyticsAdapter.js b/modules/atsAnalyticsAdapter.js index f45d2e80055..0cff7bbd68f 100644 --- a/modules/atsAnalyticsAdapter.js +++ b/modules/atsAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { logError, logInfo } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adaptermanager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -13,6 +13,9 @@ export const storage = getStorageManager(); */ const analyticsType = 'endpoint'; +// dev endpoints +// const preflightUrl = 'https://analytics-check.publishersite.xyz/check/'; +// export const analyticsUrl = 'https://analyticsv2.publishersite.xyz'; const preflightUrl = 'https://check.analytics.rlcdn.com/check/'; export const analyticsUrl = 'https://analytics.rlcdn.com'; @@ -20,7 +23,7 @@ export const analyticsUrl = 'https://analytics.rlcdn.com'; let handlerRequest = []; let handlerResponse = []; -let atsAnalyticsAdapterVersion = 3; +let atsAnalyticsAdapterVersion = 1; let browsersList = [ /* Googlebot */ @@ -204,6 +207,12 @@ let browsersList = [ }, ]; +function setSamplingCookie(samplRate) { + let now = new Date(); + now.setTime(now.getTime() + 3600000); + storage.setCookie('_lr_sampling_rate', samplRate, now.toUTCString()); +} + let listOfSupportedBrowsers = ['Safari', 'Chrome', 'Firefox', 'Microsoft Edge']; function bidRequestedHandler(args) { @@ -222,8 +231,7 @@ function bidRequestedHandler(args) { auction_start: new Date(args.auctionStart).toJSON(), domain: window.location.hostname, pid: atsAnalyticsAdapter.context.pid, - adapter_version: atsAnalyticsAdapterVersion, - bid_won: false + adapter_version: atsAnalyticsAdapterVersion }; }); return requests; @@ -248,45 +256,59 @@ export function parseBrowser() { let browserName = result && result.length ? result[0].name : ''; return (listOfSupportedBrowsers.indexOf(browserName) >= 0) ? browserName : 'Unknown'; } catch (err) { - logError('ATS Analytics - Error while checking user browser!', err); + utils.logError('ATS Analytics - Error while checking user browser!', err); } } -function sendDataToAnalytic (events) { +function sendDataToAnalytic () { // send data to ats analytic endpoint try { - let dataToSend = {'Data': events}; + let dataToSend = {'Data': atsAnalyticsAdapter.context.events}; let strJSON = JSON.stringify(dataToSend); - logInfo('ATS Analytics - tried to send analytics data!'); + utils.logInfo('ATS Analytics - tried to send analytics data!'); ajax(analyticsUrl, function () { - logInfo('ATS Analytics - events sent successfully!'); }, strJSON, {method: 'POST', contentType: 'application/json'}); } catch (err) { - logError('ATS Analytics - request encounter an error: ', err); + utils.logError('ATS Analytics - request encounter an error: ', err); } } // preflight request, to check did publisher have permission to send data to analytics endpoint -function preflightRequest (envelopeSourceCookieValue, events) { - logInfo('ATS Analytics - preflight request!'); - ajax(preflightUrl + atsAnalyticsAdapter.context.pid, - { - success: function (data) { - let samplingRateObject = JSON.parse(data); - logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); - let samplingRate = samplingRateObject.samplingRate; - atsAnalyticsAdapter.setSamplingCookie(samplingRate); - let samplingRateNumber = Number(samplingRate); - if (data && samplingRate && atsAnalyticsAdapter.shouldFireRequest(samplingRateNumber) && envelopeSourceCookieValue != null) { - logInfo('ATS Analytics - events to send: ', events); - sendDataToAnalytic(events); - } - }, - error: function () { - atsAnalyticsAdapter.setSamplingCookie(0); - logInfo('ATS Analytics - Sampling Rate Request Error!'); +function preflightRequest (envelopeSourceCookieValue) { + utils.logInfo('ATS Analytics - preflight request!'); + ajax(preflightUrl + atsAnalyticsAdapter.context.pid, function (data) { + let samplingRateObject = JSON.parse(data); + utils.logInfo('ATS Analytics - Sampling Rate: ', samplingRateObject); + let samplingRate = samplingRateObject['samplingRate']; + setSamplingCookie(samplingRate); + let samplingRateNumber = Number(samplingRate); + if (data && samplingRate && atsAnalyticsAdapter.shouldFireRequest(samplingRateNumber) && envelopeSourceCookieValue != null) { + sendDataToAnalytic(); + } + }, undefined, { method: 'GET', crossOrigin: true }); +} + +function callHandler(evtype, args) { + if (evtype === CONSTANTS.EVENTS.BID_REQUESTED) { + handlerRequest = handlerRequest.concat(bidRequestedHandler(args)); + } else if (evtype === CONSTANTS.EVENTS.BID_RESPONSE) { + handlerResponse.push(bidResponseHandler(args)); + } + if (evtype === CONSTANTS.EVENTS.AUCTION_END) { + if (handlerRequest.length) { + let events = []; + if (handlerResponse.length) { + events = handlerRequest.filter(request => handlerResponse.filter(function(response) { + if (request.bid_id === response.bid_id) { + Object.assign(request, response); + } + })); + } else { + events = handlerRequest; } - }, undefined, {method: 'GET', crossOrigin: true}); + atsAnalyticsAdapter.context.events = events; + } + } } let atsAnalyticsAdapter = Object.assign(adapter( @@ -296,7 +318,22 @@ let atsAnalyticsAdapter = Object.assign(adapter( { track({eventType, args}) { if (typeof args !== 'undefined') { - atsAnalyticsAdapter.callHandler(eventType, args); + callHandler(eventType, args); + } + if (eventType === CONSTANTS.EVENTS.AUCTION_END) { + let envelopeSourceCookieValue = storage.getCookie('_lr_env_src_ats'); + try { + let samplingRateCookie = storage.getCookie('_lr_sampling_rate'); + if (!samplingRateCookie) { + preflightRequest(envelopeSourceCookieValue); + } else { + if (atsAnalyticsAdapter.shouldFireRequest(parseInt(samplingRateCookie)) && envelopeSourceCookieValue != null) { + sendDataToAnalytic(); + } + } + } catch (err) { + utils.logError('ATS Analytics - preflight request encounter an error: ', err); + } } } }); @@ -308,10 +345,10 @@ atsAnalyticsAdapter.originEnableAnalytics = atsAnalyticsAdapter.enableAnalytics; atsAnalyticsAdapter.shouldFireRequest = function (samplingRate) { if (samplingRate !== 0) { let shouldFireRequestValue = (Math.floor((Math.random() * 100 + 1)) === 100); - logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); + utils.logInfo('ATS Analytics - Should Fire Request: ', shouldFireRequestValue); return shouldFireRequestValue; } else { - logInfo('ATS Analytics - Should Fire Request: ', false); + utils.logInfo('ATS Analytics - Should Fire Request: ', false); return false; } }; @@ -319,84 +356,21 @@ atsAnalyticsAdapter.shouldFireRequest = function (samplingRate) { atsAnalyticsAdapter.getUserAgent = function () { return window.navigator.userAgent; }; - -atsAnalyticsAdapter.setSamplingCookie = function (samplRate) { - const now = new Date(); - now.setTime(now.getTime() + 86400000); - storage.setCookie('_lr_sampling_rate', samplRate, now.toUTCString()); -} - // override enableAnalytics so we can get access to the config passed in from the page atsAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.pid) { - logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); + utils.logError('ATS Analytics - Publisher ID (pid) option is not defined. Analytics won\'t work'); return; } atsAnalyticsAdapter.context = { events: [], - pid: config.options.pid, - bidWonTimeout: config.options.bidWonTimeout + pid: config.options.pid }; let initOptions = config.options; - logInfo('ATS Analytics - adapter enabled! '); + utils.logInfo('ATS Analytics - adapter enabled! '); atsAnalyticsAdapter.originEnableAnalytics(initOptions); // call the base class function }; -atsAnalyticsAdapter.callHandler = function (evtype, args) { - if (evtype === CONSTANTS.EVENTS.BID_REQUESTED) { - handlerRequest = handlerRequest.concat(bidRequestedHandler(args)); - } else if (evtype === CONSTANTS.EVENTS.BID_RESPONSE) { - handlerResponse.push(bidResponseHandler(args)); - } - if (evtype === CONSTANTS.EVENTS.AUCTION_END) { - let bidWonTimeout = atsAnalyticsAdapter.context.bidWonTimeout ? atsAnalyticsAdapter.context.bidWonTimeout : 2000; - let events = []; - setTimeout(() => { - let winningBids = $$PREBID_GLOBAL$$.getAllWinningBids(); - logInfo('ATS Analytics - winning bids: ', winningBids) - // prepare format data for sending to analytics endpoint - if (handlerRequest.length) { - let wonEvent = {}; - if (handlerResponse.length) { - events = handlerRequest.filter(request => handlerResponse.filter(function (response) { - if (request.bid_id === response.bid_id) { - Object.assign(request, response); - } - })); - if (winningBids.length) { - events = events.filter(event => winningBids.filter(function (won) { - wonEvent.bid_id = won.requestId; - wonEvent.bid_won = true; - if (event.bid_id === wonEvent.bid_id) { - Object.assign(event, wonEvent); - } - })) - } - } else { - events = handlerRequest; - } - // check should we send data to analytics or not, check first cookie value _lr_sampling_rate - try { - let envelopeSourceCookieValue = storage.getCookie('_lr_env_src_ats'); - let samplingRateCookie = storage.getCookie('_lr_sampling_rate'); - if (!samplingRateCookie) { - preflightRequest(envelopeSourceCookieValue, events); - } else { - if (atsAnalyticsAdapter.shouldFireRequest(parseInt(samplingRateCookie)) && envelopeSourceCookieValue != null) { - logInfo('ATS Analytics - events to send: ', events); - sendDataToAnalytic(events); - } - } - // empty events array to not send duplicate events - events = []; - } catch (err) { - logError('ATS Analytics - preflight request encounter an error: ', err); - } - } - }, bidWonTimeout); - } -} - adaptermanager.registerAnalyticsAdapter({ adapter: atsAnalyticsAdapter, code: 'atsAnalytics', diff --git a/modules/atsAnalyticsAdapter.md b/modules/atsAnalyticsAdapter.md index 17819ac61b3..7c634f39ae2 100644 --- a/modules/atsAnalyticsAdapter.md +++ b/modules/atsAnalyticsAdapter.md @@ -17,7 +17,6 @@ Analytics adapter for Authenticated Traffic Solution(ATS), provided by LiveRamp. provider: 'atsAnalytics', options: { pid: '999', // publisher ID - bidWonTimeout: 2000 // on auction end for how long to wait for bid_won events, by default it's 2000 miliseconds, if it's not set it will be 2000 miliseconds. } } ``` diff --git a/modules/audiencerunBidAdapter.js b/modules/audiencerunBidAdapter.js index 2c100bce27b..da0cbb39925 100644 --- a/modules/audiencerunBidAdapter.js +++ b/modules/audiencerunBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isFn, logError, getValue, getBidIdParameter, _each, isArray, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -20,7 +20,7 @@ let requestedBids = []; function getPageUrl(bidderRequest) { return ( config.getConfig('pageUrl') || - deepAccess(bidderRequest, 'refererInfo.referer') || + utils.deepAccess(bidderRequest, 'refererInfo.referer') || null ); } @@ -32,8 +32,8 @@ function getPageUrl(bidderRequest) { * @returns {number} */ function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); } try { @@ -61,8 +61,8 @@ export const spec = { */ isBidRequestValid: function (bid) { let isValid = true; - if (!deepAccess(bid, 'params.zoneId')) { - logError('AudienceRun zoneId parameter is required. Bid aborted.'); + if (!utils.deepAccess(bid, 'params.zoneId')) { + utils.logError('AudienceRun zoneId parameter is required. Bid aborted.'); isValid = false; } return isValid; @@ -77,19 +77,19 @@ export const spec = { */ buildRequests: function (bidRequests, bidderRequest) { const bids = bidRequests.map((bid) => { - const sizes = deepAccess(bid, 'mediaTypes.banner.sizes', []); + const sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes', []); return { - zoneId: getValue(bid.params, 'zoneId'), + zoneId: utils.getValue(bid.params, 'zoneId'), sizes: sizes.map((size) => ({ w: size[0], h: size[1], })), bidfloor: getBidFloor(bid), bidId: bid.bidId, - bidderRequestId: getBidIdParameter('bidderRequestId', bid), - adUnitCode: getBidIdParameter('adUnitCode', bid), - auctionId: getBidIdParameter('auctionId', bid), - transactionId: getBidIdParameter('transactionId', bid), + bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), + adUnitCode: utils.getBidIdParameter('adUnitCode', bid), + auctionId: utils.getBidIdParameter('auctionId', bid), + transactionId: utils.getBidIdParameter('transactionId', bid), }; }); @@ -133,7 +133,7 @@ export const spec = { */ interpretResponse: function (serverResponse, bidRequest) { const bids = []; - _each(serverResponse.body.bid, function (bidObject) { + utils._each(serverResponse.body.bid, function (bidObject) { if (!bidObject.cpm || bidObject.cpm === null || !bidObject.adm) { return; } @@ -196,7 +196,7 @@ export const spec = { * @param {Array} timeoutData timeout specific data */ onTimeout: function (timeoutData) { - if (!isArray(timeoutData)) { + if (!utils.isArray(timeoutData)) { return; } @@ -204,7 +204,7 @@ export const spec = { const bidOnTimeout = requestedBids.find((requestedBid) => requestedBid.bidId === bid.bidId); if (bidOnTimeout) { - triggerPixel( + utils.triggerPixel( `${TIMEOUT_EVENT_URL}/${bidOnTimeout.zoneId}/${bidOnTimeout.bidId}` ); } diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 2cfcfbe98b4..415c52ba6d3 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -1,5 +1,5 @@ -import { logInfo } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js' +import * as utils from '../src/utils.js' import {BANNER} from '../src/mediaTypes.js' import {ajax} from '../src/ajax.js' @@ -92,7 +92,7 @@ export const spec = { }) }) } else { - logInfo('automatad :: no valid responses to interpret') + utils.logInfo('automatad :: no valid responses to interpret') } return bidResponses diff --git a/modules/axonixBidAdapter.js b/modules/axonixBidAdapter.js index 7cd8f63bd2a..daaac27e6a4 100644 --- a/modules/axonixBidAdapter.js +++ b/modules/axonixBidAdapter.js @@ -1,7 +1,7 @@ -import { isArray, logError, deepAccess, isEmpty, triggerPixel, replaceAuctionPrice } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; const BIDDER_CODE = 'axonix'; @@ -68,9 +68,9 @@ export const spec = { // video bid request validation if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { if (!bid.mediaTypes[VIDEO].hasOwnProperty('mimes') || - !isArray(bid.mediaTypes[VIDEO].mimes) || + !utils.isArray(bid.mediaTypes[VIDEO].mimes) || bid.mediaTypes[VIDEO].mimes.length === 0) { - logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); + utils.logError('mimes are mandatory for video bid request. Ad Unit: ', JSON.stringify(bid)); return false; } @@ -142,7 +142,7 @@ export const spec = { interpretResponse: function(serverResponse) { const response = serverResponse ? serverResponse.body : []; - if (!isArray(response)) { + if (!utils.isArray(response)) { return []; } @@ -160,9 +160,9 @@ export const spec = { }, onTimeout: function(timeoutData) { - const params = deepAccess(timeoutData, '0.params.0'); + const params = utils.deepAccess(timeoutData, '0.params.0'); - if (!isEmpty(params)) { + if (!utils.isEmpty(params)) { ajax(getURL(params, 'prebid/timeout'), null, timeoutData[0], { method: 'POST', options: { @@ -177,7 +177,7 @@ export const spec = { const { nurl } = bid || {}; if (bid.nurl) { - triggerPixel(replaceAuctionPrice(nurl, bid.cpm)); + utils.triggerPixel(utils.replaceAuctionPrice(nurl, bid.cpm)); }; } } diff --git a/modules/beachfrontBidAdapter.js b/modules/beachfrontBidAdapter.js index e705156d4a2..d633359eb8e 100644 --- a/modules/beachfrontBidAdapter.js +++ b/modules/beachfrontBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, deepAccess, deepSetValue, deepClone, isArray, parseSizesInput, isFn, parseUrl, getUniqueIdentifierStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; @@ -6,7 +6,7 @@ import { VIDEO, BANNER } from '../src/mediaTypes.js'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; -const ADAPTER_VERSION = '1.19'; +const ADAPTER_VERSION = '1.17'; const ADAPTER_NAME = 'BFIO_PREBID'; const OUTSTREAM = 'outstream'; const CURRENCY = 'USD'; @@ -32,27 +32,7 @@ export const spec = { supportedMediaTypes: [ VIDEO, BANNER ], isBidRequestValid(bid) { - if (isVideoBid(bid)) { - if (!getVideoBidParam(bid, 'appId')) { - logWarn('Beachfront: appId param is required for video bids.'); - return false; - } - if (!getVideoBidParam(bid, 'bidfloor')) { - logWarn('Beachfront: bidfloor param is required for video bids.'); - return false; - } - } - if (isBannerBid(bid)) { - if (!getBannerBidParam(bid, 'appId')) { - logWarn('Beachfront: appId param is required for banner bids.'); - return false; - } - if (!getBannerBidParam(bid, 'bidfloor')) { - logWarn('Beachfront: bidfloor param is required for banner bids.'); - return false; - } - } - return true; + return !!(isVideoBidValid(bid) || isBannerBidValid(bid)); }, buildRequests(bids, bidderRequest) { @@ -85,12 +65,12 @@ export const spec = { if (isVideoBid(bidRequest)) { if (!response || !response.bidPrice) { - logWarn(`No valid video bids from ${spec.code} bidder`); + utils.logWarn(`No valid video bids from ${spec.code} bidder`); return []; } let sizes = getVideoSizes(bidRequest); let firstSize = getFirstSize(sizes); - let context = deepAccess(bidRequest, 'mediaTypes.video.context'); + let context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); let responseType = getVideoBidParam(bidRequest, 'responseType') || 'both'; let responseMeta = Object.assign({ mediaType: VIDEO, advertiserDomains: [] }, response.meta); let bidResponse = { @@ -119,7 +99,7 @@ export const spec = { return bidResponse; } else { if (!response || !response.length) { - logWarn(`No valid banner bids from ${spec.code} bidder`); + utils.logWarn(`No valid banner bids from ${spec.code} bidder`); return []; } return response @@ -148,7 +128,7 @@ export const spec = { getUserSyncs(syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '') { let syncs = []; let { gdprApplies, consentString = '' } = gdprConsent; - let bannerResponse = find(serverResponses, (res) => isArray(res.body)); + let bannerResponse = find(serverResponses, (res) => utils.isArray(res.body)); if (bannerResponse) { if (syncOptions.iframeEnabled) { @@ -206,7 +186,7 @@ function getFirstSize(sizes) { } function parseSizes(sizes) { - return parseSizesInput(sizes).map(size => { + return utils.parseSizesInput(sizes).map(size => { let [ width, height ] = size.split('x'); return { w: parseInt(width, 10) || undefined, @@ -216,11 +196,11 @@ function parseSizes(sizes) { } function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); } function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); } function getOsVersion() { @@ -257,33 +237,33 @@ function getDoNotTrack() { } function isVideoBid(bid) { - return deepAccess(bid, 'mediaTypes.video'); + return utils.deepAccess(bid, 'mediaTypes.video'); } function isBannerBid(bid) { - return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); + return utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); } function getVideoBidParam(bid, key) { - return deepAccess(bid, 'params.video.' + key) || deepAccess(bid, 'params.' + key); + return utils.deepAccess(bid, 'params.video.' + key) || utils.deepAccess(bid, 'params.' + key); } function getBannerBidParam(bid, key) { - return deepAccess(bid, 'params.banner.' + key) || deepAccess(bid, 'params.' + key); + return utils.deepAccess(bid, 'params.banner.' + key) || utils.deepAccess(bid, 'params.' + key); } function getPlayerBidParam(bid, key, defaultValue) { - let param = deepAccess(bid, 'params.player.' + key); + let param = utils.deepAccess(bid, 'params.player.' + key); return param === undefined ? defaultValue : param; } function getBannerBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; + let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'banner', size: '*' }) : {}; return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); } function getVideoBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; + let floorInfo = utils.isFn(bid.getFloor) ? bid.getFloor({ currency: CURRENCY, mediaType: 'video', size: '*' }) : {}; return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); } @@ -297,7 +277,7 @@ function isBannerBidValid(bid) { function getTopWindowLocation(bidderRequest) { let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); + return utils.parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); } function getTopWindowReferrer() { @@ -316,7 +296,7 @@ function getEids(bid) { function getUserId(bid) { return ({ key, source, rtiPartner, atype }) => { - let id = deepAccess(bid, `userId.${key}`); + let id = utils.deepAccess(bid, `userId.${key}`); return id ? formatEid(id, source, rtiPartner, atype) : null; }; } @@ -360,12 +340,11 @@ function createVideoRequestData(bid, bidderRequest) { let tagid = getVideoBidParam(bid, 'tagid'); let topLocation = getTopWindowLocation(bidderRequest); let eids = getEids(bid); - let ortb2 = deepClone(config.getConfig('ortb2')); let payload = { isPrebid: true, appId: appId, domain: document.location.hostname, - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: [{ video: Object.assign({ w: firstSize.w, @@ -379,7 +358,6 @@ function createVideoRequestData(bid, bidderRequest) { displaymanagerver: ADAPTER_VERSION }], site: { - ...deepAccess(ortb2, 'site', {}), page: topLocation.href, domain: topLocation.hostname }, @@ -391,32 +369,39 @@ function createVideoRequestData(bid, bidderRequest) { js: 1, geo: {} }, - app: deepAccess(ortb2, 'app'), - user: deepAccess(ortb2, 'user'), + regs: { + ext: {} + }, + source: { + ext: {} + }, + user: { + ext: {} + }, cur: [CURRENCY] }; if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + payload.regs.ext.us_privacy = bidderRequest.uspConsent; } if (bidderRequest && bidderRequest.gdprConsent) { let { gdprApplies, consentString } = bidderRequest.gdprConsent; - deepSetValue(payload, 'regs.ext.gdpr', gdprApplies ? 1 : 0); - deepSetValue(payload, 'user.ext.consent', consentString); + payload.regs.ext.gdpr = gdprApplies ? 1 : 0; + payload.user.ext.consent = consentString; } if (bid.schain) { - deepSetValue(payload, 'source.ext.schain', bid.schain); + payload.source.ext.schain = bid.schain; } if (eids.length > 0) { - deepSetValue(payload, 'user.ext.eids', eids); + payload.user.ext.eids = eids; } let connection = navigator.connection || navigator.webkitConnection; if (connection && connection.effectiveType) { - deepSetValue(payload, 'device.connectiontype', connection.effectiveType); + payload.device.connectiontype = connection.effectiveType; } return payload; @@ -434,10 +419,8 @@ function createBannerRequestData(bids, bidderRequest) { sizes: getBannerSizes(bid) }; }); - let ortb2 = deepClone(config.getConfig('ortb2')); let payload = { slots: slots, - ortb2: ortb2, page: topLocation.href, domain: topLocation.hostname, search: topLocation.search, @@ -466,7 +449,7 @@ function createBannerRequestData(bids, bidderRequest) { } SUPPORTED_USER_IDS.forEach(({ key, queryParam }) => { - let id = deepAccess(bids, `0.userId.${key}`) + let id = utils.deepAccess(bids, `0.userId.${key}`) if (id) { payload[queryParam] = id; } diff --git a/modules/beopBidAdapter.js b/modules/beopBidAdapter.js index 2e74170fcaf..b7e6708f701 100644 --- a/modules/beopBidAdapter.js +++ b/modules/beopBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, logWarn, triggerPixel, buildUrl, logInfo, getValue, getBidIdParameter } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'beop'; @@ -36,7 +36,7 @@ export const spec = { */ buildRequests: function(validBidRequests, bidderRequest) { const slots = validBidRequests.map(beOpRequestSlotsMaker); - let pageUrl = deepAccess(window, 'location.href') || deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl'); + let pageUrl = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); let fpd = config.getLegacyFpd(config.getConfig('ortb2')); let gdpr = bidderRequest.gdprConsent; let firstSlot = slots[0]; @@ -50,7 +50,7 @@ export const spec = { kwds: (fpd && fpd.site && fpd.site.keywords) || [], dbg: false, slts: slots, - is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'), + is_amp: utils.deepAccess(bidderRequest, 'referrerInfo.isAmp'), tc_string: (gdpr && gdpr.gdprApplies) ? gdpr.consentString : null, }; const payloadString = JSON.stringify(payloadObject); @@ -61,7 +61,7 @@ export const spec = { } }, interpretResponse: function(serverResponse, request) { - if (serverResponse && serverResponse.body && isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { + if (serverResponse && serverResponse.body && utils.isArray(serverResponse.body.bids) && serverResponse.body.bids.length > 0) { return serverResponse.body.bids; } return []; @@ -73,8 +73,8 @@ export const spec = { let trackingParams = buildTrackingParams(timeoutData, 'timeout', timeoutData.timeout); - logWarn(BIDDER_CODE + ': timed out request'); - triggerPixel(buildUrl({ + utils.logWarn(BIDDER_CODE + ': timed out request'); + utils.triggerPixel(utils.buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -87,8 +87,8 @@ export const spec = { } let trackingParams = buildTrackingParams(bid, 'won', bid.cpm); - logInfo(BIDDER_CODE + ': won request'); - triggerPixel(buildUrl({ + utils.logInfo(BIDDER_CODE + ': won request'); + utils.triggerPixel(utils.buildUrl({ protocol: 'https', hostname: 't.beop.io', pathname: '/bid', @@ -99,24 +99,22 @@ export const spec = { } function buildTrackingParams(data, info, value) { - const accountId = data.params.accountId; return { - pid: accountId === undefined ? data.ad.match(/account: \“([a-f\d]{24})\“/)[1] : accountId, + pid: data.params.accountId, nid: data.params.networkId, nptnid: data.params.networkPartnerId, - bid: data.bidId || data.requestId, + bid: data.bidId, sl_n: data.adUnitCode, aid: data.auctionId, se_ca: 'bid', se_ac: info, - se_va: value, - url: window.location.href + se_va: value }; } function beOpRequestSlotsMaker(bid) { - const bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes'); - const publisherCurrency = config.getConfig('currency.adServerCurrency') || getValue(bid.params, 'currency') || 'EUR'; + const bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); + const publisherCurrency = utils.getValue(bid.params, 'currency') || 'EUR'; let floor; if (typeof bid.getFloor === 'function') { const floorInfo = bid.getFloor({currency: publisherCurrency, mediaType: 'banner', size: [1, 1]}); @@ -125,19 +123,19 @@ function beOpRequestSlotsMaker(bid) { } } return { - sizes: isArray(bannerSizes) ? bannerSizes : bid.sizes, + sizes: utils.isArray(bannerSizes) ? bannerSizes : bid.sizes, flr: floor, - pid: getValue(bid.params, 'accountId'), - nid: getValue(bid.params, 'networkId'), - nptnid: getValue(bid.params, 'networkPartnerId'), - bid: getBidIdParameter('bidId', bid), - brid: getBidIdParameter('bidderRequestId', bid), - name: getBidIdParameter('adUnitCode', bid), - aid: getBidIdParameter('auctionId', bid), - tid: getBidIdParameter('transactionId', bid), - brc: getBidIdParameter('bidRequestsCount', bid), - bdrc: getBidIdParameter('bidderRequestCount', bid), - bwc: getBidIdParameter('bidderWinsCount', bid), + pid: utils.getValue(bid.params, 'accountId'), + nid: utils.getValue(bid.params, 'networkId'), + nptnid: utils.getValue(bid.params, 'networkPartnerId'), + bid: utils.getBidIdParameter('bidId', bid), + brid: utils.getBidIdParameter('bidderRequestId', bid), + name: utils.getBidIdParameter('adUnitCode', bid), + aid: utils.getBidIdParameter('auctionId', bid), + tid: utils.getBidIdParameter('transactionId', bid), + brc: utils.getBidIdParameter('bidRequestsCount', bid), + bdrc: utils.getBidIdParameter('bidderRequestCount', bid), + bwc: utils.getBidIdParameter('bidderWinsCount', bid), } } diff --git a/modules/betweenBidAdapter.js b/modules/betweenBidAdapter.js index b2f63488e12..5a351def958 100644 --- a/modules/betweenBidAdapter.js +++ b/modules/betweenBidAdapter.js @@ -1,16 +1,14 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { getAdUnitSizes, parseSizesInput } from '../src/utils.js'; +import { getAdUnitSizes, parseSizesInput, deepAccess } from '../src/utils.js'; import { getRefererInfo } from '../src/refererDetection.js'; const BIDDER_CODE = 'between'; -let ENDPOINT = 'https://ads.betweendigital.com/adjson?t=prebid'; -const CODE_TYPES = ['inpage', 'preroll', 'midroll', 'postroll']; +const ENDPOINT = 'https://ads.betweendigital.com/adjson?t=prebid'; -const includes = require('core-js-pure/features/array/includes.js'); export const spec = { code: BIDDER_CODE, aliases: ['btw'], - supportedMediaTypes: ['banner', 'video'], + supportedMediaTypes: ['banner'], /** * Determines whether or not the given bid request is valid. * @@ -23,7 +21,7 @@ export const spec = { /** * Make a server request from the list of BidRequests. * - * @param {validBidRequest?pbjs_debug=trues[]} - an array of bids + * @param {validBidRequests[]} - an array of bids * @return ServerRequest Info describing the request to the server. */ buildRequests: function(validBidRequests, bidderRequest) { @@ -31,32 +29,21 @@ export const spec = { const gdprConsent = bidderRequest && bidderRequest.gdprConsent; const refInfo = getRefererInfo(); - validBidRequests.forEach((i) => { - const video = i.mediaTypes && i.mediaTypes.video; - + validBidRequests.forEach(i => { let params = { - eids: getUsersIds(i), sizes: parseSizesInput(getAdUnitSizes(i)), jst: 'hb', ord: Math.random() * 10000000000000000, tz: getTz(), fl: getFl(), rr: getRr(), - s: i.params && i.params.s, + shid: getSharedId(i)('id'), + shid3: getSharedId(i)('third'), + s: i.params.s, bidid: i.bidId, transactionid: i.transactionId, auctionid: i.auctionId }; - - if (video) { - params.mediaType = 2; - params.maxd = video.maxd; - params.mind = video.mind; - params.pos = 'atf'; - ENDPOINT += '&jst=pvc'; - params.codeType = includes(CODE_TYPES, video.codeType) ? video.codeType : 'inpage'; - } - if (i.params.itu !== undefined) { params.itu = i.params.itu; } @@ -107,15 +94,12 @@ export const spec = { */ interpretResponse: function(serverResponse, bidRequest) { const bidResponses = []; - for (var i = 0; i < serverResponse.body.length; i++) { let bidResponse = { requestId: serverResponse.body[i].bidid, cpm: serverResponse.body[i].cpm || 0, width: serverResponse.body[i].w, height: serverResponse.body[i].h, - vastXml: serverResponse.body[i].vastXml, - mediaType: serverResponse.body[i].mediaType, ttl: serverResponse.body[i].ttl, creativeId: serverResponse.body[i].creativeid, currency: serverResponse.body[i].currency || 'RUB', @@ -125,7 +109,6 @@ export const spec = { advertiserDomains: serverResponse.body[i].adomain ? serverResponse.body[i].adomain : [] } }; - bidResponses.push(bidResponse); } return bidResponses; @@ -166,8 +149,13 @@ export const spec = { } } -function getUsersIds({ userIdAsEids }) { - return (userIdAsEids && userIdAsEids.length !== 0) ? userIdAsEids : []; +function getSharedId(bid) { + const id = deepAccess(bid, 'userId.sharedid.id'); + const third = deepAccess(bid, 'userId.sharedid.third'); + return function(kind) { + if (kind === 'id') return id || ''; + return third || ''; + } } function getRr() { diff --git a/modules/bidViewability.js b/modules/bidViewability.js index 545d57940da..c3b72cda8d4 100644 --- a/modules/bidViewability.js +++ b/modules/bidViewability.js @@ -4,7 +4,7 @@ import { config } from '../src/config.js'; import * as events from '../src/events.js'; -import CONSTANTS from '../src/constants.json'; +import { EVENTS } from '../src/constants.json'; import { logWarn, isFn, triggerPixel } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import adapterManager, { gdprDataHandler, uspDataHandler } from '../src/adapterManager.js'; @@ -70,12 +70,12 @@ export let impressionViewableHandler = (globalModuleConfig, slot, event) => { // trigger respective bidder's onBidViewable handler adapterManager.callBidViewableBidder(respectiveBid.bidder, respectiveBid); // emit the BID_VIEWABLE event with bid details, this event can be consumed by bidders and analytics pixels - events.emit(CONSTANTS.EVENTS.BID_VIEWABLE, respectiveBid); + events.emit(EVENTS.BID_VIEWABLE, respectiveBid); } }; export let init = () => { - events.on(CONSTANTS.EVENTS.AUCTION_INIT, () => { + events.on(EVENTS.AUCTION_INIT, () => { // read the config for the module const globalModuleConfig = config.getConfig(MODULE_NAME) || {}; // do nothing if module-config.enabled is not set to true diff --git a/modules/bidViewabilityIO.js b/modules/bidViewabilityIO.js index ff7ec70e32c..4651e424d00 100644 --- a/modules/bidViewabilityIO.js +++ b/modules/bidViewabilityIO.js @@ -1,7 +1,7 @@ -import { logMessage } from '../src/utils.js'; import { config } from '../src/config.js'; import * as events from '../src/events.js'; -import CONSTANTS from '../src/constants.json'; +import { EVENTS } from '../src/constants.json'; +import * as utils from '../src/utils.js'; const MODULE_NAME = 'bidViewabilityIO'; const CONFIG_ENABLED = 'enabled'; @@ -23,8 +23,8 @@ export let isSupportedMediaType = (bid) => { return supportedMediaTypes.indexOf(bid.mediaType) > -1; } -let _logMessage = (message) => { - return logMessage(`${MODULE_NAME}: ${message}`); +let logMessage = (message) => { + return utils.logMessage(`${MODULE_NAME}: ${message}`); } // returns options for the iO that detects if the ad is viewable @@ -42,8 +42,8 @@ export let getViewableOptions = (bid) => { export let markViewed = (bid, entry, observer) => { return () => { observer.unobserve(entry.target); - events.emit(CONSTANTS.EVENTS.BID_VIEWABLE, bid); - _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); + events.emit(EVENTS.BID_VIEWABLE, bid); + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} was viewed`); } } @@ -59,13 +59,13 @@ export let viewCallbackFactory = (bid) => { return (entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { - _logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + logMessage(`viewable timer starting for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); entry.target.view_tracker = setTimeout(markViewed(bid, entry, observer), IAB_VIEWABLE_DISPLAY_TIME); } else { - _logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); + logMessage(`id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode} is out of view`); if (entry.target.view_tracker) { clearTimeout(entry.target.view_tracker); - _logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); + logMessage(`viewable timer stopped for id: ${entry.target.getAttribute('id')} code: ${bid.adUnitCode}`); } } }); @@ -77,7 +77,7 @@ export let init = () => { if (conf[MODULE_NAME][CONFIG_ENABLED] && CLIENT_SUPPORTS_IO) { // if the module is enabled and the browser supports Intersection Observer, // then listen to AD_RENDER_SUCCEEDED to setup IO's for supported mediaTypes - events.on(CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED, ({doc, bid, id}) => { + events.on(EVENTS.AD_RENDER_SUCCEEDED, ({doc, bid, id}) => { if (isSupportedMediaType(bid)) { let viewable = new IntersectionObserver(viewCallbackFactory(bid), getViewableOptions(bid)); let element = document.getElementById(bid.adUnitCode); diff --git a/modules/bidglassBidAdapter.js b/modules/bidglassBidAdapter.js index 3184372881b..b77ca474e13 100644 --- a/modules/bidglassBidAdapter.js +++ b/modules/bidglassBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, isArray, getBidIdParameter, deepClone, getUniqueIdentifierStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; // import {config} from 'src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; @@ -69,12 +69,12 @@ export const spec = { let bidglass = window['bidglass']; - _each(validBidRequests, function(bid) { - bid.sizes = ((isArray(bid.sizes) && isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); - bid.sizes = bid.sizes.filter(size => isArray(size)); + utils._each(validBidRequests, function(bid) { + bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes]); + bid.sizes = bid.sizes.filter(size => utils.isArray(size)); - var adUnitId = getBidIdParameter('adUnitId', bid.params); - var options = deepClone(bid.params); + var adUnitId = utils.getBidIdParameter('adUnitId', bid.params); + var options = utils.deepClone(bid.params); delete options.adUnitId; @@ -96,7 +96,7 @@ export const spec = { // Stuff to send: page URL const bidReq = { - reqId: getUniqueIdentifierStr(), + reqId: utils.getUniqueIdentifierStr(), imps: imps, ref: getReferer(), ori: getOrigins() @@ -125,7 +125,7 @@ export const spec = { interpretResponse: function(serverResponse) { const bidResponses = []; - _each(serverResponse.body.bidResponses, function(serverBid) { + utils._each(serverResponse.body.bidResponses, function(serverBid) { const bidResponse = { requestId: serverBid.requestId, cpm: parseFloat(serverBid.cpm), diff --git a/modules/bidscubeBidAdapter.js b/modules/bidscubeBidAdapter.js index 951bd97d255..d3f27a5ac6d 100644 --- a/modules/bidscubeBidAdapter.js +++ b/modules/bidscubeBidAdapter.js @@ -1,6 +1,6 @@ -import { logMessage, getWindowLocation } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js' +import * as utils from '../src/utils.js' const BIDDER_CODE = 'bidscube' const URL = 'https://supply.bidscube.com/?c=o&m=multi' @@ -20,9 +20,9 @@ export const spec = { try { window.top.location.toString() winTop = window.top - } catch (e) { logMessage(e) } + } catch (e) { utils.logMessage(e) } - const location = getWindowLocation() + const location = utils.getWindowLocation() const placements = [] for (let i = 0; i < validBidRequests.length; i++) { diff --git a/modules/bizzclickBidAdapter.js b/modules/bizzclickBidAdapter.js index 38195f8f9d9..95c53b78de2 100644 --- a/modules/bizzclickBidAdapter.js +++ b/modules/bizzclickBidAdapter.js @@ -1,6 +1,6 @@ -import { logMessage, getDNT, deepSetValue, deepAccess, _map, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'bizzclick'; const ACCOUNTID_MACROS = '[account_id]'; @@ -67,7 +67,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let bids = []; for (let bidRequest of validBidRequests) { @@ -80,7 +80,7 @@ export const spec = { device: { w: winTop.screen.width, h: winTop.screen.height, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, language: (navigator && navigator.language) ? navigator.language.indexOf('-') != -1 ? navigator.language.split('-')[0] : navigator.language : '', }, site: { @@ -124,12 +124,12 @@ export const spec = { } if (bidRequest) { if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) { - deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); - deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); + utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); + utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); } if (bidRequest.uspConsent !== undefined) { - deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); + utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); } } bids.push(data) @@ -194,7 +194,7 @@ export const spec = { * @returns {boolean} */ const checkRequestType = (bidRequest, type) => { - return (typeof deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); + return (typeof utils.deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); } const parseNative = admObject => { const { assets, link, imptrackers, jstracker } = admObject.native; @@ -240,7 +240,7 @@ const addNativeParameters = bidRequest => { id: bidRequest.transactionId, ver: NATIVE_VERSION, }; - const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => { + const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -286,7 +286,7 @@ const parseSizes = (bid, mediaType) => { mediaTypes.video.w, mediaTypes.video.h ]; - } else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { + } else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { size = bid.mediaTypes.video.playerSize[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) { size = bid.sizes[0]; @@ -299,7 +299,7 @@ const parseSizes = (bid, mediaType) => { } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { sizes = bid.sizes } else { - logWarn('no sizes are setup or found'); + utils.logWarn('no sizes are setup or found'); } return sizes } diff --git a/modules/bliinkBidAdapter.js b/modules/bliinkBidAdapter.js deleted file mode 100644 index 45b6c46c2df..00000000000 --- a/modules/bliinkBidAdapter.js +++ /dev/null @@ -1,336 +0,0 @@ -// eslint-disable-next-line prebid/validate-imports -// eslint-disable-next-line prebid/validate-imports -import {registerBidder} from '../src/adapters/bidderFactory.js' -export const BIDDER_CODE = 'bliink' -export const BLIINK_ENDPOINT_ENGINE = 'https://engine.bliink.io/delivery' -export const BLIINK_ENDPOINT_ENGINE_VAST = 'https://engine.bliink.io/vast' -export const BLIINK_ENDPOINT_COOKIE_SYNC = 'https://cookiesync.api.bliink.io' -export const META_KEYWORDS = 'keywords' -export const META_DESCRIPTION = 'description' - -const VIDEO = 'video' -const BANNER = 'banner' - -const supportedMediaTypes = [BANNER, VIDEO] -const aliasBidderCode = ['bk'] - -export function getMetaList(name) { - if (!name || name.length === 0) return [] - - return [ - { - key: 'name', - value: name, - }, - { - key: 'name*', - value: name, - }, - { - key: 'itemprop*', - value: name, - }, - { - key: 'property', - value: `'og:${name}'`, - }, - { - key: 'property', - value: `'twitter:${name}'`, - }, - { - key: 'property', - value: `'article:${name}'`, - }, - ] -} - -export function getOneMetaValue(query) { - const metaEl = document.querySelector(query) - - if (metaEl && metaEl.content) { - return metaEl.content - } - - return null -} - -export function getMetaValue(name) { - const metaList = getMetaList(name) - for (let i = 0; i < metaList.length; i++) { - const meta = metaList[i]; - const metaValue = getOneMetaValue(`meta[${meta.key}=${meta.value}]`); - if (metaValue) { - return metaValue - } - } - return '' -} - -export function getKeywords() { - const metaKeywords = getMetaValue(META_KEYWORDS) - if (metaKeywords) { - const keywords = [ - ...metaKeywords.split(','), - ] - - if (keywords && keywords.length > 0) { - return keywords - .filter((value) => value) - .map((value) => value.trim()) - } - } - - return [] -} - -export const parseXML = (content) => { - if (typeof content !== 'string' || content.length === 0) return null - - const parser = new DOMParser() - let xml; - - try { - xml = parser.parseFromString(content, 'text/xml') - } catch (e) {} - - if (xml && - xml.getElementsByTagName('VAST')[0] && - xml.getElementsByTagName('VAST')[0].tagName === 'VAST') { - return xml - } - - return null -} - -/** - * @param bidRequest - * @param bliinkCreative - * @return {{cpm, netRevenue: boolean, requestId, width: (*|number), currency, ttl: number, creativeId, height: (*|number)} & {mediaType: string, vastXml}} - */ -export const buildBid = (bidRequest, bliinkCreative) => { - if (!bidRequest && !bliinkCreative) return null - - const body = { - requestId: bidRequest.bidId, - currency: bliinkCreative.currency, - cpm: bliinkCreative.price, - creativeId: bliinkCreative.creativeId, - width: (bidRequest.sizes && bidRequest.sizes[0][0]) || 1, - height: (bidRequest.sizes && bidRequest.sizes[0][1]) || 1, - netRevenue: false, - ttl: 3600, - } - - // eslint-disable-next-line no-mixed-operators - if ((bliinkCreative) && bidRequest && - // eslint-disable-next-line no-mixed-operators - !bidRequest.bidId || - !bidRequest.sizes || - !bidRequest.params || - !(bidRequest.params.placement) - ) return null - - delete bidRequest['bids'] - - switch (bliinkCreative.media_type) { - case VIDEO: - return Object.assign(body, { - mediaType: VIDEO, - vastXml: bliinkCreative.content, - }) - case BANNER: - return Object.assign(body, { - mediaType: BANNER, - ad: (bliinkCreative && bliinkCreative.content && bliinkCreative.content.creative && bliinkCreative.content.creative.adm) || '', - }) - default: - break; - } -} - -/** - * @description Verify the the AdUnits.bids, respond with true (valid) or false (invalid). - * - * @param bid - * @return boolean - */ -export const isBidRequestValid = (bid) => { - return !(!bid || !bid.params || !bid.params.placement || !bid.params.tagId) -} - -/** - * @description Takes an array of valid bid requests, all of which are guaranteed to have passed the isBidRequestValid() test. - * - * @param _[] - * @param bidderRequest - * @return {{ method: string, url: string } | null} - */ -export const buildRequests = (_, bidderRequest) => { - if (!bidderRequest) return null - - let data = { - pageUrl: bidderRequest.refererInfo.referer, - pageDescription: getMetaValue(META_DESCRIPTION), - keywords: getKeywords().join(','), - gdpr: false, - gdpr_consent: '', - pageTitle: document.title, - } - - const endPoint = bidderRequest.bids[0].params.placement === VIDEO ? BLIINK_ENDPOINT_ENGINE_VAST : BLIINK_ENDPOINT_ENGINE - - const params = { - bidderRequestId: bidderRequest.bidderRequestId, - bidderCode: bidderRequest.bidderCode, - bids: bidderRequest.bids, - refererInfo: bidderRequest.refererInfo, - } - - if (bidderRequest.gdprConsent) { - data = Object.assign(data, { - gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies, - gdpr_consent: bidderRequest.gdprConsent.consentString - }) - } - - if (bidderRequest.bids && bidderRequest.bids.length > 0 && bidderRequest.bids[0].sizes && bidderRequest.bids[0].sizes[0]) { - data = Object.assign(data, { - width: bidderRequest.bids[0].sizes[0][0], - height: bidderRequest.bids[0].sizes[0][1] - }) - - return { - method: 'GET', - url: `${endPoint}/${bidderRequest.bids[0].params.tagId}`, - data: data, - params: params, - } - } - - return null -} - -/** - * @description Parse the response (from buildRequests) and generate one or more bid objects. - * - * @param serverResponse - * @param request - * @return - */ -const interpretResponse = (serverResponse, request) => { - if ((serverResponse && serverResponse.mode === 'no-ad')) { - return [] - } - - const body = serverResponse.body - const serverBody = request.params - - const xml = parseXML(body) - - let creative; - - switch (serverBody.bids[0].params.placement) { - case xml && VIDEO: - const price = xml.getElementsByTagName('Price') && xml.getElementsByTagName('Price')[0] - const currency = xml.getElementsByTagName('Currency') && xml.getElementsByTagName('Currency')[0] - const creativeId = xml.getElementsByTagName('CreativeId') && xml.getElementsByTagName('CreativeId')[0] - - creative = { - content: body, - price: (price && price.textContent) || 0, - currency: (currency && currency.textContent) || 'EUR', - creativeId: creativeId || 0, - media_type: 'video', - } - - return buildBid(serverBody.bids[0], creative) - case BANNER: - if (body) { - creative = { - content: body, - price: body.price, - currency: body.currency, - creativeId: 0, - media_type: 'banner', - } - - return buildBid(serverBody.bids[0], creative) - } - - break - default: - break - } -} - -/** - * @description If the publisher allows user-sync activity, the platform will call this function and the adapter may register pixels and/or iframe user syncs. For more information, see Registering User Syncs below - * @param syncOptions - * @param serverResponses - * @param gdprConsent - * @return {[{type: string, url: string}]|*[]} - */ -const getUserSyncs = (syncOptions, serverResponses, gdprConsent) => { - let syncs = [] - - if (syncOptions.pixelEnabled && serverResponses.length > 0) { - if (gdprConsent) { - const gdprParams = `consentString=${gdprConsent.consentString}` - const smartCallbackURL = encodeURIComponent(`${BLIINK_ENDPOINT_COOKIE_SYNC}/cookiesync?partner=smart&uid=[sas_uid]`) - const azerionCallbackURL = encodeURIComponent(`${BLIINK_ENDPOINT_COOKIE_SYNC}/cookiesync?partner=azerion&uid={PUB_USER_ID}`) - const appnexusCallbackURL = encodeURIComponent(`${BLIINK_ENDPOINT_COOKIE_SYNC}/cookiesync?partner=azerion&uid=$UID`) - return [ - { - type: 'script', - url: 'https://prg.smartadserver.com/ac?out=js&nwid=3392&siteid=305791&pgname=rg&fmtid=81127&tgt=[sas_target]&visit=m&tmstp=[timestamp]&clcturl=[countgo]' - }, - { - type: 'image', - url: `https://sync.smartadserver.com/getuid?nwid=3392&${gdprParams}&url=${smartCallbackURL}`, - }, - { - type: 'image', - url: `https://ad.360yield.com/server_match?partner_id=1531&${gdprParams}&r=${azerionCallbackURL}`, - }, - { - type: 'image', - url: `https://ads.stickyadstv.com/auto-user-sync?${gdprParams}`, - }, - { - type: 'image', - url: `https://cookiesync.api.bliink.io/getuid?url=https%3A%2F%2Fvisitor.omnitagjs.com%2Fvisitor%2Fsync%3Fuid%3D1625272249969090bb9d544bd6d8d645%26name%3DBLIINK%26visitor%3D%24UID%26external%3Dtrue&${gdprParams}`, - }, - { - type: 'image', - url: `https://cookiesync.api.bliink.io/getuid?url=https://pixel.advertising.com/ups/58444/sync?&gdpr=1&gdpr_consent=${gdprConsent.consentString}&redir=true&uid=$UID`, - }, - { - type: 'image', - url: `https://ups.analytics.yahoo.com/ups/58499/occ?gdpr=1&gdpr_consent=${gdprConsent.consentString}`, - }, - { - type: 'image', - url: `https://secure.adnxs.com/getuid?${appnexusCallbackURL}`, - }, - ] - } - } - - return syncs; -} - -/** - * @type {{interpretResponse: interpretResponse, code: string, aliases: string[], getUserSyncs: getUserSyncs, buildRequests: buildRequests, onTimeout: onTimeout, onSetTargeting: onSetTargeting, isBidRequestValid: isBidRequestValid, onBidWon: onBidWon}} - */ -export const spec = { - code: BIDDER_CODE, - aliases: aliasBidderCode, - supportedMediaTypes: supportedMediaTypes, - isBidRequestValid, - buildRequests, - interpretResponse, - getUserSyncs, -} - -registerBidder(spec) diff --git a/modules/bliinkBidAdapter.md b/modules/bliinkBidAdapter.md deleted file mode 100644 index af7aee3a1ae..00000000000 --- a/modules/bliinkBidAdapter.md +++ /dev/null @@ -1,94 +0,0 @@ -# Overview - -``` -Module Name: BLIINK Bidder Adapter -Module Type: Bidder Adapter -Maintainer: samuel@bliink.io | jonathan@bliink.io -gdpr_supported: true -tcf2_supported: true -media_types: banner, native, video -``` - -# Description - -Module that connects to BLIINK demand sources to fetch bids. - -# Test Parameters - -## Sample Banner Ad Unit - -```js -const adUnits = [ - { - code: '/19968336/test', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [ - { - bidder: 'bliink', - params: { - placement: 'banner', - tagId: '41' - } - } - ] - } -] -``` - -## Sample Instream Video Ad Unit - -```js -const adUnits = [ - { - code: '/19968336/prebid_cache_video_adunit', - sizes: [[640,480]], - mediaType: 'video', - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640,480]], - } - }, - bids: [ - { - bidder: 'bliink', - params: { - tagId: '41', - placement: 'video', - } - } - ] - } -] -``` - -## Sample outstream Video Ad Unit - -```js -const adUnits = [ - { - code: '/19968336/prebid_cache_video_adunit', - sizes: [[640,480]], - mediaType: 'video', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640,480]], - } - }, - bids: [ - { - bidder: 'bliink', - params: { - tagId: '41', - placement: 'video', - } - } - ] - } -] -``` diff --git a/modules/bluebillywigBidAdapter.js b/modules/bluebillywigBidAdapter.js index 03fb0b92c8f..3d4eeb058b3 100644 --- a/modules/bluebillywigBidAdapter.js +++ b/modules/bluebillywigBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, deepSetValue, deepClone, logWarn, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import find from 'core-js-pure/features/array/find.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO } from '../src/mediaTypes.js'; @@ -43,7 +43,7 @@ const BB_HELPERS = { if (!request.device.h) request.device.h = window.innerHeight; }, addSchain: function(request, validBidRequests) { - const schain = deepAccess(validBidRequests, '0.schain'); + const schain = utils.deepAccess(validBidRequests, '0.schain'); if (schain) request.source.ext = { schain: schain }; }, addCurrency: function(request) { @@ -52,11 +52,11 @@ const BB_HELPERS = { else if (Array.isArray(adServerCur) && adServerCur.length) request.cur = [adServerCur[0]]; }, addUserIds: function(request, validBidRequests) { - const bidUserId = deepAccess(validBidRequests, '0.userId'); + const bidUserId = utils.deepAccess(validBidRequests, '0.userId'); const eids = createEidsArray(bidUserId); if (eids.length) { - deepSetValue(request, 'user.ext.eids', eids); + utils.deepSetValue(request, 'user.ext.eids', eids); } }, substituteUrl: function (url, publication, renderer) { @@ -72,7 +72,7 @@ const BB_HELPERS = { return BB_HELPERS.substituteUrl(BB_CONSTANTS.RENDERER_URL, publication, renderer); }, transformVideoParams: function(videoParams, videoParamsExt) { - videoParams = deepClone(videoParams); + videoParams = utils.deepClone(videoParams); let playerSize = videoParams.playerSize || [BB_CONSTANTS.DEFAULT_WIDTH, BB_CONSTANTS.DEFAULT_HEIGHT]; if (Array.isArray(playerSize[0])) playerSize = playerSize[0]; @@ -105,8 +105,8 @@ const BB_HELPERS = { ttl: BB_CONSTANTS.DEFAULT_TTL }; - const extPrebidTargeting = deepAccess(bid, 'ext.prebid.targeting'); - const extPrebidCache = deepAccess(bid, 'ext.prebid.cache'); + const extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting'); + const extPrebidCache = utils.deepAccess(bid, 'ext.prebid.cache'); if (extPrebidCache && typeof extPrebidCache.vastXml === 'object' && extPrebidCache.vastXml.cacheId && extPrebidCache.vastXml.url) { bidObject.videoCacheKey = extPrebidCache.vastXml.cacheId; @@ -139,12 +139,12 @@ const BB_RENDERER = { else if (bid.vastUrl) config.vastUrl = bid.vastUrl; if (!bid.vastXml && !bid.vastUrl) { - logWarn(`${BB_CONSTANTS.BIDDER_CODE}: No vastXml or vastUrl on bid, bailing...`); + utils.logWarn(`${BB_CONSTANTS.BIDDER_CODE}: No vastXml or vastUrl on bid, bailing...`); return; } if (!(window.bluebillywig && window.bluebillywig.renderers)) { - logWarn(`${BB_CONSTANTS.BIDDER_CODE}: renderer code failed to initialize...`); + utils.logWarn(`${BB_CONSTANTS.BIDDER_CODE}: renderer code failed to initialize...`); return; } @@ -153,7 +153,7 @@ const BB_RENDERER = { const renderer = find(window.bluebillywig.renderers, r => r._id === rendererId); if (renderer) renderer.bootstrap(config, ele, bid.rendererSettings || {}); - else logWarn(`${BB_CONSTANTS.BIDDER_CODE}: Couldn't find a renderer with ${rendererId}`); + else utils.logWarn(`${BB_CONSTANTS.BIDDER_CODE}: Couldn't find a renderer with ${rendererId}`); }, newRenderer: function(rendererUrl, adUnitCode) { const renderer = Renderer.install({ @@ -165,7 +165,7 @@ const BB_RENDERER = { try { renderer.setRender(BB_RENDERER.outstreamRender); } catch (err) { - logWarn(`${BB_CONSTANTS.BIDDER_CODE}: Error tying to setRender on renderer`, err); + utils.logWarn(`${BB_CONSTANTS.BIDDER_CODE}: Error tying to setRender on renderer`, err); } return renderer; @@ -189,70 +189,70 @@ export const spec = { const rendererRegex = /^[\w+_]+$/; if (!bid.params) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no params set on bid. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no params set on bid. Rejecting bid: `, bid); return false; } if (!bid.params.hasOwnProperty('publicationName') || typeof bid.params.publicationName !== 'string') { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no publicationName specified in bid params, or it's not a string. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no publicationName specified in bid params, or it's not a string. Rejecting bid: `, bid); return false; } else if (!publicationNameRegex.test(bid.params.publicationName)) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: publicationName must be in format 'publication' or 'publication.environment'. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: publicationName must be in format 'publication' or 'publication.environment'. Rejecting bid: `, bid); return false; } if ((!bid.params.hasOwnProperty('rendererCode') || typeof bid.params.rendererCode !== 'string')) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no rendererCode was specified in bid params. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no rendererCode was specified in bid params. Rejecting bid: `, bid); return false; } else if (!rendererRegex.test(bid.params.rendererCode)) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: rendererCode must be alphanumeric, including underscores. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: rendererCode must be alphanumeric, including underscores. Rejecting bid: `, bid); return false; } if (!bid.params.accountId) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no accountId specified in bid params. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no accountId specified in bid params. Rejecting bid: `, bid); return false; } if (bid.params.hasOwnProperty('connections')) { if (!Array.isArray(bid.params.connections)) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: connections is not of type array. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: connections is not of type array. Rejecting bid: `, bid); return false; } else { for (let i = 0; i < bid.params.connections.length; i++) { if (!bid.params.hasOwnProperty(bid.params.connections[i])) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: connection specified in params.connections, but not configured in params. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: connection specified in params.connections, but not configured in params. Rejecting bid: `, bid); return false; } } } } else { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no connections specified in bid. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no connections specified in bid. Rejecting bid: `, bid); return false; } if (bid.params.hasOwnProperty('video') && (bid.params.video === null || typeof bid.params.video !== 'object')) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: params.video must be of type object. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: params.video must be of type object. Rejecting bid: `, bid); return false; } if (bid.params.hasOwnProperty('rendererSettings') && (bid.params.rendererSettings === null || typeof bid.params.rendererSettings !== 'object')) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: params.rendererSettings must be of type object. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: params.rendererSettings must be of type object. Rejecting bid: `, bid); return false; } if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { if (!bid.mediaTypes[VIDEO].hasOwnProperty('context')) { - logError(`${BB_CONSTANTS.BIDDER_CODE}: no context specified in bid. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: no context specified in bid. Rejecting bid: `, bid); return false; } if (bid.mediaTypes[VIDEO].context !== 'outstream') { - logError(`${BB_CONSTANTS.BIDDER_CODE}: video.context is invalid, must be "outstream". Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: video.context is invalid, must be "outstream". Rejecting bid: `, bid); return false; } } else { - logError(`${BB_CONSTANTS.BIDDER_CODE}: mediaTypes or mediaTypes.video is not specified. Rejecting bid: `, bid); + utils.logError(`${BB_CONSTANTS.BIDDER_CODE}: mediaTypes or mediaTypes.video is not specified. Rejecting bid: `, bid); return false; } @@ -273,7 +273,7 @@ export const spec = { return extBuilder; }, {}); - const videoParams = BB_HELPERS.transformVideoParams(deepAccess(validBidRequest, 'mediaTypes.video'), deepAccess(validBidRequest, 'params.video')); + const videoParams = BB_HELPERS.transformVideoParams(utils.deepAccess(validBidRequest, 'mediaTypes.video'), utils.deepAccess(validBidRequest, 'params.video')); imps.push({ id: validBidRequest.bidId, ext, secure: window.location.protocol === 'https' ? 1 : 0, video: videoParams }); }); @@ -294,16 +294,16 @@ export const spec = { if (bidderRequest.gdprConsent) { let gdprApplies = 0; if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') gdprApplies = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; - deepSetValue(request, 'regs.ext.gdpr', gdprApplies); - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies); + utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); this.syncStore.uspConsent = bidderRequest.uspConsent; } - if (getConfig('coppa') == true) deepSetValue(request, 'regs.coppa', 1); + if (getConfig('coppa') == true) utils.deepSetValue(request, 'regs.coppa', 1); // Enrich the request with any external data we may have BB_HELPERS.addSiteAppDevice(request, bidderRequest.refererInfo && bidderRequest.refererInfo.referer); diff --git a/modules/boldwinBidAdapter.js b/modules/boldwinBidAdapter.js index fcff7134a92..66b4cbfd77b 100644 --- a/modules/boldwinBidAdapter.js +++ b/modules/boldwinBidAdapter.js @@ -1,6 +1,6 @@ -import { isFn, deepAccess, logMessage } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'boldwin'; const AD_URL = 'https://ssp.videowalldirect.com/pbjs'; @@ -24,8 +24,8 @@ function isBidResponseValid(bid) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); } try { @@ -56,7 +56,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let placements = []; let request = { diff --git a/modules/braveBidAdapter.js b/modules/braveBidAdapter.js index 18bad6b0f75..7ea3eb9cd9b 100644 --- a/modules/braveBidAdapter.js +++ b/modules/braveBidAdapter.js @@ -1,4 +1,4 @@ -import { parseUrl, isEmpty, isStr, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -90,7 +90,7 @@ export const spec = { ua: navigator.userAgent, }, site: { - domain: parseUrl(page).hostname, + domain: utils.parseUrl(page).hostname, page: page, }, tmax: bidderRequest.timeout || config.getConfig('bidderTimeout') || 500, @@ -134,7 +134,7 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: (serverResponse) => { - if (!serverResponse || isEmpty(serverResponse.body)) return []; + if (!serverResponse || utils.isEmpty(serverResponse.body)) return []; let bids = []; serverResponse.body.seatbid.forEach(response => { @@ -173,8 +173,8 @@ export const spec = { }, onBidWon: (bid) => { - if (isStr(bid.nurl) && bid.nurl !== '') { - triggerPixel(bid.nurl); + if (utils.isStr(bid.nurl) && bid.nurl !== '') { + utils.triggerPixel(bid.nurl); } } }; diff --git a/modules/bridgewellBidAdapter.js b/modules/bridgewellBidAdapter.js index 5d545b6f722..2034a59242e 100644 --- a/modules/bridgewellBidAdapter.js +++ b/modules/bridgewellBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, inIframe, deepSetValue } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; import find from 'core-js-pure/features/array/find.js'; @@ -40,7 +40,7 @@ export const spec = { var bidderUrl = REQUEST_ENDPOINT + Math.random(); var userIds; - _each(validBidRequests, function (bid) { + utils._each(validBidRequests, function (bid) { userIds = bid.userId; if (bid.params.cid) { @@ -83,7 +83,7 @@ export const spec = { prebid: '$prebid.version$', bridgewell: BIDDER_VERSION }, - inIframe: inIframe(), + inIframe: utils.inIframe(), url: topUrl, referrer: getTopWindowReferrer(), adUnits: adUnits, @@ -104,7 +104,7 @@ export const spec = { const bidResponses = []; // map responses to requests - _each(bidRequest.validBidRequests, function (req) { + utils._each(bidRequest.validBidRequests, function (req) { const bidResponse = {}; if (!serverResponse.body) { @@ -168,7 +168,7 @@ export const spec = { bidResponse.mediaType = matchedResponse.mediaType; if (matchedResponse.adomain) { - deepSetValue(bidResponse, 'meta.advertiserDomains', Array.isArray(matchedResponse.adomain) ? matchedResponse.adomain : [matchedResponse.adomain]); + utils.deepSetValue(bidResponse, 'meta.advertiserDomains', Array.isArray(matchedResponse.adomain) ? matchedResponse.adomain : [matchedResponse.adomain]); } // check required parameters by matchedResponse.mediaType diff --git a/modules/brightMountainMediaBidAdapter.js b/modules/brightMountainMediaBidAdapter.js index d3ae1d9cf43..602e621632c 100644 --- a/modules/brightMountainMediaBidAdapter.js +++ b/modules/brightMountainMediaBidAdapter.js @@ -1,6 +1,6 @@ -import { generateUUID, deepAccess, logWarn, deepSetValue } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'bmtm'; @@ -38,7 +38,7 @@ export const spec = { }; validBidRequests.forEach((bid) => { - oRTBRequest['id'] = generateUUID(); + oRTBRequest['id'] = utils.generateUUID(); oRTBRequest['imp'] = [ { id: '1', @@ -52,7 +52,7 @@ export const spec = { }, ]; - if (deepAccess(bid, 'mediaTypes.banner')) { + if (utils.deepAccess(bid, 'mediaTypes.banner')) { if (bid.mediaTypes.banner.sizes) { size = bid.mediaTypes.banner.sizes[0]; } @@ -106,7 +106,7 @@ export const spec = { } if (!response || !bid || !bid.adm || !bid.price) { - logWarn(`Bidder ${spec.code} no valid bid`); + utils.logWarn(`Bidder ${spec.code} no valid bid`); return []; } @@ -117,7 +117,7 @@ export const spec = { width: bid.w, height: bid.h, creativeId: bid.crid, - mediaType: deepAccess(bidRequest, 'mediaTypes.banner') ? BANNER : VIDEO, + mediaType: utils.deepAccess(bidRequest, 'mediaTypes.banner') ? BANNER : VIDEO, ttl: 3000, netRevenue: true, meta: { @@ -157,12 +157,12 @@ function buildSite(bidderRequest) { }; if (bidderRequest && bidderRequest.refererInfo) { - deepSetValue( + utils.deepSetValue( site, 'page', bidderRequest.refererInfo.referer.href ? bidderRequest.refererInfo.referer.href : '', ); - deepSetValue( + utils.deepSetValue( site, 'ref', bidderRequest.refererInfo.referer ? bidderRequest.refererInfo.referer : '', @@ -189,12 +189,12 @@ function buildRegs(bidderRequest) { }; if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue( + utils.deepSetValue( regs, 'ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0, ); - deepSetValue( + utils.deepSetValue( regs, 'ext.gdprConsentString', bidderRequest.gdprConsent.consentString || 'ALL', @@ -202,7 +202,7 @@ function buildRegs(bidderRequest) { } if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(regs, + utils.deepSetValue(regs, 'ext.us_privacy', bidderRequest.uspConsent); } diff --git a/modules/brightcomBidAdapter.js b/modules/brightcomBidAdapter.js index 4895f303973..8299a2331cb 100644 --- a/modules/brightcomBidAdapter.js +++ b/modules/brightcomBidAdapter.js @@ -1,4 +1,4 @@ -import { getBidIdParameter, _each, isArray, getWindowTop, getUniqueIdentifierStr, parseUrl, deepSetValue, logError, logWarn, createTrackPixelHtml, getWindowSelf, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -22,17 +22,17 @@ function buildRequests(bidReqs, bidderRequest) { referrer = bidderRequest.refererInfo.referer; } const brightcomImps = []; - const publisherId = getBidIdParameter('publisherId', bidReqs[0].params); - _each(bidReqs, function (bid) { + const publisherId = utils.getBidIdParameter('publisherId', bidReqs[0].params); + utils._each(bidReqs, function (bid) { let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes; - bidSizes = ((isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes]); - bidSizes = bidSizes.filter(size => isArray(size)); + bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]); + bidSizes = bidSizes.filter(size => utils.isArray(size)); const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})); const element = document.getElementById(bid.adUnitCode); const minSize = _getMinSize(processedSizes); const viewabilityAmount = _isViewabilityMeasurable(element) - ? _getViewability(element, getWindowTop(), minSize) + ? _getViewability(element, utils.getWindowTop(), minSize) : 'na'; const viewabilityAmountRounded = isNaN(viewabilityAmount) ? viewabilityAmount : Math.round(viewabilityAmount); @@ -53,10 +53,10 @@ function buildRequests(bidReqs, bidderRequest) { brightcomImps.push(imp); }); const brightcomBidReq = { - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: brightcomImps, site: { - domain: parseUrl(referrer).host, + domain: utils.parseUrl(referrer).host, page: referrer, publisher: { id: publisherId @@ -71,8 +71,8 @@ function buildRequests(bidReqs, bidderRequest) { }; if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(brightcomBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); - deepSetValue(brightcomBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(brightcomBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); + utils.deepSetValue(brightcomBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } return { @@ -82,7 +82,7 @@ function buildRequests(bidReqs, bidderRequest) { options: {contentType: 'text/plain', withCredentials: false} }; } catch (e) { - logError(e, {bidReqs, bidderRequest}); + utils.logError(e, {bidReqs, bidderRequest}); } } @@ -100,7 +100,7 @@ function isBidRequestValid(bid) { function interpretResponse(serverResponse) { if (!serverResponse.body || typeof serverResponse.body != 'object') { - logWarn('Brightcom server returned empty/non-json response: ' + JSON.stringify(serverResponse.body)); + utils.logWarn('Brightcom server returned empty/non-json response: ' + JSON.stringify(serverResponse.body)); return []; } const { body: {id, seatbid} } = serverResponse; @@ -131,7 +131,7 @@ function interpretResponse(serverResponse) { } return brightcomBidResponses; } catch (e) { - logError(e, {id, seatbid}); + utils.logError(e, {id, seatbid}); } } @@ -155,7 +155,7 @@ function _getDeviceType() { function _getAdMarkup(bid) { let adm = bid.adm; if ('nurl' in bid) { - adm += createTrackPixelHtml(bid.nurl); + adm += utils.createTrackPixelHtml(bid.nurl); } return adm; } @@ -165,14 +165,14 @@ function _isViewabilityMeasurable(element) { } function _getViewability(element, topWin, { w, h } = {}) { - return getWindowTop().document.visibilityState === 'visible' + return utils.getWindowTop().document.visibilityState === 'visible' ? _getPercentInView(element, topWin, { w, h }) : 0; } function _isIframe() { try { - return getWindowSelf() !== getWindowTop(); + return utils.getWindowSelf() !== utils.getWindowTop(); } catch (e) { return true; } @@ -252,7 +252,7 @@ function _getPercentInView(element, topWin, { w, h } = {}) { } function _getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return bid.params.bidFloor ? bid.params.bidFloor : null; } @@ -261,7 +261,7 @@ function _getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/britepoolIdSystem.js b/modules/britepoolIdSystem.js index 2316fbb732d..3bf416957d2 100644 --- a/modules/britepoolIdSystem.js +++ b/modules/britepoolIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { isEmpty, triggerPixel, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js'; const PIXEL = 'https://px.britepool.com/new?partner_id=t'; @@ -47,14 +47,14 @@ export const britepoolIdSubmodule = { }; } } - if (isEmpty(params)) { - triggerPixel(PIXEL); + if (utils.isEmpty(params)) { + utils.triggerPixel(PIXEL); } // Return for async operation return { callback: function(callback) { if (errors.length > 0) { - errors.forEach(error => logError(error)); + errors.forEach(error => utils.logError(error)); callback(); return; } @@ -65,7 +65,7 @@ export const britepoolIdSubmodule = { callback(britepoolIdSubmodule.normalizeValue(response)); }); } catch (error) { - if (error !== '') logError(error); + if (error !== '') utils.logError(error); callback(); } } else { @@ -75,7 +75,7 @@ export const britepoolIdSubmodule = { callback(responseObj ? { primaryBPID: responseObj.primaryBPID } : null); }, error: error => { - if (error !== '') logError(error); + if (error !== '') utils.logError(error); callback(); } }, JSON.stringify(params), { customHeaders: headers, contentType: 'application/json', method: 'POST', withCredentials: true }); @@ -132,7 +132,7 @@ export const britepoolIdSubmodule = { try { valueObj = JSON.parse(value); } catch (error) { - logError(error); + utils.logError(error); } } return valueObj; diff --git a/modules/browsiRtdProvider.js b/modules/browsiRtdProvider.js index a1943afda8d..4ee338e94cc 100644 --- a/modules/browsiRtdProvider.js +++ b/modules/browsiRtdProvider.js @@ -15,27 +15,21 @@ * @property {?string} keyName */ -import { deepClone, logError, isGptPubadsDefined, isNumber, isFn, deepSetValue } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {submodule} from '../src/hook.js'; import {ajaxBuilder} from '../src/ajax.js'; import {loadExternalScript} from '../src/adloader.js'; import {getStorageManager} from '../src/storageManager.js'; import find from 'core-js-pure/features/array/find.js'; -import {getGlobal} from '../src/prebidGlobal.js'; -import includes from 'core-js-pure/features/array/includes.js'; const storage = getStorageManager(); /** @type {ModuleParams} */ let _moduleParams = {}; /** @type {null|Object} */ -let _browsiData = null; +let _predictionsData = null; /** @type {string} */ const DEF_KEYNAME = 'browsiViewability'; -/** @type {null | function} */ -let _dataReadyCallback = null; -/** @type {null|Object} */ -let _ic = {}; /** * add browsi script to page @@ -49,7 +43,7 @@ export function addBrowsiTag(data) { script.setAttribute('prebidbpt', 'true'); script.setAttribute('id', 'browsi-tag'); script.setAttribute('src', data.u); - script.prebidData = deepClone(data); + script.prebidData = utils.deepClone(data); if (_moduleParams.keyName) { script.prebidData.kn = _moduleParams.keyName; } @@ -67,7 +61,7 @@ export function collectData() { try { browsiData = storage.getDataFromLocalStorage('__brtd'); } catch (e) { - logError('unable to parse __brtd'); + utils.logError('unable to parse __brtd'); } let predictorData = { @@ -84,49 +78,29 @@ export function collectData() { getPredictionsFromServer(`//${_moduleParams.url}/prebid?${toUrlParams(predictorData)}`); } -/** - * wait for data from server - * call callback when data is ready - * @param {function} callback - */ -function waitForData(callback) { - if (_browsiData) { - _dataReadyCallback = null; - callback(_browsiData); - } else { - _dataReadyCallback = callback; - } -} - export function setData(data) { - _browsiData = data; - if (isFn(_dataReadyCallback)) { - _dataReadyCallback(_browsiData); - _dataReadyCallback = null; - } + _predictionsData = data; } -function getRTD(auc) { +function sendDataToModule(adUnitsCodes) { try { - const _bp = (_browsiData && _browsiData.p) || {}; - return auc.reduce((rp, uc) => { - _ic[uc] = _ic[uc] || 0; - const _c = _ic[uc]; - if (!uc) { + const _predictions = (_predictionsData && _predictionsData.p) || {}; + return adUnitsCodes.reduce((rp, adUnitCode) => { + if (!adUnitCode) { return rp } - const adSlot = getSlotByCode(uc); - const identifier = adSlot ? getMacroId(_browsiData['pmd'], adSlot) : uc; - const _pd = _bp[identifier]; - rp[uc] = getKVObject(-1); - if (!_pd) { + const adSlot = getSlotByCode(adUnitCode); + const identifier = adSlot ? getMacroId(_predictionsData['pmd'], adSlot) : adUnitCode; + const predictionData = _predictions[identifier]; + rp[adUnitCode] = getKVObject(-1, _predictionsData['kn']); + if (!predictionData) { return rp } - if (_pd.ps) { - if (!isIdMatchingAdUnit(adSlot, _pd.w)) { + if (predictionData.p) { + if (!isIdMatchingAdUnit(adSlot, predictionData.w)) { return rp; } - rp[uc] = getKVObject(getCurrentData(_pd.ps, _c)); + rp[adUnitCode] = getKVObject(predictionData.p, _predictionsData.kn); } return rp; }, {}); @@ -135,37 +109,12 @@ function getRTD(auc) { } } -/** - * get prediction - * return -1 if prediction not found - * @param {object} predictionObject - * @param {number} _c - * @return {number} - */ -export function getCurrentData(predictionObject, _c) { - if (!predictionObject || !isNumber(_c)) { - return -1; - } - if (isNumber(predictionObject[_c])) { - return predictionObject[_c]; - } - if (Object.keys(predictionObject).length > 1) { - while (_c > 0) { - _c--; - if (isNumber(predictionObject[_c])) { - return predictionObject[_c]; - } - } - } - return -1; -} - /** * get all slots on page * @return {Object[]} slot GoogleTag slots */ function getAllSlots() { - return isGptPubadsDefined() && window.googletag.pubads().getSlots(); + return utils.isGptPubadsDefined() && window.googletag.pubads().getSlots(); } /** * get prediction and return valid object for key value set @@ -173,16 +122,12 @@ function getAllSlots() { * @param {string?} keyName * @return {Object} key:value */ -function getKVObject(p) { +function getKVObject(p, keyName) { const prValue = p < 0 ? 'NA' : (Math.floor(p * 10) / 10).toFixed(2); let prObject = {}; - prObject[getKey()] = prValue.toString(); + prObject[((_moduleParams['keyName'] || keyName || DEF_KEYNAME).toString())] = prValue.toString(); return prObject; } - -function getKey() { - return ((_moduleParams['keyName'] || (_browsiData && _browsiData['kn']) || DEF_KEYNAME).toString()) -} /** * check if placement id matches one of given ad units * @param {Object} slot google slot @@ -224,7 +169,7 @@ export function getMacroId(macro, slot) { }); return macroResult; } catch (e) { - logError(`failed to evaluate: ${macro}`); + utils.logError(`failed to evaluate: ${macro}`); } } return slot.getSlotElementId(); @@ -266,7 +211,7 @@ function getPredictionsFromServer(url) { } addBrowsiTag(data); } catch (err) { - logError('unable to parse data'); + utils.logError('unable to parse data'); setData({}) } } else if (req.status === 204) { @@ -276,7 +221,7 @@ function getPredictionsFromServer(url) { }, error: function () { setData({}); - logError('unable to get prediction data'); + utils.logError('unable to get prediction data'); } } ); @@ -293,28 +238,6 @@ function toUrlParams(data) { .join('&'); } -function setBidRequestsData(bidObj, callback) { - let adUnitCodes = bidObj.adUnitCodes; - let adUnits = bidObj.adUnits || getGlobal().adUnits || []; - if (adUnitCodes) { - adUnits = adUnits.filter(au => includes(adUnitCodes, au.code)); - } else { - adUnitCodes = adUnits.map(au => au.code); - } - waitForData(() => { - const data = getRTD(adUnitCodes); - if (data) { - adUnits.forEach(adUnit => { - const adUnitCode = adUnit.code; - if (data[adUnitCode]) { - deepSetValue(adUnit, 'ortb2Imp.ext.data.browsi', {[getKey()]: data[adUnitCode][getKey()]}); - } - }); - } - callback(); - }) -} - /** @type {RtdSubmodule} */ export const browsiSubmodule = { /** @@ -327,27 +250,16 @@ export const browsiSubmodule = { * @function * @param {string[]} adUnitsCodes */ - getTargetingData: getTargetingData, + getTargetingData: sendDataToModule, init: init, - getBidRequestData: setBidRequestsData }; -function getTargetingData(uc) { - const targetingData = getRTD(uc); - uc.forEach(auc => { - if (isNumber(_ic[auc])) { - _ic[auc] = _ic[auc] + 1; - } - }); - return targetingData; -} - function init(moduleConfig) { _moduleParams = moduleConfig.params; if (_moduleParams && _moduleParams.siteKey && _moduleParams.pubKey && _moduleParams.url) { collectData(); } else { - logError('missing params for Browsi provider'); + utils.logError('missing params for Browsi provider'); } return true; } diff --git a/modules/bucksenseBidAdapter.js b/modules/bucksenseBidAdapter.js index fcf99179993..46d0dfe3590 100644 --- a/modules/bucksenseBidAdapter.js +++ b/modules/bucksenseBidAdapter.js @@ -1,6 +1,6 @@ -import { logInfo } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; const WHO = 'BKSHBID-005'; const BIDDER_CODE = 'bucksense'; @@ -17,7 +17,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - logInfo(WHO + ' isBidRequestValid() - INPUT bid:', bid); + utils.logInfo(WHO + ' isBidRequestValid() - INPUT bid:', bid); if (bid.bidder !== BIDDER_CODE || typeof bid.params === 'undefined') { return false; } @@ -34,7 +34,7 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { - logInfo(WHO + ' buildRequests() - INPUT validBidRequests:', validBidRequests, 'INPUT bidderRequest:', bidderRequest); + utils.logInfo(WHO + ' buildRequests() - INPUT validBidRequests:', validBidRequests, 'INPUT bidderRequest:', bidderRequest); let requests = []; const len = validBidRequests.length; for (let i = 0; i < len; i++) { @@ -64,7 +64,7 @@ export const spec = { data: sendData }); } - logInfo(WHO + ' buildRequests() - requests:', requests); + utils.logInfo(WHO + ' buildRequests() - requests:', requests); return requests; }, @@ -75,7 +75,7 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: function (serverResponse, request) { - logInfo(WHO + ' interpretResponse() - INPUT serverResponse:', serverResponse, 'INPUT request:', request); + utils.logInfo(WHO + ' interpretResponse() - INPUT serverResponse:', serverResponse, 'INPUT request:', request); const bidResponses = []; if (serverResponse.body) { @@ -93,12 +93,12 @@ export const spec = { var sAdomains = oResponse.adomains || []; if (request && sRequestID.length == 0) { - logInfo(WHO + ' interpretResponse() - use RequestID from Placments'); + utils.logInfo(WHO + ' interpretResponse() - use RequestID from Placments'); sRequestID = request.data.bid_id || ''; } if (request && request.data.params.hasOwnProperty('testcpm')) { - logInfo(WHO + ' interpretResponse() - use Test CPM '); + utils.logInfo(WHO + ' interpretResponse() - use Test CPM '); nCPM = request.data.params.testcpm; } @@ -118,9 +118,9 @@ export const spec = { }; bidResponses.push(bidResponse); } else { - logInfo(WHO + ' interpretResponse() - serverResponse not valid'); + utils.logInfo(WHO + ' interpretResponse() - serverResponse not valid'); } - logInfo(WHO + ' interpretResponse() - return', bidResponses); + utils.logInfo(WHO + ' interpretResponse() - return', bidResponses); return bidResponses; }, diff --git a/modules/buzzoolaBidAdapter.js b/modules/buzzoolaBidAdapter.js index c6e27c94e04..db4863f7503 100644 --- a/modules/buzzoolaBidAdapter.js +++ b/modules/buzzoolaBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, deepClone } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; @@ -62,8 +62,8 @@ export const spec = { return response.map(bid => { let requestBid = requestBids[bid.requestId]; - let context = deepAccess(requestBid, 'mediaTypes.video.context'); - let validBid = deepClone(bid); + let context = utils.deepAccess(requestBid, 'mediaTypes.video.context'); + let validBid = utils.deepClone(bid); if (validBid.mediaType === VIDEO && context === OUTSTREAM) { let renderer = Renderer.install({ @@ -88,7 +88,7 @@ export const spec = { */ function setOutstreamRenderer(bid) { let adData = JSON.parse(bid.ad); - let unitSettings = deepAccess(adData, 'placement.unit_settings'); + let unitSettings = utils.deepAccess(adData, 'placement.unit_settings'); let extendedSettings = { width: '' + bid.width, height: '' + bid.height, diff --git a/modules/byDataAnalyticsAdapter.js b/modules/byDataAnalyticsAdapter.js deleted file mode 100644 index ef6e1a503ee..00000000000 --- a/modules/byDataAnalyticsAdapter.js +++ /dev/null @@ -1,311 +0,0 @@ -import { deepClone, logInfo, logError } from '../src/utils.js'; -import Base64 from 'crypto-js/enc-base64'; -import hmacSHA512 from 'crypto-js/hmac-sha512'; -import enc from 'crypto-js/enc-utf8'; -import adapter from '../src/AnalyticsAdapter.js'; -import CONSTANTS from '../src/constants.json'; -import adapterManager from '../src/adapterManager.js'; -import { ajax } from '../src/ajax.js'; - -const secretKey = 'bydata@123456'; -const { EVENTS: { NO_BID, BID_TIMEOUT, AUCTION_END } } = CONSTANTS; -const DEFAULT_EVENT_URL = 'https://pbjs-stream.bydata.com/topics/prebid'; -const analyticsType = 'endpoint'; -var payload = {}; -var bdNbTo = { 'to': [], 'nb': [] }; -let initOptions = {}; - -function onBidTimeout(t) { - if (payload['visitor_data'] && t && t.length > 0) { - bdNbTo['to'] = t; - } -} - -function onNoBidData(t) { - if (payload['visitor_data'] && t) { - bdNbTo['nb'].push(t); - } -} - -function onAuctionEnd(t) { - _logInfo('onAuctionEnd', t); - const {isCorrectOption, logFrequency} = initOptions; - var value = Math.floor(Math.random() * 10000 + 1); - _logInfo(' value - frequency ', (value + '-' + logFrequency)); - setTimeout(() => { - if (isCorrectOption && value < logFrequency) { - ascAdapter.dataProcess(t); - addKeyForPrebidWinningAndWinningsBids(); - ascAdapter.sendPayload(); - } - }, 500); -} - -const ascAdapter = Object.assign(adapter({ url: DEFAULT_EVENT_URL, analyticsType: analyticsType }), { - track({ eventType, args }) { - switch (eventType) { - case NO_BID: - onNoBidData(args); - break; - case BID_TIMEOUT: - onBidTimeout(args); - break; - case AUCTION_END: - onAuctionEnd(args); - break; - default: - break; - } - } -}); - -// save the base class function -ascAdapter.originEnableAnalytics = ascAdapter.enableAnalytics; -// override enableAnalytics so we can get access to the config passed in from the page -ascAdapter.enableAnalytics = function(config) { - if (this.initConfig(config)) { - _logInfo('initiated:', initOptions); - initOptions.isCorrectOption && ascAdapter.getVisitorData(); - ascAdapter.originEnableAnalytics(config); - } -}; - -ascAdapter.initConfig = function (config) { - let isCorrectOption = true; - initOptions = {}; - _logInfo('initConfig', config); - initOptions.options = deepClone(config.options); - initOptions.clientId = initOptions.options.clientId || null; - initOptions.logFrequency = initOptions.options.logFrequency; - if (!initOptions.clientId) { - _logError('"options.clientId" should not empty!!'); - isCorrectOption = false; - } - initOptions.isCorrectOption = isCorrectOption; - this.initOptions = initOptions; - return isCorrectOption; -}; - -ascAdapter.getVisitorData = function(data = {}) { - var ua = data.userId ? data : {}; - var module = { - options: [], - header: [window.navigator.platform, window.navigator.userAgent, window.navigator.appVersion, window.navigator.vendor, window.opera], - dataos: [ - { name: 'Windows Phone', value: 'Windows Phone', version: 'OS' }, - { name: 'Windows', value: 'Win', version: 'NT' }, - { name: 'iPhone', value: 'iPhone', version: 'OS' }, - { name: 'iPad', value: 'iPad', version: 'OS' }, - { name: 'Kindle', value: 'Silk', version: 'Silk' }, - { name: 'Android', value: 'Android', version: 'Android' }, - { name: 'PlayBook', value: 'PlayBook', version: 'OS' }, - { name: 'BlackBerry', value: 'BlackBerry', version: '/' }, - { name: 'Macintosh', value: 'Mac', version: 'OS X' }, - { name: 'Linux', value: 'Linux', version: 'rv' }, - { name: 'Palm', value: 'Palm', version: 'PalmOS' } - ], - databrowser: [ - { name: 'Chrome', value: 'Chrome', version: 'Chrome' }, - { name: 'Firefox', value: 'Firefox', version: 'Firefox' }, - { name: 'Safari', value: 'Safari', version: 'Version' }, - { name: 'Internet Explorer', value: 'MSIE', version: 'MSIE' }, - { name: 'Opera', value: 'Opera', version: 'Opera' }, - { name: 'BlackBerry', value: 'CLDC', version: 'CLDC' }, - { name: 'Mozilla', value: 'Mozilla', version: 'Mozilla' } - ], - init: function () { var agent = this.header.join(' '); var os = this.matchItem(agent, this.dataos); var browser = this.matchItem(agent, this.databrowser); return { os: os, browser: browser }; }, - matchItem: function (string, data) { - var i = 0; var j = 0; var regex; var regexv; var match; var matches; var version; - for (i = 0; i < data.length; i += 1) { - regex = new RegExp(data[i].value, 'i'); - match = regex.test(string); - if (match) { - regexv = new RegExp(data[i].version + '[- /:;]([\\d._]+)', 'i'); - matches = string.match(regexv); - version = ''; - if (matches) { if (matches[1]) { matches = matches[1]; } } - if (matches) { - matches = matches.split(/[._]+/); - for (j = 0; j < matches.length; j += 1) { - if (j === 0) { - version += matches[j] + '.'; - } else { - version += matches[j]; - } - } - } else { - version = '0'; - } - return { - name: data[i].name, - version: parseFloat(version) - }; - } - } - return { name: 'unknown', version: 0 }; - } - }; - - function generateUid() { - try { - var buffer = new Uint8Array(16); - crypto.getRandomValues(buffer); - buffer[6] = (buffer[6] & ~176) | 64; - buffer[8] = (buffer[8] & ~64) | 128; - var hex = Array.prototype.map.call(new Uint8Array(buffer), function(x) { - return ('00' + x.toString(16)).slice(-2); - }).join(''); - return hex.slice(0, 5) + '-' + hex.slice(5, 9) + '-' + hex.slice(9, 13) + '-' + hex.slice(13, 18); - } catch (e) { - return ''; - } - } - function base64url(source) { - var encodedSource = Base64.stringify(source); - encodedSource = encodedSource.replace(/=+$/, ''); - encodedSource = encodedSource.replace(/\+/g, '-'); - encodedSource = encodedSource.replace(/\//g, '_'); - return encodedSource; - } - function getJWToken(data) { - var header = { - 'alg': 'HS256', - 'typ': 'JWT' - }; - var stringifiedHeader = enc.parse(JSON.stringify(header)); - var encodedHeader = base64url(stringifiedHeader); - var stringifiedData = enc.parse(JSON.stringify(data)); - var encodedData = base64url(stringifiedData); - var token = encodedHeader + '.' + encodedData; - var signature = hmacSHA512(token, secretKey); - signature = base64url(signature); - var signedToken = token + '.' + signature; - return signedToken; - } - const {clientId} = initOptions; - var userId = window.localStorage.getItem('userId'); - if (!userId) { - userId = generateUid(); - window.localStorage.setItem('userId', userId); - } - var screenSize = {width: window.screen.width, height: window.screen.height}; - var deviceType = window.navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i) ? 'Mobile' : 'Desktop'; - var e = module.init(); - if (!ua['userId']) { - ua['userId'] = userId; - ua['client_id'] = clientId; - ua['plateform_name'] = e.os.name; - ua['os_version'] = e.os.version; - ua['browser_name'] = e.browser.name; - ua['browser_version'] = e.browser.version; - ua['screen_size'] = screenSize; - ua['device_type'] = deviceType; - ua['time_zone'] = window.Intl.DateTimeFormat().resolvedOptions().timeZone; - } - var signedToken = getJWToken(ua); - payload['visitor_data'] = signedToken; - return signedToken; -} - -ascAdapter.dataProcess = function(t) { - payload['auction_id'] = t.auctionId; - payload['auction_start'] = t.timestamp; - payload['auctionData'] = []; - var bidderRequestsData = []; var bidsReceivedData = []; - t.bidderRequests && t.bidderRequests.forEach(bidReq => { - var pObj = {}; pObj['bids'] = []; - bidReq.bids.forEach(bid => { - var data = {}; - data['adUnitCode'] = bid.adUnitCode; - data['sizes'] = bid.sizes; - data['bidder'] = bid.bidder; - data['bidId'] = bid.bidId; - data['mediaTypes'] = []; - var mt = bid.mediaTypes.banner ? 'display' : 'video'; - data['mediaTypes'].push(mt); - pObj['bids'].push(data); - }) - bidderRequestsData.push(pObj); - }); - t.bidsReceived && t.bidsReceived.forEach(bid => { - const {requestId, bidder, width, height, cpm, currency, timeToRespond, adUnitCode} = bid; - bidsReceivedData.push({requestId, bidder, width, height, cpm, currency, timeToRespond, adUnitCode}); - }); - bidderRequestsData.length > 0 && bidderRequestsData.forEach(bdObj => { - var bdsArray = bdObj['bids']; - bdsArray.forEach(bid => { - const {adUnitCode, sizes, bidder, bidId, mediaTypes} = bid; - sizes.forEach(size => { - var sstr = size[0] + 'x' + size[1] - payload['auctionData'].push({adUnit: adUnitCode, size: sstr, media_type: mediaTypes[0], bids_bidder: bidder, bids_bid_id: bidId}); - }); - }); - }); - bidsReceivedData.length > 0 && bidsReceivedData.forEach(bdRecived => { - const {requestId, bidder, width, height, cpm, currency, timeToRespond} = bdRecived; - payload['auctionData'].forEach(rwData => { - if (rwData['bids_bid_id'] === requestId && rwData['size'] === width + 'x' + height) { - rwData['br_request_id'] = requestId; rwData['br_bidder'] = bidder; rwData['br_pb_mg'] = cpm; - rwData['br_currency'] = currency; rwData['br_time_to_respond'] = timeToRespond; rwData['br_size'] = width + 'x' + height; - } - }) - }); - payload['auctionData'] && payload['auctionData'].length > 0 && payload['auctionData'].forEach(u => { - bdNbTo['to'].forEach(i => { - if (u.bids_bid_id === i.bidId) u.is_timeout = 1; - }); - bdNbTo['nb'].forEach(i => { - if (u.adUnit === i.adUnitCode && u.bids_bidder === i.bidder && u.bids_bid_id === i.bidId) { u.is_nobid = 1; } - }) - }); - return payload; -} - -ascAdapter.sendPayload = function () { - var obj = { 'records': [ { 'value': payload } ] }; - let strJSON = JSON.stringify(obj); - _logInfo(' sendPayload ', JSON.stringify(obj)); - ajax(DEFAULT_EVENT_URL, undefined, strJSON, { - contentType: 'application/vnd.kafka.json.v2+json', - method: 'POST', - withCredentials: true - }); -} - -function addKeyForPrebidWinningAndWinningsBids() { - var prebidWinningBids = $$PREBID_GLOBAL$$.getAllPrebidWinningBids(); - var winningBids = $$PREBID_GLOBAL$$.getAllWinningBids(); - prebidWinningBids && prebidWinningBids.length > 0 && prebidWinningBids.forEach(pbbid => { - payload['auctionData'] && payload['auctionData'].forEach(rwData => { - if (rwData['bids_bid_id'] === pbbid.requestId && rwData['br_size'] === pbbid.size) { - rwData['is_prebid_winning_bid'] = 1; - } - }); - }) - winningBids && winningBids.length > 0 && winningBids.forEach(wBid => { - payload['auctionData'] && payload['auctionData'].forEach(rwData => { - if (rwData['bids_bid_id'] === wBid.requestId && rwData['br_size'] === wBid.size) { - rwData['is_winning_bid'] = 1; - } - }); - }) -} - -adapterManager.registerAnalyticsAdapter({ - adapter: ascAdapter, - code: 'bydata' -}); - -function _logInfo(message, meta) { - logInfo(buildLogMessage(message), meta); -} - -function _logError(message) { - logError(buildLogMessage(message)); -} - -function buildLogMessage(message) { - return 'Bydata Prebid Analytics: ' + message; -} - -export default ascAdapter; diff --git a/modules/byDataAnalyticsAdapter.md b/modules/byDataAnalyticsAdapter.md deleted file mode 100644 index 84207d8b3a1..00000000000 --- a/modules/byDataAnalyticsAdapter.md +++ /dev/null @@ -1,34 +0,0 @@ -# Overview - -layout: Analytics Adapter -title: Ascendeum Pvt Ltd. (https://ascendeum.com/) -description: Bydata Analytics Adapter -modulecode: byDataAnalyticsAdapter -gdpr_supported: false (EU GDPR support) -usp_supported: false (US Privacy support) -coppa_supported: false (COPPA support) -prebid_member: false -gvl_id: (IAB Global Vendor List ID) -enable_download: false (in case you don't want users of the website to download your adapter) - -Module Name: Bydata Analytics Adapter -Module Type: Analytics Adapter -Maintainer: Ascendeum - -# Description - -Analytics adapter for https://ascendeum.com/. Contact engineering@ascendeum.com for information. - -# Test Parameters - -``` -{ - provider: 'bydata', - options : { - clientId: "ASCENDEUM_PROVIDED_CLIENT_ID", - logFrequency : 100, // Sample Rate Default - 1% - } -} -``` - - diff --git a/modules/ccxBidAdapter.js b/modules/ccxBidAdapter.js index 38bc99f1d83..2160e539040 100644 --- a/modules/ccxBidAdapter.js +++ b/modules/ccxBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, _each, logWarn, isEmpty } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { config } from '../src/config.js' import { getStorageManager } from '../src/storageManager.js'; @@ -20,7 +20,7 @@ function _getDeviceObj () { function _getSiteObj (bidderRequest) { let site = {} - let url = config.getConfig('pageUrl') || deepAccess(window, 'location.href'); + let url = config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); if (url.length > 0) { url = url.split('?')[0] } @@ -30,19 +30,19 @@ function _getSiteObj (bidderRequest) { } function _validateSizes (sizeObj, type) { - if (!isArray(sizeObj) || typeof sizeObj[0] === 'undefined') { + if (!utils.isArray(sizeObj) || typeof sizeObj[0] === 'undefined') { return false } - if (type === 'video' && (!isArray(sizeObj[0]) || sizeObj[0].length !== 2)) { + if (type === 'video' && (!utils.isArray(sizeObj[0]) || sizeObj[0].length !== 2)) { return false } let result = true if (type === 'banner') { - _each(sizeObj, function (size) { - if (!isArray(size) || (size.length !== 2)) { + utils._each(sizeObj, function (size) { + if (!utils.isArray(size) || (size.length !== 2)) { result = false } }) @@ -50,11 +50,11 @@ function _validateSizes (sizeObj, type) { } if (type === 'old') { - if (!isArray(sizeObj[0]) && sizeObj.length !== 2) { + if (!utils.isArray(sizeObj[0]) && sizeObj.length !== 2) { result = false - } else if (isArray(sizeObj[0])) { - _each(sizeObj, function (size) { - if (!isArray(size) || (size.length !== 2)) { + } else if (utils.isArray(sizeObj[0])) { + utils._each(sizeObj, function (size) { + if (!utils.isArray(size) || (size.length !== 2)) { result = false } }) @@ -70,22 +70,22 @@ function _buildBid (bid) { placement.id = bid.bidId placement.secure = 1 - let sizes = deepAccess(bid, 'mediaTypes.banner.sizes') || deepAccess(bid, 'mediaTypes.video.playerSize') || deepAccess(bid, 'sizes') + let sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || utils.deepAccess(bid, 'mediaTypes.video.playerSize') || utils.deepAccess(bid, 'sizes') - if (deepAccess(bid, 'mediaTypes.banner') || deepAccess(bid, 'mediaType') === 'banner' || (!deepAccess(bid, 'mediaTypes.video') && !deepAccess(bid, 'mediaType'))) { + if (utils.deepAccess(bid, 'mediaTypes.banner') || utils.deepAccess(bid, 'mediaType') === 'banner' || (!utils.deepAccess(bid, 'mediaTypes.video') && !utils.deepAccess(bid, 'mediaType'))) { placement.banner = {'format': []} - if (isArray(sizes[0])) { - _each(sizes, function (size) { + if (utils.isArray(sizes[0])) { + utils._each(sizes, function (size) { placement.banner.format.push({'w': size[0], 'h': size[1]}) }) } else { placement.banner.format.push({'w': sizes[0], 'h': sizes[1]}) } - } else if (deepAccess(bid, 'mediaTypes.video') || deepAccess(bid, 'mediaType') === 'video') { + } else if (utils.deepAccess(bid, 'mediaTypes.video') || utils.deepAccess(bid, 'mediaType') === 'video') { placement.video = {} if (typeof sizes !== 'undefined') { - if (isArray(sizes[0])) { + if (utils.isArray(sizes[0])) { placement.video.w = sizes[0][0] placement.video.h = sizes[0][1] } else { @@ -94,12 +94,12 @@ function _buildBid (bid) { } } - placement.video.protocols = deepAccess(bid, 'mediaTypes.video.protocols') || deepAccess(bid, 'params.video.protocols') || SUPPORTED_VIDEO_PROTOCOLS - placement.video.mimes = deepAccess(bid, 'mediaTypes.video.mimes') || deepAccess(bid, 'params.video.mimes') || SUPPORTED_VIDEO_MIMES - placement.video.playbackmethod = deepAccess(bid, 'mediaTypes.video.playbackmethod') || deepAccess(bid, 'params.video.playbackmethod') || SUPPORTED_VIDEO_PLAYBACK_METHODS - placement.video.skip = deepAccess(bid, 'mediaTypes.video.skip') || deepAccess(bid, 'params.video.skip') || 0 - if (placement.video.skip === 1 && (deepAccess(bid, 'mediaTypes.video.skipafter') || deepAccess(bid, 'params.video.skipafter'))) { - placement.video.skipafter = deepAccess(bid, 'mediaTypes.video.skipafter') || deepAccess(bid, 'params.video.skipafter') + placement.video.protocols = utils.deepAccess(bid, 'mediaTypes.video.protocols') || utils.deepAccess(bid, 'params.video.protocols') || SUPPORTED_VIDEO_PROTOCOLS + placement.video.mimes = utils.deepAccess(bid, 'mediaTypes.video.mimes') || utils.deepAccess(bid, 'params.video.mimes') || SUPPORTED_VIDEO_MIMES + placement.video.playbackmethod = utils.deepAccess(bid, 'mediaTypes.video.playbackmethod') || utils.deepAccess(bid, 'params.video.playbackmethod') || SUPPORTED_VIDEO_PLAYBACK_METHODS + placement.video.skip = utils.deepAccess(bid, 'mediaTypes.video.skip') || utils.deepAccess(bid, 'params.video.skip') || 0 + if (placement.video.skip === 1 && (utils.deepAccess(bid, 'mediaTypes.video.skipafter') || utils.deepAccess(bid, 'params.video.skipafter'))) { + placement.video.skipafter = utils.deepAccess(bid, 'mediaTypes.video.skipafter') || utils.deepAccess(bid, 'params.video.skipafter') } } @@ -131,7 +131,7 @@ function _buildResponse (bid, currency, ttl) { resp.ad = bid.adm } - if (deepAccess(bid, 'dealid')) { + if (utils.deepAccess(bid, 'dealid')) { resp.dealId = bid.dealid } @@ -143,30 +143,30 @@ export const spec = { supportedMediaTypes: ['banner', 'video'], isBidRequestValid: function (bid) { - if (!deepAccess(bid, 'params.placementId')) { - logWarn('placementId param is reqeuired.') + if (!utils.deepAccess(bid, 'params.placementId')) { + utils.logWarn('placementId param is reqeuired.') return false } - if (deepAccess(bid, 'mediaTypes.banner.sizes')) { + if (utils.deepAccess(bid, 'mediaTypes.banner.sizes')) { let isValid = _validateSizes(bid.mediaTypes.banner.sizes, 'banner') if (!isValid) { - logWarn('Bid sizes are invalid.') + utils.logWarn('Bid sizes are invalid.') } return isValid - } else if (deepAccess(bid, 'mediaTypes.video.playerSize')) { + } else if (utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { let isValid = _validateSizes(bid.mediaTypes.video.playerSize, 'video') if (!isValid) { - logWarn('Bid sizes are invalid.') + utils.logWarn('Bid sizes are invalid.') } return isValid - } else if (deepAccess(bid, 'sizes')) { + } else if (utils.deepAccess(bid, 'sizes')) { let isValid = _validateSizes(bid.sizes, 'old') if (!isValid) { - logWarn('Bid sizes are invalid.') + utils.logWarn('Bid sizes are invalid.') } return isValid } else { - logWarn('Bid sizes are required.') + utils.logWarn('Bid sizes are required.') return false } }, @@ -195,7 +195,7 @@ export const spec = { }; } - _each(validBidRequests, function (bid) { + utils._each(validBidRequests, function (bid) { requestBody.imp.push(_buildBid(bid)) }) // Return the server request @@ -210,9 +210,9 @@ export const spec = { const bidResponses = [] // response is not empty (HTTP 204) - if (!isEmpty(serverResponse.body)) { - _each(serverResponse.body.seatbid, function (seatbid) { - _each(seatbid.bid, function (bid) { + if (!utils.isEmpty(serverResponse.body)) { + utils._each(serverResponse.body.seatbid, function (seatbid) { + utils._each(seatbid.bid, function (bid) { bidResponses.push(_buildResponse(bid, serverResponse.body.cur, serverResponse.body.ext.ttl)) }) }) @@ -223,8 +223,8 @@ export const spec = { getUserSyncs: function (syncOptions, serverResponses) { const syncs = [] - if (deepAccess(serverResponses[0], 'body.ext.usersync') && !isEmpty(serverResponses[0].body.ext.usersync)) { - _each(serverResponses[0].body.ext.usersync, function (match) { + if (utils.deepAccess(serverResponses[0], 'body.ext.usersync') && !utils.isEmpty(serverResponses[0].body.ext.usersync)) { + utils._each(serverResponses[0].body.ext.usersync, function (match) { if ((syncOptions.iframeEnabled && match.type === 'iframe') || (syncOptions.pixelEnabled && match.type === 'image')) { syncs.push({ type: match.type, diff --git a/modules/cleanioRtdProvider.js b/modules/cleanioRtdProvider.js deleted file mode 100644 index b9fdcef768e..00000000000 --- a/modules/cleanioRtdProvider.js +++ /dev/null @@ -1,192 +0,0 @@ -/** - * This module adds clean.io provider to the real time data module - * The {@link module:modules/realTimeData} module is required - * The module will wrap bid responses markup in clean.io agent script for protection - * @module modules/cleanioRtdProvider - * @requires module:modules/realTimeData - */ - -import { submodule } from '../src/hook.js'; -import { logError, generateUUID, insertElement } from '../src/utils.js'; - -// ============================ MODULE STATE =============================== - -/** - * @type {function(): void} - * Page-wide initialization step / strategy - */ -let onModuleInit = () => {}; - -/** - * @type {function(Object): void} - * Bid response mutation step / strategy. - */ -let onBidResponse = () => {}; - -/** - * @type {number} - * 0 for unknown, 1 for preloaded, -1 for error. - */ -let preloadStatus = 0; - -// ============================ MODULE LOGIC =============================== - -/** - * Page initialization step which just preloads the script, to be available whenever we start processing the bids. - * @param {string} scriptURL The script URL to preload - */ -function pageInitStepPreloadScript(scriptURL) { - const linkElement = document.createElement('link'); - linkElement.rel = 'preload'; - linkElement.as = 'script'; - linkElement.href = scriptURL; - linkElement.onload = () => { preloadStatus = 1; }; - linkElement.onerror = () => { preloadStatus = -1; }; - insertElement(linkElement); -} - -/** - * Page initialization step which adds the protector script to the whole page. With that, there is no need wrapping bids, and the coverage is better. - * @param {string} scriptURL The script URL to add to the page for protection - */ -function pageInitStepProtectPage(scriptURL) { - const scriptElement = document.createElement('script'); - scriptElement.type = 'text/javascript'; - scriptElement.src = scriptURL; - insertElement(scriptElement); -} - -/** - * Bid processing step which alters the ad HTML to contain bid-specific information, which can be used to identify the creative later. - * @param {Object} bidResponse Bid response data - */ -function bidWrapStepAugmentHtml(bidResponse) { - bidResponse.ad = `\n${bidResponse.ad}`; -} - -/** - * Bid processing step which applies creative protection by wrapping the ad HTML. - * @param {string} scriptURL - * @param {number} requiredPreload - * @param {Object} bidResponse - */ -function bidWrapStepProtectByWrapping(scriptURL, requiredPreload, bidResponse) { - // Still prepend bid info, it's always helpful to have creative data in its payload - bidWrapStepAugmentHtml(bidResponse); - - // If preloading failed, or if configuration requires us to finish preloading - - // we should not process this bid any further - if (preloadStatus < requiredPreload) { - return; - } - - const sid = generateUUID(); - bidResponse.ad = ` - - - `; -} - -/** - * Custom error class to differentiate validation errors - */ -class ConfigError extends Error { } - -/** - * The function to be called upon module init. Depending on the passed config, initializes properly init/bid steps or throws ConfigError. - * @param {Object} config - */ -function readConfig(config) { - if (!config.params) { - throw new ConfigError('Missing config parameters for clean.io RTD module provider.'); - } - - if (typeof config.params.cdnUrl !== 'string' || !/^https?:\/\//.test(config.params.cdnUrl)) { - throw new ConfigError('Parameter "cdnUrl" is a required string parameter, which should start with "http(s)://".'); - } - - if (typeof config.params.protectionMode !== 'string') { - throw new ConfigError('Parameter "protectionMode" is a required string parameter.'); - } - - const scriptURL = config.params.cdnUrl; - - switch (config.params.protectionMode) { - case 'full': - onModuleInit = () => pageInitStepProtectPage(scriptURL); - onBidResponse = (bidResponse) => bidWrapStepAugmentHtml(bidResponse); - break; - - case 'bids': - onModuleInit = () => pageInitStepPreloadScript(scriptURL); - onBidResponse = (bidResponse) => bidWrapStepProtectByWrapping(scriptURL, 0, bidResponse); - break; - - case 'bids-nowait': - onModuleInit = () => pageInitStepPreloadScript(scriptURL); - onBidResponse = (bidResponse) => bidWrapStepProtectByWrapping(scriptURL, 1, bidResponse); - break; - - default: - throw new ConfigError('Parameter "protectionMode" must be one of "full" | "bids" | "bids-nowait".'); - } -} - -// ============================ MODULE REGISTRATION =============================== - -/** - * The function which performs submodule registration. - */ -function beforeInit() { - submodule('realTimeData', /** @type {RtdSubmodule} */ ({ - name: 'clean.io', - - init: (config, userConsent) => { - try { - readConfig(config); - onModuleInit(); - return true; - } catch (err) { - if (err instanceof ConfigError) { - logError(err.message); - } - return false; - } - }, - - onBidResponseEvent: (bidResponse, config, userConsent) => { - onBidResponse(bidResponse); - } - })); -} - -/** - * Exporting local (and otherwise encapsulated to this module) functions - * for testing purposes - */ -export const __TEST__ = { - pageInitStepPreloadScript, - pageInitStepProtectPage, - bidWrapStepAugmentHtml, - bidWrapStepProtectByWrapping, - ConfigError, - readConfig, - beforeInit, -} - -beforeInit(); diff --git a/modules/cleanioRtdProvider.md b/modules/cleanioRtdProvider.md deleted file mode 100644 index 7870a2719b6..00000000000 --- a/modules/cleanioRtdProvider.md +++ /dev/null @@ -1,59 +0,0 @@ -# Overview - -``` -Module Name: clean.io Rtd provider -Module Type: Rtd Provider -Maintainer: nick@clean.io -``` - -The clean.io Realtime module provides effective anti-malvertising solution for publishers, including, but not limited to, -blocking unwanted 0- and 1-click redirects, deceptive ads or those with malicious landing pages, and various types of affiliate fraud. - -Using this module requires prior agreement with [clean.io](https://clean.io) to obtain the necessary distribution key. - - -# Integration - -clean.io Realtime module can be built just like any other prebid module: - -``` -gulp build --modules=cleanioRtdProvider,... -``` - - -# Configuration - -When built into prebid.js, this module can be configured through the following `pbjs.setConfig` call: - -```javascript -pbjs.setConfig({ - realTimeData: { - dataProviders: [{ - name: 'clean.io', - params: { - cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', ///< Contact clean.io to get your own CDN URL - protectionMode: 'full', ///< Supported modes are 'full', 'bids' and 'bids-nowait', see below. - } - }] - } -}); -``` - - -## Configuration parameters - -{: .table .table-bordered .table-striped } -| Name | Type | Scope | Description | -| :------------ | :------------ | :------------ |:------------ | -| ``cdnUrl`` | ``string`` | Required | CDN URL of the script, which is to be used for protection. | -| ``protectionMode`` | ``'full' \| 'bids' \| 'bids-nowait'`` | Required | Integration mode. Please refer to the "Integration modes" section for details. | - - -## Integration modes - -{: .table .table-bordered .table-striped } -| Integration Mode | Parameter Value | Description | -| :------------ | :------------ | :------------ | -| Full page protection | ``'full'`` | Preferred mode. The module will add the protector agent script directly to the page, and it will protect all placements. This mode will make the most out of various behavioral detection mechanisms, and will also prevent typical malicious behaviors. Please note that in this mode, depending on Prebid library naming, Chrome may mistakenly tag non-ad-related content as ads: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/ad_tagging.md. | -| Bids-only protection | ``'bids'`` | The module will protect specific bid responses, more specifically, the HTML representing ad payload, by wrapping it into the agent script. Please note that in this mode, ads delivered directly, outside of Prebid integration, will not be protected, since the module can only access the ads coming through Prebid. | -| Bids-only protection with no delay on bid rendering | ``'bids-nowait'`` | Same as above, but in this mode, the script will also *not* wrap those bid responses, which arrived prior to successful preloading of agent script. | diff --git a/modules/cleanmedianetBidAdapter.js b/modules/cleanmedianetBidAdapter.js index 3c2d3c51bf5..7b36117d404 100644 --- a/modules/cleanmedianetBidAdapter.js +++ b/modules/cleanmedianetBidAdapter.js @@ -1,4 +1,4 @@ -import { getDNT, inIframe, isArray, isNumber, logError, deepAccess, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {Renderer} from '../src/Renderer.js'; @@ -76,7 +76,7 @@ export const spec = { }, device: { ua: navigator.userAgent, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, h: screen.height, w: screen.width, language: navigator.language @@ -129,7 +129,7 @@ export const spec = { w: sizes.length ? sizes[0][0] : 300, h: sizes.length ? sizes[0][1] : 250, pos: params.pos || 0, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 } }); rtbBidRequest.imp.push(bannerImp); @@ -147,10 +147,10 @@ export const spec = { }; let playerSize = mediaTypes.video.playerSize || sizes; - if (isArray(playerSize[0])) { + if (utils.isArray(playerSize[0])) { videoImp.video.w = playerSize[0][0]; videoImp.video.h = playerSize[0][1]; - } else if (isNumber(playerSize[0])) { + } else if (utils.isNumber(playerSize[0])) { videoImp.video.w = playerSize[0]; videoImp.video.h = playerSize[1]; } else { @@ -179,7 +179,7 @@ export const spec = { interpretResponse: function (serverResponse, bidRequest) { const response = serverResponse && serverResponse.body; if (!response) { - logError('empty response'); + utils.logError('empty response'); return []; } @@ -203,7 +203,7 @@ export const spec = { }; if ( - deepAccess( + utils.deepAccess( bidRequest.bidRequest, 'mediaTypes.' + outBid.mediaType ) @@ -211,7 +211,7 @@ export const spec = { if (outBid.mediaType === BANNER) { outBids.push(Object.assign({}, outBid, {ad: bid.adm})); } else if (outBid.mediaType === VIDEO) { - const context = deepAccess( + const context = utils.deepAccess( bidRequest.bidRequest, 'mediaTypes.video.context' ); @@ -287,7 +287,7 @@ function newRenderer(bidRequest, bid, rendererOptions = {}) { try { renderer.setRender(renderOutstream); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; } diff --git a/modules/clickforceBidAdapter.js b/modules/clickforceBidAdapter.js index eceb4934b04..2e758c509f7 100644 --- a/modules/clickforceBidAdapter.js +++ b/modules/clickforceBidAdapter.js @@ -1,4 +1,4 @@ -import { _each } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; const BIDDER_CODE = 'clickforce'; @@ -25,7 +25,7 @@ export const spec = { */ buildRequests: function(validBidRequests) { const bidParams = []; - _each(validBidRequests, function(bid) { + utils._each(validBidRequests, function(bid) { bidParams.push({ z: bid.params.zone, bidId: bid.bidId @@ -51,12 +51,12 @@ export const spec = { const bidRequestList = []; if (typeof bidRequest != 'undefined') { - _each(bidRequest.validBidRequests, function(req) { + utils._each(bidRequest.validBidRequests, function(req) { bidRequestList[req.bidId] = req; }); } - _each(serverResponse.body, function(response) { + utils._each(serverResponse.body, function(response) { if (response.requestId != null) { // native ad size if (response.width == 3) { diff --git a/modules/codefuelBidAdapter.js b/modules/codefuelBidAdapter.js deleted file mode 100644 index b9da86ac24e..00000000000 --- a/modules/codefuelBidAdapter.js +++ /dev/null @@ -1,181 +0,0 @@ -import { deepAccess, isArray } from '../src/utils.js'; -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { BANNER } from '../src/mediaTypes.js'; -const BIDDER_CODE = 'codefuel'; -const CURRENCY = 'USD'; - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [ BANNER ], - aliases: ['ex'], // short code - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function(bid) { - if (bid.nativeParams) { - return false; - } - return !!(bid.params.placementId || (bid.params.member && bid.params.invCode)); - }, - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function(validBidRequests, bidderRequest) { - const page = bidderRequest.refererInfo.referer; - const domain = getDomainFromURL(page) - const ua = navigator.userAgent; - const devicetype = getDeviceType() - const publisher = setOnAny(validBidRequests, 'params.publisher'); - const cur = CURRENCY; - const endpointUrl = 'https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid' - const timeout = bidderRequest.timeout; - - validBidRequests.forEach(bid => bid.netRevenue = 'net'); - - const imps = validBidRequests.map((bid, idx) => { - const imp = { - id: idx + 1 + '' - } - - if (bid.params.tagid) { - imp.tagid = bid.params.tagid - } - - if (bid.sizes) { - imp.banner = { - format: transformSizes(bid.sizes) - } - } - - return imp; - }); - - const request = { - id: bidderRequest.auctionId, - site: { page, domain, publisher }, - device: { ua, devicetype }, - source: { fd: 1 }, - cur: [cur], - tmax: timeout, - imp: imps, - }; - - return { - method: 'POST', - url: endpointUrl, - data: request, - bids: validBidRequests, - options: { - withCredentials: false - } - }; - }, - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: (serverResponse, { bids }) => { - if (!serverResponse.body) { - return []; - } - const { seatbid, cur } = serverResponse.body; - - const bidResponses = flatten(seatbid.map(seat => seat.bid)).reduce((result, bid) => { - result[bid.impid - 1] = bid; - return result; - }, []); - - return bids.map((bid, id) => { - const bidResponse = bidResponses[id]; - if (bidResponse) { - const bidObject = { - requestId: bid.bidId, - cpm: bidResponse.price, - creativeId: bidResponse.crid, - ttl: 360, - netRevenue: true, - currency: cur, - mediaType: BANNER, - ad: bidResponse.adm, - width: bidResponse.w, - height: bidResponse.h, - meta: { advertiserDomains: bid.adomain ? bid.adomain : [] } - }; - return bidObject; - } - }).filter(Boolean); - }, - - /** - * Register the user sync pixels which should be dropped after the auction. - * - * @param {SyncOptions} syncOptions Which user syncs are allowed? - * @param {ServerResponse[]} serverResponses List of server's responses. - * @return {UserSync[]} The user syncs which should be dropped. - */ - getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { - return []; - } - -} -registerBidder(spec); - -function getDomainFromURL(url) { - let anchor = document.createElement('a'); - anchor.href = url; - return anchor.hostname; -} - -function getDeviceType() { - if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()))) { - return 5; // 'tablet' - } - if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(navigator.userAgent.toLowerCase()))) { - return 4; // 'mobile' - } - return 2; // 'desktop' -} - -function setOnAny(collection, key) { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); - if (result) { - return result; - } - } -} - -function flatten(arr) { - return [].concat(...arr); -} - -/* Turn bid request sizes into ut-compatible format */ -function transformSizes(requestSizes) { - if (!isArray(requestSizes)) { - return []; - } - - if (requestSizes.length === 2 && !isArray(requestSizes[0])) { - return [{ - w: parseInt(requestSizes[0], 10), - h: parseInt(requestSizes[1], 10) - }]; - } else if (isArray(requestSizes[0])) { - return requestSizes.map(item => - ({ - w: parseInt(item[0], 10), - h: parseInt(item[1], 10) - }) - ); - } - - return []; -} diff --git a/modules/codefuelBidAdapter.md b/modules/codefuelBidAdapter.md deleted file mode 100644 index 4e1a0dd6409..00000000000 --- a/modules/codefuelBidAdapter.md +++ /dev/null @@ -1,111 +0,0 @@ -# Overview - -``` -Module Name: Codefuel Adapter -Module Type: Bidder Adapter -Maintainer: hayimm@codefuel.com -``` - -# Description - -Module that connects to Codefuel bidder to fetch bids. -Display format is supported but not native format. Using OpenRTB standard. - -# Configuration - -## Bidder and usersync URLs - -The Codefuel adapter does not work without setting the correct bidder. -You will receive the URLs when contacting us. - -``` -pbjs.setConfig({ - codefuel: { - bidderUrl: 'https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid', - usersyncUrl: 'https://usersync-url.com' - } -}); -``` - - -# Test Native Parameters -``` - var adUnits = [ - code: '/19968336/prebid_native_example_1', - mediaTypes: { - native: { - image: { - required: false, - sizes: [100, 50] - }, - title: { - required: false, - len: 140 - }, - sponsoredBy: { - required: false - }, - clickUrl: { - required: false - }, - body: { - required: false - }, - icon: { - required: false, - sizes: [50, 50] - } - } - }, - bids: [{ - bidder: 'codefuel', - params: { - publisher: { - id: '2706', // required - name: 'Publishers Name', - domain: 'publisher.com' - }, - tagid: 'tag-id', - bcat: ['IAB1-1'], - badv: ['example.com'] - } - }] - ]; - - pbjs.setConfig({ - codefuel: { - bidderUrl: 'https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid' - } - }); -``` - -# Test Display Parameters -``` - var adUnits = [ - code: '/19968336/prebid_display_example_1', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [{ - bidder: 'codefuel', - params: { - publisher: { - id: '2706', // required - name: 'Publishers Name', - domain: 'publisher.com' - }, - tagid: 'tag-id', - bcat: ['IAB1-1'], - badv: ['example.com'] - }, - }] - ]; - - pbjs.setConfig({ - codefuel: { - bidderUrl: 'https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid' - } - }); -``` diff --git a/modules/cointrafficBidAdapter.js b/modules/cointrafficBidAdapter.js index e3d3c65a4f0..a6241980e06 100644 --- a/modules/cointrafficBidAdapter.js +++ b/modules/cointrafficBidAdapter.js @@ -1,4 +1,4 @@ -import { parseSizesInput, logError, isEmpty } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js' import { config } from '../src/config.js' @@ -34,14 +34,14 @@ export const spec = { */ buildRequests: function (validBidRequests, bidderRequest) { return validBidRequests.map(bidRequest => { - const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes); + const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes); const currency = config.getConfig(`currency.bidderCurrencyDefault.${BIDDER_CODE}`) || config.getConfig('currency.adServerCurrency') || DEFAULT_CURRENCY; if (ALLOWED_CURRENCIES.indexOf(currency) === -1) { - logError('Currency is not supported - ' + currency); + utils.logError('Currency is not supported - ' + currency); return; } @@ -72,7 +72,7 @@ export const spec = { const bidResponses = []; const response = serverResponse.body; - if (isEmpty(response)) { + if (utils.isEmpty(response)) { return bidResponses; } diff --git a/modules/coinzillaBidAdapter.js b/modules/coinzillaBidAdapter.js index cd087daa8cb..e1c2b7d01b2 100644 --- a/modules/coinzillaBidAdapter.js +++ b/modules/coinzillaBidAdapter.js @@ -1,4 +1,4 @@ -import { parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; @@ -31,7 +31,7 @@ export const spec = { return []; } return validBidRequests.map(bidRequest => { - const sizes = parseSizesInput(bidRequest.params.size || bidRequest.sizes)[0]; + const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes)[0]; const width = sizes.split('x')[0]; const height = sizes.split('x')[1]; const payload = { diff --git a/modules/colossussspBidAdapter.js b/modules/colossussspBidAdapter.js index 72df7c7b465..8780936566b 100644 --- a/modules/colossussspBidAdapter.js +++ b/modules/colossussspBidAdapter.js @@ -1,7 +1,6 @@ -import { getWindowTop, deepAccess, logMessage } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import { ajax } from '../src/ajax.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'colossusssp'; const G_URL = 'https://colossusssp.com/?c=o&m=multi'; @@ -60,17 +59,17 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: (validBidRequests, bidderRequest) => { - const winTop = getWindowTop(); + const winTop = utils.getWindowTop(); const location = winTop.location; let placements = []; let request = { - deviceWidth: winTop.screen.width, - deviceHeight: winTop.screen.height, - language: (navigator && navigator.language) ? navigator.language : '', - secure: location.protocol === 'https:' ? 1 : 0, - host: location.host, - page: location.pathname, - placements: placements, + 'deviceWidth': winTop.screen.width, + 'deviceHeight': winTop.screen.height, + 'language': (navigator && navigator.language) ? navigator.language : '', + 'secure': location.protocol === 'https:' ? 1 : 0, + 'host': location.host, + 'page': location.pathname, + 'placements': placements, }; if (bidderRequest) { @@ -88,7 +87,6 @@ export const spec = { let traff = bid.params.traffic || BANNER let placement = { placementId: bid.params.placement_id, - groupId: bid.params.group_id, bidId: bid.bidId, sizes: bid.mediaTypes[traff].sizes, traffic: traff, @@ -111,15 +109,10 @@ export const spec = { if (bid.schain) { placement.schain = bid.schain; } - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); - if (gpid) { - placement.gpid = gpid; - } if (bid.userId) { getUserId(placement.eids, bid.userId.britepoolid, 'britepool.com'); getUserId(placement.eids, bid.userId.idl_env, 'identityLink'); - getUserId(placement.eids, bid.userId.id5id, 'id5-sync.com'); - getUserId(placement.eids, bid.userId.uid2 && bid.userId.uid2.id, 'uidapi.com'); + getUserId(placement.eids, bid.userId.id5id, 'id5-sync.com') getUserId(placement.eids, bid.userId.tdid, 'adserver.org', { rtiPartner: 'TDID' }); @@ -170,7 +163,7 @@ export const spec = { } } } catch (e) { - logMessage(e); + utils.logMessage(e); }; return response; }, @@ -180,12 +173,6 @@ export const spec = { type: 'image', url: G_URL_SYNC }]; - }, - - onBidWon: (bid) => { - if (bid.nurl) { - ajax(bid.nurl, null); - } } }; diff --git a/modules/colossussspBidAdapter.md b/modules/colossussspBidAdapter.md index 4187dfbf36e..8797c648c95 100644 --- a/modules/colossussspBidAdapter.md +++ b/modules/colossussspBidAdapter.md @@ -26,19 +26,5 @@ Module that connects to Colossus SSP demand sources traffic: 'banner' } }] - }, { - code: 'placementid_1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300,600]] - } - }, - bids: [{ - bidder: 'colossusssp', - params: { - group_id: 0, - traffic: 'banner' - } - }] - }]; + ]; ``` diff --git a/modules/compassBidAdapter.js b/modules/compassBidAdapter.js deleted file mode 100644 index a1d1ff9c8c3..00000000000 --- a/modules/compassBidAdapter.js +++ /dev/null @@ -1,208 +0,0 @@ -import { isFn, deepAccess, logMessage, logError } from '../src/utils.js'; - -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import { config } from '../src/config.js'; - -const BIDDER_CODE = 'compass'; -const AD_URL = 'https://sa-lb.deliverimp.com/pbjs'; -const SYNC_URL = 'https://sa-cs.deliverimp.com'; - -function isBidResponseValid(bid) { - if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency) { - return false; - } - - switch (bid.mediaType) { - case BANNER: - return Boolean(bid.width && bid.height && bid.ad); - case VIDEO: - return Boolean(bid.vastUrl || bid.vastXml); - case NATIVE: - return Boolean(bid.native && bid.native.impressionTrackers && bid.native.impressionTrackers.length); - default: - return false; - } -} - -function getPlacementReqData(bid) { - const { params, bidId, mediaTypes } = bid; - const schain = bid.schain || {}; - const { placementId, endpointId } = params; - const bidfloor = getBidFloor(bid); - - const placement = { - bidId, - schain, - bidfloor - }; - - if (placementId) { - placement.placementId = placementId; - placement.type = 'publisher'; - } else if (endpointId) { - placement.endpointId = endpointId; - placement.type = 'network'; - } - - if (mediaTypes && mediaTypes[BANNER]) { - placement.adFormat = BANNER; - placement.sizes = mediaTypes[BANNER].sizes; - } else if (mediaTypes && mediaTypes[VIDEO]) { - placement.adFormat = VIDEO; - placement.playerSize = mediaTypes[VIDEO].playerSize; - placement.minduration = mediaTypes[VIDEO].minduration; - placement.maxduration = mediaTypes[VIDEO].maxduration; - placement.mimes = mediaTypes[VIDEO].mimes; - placement.protocols = mediaTypes[VIDEO].protocols; - placement.startdelay = mediaTypes[VIDEO].startdelay; - placement.placement = mediaTypes[VIDEO].placement; - placement.skip = mediaTypes[VIDEO].skip; - placement.skipafter = mediaTypes[VIDEO].skipafter; - placement.minbitrate = mediaTypes[VIDEO].minbitrate; - placement.maxbitrate = mediaTypes[VIDEO].maxbitrate; - placement.delivery = mediaTypes[VIDEO].delivery; - placement.playbackmethod = mediaTypes[VIDEO].playbackmethod; - placement.api = mediaTypes[VIDEO].api; - placement.linearity = mediaTypes[VIDEO].linearity; - } else if (mediaTypes && mediaTypes[NATIVE]) { - placement.native = mediaTypes[NATIVE]; - placement.adFormat = NATIVE; - } - - return placement; -} - -function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); - } - - try { - const bidFloor = bid.getFloor({ - currency: 'USD', - mediaType: '*', - size: '*', - }); - return bidFloor.floor; - } catch (err) { - logError(err); - return 0; - } -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO, NATIVE], - - isBidRequestValid: (bid = {}) => { - const { params, bidId, mediaTypes } = bid; - let valid = Boolean(bidId && params && params.placementId); - - if (mediaTypes && mediaTypes[BANNER]) { - valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes); - } else if (mediaTypes && mediaTypes[VIDEO]) { - valid = valid && Boolean(mediaTypes[VIDEO] && mediaTypes[VIDEO].playerSize); - } else if (mediaTypes && mediaTypes[NATIVE]) { - valid = valid && Boolean(mediaTypes[NATIVE]); - } else { - valid = false; - } - return valid; - }, - - buildRequests: (validBidRequests = [], bidderRequest = {}) => { - let deviceWidth = 0; - let deviceHeight = 0; - - let winLocation; - try { - const winTop = window.top; - deviceWidth = winTop.screen.width; - deviceHeight = winTop.screen.height; - winLocation = winTop.location; - } catch (e) { - logMessage(e); - winLocation = window.location; - } - - const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - let refferLocation; - try { - refferLocation = refferUrl && new URL(refferUrl); - } catch (e) { - logMessage(e); - } - - let location = refferLocation || winLocation; - const language = (navigator && navigator.language) ? navigator.language.split('-')[0] : ''; - const host = location.host; - const page = location.pathname; - const secure = location.protocol === 'https:' ? 1 : 0; - const placements = []; - const request = { - deviceWidth, - deviceHeight, - language, - secure, - host, - page, - placements, - coppa: config.getConfig('coppa') === true ? 1 : 0, - ccpa: bidderRequest.uspConsent || undefined, - gdpr: bidderRequest.gdprConsent || undefined, - tmax: config.getConfig('bidderTimeout') - }; - - const len = validBidRequests.length; - for (let i = 0; i < len; i++) { - const bid = validBidRequests[i]; - placements.push(getPlacementReqData(bid)); - } - - return { - method: 'POST', - url: AD_URL, - data: request - }; - }, - - interpretResponse: (serverResponse) => { - let response = []; - for (let i = 0; i < serverResponse.body.length; i++) { - let resItem = serverResponse.body[i]; - if (isBidResponseValid(resItem)) { - const advertiserDomains = resItem.adomain && resItem.adomain.length ? resItem.adomain : []; - resItem.meta = { ...resItem.meta, advertiserDomains }; - - response.push(resItem); - } - } - return response; - }, - - getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { - let syncType = syncOptions.iframeEnabled ? 'iframe' : 'image'; - let syncUrl = SYNC_URL + `/${syncType}?pbjs=1`; - if (gdprConsent && gdprConsent.consentString) { - if (typeof gdprConsent.gdprApplies === 'boolean') { - syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; - } else { - syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`; - } - } - if (uspConsent && uspConsent.consentString) { - syncUrl += `&ccpa_consent=${uspConsent.consentString}`; - } - - const coppa = config.getConfig('coppa') ? 1 : 0; - syncUrl += `&coppa=${coppa}`; - - return [{ - type: syncType, - url: syncUrl - }]; - } -}; - -registerBidder(spec); diff --git a/modules/compassBidAdapter.md b/modules/compassBidAdapter.md deleted file mode 100644 index 18d52c12384..00000000000 --- a/modules/compassBidAdapter.md +++ /dev/null @@ -1,79 +0,0 @@ -# Overview - -``` -Module Name: Compass Bidder Adapter -Module Type: Compass Bidder Adapter -Maintainer: sa-support@brightcom.com -``` - -# Description - -Connects to Compass exchange for bids. -Compass bid adapter supports Banner, Video (instream and outstream) and Native. - -# Test Parameters -``` - var adUnits = [ - // Will return static test banner - { - code: 'adunit1', - mediaTypes: { - banner: { - sizes: [ [300, 250], [320, 50] ], - } - }, - bids: [ - { - bidder: 'compass', - params: { - placementId: 'testBanner', - } - } - ] - }, - { - code: 'addunit2', - mediaTypes: { - video: { - playerSize: [ [640, 480] ], - context: 'instream', - minduration: 5, - maxduration: 60, - } - }, - bids: [ - { - bidder: 'compass', - params: { - placementId: 'testVideo', - } - } - ] - }, - { - code: 'addunit3', - mediaTypes: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - }, - bids: [ - { - bidder: 'compass', - params: { - placementId: 'testNative', - } - } - ] - } - ]; -``` \ No newline at end of file diff --git a/modules/concertAnalyticsAdapter.js b/modules/concertAnalyticsAdapter.js index cd52a2ffabf..a81d07e63b5 100644 --- a/modules/concertAnalyticsAdapter.js +++ b/modules/concertAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { logMessage } from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; const analyticsType = 'endpoint'; @@ -90,7 +90,7 @@ function sendEvents() { if (!queue.length) return; if (!pageIncludedInSample) { - logMessage('Page not included in sample for Concert Analytics'); + utils.logMessage('Page not included in sample for Concert Analytics'); return; } @@ -100,7 +100,7 @@ function sendEvents() { contentType: 'application/json', method: 'POST' }); - } catch (err) { logMessage('Concert Analytics error') } + } catch (err) { utils.logMessage('Concert Analytics error') } } // save the base class function diff --git a/modules/concertBidAdapter.js b/modules/concertBidAdapter.js index 9a55e9cef1d..60634151aba 100644 --- a/modules/concertBidAdapter.js +++ b/modules/concertBidAdapter.js @@ -1,4 +1,5 @@ -import { logWarn, logMessage, debugTurnedOn, generateUUID } from '../src/utils.js'; + +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js' @@ -16,7 +17,7 @@ export const spec = { */ isBidRequestValid: function(bid) { if (!bid.params.partnerId) { - logWarn('Missing partnerId bid parameter'); + utils.logWarn('Missing partnerId bid parameter'); return false; } @@ -31,14 +32,14 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function(validBidRequests, bidderRequest) { - logMessage(validBidRequests); - logMessage(bidderRequest); + utils.logMessage(validBidRequests); + utils.logMessage(bidderRequest); let payload = { meta: { prebidVersion: '$prebid.version$', pageUrl: bidderRequest.refererInfo.referer, screen: [window.screen.width, window.screen.height].join('x'), - debug: debugTurnedOn(), + debug: utils.debugTurnedOn(), uid: getUid(bidderRequest), optedOut: hasOptedOutOfPersonalization(), adapterVersion: '1.1.1', @@ -63,7 +64,7 @@ export const spec = { return slot; }); - logMessage(payload); + utils.logMessage(payload); return { method: 'POST', @@ -78,8 +79,8 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: function(serverResponse, bidRequest) { - logMessage(serverResponse); - logMessage(bidRequest); + utils.logMessage(serverResponse); + utils.logMessage(bidRequest); const serverBody = serverResponse.body; @@ -104,11 +105,11 @@ export const spec = { } }); - if (debugTurnedOn() && serverBody.debug) { - logMessage(`CONCERT`, serverBody.debug); + if (utils.debugTurnedOn() && serverBody.debug) { + utils.logMessage(`CONCERT`, serverBody.debug); } - logMessage(bidResponses); + utils.logMessage(bidResponses); return bidResponses; }, @@ -149,8 +150,8 @@ export const spec = { * @param {data} Containing timeout specific data */ onTimeout: function(data) { - logMessage('concert bidder timed out'); - logMessage(data); + utils.logMessage('concert bidder timed out'); + utils.logMessage(data); }, /** @@ -158,8 +159,8 @@ export const spec = { * @param {Bid} The bid that won the auction */ onBidWon: function(bid) { - logMessage('concert bidder won bid'); - logMessage(bid); + utils.logMessage('concert bidder won bid'); + utils.logMessage(bid); } } @@ -181,7 +182,7 @@ function getUid(bidderRequest) { let uid = storage.getDataFromLocalStorage(CONCERT_UID_KEY); if (!uid) { - uid = generateUUID(); + uid = utils.generateUUID(); storage.setDataInLocalStorage(CONCERT_UID_KEY, uid); } diff --git a/modules/connectIdSystem.js b/modules/connectIdSystem.js deleted file mode 100644 index ac44a8b5a2d..00000000000 --- a/modules/connectIdSystem.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * This module adds support for Yahoo ConnectID to the user ID module system. - * The {@link module:modules/userId} module is required - * @module modules/connectIdSystem - * @requires module:modules/userId - */ - -import {ajax} from '../src/ajax.js'; -import {submodule} from '../src/hook.js'; -import {logError, formatQS} from '../src/utils.js'; -import includes from 'core-js-pure/features/array/includes.js'; - -const MODULE_NAME = 'connectId'; -const VENDOR_ID = 25; -const PLACEHOLDER = '__PIXEL_ID__'; -const UPS_ENDPOINT = `https://ups.analytics.yahoo.com/ups/${PLACEHOLDER}/fed`; - -function isEUConsentRequired(consentData) { - return !!(consentData && consentData.gdpr && consentData.gdpr.gdprApplies); -} - -/** @type {Submodule} */ -export const connectIdSubmodule = { - /** - * used to link submodule with config - * @type {string} - */ - name: MODULE_NAME, - /** - * @type {Number} - */ - gvlid: VENDOR_ID, - /** - * decode the stored id value for passing to bid requests - * @function - * @returns {{connectId: string} | undefined} - */ - decode(value) { - return (typeof value === 'object' && value.connectid) - ? {connectId: value.connectid} : undefined; - }, - /** - * Gets the Yahoo ConnectID - * @function - * @param {SubmoduleConfig} [config] - * @param {ConsentData} [consentData] - * @returns {IdResponse|undefined} - */ - getId(config, consentData) { - const params = config.params || {}; - if (!params || typeof params.he !== 'string' || - (typeof params.pixelId === 'undefined' && typeof params.endpoint === 'undefined')) { - logError('The connectId submodule requires the \'he\' and \'pixelId\' parameters to be defined.'); - return; - } - - const data = { - '1p': includes([1, '1', true], params['1p']) ? '1' : '0', - he: params.he, - gdpr: isEUConsentRequired(consentData) ? '1' : '0', - gdpr_consent: isEUConsentRequired(consentData) ? consentData.gdpr.consentString : '', - us_privacy: consentData && consentData.uspConsent ? consentData.uspConsent : '' - }; - - if (params.pixelId) { - data.pixelId = params.pixelId - } - - const resp = function (callback) { - const callbacks = { - success: response => { - let responseObj; - if (response) { - try { - responseObj = JSON.parse(response); - } catch (error) { - logError(error); - } - } - callback(responseObj); - }, - error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); - callback(); - } - }; - const endpoint = UPS_ENDPOINT.replace(PLACEHOLDER, params.pixelId); - let url = `${params.endpoint || endpoint}?${formatQS(data)}`; - connectIdSubmodule.getAjaxFn()(url, callbacks, null, {method: 'GET', withCredentials: true}); - }; - return {callback: resp}; - }, - - /** - * Return the function used to perform XHR calls. - * Utilised for each of testing. - * @returns {Function} - */ - getAjaxFn() { - return ajax; - } -}; - -submodule('userId', connectIdSubmodule); diff --git a/modules/connectIdSystem.md b/modules/connectIdSystem.md deleted file mode 100644 index f2153e1b6cb..00000000000 --- a/modules/connectIdSystem.md +++ /dev/null @@ -1,33 +0,0 @@ -## Yahoo ConnectID User ID Submodule - -Yahoo ConnectID user ID Module. - -### Prebid Params - -``` -pbjs.setConfig({ - userSync: { - userIds: [{ - name: 'connectId', - storage: { - name: 'connectId', - type: 'html5', - expires: 15 - }, - params: { - pixelId: 58776, - he: '0bef996248d63cea1529cb86de31e9547a712d9f380146e98bbd39beec70355a' - } - }] - } -}); -``` -## Parameter Descriptions for the `usersync` Configuration Section -The below parameters apply only to the Yahoo ConnectID user ID Module. - -| Param under usersync.userIds[] | Scope | Type | Description | Example | -| --- | --- | --- | --- | --- | -| name | Required | String | ID value for the Yahoo ConnectID module - `"connectId"` | `"connectId"` | -| params | Required | Object | Data for Yahoo ConnectID initialization. | | -| params.pixelId | Required | Number | The Yahoo supplied publisher specific pixel Id | `8976` | -| params.he | Required | String | The SHA-256 hashed user email address | `"529cb86de31e9547a712d9f380146e98bbd39beec"` | diff --git a/modules/connectadBidAdapter.js b/modules/connectadBidAdapter.js index 711afd98d0f..111b6ac10e8 100644 --- a/modules/connectadBidAdapter.js +++ b/modules/connectadBidAdapter.js @@ -1,4 +1,4 @@ -import { deepSetValue, convertTypes, tryAppendQueryString, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js' import {config} from '../src/config.js'; @@ -47,12 +47,12 @@ export const spec = { // coppa compliance if (config.getConfig('coppa') === true) { - deepSetValue(data, 'user.coppa', 1); + utils.deepSetValue(data, 'user.coppa', 1); } // adding schain object if (validBidRequests[0].schain) { - deepSetValue(data, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(data, 'source.ext.schain', validBidRequests[0].schain); } // Attaching GDPR Consent Params @@ -61,18 +61,18 @@ export const spec = { if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { gdprApplies = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; } - deepSetValue(data, 'user.ext.gdpr', gdprApplies); - deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(data, 'user.ext.gdpr', gdprApplies); + utils.deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } // CCPA if (bidderRequest.uspConsent) { - deepSetValue(data, 'user.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(data, 'user.ext.us_privacy', bidderRequest.uspConsent); } // EIDS Support if (validBidRequests[0].userId) { - deepSetValue(data, 'user.ext.eids', createEidsArray(validBidRequests[0].userId)); + utils.deepSetValue(data, 'user.ext.eids', createEidsArray(validBidRequests[0].userId)); } validBidRequests.map(bid => { @@ -139,7 +139,7 @@ export const spec = { }, transformBidParams: function (params, isOpenRtb) { - return convertTypes({ + return utils.convertTypes({ 'siteId': 'number', 'networkId': 'number' }, params); @@ -149,19 +149,19 @@ export const spec = { let syncEndpoint = 'https://cdn.connectad.io/connectmyusers.php?'; if (gdprConsent) { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'gdpr', (gdprConsent.gdprApplies ? 1 : 0)); } if (gdprConsent && typeof gdprConsent.consentString === 'string') { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr_consent', gdprConsent.consentString); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'gdpr_consent', gdprConsent.consentString); } if (uspConsent) { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'us_privacy', uspConsent); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'us_privacy', uspConsent); } if (config.getConfig('coppa') === true) { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'coppa', 1); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'coppa', 1); } if (syncOptions.iframeEnabled) { @@ -170,7 +170,7 @@ export const spec = { url: syncEndpoint }]; } else { - logWarn('Bidder ConnectAd: Please activate iFrame Sync'); + utils.logWarn('Bidder ConnectAd: Please activate iFrame Sync'); } } }; diff --git a/modules/consentManagement.js b/modules/consentManagement.js index ecd0c0eec4b..6a13e73b8a2 100644 --- a/modules/consentManagement.js +++ b/modules/consentManagement.js @@ -1,11 +1,10 @@ - /** * This module adds GDPR consentManagement support to prebid.js. It interacts with * supported CMPs (Consent Management Platforms) to grab the user's consent information * and make it available for any GDPR supported adapters to read/pass this information to * their system. */ -import { logInfo, isFn, getAdUnitSizes, logWarn, isStr, isPlainObject, logError, isNumber } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { gdprDataHandler } from '../src/adapterManager.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -99,7 +98,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { } function v2CmpResponseCallback(tcfData, success) { - logInfo('Received a response from CMP', tcfData); + utils.logInfo('Received a response from CMP', tcfData); if (success) { if (tcfData.gdprApplies === false || tcfData.eventStatus === 'tcloaded' || tcfData.eventStatus === 'useractioncomplete') { cmpSuccess(tcfData, hookConfig); @@ -114,7 +113,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { function afterEach() { if (cmpResponse.getConsentData && cmpResponse.getVendorConsents) { - logInfo('Received all requested responses from CMP', cmpResponse); + utils.logInfo('Received all requested responses from CMP', cmpResponse); cmpSuccess(cmpResponse, hookConfig); } } @@ -148,8 +147,8 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { // else assume prebid may be inside an iframe and use the IAB CMP locator code to see if CMP's located in a higher parent window. this works in cross domain iframes // if the CMP is not found, the iframe function will call the cmpError exit callback to abort the rest of the CMP workflow - if (isFn(cmpFunction)) { - logInfo('Detected CMP API is directly accessible, calling it now...'); + if (utils.isFn(cmpFunction)) { + utils.logInfo('Detected CMP API is directly accessible, calling it now...'); if (cmpVersion === 1) { cmpFunction('getConsentData', null, v1CallbackHandler.consentDataCallback); cmpFunction('getVendorConsents', null, v1CallbackHandler.vendorConsentsCallback); @@ -158,11 +157,11 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { } } else if (cmpVersion === 1 && inASafeFrame() && typeof window.$sf.ext.cmp === 'function') { // this safeframe workflow is only supported with TCF v1 spec; the v2 recommends to use the iframe postMessage route instead (even if you are in a safeframe). - logInfo('Detected Prebid.js is encased in a SafeFrame and CMP is registered, calling it now...'); + utils.logInfo('Detected Prebid.js is encased in a SafeFrame and CMP is registered, calling it now...'); callCmpWhileInSafeFrame('getConsentData', v1CallbackHandler.consentDataCallback); callCmpWhileInSafeFrame('getVendorConsents', v1CallbackHandler.vendorConsentsCallback); } else { - logInfo('Detected CMP is outside the current iframe where Prebid.js is located, calling it now...'); + utils.logInfo('Detected CMP is outside the current iframe where Prebid.js is located, calling it now...'); if (cmpVersion === 1) { callCmpWhileInIframe('getConsentData', cmpFrame, v1CallbackHandler.consentDataCallback); callCmpWhileInIframe('getVendorConsents', cmpFrame, v1CallbackHandler.vendorConsentsCallback); @@ -188,7 +187,7 @@ function lookupIabConsent(cmpSuccess, cmpError, hookConfig) { let width = 1; let height = 1; if (Array.isArray(adUnits) && adUnits.length > 0) { - let sizes = getAdUnitSizes(adUnits[0]); + let sizes = utils.getAdUnitSizes(adUnits[0]); width = sizes[0][0]; height = sizes[0][1]; } @@ -283,12 +282,12 @@ export function requestBidsHook(fn, reqBidsConfigObj) { // in case we already have consent (eg during bid refresh) if (consentData) { - logInfo('User consent information already known. Pulling internally stored information...'); + utils.logInfo('User consent information already known. Pulling internally stored information...'); return exitModule(null, hookConfig); } if (!includes(Object.keys(cmpCallMap), userCMP)) { - logWarn(`CMP framework (${userCMP}) is not a supported framework. Aborting consentManagement module and resuming auction.`); + utils.logWarn(`CMP framework (${userCMP}) is not a supported framework. Aborting consentManagement module and resuming auction.`); return hookConfig.nextFn.apply(hookConfig.context, hookConfig.args); } @@ -317,8 +316,8 @@ function processCmpData(consentObject, hookConfig) { return !!( (typeof gdprApplies !== 'boolean') || (gdprApplies === true && - !(isStr(consentObject.getConsentData.consentData) && - isPlainObject(consentObject.getVendorConsents) && + !(utils.isStr(consentObject.getConsentData.consentData) && + utils.isPlainObject(consentObject.getVendorConsents) && Object.keys(consentObject.getVendorConsents).length > 1 ) ) @@ -331,7 +330,7 @@ function processCmpData(consentObject, hookConfig) { let tcString = consentObject && consentObject.tcString; return !!( (typeof gdprApplies !== 'boolean') || - (gdprApplies === true && !isStr(tcString)) + (gdprApplies === true && !utils.isStr(tcString)) ); } @@ -349,12 +348,12 @@ function processCmpData(consentObject, hookConfig) { // Raise deprecation warning if 'allowAuctionWithoutConsent' is used with TCF 2. if (allowAuction.definedInConfig && cmpVersion === 2) { - logWarn(`'allowAuctionWithoutConsent' ignored for TCF 2`); + utils.logWarn(`'allowAuctionWithoutConsent' ignored for TCF 2`); } else if (!allowAuction.definedInConfig && cmpVersion === 1) { - logInfo(`'allowAuctionWithoutConsent' using system default: (${DEFAULT_ALLOW_AUCTION_WO_CONSENT}).`); + utils.logInfo(`'allowAuctionWithoutConsent' using system default: (${DEFAULT_ALLOW_AUCTION_WO_CONSENT}).`); } - if (isFn(checkFn)) { + if (utils.isFn(checkFn)) { if (checkFn(consentObject)) { cmpFailed(`CMP returned unexpected value during lookup process.`, hookConfig, consentObject); } else { @@ -371,13 +370,7 @@ function processCmpData(consentObject, hookConfig) { * General timeout callback when interacting with CMP takes too long. */ function cmpTimedOut(hookConfig) { - if (cmpVersion === 2) { - logWarn(`No response from CMP, continuing auction...`) - storeConsentData(undefined); - exitModule(null, hookConfig) - } else { - cmpFailed('CMP workflow exceeded timeout threshold.', hookConfig); - } + cmpFailed('CMP workflow exceeded timeout threshold.', hookConfig); } /** @@ -413,7 +406,7 @@ function storeConsentData(cmpConsentObject) { vendorData: (cmpConsentObject) || undefined, gdprApplies: cmpConsentObject && typeof cmpConsentObject.gdprApplies === 'boolean' ? cmpConsentObject.gdprApplies : gdprScope }; - if (cmpConsentObject && cmpConsentObject.addtlConsent && isStr(cmpConsentObject.addtlConsent)) { + if (cmpConsentObject && cmpConsentObject.addtlConsent && utils.isStr(cmpConsentObject.addtlConsent)) { consentData.addtlConsent = cmpConsentObject.addtlConsent; }; } @@ -448,14 +441,14 @@ function exitModule(errMsg, hookConfig, extraArgs) { if (errMsg) { if (allowAuction.value && cmpVersion === 1) { - logWarn(errMsg + ` 'allowAuctionWithoutConsent' activated.`, extraArgs); + utils.logWarn(errMsg + ` 'allowAuctionWithoutConsent' activated.`, extraArgs); nextFn.apply(context, args); } else { - logError(errMsg + ' Canceling auction as per consentManagement config.', extraArgs); + utils.logError(errMsg + ' Canceling auction as per consentManagement config.', extraArgs); if (typeof hookConfig.bidsBackHandler === 'function') { hookConfig.bidsBackHandler(); } else { - logError('Error executing bidsBackHandler'); + utils.logError('Error executing bidsBackHandler'); } } } else { @@ -483,21 +476,21 @@ export function setConsentConfig(config) { // else for backward compatability, just use `config` config = config && (config.gdpr || config.usp ? config.gdpr : config); if (!config || typeof config !== 'object') { - logWarn('consentManagement config not defined, exiting consent manager'); + utils.logWarn('consentManagement config not defined, exiting consent manager'); return; } - if (isStr(config.cmpApi)) { + if (utils.isStr(config.cmpApi)) { userCMP = config.cmpApi; } else { userCMP = DEFAULT_CMP; - logInfo(`consentManagement config did not specify cmp. Using system default setting (${DEFAULT_CMP}).`); + utils.logInfo(`consentManagement config did not specify cmp. Using system default setting (${DEFAULT_CMP}).`); } - if (isNumber(config.timeout)) { + if (utils.isNumber(config.timeout)) { consentTimeout = config.timeout; } else { consentTimeout = DEFAULT_CONSENT_TIMEOUT; - logInfo(`consentManagement config did not specify timeout. Using system default setting (${DEFAULT_CONSENT_TIMEOUT}).`); + utils.logInfo(`consentManagement config did not specify timeout. Using system default setting (${DEFAULT_CONSENT_TIMEOUT}).`); } if (typeof config.allowAuctionWithoutConsent === 'boolean') { @@ -508,14 +501,14 @@ export function setConsentConfig(config) { // if true, then gdprApplies should be set to true gdprScope = config.defaultGdprScope === true; - logInfo('consentManagement module has been activated...'); + utils.logInfo('consentManagement module has been activated...'); if (userCMP === 'static') { - if (isPlainObject(config.consentData)) { + if (utils.isPlainObject(config.consentData)) { staticConsentData = config.consentData; consentTimeout = 0; } else { - logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`); + utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`); } } if (!addedConsentHook) { diff --git a/modules/consentManagementUsp.js b/modules/consentManagementUsp.js index 4a4c4ae0a55..cba9c2758d0 100644 --- a/modules/consentManagementUsp.js +++ b/modules/consentManagementUsp.js @@ -4,7 +4,7 @@ * information and make it available for any USP (CCPA) supported adapters to * read/pass this information to their system. */ -import { isFn, logInfo, logWarn, isStr, isNumber, isPlainObject, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { uspDataHandler } from '../src/adapterManager.js'; @@ -111,15 +111,15 @@ function lookupUspConsent(uspSuccess, uspError, hookConfig) { // - else assume prebid is in an iframe, and use the locator to see if the CMP is located in a higher parent window. This works in cross domain iframes. // - if USPAPI is not found, the iframe function will call the uspError exit callback to abort the rest of the USPAPI workflow - if (isFn(uspapiFunction)) { - logInfo('Detected USP CMP is directly accessible, calling it now...'); + if (utils.isFn(uspapiFunction)) { + utils.logInfo('Detected USP CMP is directly accessible, calling it now...'); uspapiFunction( 'getUSPData', USPAPI_VERSION, callbackHandler.consentDataCallback ); } else { - logInfo( + utils.logInfo( 'Detected USP CMP is outside the current iframe where Prebid.js is located, calling it now...' ); callUspApiWhileInIframe( @@ -185,7 +185,7 @@ export function requestBidsHook(fn, reqBidsConfigObj) { }; if (!uspCallMap[consentAPI]) { - logWarn(`USP framework (${consentAPI}) is not a supported framework. Aborting consentManagement module and resuming auction.`); + utils.logWarn(`USP framework (${consentAPI}) is not a supported framework. Aborting consentManagement module and resuming auction.`); return hookConfig.nextFn.apply(hookConfig.context, hookConfig.args); } @@ -275,7 +275,7 @@ function exitModule(errMsg, hookConfig, extraArgs) { let nextFn = hookConfig.nextFn; if (errMsg) { - logWarn(errMsg + ' Resuming auction without consent data as per consentManagement config.', extraArgs); + utils.logWarn(errMsg + ' Resuming auction without consent data as per consentManagement config.', extraArgs); } nextFn.apply(context, args); } @@ -297,31 +297,31 @@ export function resetConsentData() { export function setConsentConfig(config) { config = config && config.usp; if (!config || typeof config !== 'object') { - logWarn('consentManagement.usp config not defined, exiting usp consent manager'); + utils.logWarn('consentManagement.usp config not defined, exiting usp consent manager'); return; } - if (isStr(config.cmpApi)) { + if (utils.isStr(config.cmpApi)) { consentAPI = config.cmpApi; } else { consentAPI = DEFAULT_CONSENT_API; - logInfo(`consentManagement.usp config did not specify cmpApi. Using system default setting (${DEFAULT_CONSENT_API}).`); + utils.logInfo(`consentManagement.usp config did not specify cmpApi. Using system default setting (${DEFAULT_CONSENT_API}).`); } - if (isNumber(config.timeout)) { + if (utils.isNumber(config.timeout)) { consentTimeout = config.timeout; } else { consentTimeout = DEFAULT_CONSENT_TIMEOUT; - logInfo(`consentManagement.usp config did not specify timeout. Using system default setting (${DEFAULT_CONSENT_TIMEOUT}).`); + utils.logInfo(`consentManagement.usp config did not specify timeout. Using system default setting (${DEFAULT_CONSENT_TIMEOUT}).`); } - logInfo('USPAPI consentManagement module has been activated...'); + utils.logInfo('USPAPI consentManagement module has been activated...'); if (consentAPI === 'static') { - if (isPlainObject(config.consentData) && isPlainObject(config.consentData.getUSPData)) { + if (utils.isPlainObject(config.consentData) && utils.isPlainObject(config.consentData.getUSPData)) { if (config.consentData.getUSPData.uspString) staticConsentData = { usPrivacy: config.consentData.getUSPData.uspString }; consentTimeout = 0; } else { - logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`); + utils.logError(`consentManagement config with cmpApi: 'static' did not specify consentData. No consents will be available to adapters.`); } } if (!addedConsentHook) { diff --git a/modules/consumableBidAdapter.js b/modules/consumableBidAdapter.js index 1a2845ba85b..92e2192b925 100644 --- a/modules/consumableBidAdapter.js +++ b/modules/consumableBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, createTrackPixelHtml } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'consumable'; @@ -145,7 +145,7 @@ export const spec = { if (syncOptions.pixelEnabled && serverResponses.length > 0) { return serverResponses[0].body.pixels; } else { - logWarn(bidder + ': Please enable iframe based user syncing.'); + utils.logWarn(bidder + ': Please enable iframe based user syncing.'); } } }; @@ -207,7 +207,7 @@ function getSize(sizes) { } function retrieveAd(decision, unitId, unitName) { - let ad = decision.contents && decision.contents[0] && decision.contents[0].body + createTrackPixelHtml(decision.impressionUrl); + let ad = decision.contents && decision.contents[0] && decision.contents[0].body + utils.createTrackPixelHtml(decision.impressionUrl); return ad; } diff --git a/modules/contentexchangeBidAdapter.js b/modules/contentexchangeBidAdapter.js index b3a5056f816..de4cf8df933 100644 --- a/modules/contentexchangeBidAdapter.js +++ b/modules/contentexchangeBidAdapter.js @@ -1,6 +1,6 @@ -import { isFn, deepAccess, logMessage } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'contentexchange'; @@ -69,8 +69,8 @@ function getPlacementReqData (bid) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return deepAccess(bid, 'params.bidfloor', 0); + if (!utils.isFn(bid.getFloor)) { + return utils.deepAccess(bid, 'params.bidfloor', 0); } try { @@ -123,7 +123,7 @@ export const spec = { deviceHeight = winTop.screen.height; winLocation = winTop.location; } catch (e) { - logMessage(e); + utils.logMessage(e); winLocation = window.location; } @@ -132,7 +132,7 @@ export const spec = { try { refferLocation = refferUrl && new URL(refferUrl); } catch (e) { - logMessage(e); + utils.logMessage(e); } let location = refferLocation || winLocation; diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index 92b5d47277e..a1ca094273b 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, isStr, deepAccess, isArray, getBidIdParameter, deepSetValue, isEmpty, _each, convertTypes, parseUrl, mergeDeep, buildUrl, _map, logError, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -23,22 +23,22 @@ export const spec = { */ isBidRequestValid: function(bid) { if (!bid || !bid.params) { - logWarn(BIDDER_CODE + ': Missing bid parameters'); + utils.logWarn(BIDDER_CODE + ': Missing bid parameters'); return false; } - if (!isStr(bid.params.site_id)) { - logWarn(BIDDER_CODE + ': site_id must be specified as a string'); + if (!utils.isStr(bid.params.site_id)) { + utils.logWarn(BIDDER_CODE + ': site_id must be specified as a string'); return false; } if (isVideoRequest(bid)) { - const mimes = bid.params.mimes || deepAccess(bid, 'mediaTypes.video.mimes'); + const mimes = bid.params.mimes || utils.deepAccess(bid, 'mediaTypes.video.mimes'); if (!mimes) { // Give a warning but let it pass - logWarn(BIDDER_CODE + ': mimes should be specified for videos'); - } else if (!isArray(mimes) || !mimes.every(s => isStr(s))) { - logWarn(BIDDER_CODE + ': mimes must be an array of strings'); + utils.logWarn(BIDDER_CODE + ': mimes should be specified for videos'); + } else if (!utils.isArray(mimes) || !mimes.every(s => utils.isStr(s))) { + utils.logWarn(BIDDER_CODE + ': mimes must be an array of strings'); return false; } } @@ -64,8 +64,8 @@ export const spec = { const conversantImps = validBidRequests.map(function(bid) { const bidfloor = getBidFloor(bid); - siteId = getBidIdParameter('site_id', bid.params) || siteId; - pubcidName = getBidIdParameter('pubcid_name', bid.params) || pubcidName; + siteId = utils.getBidIdParameter('site_id', bid.params) || siteId; + pubcidName = utils.getBidIdParameter('pubcid_name', bid.params) || pubcidName; requestId = bid.auctionId; @@ -80,7 +80,7 @@ export const spec = { copyOptProperty(bid.params.tag_id, imp, 'tagid'); if (isVideoRequest(bid)) { - const videoData = deepAccess(bid, 'mediaTypes.video') || {}; + const videoData = utils.deepAccess(bid, 'mediaTypes.video') || {}; const format = convertSizes(videoData.playerSize || bid.sizes); const video = {}; @@ -97,7 +97,7 @@ export const spec = { imp.video = video; } else { - const bannerData = deepAccess(bid, 'mediaTypes.banner') || {}; + const bannerData = utils.deepAccess(bid, 'mediaTypes.banner') || {}; const format = convertSizes(bannerData.sizes || bid.sizes); const banner = {format: format}; @@ -138,12 +138,12 @@ export const spec = { userExt.consent = bidderRequest.gdprConsent.consentString; if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { - deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + utils.deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); } } if (bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } } @@ -163,7 +163,7 @@ export const spec = { } // Only add the user object if it's not empty - if (!isEmpty(userExt)) { + if (!utils.isEmpty(userExt)) { payload.user = {ext: userExt}; } @@ -186,12 +186,12 @@ export const spec = { serverResponse = serverResponse.body; if (bidRequest && bidRequest.data && bidRequest.data.imp) { - _each(bidRequest.data.imp, imp => requestMap[imp.id] = imp); + utils._each(bidRequest.data.imp, imp => requestMap[imp.id] = imp); } - if (serverResponse && isArray(serverResponse.seatbid)) { - _each(serverResponse.seatbid, function(bidList) { - _each(bidList.bid, function(conversantBid) { + if (serverResponse && utils.isArray(serverResponse.seatbid)) { + utils._each(serverResponse.seatbid, function(bidList) { + utils._each(bidList.bid, function(conversantBid) { const responseCPM = parseFloat(conversantBid.price); if (responseCPM > 0.0 && conversantBid.impid) { const responseAd = conversantBid.adm || ''; @@ -243,7 +243,7 @@ export const spec = { * @return {Object} params bid params */ transformBidParams: function(params, isOpenRtb) { - return convertTypes({ + return utils.convertTypes({ 'site_id': 'string', 'secure': 'number', 'mobile': 'number' @@ -277,12 +277,12 @@ export const spec = { }) .map((entry) => { return entry.urls.map((endpoint) => { - let urlInfo = parseUrl(endpoint); - mergeDeep(urlInfo.search, params); + let urlInfo = utils.parseUrl(endpoint); + utils.mergeDeep(urlInfo.search, params); if (Object.keys(urlInfo.search).length === 0) { delete urlInfo.search; // empty search object causes buildUrl to add a trailing ? to the url } - return {type: entry.type, url: buildUrl(urlInfo)}; + return {type: entry.type, url: utils.buildUrl(urlInfo)}; }) .reduce((x, y) => x.concat(y), []); }) @@ -333,7 +333,7 @@ function convertSizes(bidSizes) { if (bidSizes.length === 2 && typeof bidSizes[0] === 'number' && typeof bidSizes[1] === 'number') { format = [{w: bidSizes[0], h: bidSizes[1]}]; } else { - format = _map(bidSizes, d => { return {w: d[0], h: d[1]}; }); + format = utils._map(bidSizes, d => { return {w: d[0], h: d[1]}; }); } } @@ -347,7 +347,7 @@ function convertSizes(bidSizes) { * @returns {boolean} True if it's a video bid */ function isVideoRequest(bid) { - return bid.mediaType === 'video' || !!deepAccess(bid, 'mediaTypes.video'); + return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video'); } /** @@ -370,10 +370,9 @@ function copyOptProperty(src, dst, dstName) { function collectEids(bidRequests) { const request = bidRequests[0]; // bidRequests have the same userId object const eids = []; - if (isArray(request.userIdAsEids) && request.userIdAsEids.length > 0) { + if (utils.isArray(request.userIdAsEids) && request.userIdAsEids.length > 0) { // later following white-list can be converted to block-list if needed const requiredSourceValues = { - 'epsilon.com': 1, 'adserver.org': 1, 'liveramp.com': 1, 'criteo.com': 1, @@ -411,11 +410,11 @@ function readStoredValue(key) { } // deserialize JSON if needed - if (isStr(storedValue) && storedValue.charAt(0) === '{') { + if (utils.isStr(storedValue) && storedValue.charAt(0) === '{') { storedValue = JSON.parse(storedValue); } } catch (e) { - logError(e); + utils.logError(e); } return storedValue; @@ -428,16 +427,16 @@ function readStoredValue(key) { * @returns {*|number} floor price */ function getBidFloor(bid) { - let floor = getBidIdParameter('bidfloor', bid.params); + let floor = utils.getBidIdParameter('bidfloor', bid.params); - if (!floor && isFn(bid.getFloor)) { + if (!floor && utils.isFn(bid.getFloor)) { const floorObj = bid.getFloor({ currency: 'USD', mediaType: '*', size: '*' }); - if (isPlainObject(floorObj) && !isNaN(floorObj.floor) && floorObj.currency === 'USD') { + if (utils.isPlainObject(floorObj) && !isNaN(floorObj.floor) && floorObj.currency === 'USD') { floor = floorObj.floor; } } diff --git a/modules/cpmstarBidAdapter.js b/modules/cpmstarBidAdapter.js index 75a7007ee36..14c0d43add7 100755 --- a/modules/cpmstarBidAdapter.js +++ b/modules/cpmstarBidAdapter.js @@ -1,4 +1,5 @@ -import { deepAccess, getBidIdParameter, logWarn, logError } from '../src/utils.js'; + +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -25,11 +26,11 @@ export const spec = { getMediaType: function (bidRequest) { if (bidRequest == null) return BANNER; - return !deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO; + return !utils.deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO; }, getPlayerSize: function (bidRequest) { - var playerSize = deepAccess(bidRequest, 'mediaTypes.video.playerSize'); + var playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'); if (playerSize == null) return [640, 440]; if (playerSize[0] != null) playerSize = playerSize[0]; if (playerSize == null || playerSize[0] == null || playerSize[1] == null) return [640, 440]; @@ -47,13 +48,13 @@ export const spec = { for (var i = 0; i < validBidRequests.length; i++) { var bidRequest = validBidRequests[i]; var referer = encodeURIComponent(bidderRequest.refererInfo.referer); - var e = getBidIdParameter('endpoint', bidRequest.params); + var e = utils.getBidIdParameter('endpoint', bidRequest.params); var ENDPOINT = e == 'dev' ? ENDPOINT_DEV : e == 'staging' ? ENDPOINT_STAGING : ENDPOINT_PRODUCTION; var mediaType = spec.getMediaType(bidRequest); var playerSize = spec.getPlayerSize(bidRequest); var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : ''); var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') + - '&json=c_b&mv=1&poolid=' + getBidIdParameter('placementId', bidRequest.params) + + '&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) + '&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) + '&requestid=' + bidRequest.bidId + '&referer=' + encodeURIComponent(referer); @@ -116,13 +117,13 @@ export const spec = { var raw = serverResponse.body[i]; var rawBid = raw.creatives[0]; if (!rawBid) { - logWarn('cpmstarBidAdapter: server response failed check'); + utils.logWarn('cpmstarBidAdapter: server response failed check'); return; } var cpm = (parseFloat(rawBid.cpm) || 0); if (!cpm) { - logWarn('cpmstarBidAdapter: server response failed check. Missing cpm') + utils.logWarn('cpmstarBidAdapter: server response failed check. Missing cpm') return; } @@ -155,7 +156,7 @@ export const spec = { bidResponse.mediaType = VIDEO; bidResponse.vastXml = rawBid.creativemacros.HTML5VID_VASTSTRING; } else { - return logError('bad response', rawBid); + return utils.logError('bad response', rawBid); } bidResponses.push(bidResponse); diff --git a/modules/craftBidAdapter.js b/modules/craftBidAdapter.js index 812ec53d686..0124f96a107 100644 --- a/modules/craftBidAdapter.js +++ b/modules/craftBidAdapter.js @@ -1,11 +1,10 @@ -import { logError, convertTypes, convertCamelToUnderscore, isArray, deepAccess, getBidRequest, isEmpty, transformBidderParamKeywords } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { auctionManager } from '../src/auctionManager.js'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; import { getStorageManager } from '../src/storageManager.js'; -import {ajax} from '../src/ajax.js'; const BIDDER_CODE = 'craft'; const URL_BASE = 'https://gacraft.jp/prebid-v3'; @@ -68,7 +67,7 @@ export const spec = { if (serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - logError(errorMessage); + utils.logError(errorMessage); return bids; } if (serverResponse.tags) { @@ -90,17 +89,17 @@ export const spec = { }, transformBidParams: function(params, isOpenRtb) { - params = convertTypes({ + params = utils.convertTypes({ 'sitekey': 'string', 'placementId': 'string', - 'keywords': transformBidderParamKeywords + 'keywords': utils.transformBidderParamKeywords }, params); if (isOpenRtb) { if (isPopulatedArray(params.keywords)) { params.keywords.forEach(deleteValues); } Object.keys(params).forEach(paramKey => { - let convertedKey = convertCamelToUnderscore(paramKey); + let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { params[convertedKey] = params[paramKey]; delete params[paramKey]; @@ -111,15 +110,14 @@ export const spec = { }, onBidWon: function(bid) { - ajax(bid._prebidWon, null, null, { - method: 'POST', - contentType: 'application/json' - }); + var xhr = new XMLHttpRequest(); + xhr.open('POST', bid._prebidWon); + xhr.send(); } }; function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); + return !!(utils.isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -132,7 +130,7 @@ function hasPurpose1Consent(bidderRequest) { let result = true; if (bidderRequest && bidderRequest.gdprConsent) { if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -157,7 +155,7 @@ function formatRequest(payload, bidderRequest) { } function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); + const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { requestId: serverBid.uuid, cpm: rtbBid.cpm, @@ -192,8 +190,8 @@ function bidToTag(bid) { tag.primary_size = tag.sizes[0]; tag.ad_types = []; tag.uuid = bid.bidId; - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); + if (!utils.isEmpty(bid.params.keywords)) { + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); } diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index 4dfb5d38f4c..363b9322204 100644 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -1,8 +1,8 @@ -import { isArray, getUniqueIdentifierStr, parseUrl, deepAccess, logWarn, logError, logInfo } from '../src/utils.js'; import {loadExternalScript} from '../src/adloader.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import find from 'core-js-pure/features/array/find.js'; import { verify } from 'criteo-direct-rsa-validate/build/verify.js'; // ref#2 import { getStorageManager } from '../src/storageManager.js'; @@ -24,7 +24,7 @@ const LOG_PREFIX = 'Criteo: '; Unminified source code can be found in the privately shared repo: https://github.com/Prebid-org/prebid-js-external-js-criteo/blob/master/dist/prod.js */ const FAST_BID_VERSION_PLACEHOLDER = '%FAST_BID_VERSION%'; -export const FAST_BID_VERSION_CURRENT = 117; +export const FAST_BID_VERSION_CURRENT = 105; const FAST_BID_VERSION_LATEST = 'latest'; const FAST_BID_VERSION_NONE = 'none'; const PUBLISHER_TAG_URL_TEMPLATE = 'https://static.criteo.net/js/ld/publishertag.prebid' + FAST_BID_VERSION_PLACEHOLDER + '.js'; @@ -123,13 +123,13 @@ export const spec = { const bids = []; - if (body && body.slots && isArray(body.slots)) { + if (body && body.slots && utils.isArray(body.slots)) { body.slots.forEach(slot => { const bidRequest = find(request.bidRequests, b => b.adUnitCode === slot.impid && (!b.params.zoneId || parseInt(b.params.zoneId) === slot.zoneid)); const bidId = bidRequest.bidId; const bid = { requestId: bidId, - adId: slot.bidId || getUniqueIdentifierStr(), + adId: slot.bidId || utils.getUniqueIdentifierStr(), cpm: slot.cpm, currency: slot.currency, netRevenue: true, @@ -219,7 +219,7 @@ function buildContext(bidRequests, bidderRequest) { if (bidderRequest && bidderRequest.refererInfo) { referrer = bidderRequest.refererInfo.referer; } - const queryString = parseUrl(referrer).search; + const queryString = utils.parseUrl(referrer).search; const context = { url: referrer, @@ -296,7 +296,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) { if (bidRequest.params.zoneId) { slot.zoneid = bidRequest.params.zoneId; } - if (deepAccess(bidRequest, 'ortb2Imp.ext')) { + if (utils.deepAccess(bidRequest, 'ortb2Imp.ext')) { slot.ext = bidRequest.ortb2Imp.ext; } if (bidRequest.params.ext) { @@ -305,10 +305,10 @@ function buildCdbRequest(context, bidRequests, bidderRequest) { if (bidRequest.params.publisherSubId) { slot.publishersubid = bidRequest.params.publisherSubId; } - if (bidRequest.params.nativeCallback || deepAccess(bidRequest, `mediaTypes.${NATIVE}`)) { + if (bidRequest.params.nativeCallback || utils.deepAccess(bidRequest, `mediaTypes.${NATIVE}`)) { slot.native = true; if (!checkNativeSendId(bidRequest)) { - logWarn(LOG_PREFIX + 'all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)'); + utils.logWarn(LOG_PREFIX + 'all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)'); } slot.sizes = parseSizes(retrieveBannerSizes(bidRequest), parseNativeSize); } else { @@ -316,25 +316,17 @@ function buildCdbRequest(context, bidRequests, bidderRequest) { } if (hasVideoMediaType(bidRequest)) { const video = { - playersizes: parseSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize'), parseSize), + playersizes: parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'), parseSize), mimes: bidRequest.mediaTypes.video.mimes, protocols: bidRequest.mediaTypes.video.protocols, maxduration: bidRequest.mediaTypes.video.maxduration, api: bidRequest.mediaTypes.video.api, - skip: bidRequest.mediaTypes.video.skip, - placement: bidRequest.mediaTypes.video.placement, - minduration: bidRequest.mediaTypes.video.minduration, - playbackmethod: bidRequest.mediaTypes.video.playbackmethod, - startdelay: bidRequest.mediaTypes.video.startdelay + skip: bidRequest.mediaTypes.video.skip || bidRequest.params.video.skip, + placement: bidRequest.mediaTypes.video.placement || bidRequest.params.video.placement, + minduration: bidRequest.mediaTypes.video.minduration || bidRequest.params.video.minduration, + playbackmethod: bidRequest.mediaTypes.video.playbackmethod || bidRequest.params.video.playbackmethod, + startdelay: bidRequest.mediaTypes.video.startdelay || bidRequest.params.video.startdelay }; - const paramsVideo = bidRequest.params.video; - if (paramsVideo !== undefined) { - video.skip = video.skip || paramsVideo.skip || 0; - video.placement = video.placement || paramsVideo.placement; - video.minduration = video.minduration || paramsVideo.minduration; - video.playbackmethod = video.playbackmethod || paramsVideo.playbackmethod; - video.startdelay = video.startdelay || paramsVideo.startdelay || 0; - } slot.video = video; } @@ -367,7 +359,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) { } function retrieveBannerSizes(bidRequest) { - return deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes; + return utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes; } function parseSizes(sizes, parser) { @@ -389,7 +381,7 @@ function parseNativeSize(size) { } function hasVideoMediaType(bidRequest) { - return deepAccess(bidRequest, 'mediaTypes.video') !== undefined; + return utils.deepAccess(bidRequest, 'mediaTypes.video') !== undefined; } function hasValidVideoMediaType(bidRequest) { @@ -398,9 +390,9 @@ function hasValidVideoMediaType(bidRequest) { var requiredMediaTypesParams = ['mimes', 'playerSize', 'maxduration', 'protocols', 'api', 'skip', 'placement', 'playbackmethod']; requiredMediaTypesParams.forEach(function(param) { - if (deepAccess(bidRequest, 'mediaTypes.video.' + param) === undefined && deepAccess(bidRequest, 'params.video.' + param) === undefined) { + if (utils.deepAccess(bidRequest, 'mediaTypes.video.' + param) === undefined && utils.deepAccess(bidRequest, 'params.video.' + param) === undefined) { isValid = false; - logError('Criteo Bid Adapter: mediaTypes.video.' + param + ' is required'); + utils.logError('Criteo Bid Adapter: mediaTypes.video.' + param + ' is required'); } }); @@ -476,7 +468,7 @@ export function getFastBidUrl(fastBidVersion) { } else if (fastBidVersion) { let majorVersion = String(fastBidVersion).split('.')[0]; if (majorVersion < 102) { - logWarn('Specifying a Fastbid version which is not supporting version selection.') + utils.logWarn('Specifying a Fastbid version which is not supporting version selection.') } version = '.' + fastBidVersion; } else { @@ -499,7 +491,7 @@ export function tryGetCriteoFastBid() { const firstLine = fastBidFromStorage.substr(0, firstLineEndPosition).trim(); if (firstLine.substr(0, hashPrefix.length) !== hashPrefix) { - logWarn('No hash found in FastBid'); + utils.logWarn('No hash found in FastBid'); storage.removeDataFromLocalStorage(fastBidStorageKey); } else { // Remove the hash part from the locally stored value @@ -507,10 +499,10 @@ export function tryGetCriteoFastBid() { const publisherTag = fastBidFromStorage.substr(firstLineEndPosition + 1); if (verify(publisherTag, publisherTagHash, FAST_BID_PUBKEY_N, FAST_BID_PUBKEY_E)) { - logInfo('Using Criteo FastBid'); + utils.logInfo('Using Criteo FastBid'); eval(publisherTag); // eslint-disable-line no-eval } else { - logWarn('Invalid Criteo FastBid found'); + utils.logWarn('Invalid Criteo FastBid found'); storage.removeDataFromLocalStorage(fastBidStorageKey); } } diff --git a/modules/criteoIdSystem.js b/modules/criteoIdSystem.js index ecf7b3aaac4..ac26d34d529 100644 --- a/modules/criteoIdSystem.js +++ b/modules/criteoIdSystem.js @@ -5,9 +5,9 @@ * @requires module:modules/userId */ -import { timestamp, parseUrl, triggerPixel, logError } from '../src/utils.js'; -import { ajax } from '../src/ajax.js'; -import { getRefererInfo } from '../src/refererDetection.js'; +import * as utils from '../src/utils.js' +import * as ajax from '../src/ajax.js' +import { getRefererInfo } from '../src/refererDetection.js' import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -20,10 +20,10 @@ const bundleStorageKey = 'cto_bundle'; const cookiesMaxAge = 13 * 30 * 24 * 60 * 60 * 1000; const pastDateString = new Date(0).toString(); -const expirationString = new Date(timestamp() + cookiesMaxAge).toString(); +const expirationString = new Date(utils.timestamp() + cookiesMaxAge).toString(); function extractProtocolHost (url, returnOnlyHost = false) { - const parsedUrl = parseUrl(url, {noDecodeWholeURL: true}) + const parsedUrl = utils.parseUrl(url, {noDecodeWholeURL: true}) return returnOnlyHost ? `${parsedUrl.hostname}` : `${parsedUrl.protocol}://${parsedUrl.hostname}${parsedUrl.port ? ':' + parsedUrl.port : ''}/`; @@ -33,37 +33,15 @@ function getFromAllStorages(key) { return storage.getCookie(key) || storage.getDataFromLocalStorage(key); } -function saveOnAllStorages(key, value, hostname) { +function saveOnAllStorages(key, value) { if (key && value) { + storage.setCookie(key, value, expirationString); storage.setDataInLocalStorage(key, value); - setCookieOnAllDomains(key, value, expirationString, hostname, true); } } -function setCookieOnAllDomains(key, value, expiration, hostname, stopOnSuccess) { - const subDomains = hostname.split('.'); - for (let i = 0; i < subDomains.length; ++i) { - // Try to write the cookie on this subdomain (we want it to be stored only on the TLD+1) - const domain = subDomains.slice(subDomains.length - i - 1, subDomains.length).join('.'); - - try { - storage.setCookie(key, value, expiration, null, '.' + domain); - - if (stopOnSuccess) { - // Try to read the cookie to check if we wrote it - const ck = storage.getCookie(key); - if (ck && ck === value) { - break; - } - } - } catch (error) { - - } - } -} - -function deleteFromAllStorages(key, hostname) { - setCookieOnAllDomains(key, '', pastDateString, hostname, true); +function deleteFromAllStorages(key) { + storage.setCookie(key, '', pastDateString); storage.removeDataFromLocalStorage(key); } @@ -87,7 +65,7 @@ function buildCriteoUsersyncUrl(topUrl, domain, bundle, areCookiesWriteable, isL return url; } -function callCriteoUserSync(parsedCriteoData, gdprString, callback) { +function callCriteoUserSync(parsedCriteoData, gdprString) { const cw = storage.cookiesAreEnabled(); const lsw = storage.localStorageIsEnabled(); const topUrl = extractProtocolHost(getRefererInfo().referer); @@ -104,32 +82,26 @@ function callCriteoUserSync(parsedCriteoData, gdprString, callback) { gdprString ); - const callbacks = { - success: response => { + ajax.ajaxBuilder()( + url, + response => { const jsonResponse = JSON.parse(response); + if (jsonResponse.bidId) { + saveOnAllStorages(bididStorageKey, jsonResponse.bidId); + } else { + deleteFromAllStorages(bididStorageKey); + } + if (jsonResponse.acwsUrl) { const urlsToCall = typeof jsonResponse.acwsUrl === 'string' ? [jsonResponse.acwsUrl] : jsonResponse.acwsUrl; - urlsToCall.forEach(url => triggerPixel(url)); + urlsToCall.forEach(url => utils.triggerPixel(url)); } else if (jsonResponse.bundle) { - saveOnAllStorages(bundleStorageKey, jsonResponse.bundle, domain); - } - - if (jsonResponse.bidId) { - saveOnAllStorages(bididStorageKey, jsonResponse.bidId, domain); - const criteoId = { criteoId: jsonResponse.bidId }; - callback(criteoId); - } else { - deleteFromAllStorages(bididStorageKey, domain); - callback(); + saveOnAllStorages(bundleStorageKey, jsonResponse.bundle); } }, - error: error => { - logError(`criteoIdSystem: unable to sync user id`, error); - callback(); - } - }; - - ajax(url, callbacks, undefined, { method: 'GET', contentType: 'application/json', withCredentials: true }); + undefined, + { method: 'GET', contentType: 'application/json', withCredentials: true } + ); } /** @type {Submodule} */ @@ -160,13 +132,9 @@ export const criteoIdSubmodule = { const gdprConsentString = hasGdprData ? consentData.consentString : undefined; let localData = getCriteoDataFromAllStorages(); + callCriteoUserSync(localData, gdprConsentString); - const result = (callback) => callCriteoUserSync(localData, gdprConsentString, callback); - - return { - id: localData.bidId ? { criteoId: localData.bidId } : undefined, - callback: result - } + return { id: localData.bidId ? { criteoId: localData.bidId } : undefined } } }; diff --git a/modules/currency.js b/modules/currency.js index 5f7add764ad..0464d9b5cdb 100644 --- a/modules/currency.js +++ b/modules/currency.js @@ -1,8 +1,8 @@ -import { logInfo, logWarn, logError, logMessage } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { createBid } from '../src/bidfactory.js'; -import CONSTANTS from '../src/constants.json'; +import { STATUS } from '../src/constants.json'; import { ajax } from '../src/ajax.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { getHook } from '../src/hook.js'; @@ -70,11 +70,11 @@ export function setConfig(config) { } if (typeof config.adServerCurrency === 'string') { - logInfo('enabling currency support', arguments); + utils.logInfo('enabling currency support', arguments); adServerCurrency = config.adServerCurrency; if (config.conversionRateFile) { - logInfo('currency using override conversionRateFile:', config.conversionRateFile); + utils.logInfo('currency using override conversionRateFile:', config.conversionRateFile); url = config.conversionRateFile; } @@ -99,7 +99,7 @@ export function setConfig(config) { initCurrency(url); } else { // currency support is disabled, setting defaults - logInfo('disabling currency support'); + utils.logInfo('disabling currency support'); resetCurrency(); } if (typeof config.bidderCurrencyDefault === 'object') { @@ -110,10 +110,10 @@ config.getConfig('currency', config => setConfig(config.currency)); function errorSettingsRates(msg) { if (defaultRates) { - logWarn(msg); - logWarn('Currency failed loading rates, falling back to currency.defaultRates'); + utils.logWarn(msg); + utils.logWarn('Currency failed loading rates, falling back to currency.defaultRates'); } else { - logError(msg); + utils.logError(msg); } } @@ -121,7 +121,7 @@ function initCurrency(url) { conversionCache = {}; currencySupportEnabled = true; - logInfo('Installing addBidResponse decorator for currency module', arguments); + utils.logInfo('Installing addBidResponse decorator for currency module', arguments); // Adding conversion function to prebid global for external module and on page use getGlobal().convertCurrency = (cpm, fromCurrency, toCurrency) => parseFloat(cpm) * getCurrencyConversion(fromCurrency, toCurrency); @@ -135,7 +135,7 @@ function initCurrency(url) { success: function (response) { try { currencyRates = JSON.parse(response); - logInfo('currencyRates set to ' + JSON.stringify(currencyRates)); + utils.logInfo('currencyRates set to ' + JSON.stringify(currencyRates)); currencyRatesLoaded = true; processBidResponseQueue(); } catch (e) { @@ -149,7 +149,7 @@ function initCurrency(url) { } function resetCurrency() { - logInfo('Uninstalling addBidResponse decorator for currency module', arguments); + utils.logInfo('Uninstalling addBidResponse decorator for currency module', arguments); getHook('addBidResponse').getHooks({hook: addBidResponseHook}).remove(); delete getGlobal().convertCurrency; @@ -172,7 +172,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { if (bidderCurrencyDefault[bidder]) { let currencyDefault = bidderCurrencyDefault[bidder]; if (bid.currency && currencyDefault !== bid.currency) { - logWarn(`Currency default '${bidder}: ${currencyDefault}' ignored. adapter specified '${bid.currency}'`); + utils.logWarn(`Currency default '${bidder}: ${currencyDefault}' ignored. adapter specified '${bid.currency}'`); } else { bid.currency = currencyDefault; } @@ -180,7 +180,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { // default to USD if currency not set if (!bid.currency) { - logWarn('Currency not specified on bid. Defaulted to "USD"'); + utils.logWarn('Currency not specified on bid. Defaulted to "USD"'); bid.currency = 'USD'; } @@ -218,8 +218,8 @@ function wrapFunction(fn, context, params) { bid.currency = adServerCurrency; } } catch (e) { - logWarn('Returning NO_BID, getCurrencyConversion threw error: ', e); - params[1] = createBid(CONSTANTS.STATUS.NO_BID, { + utils.logWarn('Returning NO_BID, getCurrencyConversion threw error: ', e); + params[1] = createBid(STATUS.NO_BID, { bidder: bid.bidderCode || bid.bidder, bidId: bid.requestId }); @@ -235,7 +235,7 @@ function getCurrencyConversion(fromCurrency, toCurrency = adServerCurrency) { let cacheKey = `${fromCurrency}->${toCurrency}`; if (cacheKey in conversionCache) { conversionRate = conversionCache[cacheKey]; - logMessage('Using conversionCache value ' + conversionRate + ' for ' + cacheKey); + utils.logMessage('Using conversionCache value ' + conversionRate + ' for ' + cacheKey); } else if (currencySupportEnabled === false) { if (fromCurrency === 'USD') { conversionRate = 1; @@ -253,7 +253,7 @@ function getCurrencyConversion(fromCurrency, toCurrency = adServerCurrency) { throw new Error('Specified adServerCurrency in config \'' + toCurrency + '\' not found in the currency rates file'); } conversionRate = rates[toCurrency]; - logInfo('getCurrencyConversion using direct ' + fromCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); + utils.logInfo('getCurrencyConversion using direct ' + fromCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); } else if (toCurrency in currencyRates.conversions) { // using reciprocal of conversion rate from toCurrency to fromCurrency rates = currencyRates.conversions[toCurrency]; @@ -262,7 +262,7 @@ function getCurrencyConversion(fromCurrency, toCurrency = adServerCurrency) { throw new Error('Specified fromCurrency \'' + fromCurrency + '\' not found in the currency rates file'); } conversionRate = roundFloat(1 / rates[fromCurrency], CURRENCY_RATE_PRECISION); - logInfo('getCurrencyConversion using reciprocal ' + fromCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); + utils.logInfo('getCurrencyConversion using reciprocal ' + fromCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); } else { // first defined currency base used as intermediary var anyBaseCurrency = Object.keys(currencyRates.conversions)[0]; @@ -280,11 +280,11 @@ function getCurrencyConversion(fromCurrency, toCurrency = adServerCurrency) { var fromIntermediateConversionRate = currencyRates.conversions[anyBaseCurrency][toCurrency]; conversionRate = roundFloat(toIntermediateConversionRate * fromIntermediateConversionRate, CURRENCY_RATE_PRECISION); - logInfo('getCurrencyConversion using intermediate ' + fromCurrency + ' thru ' + anyBaseCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); + utils.logInfo('getCurrencyConversion using intermediate ' + fromCurrency + ' thru ' + anyBaseCurrency + ' to ' + toCurrency + ' conversionRate ' + conversionRate); } } if (!(cacheKey in conversionCache)) { - logMessage('Adding conversionCache value ' + conversionRate + ' for ' + cacheKey); + utils.logMessage('Adding conversionCache value ' + conversionRate + ' for ' + cacheKey); conversionCache[cacheKey] = conversionRate; } return conversionRate; diff --git a/modules/cwireBidAdapter.js b/modules/cwireBidAdapter.js deleted file mode 100644 index c9caa78e5e7..00000000000 --- a/modules/cwireBidAdapter.js +++ /dev/null @@ -1,275 +0,0 @@ -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import { getRefererInfo } from '../src/refererDetection.js'; -import { getStorageManager } from '../src/storageManager.js'; -import {BANNER, VIDEO} from '../src/mediaTypes.js'; -import { OUTSTREAM } from '../src/video.js'; -import { - isArray, - isNumber, - generateUUID, - parseSizesInput, - deepAccess, - getParameterByName, - getValue, - getBidIdParameter, - logError, - logWarn, -} from '../src/utils.js'; -import { Renderer } from '../src/Renderer.js'; -import find from 'core-js-pure/features/array/find.js'; - -// ------------------------------------ -const BIDDER_CODE = 'cwire'; -export const ENDPOINT_URL = 'https://embed.cwi.re/delivery/prebid'; -export const RENDERER_URL = 'https://cdn.cwi.re/prebid/renderer/LATEST/renderer.min.js'; -// ------------------------------------ -export const CW_PAGE_VIEW_ID = generateUUID(); -const LS_CWID_KEY = 'cw_cwid'; -const CW_GROUPS_QUERY = 'cwgroups'; -const CW_CREATIVE_QUERY = 'cwcreative'; - -const storage = getStorageManager(); - -/** - * ------------------------------------ - * ------------------------------------ - * @param bid - * @returns {Array} - */ -export function getSlotSizes(bid) { - return parseSizesInput(getAllMediaSizes(bid)); -} - -/** - * ------------------------------------ - * ------------------------------------ - * @param bid - * @returns {*[]} - */ -export function getAllMediaSizes(bid) { - let playerSizes = deepAccess(bid, 'mediaTypes.video.playerSize'); - let videoSizes = deepAccess(bid, 'mediaTypes.video.sizes'); - let bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes'); - - const sizes = []; - - if (isArray(playerSizes)) { - playerSizes.forEach((s) => { - sizes.push(s); - }) - } - - if (isArray(videoSizes)) { - videoSizes.forEach((s) => { - sizes.push(s); - }) - } - - if (isArray(bannerSizes)) { - bannerSizes.forEach((s) => { - sizes.push(s); - }) - } - return sizes; -} - -const getQueryVariable = (variable) => { - let value = getParameterByName(variable); - if (value === '') { - value = null; - } - return value; -}; - -/** - * ------------------------------------ - * ------------------------------------ - * @param validBidRequests - * @returns {*[]} - */ -export const mapSlotsData = function(validBidRequests) { - const slots = []; - validBidRequests.forEach(bid => { - const bidObj = {}; - // get the pacement and page ids - let placementId = getValue(bid.params, 'placementId'); - let pageId = getValue(bid.params, 'pageId'); - let adUnitElementId = getValue(bid.params, 'adUnitElementId'); - // get the rest of the auction/bid/transaction info - bidObj.auctionId = getBidIdParameter('auctionId', bid); - bidObj.adUnitCode = getBidIdParameter('adUnitCode', bid); - bidObj.adUnitElementId = adUnitElementId; - bidObj.bidId = getBidIdParameter('bidId', bid); - bidObj.bidderRequestId = getBidIdParameter('bidderRequestId', bid); - bidObj.placementId = placementId; - bidObj.pageId = pageId; - bidObj.mediaTypes = getBidIdParameter('mediaTypes', bid); - bidObj.transactionId = getBidIdParameter('transactionId', bid); - bidObj.sizes = getSlotSizes(bid); - slots.push(bidObj); - }); - - return slots; -}; - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function(bid) { - bid.params = bid.params || {}; - - // if ad unit elemt id not provided - use adUnitCode by default - if (!bid.params.adUnitElementId) { - bid.params.adUnitElementId = bid.code; - } - - if (!bid.params.placementId || !isNumber(bid.params.placementId)) { - logError('placementId not provided or invalid'); - return false; - } - - if (!bid.params.pageId || !isNumber(bid.params.pageId)) { - logError('pageId not provided'); - return false; - } - - return true; - }, - - /** - * ------------------------------------ - * Make a server request from the - * list of BidRequests. - * ------------------------------------ - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function(validBidRequests, bidderRequest) { - let slots = []; - let referer; - try { - referer = getRefererInfo().referer; - slots = mapSlotsData(validBidRequests); - } catch (e) { - logWarn(e); - } - - let refgroups = []; - - const cwCreativeId = getQueryVariable(CW_CREATIVE_QUERY); - const rgQuery = getQueryVariable(CW_GROUPS_QUERY); - if (rgQuery !== null) { - refgroups = rgQuery.split(','); - } - - const localStorageCWID = storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(LS_CWID_KEY) : null; - - const payload = { - cwid: localStorageCWID, - refgroups, - cwcreative: cwCreativeId, - slots: slots, - httpRef: referer || '', - pageViewId: CW_PAGE_VIEW_ID, - }; - - return { - method: 'POST', - url: ENDPOINT_URL, - data: payload - }; - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function(serverResponse, bidRequest) { - const bidResponses = []; - - try { - if (typeof bidRequest.data === 'string') { - bidRequest.data = JSON.parse(bidRequest.data); - } - const serverBody = serverResponse.body; - serverBody.bids.forEach((br) => { - const bidReq = find(bidRequest.data.slots, bid => bid.bidId === br.requestId); - - let mediaType = BANNER; - - const bidResponse = { - requestId: br.requestId, - cpm: br.cpm, - bidderCode: BIDDER_CODE, - width: br.dimensions[0], - height: br.dimensions[1], - creativeId: br.creativeId, - currency: br.currency, - netRevenue: br.netRevenue, - ttl: br.ttl, - meta: { - advertiserDomains: br.adomains ? br.advertiserDomains : [], - }, - - }; - - // ------------------------------------ - // IF BANNER - // ------------------------------------ - - if (deepAccess(bidReq, 'mediaTypes.banner')) { - bidResponse.ad = br.html; - } - // ------------------------------------ - // IF VIDEO - // ------------------------------------ - if (deepAccess(bidReq, 'mediaTypes.video')) { - mediaType = VIDEO; - bidResponse.vastXml = br.vastXml; - bidResponse.videoScript = br.html; - const mediaTypeContext = deepAccess(bidReq, 'mediaTypes.video.context'); - if (mediaTypeContext === OUTSTREAM) { - const r = Renderer.install({ - id: bidResponse.requestId, - adUnitCode: bidReq.adUnitCode, - url: RENDERER_URL, - loaded: false, - config: { - ...deepAccess(bidReq, 'mediaTypes.video'), - ...deepAccess(br, 'outstream', {}) - } - }); - - // set renderer - try { - bidResponse.renderer = r; - bidResponse.renderer.setRender(function(bid) { - if (window.CWIRE && window.CWIRE.outstream) { - window.CWIRE.outstream.renderAd(bid); - } - }); - } catch (err) { - logWarn('Prebid Error calling setRender on newRenderer', err); - } - } - } - - bidResponse.mediaType = mediaType; - bidResponses.push(bidResponse); - }); - } catch (e) { - logWarn(e); - } - - return bidResponses; - }, -} -registerBidder(spec); diff --git a/modules/cwireBidAdapter.md b/modules/cwireBidAdapter.md deleted file mode 100644 index fc0889e05ad..00000000000 --- a/modules/cwireBidAdapter.md +++ /dev/null @@ -1,43 +0,0 @@ -# Overview - -Module Name: C-WIRE Bid Adapter -Module Type: Adagio Adapter -Maintainer: dragan@cwire.ch - -## Description - -Connects to C-WIRE demand source to fetch bids. - -## Configuration - - -Below, the list of C-WIRE params and where they can be set. - -| Param name | Global config | AdUnit config | Type | Required | -| ---------- | ------------- | ------------- | ---- | ---------| -| pageId | | x | number | YES | -| placementId | | x | number | YES | -| adUnitElementId | | x | string | NO | - -### adUnit configuration - -```javascript -var adUnits = [ - { - code: 'target_div_id', // REQUIRED - bids: [{ - bidder: 'cwire', - mediaTypes: { - banner: { - sizes: [[1, 1]], - } - }, - params: { - pageId: 1422, // required - number - placementId: 2211521, // required - number - adUnitElementId: 'other_div', // optional, div id to write to, if not set it will default to ad unit code - } - }] - } -]; -``` \ No newline at end of file diff --git a/modules/dailyhuntBidAdapter.js b/modules/dailyhuntBidAdapter.js deleted file mode 100644 index cdcc9f1d038..00000000000 --- a/modules/dailyhuntBidAdapter.js +++ /dev/null @@ -1,435 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import * as mediaTypes from '../src/mediaTypes.js'; -import {deepAccess, _map, isEmpty} from '../src/utils.js'; -import { ajax } from '../src/ajax.js'; -import find from 'core-js-pure/features/array/find.js'; -import { OUTSTREAM, INSTREAM } from '../src/video.js'; - -const BIDDER_CODE = 'dailyhunt'; -const BIDDER_ALIAS = 'dh'; -const SUPPORTED_MEDIA_TYPES = [mediaTypes.BANNER, mediaTypes.NATIVE, mediaTypes.VIDEO]; - -const PROD_PREBID_ENDPOINT_URL = 'https://pbs.dailyhunt.in/openrtb2/auction?partner='; -const PROD_PREBID_TEST_ENDPOINT_URL = 'https://qa-pbs-van.dailyhunt.in/openrtb2/auction?partner='; - -const ORTB_NATIVE_TYPE_MAPPING = { - img: { - '3': 'image', - '1': 'icon' - }, - data: { - '1': 'sponsoredBy', - '2': 'body', - '3': 'rating', - '4': 'likes', - '5': 'downloads', - '6': 'price', - '7': 'salePrice', - '8': 'phone', - '9': 'address', - '10': 'body2', - '11': 'displayUrl', - '12': 'cta' - } -} - -const ORTB_NATIVE_PARAMS = { - title: { - id: 0, - name: 'title' - }, - icon: { - id: 1, - type: 1, - name: 'img' - }, - image: { - id: 2, - type: 3, - name: 'img' - }, - sponsoredBy: { - id: 3, - name: 'data', - type: 1 - }, - body: { - id: 4, - name: 'data', - type: 2 - }, - cta: { - id: 5, - type: 12, - name: 'data' - }, - body2: { - id: 4, - name: 'data', - type: 10 - }, -}; - -// Encode URI. -const _encodeURIComponent = function (a) { - let b = window.encodeURIComponent(a); - b = b.replace(/'/g, '%27'); - return b; -} - -// Extract key from collections. -const extractKeyInfo = (collection, key) => { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i].params, key); - if (result) { - return result; - } - } - return undefined -} - -// Flattern Array. -const flatten = (arr) => { - return [].concat(...arr); -} - -const createOrtbRequest = (validBidRequests, bidderRequest) => { - let device = createOrtbDeviceObj(validBidRequests); - let user = createOrtbUserObj(validBidRequests) - let site = createOrtbSiteObj(validBidRequests, bidderRequest.refererInfo.referer) - return { - id: bidderRequest.auctionId, - imp: [], - site, - device, - user, - }; -} - -const createOrtbDeviceObj = (validBidRequests) => { - let device = { ...extractKeyInfo(validBidRequests, `device`) }; - device.ua = navigator.userAgent; - return device; -} - -const createOrtbUserObj = (validBidRequests) => ({ ...extractKeyInfo(validBidRequests, `user`) }) - -const createOrtbSiteObj = (validBidRequests, page) => { - let site = { ...extractKeyInfo(validBidRequests, `site`), page }; - let publisher = createOrtbPublisherObj(validBidRequests); - if (!site.publisher) { - site.publisher = publisher - } - return site -} - -const createOrtbPublisherObj = (validBidRequests) => ({ ...extractKeyInfo(validBidRequests, `publisher`) }) - -// get bidFloor Function for different creatives -function getBidFloor(bid, creative) { - let floorInfo = typeof (bid.getFloor) == 'function' ? bid.getFloor({ currency: 'USD', mediaType: creative, size: '*' }) : {}; - return Math.floor(floorInfo.floor || (bid.params.bidfloor ? bid.params.bidfloor : 0.0)); -} - -const createOrtbImpObj = (bid) => { - let params = bid.params - let testMode = !!bid.params.test_mode - - // Validate Banner Request. - let bannerObj = deepAccess(bid.mediaTypes, `banner`); - let nativeObj = deepAccess(bid.mediaTypes, `native`); - let videoObj = deepAccess(bid.mediaTypes, `video`); - - let imp = { - id: bid.bidId, - ext: { - dailyhunt: { - placement_id: params.placement_id, - publisher_id: params.publisher_id, - partner: params.partner_name - } - } - }; - - // Test Mode Campaign. - if (testMode) { - imp.ext.test_mode = testMode; - } - - if (bannerObj) { - imp.banner = { - ...createOrtbImpBannerObj(bid, bannerObj) - } - imp.bidfloor = getBidFloor(bid, 'banner'); - } else if (nativeObj) { - imp.native = { - ...createOrtbImpNativeObj(bid, nativeObj) - } - imp.bidfloor = getBidFloor(bid, 'native'); - } else if (videoObj) { - imp.video = { - ...createOrtbImpVideoObj(bid, videoObj) - } - imp.bidfloor = getBidFloor(bid, 'video'); - } - return imp; -} - -const createOrtbImpBannerObj = (bid, bannerObj) => { - let format = []; - bannerObj.sizes.forEach(size => format.push({ w: size[0], h: size[1] })) - - return { - id: 'banner-' + bid.bidId, - format - } -} - -const createOrtbImpNativeObj = (bid, nativeObj) => { - const assets = _map(bid.nativeParams, (bidParams, key) => { - const props = ORTB_NATIVE_PARAMS[key]; - const asset = { - required: bidParams.required & 1, - }; - if (props) { - let h = 0; - let w = 0; - - asset.id = props.id; - - if (bidParams.sizes) { - const sizes = flatten(bidParams.sizes); - w = sizes[0]; - h = sizes[1]; - } - - asset[props.name] = { - len: bidParams.len ? bidParams.len : 20, - type: props.type, - w, - h - }; - - return asset; - } - }).filter(Boolean); - let request = { - assets, - ver: '1,0' - } - return { request: JSON.stringify(request) }; -} - -const createOrtbImpVideoObj = (bid, videoObj) => { - let obj = {}; - let params = bid.params - if (!isEmpty(bid.params.video)) { - obj = { - topframe: 1, - skip: params.video.skippable || 0, - linearity: params.video.linearity || 1, - minduration: params.video.minduration || 5, - maxduration: params.video.maxduration || 60, - mimes: params.video.mimes || ['video/mp4'], - protocols: getProtocols(params.video), - w: params.video.playerSize[0][0], - h: params.video.playerSize[0][1], - }; - } else { - obj = { - mimes: ['video/mp4'], - }; - } - obj.ext = { - ...videoObj, - } - return obj; -} - -export function getProtocols({protocols}) { - let defaultValue = [2, 3, 5, 6, 7, 8]; - let listProtocols = [ - {key: 'VAST_1_0', value: 1}, - {key: 'VAST_2_0', value: 2}, - {key: 'VAST_3_0', value: 3}, - {key: 'VAST_1_0_WRAPPER', value: 4}, - {key: 'VAST_2_0_WRAPPER', value: 5}, - {key: 'VAST_3_0_WRAPPER', value: 6}, - {key: 'VAST_4_0', value: 7}, - {key: 'VAST_4_0_WRAPPER', value: 8} - ]; - if (protocols) { - return listProtocols.filter(p => { - return protocols.indexOf(p.key) !== -1 - }).map(p => p.value); - } else { - return defaultValue; - } -} - -const createServerRequest = (ortbRequest, validBidRequests, isTestMode = 'false') => ({ - method: 'POST', - url: isTestMode === 'true' ? PROD_PREBID_TEST_ENDPOINT_URL + validBidRequests[0].params.partner_name : PROD_PREBID_ENDPOINT_URL + validBidRequests[0].params.partner_name, - data: JSON.stringify(ortbRequest), - options: { - contentType: 'application/json', - withCredentials: true - }, - bids: validBidRequests -}) - -const createPrebidBannerBid = (bid, bidResponse) => ({ - requestId: bid.bidId, - cpm: bidResponse.price.toFixed(2), - creativeId: bidResponse.crid, - width: bidResponse.w, - height: bidResponse.h, - ttl: 360, - netRevenue: bid.netRevenue === 'net', - currency: 'USD', - ad: bidResponse.adm, - mediaType: 'banner', - winUrl: bidResponse.nurl, - adomain: bidResponse.adomain -}) - -const createPrebidNativeBid = (bid, bidResponse) => ({ - requestId: bid.bidId, - cpm: bidResponse.price.toFixed(2), - creativeId: bidResponse.crid, - currency: 'USD', - ttl: 360, - netRevenue: bid.netRevenue === 'net', - native: parseNative(bidResponse), - mediaType: 'native', - winUrl: bidResponse.nurl, - width: bidResponse.w, - height: bidResponse.h, - adomain: bidResponse.adomain -}) - -const parseNative = (bid) => { - let adm = JSON.parse(bid.adm) - const { assets, link, imptrackers, jstracker } = adm.native; - const result = { - clickUrl: _encodeURIComponent(link.url), - clickTrackers: link.clicktrackers || [], - impressionTrackers: imptrackers || [], - javascriptTrackers: jstracker ? [ jstracker ] : [] - }; - assets.forEach(asset => { - if (!isEmpty(asset.title)) { - result.title = asset.title.text - } else if (!isEmpty(asset.img)) { - result[ORTB_NATIVE_TYPE_MAPPING.img[asset.img.type]] = { - url: asset.img.url, - height: asset.img.h, - width: asset.img.w - } - } else if (!isEmpty(asset.data)) { - result[ORTB_NATIVE_TYPE_MAPPING.data[asset.data.type]] = asset.data.value - } - }); - - return result; -} - -const createPrebidVideoBid = (bid, bidResponse) => { - let videoBid = { - requestId: bid.bidId, - cpm: bidResponse.price.toFixed(2), - creativeId: bidResponse.crid, - width: bidResponse.w, - height: bidResponse.h, - ttl: 360, - netRevenue: bid.netRevenue === 'net', - currency: 'USD', - mediaType: 'video', - winUrl: bidResponse.nurl, - adomain: bidResponse.adomain - }; - - let videoContext = bid.mediaTypes.video.context; - switch (videoContext) { - case OUTSTREAM: - videoBid.vastXml = bidResponse.adm; - break; - case INSTREAM: - videoBid.videoCacheKey = bidResponse.ext.bidder.cacheKey; - videoBid.vastUrl = bidResponse.ext.bidder.vastUrl; - break; - } - return videoBid; -} - -const getQueryVariable = (variable) => { - let query = window.location.search.substring(1); - let vars = query.split('&'); - for (var i = 0; i < vars.length; i++) { - let pair = vars[i].split('='); - if (decodeURIComponent(pair[0]) == variable) { - return decodeURIComponent(pair[1]); - } - } - return false; -} - -export const spec = { - code: BIDDER_CODE, - - aliases: [BIDDER_ALIAS], - - supportedMediaTypes: SUPPORTED_MEDIA_TYPES, - - isBidRequestValid: bid => !!bid.params.placement_id && !!bid.params.publisher_id && !!bid.params.partner_name, - - buildRequests: function (validBidRequests, bidderRequest) { - let serverRequests = []; - - // ORTB Request. - let ortbReq = createOrtbRequest(validBidRequests, bidderRequest); - - validBidRequests.forEach((bid) => { - let imp = createOrtbImpObj(bid) - ortbReq.imp.push(imp); - }); - - serverRequests.push({ ...createServerRequest(ortbReq, validBidRequests, getQueryVariable('dh_test')) }); - - return serverRequests; - }, - - interpretResponse: function (serverResponse, request) { - const { seatbid } = serverResponse.body; - let bids = request.bids; - let prebidResponse = []; - - let seatBids = seatbid[0].bid; - - seatBids.forEach(ortbResponseBid => { - let bidId = ortbResponseBid.impid; - let actualBid = find(bids, (bid) => bid.bidId === bidId); - let bidMediaType = ortbResponseBid.ext.prebid.type - switch (bidMediaType) { - case mediaTypes.BANNER: - prebidResponse.push(createPrebidBannerBid(actualBid, ortbResponseBid)); - break; - case mediaTypes.NATIVE: - prebidResponse.push(createPrebidNativeBid(actualBid, ortbResponseBid)); - break; - case mediaTypes.VIDEO: - prebidResponse.push(createPrebidVideoBid(actualBid, ortbResponseBid)); - break; - } - }) - return prebidResponse; - }, - - onBidWon: function(bid) { - ajax(bid.winUrl, null, null, { - method: 'GET' - }) - } -} - -registerBidder(spec); diff --git a/modules/dailyhuntBidAdapter.md b/modules/dailyhuntBidAdapter.md index a08b66fb826..acfd20a4de0 100644 --- a/modules/dailyhuntBidAdapter.md +++ b/modules/dailyhuntBidAdapter.md @@ -99,7 +99,3 @@ Dailyhunt bid adapter supports Banner, Native and Video. } ]; ``` - -## latest commit has all the required support for latest version of prebid above 6.x -## Dailyhunt adapter was there till 4.x and then removed in version 5.x of prebid. -## this doc has been also submitted to https://github.com/prebid/prebid.github.io \ No newline at end of file diff --git a/modules/datablocksBidAdapter.js b/modules/datablocksBidAdapter.js index 43039e070c3..bfbe7a16fc6 100644 --- a/modules/datablocksBidAdapter.js +++ b/modules/datablocksBidAdapter.js @@ -1,6 +1,6 @@ -import { getWindowTop, isGptPubadsDefined, deepAccess, getAdUnitSizes, isEmpty } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; import { ajax } from '../src/ajax.js'; @@ -94,7 +94,7 @@ export const spec = { code: 'datablocks', // DATABLOCKS SCOPED OBJECT - db_obj: {metrics_host: 'prebid.dblks.net', metrics: [], metrics_timer: null, metrics_queue_time: 1000, vis_optout: false, source_id: 0}, + db_obj: {metrics_host: 'prebid.datablocks.net', metrics: [], metrics_timer: null, metrics_queue_time: 1000, vis_optout: false, source_id: 0}, // STORE THE DATABLOCKS BUYERID IN STORAGE store_dbid: function(dbid) { @@ -199,7 +199,7 @@ export const spec = { // GET BASIC CLIENT INFORMATION get_client_info: function () { let botTest = new BotClientTests(); - let win = getWindowTop(); + let win = utils.getWindowTop(); return { 'wiw': win.innerWidth, 'wih': win.innerHeight, @@ -226,7 +226,7 @@ export const spec = { // ADD GPT EVENT LISTENERS let scope = this; - if (isGptPubadsDefined()) { + if (utils.isGptPubadsDefined()) { if (typeof window['googletag'].pubads().addEventListener == 'function') { window['googletag'].pubads().addEventListener('impressionViewable', function(event) { scope.queue_metric({type: 'slot_view', source_id: scope.db_obj.source_id, auction_id: bid.auctionId, div_id: event.slot.getSlotElementId(), slot_id: event.slot.getSlotId().getAdUnitPath()}); @@ -306,7 +306,7 @@ export const spec = { tagid: bidRequest.params.tagid || bidRequest.adUnitCode, placement_id: bidRequest.params.placement_id || 0, secure: window.location.protocol == 'https:', - ortb2: deepAccess(bidRequest, `ortb2Imp`) || {}, + ortb2: utils.deepAccess(bidRequest, `ortb2Imp`) || {}, floor: {} } @@ -320,8 +320,8 @@ export const spec = { } // BUILD THE SIZES - if (deepAccess(bidRequest, `mediaTypes.banner`)) { - let sizes = getAdUnitSizes(bidRequest); + if (utils.deepAccess(bidRequest, `mediaTypes.banner`)) { + let sizes = utils.getAdUnitSizes(bidRequest); if (sizes.length) { imp.banner = { w: sizes[0][0], @@ -332,7 +332,7 @@ export const spec = { // ADD TO THE LIST OF IMP REQUESTS imps.push(imp); } - } else if (deepAccess(bidRequest, `mediaTypes.native`)) { + } else if (utils.deepAccess(bidRequest, `mediaTypes.native`)) { // ADD TO THE LIST OF IMP REQUESTS imp.native = createNativeRequest(bidRequest); imps.push(imp); @@ -388,12 +388,12 @@ export const spec = { }; let sourceId = validRequests[0].params.source_id || 0; - let host = validRequests[0].params.host || 'prebid.dblks.net'; + let host = validRequests[0].params.host || 'prebid.datablocks.net'; // RETURN WITH THE REQUEST AND PAYLOAD return { method: 'POST', - url: `https://${host}/openrtb/?sid=${sourceId}`, + url: `https://${sourceId}.${host}/openrtb/?sid=${sourceId}`, data: { id: bidderRequest.auctionId, imp: imps, @@ -521,15 +521,15 @@ export const spec = { const {id, img, data, title} = asset; const key = NATIVE_ID_MAP[id]; if (key) { - if (!isEmpty(title)) { + if (!utils.isEmpty(title)) { result.title = title.text - } else if (!isEmpty(img)) { + } else if (!utils.isEmpty(img)) { result[key] = { url: img.url, height: img.h, width: img.w } - } else if (!isEmpty(data)) { + } else if (!utils.isEmpty(data)) { result[key] = data.value; } } @@ -539,11 +539,11 @@ export const spec = { } let bids = []; - let resBids = deepAccess(rtbResponse, 'body.seatbid') || []; + let resBids = utils.deepAccess(rtbResponse, 'body.seatbid') || []; resBids.forEach(bid => { let resultItem = {requestId: bid.id, cpm: bid.price, creativeId: bid.crid, currency: bid.currency || 'USD', netRevenue: true, ttl: bid.ttl || 360, meta: {advertiserDomains: bid.adomain}}; - let mediaType = deepAccess(bid, 'ext.mtype') || ''; + let mediaType = utils.deepAccess(bid, 'ext.mtype') || ''; switch (mediaType) { case 'banner': bids.push(Object.assign({}, resultItem, {mediaType: BANNER, width: bid.w, height: bid.h, ad: bid.adm})); diff --git a/modules/dchain.js b/modules/dchain.js deleted file mode 100644 index 6a1bd1ebf70..00000000000 --- a/modules/dchain.js +++ /dev/null @@ -1,149 +0,0 @@ -import includes from 'core-js-pure/features/array/includes.js'; -import { config } from '../src/config.js'; -import { getHook } from '../src/hook.js'; -import { _each, isStr, isArray, isPlainObject, hasOwn, deepClone, deepAccess, logWarn, logError } from '../src/utils.js'; - -const shouldBeAString = ' should be a string'; -const shouldBeAnObject = ' should be an object'; -const shouldBeAnArray = ' should be an Array'; -const shouldBeValid = ' is not a valid dchain property'; -const MODE = { - STRICT: 'strict', - RELAXED: 'relaxed', - OFF: 'off' -}; -const MODES = []; // an array of modes -_each(MODE, mode => MODES.push(mode)); - -export function checkDchainSyntax(bid, mode) { - let dchainObj = deepClone(bid.meta.dchain); - let failPrefix = 'Detected something wrong in bid.meta.dchain object for bid:'; - let failMsg = ''; - const dchainPropList = ['ver', 'complete', 'nodes', 'ext']; - - function appendFailMsg(msg) { - failMsg += '\n' + msg; - } - - function printFailMsg() { - if (mode === MODE.STRICT) { - logError(failPrefix, bid, '\n', dchainObj, failMsg); - } else { - logWarn(failPrefix, bid, `\n`, dchainObj, failMsg); - } - } - - let dchainProps = Object.keys(dchainObj); - dchainProps.forEach(prop => { - if (!includes(dchainPropList, prop)) { - appendFailMsg(`dchain.${prop}` + shouldBeValid); - } - }); - - if (dchainObj.complete !== 0 && dchainObj.complete !== 1) { - appendFailMsg(`dchain.complete should be 0 or 1`); - } - - if (!isStr(dchainObj.ver)) { - appendFailMsg(`dchain.ver` + shouldBeAString); - } - - if (hasOwn(dchainObj, 'ext')) { - if (!isPlainObject(dchainObj.ext)) { - appendFailMsg(`dchain.ext` + shouldBeAnObject); - } - } - - if (!isArray(dchainObj.nodes)) { - appendFailMsg(`dchain.nodes` + shouldBeAnArray); - printFailMsg(); - if (mode === MODE.STRICT) return false; - } else { - const nodesPropList = ['asi', 'bsid', 'rid', 'name', 'domain', 'ext']; - dchainObj.nodes.forEach((node, index) => { - if (!isPlainObject(node)) { - appendFailMsg(`dchain.nodes[${index}]` + shouldBeAnObject); - } else { - let nodeProps = Object.keys(node); - nodeProps.forEach(prop => { - if (!includes(nodesPropList, prop)) { - appendFailMsg(`dchain.nodes[${index}].${prop}` + shouldBeValid); - } - - if (prop === 'ext') { - if (!isPlainObject(node.ext)) { - appendFailMsg(`dchain.nodes[${index}].ext` + shouldBeAnObject); - } - } else { - if (!isStr(node[prop])) { - appendFailMsg(`dchain.nodes[${index}].${prop}` + shouldBeAString); - } - } - }); - } - }); - } - - if (failMsg.length > 0) { - printFailMsg(); - if (mode === MODE.STRICT) { - return false; - } - } - return true; -} - -function isValidDchain(bid) { - let mode = MODE.STRICT; - const dchainConfig = config.getConfig('dchain'); - - if (dchainConfig && isStr(dchainConfig.validation) && MODES.indexOf(dchainConfig.validation) != -1) { - mode = dchainConfig.validation; - } - - if (mode === MODE.OFF) { - return true; - } else { - return checkDchainSyntax(bid, mode); - } -} - -export function addBidResponseHook(fn, adUnitCode, bid) { - const basicDchain = { - ver: '1.0', - complete: 0, - nodes: [] - }; - - if (deepAccess(bid, 'meta.networkId') && deepAccess(bid, 'meta.networkName')) { - basicDchain.nodes.push({ name: bid.meta.networkName, bsid: bid.meta.networkId.toString() }); - } - basicDchain.nodes.push({ name: bid.bidderCode }); - - let bidDchain = deepAccess(bid, 'meta.dchain'); - if (bidDchain && isPlainObject(bidDchain)) { - let result = isValidDchain(bid); - - if (result) { - // extra check in-case mode is OFF and there is a setup issue - if (isArray(bidDchain.nodes)) { - bid.meta.dchain.nodes.push({ asi: bid.bidderCode }); - } else { - logWarn('bid.meta.dchain.nodes did not exist or was not an array; did not append prebid dchain.', bid); - } - } else { - // remove invalid dchain - delete bid.meta.dchain; - } - } else { - bid.meta.dchain = basicDchain; - } - - fn(adUnitCode, bid); -} - -export function init() { - getHook('addBidResponse').before(addBidResponseHook, 35); -} - -init(); diff --git a/modules/dchain.md b/modules/dchain.md deleted file mode 100644 index f01b3483f3c..00000000000 --- a/modules/dchain.md +++ /dev/null @@ -1,45 +0,0 @@ -# dchain module - -Refer: -- https://iabtechlab.com/buyers-json-demand-chain/ - -## Sample code for dchain setConfig and dchain object -``` -pbjs.setConfig({ - "dchain": { - "validation": "strict" - } -}); -``` - -``` -bid.meta.dchain: { - "complete": 0, - "ver": "1.0", - "ext": {...}, - "nodes": [{ - "asi": "abc", - "bsid": "123", - "rid": "d4e5f6", - "name": "xyz", - "domain": "mno", - "ext": {...} - }, ...] -} -``` - -## Workflow -The dchain module is not enabled by default as it may not be necessary for all publishers. -If required, dchain module can be included as following -``` - $ gulp build --modules=dchain,pubmaticBidAdapter,openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter -``` - -The dchain module will validate a bidder's dchain object (if it was defined). Bidders should assign their dchain object into `bid.meta` field. If the dchain object is valid, it will remain in the bid object for later use. - -If it was not defined, the dchain will create a default dchain object for prebid. - -## Validation modes -- ```strict```: It is the default validation mode. In this mode, dchain object will not be accpeted from adapters if it is invalid. Errors are thrown for invalid dchain object. -- ```relaxed```: In this mode, errors are thrown for an invalid dchain object but the invalid dchain object is still accepted from adapters. -- ```off```: In this mode, no validations are performed and dchain object is accepted as is from adapters. \ No newline at end of file diff --git a/modules/deepintentBidAdapter.js b/modules/deepintentBidAdapter.js index 94167b92bb0..25c6ee9b25b 100644 --- a/modules/deepintentBidAdapter.js +++ b/modules/deepintentBidAdapter.js @@ -1,38 +1,13 @@ -import { generateUUID, deepSetValue, deepAccess, isArray, isInteger, logError, logWarn } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {BANNER} from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'deepintent'; const BIDDER_ENDPOINT = 'https://prebid.deepintent.com/prebid'; const USER_SYNC_URL = 'https://cdn.deepintent.com/syncpixel.html'; const DI_M_V = '1.0.0'; -export const ORTB_VIDEO_PARAMS = { - 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), - 'minduration': (value) => isInteger(value), - 'maxduration': (value) => isInteger(value), - 'protocols': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 10), - 'w': (value) => isInteger(value), - 'h': (value) => isInteger(value), - 'startdelay': (value) => isInteger(value), - 'placement': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 5), - 'linearity': (value) => [1, 2].indexOf(value) !== -1, - 'skip': (value) => [0, 1].indexOf(value) !== -1, - 'skipmin': (value) => isInteger(value), - 'skipafter': (value) => isInteger(value), - 'sequence': (value) => isInteger(value), - 'battr': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 17), - 'maxextended': (value) => isInteger(value), - 'minbitrate': (value) => isInteger(value), - 'maxbitrate': (value) => isInteger(value), - 'boxingallowed': (value) => [0, 1].indexOf(value) !== -1, - 'playbackmethod': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6), - 'playbackend': (value) => [1, 2, 3].indexOf(value) !== -1, - 'delivery': (value) => [1, 2, 3].indexOf(value) !== -1, - 'pos': (value) => [0, 1, 2, 3, 4, 5, 6, 7].indexOf(value) !== -1, - 'api': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6) -}; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], + supportedMediaTypes: [BANNER], aliases: [], // tagId is mandatory param @@ -40,38 +15,16 @@ export const spec = { let valid = false; if (bid && bid.params && bid.params.tagId) { if (typeof bid.params.tagId === 'string' || bid.params.tagId instanceof String) { - if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { - if (bid.mediaTypes[VIDEO].hasOwnProperty('context')) { - valid = true; - } - } else { - valid = true; - } + valid = true; } } return valid; }, - interpretResponse: function(bidResponse, bidRequest) { + interpretResponse: function(bidResponse, request) { let responses = []; if (bidResponse && bidResponse.body) { - try { - let bids = bidResponse.body.seatbid && bidResponse.body.seatbid[0] ? bidResponse.body.seatbid[0].bid : []; - if (bids) { - bids.forEach(bidObj => { - let newBid = formatResponse(bidObj); - let mediaType = _checkMediaType(bidObj); - if (mediaType === BANNER) { - newBid.mediaType = BANNER; - } else if (mediaType === VIDEO) { - newBid.mediaType = VIDEO; - newBid.vastXml = bidObj.adm; - } - responses.push(newBid); - }); - } - } catch (err) { - logError(err); - } + let bids = bidResponse.body.seatbid && bidResponse.body.seatbid[0] ? bidResponse.body.seatbid[0].bid : []; + responses = bids.map(bid => formatResponse(bid)) } return responses; }, @@ -79,7 +32,7 @@ export const spec = { var user = validBidRequests.map(bid => buildUser(bid)); clean(user); const openRtbBidRequest = { - id: generateUUID(), + id: utils.generateUUID(), at: 1, imp: validBidRequests.map(bid => buildImpression(bid)), site: buildSite(bidderRequest), @@ -88,12 +41,12 @@ export const spec = { }; if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(openRtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(openRtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(openRtbBidRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(openRtbBidRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(openRtbBidRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(openRtbBidRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } injectEids(openRtbBidRequest, validBidRequests); @@ -120,17 +73,6 @@ export const spec = { } }; -function _checkMediaType(bid) { - let videoRegex = new RegExp(/VAST\s+version/); - let mediaType; - if (bid.adm && bid.adm.indexOf('deepintent_wrapper') >= 0) { - mediaType = BANNER; - } else if (videoRegex.test(bid.adm)) { - mediaType = VIDEO; - } - return mediaType; -} - function clean(obj) { for (let propName in obj) { if (obj[propName] === null || obj[propName] === undefined) { @@ -158,55 +100,16 @@ function formatResponse(bid) { } function buildImpression(bid) { - let impression = {}; - impression = { + return { id: bid.bidId, tagid: bid.params.tagId || '', - secure: window.location.protocol === 'https:' ? 1 : 0, + secure: window.location.protocol === 'https' ? 1 : 0, + banner: buildBanner(bid), displaymanager: 'di_prebid', displaymanagerver: DI_M_V, ext: buildCustomParams(bid) }; - if (deepAccess(bid, 'mediaTypes.banner')) { - impression['banner'] = buildBanner(bid); - } - if (deepAccess(bid, 'mediaTypes.video')) { - impression['video'] = _buildVideo(bid); - } - return impression; } - -function _buildVideo(bid) { - const videoObj = {}; - const videoAdUnitParams = deepAccess(bid, 'mediaTypes.video', {}); - const videoBidderParams = deepAccess(bid, 'params.video', {}); - const computedParams = {}; - - if (Array.isArray(videoAdUnitParams.playerSize)) { - const tempSize = (Array.isArray(videoAdUnitParams.playerSize[0])) ? videoAdUnitParams.playerSize[0] : videoAdUnitParams.playerSize; - computedParams.w = tempSize[0]; - computedParams.h = tempSize[1]; - } - - const videoParams = { - ...computedParams, - ...videoAdUnitParams, - ...videoBidderParams - }; - - Object.keys(ORTB_VIDEO_PARAMS).forEach(paramName => { - if (videoParams.hasOwnProperty(paramName)) { - if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) { - videoObj[paramName] = videoParams[paramName]; - } else { - logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); - } - } - }); - - return videoObj; -}; - function buildCustomParams(bid) { if (bid.params && bid.params.custom) { return { @@ -231,19 +134,19 @@ function buildUser(bid) { } function injectEids(openRtbBidRequest, validBidRequests) { - const bidUserIdAsEids = deepAccess(validBidRequests, '0.userIdAsEids'); - if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { - deepSetValue(openRtbBidRequest, 'user.eids', bidUserIdAsEids); - deepSetValue(openRtbBidRequest, 'user.ext.eids', bidUserIdAsEids); + const bidUserIdAsEids = utils.deepAccess(validBidRequests, '0.userIdAsEids'); + if (utils.isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { + utils.deepSetValue(openRtbBidRequest, 'user.eids', bidUserIdAsEids); + utils.deepSetValue(openRtbBidRequest, 'user.ext.eids', bidUserIdAsEids); } } function buildBanner(bid) { - if (deepAccess(bid, 'mediaTypes.banner')) { + if (utils.deepAccess(bid, 'mediaTypes.banner')) { // Get Sizes from MediaTypes Object, Will always take first size, will be overrided by params for exact w,h - if (deepAccess(bid, 'mediaTypes.banner.sizes') && !bid.params.height && !bid.params.width) { - let sizes = deepAccess(bid, 'mediaTypes.banner.sizes'); - if (isArray(sizes) && sizes.length > 0) { + if (utils.deepAccess(bid, 'mediaTypes.banner.sizes') && !bid.params.height && !bid.params.width) { + let sizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); + if (utils.isArray(sizes) && sizes.length > 0) { return { h: sizes[0][1], w: sizes[0][0], diff --git a/modules/deepintentBidAdapter.md b/modules/deepintentBidAdapter.md index 84c375d69a4..79a6a1679e2 100644 --- a/modules/deepintentBidAdapter.md +++ b/modules/deepintentBidAdapter.md @@ -8,7 +8,7 @@ Maintainer: prebid@deepintent.com # Description -Deepintent currently supports the BANNER and VIDEO type ads through prebid js +Deepintent currently supports the BANNER type ads through prebid js Module that connects to Deepintent's demand sources. @@ -40,41 +40,6 @@ Module that connects to Deepintent's demand sources. ]; ``` -# Sample Video Ad Unit -``` -var adVideoAdUnits = [ -{ - code: 'test-div-video', - mediaTypes: { - video: { - playerSize: [640, 480], // required - context: 'instream' //required - } - }, - bids: [{ - bidder: 'deepintent', - params: { - tagId: '1300', // Required parameter // required - video: { - mimes: ['video/mp4','video/x-flv'], // required - skippable: true, // optional - minduration: 5, // optional - maxduration: 30, // optional - startdelay: 5, // optional - playbackmethod: [1,3], // optional - api: [ 1, 2 ], // optional - protocols: [ 2, 3 ], // optional - battr: [ 13, 14 ], // optional - linearity: 1, // optional - placement: 2, // optional - minbitrate: 10, // optional - maxbitrate: 10 // optional - } - } - }] -}] -``` - ###Recommended User Sync Configuration ```javascript diff --git a/modules/deltaprojectsBidAdapter.js b/modules/deltaprojectsBidAdapter.js deleted file mode 100644 index 33df5bd252e..00000000000 --- a/modules/deltaprojectsBidAdapter.js +++ /dev/null @@ -1,252 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER } from '../src/mediaTypes.js'; -import { - _each, _map, isFn, isNumber, createTrackPixelHtml, deepAccess, parseUrl, logWarn, logError -} from '../src/utils.js'; -import {config} from '../src/config.js'; - -export const BIDDER_CODE = 'deltaprojects'; -export const BIDDER_ENDPOINT_URL = 'https://d5p.de17a.com/dogfight/prebid'; -export const USERSYNC_URL = 'https://userservice.de17a.com/getuid/prebid'; - -/** -- isBidRequestValid --**/ -function isBidRequestValid(bid) { - if (!bid) return false; - - if (bid.bidder !== BIDDER_CODE) return false; - - // publisher id is required - const publisherId = deepAccess(bid, 'params.publisherId') - if (!publisherId) { - logError('Invalid bid request, missing publisher id in params'); - return false; - } - - return true; -} - -/** -- Build requests --**/ -function buildRequests(validBidRequests, bidderRequest) { - /** == shared ==**/ - // -- build id - const id = bidderRequest.auctionId; - - // -- build site - const loc = parseUrl(bidderRequest.refererInfo.referer); - const publisherId = setOnAny(validBidRequests, 'params.publisherId'); - const siteId = setOnAny(validBidRequests, 'params.siteId'); - const site = { - id: siteId, - domain: loc.hostname, - page: loc.href, - ref: loc.href, - publisher: { id: publisherId }, - }; - - // -- build device - const ua = navigator.userAgent; - const device = { - ua, - w: screen.width, - h: screen.height - } - - // -- build user, reg - let user = { ext: {} }; - const regs = { ext: {} }; - const gdprConsent = bidderRequest && bidderRequest.gdprConsent; - if (gdprConsent) { - user.ext = { consent: gdprConsent.consentString }; - if (typeof gdprConsent.gdprApplies == 'boolean') { - regs.ext.gdpr = gdprConsent.gdprApplies ? 1 : 0 - } - } - - // -- build tmax - let tmax = (bidderRequest && bidderRequest.timeout > 0) ? bidderRequest.timeout : undefined; - - // build bid specific - return validBidRequests.map(validBidRequest => { - const openRTBRequest = buildOpenRTBRequest(validBidRequest, id, site, device, user, tmax, regs); - return { - method: 'POST', - url: BIDDER_ENDPOINT_URL, - data: openRTBRequest, - options: { contentType: 'application/json' }, - bids: [validBidRequest], - }; - }); -} - -function buildOpenRTBRequest(validBidRequest, id, site, device, user, tmax, regs) { - // build cur - const currency = config.getConfig('currency.adServerCurrency') || deepAccess(validBidRequest, 'params.currency'); - const cur = currency && [currency]; - - // build impression - const impression = buildImpression(validBidRequest, currency); - - // build test - const test = deepAccess(validBidRequest, 'params.test') ? 1 : 0 - - const at = 1 - - // build source - const source = { - tid: validBidRequest.transactionId, - fd: 1, - } - - return { - id, - at, - imp: [impression], - site, - device, - user, - test, - tmax, - cur, - source, - regs, - ext: {}, - }; -} - -function buildImpression(bid, currency) { - const impression = { - id: bid.bidId, - tagid: bid.params.tagId, - ext: {}, - }; - - const bannerMediaType = deepAccess(bid, `mediaTypes.${BANNER}`); - impression.banner = buildImpressionBanner(bid, bannerMediaType); - - // bid floor - const bidFloor = getBidFloor(bid, BANNER, '*', currency); - if (bidFloor) { - impression.bidfloor = bidFloor.floor; - impression.bidfloorcur = bidFloor.currency; - } - - return impression; -} - -function buildImpressionBanner(bid, bannerMediaType) { - const bannerSizes = (bannerMediaType && bannerMediaType.sizes) || bid.sizes; - return { - format: _map(bannerSizes, ([width, height]) => ({ w: width, h: height })), - }; -} - -/** -- Interpret response --**/ -function interpretResponse(serverResponse) { - if (!serverResponse.body) { - logWarn('Response body is invalid, return !!'); - return []; - } - - const { body: { id, seatbid, cur } } = serverResponse; - if (!id || !seatbid) { - logWarn('Id / seatbid of response is invalid, return !!'); - return []; - } - - const bidResponses = []; - - _each(seatbid, seatbid => { - _each(seatbid.bid, bid => { - const bidObj = { - requestId: bid.impid, - cpm: parseFloat(bid.price), - width: parseInt(bid.w), - height: parseInt(bid.h), - creativeId: bid.crid || bid.id, - dealId: bid.dealid || null, - currency: cur, - netRevenue: true, - ttl: 60, - }; - - bidObj.mediaType = BANNER; - bidObj.ad = bid.adm; - if (bid.nurl) { - bidObj.ad += createTrackPixelHtml(decodeURIComponent(bid.nurl)); - } - if (bid.ext) { - bidObj[BIDDER_CODE] = bid.ext; - } - bidResponses.push(bidObj); - }); - }); - return bidResponses; -} - -/** -- On Bid Won -- **/ -function onBidWon(bid) { - let cpm = bid.cpm; - if (bid.currency && bid.currency !== bid.originalCurrency && typeof bid.getCpmInNewCurrency === 'function') { - cpm = bid.getCpmInNewCurrency(bid.originalCurrency); - } - const wonPrice = Math.round(cpm * 1000000); - const wonPriceMacroPatten = /\$\{AUCTION_PRICE:B64\}/g; - bid.ad = bid.ad.replace(wonPriceMacroPatten, wonPrice); -} - -/** -- Get user syncs --**/ -function getUserSyncs(syncOptions, serverResponses, gdprConsent) { - const syncs = [] - - if (syncOptions.pixelEnabled) { - let gdprParams; - if (gdprConsent) { - if (typeof gdprConsent.gdprApplies === 'boolean') { - gdprParams = `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; - } else { - gdprParams = `?gdpr_consent=${gdprConsent.consentString}`; - } - } else { - gdprParams = ''; - } - syncs.push({ - type: 'image', - url: USERSYNC_URL + gdprParams - }); - } - return syncs; -} - -/** -- Get bid floor --**/ -export function getBidFloor(bid, mediaType, size, currency) { - if (isFn(bid.getFloor)) { - const bidFloorCurrency = currency || 'USD'; - const bidFloor = bid.getFloor({currency: bidFloorCurrency, mediaType: mediaType, size: size}); - if (isNumber(bidFloor.floor)) { - return bidFloor; - } - } -} - -/** -- Helper methods --**/ -function setOnAny(collection, key) { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); - if (result) { - return result; - } - } -} - -/** -- Register -- */ -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER], - isBidRequestValid, - buildRequests, - interpretResponse, - onBidWon, - getUserSyncs, -}; - -registerBidder(spec); diff --git a/modules/deltaprojectsBidAdapter.md b/modules/deltaprojectsBidAdapter.md deleted file mode 100644 index 97cef4dd228..00000000000 --- a/modules/deltaprojectsBidAdapter.md +++ /dev/null @@ -1,32 +0,0 @@ -# Overview - -``` -Module Name: Delta Projects Bid Adapter -Module Type: Bidder Adapter -Maintainer: dev@deltaprojects.com -``` - -# Description - -Connects to Delta Projects DSP for bids. - -# Test Parameters -``` -// define banner unit -var bannerUnit = { - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300,600]], - } - }, - // Replace this object to test a new Adapter! - bids: [{ - bidder: 'deltaprojects', - params: { - publisherId: '4' //required - } - }] -}; -``` - diff --git a/modules/dgkeywordRtdProvider.js b/modules/dgkeywordRtdProvider.js index 26a8257077a..58cec36a6b9 100644 --- a/modules/dgkeywordRtdProvider.js +++ b/modules/dgkeywordRtdProvider.js @@ -7,7 +7,7 @@ * @requires module:modules/realTimeData */ -import { logMessage, deepSetValue, logError, logInfo } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getGlobal } from '../src/prebidGlobal.js'; @@ -26,19 +26,19 @@ export function getDgKeywordsAndSet(reqBidsConfigObj, callback, moduleConfig, us const url = (moduleConfig && moduleConfig.params && moduleConfig.params.url) ? moduleConfig.params.url : URL + encodeURIComponent(window.location.href); const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; let isFinish = false; - logMessage('[dgkeyword sub module]', adUnits, timeout); + utils.logMessage('[dgkeyword sub module]', adUnits, timeout); let setKeywordTargetBidders = getTargetBidderOfDgKeywords(adUnits); if (setKeywordTargetBidders.length <= 0) { - logMessage('[dgkeyword sub module] no dgkeyword targets.'); + utils.logMessage('[dgkeyword sub module] no dgkeyword targets.'); callback(); } else { - logMessage('[dgkeyword sub module] dgkeyword targets:', setKeywordTargetBidders); - logMessage('[dgkeyword sub module] get targets from profile api start.'); + utils.logMessage('[dgkeyword sub module] dgkeyword targets:', setKeywordTargetBidders); + utils.logMessage('[dgkeyword sub module] get targets from profile api start.'); ajax(url, { success: function(response) { const res = JSON.parse(response); if (!isFinish) { - logMessage('[dgkeyword sub module] get targets from profile api end.'); + utils.logMessage('[dgkeyword sub module] get targets from profile api end.'); if (res) { let keywords = {}; if (res['s'] != null && res['s'].length > 0) { @@ -60,8 +60,8 @@ export function getDgKeywordsAndSet(reqBidsConfigObj, callback, moduleConfig, us if (!reqBidsConfigObj._ignoreSetOrtb2) { // set keywrods to ortb2 let addOrtb2 = {}; - deepSetValue(addOrtb2, 'site.keywords', keywords); - deepSetValue(addOrtb2, 'user.keywords', keywords); + utils.deepSetValue(addOrtb2, 'site.keywords', keywords); + utils.deepSetValue(addOrtb2, 'user.keywords', keywords); const ortb2 = {ortb2: addOrtb2}; reqBidsConfigObj.setBidderConfig({ bidders: Object.keys(targetBidKeys), config: ortb2 }); } @@ -73,16 +73,17 @@ export function getDgKeywordsAndSet(reqBidsConfigObj, callback, moduleConfig, us }, error: function(errorStatus) { // error occur - logError('[dgkeyword sub module] profile api access error.', errorStatus); + utils.logError('[dgkeyword sub module] profile api access error.', errorStatus); callback(); } }, null, { withCredentials: true, + contentType: 'application/json', }); setTimeout(function () { if (!isFinish) { // profile api timeout - logInfo('[dgkeyword sub module] profile api timeout. [timeout: ' + timeout + 'ms]'); + utils.logInfo('[dgkeyword sub module] profile api timeout. [timeout: ' + timeout + 'ms]'); isFinish = true; } callback(); diff --git a/modules/districtmDMXBidAdapter.js b/modules/districtmDMXBidAdapter.js index f909a1f1329..a35965c4cb4 100644 --- a/modules/districtmDMXBidAdapter.js +++ b/modules/districtmDMXBidAdapter.js @@ -1,4 +1,4 @@ -import { isArray, generateUUID, deepAccess, isStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -30,7 +30,7 @@ export const spec = { interpretResponse(response, bidRequest) { response = response.body || {}; if (response.seatbid) { - if (isArray(response.seatbid)) { + if (utils.isArray(response.seatbid)) { const { seatbid } = response; let winners = seatbid.reduce((bid, ads) => { let ad = ads.bid.reduce(function (oBid, nBid) { @@ -89,7 +89,7 @@ export const spec = { let timeout = config.getConfig('bidderTimeout'); let schain = null; let dmxRequest = { - id: generateUUID(), + id: utils.generateUUID(), cur: ['USD'], tmax: (timeout - 300), test: this.test() || 0, @@ -109,17 +109,17 @@ export const spec = { let eids = []; if (bidRequest[0] && bidRequest[0].userId) { - bindUserId(eids, deepAccess(bidRequest[0], `userId.idl_env`), 'liveramp.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.id5id.uid`), 'id5-sync.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.pubcid`), 'pubcid.org', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.tdid`), 'adserver.org', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.criteoId`), 'criteo.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.britepoolid`), 'britepool.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.lipb.lipbid`), 'liveintent.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.intentiqid`), 'intentiq.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.lotamePanoramaId`), 'lotame.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.parrableId`), 'parrable.com', 1); - bindUserId(eids, deepAccess(bidRequest[0], `userId.netId`), 'netid.de', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.idl_env`), 'liveramp.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.id5id.uid`), 'id5-sync.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.pubcid`), 'pubcid.org', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.tdid`), 'adserver.org', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.criteoId`), 'criteo.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.britepoolid`), 'britepool.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.lipb.lipbid`), 'liveintent.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.intentiqid`), 'intentiq.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.lotamePanoramaId`), 'lotame.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.parrableId`), 'parrable.com', 1); + bindUserId(eids, utils.deepAccess(bidRequest[0], `userId.netId`), 'netid.de', 1); dmxRequest.user = dmxRequest.user || {}; dmxRequest.user.ext = dmxRequest.user.ext || {}; dmxRequest.user.ext.eids = eids; @@ -370,7 +370,7 @@ export function defaultSize(thebidObj) { } export function bindUserId(eids, value, source, atype) { - if (isStr(value) && Array.isArray(eids)) { + if (utils.isStr(value) && Array.isArray(eids)) { eids.push({ source, uids: [ diff --git a/modules/dmdIdSystem.js b/modules/dmdIdSystem.js index b42315d66ee..72d3518c20f 100644 --- a/modules/dmdIdSystem.js +++ b/modules/dmdIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logError, getWindowLocation } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { submodule } from '../src/hook.js'; import { ajax } from '../src/ajax.js'; @@ -46,7 +46,7 @@ export const dmdIdSubmodule = { !configParams.api_key || typeof configParams.api_key !== 'string' ) { - logError('dmd submodule requires an api_key.'); + utils.logError('dmd submodule requires an api_key.'); return; } // If cahceIdObj is null or undefined - calling AIX-API @@ -59,7 +59,7 @@ export const dmdIdSubmodule = { // Setting headers const headers = {}; headers['x-api-key'] = configParams.api_key; - headers['x-domain'] = getWindowLocation(); + headers['x-domain'] = utils.getWindowLocation(); // Response callbacks const resp = function (callback) { const callbacks = { @@ -72,12 +72,12 @@ export const dmdIdSubmodule = { responseId = responseObj.dgid; } } catch (error) { - logError(error); + utils.logError(error); } callback(responseId); }, error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; diff --git a/modules/docereeBidAdapter.js b/modules/docereeBidAdapter.js index 737a9f707db..f9f3e1bcc70 100644 --- a/modules/docereeBidAdapter.js +++ b/modules/docereeBidAdapter.js @@ -1,4 +1,4 @@ -import { tryAppendQueryString } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -14,13 +14,6 @@ export const spec = { const { placementId } = bid.params; return !!placementId }, - isGdprConsentPresent: (bid) => { - const { gdpr, gdprConsent } = bid.params; - if (gdpr == '1') { - return !!gdprConsent - } - return true - }, buildRequests: (validBidRequests) => { const serverRequests = []; const { data } = config.getConfig('doceree.user') @@ -28,19 +21,17 @@ export const spec = { const encodedUserInfo = window.btoa(encodeURIComponent(JSON.stringify(data))) validBidRequests.forEach(function(validBidRequest) { - const { publisherUrl, placementId, gdpr, gdprConsent } = validBidRequest.params; + const { publisherUrl, placementId } = validBidRequest.params; const url = publisherUrl || page let queryString = ''; - queryString = tryAppendQueryString(queryString, 'id', placementId); - queryString = tryAppendQueryString(queryString, 'publisherDomain', domain); - queryString = tryAppendQueryString(queryString, 'pubRequestedURL', encodeURIComponent(url)); - queryString = tryAppendQueryString(queryString, 'loggedInUser', encodedUserInfo); - queryString = tryAppendQueryString(queryString, 'currentUrl', url); - queryString = tryAppendQueryString(queryString, 'prebidjs', true); - queryString = tryAppendQueryString(queryString, 'token', token); - queryString = tryAppendQueryString(queryString, 'requestId', validBidRequest.bidId); - queryString = tryAppendQueryString(queryString, 'gdpr', gdpr); - queryString = tryAppendQueryString(queryString, 'gdpr_consent', gdprConsent); + queryString = utils.tryAppendQueryString(queryString, 'id', placementId); + queryString = utils.tryAppendQueryString(queryString, 'publisherDomain', domain); + queryString = utils.tryAppendQueryString(queryString, 'pubRequestedURL', encodeURIComponent(url)); + queryString = utils.tryAppendQueryString(queryString, 'loggedInUser', encodedUserInfo); + queryString = utils.tryAppendQueryString(queryString, 'currentUrl', url); + queryString = utils.tryAppendQueryString(queryString, 'prebidjs', true); + queryString = utils.tryAppendQueryString(queryString, 'token', token); + queryString = utils.tryAppendQueryString(queryString, 'requestId', validBidRequest.bidId); serverRequests.push({ method: 'GET', diff --git a/modules/docereeBidAdapter.md b/modules/docereeBidAdapter.md index 9072fb374b6..d977e11f40a 100644 --- a/modules/docereeBidAdapter.md +++ b/modules/docereeBidAdapter.md @@ -25,8 +25,6 @@ var adUnits = [ params: { placementId: 'DOC_7jm9j5eqkl0xvc5w', //required publisherUrl: document.URL || window.location.href, //optional - gdpr: '1', //optional - gdprConsent:'CPQfU1jPQfU1jG0AAAENAwCAAAAAAAAAAAAAAAAAAAAA.IGLtV_T9fb2vj-_Z99_tkeYwf95y3p-wzhheMs-8NyZeH_B4Wv2MyvBX4JiQKGRgksjLBAQdtHGlcTQgBwIlViTLMYk2MjzNKJrJEilsbO2dYGD9Pn8HT3ZCY70-vv__7v3ff_3g', //optional } } ] diff --git a/modules/dspxBidAdapter.js b/modules/dspxBidAdapter.js index 09de5254745..df0f6f3b8ea 100644 --- a/modules/dspxBidAdapter.js +++ b/modules/dspxBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -12,7 +12,7 @@ const GVLID = 602; export const spec = { code: BIDDER_CODE, gvlid: GVLID, - aliases: [], + aliases: ['dspx'], supportedMediaTypes: [BANNER, VIDEO], isBidRequestValid: function(bid) { return !!(bid.params.placement); @@ -199,7 +199,7 @@ function objectToQueryString(obj, prefix) { * @returns {boolean} True if it's a banner bid */ function isBannerRequest(bid) { - return bid.mediaType === 'banner' || !!deepAccess(bid, 'mediaTypes.banner') || !isVideoRequest(bid); + return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoRequest(bid); } /** @@ -209,7 +209,7 @@ function isBannerRequest(bid) { * @returns {boolean} True if it's a video bid */ function isVideoRequest(bid) { - return bid.mediaType === 'video' || !!deepAccess(bid, 'mediaTypes.video'); + return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video'); } /** @@ -219,7 +219,7 @@ function isVideoRequest(bid) { * @returns {object} True if it's a video bid */ function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); } /** @@ -229,7 +229,7 @@ function getVideoSizes(bid) { * @returns {object} True if it's a video bid */ function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); } /** diff --git a/modules/ebdrBidAdapter.js b/modules/ebdrBidAdapter.js index 62a3b171b74..cfbbbee61cb 100644 --- a/modules/ebdrBidAdapter.js +++ b/modules/ebdrBidAdapter.js @@ -1,4 +1,4 @@ -import { logInfo, getBidIdParameter } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'ebdr'; @@ -18,11 +18,11 @@ export const spec = { let zoneid = ''; let requestId = ''; bids.forEach(bid => { - logInfo('Log bid', bid); - let bidFloor = getBidIdParameter('bidfloor', bid.params); + utils.logInfo('Log bid', bid); + let bidFloor = utils.getBidIdParameter('bidfloor', bid.params); let whArr = getWidthAndHeight(bid); let _mediaTypes = (bid.mediaTypes && bid.mediaTypes.video) ? VIDEO : BANNER; - zoneid = getBidIdParameter('zoneid', bid.params); + zoneid = utils.getBidIdParameter('zoneid', bid.params); requestId = bid.bidderRequestId; ebdrImps.push({ id: bid.bidId, @@ -36,9 +36,9 @@ export const spec = { w: whArr[0], h: whArr[1] }; - ebdrParams['latitude'] = getBidIdParameter('latitude', bid.params); - ebdrParams['longitude'] = getBidIdParameter('longitude', bid.params); - ebdrParams['ifa'] = (getBidIdParameter('IDFA', bid.params).length > getBidIdParameter('ADID', bid.params).length) ? getBidIdParameter('IDFA', bid.params) : getBidIdParameter('ADID', bid.params); + ebdrParams['latitude'] = utils.getBidIdParameter('latitude', bid.params); + ebdrParams['longitude'] = utils.getBidIdParameter('longitude', bid.params); + ebdrParams['ifa'] = (utils.getBidIdParameter('IDFA', bid.params).length > utils.getBidIdParameter('ADID', bid.params).length) ? utils.getBidIdParameter('IDFA', bid.params) : utils.getBidIdParameter('ADID', bid.params); }); let ebdrBidReq = { id: requestId, @@ -62,8 +62,8 @@ export const spec = { }; }, interpretResponse: function(serverResponse, bidRequest) { - logInfo('Log serverResponse', serverResponse); - logInfo('Log bidRequest', bidRequest); + utils.logInfo('Log serverResponse', serverResponse); + utils.logInfo('Log bidRequest', bidRequest); let ebdrResponseImps = []; const ebdrResponseObj = serverResponse.body; if (!ebdrResponseObj || !ebdrResponseObj.seatbid || ebdrResponseObj.seatbid.length === 0 || !ebdrResponseObj.seatbid[0].bid || ebdrResponseObj.seatbid[0].bid.length === 0) { diff --git a/modules/emx_digitalBidAdapter.js b/modules/emx_digitalBidAdapter.js index 0ed23f11631..260ffe105f4 100644 --- a/modules/emx_digitalBidAdapter.js +++ b/modules/emx_digitalBidAdapter.js @@ -1,4 +1,4 @@ -import { isArray, logWarn, logError, parseUrl, deepAccess, isStr, _each, getBidIdParameter, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { Renderer } from '../src/Renderer.js'; @@ -18,11 +18,11 @@ const EIDS_SUPPORTED = [ export const emxAdapter = { validateSizes: (sizes) => { - if (!isArray(sizes) || typeof sizes[0] === 'undefined') { - logWarn(BIDDER_CODE + ': Sizes should be an array'); + if (!utils.isArray(sizes) || typeof sizes[0] === 'undefined') { + utils.logWarn(BIDDER_CODE + ': Sizes should be an array'); return false; } - return sizes.every(size => isArray(size) && size.length === 2); + return sizes.every(size => utils.isArray(size) && size.length === 2); }, checkVideoContext: (bid) => { return ((bid && bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.context) && ((bid.mediaTypes.video.context === 'instream') || (bid.mediaTypes.video.context === 'outstream'))); @@ -31,7 +31,7 @@ export const emxAdapter = { let sizes = []; bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes ? sizes = bid.mediaTypes.banner.sizes : sizes = bid.sizes; if (!emxAdapter.validateSizes(sizes)) { - logWarn(BIDDER_CODE + ': could not detect mediaType banner sizes. Assigning to bid sizes instead'); + utils.logWarn(BIDDER_CODE + ': could not detect mediaType banner sizes. Assigning to bid sizes instead'); sizes = bid.sizes } return { @@ -78,7 +78,7 @@ export const emxAdapter = { cleanProtocols: (video) => { if (video.protocols && includes(video.protocols, 7)) { // not supporting VAST protocol 7 (VAST 4.0); - logWarn(BIDDER_CODE + ': VAST 4.0 is currently not supported. This protocol has been filtered out of the request.'); + utils.logWarn(BIDDER_CODE + ': VAST 4.0 is currently not supported. This protocol has been filtered out of the request.'); video.protocols = video.protocols.filter(protocol => protocol !== 7); } return video; @@ -106,7 +106,7 @@ export const emxAdapter = { try { renderer.setRender(emxAdapter.outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; @@ -114,7 +114,7 @@ export const emxAdapter = { buildVideo: (bid) => { let videoObj = Object.assign(bid.mediaTypes.video, bid.params.video); - if (isArray(bid.mediaTypes.video.playerSize[0])) { + if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { videoObj['w'] = bid.mediaTypes.video.playerSize[0][0]; videoObj['h'] = bid.mediaTypes.video.playerSize[0][1]; } else { @@ -127,7 +127,7 @@ export const emxAdapter = { try { return decodeURIComponent(bidResponseAdm.replace(/%(?![0-9][0-9a-fA-F]+)/g, '%25')); } catch (err) { - logError('emx_digitalBidAdapter', 'error', err); + utils.logError('emx_digitalBidAdapter', 'error', err); } }, getReferrer: () => { @@ -138,7 +138,7 @@ export const emxAdapter = { } }, getSite: (refInfo) => { - let url = parseUrl(refInfo.referer); + let url = utils.parseUrl(refInfo.referer); return { domain: url.hostname, page: refInfo.referer, @@ -182,7 +182,7 @@ export const emxAdapter = { }, getUserId(bidRequests) { return ({ key, source, rtiPartner }) => { - let id = deepAccess(bidRequests, `userId.${key}`); + let id = utils.deepAccess(bidRequests, `userId.${key}`); return id ? emxAdapter.formatEid(id, source, rtiPartner) : null; }; }, @@ -203,17 +203,17 @@ export const spec = { supportedMediaTypes: [BANNER, VIDEO], isBidRequestValid: function (bid) { if (!bid || !bid.params) { - logWarn(BIDDER_CODE + ': Missing bid or bid params.'); + utils.logWarn(BIDDER_CODE + ': Missing bid or bid params.'); return false; } if (bid.bidder !== BIDDER_CODE) { - logWarn(BIDDER_CODE + ': Must use "emx_digital" as bidder code.'); + utils.logWarn(BIDDER_CODE + ': Must use "emx_digital" as bidder code.'); return false; } - if (!bid.params.tagid || !isStr(bid.params.tagid)) { - logWarn(BIDDER_CODE + ': Missing tagid param or tagid present and not type String.'); + if (!bid.params.tagid || !utils.isStr(bid.params.tagid)) { + utils.logWarn(BIDDER_CODE + ': Missing tagid param or tagid present and not type String.'); return false; } @@ -221,17 +221,17 @@ export const spec = { let sizes; bid.mediaTypes.banner.sizes ? sizes = bid.mediaTypes.banner.sizes : sizes = bid.sizes; if (!emxAdapter.validateSizes(sizes)) { - logWarn(BIDDER_CODE + ': Missing sizes in bid'); + utils.logWarn(BIDDER_CODE + ': Missing sizes in bid'); return false; } } else if (bid.mediaTypes && bid.mediaTypes.video) { if (!emxAdapter.checkVideoContext(bid)) { - logWarn(BIDDER_CODE + ': Missing video context: instream or outstream'); + utils.logWarn(BIDDER_CODE + ': Missing video context: instream or outstream'); return false; } if (!bid.mediaTypes.video.playerSize) { - logWarn(BIDDER_CODE + ': Missing video playerSize'); + utils.logWarn(BIDDER_CODE + ': Missing video playerSize'); return false; } } @@ -247,8 +247,8 @@ export const spec = { const device = emxAdapter.getDevice(); const site = emxAdapter.getSite(bidderRequest.refererInfo); - _each(validBidRequests, function (bid) { - let tagid = getBidIdParameter('tagid', bid.params); + utils._each(validBidRequests, function (bid) { + let tagid = utils.getBidIdParameter('tagid', bid.params); let bidfloor = parseFloat(getBidFloor(bid)) || 0; let isVideo = !!bid.mediaTypes.video; let data = { @@ -257,18 +257,10 @@ export const spec = { tagid, secure }; - - // adding gpid support - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.adserver.adslot'); - if (!gpid) { - gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); - } - if (gpid) { - data.ext = {gpid: gpid.toString()}; - } let typeSpecifics = isVideo ? { video: emxAdapter.buildVideo(bid) } : { banner: emxAdapter.buildBanner(bid) }; let bidfloorObj = bidfloor > 0 ? { bidfloor, bidfloorcur: DEFAULT_CUR } : {}; let emxBid = Object.assign(data, typeSpecifics, bidfloorObj); + emxImps.push(emxBid); }); @@ -372,8 +364,8 @@ export const spec = { // support floors module in prebid 5.0 function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return parseFloat(getBidIdParameter('bidfloor', bid.params)); + if (!utils.isFn(bid.getFloor)) { + return parseFloat(utils.getBidIdParameter('bidfloor', bid.params)); } let floor = bid.getFloor({ @@ -381,7 +373,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/engageyaBidAdapter.js b/modules/engageyaBidAdapter.js deleted file mode 100644 index 3e0f1d443b1..00000000000 --- a/modules/engageyaBidAdapter.js +++ /dev/null @@ -1,171 +0,0 @@ -import { BANNER, NATIVE } from '../src/mediaTypes.js'; -import { createTrackPixelHtml } from '../src/utils.js'; - -const { - registerBidder -} = require('../src/adapters/bidderFactory.js'); -const BIDDER_CODE = 'engageya'; -const ENDPOINT_URL = 'https://recs.engageya.com/rec-api/getrecs.json'; -const ENDPOINT_METHOD = 'GET'; -const SUPPORTED_SIZES = [ - [100, 75], [236, 202], [100, 100], [130, 130], [200, 200], [250, 250], [300, 272], [300, 250], [300, 230], [300, 214], [300, 187], [300, 166], [300, 150], [300, 133], [300, 120], [400, 200], [300, 200], [250, 377], [620, 410], [207, 311], [310, 166], [310, 333], [190, 106], [228, 132], [300, 174], [80, 60], [600, 500], [600, 600], [1080, 610], [1080, 610], [624, 350], [650, 1168], [1080, 1920], [300, 374], [336, 280] -]; - -function getPageUrl(bidRequest, bidderRequest) { - if (bidRequest.params.pageUrl && bidRequest.params.pageUrl != '[PAGE_URL]') { - return bidRequest.params.pageUrl; - } - if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) { - return bidderRequest.refererInfo.referer; - } - const pageUrl = (isInIframe() && document.referrer) - ? document.referrer - : window.location.href; - return encodeURIComponent(pageUrl); -} - -function isInIframe() { - try { - var isInIframe = (window.self !== window.top); - } catch (e) { - isInIframe = true; - } - return isInIframe; -} - -function getImageSrc(rec) { - return rec.thumbnail_path.indexOf('http') === -1 ? 'https:' + rec.thumbnail_path : rec.thumbnail_path; -} - -function getImpressionTrackers(rec, response) { - const responseTrackers = [response.viewPxl]; - if (!rec.trackers) { - return responseTrackers; - } - const impressionTrackers = rec.trackers.impressionPixels || []; - const viewTrackers = rec.trackers.viewPixels || []; - return [...impressionTrackers, ...viewTrackers, ...responseTrackers]; -} - -function parseNativeResponse(rec, response) { - return { - title: rec.title, - body: '', - image: { - url: getImageSrc(rec), - width: response.imageWidth, - height: response.imageHeight - }, - privacyLink: '', - clickUrl: rec.clickUrl, - displayUrl: rec.url, - cta: '', - sponsoredBy: rec.displayName, - impressionTrackers: getImpressionTrackers(rec, response), - }; -} - -function parseBannerResponse(rec, response) { - if (rec.tag) { - return rec.tag; - } - let style; - try { - let additionalData = JSON.parse(response.widget.additionalData); - const css = additionalData.css || ''; - style = css ? `` : ''; - } catch (e) { - style = ''; - } - const title = rec.title && rec.title.trim() ? `` : ''; - const displayName = rec.displayName && title ? `` : ''; - const trackers = getImpressionTrackers(rec, response) - .map(createTrackPixelHtml) - .join(''); - return `${style}`; -} - -function getImageSize(bidRequest) { - if (bidRequest.sizes && bidRequest.sizes.length > 0) { - return bidRequest.sizes[0]; - } else if (bidRequest.nativeParams && bidRequest.nativeParams.image && bidRequest.nativeParams.image.sizes) { - return bidRequest.nativeParams.image.sizes; - } - return [-1, -1]; -} - -function isValidSize([width, height]) { - if (!width || !height) { - return false; - } - return SUPPORTED_SIZES.some(([supportedWidth, supportedHeight]) => supportedWidth === width && supportedHeight === height); -} - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, NATIVE], - - isBidRequestValid: function (bidRequest) { - return bidRequest && - bidRequest.params && - bidRequest.params.hasOwnProperty('widgetId') && - bidRequest.params.hasOwnProperty('websiteId') && - !isNaN(bidRequest.params.widgetId) && - !isNaN(bidRequest.params.websiteId) && - isValidSize(getImageSize(bidRequest)); - }, - - buildRequests: function (validBidRequests, bidderRequest) { - if (!validBidRequests) { - return []; - } - return validBidRequests.map(bidRequest => { - if (bidRequest.params) { - const mediaType = bidRequest.hasOwnProperty('nativeParams') ? 1 : 2; - const [imageWidth, imageHeight] = getImageSize(bidRequest); - const widgetId = bidRequest.params.widgetId; - const websiteId = bidRequest.params.websiteId; - const pageUrl = getPageUrl(bidRequest, bidderRequest); - const bidId = bidRequest.bidId; - let finalUrl = ENDPOINT_URL + '?pubid=0&webid=' + websiteId + '&wid=' + widgetId + '&url=' + pageUrl + '&ireqid=' + bidId + '&pbtpid=' + mediaType + '&imw=' + imageWidth + '&imh=' + imageHeight; - if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprApplies && bidderRequest.consentString) { - finalUrl += '&is_gdpr=1&gdpr_consent=' + bidderRequest.consentString; - } - return { - url: finalUrl, - method: ENDPOINT_METHOD, - data: '' - }; - } - }).filter(Boolean); - }, - - interpretResponse: function (serverResponse, bidRequest) { - if (!serverResponse.body || !serverResponse.body.recs || !serverResponse.body.recs.length) { - return []; - } - var response = serverResponse.body; - var isNative = response.pbtypeId == 1; - return response.recs.map(rec => { - let bid = { - requestId: response.ireqId, - width: response.imageWidth, - height: response.imageHeight, - creativeId: rec.postId, - cpm: rec.pecpm || (rec.ecpm / 100), - currency: 'USD', - netRevenue: !!rec.pecpm, - ttl: 360, - meta: { advertiserDomains: rec.domain ? [rec.domain] : [] }, - } - if (isNative) { - bid.native = parseNativeResponse(rec, response); - } else { - bid.ad = parseBannerResponse(rec, response); - } - return bid; - }); - } -}; - -registerBidder(spec); diff --git a/modules/enrichmentFpdModule.js b/modules/enrichmentFpdModule.js index 9268c81c033..a1d815917e0 100644 --- a/modules/enrichmentFpdModule.js +++ b/modules/enrichmentFpdModule.js @@ -1,83 +1,26 @@ - /** * This module sets default values and validates ortb2 first part data * @module modules/firstPartyData */ -import { timestamp, mergeDeep } from '../src/utils.js'; -import { submodule } from '../src/hook.js'; -import { getRefererInfo } from '../src/refererDetection.js'; -import { getCoreStorageManager } from '../src/storageManager.js'; +import * as utils from '../src/utils.js'; +import { submodule } from '../src/hook.js' +import { getRefererInfo } from '../src/refererDetection.js' let ortb2 = {}; let win = (window === window.top) ? window : window.top; -export const coreStorage = getCoreStorageManager('enrichmentFpd'); - -/** - * Find the root domain - * @param {string|undefined} fullDomain - * @return {string} -*/ -export function findRootDomain(fullDomain = window.location.hostname) { - if (!coreStorage.cookiesAreEnabled()) { - return fullDomain; - } - - const domainParts = fullDomain.split('.'); - if (domainParts.length == 2) { - return fullDomain; - } - let rootDomain; - let continueSearching; - let startIndex = -2; - const TEST_COOKIE_NAME = `_rdc${Date.now()}`; - const TEST_COOKIE_VALUE = 'writeable'; - do { - rootDomain = domainParts.slice(startIndex).join('.'); - let expirationDate = new Date(timestamp() + 10 * 1000).toUTCString(); - - // Write a test cookie - coreStorage.setCookie( - TEST_COOKIE_NAME, - TEST_COOKIE_VALUE, - expirationDate, - 'Lax', - rootDomain, - undefined - ); - - // See if the write was successful - const value = coreStorage.getCookie(TEST_COOKIE_NAME, undefined); - if (value === TEST_COOKIE_VALUE) { - continueSearching = false; - // Delete our test cookie - coreStorage.setCookie( - TEST_COOKIE_NAME, - '', - 'Thu, 01 Jan 1970 00:00:01 GMT', - undefined, - rootDomain, - undefined - ); - } else { - startIndex += -1; - continueSearching = Math.abs(startIndex) <= domainParts.length; - } - } while (continueSearching); - return rootDomain; -} /** * Checks for referer and if exists merges into ortb2 global data */ function setReferer() { - if (getRefererInfo().referer) mergeDeep(ortb2, { site: { ref: getRefererInfo().referer } }); + if (getRefererInfo().referer) utils.mergeDeep(ortb2, { site: { ref: getRefererInfo().referer } }); } /** * Checks for canonical url and if exists merges into ortb2 global data */ function setPage() { - if (getRefererInfo().canonicalUrl) mergeDeep(ortb2, { site: { page: getRefererInfo().canonicalUrl } }); + if (getRefererInfo().canonicalUrl) utils.mergeDeep(ortb2, { site: { page: getRefererInfo().canonicalUrl } }); } /** @@ -94,10 +37,7 @@ function setDomain() { let domain = parseDomain(getRefererInfo().canonicalUrl) - if (domain) { - mergeDeep(ortb2, { site: { domain: domain } }); - mergeDeep(ortb2, { site: { publisher: { domain: findRootDomain(domain) } } }); - }; + if (domain) utils.mergeDeep(ortb2, { site: { domain: domain } }); } /** @@ -115,7 +55,7 @@ function setDimensions() { height = window.innerHeight || window.document.documentElement.clientHeight || window.document.body.clientHeight; } - mergeDeep(ortb2, { device: { w: width, h: height } }); + utils.mergeDeep(ortb2, { device: { w: width, h: height } }); } /** @@ -130,7 +70,7 @@ function setKeywords() { keywords = window.document.querySelector("meta[name='keywords']"); } - if (keywords && keywords.content) mergeDeep(ortb2, { site: { keywords: keywords.content.replace(/\s/g, '') } }); + if (keywords && keywords.content) utils.mergeDeep(ortb2, { site: { keywords: keywords.content.replace(/\s/g, '') } }); } /** @@ -154,7 +94,7 @@ function runEnrichments() { export function initSubmodule(fpdConf, data) { resetOrtb2(); - return (!fpdConf.skipEnrichments) ? mergeDeep(runEnrichments(), data) : data; + return (!fpdConf.skipEnrichments) ? utils.mergeDeep(runEnrichments(), data) : data; } /** @type {firstPartyDataSubmodule} */ diff --git a/modules/eplanningAnalyticsAdapter.js b/modules/eplanningAnalyticsAdapter.js index fb77014400c..08db2f2ca9d 100644 --- a/modules/eplanningAnalyticsAdapter.js +++ b/modules/eplanningAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { logError } from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; const CONSTANTS = require('../src/constants.json'); @@ -110,7 +110,7 @@ eplAnalyticsAdapter.originEnableAnalytics = eplAnalyticsAdapter.enableAnalytics; eplAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.ci) { - logError('Client ID (ci) option is not defined. Analytics won\'t work'); + utils.logError('Client ID (ci) option is not defined. Analytics won\'t work'); return; } diff --git a/modules/eplanningBidAdapter.js b/modules/eplanningBidAdapter.js index 330754091a1..dd96353dea3 100644 --- a/modules/eplanningBidAdapter.js +++ b/modules/eplanningBidAdapter.js @@ -1,4 +1,4 @@ -import { isEmpty, getWindowSelf, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -7,10 +7,10 @@ export const storage = getStorageManager(); const BIDDER_CODE = 'eplanning'; const rnd = Math.random(); -const DEFAULT_SV = 'pbjs.e-planning.net'; +const DEFAULT_SV = 'ads.us.e-planning.net'; const DEFAULT_ISV = 'i.e-planning.net'; const PARAMS = ['ci', 'sv', 't', 'ml', 'sn']; -const DOLLAR_CODE = 'USD'; +const DOLLARS = 'USD'; const NET_REVENUE = true; const TTL = 120; const NULL_SIZE = '1x1'; @@ -102,9 +102,9 @@ export const spec = { const response = serverResponse.body; let bidResponses = []; - if (response && !isEmpty(response.sp)) { + if (response && !utils.isEmpty(response.sp)) { response.sp.forEach(space => { - if (!isEmpty(space.a)) { + if (!utils.isEmpty(space.a)) { space.a.forEach(ad => { const bidResponse = { requestId: request.adUnitToBidId[space.k], @@ -115,7 +115,7 @@ export const spec = { ttl: TTL, creativeId: ad.crid, netRevenue: NET_REVENUE, - currency: DOLLAR_CODE, + currency: DOLLARS, }; if (ad.adom) { bidResponse.meta = { @@ -132,9 +132,9 @@ export const spec = { }, getUserSyncs: function(syncOptions, serverResponses) { const syncs = []; - const response = !isEmpty(serverResponses) && serverResponses[0].body; + const response = !utils.isEmpty(serverResponses) && serverResponses[0].body; - if (response && !isEmpty(response.cs)) { + if (response && !utils.isEmpty(response.cs)) { const responseSyncs = response.cs; responseSyncs.forEach(sync => { if (typeof sync === 'string' && syncOptions.pixelEnabled) { @@ -159,7 +159,7 @@ function getUserAgent() { return window.navigator.userAgent; } function getInnerWidth() { - return getWindowSelf().innerWidth; + return utils.getWindowSelf().innerWidth; } function isMobileUserAgent() { return getUserAgent().match(/(mobile)|(ip(hone|ad))|(android)|(blackberry)|(nokia)|(phone)|(opera\smini)/i); @@ -216,7 +216,7 @@ function compareSizesByPriority(size1, size2) { } function getSizesSortedByPriority(sizes) { - return parseSizesInput(sizes).sort(compareSizesByPriority); + return utils.parseSizesInput(sizes).sort(compareSizesByPriority); } function getSize(bid, first) { diff --git a/modules/etargetBidAdapter.js b/modules/etargetBidAdapter.js index f7d552b1b09..51f2759d256 100644 --- a/modules/etargetBidAdapter.js +++ b/modules/etargetBidAdapter.js @@ -1,4 +1,4 @@ -import { deepSetValue, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -145,7 +145,7 @@ export const spec = { bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent; } if (bid.adomain) { - deepSetValue(bidObject, 'meta.advertiserDomains', Array.isArray(bid.adomain) ? bid.adomain : [bid.adomain]); + utils.deepSetValue(bidObject, 'meta.advertiserDomains', Array.isArray(bid.adomain) ? bid.adomain : [bid.adomain]); } bidRespones.push(bidObject); } @@ -165,7 +165,7 @@ export const spec = { } }; function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return null; } let floor = bid.getFloor({ @@ -173,7 +173,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor)) { + if (utils.isPlainObject(floor) && !isNaN(floor.floor)) { return floor.floor; } return null; diff --git a/modules/express.js b/modules/express.js index 0b1780e3c26..f4a76daefdf 100644 --- a/modules/express.js +++ b/modules/express.js @@ -1,4 +1,5 @@ -import { logMessage, logWarn, logError, logInfo } from '../src/utils.js'; + +import * as utils from '../src/utils.js'; const MODULE_NAME = 'express'; @@ -13,10 +14,10 @@ const MODULE_NAME = 'express'; * @param {Object[]} [adUnits = pbjs.adUnits] - an array of adUnits for express to operate on. */ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { - logMessage('loading ' + MODULE_NAME); + utils.logMessage('loading ' + MODULE_NAME); if (adUnits.length === 0) { - logWarn('no valid adUnits found, not loading ' + MODULE_NAME); + utils.logWarn('no valid adUnits found, not loading ' + MODULE_NAME); } // store gpt slots in a more performant hash lookup by elementId (adUnit code) @@ -26,7 +27,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { if (adUnit.code && adUnit.bids) { cache[adUnit.code] = adUnit; } else { - logError('misconfigured adUnit', null, adUnit); + utils.logError('misconfigured adUnit', null, adUnit); } return cache; }, {}); @@ -38,10 +39,10 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { var gpt = window.googletag; var pads = gpt.pubads; if (!gpt.display || !gpt.enableServices || typeof pads !== 'function' || !pads().refresh || !pads().disableInitialLoad || !pads().getSlots || !pads().enableSingleRequest) { - logError('could not bind to gpt googletag api'); + utils.logError('could not bind to gpt googletag api'); return; } - logMessage('running'); + utils.logMessage('running'); // function to convert google tag slot sizes to [[w,h],...] function mapGptSlotSizes(aGPTSlotSizes) { @@ -50,7 +51,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { try { aSlotSizes.push([aGPTSlotSizes[i].getWidth(), aGPTSlotSizes[i].getHeight()]); } catch (e) { - logWarn('slot size ' + aGPTSlotSizes[i].toString() + ' not supported by' + MODULE_NAME); + utils.logWarn('slot size ' + aGPTSlotSizes[i].toString() + ' not supported by' + MODULE_NAME); } } return aSlotSizes; @@ -109,7 +110,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { // - else run an auction and call the real fGptRefresh() to // initiate the DFP request gpt.display = function (sElementId) { - logInfo('display:', sElementId); + utils.logInfo('display:', sElementId); // call original gpt display() function fGptDisplay.apply(gpt, arguments); @@ -156,7 +157,7 @@ $$PREBID_GLOBAL$$.express = function(adUnits = $$PREBID_GLOBAL$$.adUnits) { // override gpt refresh() function // - run auctions for provided gpt slots, then initiate ad-server call pads().refresh = function (aGptSlots, options) { - logInfo('refresh:', aGptSlots); + utils.logInfo('refresh:', aGptSlots); // get already displayed adUnits from aGptSlots if provided, else all defined gptSlots aGptSlots = defaultSlots(aGptSlots); var adUnits = pickAdUnits(/* mutated: */ aGptSlots).filter(function (adUnit) { diff --git a/modules/fabrickIdSystem.js b/modules/fabrickIdSystem.js index 08eb2d4f043..bb838788f07 100644 --- a/modules/fabrickIdSystem.js +++ b/modules/fabrickIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getRefererInfo } from '../src/refererDetection.js'; @@ -47,7 +47,7 @@ export const fabrickIdSubmodule = { window.fabrickMod1(configParams, consentData, cacheIdObj); } if (!configParams || !configParams.apiKey || typeof configParams.apiKey !== 'string') { - logError('fabrick submodule requires an apiKey.'); + utils.logError('fabrick submodule requires an apiKey.'); return; } try { @@ -96,7 +96,7 @@ export const fabrickIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - logError(error); + utils.logError(error); responseObj = {}; } } @@ -104,7 +104,7 @@ export const fabrickIdSubmodule = { } }, error: error => { - logError(`fabrickId fetch encountered an error`, error); + utils.logError(`fabrickId fetch encountered an error`, error); callback(); } }; @@ -112,10 +112,10 @@ export const fabrickIdSubmodule = { }; return {callback: resp}; } catch (e) { - logError(`fabrickIdSystem encountered an error`, e); + utils.logError(`fabrickIdSystem encountered an error`, e); } } catch (e) { - logError(`fabrickIdSystem encountered an error`, e); + utils.logError(`fabrickIdSystem encountered an error`, e); } } }; diff --git a/modules/feedadBidAdapter.js b/modules/feedadBidAdapter.js index 6fb39c49ec8..54a4ef0c998 100644 --- a/modules/feedadBidAdapter.js +++ b/modules/feedadBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; import {ajax} from '../src/ajax.js'; @@ -107,15 +107,15 @@ const BID_METADATA = {}; * @return {boolean} true if the bid is valid */ function isBidRequestValid(bid) { - const clientToken = deepAccess(bid, 'params.clientToken'); + const clientToken = utils.deepAccess(bid, 'params.clientToken'); if (!clientToken || !isValidClientToken(clientToken)) { - logWarn(TAG, "missing or invalid parameter 'clientToken'. found value:", clientToken); + utils.logWarn(TAG, "missing or invalid parameter 'clientToken'. found value:", clientToken); return false; } - const placementId = deepAccess(bid, 'params.placementId'); + const placementId = utils.deepAccess(bid, 'params.placementId'); if (!placementId || !isValidPlacementId(placementId)) { - logWarn(TAG, "missing or invalid parameter 'placementId'. found value:", placementId); + utils.logWarn(TAG, "missing or invalid parameter 'placementId'. found value:", placementId); return false; } @@ -176,13 +176,13 @@ function isMediaTypesEmpty(mediaTypes) { * @return {FeedAdApiBidRequest} */ function createApiBidRParams(request) { - return Object.assign({}, request.params, { + return { ad_type: 0, client_token: request.params.clientToken, placement_id: request.params.placementId, sdk_version: `prebid_${VERSION}`, app_hybrid: false, - }); + }; } /** diff --git a/modules/feedadBidAdapter.md b/modules/feedadBidAdapter.md index fc3537ec331..6f705df36b5 100644 --- a/modules/feedadBidAdapter.md +++ b/modules/feedadBidAdapter.md @@ -26,7 +26,6 @@ Prebid.JS adapter that connects to the FeedAd demand sources. params: { clientToken: 'your-client-token' // see below for more info placementId: 'your-placement-id' // see below for more info - decoration: 'decoration parameters' // optional, see below for info } } ] @@ -36,8 +35,7 @@ Prebid.JS adapter that connects to the FeedAd demand sources. # Required Parameters -| Parameter | Description | -|---------------| ----------- | +| Parameter | Description | +| --------- | ----------- | | `clientToken` | Your FeedAd web client token. You can view your client token inside the FeedAd admin panel. | | `placementId` | You can choose placement IDs yourself. A placement ID should be named after the ad position inside your product. For example, if you want to display an ad inside a list of news articles, you could name it "ad-news-overview".
A placement ID may consist of lowercase `a-z`, `0-9`, `-` and `_`. You do not have to manually create the placement IDs before using them. Just specify them within the code, and they will appear in the FeedAd admin panel after the first request.
[Learn more](/concept/feed_ad/index.html) about Placement IDs and how they are grouped to play the same Creative. | -| `decoration` | Optional. If you want to apply a [decoration](https://docs.feedad.com/web/feed_ad/#decorations) to the ad. diff --git a/modules/fintezaAnalyticsAdapter.js b/modules/fintezaAnalyticsAdapter.js index 12abd2d0efd..8729035491f 100644 --- a/modules/fintezaAnalyticsAdapter.js +++ b/modules/fintezaAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { parseUrl, logError } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; const storage = getStorageManager(); @@ -28,7 +28,7 @@ function getPageInfo() { } if (document.referrer) { - pageInfo.referrerDomain = parseUrl(document.referrer).hostname; + pageInfo.referrerDomain = utils.parseUrl(document.referrer).hostname; } return pageInfo; @@ -399,7 +399,7 @@ function sendTrackRequest(trackData) { ); saveTrackRequestTime(); } catch (err) { - logError('Error on send data: ', err); + utils.logError('Error on send data: ', err); } } @@ -424,7 +424,7 @@ fntzAnalyticsAdapter.originEnableAnalytics = fntzAnalyticsAdapter.enableAnalytic fntzAnalyticsAdapter.enableAnalytics = function (config) { if (!config.options.id) { - logError('Client ID (id) option is not defined. Analytics won\'t work'); + utils.logError('Client ID (id) option is not defined. Analytics won\'t work'); return; } diff --git a/modules/flocIdSystem.js b/modules/flocIdSystem.js index 0cff7e86d73..e4bd31e49df 100644 --- a/modules/flocIdSystem.js +++ b/modules/flocIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logInfo, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {submodule} from '../src/hook.js' const MODULE_NAME = 'flocId'; @@ -45,7 +45,7 @@ function encodeId(value) { const result = {}; if (value) { result.flocId = value; - logInfo('Decoded value ' + JSON.stringify(result)); + utils.logInfo('Decoded value ' + JSON.stringify(result)); return result; } return undefined; @@ -78,7 +78,7 @@ export const flocIdSubmodule = { // Block usage of storage of cohort ID const checkStorage = (config && config.storage); if (checkStorage) { - logError('User ID - flocId submodule storage should not defined'); + utils.logError('User ID - flocId submodule storage should not defined'); return; } // Validate feature is enabled @@ -94,10 +94,10 @@ export const flocIdSubmodule = { let returnCallback = (cb) => { getFlocData((data) => { returnCallback = () => { return data; } - logInfo('Cohort id: ' + JSON.stringify(data)); + utils.logInfo('Cohort id: ' + JSON.stringify(data)); cb(data); }, (err) => { - logInfo(err); + utils.logInfo(err); cb(undefined); }); }; diff --git a/modules/fluctBidAdapter.js b/modules/fluctBidAdapter.js deleted file mode 100644 index 2aa86077991..00000000000 --- a/modules/fluctBidAdapter.js +++ /dev/null @@ -1,126 +0,0 @@ -import { _each, isEmpty } from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import URLSearchParams from 'core-js-pure/web/url-search-params' - -const BIDDER_CODE = 'fluct'; -const END_POINT = 'https://hb.adingo.jp/prebid'; -const VERSION = '1.2'; -const NET_REVENUE = true; -const TTL = 300; - -export const spec = { - code: BIDDER_CODE, - aliases: ['adingo'], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: (bid) => { - return !!(bid.params.groupId && bid.params.tagId); - }, - - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids. - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: (validBidRequests, bidderRequest) => { - const serverRequests = []; - const referer = bidderRequest.refererInfo.referer; - - _each(validBidRequests, (request) => { - const data = Object(); - - data.referer = referer; - data.adUnitCode = request.adUnitCode; - data.bidId = request.bidId; - data.transactionId = request.transactionId; - - data.sizes = []; - _each(request.sizes, (size) => { - data.sizes.push({ - w: size[0], - h: size[1] - }); - }); - - data.params = request.params; - const searchParams = new URLSearchParams(request.params); - - serverRequests.push({ - method: 'POST', - url: END_POINT + '?' + searchParams.toString(), - options: { - contentType: 'application/json', - withCredentials: true, - customHeaders: { - 'x-fluct-app': 'prebid/fluctBidAdapter', - 'x-fluct-version': VERSION, - 'x-openrtb-version': 2.5 - } - }, - data: data - }); - }); - - return serverRequests; - }, - - /* - * Unpack the respnse from the server into a list of bids. - * - * @param {serverResponse} serverResponse A successful response from the server. - * @return {bid[]} An array of bids which weer nested inside the server. - */ - interpretResponse: (serverResponse, serverRequest) => { - const bidResponses = []; - - const res = serverResponse.body; - if (!isEmpty(res) && !isEmpty(res.seatbid) && !isEmpty(res.seatbid[0].bid)) { - const bid = res.seatbid[0].bid[0]; - const dealId = bid.dealid; - const beaconUrl = bid.burl; - const callImpBeacon = ``; - let data = { - bidderCode: BIDDER_CODE, - requestId: res.id, - currency: res.cur, - cpm: parseFloat(bid.price) || 0, - netRevenue: NET_REVENUE, - width: bid.w, - height: bid.h, - creativeId: bid.crid, - ttl: TTL, - ad: bid.adm + callImpBeacon, - meta: { - advertiserDomains: bid.adomain || [], - }, - }; - if (!isEmpty(dealId)) { - data.dealId = dealId; - } - bidResponses.push(data); - } - return bidResponses; - }, - - /* - * Register the user sync pixels which should be dropped after the auction. - * - * @params {syncOptions} syncOptions which user syncs are allowed? - * @params {ServerResponse[]} serverResponses List of server's responses. - * @return {UserSync[]} The user syncs which should be dropped. - * - */ - getUserSyncs: (syncOptions, serverResponses) => { - return []; - }, -}; - -registerBidder(spec); diff --git a/modules/freewheel-sspBidAdapter.js b/modules/freewheel-sspBidAdapter.js index eca31dd5a95..fa2f7b4cd6b 100644 --- a/modules/freewheel-sspBidAdapter.js +++ b/modules/freewheel-sspBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -72,7 +72,7 @@ function getPricing(xmlNode) { price: priceNode.textContent || priceNode.innerText }; } else { - logWarn('PREBID - ' + BIDDER_CODE + ': No bid received or missing pricing extension.'); + utils.logWarn('PREBID - ' + BIDDER_CODE + ': No bid received or missing pricing extension.'); } return princingData; @@ -312,12 +312,6 @@ export const spec = { requestParams._fw_us_privacy = bidderRequest.uspConsent; } - // Add schain object - var schain = currentBidRequest.schain; - if (schain) { - requestParams.schain = schain; - } - var vastParams = currentBidRequest.params.vastUrlParams; if (typeof vastParams === 'object') { for (var key in vastParams) { @@ -335,7 +329,7 @@ export const spec = { var playerSize = []; if (currentBidRequest.mediaTypes.video && currentBidRequest.mediaTypes.video.playerSize) { // If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3 - if (isArray(currentBidRequest.mediaTypes.video.playerSize[0])) { + if (utils.isArray(currentBidRequest.mediaTypes.video.playerSize[0])) { playerSize = currentBidRequest.mediaTypes.video.playerSize[0]; } else { playerSize = currentBidRequest.mediaTypes.video.playerSize; @@ -377,7 +371,7 @@ export const spec = { var playerSize = []; if (bidrequest.mediaTypes.video && bidrequest.mediaTypes.video.playerSize) { // If mediaTypes is video, get size from mediaTypes.video.playerSize per http://prebid.org/blog/pbjs-3 - if (isArray(bidrequest.mediaTypes.video.playerSize[0])) { + if (utils.isArray(bidrequest.mediaTypes.video.playerSize[0])) { playerSize = bidrequest.mediaTypes.video.playerSize[0]; } else { playerSize = bidrequest.mediaTypes.video.playerSize; @@ -399,7 +393,7 @@ export const spec = { var parser = new DOMParser(); xmlDoc = parser.parseFromString(serverResponse, 'application/xml'); } catch (err) { - logWarn('Prebid.js - ' + BIDDER_CODE + ' : ' + err); + utils.logWarn('Prebid.js - ' + BIDDER_CODE + ' : ' + err); return; } @@ -426,7 +420,7 @@ export const spec = { currency: princingData.currency, netRevenue: true, ttl: 360, - meta: { advertiserDomains: princingData.adomain && isArray(princingData.adomain) ? princingData.adomain : [] }, + meta: { advertiserDomains: princingData.adomain && utils.isArray(princingData.adomain) ? princingData.adomain : [] }, dealId: dealId, campaignId: campaignId, bannerId: bannerId diff --git a/modules/futureads.md b/modules/futureads.md deleted file mode 100644 index 7b1c1d55b7f..00000000000 --- a/modules/futureads.md +++ /dev/null @@ -1,48 +0,0 @@ -# Overview -Module Name: Future Ads Bidder Adapter -Module Type: Bidder Adapter -Maintainer: contact@futureads.io -# Description -Connects to Future Ads demand source to fetch bids. -Banner and Video formats are supported. -Please use ```futureads``` as the bidder code. -# Test Parameters -``` -var adUnits = [ - { - code: 'desktop-banner-ad-div', - sizes: [[300, 250]], // a display size - bids: [ - { - bidder: "futureads", - params: { - zone: '2eb6bd58-865c-47ce-af7f-a918108c3fd2' - } - } - ] - },{ - code: 'mobile-banner-ad-div', - sizes: [[300, 50]], // a mobile size - bids: [ - { - bidder: "futureads", - params: { - zone: '62211486-c50b-4356-9f0f-411778d31fcc' - } - } - ] - },{ - code: 'video-ad', - sizes: [[300, 50]], - mediaType: 'video', - bids: [ - { - bidder: "futureads", - params: { - zone: 'ebeb1e79-8cb4-4473-b2d0-2e24b7ff47fd' - } - } - ] - }, -]; -``` diff --git a/modules/gamoshiBidAdapter.js b/modules/gamoshiBidAdapter.js index 34b164f26ca..68233ce7814 100644 --- a/modules/gamoshiBidAdapter.js +++ b/modules/gamoshiBidAdapter.js @@ -1,4 +1,4 @@ -import { isFn, isPlainObject, isStr, isNumber, getDNT, deepSetValue, inIframe, isArray, deepAccess, logError, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {Renderer} from '../src/Renderer.js'; @@ -40,7 +40,7 @@ export const helper = { return BANNER; }, getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return bid.params.bidfloor ? bid.params.bidfloor : null; } @@ -50,7 +50,7 @@ export const helper = { currency: 'USD' }); - if (isPlainObject(bidFloor) && !isNaN(bidFloor.floor) && bidFloor.currency === 'USD') { + if (utils.isPlainObject(bidFloor) && !isNaN(bidFloor.floor) && bidFloor.currency === 'USD') { return bidFloor.floor; } @@ -64,10 +64,10 @@ export const spec = { supportedMediaTypes: ['banner', 'video'], isBidRequestValid: function (bid) { - return !!bid.params.supplyPartnerId && isStr(bid.params.supplyPartnerId) && - (!bid.params['rtbEndpoint'] || isStr(bid.params['rtbEndpoint'])) && - (!bid.params.bidfloor || isNumber(bid.params.bidfloor)) && - (!bid.params['adpos'] || isNumber(bid.params['adpos'])) && + return !!bid.params.supplyPartnerId && utils.isStr(bid.params.supplyPartnerId) && + (!bid.params['rtbEndpoint'] || utils.isStr(bid.params['rtbEndpoint'])) && + (!bid.params.bidfloor || utils.isNumber(bid.params.bidfloor)) && + (!bid.params['adpos'] || utils.isNumber(bid.params['adpos'])) && (!bid.params['protocols'] || Array.isArray(bid.params['protocols'])) && (!bid.params.instl || bid.params.instl === 0 || bid.params.instl === 1); }, @@ -88,7 +88,7 @@ export const spec = { }, device: { ua: navigator.userAgent, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, h: screen.height, w: screen.width, language: navigator.language @@ -107,16 +107,16 @@ export const spec = { consent_required: gdprConsent.gdprApplies }; - deepSetValue(rtbBidRequest, 'regs.ext.gdpr', gdprConsent.gdprApplies === true ? 1 : 0); - deepSetValue(rtbBidRequest, 'user.ext.consent', gdprConsent.consentString); + utils.deepSetValue(rtbBidRequest, 'regs.ext.gdpr', gdprConsent.gdprApplies === true ? 1 : 0); + utils.deepSetValue(rtbBidRequest, 'user.ext.consent', gdprConsent.consentString); } if (validBidRequests[0].schain) { - deepSetValue(rtbBidRequest, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(rtbBidRequest, 'source.ext.schain', validBidRequests[0].schain); } if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(rtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(rtbBidRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); } const imp = { @@ -138,7 +138,7 @@ export const spec = { w: sizes.length ? sizes[0][0] : 300, h: sizes.length ? sizes[0][1] : 250, pos: params.pos || 0, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 } }); rtbBidRequest.imp.push(bannerImp); @@ -166,10 +166,10 @@ export const spec = { } }); - if (isArray(playerSize[0])) { + if (utils.isArray(playerSize[0])) { videoImp.video.w = playerSize[0][0]; videoImp.video.h = playerSize[0][1]; - } else if (isNumber(playerSize[0])) { + } else if (utils.isNumber(playerSize[0])) { videoImp.video.w = playerSize[0]; videoImp.video.h = playerSize[1]; } else { @@ -183,8 +183,8 @@ export const spec = { let eids = []; if (bidRequest && bidRequest.userId) { - addExternalUserId(eids, deepAccess(bidRequest, `userId.id5id.uid`), 'id5-sync.com', 'ID5ID'); - addExternalUserId(eids, deepAccess(bidRequest, `userId.tdid`), 'adserver.org', 'TDID'); + addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id.uid`), 'id5-sync.com', 'ID5ID'); + addExternalUserId(eids, utils.deepAccess(bidRequest, `userId.tdid`), 'adserver.org', 'TDID'); } if (eids.length > 0) { rtbBidRequest.user.ext.eids = eids; @@ -206,7 +206,7 @@ export const spec = { interpretResponse: function (serverResponse, bidRequest) { const response = serverResponse && serverResponse.body; if (!response) { - logError('empty response'); + utils.logError('empty response'); return []; } @@ -232,11 +232,11 @@ export const spec = { } } - if (deepAccess(bidRequest.bidRequest, 'mediaTypes.' + outBid.mediaType)) { + if (utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.' + outBid.mediaType)) { if (outBid.mediaType === BANNER) { outBids.push(Object.assign({}, outBid, {ad: bid.adm})); } else if (outBid.mediaType === VIDEO) { - const context = deepAccess(bidRequest.bidRequest, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidRequest.bidRequest, 'mediaTypes.video.context'); outBids.push(Object.assign({}, outBid, { vastUrl: bid.ext.vast_url, vastXml: bid.adm, @@ -315,7 +315,7 @@ function newRenderer(bidRequest, bid, rendererOptions = {}) { try { renderer.setRender(renderOutstream); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; } @@ -341,7 +341,7 @@ function renderOutstream(bid) { } function addExternalUserId(eids, value, source, rtiPartner) { - if (isStr(value)) { + if (utils.isStr(value)) { eids.push({ source, uids: [{ diff --git a/modules/gdprEnforcement.js b/modules/gdprEnforcement.js index 978bd8de9e3..02a2da3a7a4 100644 --- a/modules/gdprEnforcement.js +++ b/modules/gdprEnforcement.js @@ -2,8 +2,9 @@ * This module gives publishers extra set of features to enforce individual purposes of TCF v2 */ -import { deepAccess, logWarn, isArray, hasDeviceAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; +import { hasDeviceAccess } from '../src/utils.js'; import adapterManager, { gdprDataHandler } from '../src/adapterManager.js'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -135,9 +136,9 @@ export function validateRules(rule, consentData, currentModule, gvlId) { } // get data from the consent string - const purposeConsent = deepAccess(consentData, `vendorData.purpose.consents.${purposeId}`); - const vendorConsent = deepAccess(consentData, `vendorData.vendor.consents.${gvlId}`); - const liTransparency = deepAccess(consentData, `vendorData.purpose.legitimateInterests.${purposeId}`); + const purposeConsent = utils.deepAccess(consentData, `vendorData.purpose.consents.${purposeId}`); + const vendorConsent = utils.deepAccess(consentData, `vendorData.vendor.consents.${gvlId}`); + const liTransparency = utils.deepAccess(consentData, `vendorData.purpose.legitimateInterests.${purposeId}`); /* Since vendor exceptions have already been handled, the purpose as a whole is allowed if it's not being enforced @@ -169,7 +170,7 @@ export function deviceAccessHook(fn, gvlid, moduleName, result) { hasEnforcementHook: true }); if (!hasDeviceAccess()) { - logWarn('Device access is disabled by Publisher'); + utils.logWarn('Device access is disabled by Publisher'); result.valid = false; fn.call(this, gvlid, moduleName, result); } else { @@ -189,7 +190,7 @@ export function deviceAccessHook(fn, gvlid, moduleName, result) { result.valid = true; fn.call(this, gvlid, moduleName, result); } else { - curModule && logWarn(`TCF2 denied device access for ${curModule}`); + curModule && utils.logWarn(`TCF2 denied device access for ${curModule}`); result.valid = false; storageBlocked.push(curModule); fn.call(this, gvlid, moduleName, result); @@ -221,7 +222,7 @@ export function userSyncHook(fn, ...args) { if (isAllowed) { fn.call(this, ...args); } else { - logWarn(`User sync not allowed for ${curBidder}`); + utils.logWarn(`User sync not allowed for ${curBidder}`); storageBlocked.push(curBidder); } } else { @@ -249,7 +250,7 @@ export function userIdHook(fn, submodules, consentData) { if (isAllowed) { return submodule; } else { - logWarn(`User denied permission to fetch user id for ${moduleName} User id module`); + utils.logWarn(`User denied permission to fetch user id for ${moduleName} User id module`); storageBlocked.push(moduleName); } return undefined; @@ -281,7 +282,7 @@ export function makeBidRequestsHook(fn, adUnits, ...args) { if (includes(biddersBlocked, currBidder)) return false; const isAllowed = !!validateRules(purpose2Rule, consentData, currBidder, gvlId); if (!isAllowed) { - logWarn(`TCF2 blocked auction for ${currBidder}`); + utils.logWarn(`TCF2 blocked auction for ${currBidder}`); biddersBlocked.push(currBidder); } return isAllowed; @@ -307,7 +308,7 @@ export function enableAnalyticsHook(fn, config) { const consentData = gdprDataHandler.getConsentData(); if (consentData && consentData.gdprApplies) { if (consentData.apiVersion === 2) { - if (!isArray(config)) { + if (!utils.isArray(config)) { config = [config] } config = config.filter(conf => { @@ -316,7 +317,7 @@ export function enableAnalyticsHook(fn, config) { const isAllowed = !!validateRules(purpose7Rule, consentData, analyticsAdapterCode, gvlid); if (!isAllowed) { analyticsBlocked.push(analyticsAdapterCode); - logWarn(`TCF2 blocked analytics adapter ${conf.provider}`); + utils.logWarn(`TCF2 blocked analytics adapter ${conf.provider}`); } return isAllowed; }); @@ -361,9 +362,9 @@ const hasPurpose7 = (rule) => { return rule.purpose === TCF2.purpose7.name } * @param {Object} config - GDPR enforcement config object */ export function setEnforcementConfig(config) { - const rules = deepAccess(config, 'gdpr.rules'); + const rules = utils.deepAccess(config, 'gdpr.rules'); if (!rules) { - logWarn('TCF2: enforcing P1 and P2 by default'); + utils.logWarn('TCF2: enforcing P1 and P2 by default'); enforcementRules = DEFAULT_RULES; } else { enforcementRules = rules; diff --git a/modules/getintentBidAdapter.js b/modules/getintentBidAdapter.js index 98659cc25e2..9127bc4be6e 100644 --- a/modules/getintentBidAdapter.js +++ b/modules/getintentBidAdapter.js @@ -1,5 +1,6 @@ -import { getBidIdParameter, isFn, isInteger } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { isInteger } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'getintent'; const IS_NET_REVENUE = true; @@ -123,7 +124,7 @@ function buildGiBidRequest(bidRequest) { giBidRequest.size = produceSize(bidRequest.sizes); } - const currency = getBidIdParameter(CURRENCY_PARAM, bidRequest.params); + const currency = utils.getBidIdParameter(CURRENCY_PARAM, bidRequest.params); const floorInfo = getBidFloor(bidRequest, currency); if (floorInfo.floor) { giBidRequest[FLOOR_PARAM] = floorInfo.floor; @@ -142,7 +143,7 @@ function buildGiBidRequest(bidRequest) { function getBidFloor(bidRequest, currency) { let floorInfo = {}; - if (isFn(bidRequest.getFloor)) { + if (utils.isFn(bidRequest.getFloor)) { floorInfo = bidRequest.getFloor({ currency: currency || DEFAULT_CURRENCY, mediaType: bidRequest.mediaType, diff --git a/modules/gjirafaBidAdapter.js b/modules/gjirafaBidAdapter.js index c6777ebe44e..df33369d6ad 100644 --- a/modules/gjirafaBidAdapter.js +++ b/modules/gjirafaBidAdapter.js @@ -1,15 +1,10 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { getStorageManager } from '../src/storageManager.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; const BIDDER_CODE = 'gjirafa'; const ENDPOINT_URL = 'https://central.gjirafa.com/bid'; const DIMENSION_SEPARATOR = 'x'; const SIZE_SEPARATOR = ';'; -const BISKO_ID = 'biskoId'; -const STORAGE_ID = 'bisko-sid'; -const SEGMENTS = 'biskoSegments'; -const storage = getStorageManager(); export const spec = { code: BIDDER_CODE, @@ -30,12 +25,9 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { - const storageId = storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(STORAGE_ID) || '' : ''; - const biskoId = storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(BISKO_ID) || '' : ''; - const segments = storage.localStorageIsEnabled() ? JSON.parse(storage.getDataFromLocalStorage(SEGMENTS)) || [] : []; - let propertyId = ''; let pageViewGuid = ''; + let storageId = ''; let bidderRequestId = ''; let url = ''; let contents = []; @@ -44,6 +36,7 @@ export const spec = { let placements = validBidRequests.map(bidRequest => { if (!propertyId) { propertyId = bidRequest.params.propertyId; } if (!pageViewGuid && bidRequest.params) { pageViewGuid = bidRequest.params.pageViewGuid || ''; } + if (!storageId && bidRequest.params) { storageId = bidRequest.params.storageId || ''; } if (!bidderRequestId) { bidderRequestId = bidRequest.bidderRequestId; } if (!url && bidderRequest) { url = bidderRequest.refererInfo.referer; } if (!contents.length && bidRequest.params.contents && bidRequest.params.contents.length) { contents = bidRequest.params.contents; } @@ -67,8 +60,6 @@ export const spec = { propertyId: propertyId, pageViewGuid: pageViewGuid, storageId: storageId, - biskoId: biskoId, - segments: segments, url: url, requestid: bidderRequestId, placements: placements, diff --git a/modules/glimpseBidAdapter.js b/modules/glimpseBidAdapter.js index 64b987254e9..9ef46f62f1d 100644 --- a/modules/glimpseBidAdapter.js +++ b/modules/glimpseBidAdapter.js @@ -1,231 +1,69 @@ -import { BANNER } from '../src/mediaTypes.js' -import { config } from '../src/config.js' -import { getStorageManager } from '../src/storageManager.js' -import { isArray } from '../src/utils.js' -import { registerBidder } from '../src/adapters/bidderFactory.js' +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { BANNER } from '../src/mediaTypes.js'; -const storageManager = getStorageManager() +const BIDDER_CODE = 'glimpse'; -const GVLID = 1012 -const BIDDER_CODE = 'glimpse' -const ENDPOINT = 'https://api.glimpsevault.io/ads/serving/public/v1/prebid' -const LOCAL_STORAGE_KEY = { - vault: { - jwt: 'gp_vault_jwt', - }, +function transformEachBidResponse(glimpseBid) { + const bid = glimpseBid; + bid.meta = { advertiserDomains: [] }; + + if (glimpseBid.adomain) { + bid.meta.advertiserDomains = glimpseBid.adomain; + } + + return bid; } export const spec = { - gvlid: GVLID, code: BIDDER_CODE, + url: 'https://api.glimpseprotocol.io/cloud/v1/vault/prebid', supportedMediaTypes: [BANNER], - /** - * Determines whether or not the given bid request is valid - * @param bid {BidRequest} The bid to validate - * @return {boolean} - */ isBidRequestValid: (bid) => { - return ( - hasValue(bid) && - hasValue(bid.params) && - hasStringValue(bid.params.placementId) - ) + try { + const { placementId } = bid.params; + return typeof placementId === 'string' && placementId.length > 0; + } catch (error) { + return false; + } }, - /** - * Builds http request for Glimpse bids - * @param validBidRequests {BidRequest[]} - * @param bidderRequest {BidderRequest} - * @returns {ServerRequest} - */ buildRequests: (validBidRequests, bidderRequest) => { - const auth = getVaultJwt() - const referer = getReferer(bidderRequest) - const gdprConsent = getGdprConsentChoice(bidderRequest) - const bidRequests = validBidRequests.map(processBidRequest) - const firstPartyData = getFirstPartyData() + const { url, code: bidderCode } = spec; - const data = { - auth, - data: { - referer, - gdprConsent, - bidRequests, - site: firstPartyData.site, - user: firstPartyData.user, - bidderCode: spec.code, - } - } + const bids = validBidRequests.map((request) => { + delete request.mediaTypes; + return request; + }); + + const sdk = { + source: 'pbjs', + version: '$prebid.version$', + }; + + const payload = { + ...bidderRequest, + bidderCode, + bids, + sdk, + }; return { method: 'POST', - url: ENDPOINT, - data: JSON.stringify(data), - options: {}, - } + url, + data: JSON.stringify(payload), + }; }, - /** - * Parse response from Glimpse server - * @param bidResponse {ServerResponse} - * @returns {Bid[]} - */ - interpretResponse: (bidResponse) => { - const isValidResponse = isValidBidResponse(bidResponse) - - if (isValidResponse) { - const {auth, data} = bidResponse.body - setVaultJwt(auth) - return data.bids - } + interpretResponse: (serverResponse, _) => { + let bids = []; + try { + const { body } = serverResponse; + bids = body.map(transformEachBidResponse); + } catch (error) {} - return [] + return bids; }, -} - -function setVaultJwt(auth) { - storageManager.setDataInLocalStorage(LOCAL_STORAGE_KEY.vault.jwt, auth) -} - -function getVaultJwt() { - return storageManager.getDataFromLocalStorage(LOCAL_STORAGE_KEY.vault.jwt) || '' -} - -function getReferer(bidderRequest) { - const hasReferer = - hasValue(bidderRequest) && - hasValue(bidderRequest.refererInfo) && - hasStringValue(bidderRequest.refererInfo.referer) - - if (hasReferer) { - return bidderRequest.refererInfo.referer - } - - return '' -} - -function getGdprConsentChoice(bidderRequest) { - const hasGdprConsent = - hasValue(bidderRequest) && - hasValue(bidderRequest.gdprConsent) - - if (hasGdprConsent) { - const gdprConsent = bidderRequest.gdprConsent - const hasGdprApplies = hasBooleanValue(gdprConsent.gdprApplies) - - return { - consentString: gdprConsent.consentString || '', - vendorData: gdprConsent.vendorData || {}, - gdprApplies: hasGdprApplies ? gdprConsent.gdprApplies : true, - } - } - - return { - consentString: '', - vendorData: {}, - gdprApplies: false, - } -} - -function processBidRequest(bidRequest) { - const demand = bidRequest.params.demand || 'glimpse' - const sizes = normalizeSizes(bidRequest.sizes) - const keywords = bidRequest.params.keywords || {} - - return { - demand, - sizes, - keywords, - bidId: bidRequest.bidId, - placementId: bidRequest.params.placementId, - unitCode: bidRequest.adUnitCode, - } -} - -function normalizeSizes(sizes) { - const isSingleSize = - isArray(sizes) && - sizes.length === 2 && - !isArray(sizes[0]) && - !isArray(sizes[1]) - - if (isSingleSize) { - return [sizes] - } - - return sizes -} - -function getFirstPartyData() { - const siteKeywords = parseGlobalKeywords('site') - const userKeywords = parseGlobalKeywords('user') - - const siteAttributes = getConfig('ortb2.site.ext.data', {}) - const userAttributes = getConfig('ortb2.user.ext.data', {}) - - return { - site: { - keywords: siteKeywords, - attributes: siteAttributes, - }, - user: { - keywords: userKeywords, - attributes: userAttributes, - }, - } -} - -function parseGlobalKeywords(scope) { - const keywords = getConfig(`ortb2.${scope}.keywords`, '') - - return keywords - .split(', ') - .filter((keyword) => keyword !== '') -} - -function getConfig(path, defaultValue) { - return config.getConfig(path) || defaultValue -} - -function isValidBidResponse(bidResponse) { - return ( - hasValue(bidResponse) && - hasValue(bidResponse.body) && - hasValue(bidResponse.body.data) && - hasArrayValue(bidResponse.body.data.bids) && - hasStringValue(bidResponse.body.auth) - ) -} - -function hasValue(value) { - return ( - value !== undefined && - value !== null - ) -} - -function hasBooleanValue(value) { - return ( - hasValue(value) && - typeof value === 'boolean' - ) -} - -function hasStringValue(value) { - return ( - hasValue(value) && - typeof value === 'string' && - value.length > 0 - ) -} - -function hasArrayValue(value) { - return ( - hasValue(value) && - isArray(value) && - value.length > 0 - ) -} +}; -registerBidder(spec) +registerBidder(spec); diff --git a/modules/glimpseBidAdapter.md b/modules/glimpseBidAdapter.md index 767efcecf54..024cc9ebfa7 100644 --- a/modules/glimpseBidAdapter.md +++ b/modules/glimpseBidAdapter.md @@ -3,7 +3,7 @@ ``` Module Name: Glimpse Protocol Bid Adapter Module Type: Bidder Adapter -Maintainer: publisher@glimpseprotocol.io +Maintainer: hello@glimpseprotocol.io ``` # Description @@ -11,12 +11,12 @@ Maintainer: publisher@glimpseprotocol.io This module connects publishers to Glimpse Protocol's demand sources via Prebid.js. Our innovative marketplace protects consumer privacy while allowing precise targeting. It is compliant with GDPR, DPA and CCPA. -The Glimpse Adapter supports banner formats. +This adapter supports Banner. # Test Parameters ```javascript -const adUnits = [ +var adUnits = [ { code: 'banner-div-a', mediaTypes: { @@ -24,15 +24,78 @@ const adUnits = [ sizes: [[300, 250]], }, }, - bids: [{ - bidder: 'glimpse', - params: { - placementId: 'e53a7f564f8f44cc913b', - keywords: { - country: 'uk', + bids: [ + { + bidder: 'glimpse', + params: { + placementId: 'glimpse-demo-300x250', }, }, - }], + ], }, -] + { + code: 'banner-div-b', + mediaTypes: { + banner: { + sizes: [[320, 50]], + }, + }, + bids: [ + { + bidder: 'glimpse', + params: { + placementId: 'glimpse-demo-320x50', + }, + }, + ], + }, + { + code: 'banner-div-c', + mediaTypes: { + banner: { + sizes: [[970, 250]], + }, + }, + bids: [ + { + bidder: 'glimpse', + params: { + placementId: 'glimpse-demo-970x250', + }, + }, + ], + }, + { + code: 'banner-div-d', + mediaTypes: { + banner: { + sizes: [[728, 90]], + }, + }, + bids: [ + { + bidder: 'glimpse', + params: { + placementId: 'glimpse-demo-728x90', + }, + }, + ], + }, + { + code: 'banner-div-e', + mediaTypes: { + banner: { + sizes: [[300, 600]], + }, + }, + bids: [ + { + bidder: 'glimpse', + params: { + placementId: 'glimpse-demo-300x600', + }, + }, + ], + }, +]; ``` diff --git a/modules/gmosspBidAdapter.js b/modules/gmosspBidAdapter.js index fac19896177..2b9bd6db034 100644 --- a/modules/gmosspBidAdapter.js +++ b/modules/gmosspBidAdapter.js @@ -1,5 +1,5 @@ -import { getDNT, getBidIdParameter, tryAppendQueryString, isEmpty, createTrackPixelHtml, logError, deepSetValue } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -33,7 +33,7 @@ export const spec = { const urlInfo = getUrlInfo(bidderRequest.refererInfo); const cur = getCurrencyType(); - const dnt = getDNT() ? '1' : '0'; + const dnt = utils.getDNT() ? '1' : '0'; const imuid = storage.getCookie('_im_uid.1000283') || ''; for (let i = 0; i < validBidRequests.length; i++) { @@ -43,17 +43,17 @@ export const spec = { const tid = request.transactionId; const bid = request.bidId; const ver = '$prebid.version$'; - const sid = getBidIdParameter('sid', request.params); - - queryString = tryAppendQueryString(queryString, 'tid', tid); - queryString = tryAppendQueryString(queryString, 'bid', bid); - queryString = tryAppendQueryString(queryString, 'ver', ver); - queryString = tryAppendQueryString(queryString, 'sid', sid); - queryString = tryAppendQueryString(queryString, 'im_uid', imuid); - queryString = tryAppendQueryString(queryString, 'url', urlInfo.url); - queryString = tryAppendQueryString(queryString, 'ref', urlInfo.ref); - queryString = tryAppendQueryString(queryString, 'cur', cur); - queryString = tryAppendQueryString(queryString, 'dnt', dnt); + const sid = utils.getBidIdParameter('sid', request.params); + + queryString = utils.tryAppendQueryString(queryString, 'tid', tid); + queryString = utils.tryAppendQueryString(queryString, 'bid', bid); + queryString = utils.tryAppendQueryString(queryString, 'ver', ver); + queryString = utils.tryAppendQueryString(queryString, 'sid', sid); + queryString = utils.tryAppendQueryString(queryString, 'im_uid', imuid); + queryString = utils.tryAppendQueryString(queryString, 'url', urlInfo.url); + queryString = utils.tryAppendQueryString(queryString, 'ref', urlInfo.ref); + queryString = utils.tryAppendQueryString(queryString, 'cur', cur); + queryString = utils.tryAppendQueryString(queryString, 'dnt', dnt); bidRequests.push({ method: 'GET', @@ -73,17 +73,17 @@ export const spec = { interpretResponse: function (bidderResponse, requests) { const res = bidderResponse.body; - if (isEmpty(res)) { + if (utils.isEmpty(res)) { return []; } try { res.imps.forEach(impTracker => { - const tracker = createTrackPixelHtml(impTracker); + const tracker = utils.createTrackPixelHtml(impTracker); res.ad += tracker; }); } catch (error) { - logError('Error appending tracking pixel', error); + utils.logError('Error appending tracking pixel', error); } const bid = { @@ -99,7 +99,7 @@ export const spec = { }; if (res.adomains) { - deepSetValue(bid, 'meta.advertiserDomains', Array.isArray(res.adomains) ? res.adomains : [res.adomains]); + utils.deepSetValue(bid, 'meta.advertiserDomains', Array.isArray(res.adomains) ? res.adomains : [res.adomains]); } return [bid]; diff --git a/modules/gnetBidAdapter.js b/modules/gnetBidAdapter.js index f5e461afac8..f45c10195cd 100644 --- a/modules/gnetBidAdapter.js +++ b/modules/gnetBidAdapter.js @@ -1,5 +1,5 @@ -import { _each, parseSizesInput, isEmpty } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; const BIDDER_CODE = 'gnet'; @@ -29,7 +29,7 @@ export const spec = { const bidRequests = []; const referer = bidderRequest.refererInfo.referer; - _each(validBidRequests, (request) => { + utils._each(validBidRequests, (request) => { const data = {}; data.referer = referer; @@ -37,7 +37,7 @@ export const spec = { data.bidId = request.bidId; data.transactionId = request.transactionId; - data.sizes = parseSizesInput(request.sizes); + data.sizes = utils.parseSizesInput(request.sizes); data.params = request.params; @@ -70,13 +70,13 @@ export const spec = { const res = serverResponse && serverResponse.body; - if (isEmpty(res)) { + if (utils.isEmpty(res)) { return []; } if (res.bids) { const bids = []; - _each(res.bids, (bidData) => { + utils._each(res.bids, (bidData) => { const bid = { requestId: bidData.bidId, cpm: bidData.cpm, diff --git a/modules/goldbachBidAdapter.js b/modules/goldbachBidAdapter.js deleted file mode 100644 index 8057925a62c..00000000000 --- a/modules/goldbachBidAdapter.js +++ /dev/null @@ -1,1176 +0,0 @@ -import { Renderer } from '../src/Renderer.js'; -import { - isEmpty, - convertCamelToUnderscore, - isFn, - createTrackPixelHtml, - convertTypes, - deepClone, - fill, - getParameterByName, - getMaxValueFromArray, - getMinValueFromArray, - chunk, - isArray, - isArrayOfNums, - isNumber, - isStr, - isPlainObject, - logError, - logInfo, - logMessage, - deepAccess, - getBidRequest, - transformBidderParamKeywords -} from '../src/utils.js'; -import { config } from '../src/config.js'; -import { registerBidder, getIabSubCategory } from '../src/adapters/bidderFactory.js'; -import { BANNER, NATIVE, VIDEO, ADPOD } from '../src/mediaTypes.js'; -import { auctionManager } from '../src/auctionManager.js'; -import find from 'core-js-pure/features/array/find.js'; -import includes from 'core-js-pure/features/array/includes.js'; -import { OUTSTREAM, INSTREAM } from '../src/video.js'; - -const BIDDER_CODE = 'goldbach'; -const URL = 'https://ib.adnxs.com/ut/v3/prebid'; -const PRICING_URL = 'https://templates.da-services.ch/01_universal/burda_prebid/1.0/json/sizeCPMMapping.json'; -const URL_SIMPLE = 'https://ib.adnxs-simple.com/ut/v3/prebid'; -const VIDEO_TARGETING = ['id', 'minduration', 'maxduration', - 'skippable', 'playback_method', 'frameworks', 'context', 'skipoffset']; -const VIDEO_RTB_TARGETING = ['minduration', 'maxduration', 'skip', 'skipafter', 'playbackmethod', 'api']; -const USER_PARAMS = ['age', 'externalUid', 'segments', 'gender', 'dnt', 'language']; -const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately -const DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout']; -const DEFAULT_PRICE_MAPPING = { - '0x0': 2.5, - '300x600': 5, - '800x250': 6, - '350x600': 6 -}; -let PRICE_MAPPING; -const VIDEO_MAPPING = { - playback_method: { - 'unknown': 0, - 'auto_play_sound_on': 1, - 'auto_play_sound_off': 2, - 'click_to_play': 3, - 'mouse_over': 4, - 'auto_play_sound_unknown': 5 - }, - context: { - 'unknown': 0, - 'pre_roll': 1, - 'mid_roll': 2, - 'post_roll': 3, - 'outstream': 4, - 'in-banner': 5 - } -}; -const NATIVE_MAPPING = { - body: 'description', - body2: 'desc2', - cta: 'ctatext', - image: { - serverName: 'main_image', - requiredParams: { required: true } - }, - icon: { - serverName: 'icon', - requiredParams: { required: true } - }, - sponsoredBy: 'sponsored_by', - privacyLink: 'privacy_link', - salePrice: 'saleprice', - displayUrl: 'displayurl' -}; -const SOURCE = 'pbjs'; -const MAX_IMPS_PER_REQUEST = 15; -const mappingFileUrl = 'https://acdn.adnxs-simple.com/prebid/appnexus-mapping/mappings.json'; -const SCRIPT_TAG_START = ' { - if (Array.isArray(bid.params.placementId)) { - const ids = bid.params.placementId; - for (let i = 0; i < ids.length; i++) { - const newBid = Object.assign({}, bid, {params: {placementId: ids[i]}}); - localBidRequests.push(newBid) - } - } else { - localBidRequests.push(bid); - } - }); - const tags = localBidRequests.map(bidToTag); - const userObjBid = find(bidRequests, hasUserInfo); - let userObj = {}; - if (config.getConfig('coppa') === true) { - userObj = { 'coppa': true }; - } - if (userObjBid) { - Object.keys(userObjBid.params.user) - .filter(param => includes(USER_PARAMS, param)) - .forEach((param) => { - let uparam = convertCamelToUnderscore(param); - if (param === 'segments' && isArray(userObjBid.params.user[param])) { - let segs = []; - userObjBid.params.user[param].forEach(val => { - if (isNumber(val)) { - segs.push({'id': val}); - } else if (isPlainObject(val)) { - segs.push(val); - } - }); - userObj[uparam] = segs; - } else if (param !== 'segments') { - userObj[uparam] = userObjBid.params.user[param]; - } - }); - } - - const appDeviceObjBid = find(bidRequests, hasAppDeviceInfo); - let appDeviceObj; - if (appDeviceObjBid && appDeviceObjBid.params && appDeviceObjBid.params.app) { - appDeviceObj = {}; - Object.keys(appDeviceObjBid.params.app) - .filter(param => includes(APP_DEVICE_PARAMS, param)) - .forEach(param => appDeviceObj[param] = appDeviceObjBid.params.app[param]); - } - - const appIdObjBid = find(bidRequests, hasAppId); - let appIdObj; - if (appIdObjBid && appIdObjBid.params && appDeviceObjBid.params.app && appDeviceObjBid.params.app.id) { - appIdObj = { - appid: appIdObjBid.params.app.id - }; - } - - let debugObj = {}; - let debugObjParams = {}; - const debugBidRequest = find(bidRequests, hasDebug); - if (debugBidRequest && debugBidRequest.debug) { - debugObj = debugBidRequest.debug; - } - - if (debugObj && debugObj.enabled) { - Object.keys(debugObj) - .filter(param => includes(DEBUG_PARAMS, param)) - .forEach(param => { - debugObjParams[param] = debugObj[param]; - }); - } - - const memberIdBid = find(bidRequests, hasMemberId); - const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0; - const schain = bidRequests[0].schain; - const omidSupport = find(bidRequests, hasOmidSupport); - - const payload = { - tags: [...tags], - user: userObj, - sdk: { - source: SOURCE, - version: '$prebid.version$' - }, - schain: schain - }; - - if (omidSupport) { - payload['iab_support'] = { - omidpn: 'Appnexus', - omidpv: '$prebid.version$' - } - } - - if (member > 0) { - payload.member_id = member; - } - - if (appDeviceObjBid) { - payload.device = appDeviceObj - } - if (appIdObjBid) { - payload.app = appIdObj; - } - - if (config.getConfig('adpod.brandCategoryExclusion')) { - payload.brand_category_uniqueness = true; - } - - if (debugObjParams.enabled) { - payload.debug = debugObjParams; - logInfo('Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); - } - - if (bidderRequest && bidderRequest.gdprConsent) { - // note - objects for impbus use underscore instead of camelCase - payload.gdpr_consent = { - consent_string: bidderRequest.gdprConsent.consentString, - consent_required: bidderRequest.gdprConsent.gdprApplies - }; - - if (bidderRequest.gdprConsent.addtlConsent && bidderRequest.gdprConsent.addtlConsent.indexOf('~') !== -1) { - let ac = bidderRequest.gdprConsent.addtlConsent; - // pull only the ids from the string (after the ~) and convert them to an array of ints - let acStr = ac.substring(ac.indexOf('~') + 1); - payload.gdpr_consent.addtl_consent = acStr.split('.').map(id => parseInt(id, 10)); - } - } - - if (bidderRequest && bidderRequest.uspConsent) { - payload.us_privacy = bidderRequest.uspConsent - } - - if (bidderRequest && bidderRequest.refererInfo) { - let refererinfo = { - rd_ref: encodeURIComponent(bidderRequest.refererInfo.referer), - rd_top: bidderRequest.refererInfo.reachedTop, - rd_ifs: bidderRequest.refererInfo.numIframes, - rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(',') - } - payload.referrer_detection = refererinfo; - } - - const hasAdPodBid = find(bidRequests, hasAdPod); - if (hasAdPodBid) { - bidRequests.filter(hasAdPod).forEach(adPodBid => { - const adPodTags = createAdPodRequest(tags, adPodBid); - // don't need the original adpod placement because it's in adPodTags - const nonPodTags = payload.tags.filter(tag => tag.uuid !== adPodBid.bidId); - payload.tags = [...nonPodTags, ...adPodTags]; - }); - } - - if (bidRequests[0].userId) { - let eids = []; - - addUserId(eids, deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); - addUserId(eids, deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); - - if (eids.length) { - payload.eids = eids; - } - } - - if (tags[0].publisher_id) { - payload.publisher_id = tags[0].publisher_id; - } - - const request = formatRequest(payload, bidderRequest); - // add pricing endpoint - return [{method: 'GET', url: PRICING_URL, options: {withCredentials: false}}, request]; - }, - - parseAndMapCpm: function(serverResponse) { - const responseBody = serverResponse.body; - if (Array.isArray(responseBody) && responseBody.length) { - let localData = {}; - responseBody.forEach(cpmPerSize => { - Object.keys(cpmPerSize).forEach(size => { - let obj = {}; - obj[size] = cpmPerSize[size]; - localData = Object.assign({}, localData, obj) - }) - }) - PRICE_MAPPING = localData; - return null; - } - - if (responseBody.version) { - const localPriceMapping = PRICE_MAPPING || DEFAULT_PRICE_MAPPING; - if (responseBody.tags && Array.isArray(responseBody.tags) && responseBody.tags.length) { - responseBody.tags.forEach((tag) => { - if (tag.ads && Array.isArray(tag.ads) && tag.ads.length) { - tag.ads.forEach(ad => { - if (ad.ad_type === 'banner') { - const size = `${ad.rtb.banner.width}x${ad.rtb.banner.height}`; - if (localPriceMapping[size]) { - ad.cpm = localPriceMapping[size]; - } else { - ad.cpm = localPriceMapping['0x0']; - } - } - }) - } - }); - } - } - return responseBody; - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {*} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function (serverResponse, { bidderRequest }) { - serverResponse = this.parseAndMapCpm(serverResponse); - if (!serverResponse) return []; - const bids = []; - if (serverResponse.error) { - let errorMessage = `in response for ${bidderRequest.bidderCode} adapter : ${serverResponse.error}`; - logError(errorMessage); - return bids; - } - - if (serverResponse.tags) { - serverResponse.tags.forEach(serverBid => { - const rtbBid = getRtbBid(serverBid); - if (rtbBid) { - if (rtbBid.cpm !== 0 && includes(this.supportedMediaTypes, rtbBid.ad_type)) { - const bid = newBid(serverBid, rtbBid, bidderRequest); - bid.mediaType = parseMediaType(rtbBid); - bids.push(bid); - } - } - }); - } - - if (serverResponse.debug && serverResponse.debug.debug_info) { - let debugHeader = 'AppNexus Debug Auction for Prebid\n\n' - let debugText = debugHeader + serverResponse.debug.debug_info - debugText = debugText - .replace(/(|)/gm, '\t') // Tables - .replace(/(<\/td>|<\/th>)/gm, '\n') // Tables - .replace(/^
/gm, '') // Remove leading
- .replace(/(
\n|
)/gm, '\n') //
- .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 - .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers - .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags - logMessage(debugText); - } - - return bids; - }, - - /** - * @typedef {Object} mappingFileInfo - * @property {string} url mapping file json url - * @property {number} refreshInDays prebid stores mapping data in localstorage so you can return in how many days you want to update value stored in localstorage. - * @property {string} localStorageKey unique key to store your mapping json in localstorage - */ - - /** - * Returns mapping file info. This info will be used by bidderFactory to preload mapping file and store data in local storage - * @returns {mappingFileInfo} - */ - getMappingFileInfo: function () { - return { - url: mappingFileUrl, - refreshInDays: 2 - } - }, - - getUserSyncs: function (syncOptions, responses, gdprConsent) { - if (syncOptions.iframeEnabled && hasPurpose1Consent({gdprConsent})) { - return [{ - type: 'iframe', - url: 'https://acdn.adnxs.com/dmp/async_usersync.html' - }]; - } - }, - - transformBidParams: function (params, isOpenRtb) { - params = convertTypes({ - 'member': 'string', - 'invCode': 'string', - 'placementId': 'number', - 'keywords': transformBidderParamKeywords, - 'publisherId': 'number' - }, params); - - if (isOpenRtb) { - params.use_pmt_rule = (typeof params.usePaymentRule === 'boolean') ? params.usePaymentRule : false; - if (params.usePaymentRule) { delete params.usePaymentRule; } - - if (isPopulatedArray(params.keywords)) { - params.keywords.forEach(deleteValues); - } - - Object.keys(params).forEach(paramKey => { - let convertedKey = convertCamelToUnderscore(paramKey); - if (convertedKey !== paramKey) { - params[convertedKey] = params[paramKey]; - delete params[paramKey]; - } - }); - } - - return params; - }, - - /** - * Add element selector to javascript tracker to improve native viewability - * @param {Bid} bid - */ - onBidWon: function (bid) { - if (bid.native) { - reloadViewabilityScriptWithCorrectParameters(bid); - } - } -} - -function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); -} - -function deleteValues(keyPairObj) { - if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') { - delete keyPairObj.value; - } -} - -function reloadViewabilityScriptWithCorrectParameters(bid) { - let viewJsPayload = getAppnexusViewabilityScriptFromJsTrackers(bid.native.javascriptTrackers); - - if (viewJsPayload) { - let prebidParams = 'pbjs_adid=' + bid.adId + ';pbjs_auc=' + bid.adUnitCode; - - let jsTrackerSrc = getViewabilityScriptUrlFromPayload(viewJsPayload) - - let newJsTrackerSrc = jsTrackerSrc.replace('dom_id=%native_dom_id%', prebidParams); - - // find iframe containing script tag - let frameArray = document.getElementsByTagName('iframe'); - - // boolean var to modify only one script. That way if there are muliple scripts, - // they won't all point to the same creative. - let modifiedAScript = false; - - // first, loop on all ifames - for (let i = 0; i < frameArray.length && !modifiedAScript; i++) { - let currentFrame = frameArray[i]; - try { - // IE-compatible, see https://stackoverflow.com/a/3999191/2112089 - let nestedDoc = currentFrame.contentDocument || currentFrame.contentWindow.document; - - if (nestedDoc) { - // if the doc is present, we look for our jstracker - let scriptArray = nestedDoc.getElementsByTagName('script'); - for (let j = 0; j < scriptArray.length && !modifiedAScript; j++) { - let currentScript = scriptArray[j]; - if (currentScript.getAttribute('data-src') == jsTrackerSrc) { - currentScript.setAttribute('src', newJsTrackerSrc); - currentScript.setAttribute('data-src', ''); - if (currentScript.removeAttribute) { - currentScript.removeAttribute('data-src'); - } - modifiedAScript = true; - } - } - } - } catch (exception) { - // trying to access a cross-domain iframe raises a SecurityError - // this is expected and ignored - if (!(exception instanceof DOMException && exception.name === 'SecurityError')) { - // all other cases are raised again to be treated by the calling function - throw exception; - } - } - } - } -} - -function strIsAppnexusViewabilityScript(str) { - let regexMatchUrlStart = str.match(VIEWABILITY_URL_START); - let viewUrlStartInStr = regexMatchUrlStart != null && regexMatchUrlStart.length >= 1; - - let regexMatchFileName = str.match(VIEWABILITY_FILE_NAME); - let fileNameInStr = regexMatchFileName != null && regexMatchFileName.length >= 1; - - return str.startsWith(SCRIPT_TAG_START) && fileNameInStr && viewUrlStartInStr; -} - -function getAppnexusViewabilityScriptFromJsTrackers(jsTrackerArray) { - let viewJsPayload; - if (isStr(jsTrackerArray) && strIsAppnexusViewabilityScript(jsTrackerArray)) { - viewJsPayload = jsTrackerArray; - } else if (isArray(jsTrackerArray)) { - for (let i = 0; i < jsTrackerArray.length; i++) { - let currentJsTracker = jsTrackerArray[i]; - if (strIsAppnexusViewabilityScript(currentJsTracker)) { - viewJsPayload = currentJsTracker; - } - } - } - return viewJsPayload; -} - -function getViewabilityScriptUrlFromPayload(viewJsPayload) { - // extracting the content of the src attribute - // -> substring between src=" and " - let indexOfFirstQuote = viewJsPayload.indexOf('src="') + 5; // offset of 5: the length of 'src=' + 1 - let indexOfSecondQuote = viewJsPayload.indexOf('"', indexOfFirstQuote); - let jsTrackerSrc = viewJsPayload.substring(indexOfFirstQuote, indexOfSecondQuote); - return jsTrackerSrc; -} - -function hasPurpose1Consent(bidderRequest) { - let result = true; - if (bidderRequest && bidderRequest.gdprConsent) { - if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); - } - } - return result; -} - -function formatRequest(payload, bidderRequest) { - let request = []; - let options = { - withCredentials: true - }; - - let endpointUrl = URL; - - if (!hasPurpose1Consent(bidderRequest)) { - endpointUrl = URL_SIMPLE; - } - - if (getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true) { - options.customHeaders = { - 'X-Is-Test': 1 - } - } - - if (payload.tags.length > MAX_IMPS_PER_REQUEST) { - const clonedPayload = deepClone(payload); - - chunk(payload.tags, MAX_IMPS_PER_REQUEST).forEach(tags => { - clonedPayload.tags = tags; - const payloadString = JSON.stringify(clonedPayload); - request.push({ - method: 'POST', - url: endpointUrl, - data: payloadString, - bidderRequest, - options - }); - }); - } else { - const payloadString = JSON.stringify(payload); - request = { - method: 'POST', - url: endpointUrl, - data: payloadString, - bidderRequest, - options - }; - } - - return request; -} - -function newRenderer(adUnitCode, rtbBid, rendererOptions = {}) { - const renderer = Renderer.install({ - id: rtbBid.renderer_id, - url: rtbBid.renderer_url, - config: rendererOptions, - loaded: false, - adUnitCode - }); - - try { - renderer.setRender(outstreamRender); - } catch (err) { - logError('Prebid Error calling setRender on renderer', err); - } - - renderer.setEventHandlers({ - impression: () => logMessage('Outstream video impression event'), - loaded: () => logMessage('Outstream video loaded event'), - ended: () => { - logMessage('Outstream renderer video event'); - document.querySelector(`#${adUnitCode}`).style.display = 'none'; - } - }); - return renderer; -} - -/** - * Unpack the Server's Bid into a Prebid-compatible one. - * @param serverBid - * @param rtbBid - * @param bidderRequest - * @return Bid - */ -function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); - const bid = { - requestId: serverBid.uuid, - cpm: rtbBid.cpm, - creativeId: rtbBid.creative_id, - dealId: rtbBid.deal_id, - currency: 'USD', - netRevenue: true, - ttl: 300, - adUnitCode: bidRequest.adUnitCode, - appnexus: { - buyerMemberId: rtbBid.buyer_member_id, - dealPriority: rtbBid.deal_priority, - dealCode: rtbBid.deal_code - } - }; - - // WE DON'T FULLY SUPPORT THIS ATM - future spot for adomain code; creating a stub for 5.0 compliance - if (rtbBid.adomain) { - bid.meta = Object.assign({}, bid.meta, { advertiserDomains: [] }); - } - - if (rtbBid.advertiser_id) { - bid.meta = Object.assign({}, bid.meta, { advertiserId: rtbBid.advertiser_id }); - } - - if (rtbBid.rtb.video) { - // shared video properties used for all 3 contexts - Object.assign(bid, { - width: rtbBid.rtb.video.player_width, - height: rtbBid.rtb.video.player_height, - vastImpUrl: rtbBid.notify_url, - ttl: 3600 - }); - - const videoContext = deepAccess(bidRequest, 'mediaTypes.video.context'); - switch (videoContext) { - case ADPOD: - const primaryCatId = getIabSubCategory(bidRequest.bidder, rtbBid.brand_category_id); - bid.meta = Object.assign({}, bid.meta, { primaryCatId }); - const dealTier = rtbBid.deal_priority; - bid.video = { - context: ADPOD, - durationSeconds: Math.floor(rtbBid.rtb.video.duration_ms / 1000), - dealTier - }; - bid.vastUrl = rtbBid.rtb.video.asset_url; - break; - case OUTSTREAM: - bid.adResponse = serverBid; - bid.adResponse.ad = bid.adResponse.ads[0]; - bid.adResponse.ad.video = bid.adResponse.ad.rtb.video; - bid.vastXml = rtbBid.rtb.video.content; - - if (rtbBid.renderer_url) { - const videoBid = find(bidderRequest.bids, bid => bid.bidId === serverBid.uuid); - const rendererOptions = deepAccess(videoBid, 'renderer.options'); - bid.renderer = newRenderer(bid.adUnitCode, rtbBid, rendererOptions); - } - break; - case INSTREAM: - bid.vastUrl = rtbBid.notify_url + '&redir=' + encodeURIComponent(rtbBid.rtb.video.asset_url); - break; - } - } else if (rtbBid.rtb[NATIVE]) { - const nativeAd = rtbBid.rtb[NATIVE]; - - // setting up the jsTracker: - // we put it as a data-src attribute so that the tracker isn't called - // until we have the adId (see onBidWon) - let jsTrackerDisarmed = rtbBid.viewability.config.replace('src=', 'data-src='); - - let jsTrackers = nativeAd.javascript_trackers; - - if (jsTrackers == undefined) { - jsTrackers = jsTrackerDisarmed; - } else if (isStr(jsTrackers)) { - jsTrackers = [jsTrackers, jsTrackerDisarmed]; - } else { - jsTrackers.push(jsTrackerDisarmed); - } - - bid[NATIVE] = { - title: nativeAd.title, - body: nativeAd.desc, - body2: nativeAd.desc2, - cta: nativeAd.ctatext, - rating: nativeAd.rating, - sponsoredBy: nativeAd.sponsored, - privacyLink: nativeAd.privacy_link, - address: nativeAd.address, - downloads: nativeAd.downloads, - likes: nativeAd.likes, - phone: nativeAd.phone, - price: nativeAd.price, - salePrice: nativeAd.saleprice, - clickUrl: nativeAd.link.url, - displayUrl: nativeAd.displayurl, - clickTrackers: nativeAd.link.click_trackers, - impressionTrackers: nativeAd.impression_trackers, - javascriptTrackers: jsTrackers - }; - if (nativeAd.main_img) { - bid['native'].image = { - url: nativeAd.main_img.url, - height: nativeAd.main_img.height, - width: nativeAd.main_img.width, - }; - } - if (nativeAd.icon) { - bid['native'].icon = { - url: nativeAd.icon.url, - height: nativeAd.icon.height, - width: nativeAd.icon.width, - }; - } - } else { - Object.assign(bid, { - width: rtbBid.rtb.banner.width, - height: rtbBid.rtb.banner.height, - ad: rtbBid.rtb.banner.content - }); - try { - if (rtbBid.rtb.trackers) { - const url = rtbBid.rtb.trackers[0].impression_urls[0]; - const tracker = createTrackPixelHtml(url); - bid.ad += tracker; - } - } catch (error) { - logError('Error appending tracking pixel', error); - } - } - - return bid; -} - -function bidToTag(bid) { - const tag = {}; - tag.sizes = transformSizes(bid.sizes); - tag.primary_size = tag.sizes[0]; - tag.ad_types = []; - tag.uuid = bid.bidId; - if (bid.params.placementId) { - tag.id = parseInt(bid.params.placementId, 10); - } else { - tag.code = bid.params.invCode; - } - tag.allow_smaller_sizes = bid.params.allowSmallerSizes || false; - tag.use_pmt_rule = bid.params.usePaymentRule || false - tag.prebid = true; - tag.disable_psa = true; - let bidFloor = getBidFloor(bid); - if (bidFloor) { - tag.reserve = bidFloor; - } - if (bid.params.position) { - tag.position = { 'above': 1, 'below': 2 }[bid.params.position] || 0; - } - if (bid.params.trafficSourceCode) { - tag.traffic_source_code = bid.params.trafficSourceCode; - } - if (bid.params.privateSizes) { - tag.private_sizes = transformSizes(bid.params.privateSizes); - } - if (bid.params.supplyType) { - tag.supply_type = bid.params.supplyType; - } - if (bid.params.pubClick) { - tag.pubclick = bid.params.pubClick; - } - if (bid.params.extInvCode) { - tag.ext_inv_code = bid.params.extInvCode; - } - if (bid.params.publisherId) { - tag.publisher_id = parseInt(bid.params.publisherId, 10); - } - if (bid.params.externalImpId) { - tag.external_imp_id = bid.params.externalImpId; - } - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); - - if (keywords.length > 0) { - keywords.forEach(deleteValues); - } - tag.keywords = keywords; - } - - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); - if (gpid) { - tag.gpid = gpid; - } - - if (bid.mediaType === NATIVE || deepAccess(bid, `mediaTypes.${NATIVE}`)) { - tag.ad_types.push(NATIVE); - if (tag.sizes.length === 0) { - tag.sizes = transformSizes([1, 1]); - } - - if (bid.nativeParams) { - const nativeRequest = buildNativeRequest(bid.nativeParams); - tag[NATIVE] = { layouts: [nativeRequest] }; - } - } - - const videoMediaType = deepAccess(bid, `mediaTypes.${VIDEO}`); - const context = deepAccess(bid, 'mediaTypes.video.context'); - - if (videoMediaType && context === 'adpod') { - tag.hb_source = 7; - } else { - tag.hb_source = 1; - } - if (bid.mediaType === VIDEO || videoMediaType) { - tag.ad_types.push(VIDEO); - } - - // instream gets vastUrl, outstream gets vastXml - if (bid.mediaType === VIDEO || (videoMediaType && context !== 'outstream')) { - tag.require_asset_url = true; - } - - if (bid.params.video) { - tag.video = {}; - // place any valid video params on the tag - Object.keys(bid.params.video) - .filter(param => includes(VIDEO_TARGETING, param)) - .forEach(param => { - switch (param) { - case 'context': - case 'playback_method': - let type = bid.params.video[param]; - type = (isArray(type)) ? type[0] : type; - tag.video[param] = VIDEO_MAPPING[param][type]; - break; - // Deprecating tags[].video.frameworks in favor of tags[].video_frameworks - case 'frameworks': - break; - default: - tag.video[param] = bid.params.video[param]; - } - }); - - if (bid.params.video.frameworks && isArray(bid.params.video.frameworks)) { - tag['video_frameworks'] = bid.params.video.frameworks; - } - } - - // use IAB ORTB values if the corresponding values weren't already set by bid.params.video - if (videoMediaType) { - tag.video = tag.video || {}; - Object.keys(videoMediaType) - .filter(param => includes(VIDEO_RTB_TARGETING, param)) - .forEach(param => { - switch (param) { - case 'minduration': - case 'maxduration': - if (typeof tag.video[param] !== 'number') tag.video[param] = videoMediaType[param]; - break; - case 'skip': - if (typeof tag.video['skippable'] !== 'boolean') tag.video['skippable'] = (videoMediaType[param] === 1); - break; - case 'skipafter': - if (typeof tag.video['skipoffset'] !== 'number') tag.video['skippoffset'] = videoMediaType[param]; - break; - case 'playbackmethod': - if (typeof tag.video['playback_method'] !== 'number') { - let type = videoMediaType[param]; - type = (isArray(type)) ? type[0] : type; - - // we only support iab's options 1-4 at this time. - if (type >= 1 && type <= 4) { - tag.video['playback_method'] = type; - } - } - break; - case 'api': - if (!tag['video_frameworks'] && isArray(videoMediaType[param])) { - // need to read thru array; remove 6 (we don't support it), swap 4 <> 5 if found (to match our adserver mapping for these specific values) - let apiTmp = videoMediaType[param].map(val => { - let v = (val === 4) ? 5 : (val === 5) ? 4 : val; - - if (v >= 1 && v <= 5) { - return v; - } - }).filter(v => v); - tag['video_frameworks'] = apiTmp; - } - break; - } - }); - } - - if (bid.renderer) { - tag.video = Object.assign({}, tag.video, { custom_renderer_present: true }); - } - - if (bid.params.frameworks && isArray(bid.params.frameworks)) { - tag['banner_frameworks'] = bid.params.frameworks; - } - - let adUnit = find(auctionManager.getAdUnits(), au => bid.transactionId === au.transactionId); - if (adUnit && adUnit.mediaTypes && adUnit.mediaTypes.banner) { - tag.ad_types.push(BANNER); - } - - if (tag.ad_types.length === 0) { - delete tag.ad_types; - } - - return tag; -} - -/* Turn bid request sizes into ut-compatible format */ -function transformSizes(requestSizes) { - let sizes = []; - let sizeObj = {}; - - if (isArray(requestSizes) && requestSizes.length === 2 && - !isArray(requestSizes[0])) { - sizeObj.width = parseInt(requestSizes[0], 10); - sizeObj.height = parseInt(requestSizes[1], 10); - sizes.push(sizeObj); - } else if (typeof requestSizes === 'object') { - for (let i = 0; i < requestSizes.length; i++) { - let size = requestSizes[i]; - sizeObj = {}; - sizeObj.width = parseInt(size[0], 10); - sizeObj.height = parseInt(size[1], 10); - sizes.push(sizeObj); - } - } - - return sizes; -} - -function hasUserInfo(bid) { - return !!bid.params.user; -} - -function hasMemberId(bid) { - return !!parseInt(bid.params.member, 10); -} - -function hasAppDeviceInfo(bid) { - if (bid.params) { - return !!bid.params.app - } -} - -function hasAppId(bid) { - if (bid.params && bid.params.app) { - return !!bid.params.app.id - } - return !!bid.params.app -} - -function hasDebug(bid) { - return !!bid.debug -} - -function hasAdPod(bid) { - return ( - bid.mediaTypes && - bid.mediaTypes.video && - bid.mediaTypes.video.context === ADPOD - ); -} - -function hasOmidSupport(bid) { - let hasOmid = false; - const bidderParams = bid.params; - const videoParams = bid.params.video; - if (bidderParams.frameworks && isArray(bidderParams.frameworks)) { - hasOmid = includes(bid.params.frameworks, 6); - } - if (!hasOmid && videoParams && videoParams.frameworks && isArray(videoParams.frameworks)) { - hasOmid = includes(bid.params.video.frameworks, 6); - } - return hasOmid; -} - -/** - * Expand an adpod placement into a set of request objects according to the - * total adpod duration and the range of duration seconds. Sets minduration/ - * maxduration video property according to requireExactDuration configuration - */ -function createAdPodRequest(tags, adPodBid) { - const { durationRangeSec, requireExactDuration } = adPodBid.mediaTypes.video; - - const numberOfPlacements = getAdPodPlacementNumber(adPodBid.mediaTypes.video); - const maxDuration = getMaxValueFromArray(durationRangeSec); - - const tagToDuplicate = tags.filter(tag => tag.uuid === adPodBid.bidId); - let request = fill(...tagToDuplicate, numberOfPlacements); - - if (requireExactDuration) { - const divider = Math.ceil(numberOfPlacements / durationRangeSec.length); - const chunked = chunk(request, divider); - - // each configured duration is set as min/maxduration for a subset of requests - durationRangeSec.forEach((duration, index) => { - chunked[index].map(tag => { - setVideoProperty(tag, 'minduration', duration); - setVideoProperty(tag, 'maxduration', duration); - }); - }); - } else { - // all maxdurations should be the same - request.map(tag => setVideoProperty(tag, 'maxduration', maxDuration)); - } - - return request; -} - -function getAdPodPlacementNumber(videoParams) { - const { adPodDurationSec, durationRangeSec, requireExactDuration } = videoParams; - const minAllowedDuration = getMinValueFromArray(durationRangeSec); - const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration); - - return requireExactDuration - ? Math.max(numberOfPlacements, durationRangeSec.length) - : numberOfPlacements; -} - -function setVideoProperty(tag, key, value) { - if (isEmpty(tag.video)) { tag.video = {}; } - tag.video[key] = value; -} - -function getRtbBid(tag) { - return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); -} - -function buildNativeRequest(params) { - const request = {}; - - // map standard prebid native asset identifier to /ut parameters - // e.g., tag specifies `body` but /ut only knows `description`. - // mapping may be in form {tag: ''} or - // {tag: {serverName: '', requiredParams: {...}}} - Object.keys(params).forEach(key => { - // check if one of the forms is used, otherwise - // a mapping wasn't specified so pass the key straight through - const requestKey = - (NATIVE_MAPPING[key] && NATIVE_MAPPING[key].serverName) || - NATIVE_MAPPING[key] || - key; - - // required params are always passed on request - const requiredParams = NATIVE_MAPPING[key] && NATIVE_MAPPING[key].requiredParams; - request[requestKey] = Object.assign({}, requiredParams, params[key]); - - // convert the sizes of image/icon assets to proper format (if needed) - const isImageAsset = !!(requestKey === NATIVE_MAPPING.image.serverName || requestKey === NATIVE_MAPPING.icon.serverName); - if (isImageAsset && request[requestKey].sizes) { - let sizes = request[requestKey].sizes; - if (isArrayOfNums(sizes) || (isArray(sizes) && sizes.length > 0 && sizes.every(sz => isArrayOfNums(sz)))) { - request[requestKey].sizes = transformSizes(request[requestKey].sizes); - } - } - - if (requestKey === NATIVE_MAPPING.privacyLink) { - request.privacy_supported = true; - } - }); - - return request; -} - -/** - * This function hides google div container for outstream bids to remove unwanted space on page. Appnexus renderer creates a new iframe outside of google iframe to render the outstream creative. - * @param {string} elementId element id - */ -function hidedfpContainer(elementId) { - var el = document.getElementById(elementId).querySelectorAll("div[id^='google_ads']"); - if (el[0]) { - el[0].style.setProperty('display', 'none'); - } -} - -function hideSASIframe(elementId) { - try { - // find script tag with id 'sas_script'. This ensures it only works if you're using Smart Ad Server. - const el = document.getElementById(elementId).querySelectorAll("script[id^='sas_script']"); - if (el[0].nextSibling && el[0].nextSibling.localName === 'iframe') { - el[0].nextSibling.style.setProperty('display', 'none'); - } - } catch (e) { - // element not found! - } -} - -function outstreamRender(bid) { - hidedfpContainer(bid.adUnitCode); - hideSASIframe(bid.adUnitCode); - // push to render queue because ANOutstreamVideo may not be loaded yet - bid.renderer.push(() => { - window.ANOutstreamVideo.renderAd({ - tagId: bid.adResponse.tag_id, - sizes: [bid.getSize().split('x')], - targetId: bid.adUnitCode, // target div id to render video - uuid: bid.adResponse.uuid, - adResponse: bid.adResponse, - rendererOptions: bid.renderer.getConfig() - }, handleOutstreamRendererEvents.bind(null, bid)); - }); -} - -function handleOutstreamRendererEvents(bid, id, eventName) { - bid.renderer.handleVideoEvent({ id, eventName }); -} - -function parseMediaType(rtbBid) { - const adType = rtbBid.ad_type; - if (adType === VIDEO) { - return VIDEO; - } else if (adType === NATIVE) { - return NATIVE; - } else { - return BANNER; - } -} - -function addUserId(eids, id, source, rti) { - if (id) { - if (rti) { - eids.push({ source, id, rti_partner: rti }); - } else { - eids.push({ source, id }); - } - } - return eids; -} - -function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return (bid.params.reserve) ? bid.params.reserve : null; - } - - let floor = bid.getFloor({ - currency: 'USD', - mediaType: '*', - size: '*' - }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { - return floor.floor; - } - return null; -} - -registerBidder(spec); diff --git a/modules/goldbachBidAdapter.md b/modules/goldbachBidAdapter.md deleted file mode 100644 index f7c9479439b..00000000000 --- a/modules/goldbachBidAdapter.md +++ /dev/null @@ -1,151 +0,0 @@ -#Overview - -``` -Module Name: Goldbach Bid Adapter -Module Type: Bidder Adapter -Maintainer: dusan.veljovic@goldbach.com -``` - -# Description - -Connects to Xandr exchange for bids. - -Goldbach bid adapter supports Banner, Video (instream and outstream) and Native. - -# Test Parameters -``` -var adUnits = [ - // Banner adUnit - { - code: 'banner-div', - mediaTypes: { - banner: { - sizes: [[300, 250], [300,600]] - } - }, - bids: [{ - bidder: 'goldbach', - params: { - placementId: 13144370 - } - }] - }, - // Native adUnit - { - code: 'native-div', - sizes: [[1, 1]], - mediaTypes: { - native: { - title: { - required: true - }, - body: { - required: true - }, - image: { - required: true - }, - sponsoredBy: { - required: true - }, - icon: { - required: false - } - } - }, - bids: [{ - bidder: 'goldbach', - params: { - placementId: 13232354, - allowSmallerSizes: true - } - }] - }, - // Video instream adUnit - { - code: 'video-instream', - sizes: [[640, 480]], - mediaTypes: { - video: { - playerSize: [[640, 480]], - context: 'instream' - }, - }, - bids: [{ - goldbach: 'goldbach', - params: { - placementId: 13232361, - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'] - } - } - }] - }, - // Video outstream adUnit - { - code: 'video-outstream', - sizes: [[300, 250]], - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream', - // Certain ORTB 2.5 video values can be read from the mediatypes object; below are examples of supported params. - // To note - goldbach supports additional values for our system that are not part of the ORTB spec. If you want - // to use these values, they will have to be declared in the bids[].params.video object instead using the goldbach syntax. - // Between the corresponding values of the mediaTypes.video and params.video objects, the properties in params.video will - // take precedence if declared; eg in the example below, the `skippable: true` setting will be used instead of the `skip: 0`. - minduration: 1, - maxduration: 60, - skip: 0, // 1 - true, 0 - false - skipafter: 5, - playbackmethod: [2], // note - we only support options 1-4 at this time - api: [1,2,3] // note - option 6 is not supported at this time - } - }, - bids: [ - { - bidder: 'goldbach', - params: { - placementId: 13232385, - video: { - skippable: true, - playback_method: 'auto_play_sound_off' - } - } - } - ] - }, - // Banner adUnit in a App Webview - // Only use this for situations where prebid.js is in a webview of an App - // See Prebid Mobile for displaying ads via an SDK - { - code: 'banner-div', - mediaTypes: { - banner: { - sizes: [[300, 250], [300,600]] - } - } - bids: [{ - bidder: 'goldbach', - params: { - placementId: 13144370, - app: { - id: "B1O2W3M4AN.com.prebid.webview", - geo: { - lat: 40.0964439, - lng: -75.3009142 - }, - device_id: { - idfa: "4D12078D-3246-4DA4-AD5E-7610481E7AE", // Apple advertising identifier - aaid: "38400000-8cf0-11bd-b23e-10b96e40000d", // Android advertising identifier - md5udid: "5756ae9022b2ea1e47d84fead75220c8", // MD5 hash of the ANDROID_ID - sha1udid: "4DFAA92388699AC6539885AEF1719293879985BF", // SHA1 hash of the ANDROID_ID - windowsadid: "750c6be243f1c4b5c9912b95a5742fc5" // Windows advertising identifier - } - } - } - }] - } -]; -``` diff --git a/modules/googleAnalyticsAdapter.js b/modules/googleAnalyticsAdapter.js index b230d1c9516..a8fc83ae62e 100644 --- a/modules/googleAnalyticsAdapter.js +++ b/modules/googleAnalyticsAdapter.js @@ -2,8 +2,8 @@ * ga.js - analytics adapter for google analytics */ -import { _each, logMessage } from '../src/utils.js'; var events = require('../src/events.js'); +var utils = require('../src/utils.js'); var CONSTANTS = require('../src/constants.json'); var adapterManager = require('../src/adapterManager.js').default; @@ -54,7 +54,7 @@ adapter.enableAnalytics = function ({ provider, options }) { var existingEvents = events.getEvents(); - _each(existingEvents, function (eventObj) { + utils._each(existingEvents, function (eventObj) { if (typeof eventObj !== 'object') { return; } @@ -98,12 +98,12 @@ adapter.enableAnalytics = function ({ provider, options }) { sendBidWonToGa(bid); }); } else { - logMessage('Prebid.js google analytics disabled by sampling'); + utils.logMessage('Prebid.js google analytics disabled by sampling'); } // finally set this function to return log message, prevents multiple adapter listeners this.enableAnalytics = function _enable() { - return logMessage(`Analytics adapter already enabled, unnecessary call to \`enableAnalytics\`.`); + return utils.logMessage(`Analytics adapter already enabled, unnecessary call to \`enableAnalytics\`.`); }; }; @@ -129,7 +129,7 @@ function checkAnalytics() { _enableCheck = false; } - logMessage('event count sent to GA: ' + _eventCount); + utils.logMessage('event count sent to GA: ' + _eventCount); } function convertToCents(dollars) { @@ -242,7 +242,7 @@ function sendBidResponseToGa(bid) { function sendBidTimeouts(timedOutBidders) { _analyticsQueue.push(function () { - _each(timedOutBidders, function (bidderCode) { + utils._each(timedOutBidders, function (bidderCode) { _eventCount++; var bidderName = bidderCode.bidder; window[_gaGlobal](_trackerSend, 'event', _category, 'Timeouts', bidderName, _disableInteraction); diff --git a/modules/gothamadsBidAdapter.js b/modules/gothamadsBidAdapter.js index 1993f0c9b64..ff6fa5221f3 100644 --- a/modules/gothamadsBidAdapter.js +++ b/modules/gothamadsBidAdapter.js @@ -1,6 +1,6 @@ -import { logMessage, deepSetValue, deepAccess, _map, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'gothamads'; @@ -79,7 +79,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let bids = []; @@ -110,12 +110,12 @@ export const spec = { }; if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) { - deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); - deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); + utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0); + utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString); } if (bidRequest.uspConsent !== undefined) { - deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); + utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent); } bids.push(data) @@ -186,7 +186,7 @@ export const spec = { * @returns {boolean} */ const checkRequestType = (bidRequest, type) => { - return (typeof deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); + return (typeof utils.deepAccess(bidRequest, `mediaTypes.${type}`) !== 'undefined'); } const parseNative = admObject => { @@ -246,7 +246,7 @@ const addNativeParameters = bidRequest => { ver: NATIVE_VERSION, }; - const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => { + const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -300,7 +300,7 @@ const parseSizes = (bid, mediaType) => { mediaTypes.video.w, mediaTypes.video.h ]; - } else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { + } else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { size = bid.mediaTypes.video.playerSize[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) { size = bid.sizes[0]; @@ -313,7 +313,7 @@ const parseSizes = (bid, mediaType) => { } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { sizes = bid.sizes } else { - logWarn('no sizes are setup or found'); + utils.logWarn('no sizes are setup or found'); } return sizes diff --git a/modules/gptPreAuction.js b/modules/gptPreAuction.js index 88f90419aeb..c351a5181a9 100644 --- a/modules/gptPreAuction.js +++ b/modules/gptPreAuction.js @@ -1,5 +1,5 @@ -import { isGptPubadsDefined, isAdUnitCodeMatchingSlot, deepAccess, pick, logInfo } from '../src/utils.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { getHook } from '../src/hook.js'; import find from 'core-js-pure/features/array/find.js'; @@ -10,7 +10,7 @@ let hooksAdded = false; export const appendGptSlots = adUnits => { const { customGptSlotMatching } = _currentConfig; - if (!isGptPubadsDefined()) { + if (!utils.isGptPubadsDefined()) { return; } @@ -22,7 +22,7 @@ export const appendGptSlots = adUnits => { window.googletag.pubads().getSlots().forEach(slot => { const matchingAdUnitCode = find(Object.keys(adUnitMap), customGptSlotMatching ? customGptSlotMatching(slot) - : isAdUnitCodeMatchingSlot(slot)); + : utils.isAdUnitCodeMatchingSlot(slot)); if (matchingAdUnitCode) { const adUnit = adUnitMap[matchingAdUnitCode]; @@ -48,48 +48,22 @@ const sanitizeSlotPath = (path) => { return path; } -const defaultPreAuction = (adUnit, adServerAdSlot) => { - const context = adUnit.ortb2Imp.ext.data; - - // use pbadslot if supplied - if (context.pbadslot) { - return context.pbadslot; - } - - // confirm that GPT is set up - if (!isGptPubadsDefined()) { - return; - } - - // find all GPT slots with this name - var gptSlots = window.googletag.pubads().getSlots().filter(slot => slot.getAdUnitPath() === adServerAdSlot); - - if (gptSlots.length === 0) { - return; // should never happen - } - - if (gptSlots.length === 1) { - return adServerAdSlot; - } - - // else the adunit code must be div id. append it. - return `${adServerAdSlot}#${adUnit.code}`; -} - export const appendPbAdSlot = adUnit => { + adUnit.ortb2Imp = adUnit.ortb2Imp || {}; + adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {}; + adUnit.ortb2Imp.ext.data = adUnit.ortb2Imp.ext.data || {}; const context = adUnit.ortb2Imp.ext.data; const { customPbAdSlot } = _currentConfig; - // use context.pbAdSlot if set (if someone set it already, it will take precedence over others) - if (context.pbadslot) { + if (customPbAdSlot) { + context.pbadslot = customPbAdSlot(adUnit.code, utils.deepAccess(context, 'adserver.adslot')); return; } - if (customPbAdSlot) { - context.pbadslot = customPbAdSlot(adUnit.code, deepAccess(context, 'adserver.adslot')); + // use context.pbAdSlot if set + if (context.pbadslot) { return; } - // use data attribute 'data-adslotid' if set try { const adUnitCodeDiv = document.getElementById(adUnit.code); @@ -99,55 +73,27 @@ export const appendPbAdSlot = adUnit => { } } catch (e) {} // banner adUnit, use GPT adunit if defined - if (deepAccess(context, 'adserver.adslot')) { + if (utils.deepAccess(context, 'adserver.adslot')) { context.pbadslot = context.adserver.adslot; return; } context.pbadslot = adUnit.code; - return true; }; export const makeBidRequestsHook = (fn, adUnits, ...args) => { appendGptSlots(adUnits); - const { useDefaultPreAuction, customPreAuction } = _currentConfig; adUnits.forEach(adUnit => { - // init the ortb2Imp if not done yet - adUnit.ortb2Imp = adUnit.ortb2Imp || {}; - adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {}; - adUnit.ortb2Imp.ext.data = adUnit.ortb2Imp.ext.data || {}; - const context = adUnit.ortb2Imp.ext; - - // if neither new confs set do old stuff - if (!customPreAuction && !useDefaultPreAuction) { - const usedAdUnitCode = appendPbAdSlot(adUnit); - // gpid should be set to itself if already set, or to what pbadslot was (as long as it was not adUnit code) - if (!context.gpid && !usedAdUnitCode) { - context.gpid = context.data.pbadslot; - } - } else { - let adserverSlot = deepAccess(context, 'data.adserver.adslot'); - let result; - if (customPreAuction) { - result = customPreAuction(adUnit, adserverSlot); - } else if (useDefaultPreAuction) { - result = defaultPreAuction(adUnit, adserverSlot); - } - if (result) { - context.gpid = context.data.pbadslot = result; - } - } + appendPbAdSlot(adUnit); }); return fn.call(this, adUnits, ...args); }; const handleSetGptConfig = moduleConfig => { - _currentConfig = pick(moduleConfig, [ + _currentConfig = utils.pick(moduleConfig, [ 'enabled', enabled => enabled !== false, 'customGptSlotMatching', customGptSlotMatching => typeof customGptSlotMatching === 'function' && customGptSlotMatching, 'customPbAdSlot', customPbAdSlot => typeof customPbAdSlot === 'function' && customPbAdSlot, - 'customPreAuction', customPreAuction => typeof customPreAuction === 'function' && customPreAuction, - 'useDefaultPreAuction', useDefaultPreAuction => useDefaultPreAuction === true, ]); if (_currentConfig.enabled) { @@ -156,7 +102,7 @@ const handleSetGptConfig = moduleConfig => { hooksAdded = true; } } else { - logInfo(`${MODULE_NAME}: Turning off module`); + utils.logInfo(`${MODULE_NAME}: Turning off module`); _currentConfig = {}; getHook('makeBidRequests').getHooks({hook: makeBidRequestsHook}).remove(); hooksAdded = false; diff --git a/modules/gridBidAdapter.js b/modules/gridBidAdapter.js index df1f4f3b6d7..0da15499e0c 100644 --- a/modules/gridBidAdapter.js +++ b/modules/gridBidAdapter.js @@ -1,18 +1,17 @@ -import { isEmpty, deepAccess, logError, parseGPTSingleSizeArrayToRtbSize, generateUUID, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; -import { getStorageManager } from '../src/storageManager.js'; const BIDDER_CODE = 'grid'; const ENDPOINT_URL = 'https://grid.bidswitch.net/hbjson'; const SYNC_URL = 'https://x.bidswitch.net/sync?ssp=themediagrid'; const TIME_TO_LIVE = 360; -const USER_ID_KEY = 'tmguid'; -const GVLID = 686; const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js'; -export const storage = getStorageManager(GVLID, BIDDER_CODE); + +let hasSynced = false; + const LOG_ERROR_MESS = { noAuid: 'Bid from response has no auid parameter - ', noAdm: 'Bid from response has no adm parameter - ', @@ -24,12 +23,8 @@ const LOG_ERROR_MESS = { hasEmptySeatbidArray: 'Response has empty seatbid array', hasNoArrayOfBids: 'Seatbid from response has no array of bid objects - ' }; - -let hasSynced = false; - export const spec = { code: BIDDER_CODE, - aliases: ['playwire', 'adlivetech'], supportedMediaTypes: [ BANNER, VIDEO ], /** * Determines whether or not the given bid request is valid. @@ -55,6 +50,7 @@ export const spec = { let jwpseg = null; let content = null; let schain = null; + let userId = null; let userIdAsEids = null; let user = null; let userExt = null; @@ -74,6 +70,9 @@ export const spec = { if (!schain) { schain = bid.schain; } + if (!userId) { + userId = bid.userId; + } if (!userIdAsEids) { userIdAsEids = bid.userIdAsEids; } @@ -90,21 +89,19 @@ export const spec = { } } let impObj = { - id: bidId.toString(), + id: bidId, tagid: uid.toString(), ext: { - divid: adUnitCode.toString() + divid: adUnitCode } }; if (ortb2Imp && ortb2Imp.ext && ortb2Imp.ext.data) { impObj.ext.data = ortb2Imp.ext.data; if (impObj.ext.data.adserver && impObj.ext.data.adserver.adslot) { - impObj.ext.gpid = impObj.ext.data.adserver.adslot.toString(); - } else { - impObj.ext.gpid = ortb2Imp.ext.data.pbadslot && ortb2Imp.ext.data.pbadslot.toString(); + impObj.ext.gpid = impObj.ext.data.adserver.adslot; } } - if (!isEmpty(keywords)) { + if (!utils.isEmpty(keywords)) { if (!pageKeywords) { pageKeywords = keywords; } @@ -134,7 +131,7 @@ export const spec = { }); const source = { - tid: auctionId && auctionId.toString(), + tid: auctionId, ext: { wrapper: 'Prebid_js', wrapper_version: '$prebid.version$' @@ -149,7 +146,7 @@ export const spec = { const tmax = timeout ? Math.min(bidderTimeout, timeout) : bidderTimeout; let request = { - id: bidderRequestId && bidderRequestId.toString(), + id: bidderRequestId, site: { page: referer }, @@ -187,19 +184,12 @@ export const spec = { user.ext = userExt; } - const fpdUserId = getUserIdFromFPDStorage(); - - if (fpdUserId) { - user = user || {}; - user.id = fpdUserId.toString(); - } - if (user) { request.user = user; } - const userKeywords = deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; - const siteKeywords = deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; + const userKeywords = utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; + const siteKeywords = utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; if (userKeywords) { pageKeywords = pageKeywords || {}; @@ -284,18 +274,17 @@ export const spec = { _addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses); }); } - if (errorMessage) logError(errorMessage); + if (errorMessage) utils.logError(errorMessage); return bidResponses; }, getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { if (!hasSynced && syncOptions.pixelEnabled) { let params = ''; - if (gdprConsent) { + if (gdprConsent && typeof gdprConsent.consentString === 'string') { if (typeof gdprConsent.gdprApplies === 'boolean') { - params += `&gdpr=${Number(gdprConsent.gdprApplies)}`; - } - if (typeof gdprConsent.consentString === 'string') { + params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { params += `&gdpr_consent=${gdprConsent.consentString}`; } } @@ -341,11 +330,11 @@ function _getFloor (mediaTypes, bid) { function _getBidFromResponse(respItem) { if (!respItem) { - logError(LOG_ERROR_MESS.emptySeatbid); + utils.logError(LOG_ERROR_MESS.emptySeatbid); } else if (!respItem.bid) { - logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); + utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); } else if (!respItem.bid[0]) { - logError(LOG_ERROR_MESS.noBid); + utils.logError(LOG_ERROR_MESS.noBid); } return respItem && respItem.bid && respItem.bid[0]; } @@ -354,7 +343,7 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) { if (!serverBid) return; let errorMessage; if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid); - if (!errorMessage && !serverBid.adm && !serverBid.nurl) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); + if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); else { const bid = bidRequest.bidsMap[serverBid.impid]; if (bid) { @@ -379,15 +368,11 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) { } if (serverBid.content_type === 'video') { - if (serverBid.adm) { - bidResponse.vastXml = serverBid.adm; - bidResponse.adResponse = { - content: bidResponse.vastXml - }; - } else if (serverBid.nurl) { - bidResponse.vastUrl = serverBid.nurl; - } + bidResponse.vastXml = serverBid.adm; bidResponse.mediaType = VIDEO; + bidResponse.adResponse = { + content: bidResponse.vastXml + }; if (!bid.renderer && (!bid.mediaTypes || !bid.mediaTypes.video || bid.mediaTypes.video.context === 'outstream')) { bidResponse.renderer = createRenderer(bidResponse, { id: bid.bidId, @@ -402,7 +387,7 @@ function _addBidResponse(serverBid, bidRequest, bidResponses) { } } if (errorMessage) { - logError(errorMessage); + utils.logError(errorMessage); } } @@ -411,7 +396,7 @@ function createVideoRequest(bid, mediaType) { const size = (playerSize || bid.sizes || [])[0]; if (!size) return; - let result = parseGPTSingleSizeArrayToRtbSize(size); + let result = utils.parseGPTSingleSizeArrayToRtbSize(size); if (mimes) { result.mimes = mimes; @@ -433,8 +418,8 @@ function createBannerRequest(bid, mediaType) { const sizes = mediaType.sizes || bid.sizes; if (!sizes || !sizes.length) return; - let format = sizes.map((size) => parseGPTSingleSizeArrayToRtbSize(size)); - let result = parseGPTSingleSizeArrayToRtbSize(sizes[0]); + let format = sizes.map((size) => utils.parseGPTSingleSizeArrayToRtbSize(size)); + let result = utils.parseGPTSingleSizeArrayToRtbSize(sizes[0]); if (format.length) { result.format = format @@ -442,20 +427,6 @@ function createBannerRequest(bid, mediaType) { return result; } -function makeNewUserIdInFPDStorage() { - if (config.getConfig('localStorageWriteAllowed')) { - const value = generateUUID().replace(/-/g, ''); - - storage.setDataInLocalStorage(USER_ID_KEY, value); - return value; - } - return null; -} - -function getUserIdFromFPDStorage() { - return storage.getDataFromLocalStorage(USER_ID_KEY) || makeNewUserIdInFPDStorage(); -} - function reformatKeywords(pageKeywords) { const formatedPageKeywords = {}; Object.keys(pageKeywords).forEach((name) => { @@ -520,7 +491,7 @@ function createRenderer (bid, rendererParams) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; diff --git a/modules/gridBidAdapter.md b/modules/gridBidAdapter.md index 8eb8dfc19fb..6a7075ccb00 100644 --- a/modules/gridBidAdapter.md +++ b/modules/gridBidAdapter.md @@ -9,17 +9,6 @@ Maintainer: grid-tech@themediagrid.com Module that connects to Grid demand source to fetch bids. Grid bid adapter supports Banner and Video (instream and outstream). -#Bidder Config -You can allow writing in localStorage `pbjs.setBidderConfig` for the bidder `grid` -``` -pbjs.setBidderConfig({ - bidders: ["grid"], - config: { - localStorageWriteAllowed: true - } - }) -``` - # Test Parameters ``` var adUnits = [ diff --git a/modules/gridNMBidAdapter.js b/modules/gridNMBidAdapter.js index 3c46b25b8e1..4ab8464b115 100644 --- a/modules/gridNMBidAdapter.js +++ b/modules/gridNMBidAdapter.js @@ -1,11 +1,10 @@ -import { isStr, deepAccess, isArray, isNumber, logError, logWarn, parseGPTSingleSizeArrayToRtbSize } from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import { VIDEO } from '../src/mediaTypes.js'; -import { config } from '../src/config.js'; const BIDDER_CODE = 'gridNM'; -const ENDPOINT_URL = 'https://grid.bidswitch.net/hbjson'; +const ENDPOINT_URL = 'https://grid.bidswitch.net/hbnm'; const SYNC_URL = 'https://x.bidswitch.net/sync?ssp=themediagrid'; const TIME_TO_LIVE = 360; const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js'; @@ -38,19 +37,19 @@ export const spec = { */ isBidRequestValid: function(bid) { let invalid = - !bid.params.source || !isStr(bid.params.source) || - !bid.params.secid || !isStr(bid.params.secid) || - !bid.params.pubid || !isStr(bid.params.pubid); + !bid.params.source || !utils.isStr(bid.params.source) || + !bid.params.secid || !utils.isStr(bid.params.secid) || + !bid.params.pubid || !utils.isStr(bid.params.pubid); - const video = deepAccess(bid, 'mediaTypes.video') || {}; - const { protocols = video.protocols, mimes = video.mimes } = deepAccess(bid, 'params.video') || {}; + const video = utils.deepAccess(bid, 'mediaTypes.video') || {}; + const { protocols = video.protocols, mimes = video.mimes } = utils.deepAccess(bid, 'params.video') || {}; if (!invalid) { invalid = !protocols || !mimes; } if (!invalid) { - invalid = !isArray(mimes) || !mimes.length || mimes.filter((it) => !(it && isStr(it))).length; + invalid = !utils.isArray(mimes) || !mimes.length || mimes.filter((it) => !(it && utils.isStr(it))).length; if (!invalid) { - invalid = !isArray(protocols) || !protocols.length || protocols.filter((it) => !(isNumber(it) && it > 0 && !(it % 1))).length; + invalid = !utils.isArray(protocols) || !protocols.length || protocols.filter((it) => !(utils.isNumber(it) && it > 0 && !(it % 1))).length; } } return !invalid; @@ -65,146 +64,62 @@ export const spec = { buildRequests: function(validBidRequests, bidderRequest) { const bids = validBidRequests || []; const requests = []; - let { bidderRequestId, auctionId, gdprConsent, uspConsent, timeout, refererInfo } = bidderRequest || {}; - - const referer = refererInfo ? encodeURIComponent(refererInfo.referer) : ''; bids.forEach(bid => { - let user; - let userExt; - - const schain = bid.schain; - const userIdAsEids = bid.userIdAsEids; - - if (!bidderRequestId) { - bidderRequestId = bid.bidderRequestId; - } - if (!auctionId) { - auctionId = bid.auctionId; - } - const { - params: { floorcpm, pubdata, source, secid, pubid, content, video }, - mediaTypes, bidId, adUnitCode, rtd, ortb2Imp, sizes - } = bid; - - const bidFloor = _getFloor(mediaTypes || {}, bid, isNumber(floorcpm) && floorcpm); - const jwTargeting = rtd && rtd.jwplayer && rtd.jwplayer.targeting; - const jwpseg = (pubdata && pubdata.jwpseg) || (jwTargeting && jwTargeting.segments); - - const siteContent = content || (jwTargeting && jwTargeting.content); - - const impObj = { - id: bidId.toString(), - tagid: secid.toString(), - video: createVideoForImp(video, sizes, mediaTypes && mediaTypes.video), - ext: { - divid: adUnitCode.toString() - } + const { params, bidderRequestId, sizes } = bid; + const payload = { + sizes: utils.parseSizesInput(sizes).join(','), + r: bidderRequestId, + wrapperType: 'Prebid_js', + wrapperVersion: '$prebid.version$' }; - if (ortb2Imp && ortb2Imp.ext && ortb2Imp.ext.data) { - impObj.ext.data = ortb2Imp.ext.data; - if (impObj.ext.data.adserver && impObj.ext.data.adserver.adslot) { - impObj.ext.gpid = impObj.ext.data.adserver.adslot.toString(); - } else { - impObj.ext.gpid = ortb2Imp.ext.data.pbadslot && ortb2Imp.ext.data.pbadslot.toString(); + if (bidderRequest) { + if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) { + payload.u = bidderRequest.refererInfo.referer; } - } - - if (bidFloor) { - impObj.bidfloor = bidFloor; - } - - const imp = [impObj]; - - const reqSource = { - tid: auctionId && auctionId.toString(), - ext: { - wrapper: 'Prebid_js', - wrapper_version: '$prebid.version$' + if (bidderRequest.timeout) { + payload.wtimeout = bidderRequest.timeout; } - }; - - if (schain) { - reqSource.ext.schain = schain; - } - - const bidderTimeout = config.getConfig('bidderTimeout') || timeout; - const tmax = timeout ? Math.min(bidderTimeout, timeout) : bidderTimeout; - - const request = { - id: bidderRequestId && bidderRequestId.toString(), - site: { - page: referer, - publisher: { - id: pubid, - }, - }, - source: reqSource, - tmax, - imp, - }; - - if (siteContent) { - request.site.content = siteContent; - } - - if (jwpseg && jwpseg.length) { - user = { - data: [{ - name: 'iow_labs_pub_data', - segment: jwpseg.map((seg) => { - return {name: 'jwpseg', value: seg}; - }) - }] - }; - } - - if (gdprConsent && gdprConsent.consentString) { - userExt = { consent: gdprConsent.consentString }; - } - - if (userIdAsEids && userIdAsEids.length) { - userExt = userExt || {}; - userExt.eids = [...userIdAsEids]; - } - - if (userExt && Object.keys(userExt).length) { - user = user || {}; - user.ext = userExt; - } - - if (user) { - request.user = user; - } - - if (gdprConsent && gdprConsent.gdprApplies) { - request.regs = { - ext: { - gdpr: gdprConsent.gdprApplies ? 1 : 0 + if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent.consentString) { + payload.gdpr_consent = bidderRequest.gdprConsent.consentString; } + payload.gdpr_applies = + (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') + ? Number(bidderRequest.gdprConsent.gdprApplies) : 1; + } + if (bidderRequest.uspConsent) { + payload.us_privacy = bidderRequest.uspConsent; } } - if (uspConsent) { - if (!request.regs) { - request.regs = { ext: {} }; + const video = utils.deepAccess(bid, 'mediaTypes.video') || {}; + const paramsVideo = Object.assign({}, params.video); + VIDEO_KEYS.forEach((key) => { + if (!(key in paramsVideo) && key in video) { + paramsVideo[key] = video[key]; } - request.regs.ext.us_privacy = uspConsent; + }); + + if (!paramsVideo.size && video.playerSize && video.playerSize.length === 2) { + paramsVideo.size = video.playerSize.join('x'); } - if (config.getConfig('coppa') === true) { - if (!request.regs) { - request.regs = {}; - } - request.regs.coppa = 1; + if (!('mind' in paramsVideo) && 'minduration' in video) { + paramsVideo.mind = video.minduration; } + if (!('maxd' in paramsVideo) && 'maxduration' in video) { + paramsVideo.maxd = video.maxduration; + } + + const paramsToSend = Object.assign({}, params, {video: paramsVideo}); requests.push({ method: 'POST', - url: ENDPOINT_URL + '?no_mapping=1&sp=' + source, + url: ENDPOINT_URL + '?' + utils.parseQueryStringParameters(payload).replace(/\&$/, ''), bid: bid, - data: request + data: paramsToSend // content }); }); @@ -231,11 +146,16 @@ export const spec = { if (!errorMessage && serverResponse.seatbid) { const serverBid = _getBidFromResponse(serverResponse.seatbid[0]); if (serverBid) { - if (!serverBid.adm && !serverBid.nurl) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); + if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); else if (!serverBid.price) errorMessage = LOG_ERROR_MESS.noPrice + JSON.stringify(serverBid); else if (serverBid.content_type !== 'video') errorMessage = LOG_ERROR_MESS.wrongContentType + serverBid.content_type; if (!errorMessage) { const bid = bidRequest.bid; + if (!serverBid.w || !serverBid.h) { + const size = utils.parseSizesInput(bid.sizes)[0].split('x'); + serverBid.w = size[0]; + serverBid.h = size[1]; + } const bidResponse = { requestId: bid.bidId, cpm: serverBid.price, @@ -246,21 +166,16 @@ export const spec = { netRevenue: true, ttl: TIME_TO_LIVE, dealId: serverBid.dealid, + vastXml: serverBid.adm, mediaType: VIDEO, meta: { advertiserDomains: serverBid.adomain ? serverBid.adomain : [] + }, + adResponse: { + content: serverBid.adm } }; - if (serverBid.adm) { - bidResponse.vastXml = serverBid.adm; - bidResponse.adResponse = { - content: bidResponse.vastXml - }; - } else if (serverBid.nurl) { - bidResponse.vastUrl = serverBid.nurl; - } - if (!bid.renderer && (!bid.mediaTypes || !bid.mediaTypes.video || bid.mediaTypes.video.context === 'outstream')) { bidResponse.renderer = createRenderer(bidResponse, { id: bid.bidId, @@ -271,7 +186,7 @@ export const spec = { } } } - if (errorMessage) logError(errorMessage); + if (errorMessage) utils.logError(errorMessage); return bidResponses; }, getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { @@ -298,40 +213,13 @@ export const spec = { } }; -/** - * Gets bidfloor - * @param {Object} mediaTypes - * @param {Object} bid - * @param {Number} floor - * @returns {Number} floor - */ -function _getFloor (mediaTypes, bid, floor) { - const curMediaType = mediaTypes.video ? 'video' : 'banner'; - - if (typeof bid.getFloor === 'function') { - const floorInfo = bid.getFloor({ - currency: 'USD', - mediaType: curMediaType, - size: bid.sizes.map(([w, h]) => ({w, h})) - }); - - if (typeof floorInfo === 'object' && - floorInfo.currency === 'USD' && - !isNaN(parseFloat(floorInfo.floor))) { - floor = Math.max(floor, parseFloat(floorInfo.floor)); - } - } - - return floor; -} - function _getBidFromResponse(respItem) { if (!respItem) { - logError(LOG_ERROR_MESS.emptySeatbid); + utils.logError(LOG_ERROR_MESS.emptySeatbid); } else if (!respItem.bid) { - logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); + utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); } else if (!respItem.bid[0]) { - logError(LOG_ERROR_MESS.noBid); + utils.logError(LOG_ERROR_MESS.noBid); } return respItem && respItem.bid && respItem.bid[0]; } @@ -355,51 +243,12 @@ function createRenderer (bid, rendererParams) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; } -function createVideoForImp({ mind, maxd, size, ...paramsVideo }, bidSizes, bidVideo = {}) { - VIDEO_KEYS.forEach((key) => { - if (!(key in paramsVideo) && key in bidVideo) { - paramsVideo[key] = bidVideo[key]; - } - }); - - if (size && isStr(size)) { - const sizeArray = size.split('x'); - if (sizeArray.length === 2 && parseInt(sizeArray[0]) && parseInt(sizeArray[1])) { - paramsVideo.w = parseInt(sizeArray[0]); - paramsVideo.h = parseInt(sizeArray[1]); - } - } - - if (!paramsVideo.w || !paramsVideo.h) { - const playerSizes = bidVideo.playerSize && bidVideo.playerSize.length === 2 ? bidVideo.playerSize : bidSizes; - if (playerSizes) { - const playerSize = playerSizes[0]; - if (playerSize) { - Object.assign(paramsVideo, parseGPTSingleSizeArrayToRtbSize(playerSize)); - } - } - } - - const durationRangeSec = bidVideo.durationRangeSec || []; - const minDur = mind || durationRangeSec[0] || bidVideo.minduration; - const maxDur = maxd || durationRangeSec[1] || bidVideo.maxduration; - - if (minDur) { - paramsVideo.minduration = minDur; - } - if (maxDur) { - paramsVideo.maxduration = maxDur; - } - - return paramsVideo; -} - export function resetUserSync() { hasSynced = false; } diff --git a/modules/growadvertisingBidAdapter.js b/modules/growadvertisingBidAdapter.js index 286d27607c5..0626b137a1b 100644 --- a/modules/growadvertisingBidAdapter.js +++ b/modules/growadvertisingBidAdapter.js @@ -1,8 +1,9 @@ 'use strict'; -import { getBidIdParameter, deepAccess, _each, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE} from '../src/mediaTypes.js'; +import {triggerPixel} from '../src/utils.js'; const BIDDER_CODE = 'growads'; @@ -22,8 +23,8 @@ export const spec = { const zoneCounters = {}; return validBidRequests.map(bidRequest => { - zoneId = getBidIdParameter('zoneId', bidRequest.params); - domain = getBidIdParameter('domain', bidRequest.params); + zoneId = utils.getBidIdParameter('zoneId', bidRequest.params); + domain = utils.getBidIdParameter('domain', bidRequest.params); if (!(zoneId in zoneCounters)) { zoneCounters[zoneId] = 0; @@ -76,8 +77,8 @@ export const spec = { width = parseInt(response.width); height = parseInt(response.height); - minCPM = getBidIdParameter('minCPM', request.params); - maxCPM = getBidIdParameter('maxCPM', request.params); + minCPM = utils.getBidIdParameter('minCPM', request.params); + maxCPM = utils.getBidIdParameter('maxCPM', request.params); width = parseInt(response.width); height = parseInt(response.height); @@ -101,7 +102,7 @@ export const spec = { netRevenue: true, ttl: response.ttl, adUnitCode: request.adUnitCode, - referrer: deepAccess(request, 'refererInfo.referer') + referrer: utils.deepAccess(request, 'refererInfo.referer') }; if (response.hasOwnProperty(NATIVE)) { @@ -136,7 +137,7 @@ export const spec = { bid.ad = response.ad; bid.mediaType = BANNER; // Ensure that response ad matches one of the placement sizes. - _each(deepAccess(request, 'mediaTypes.banner.sizes', []), function (size) { + utils._each(utils.deepAccess(request, 'mediaTypes.banner.sizes', []), function (size) { if (width === size[0] && height === size[1]) { isCorrectSize = true; } diff --git a/modules/gumgumBidAdapter.js b/modules/gumgumBidAdapter.js index 244ac0c7c09..3a0862b9aec 100644 --- a/modules/gumgumBidAdapter.js +++ b/modules/gumgumBidAdapter.js @@ -1,5 +1,6 @@ +import * as utils from '../src/utils.js' + import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import { _each, deepAccess, logError, logWarn, parseSizesInput } from '../src/utils.js'; import { config } from '../src/config.js' import { getStorageManager } from '../src/storageManager.js'; @@ -50,7 +51,7 @@ function _getBrowserParams(topWindowUrl) { topScreen = topWindow.screen; topUrl = topWindowUrl || ''; } catch (error) { - logError(error); + utils.logError(error); return browserParams } @@ -130,7 +131,7 @@ function isBidRequestValid(bid) { const id = legacyParamID || params.slot || params.native || params.zone || params.pubID; if (invalidRequestIds[id]) { - logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`); + utils.logWarn(`[GumGum] Please check the implementation for ${id} for the placement ${adUnitCode}`); return false; } @@ -145,12 +146,12 @@ function isBidRequestValid(bid) { case !!(params.inVideo): break; case !!(params.videoPubID): break; default: - logWarn(`[GumGum] No product selected for the placement ${adUnitCode}, please check your implementation.`); + utils.logWarn(`[GumGum] No product selected for the placement ${adUnitCode}, please check your implementation.`); return false; } if (params.bidfloor && !(typeof params.bidfloor === 'number' && isFinite(params.bidfloor))) { - logWarn('[GumGum] bidfloor must be a Number'); + utils.logWarn('[GumGum] bidfloor must be a Number'); return false; } @@ -172,7 +173,7 @@ function _getVidParams(attributes) { protocols = [], playerSize = [] } = attributes; - const sizes = parseSizesInput(playerSize); + const sizes = utils.parseSizesInput(playerSize); const [viw, vih] = sizes[0] && sizes[0].split('x'); let pr = ''; @@ -278,7 +279,7 @@ function buildRequests(validBidRequests, bidderRequest) { const uspConsent = bidderRequest && bidderRequest.uspConsent; const timeout = config.getConfig('bidderTimeout'); const topWindowUrl = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - _each(validBidRequests, bidRequest => { + utils._each(validBidRequests, bidRequest => { const { bidId, mediaTypes = {}, @@ -286,8 +287,7 @@ function buildRequests(validBidRequests, bidderRequest) { schain, transactionId, userId = {}, - ortb2Imp, - adUnitCode = '' + ortb2Imp } = bidRequest; const { currency, floor } = _getFloor(mediaTypes, params.bidfloor, bidRequest); const eids = getEids(userId); @@ -295,24 +295,11 @@ function buildRequests(validBidRequests, bidderRequest) { let data = {}; let gpid = ''; - const date = new Date(); - const lt = date.getTime(); - const to = date.getTimezoneOffset(); - - // ADTS-174 Removed unnecessary checks to fix failing test - data.lt = lt; - data.to = to; - - // ADTS-169 add adUnitCode to requests - if (adUnitCode) data.aun = adUnitCode - // ADTS-134 Retrieve ID envelopes for (const eid in eids) data[eid] = eids[eid]; - // ADJS-1024 & ADSS-1297 - if (deepAccess(ortb2Imp, 'ext.data.pbadslot')) { - gpid = deepAccess(ortb2Imp, 'ext.data.pbadslot') - } else if (deepAccess(ortb2Imp, 'ext.data.adserver.name')) { + // ADJS-1024 + if (utils.deepAccess(ortb2Imp, 'ext.data.adserver.name')) { gpid = ortb2Imp.ext.data.adserver.adslot } @@ -349,11 +336,11 @@ function buildRequests(validBidRequests, bidderRequest) { const [maxw, maxh] = getGreatestDimensions(sizes); data.maxw = maxw; data.maxh = maxh; - data.si = params.slot; + data.si = parseInt(params.slot, 10); data.pi = 3; data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, ''); } else if (params.native) { - data.ni = params.native; + data.ni = parseInt(params.native, 10); data.pi = 5; } else if (mediaTypes.video) { data.pi = mediaTypes.video.linearity === 2 ? 6 : 7; // invideo : video @@ -404,12 +391,12 @@ function handleLegacyParams(params, sizes) { const [maxw, maxh] = getGreatestDimensions(sizes); data.maxw = maxw; data.maxh = maxh; - data.si = params.inSlot; + data.si = parseInt(params.inSlot, 10); data.pi = 3; data.bf = sizes.reduce((acc, curSlotDim) => `${acc}${acc && ','}${curSlotDim[0]}x${curSlotDim[1]}`, ''); } if (params.ICV) { - data.ni = params.ICV; + data.ni = parseInt(params.ICV, 10); data.pi = 5; } if (params.videoPubID) { @@ -446,7 +433,7 @@ function interpretResponse(serverResponse, bidRequest) { setTimeout(() => { !!invalidRequestIds[id] && delete invalidRequestIds[id]; }, delayTime); - logWarn(`[GumGum] Please check the implementation for ${id}`); + utils.logWarn(`[GumGum] Please check the implementation for ${id}`); } const defaultResponse = { @@ -494,19 +481,14 @@ function interpretResponse(serverResponse, bidRequest) { advertiserDomains: advertiserDomains || [], mediaType: type || mediaType }; - let sizes = parseSizesInput(bidRequest.sizes); + let sizes = utils.parseSizesInput(bidRequest.sizes); if (maxw && maxh) { sizes = [`${maxw}x${maxh}`]; } else if (product === 5 && includes(sizes, '1x1')) { sizes = ['1x1']; } else if (product === 2 && includes(sizes, '1x1')) { - const requestSizesThatMatchResponse = (bidRequest.sizes && bidRequest.sizes.reduce((result, current) => { - const [ width, height ] = current; - if (responseWidth === width || responseHeight === height) result.push(current.join('x')); - return result - }, [])) || []; - sizes = requestSizesThatMatchResponse.length ? requestSizesThatMatchResponse : parseSizesInput(bidRequest.sizes) + sizes = responseWidth && responseHeight ? [`${responseWidth}x${responseHeight}`] : utils.parseSizesInput(bidRequest.sizes) } let [width, height] = sizes[0].split('x'); diff --git a/modules/h12mediaBidAdapter.js b/modules/h12mediaBidAdapter.js index 9a6244a9e82..7b736780226 100644 --- a/modules/h12mediaBidAdapter.js +++ b/modules/h12mediaBidAdapter.js @@ -1,4 +1,4 @@ -import { inIframe, logError, logMessage, deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'h12media'; const DEFAULT_URL = 'https://bidder.h12-media.com/prebid/'; @@ -15,7 +15,7 @@ export const spec = { }, buildRequests: function(validBidRequests, bidderRequest) { - const isiframe = inIframe(); + const isiframe = utils.inIframe(); const screenSize = getClientDimensions(); const docSize = getDocumentDimensions(); @@ -24,7 +24,7 @@ export const spec = { const requestUrl = bidderParams.endpointdom || DEFAULT_URL; let pubsubid = bidderParams.pubsubid || ''; if (pubsubid && pubsubid.length > 32) { - logError('Bidder param \'pubsubid\' should be not more than 32 chars.'); + utils.logError('Bidder param \'pubsubid\' should be not more than 32 chars.'); pubsubid = ''; } const pubcontainerid = bidderParams.pubcontainerid; @@ -57,7 +57,7 @@ export const spec = { try { windowTop = window.top; } catch (e) { - logMessage(e); + utils.logMessage(e); windowTop = window; } @@ -66,11 +66,11 @@ export const spec = { url: requestUrl, options: {withCredentials: true}, data: { - gdpr: !!deepAccess(bidderRequest, 'gdprConsent.gdprApplies', false), - gdpr_cs: deepAccess(bidderRequest, 'gdprConsent.consentString', ''), - usp: !!deepAccess(bidderRequest, 'uspConsent', false), - usp_cs: deepAccess(bidderRequest, 'uspConsent', ''), - topLevelUrl: deepAccess(bidderRequest, 'refererInfo.referer', ''), + gdpr: !!utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies', false), + gdpr_cs: utils.deepAccess(bidderRequest, 'gdprConsent.consentString', ''), + usp: !!utils.deepAccess(bidderRequest, 'uspConsent', false), + usp_cs: utils.deepAccess(bidderRequest, 'uspConsent', ''), + topLevelUrl: utils.deepAccess(bidderRequest, 'refererInfo.referer', ''), refererUrl: windowTop.document.referrer, isiframe, version: '$prebid.version$', @@ -122,14 +122,14 @@ export const spec = { } return bidResponses; } catch (err) { - logError(err); + utils.logError(err); } }, getUserSyncs: function(syncOptions, serverResponses, gdprConsent, usPrivacy) { const syncs = []; - const uspApplies = !!deepAccess(usPrivacy, 'uspConsent', false); - const uspString = deepAccess(usPrivacy, 'uspConsent', ''); + const uspApplies = !!utils.deepAccess(usPrivacy, 'uspConsent', false); + const uspString = utils.deepAccess(usPrivacy, 'uspConsent', ''); gdprConsent = gdprConsent || { gdprApplies: false, consentString: '', }; diff --git a/modules/haloIdSystem.js b/modules/haloIdSystem.js index e961f75d31b..3011569a17d 100644 --- a/modules/haloIdSystem.js +++ b/modules/haloIdSystem.js @@ -8,7 +8,7 @@ import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; import {submodule} from '../src/hook.js'; -import { isFn, isStr, isPlainObject, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const MODULE_NAME = 'haloId'; const AU_GVLID = 561; @@ -21,9 +21,9 @@ export const storage = getStorageManager(AU_GVLID, 'halo'); * @param {String} defaultVal */ function paramOrDefault(param, defaultVal, arg) { - if (isFn(param)) { + if (utils.isFn(param)) { return param(arg); - } else if (isStr(param)) { + } else if (utils.isStr(param)) { return param; } return defaultVal; @@ -44,7 +44,7 @@ export const haloIdSubmodule = { */ decode(value) { let haloId = storage.getDataFromLocalStorage('auHaloId'); - if (isStr(haloId)) { + if (utils.isStr(haloId)) { return {haloId: haloId}; } return (value && typeof value['haloId'] === 'string') ? { 'haloId': value['haloId'] } : undefined; @@ -56,7 +56,7 @@ export const haloIdSubmodule = { * @returns {IdResponse|undefined} */ getId(config) { - if (!isPlainObject(config.params)) { + if (!utils.isPlainObject(config.params)) { config.params = {}; } const url = paramOrDefault(config.params.url, @@ -65,7 +65,7 @@ export const haloIdSubmodule = { const resp = function (callback) { let haloId = storage.getDataFromLocalStorage('auHaloId'); - if (isStr(haloId)) { + if (utils.isStr(haloId)) { const responseObj = {haloId: haloId}; callback(responseObj); } else { @@ -76,13 +76,13 @@ export const haloIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - logError(error); + utils.logError(error); } } callback(responseObj); }, error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; diff --git a/modules/hybridBidAdapter.js b/modules/hybridBidAdapter.js index 4383e62c16e..15f8acd824f 100644 --- a/modules/hybridBidAdapter.js +++ b/modules/hybridBidAdapter.js @@ -1,4 +1,4 @@ -import { _map, logWarn, deepAccess, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { auctionManager } from '../src/auctionManager.js' import { BANNER, VIDEO } from '../src/mediaTypes.js' @@ -21,7 +21,7 @@ const placementTypes = { }; function buildBidRequests(validBidRequests) { - return _map(validBidRequests, function(validBidRequest) { + return utils._map(validBidRequests, function(validBidRequest) { const params = validBidRequest.params; const bidRequest = { bidId: validBidRequest.bidId, @@ -63,7 +63,7 @@ const createRenderer = (bid) => { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; @@ -143,8 +143,8 @@ function hasVideoMandatoryParams(mediaTypes) { const isHasVideoContext = !!mediaTypes.video && (mediaTypes.video.context === 'instream' || mediaTypes.video.context === 'outstream'); const isPlayerSize = - !!deepAccess(mediaTypes, 'video.playerSize') && - isArray(deepAccess(mediaTypes, 'video.playerSize')); + !!utils.deepAccess(mediaTypes, 'video.playerSize') && + utils.isArray(utils.deepAccess(mediaTypes, 'video.playerSize')); return isHasVideoContext && isPlayerSize; } @@ -237,8 +237,8 @@ export const spec = { let bidRequests = JSON.parse(bidRequest.data).bidRequests; const serverBody = serverResponse.body; - if (serverBody && serverBody.bids && isArray(serverBody.bids)) { - return _map(serverBody.bids, function(bid) { + if (serverBody && serverBody.bids && utils.isArray(serverBody.bids)) { + return utils._map(serverBody.bids, function(bid) { let rawBid = find(bidRequests, function (item) { return item.bidId === bid.bidId; }); diff --git a/modules/iasRtdProvider.js b/modules/iasRtdProvider.js index 6f7b2d5215d..bbd2529bf86 100644 --- a/modules/iasRtdProvider.js +++ b/modules/iasRtdProvider.js @@ -1,18 +1,11 @@ import { submodule } from '../src/hook.js'; -import * as utils from '../src/utils.js'; -import { ajax } from '../src/ajax.js'; import { getGlobal } from '../src/prebidGlobal.js'; +import * as utils from '../src/utils.js'; +import { ajaxBuilder } from '../src/ajax.js'; /** @type {string} */ const MODULE_NAME = 'realTimeData'; const SUBMODULE_NAME = 'ias'; -const IAS_HOST = 'https://pixel.adsafeprotected.com/services/pub'; -export let iasTargeting = {}; -const BRAND_SAFETY_OBJECT_FIELD_NAME = 'brandSafety'; -const FRAUD_FIELD_NAME = 'fr'; -const SLOTS_OBJECT_FIELD_NAME = 'slots'; -const CUSTOM_FIELD_NAME = 'custom'; -const IAS_KW = 'ias-kw'; /** * Module init @@ -21,11 +14,6 @@ const IAS_KW = 'ias-kw'; * @return {boolean} */ export function init(config, userConsent) { - const params = config.params; - if (!params || !params.pubId) { - utils.logError('missing pubId param for IAS provider'); - return false; - } return true; } @@ -42,11 +30,9 @@ function stringifySlotSizes(sizes) { } function stringifySlot(bidRequest) { - const sizes = utils.getAdUnitSizes(bidRequest); const id = bidRequest.code; - const ss = stringifySlotSizes(sizes); - const adSlot = utils.getGptSlotInfoForAdUnitCode(bidRequest.code); - const p = utils.isEmpty(adSlot) ? bidRequest.code : adSlot.gptSlot; + const ss = stringifySlotSizes(bidRequest.sizes); + const p = bidRequest.bids[0].params.adUnitPath; const slot = { id, ss, p }; const keyValues = utils.getKeys(slot).map(function (key) { return [key, slot[key]].join(':'); @@ -62,24 +48,31 @@ function stringifyScreenSize() { return [(window.screen && window.screen.width) || -1, (window.screen && window.screen.height) || -1].join('.'); } -function formatTargetingData(adUnit) { +function getPageLevelKeywords(response) { let result = {}; - if (iasTargeting[BRAND_SAFETY_OBJECT_FIELD_NAME]) { - utils.mergeDeep(result, iasTargeting[BRAND_SAFETY_OBJECT_FIELD_NAME]); - } - if (iasTargeting[FRAUD_FIELD_NAME]) { - result[FRAUD_FIELD_NAME] = iasTargeting[FRAUD_FIELD_NAME]; - } - if (iasTargeting[CUSTOM_FIELD_NAME] && IAS_KW in iasTargeting[CUSTOM_FIELD_NAME]) { - result[IAS_KW] = iasTargeting[CUSTOM_FIELD_NAME][IAS_KW]; - } - if (iasTargeting[SLOTS_OBJECT_FIELD_NAME] && adUnit in iasTargeting[SLOTS_OBJECT_FIELD_NAME]) { - utils.mergeDeep(result, iasTargeting[SLOTS_OBJECT_FIELD_NAME][adUnit]); + if (response.brandSafety) { + shallowMerge(result, response.brandSafety); } + result.fr = response.fr; + result.custom = response.custom; return result; } -function constructQueryString(anId, adUnits) { +function shallowMerge(dest, src) { + utils.getKeys(src).reduce((dest, srcKey) => { + dest[srcKey] = src[srcKey]; + return dest; + }, dest); +} + +function getBidRequestData(reqBidsConfigObj, callback, config) { + const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; + + let isFinish = false; + + const IAS_HOST = 'https://pixel.adsafeprotected.com/services/pub'; + const { pubId } = config.params; + const anId = pubId; let queries = []; queries.push(['anId', anId]); @@ -92,68 +85,39 @@ function constructQueryString(anId, adUnits) { queries.push(['sr', stringifyScreenSize()]); queries.push(['url', encodeURIComponent(window.location.href)]); - return encodeURI(queries.map(qs => qs.join('=')).join('&')); -} - -function parseResponse(result) { - let iasResponse = {}; - try { - iasResponse = JSON.parse(result); - } catch (err) { - utils.logError('error', err); - } - iasTargeting = iasResponse; -} - -function getTargetingData(adUnits, config, userConsent) { - const targeting = {}; - try { - if (!utils.isEmpty(iasTargeting)) { - adUnits.forEach(function (adUnit) { - targeting[adUnit] = formatTargetingData(adUnit); - }); - } - } catch (err) { - utils.logError('error', err); - } - utils.logInfo('IAS targeting', targeting); - return targeting; -} - -export function getApiCallback() { - return { - success: function (response, req) { - if (req.status === 200) { - try { - parseResponse(response); - } catch (e) { - utils.logError('Unable to parse IAS response.', e); + const queryString = encodeURI(queries.map(qs => qs.join('=')).join('&')); + + const ajax = ajaxBuilder(); + + ajax(`${IAS_HOST}?${queryString}`, { + success: function (response, request) { + if (!isFinish) { + if (request.status === 200) { + const iasResponse = JSON.parse(response); + adUnits.forEach(adUnit => { + adUnit.bids.forEach(bid => { + const rtd = bid.rtd || {}; + const iasRtd = {}; + iasRtd[SUBMODULE_NAME] = Object.assign({}, rtd[SUBMODULE_NAME], getPageLevelKeywords(iasResponse)); + bid.rtd = Object.assign({}, rtd, iasRtd); + }); + }); } + isFinish = true; } + callback(); }, error: function () { - utils.logError('failed to retrieve IAS data'); + utils.logError('failed to retrieve targeting information'); + callback(); } - } -} - -function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { - const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; - const { pubId } = config.params; - const queryString = constructQueryString(pubId, adUnits); - ajax( - `${IAS_HOST}?${queryString}`, - getApiCallback(), - undefined, - { method: 'GET' } - ); + }); } /** @type {RtdSubmodule} */ export const iasSubModule = { name: SUBMODULE_NAME, init: init, - getTargetingData: getTargetingData, getBidRequestData: getBidRequestData }; diff --git a/modules/id5IdSystem.js b/modules/id5IdSystem.js index 43d26224164..d2d64f52738 100644 --- a/modules/id5IdSystem.js +++ b/modules/id5IdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { deepAccess, logInfo, deepSetValue, logError, isEmpty, isEmptyStr, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getRefererInfo } from '../src/refererDetection.js'; @@ -67,25 +67,25 @@ export const id5IdSubmodule = { } }; - const abTestingResult = deepAccess(value, 'ab_testing.result'); + const abTestingResult = utils.deepAccess(value, 'ab_testing.result'); switch (abTestingResult) { case 'control': // A/B Testing is enabled and user is in the Control Group - logInfo(LOG_PREFIX + 'A/B Testing - user is in the Control Group: ID5 ID is NOT exposed'); - deepSetValue(responseObj, 'id5id.ext.abTestingControlGroup', true); + utils.logInfo(LOG_PREFIX + 'A/B Testing - user is in the Control Group: ID5 ID is NOT exposed'); + utils.deepSetValue(responseObj, 'id5id.ext.abTestingControlGroup', true); break; case 'error': // A/B Testing is enabled, but configured improperly, so skip A/B testing - logError(LOG_PREFIX + 'A/B Testing ERROR! controlGroupPct must be a number >= 0 and <= 1'); + utils.logError(LOG_PREFIX + 'A/B Testing ERROR! controlGroupPct must be a number >= 0 and <= 1'); break; case 'normal': // A/B Testing is enabled but user is not in the Control Group, so ID5 ID is shared - logInfo(LOG_PREFIX + 'A/B Testing - user is NOT in the Control Group'); - deepSetValue(responseObj, 'id5id.ext.abTestingControlGroup', false); + utils.logInfo(LOG_PREFIX + 'A/B Testing - user is NOT in the Control Group'); + utils.deepSetValue(responseObj, 'id5id.ext.abTestingControlGroup', false); break; } - logInfo(LOG_PREFIX + 'Decoded ID', responseObj); + utils.logInfo(LOG_PREFIX + 'Decoded ID', responseObj); return responseObj; }, @@ -120,19 +120,19 @@ export const id5IdSubmodule = { }; // pass in optional data, but only if populated - if (hasGdpr && typeof consentData.consentString !== 'undefined' && !isEmpty(consentData.consentString) && !isEmptyStr(consentData.consentString)) { + if (hasGdpr && typeof consentData.consentString !== 'undefined' && !utils.isEmpty(consentData.consentString) && !utils.isEmptyStr(consentData.consentString)) { data.gdpr_consent = consentData.consentString; } - if (typeof usp !== 'undefined' && !isEmpty(usp) && !isEmptyStr(usp)) { + if (typeof usp !== 'undefined' && !utils.isEmpty(usp) && !utils.isEmptyStr(usp)) { data.us_privacy = usp; } - if (typeof signature !== 'undefined' && !isEmptyStr(signature)) { + if (typeof signature !== 'undefined' && !utils.isEmptyStr(signature)) { data.s = signature; } - if (typeof config.params.pd !== 'undefined' && !isEmptyStr(config.params.pd)) { + if (typeof config.params.pd !== 'undefined' && !utils.isEmptyStr(config.params.pd)) { data.pd = config.params.pd; } - if (typeof config.params.provider !== 'undefined' && !isEmptyStr(config.params.provider)) { + if (typeof config.params.provider !== 'undefined' && !utils.isEmptyStr(config.params.provider)) { data.provider = config.params.provider; } @@ -151,7 +151,7 @@ export const id5IdSubmodule = { if (response) { try { responseObj = JSON.parse(response); - logInfo(LOG_PREFIX + 'response received from the server', responseObj); + utils.logInfo(LOG_PREFIX + 'response received from the server', responseObj); resetNb(config.params.partner); @@ -165,17 +165,17 @@ export const id5IdSubmodule = { removeLegacyCookies(config.params.partner); } } catch (error) { - logError(LOG_PREFIX + error); + utils.logError(LOG_PREFIX + error); } } callback(responseObj); }, error: error => { - logError(LOG_PREFIX + 'getId fetch encountered an error', error); + utils.logError(LOG_PREFIX + 'getId fetch encountered an error', error); callback(); } }; - logInfo(LOG_PREFIX + 'requesting an ID from the server', data); + utils.logInfo(LOG_PREFIX + 'requesting an ID from the server', data); ajax(url, callbacks, JSON.stringify(data), { method: 'POST', withCredentials: true }); }; return { callback: resp }; @@ -198,29 +198,29 @@ export const id5IdSubmodule = { const partnerId = (config && config.params && config.params.partner) || 0; incrementNb(partnerId); - logInfo(LOG_PREFIX + 'using cached ID', cacheIdObj); + utils.logInfo(LOG_PREFIX + 'using cached ID', cacheIdObj); return cacheIdObj; } }; function hasRequiredConfig(config) { if (!config || !config.params || !config.params.partner || typeof config.params.partner !== 'number') { - logError(LOG_PREFIX + 'partner required to be defined as a number'); + utils.logError(LOG_PREFIX + 'partner required to be defined as a number'); return false; } if (!config.storage || !config.storage.type || !config.storage.name) { - logError(LOG_PREFIX + 'storage required to be set'); + utils.logError(LOG_PREFIX + 'storage required to be set'); return false; } // in a future release, we may return false if storage type or name are not set as required if (config.storage.type !== LOCAL_STORAGE) { - logWarn(LOG_PREFIX + `storage type recommended to be '${LOCAL_STORAGE}'. In a future release this may become a strict requirement`); + utils.logWarn(LOG_PREFIX + `storage type recommended to be '${LOCAL_STORAGE}'. In a future release this may become a strict requirement`); } // in a future release, we may return false if storage type or name are not set as required if (config.storage.name !== ID5_STORAGE_NAME) { - logWarn(LOG_PREFIX + `storage name recommended to be '${ID5_STORAGE_NAME}'. In a future release this may become a strict requirement`); + utils.logWarn(LOG_PREFIX + `storage name recommended to be '${ID5_STORAGE_NAME}'. In a future release this may become a strict requirement`); } return true; @@ -265,7 +265,7 @@ function getLegacyCookieSignature() { * @param {integer} partnerId */ function removeLegacyCookies(partnerId) { - logInfo(LOG_PREFIX + 'removing legacy cookies'); + utils.logInfo(LOG_PREFIX + 'removing legacy cookies'); LEGACY_COOKIE_NAMES.forEach(function(cookie) { storage.setCookie(`${cookie}`, ' ', expDaysStr(-1)); storage.setCookie(`${cookie}_nb`, ' ', expDaysStr(-1)); @@ -313,7 +313,7 @@ export function storeInLocalStorage(key, value, expDays) { * @returns {Object} an object which always contains at least the property "enabled" */ function getAbTestingConfig(config) { - return deepAccess(config, 'params.abTesting', { enabled: false }); + return utils.deepAccess(config, 'params.abTesting', { enabled: false }); } submodule('userId', id5IdSubmodule); diff --git a/modules/id5IdSystem.md b/modules/id5IdSystem.md index 11f8ffc5609..8ffe29e091f 100644 --- a/modules/id5IdSystem.md +++ b/modules/id5IdSystem.md @@ -1,14 +1,14 @@ # ID5 Universal ID -The ID5 ID is a shared, neutral identifier that publishers and ad tech platforms can use to recognise users even in environments where 3rd party cookies are not available. The ID5 ID is designed to respect users' privacy choices and publishers’ preferences throughout the advertising value chain. For more information about the ID5 ID and detailed integration docs, please visit [our documentation](https://support.id5.io/portal/en/kb/articles/prebid-js-user-id-module). +The ID5 Universal ID is a shared, neutral identifier that publishers and ad tech platforms can use to recognise users even in environments where 3rd party cookies are not available. The ID5 Universal ID is designed to respect users' privacy choices and publishers’ preferences throughout the advertising value chain. For more information about the ID5 Universal ID and detailed integration docs, please visit [our documentation](https://support.id5.io/portal/en/kb/articles/prebid-js-user-id-module). We also recommend that you sign up for our [release notes](https://id5.io/universal-id/release-notes) to stay up-to-date with any changes to the implementation of the ID5 Universal ID in Prebid. -## ID5 ID Registration +## ID5 Universal ID Registration -The ID5 ID is free to use, but requires a simple registration with ID5. Please visit [our website](https://id5.io/solutions/#publishers) to sign up and request your ID5 Partner Number to get started. +The ID5 Universal ID is free to use, but requires a simple registration with ID5. Please visit [id5.io/universal-id](https://id5.io/universal-id) to sign up and request your ID5 Partner Number to get started. -The ID5 privacy policy is at [https://id5.io/platform-privacy-policy](https://id5.io/platform-privacy-policy). +The ID5 privacy policy is at [https://www.id5.io/platform-privacy-policy](https://www.id5.io/platform-privacy-policy). -## ID5 ID Configuration +## ID5 Universal ID Configuration First, make sure to add the ID5 submodule to your Prebid.js package with: @@ -46,7 +46,7 @@ pbjs.setConfig({ | Param under userSync.userIds[] | Scope | Type | Description | Example | | --- | --- | --- | --- | --- | | name | Required | String | The name of this module: `"id5Id"` | `"id5Id"` | -| params | Required | Object | Details for the ID5 ID. | | +| params | Required | Object | Details for the ID5 Universal ID. | | | params.partner | Required | Number | This is the ID5 Partner Number obtained from registering with ID5. | `173` | | params.pd | Optional | String | Partner-supplied data used for linking ID5 IDs across domains. See [our documentation](https://support.id5.io/portal/en/kb/articles/passing-partner-data-to-id5) for details on generating the string. Omit the parameter or leave as an empty string if no data to supply | `"MT1iNTBjY..."` | | params.provider | Optional | String | An identifier provided by ID5 to technology partners who manage Prebid setups on behalf of publishers. Reach out to [ID5](mailto:prebid@id5.io) if you have questions about this parameter | `pubmatic-identity-hub` | diff --git a/modules/idImportLibrary.js b/modules/idImportLibrary.js index e1847edfce4..2a3a86cf270 100644 --- a/modules/idImportLibrary.js +++ b/modules/idImportLibrary.js @@ -1,7 +1,7 @@ -import { logInfo, logError } from '../src/utils.js'; import {getGlobal} from '../src/prebidGlobal.js'; import {ajax} from '../src/ajax.js'; import {config} from '../src/config.js'; +import * as utils from '../src/utils.js'; import MD5 from 'crypto-js/md5.js'; let email; @@ -9,7 +9,6 @@ let conf; const LOG_PRE_FIX = 'ID-Library: '; const CONF_DEFAULT_OBSERVER_DEBOUNCE_MS = 250; const CONF_DEFAULT_FULL_BODY_SCAN = false; -const CONF_DEFAULT_INPUT_SCAN = false; const OBSERVER_CONFIG = { subtree: true, attributes: true, @@ -19,18 +18,18 @@ const OBSERVER_CONFIG = { characterData: true, characterDataOldValue: false }; -const _logInfo = createLogInfo(LOG_PRE_FIX); -const _logError = createLogError(LOG_PRE_FIX); +const logInfo = createLogInfo(LOG_PRE_FIX); +const logError = createLogError(LOG_PRE_FIX); function createLogInfo(prefix) { return function (...strings) { - logInfo(prefix + ' ', ...strings); + utils.logInfo(prefix + ' ', ...strings); } } function createLogError(prefix) { return function (...strings) { - logError(prefix + ' ', ...strings); + utils.logError(prefix + ' ', ...strings); } } @@ -39,39 +38,39 @@ function getEmail(value) { if (!matched) { return null; } - _logInfo('Email found: ' + matched[0]); + logInfo('Email found: ' + matched[0]); return matched[0]; } function bodyAction(mutations, observer) { - _logInfo('BODY observer on debounce called'); + logInfo('BODY observer on debounce called'); // If the email is found in the input element, disconnect the observer if (email) { observer.disconnect(); - _logInfo('Email is found, body observer disconnected'); + logInfo('Email is found, body observer disconnected'); return; } const body = document.body.innerHTML; email = getEmail(body); if (email !== null) { - _logInfo(`Email obtained from the body ${email}`); + logInfo(`Email obtained from the body ${email}`); observer.disconnect(); - _logInfo('Post data on email found in body'); + logInfo('Post data on email found in body'); postData(); } } function targetAction(mutations, observer) { - _logInfo('Target observer called'); + logInfo('Target observer called'); for (const mutation of mutations) { for (const node of mutation.addedNodes) { email = node.textContent; if (email) { - _logInfo('Email obtained from the target ' + email); + logInfo('Email obtained from the target ' + email); observer.disconnect(); - _logInfo('Post data on email found in target'); + logInfo('Post data on email found in target'); postData(); return; } @@ -79,38 +78,19 @@ function targetAction(mutations, observer) { } } -function addInputElementsElementListner() { - if (doesInputElementsHaveEmail()) { - _logInfo('Email found in input elements ' + email); - _logInfo('Post data on email found in target without'); - postData(); - return; - } - _logInfo('Adding input element listeners'); +function addInputElementsElementListner(conf) { + logInfo('Adding input element listeners'); const inputs = document.querySelectorAll('input[type=text], input[type=email]'); for (var i = 0; i < inputs.length; i++) { - _logInfo(`Original Value in Input = ${inputs[i].value}`); + logInfo(`Original Value in Input = ${inputs[i].value}`); inputs[i].addEventListener('change', event => processInputChange(event)); inputs[i].addEventListener('blur', event => processInputChange(event)); } } -function addFormInputElementsElementListner(id) { - _logInfo('Adding input element listeners'); - if (doesFormInputElementsHaveEmail(id)) { - _logInfo('Email found in input elements ' + email); - postData(); - return; - } - _logInfo('Adding input element listeners'); - const input = document.getElementById(id); - input.addEventListener('change', event => processInputChange(event)); - input.addEventListener('blur', event => processInputChange(event)); -} - function removeInputElementsElementListner() { - _logInfo('Removing input element listeners'); + logInfo('Removing input element listeners'); const inputs = document.querySelectorAll('input[type=text], input[type=email]'); for (var i = 0; i < inputs.length; i++) { @@ -121,10 +101,10 @@ function removeInputElementsElementListner() { function processInputChange(event) { const value = event.target.value; - _logInfo(`Modified Value of input ${event.target.value}`); + logInfo(`Modified Value of input ${event.target.value}`); email = getEmail(value); if (email !== null) { - _logInfo('Email found in input ' + email); + logInfo('Email found in input ' + email); postData(); removeInputElementsElementListner(); } @@ -144,7 +124,7 @@ function debounce(func, wait, immediate) { if (callNow) { func.apply(context, args); } else { - _logInfo('Debounce wait time ' + wait); + logInfo('Debounce wait time ' + wait); timeout = setTimeout(later, wait); } }; @@ -158,25 +138,31 @@ function handleTargetElement() { email = targetElement.innerText; if (!email) { - _logInfo('Finding the email with observer'); + logInfo('Finding the email with observer'); targetObserver.observe(targetElement, OBSERVER_CONFIG); } else { - _logInfo('Target found with target ' + email); - _logInfo('Post data on email found in target with target'); + logInfo('Target found with target ' + email); + logInfo('Post data on email found in target with target'); postData(); } } } function handleBodyElements() { + if (doesInputElementsHaveEmail()) { + logInfo('Email found in input elements ' + email); + logInfo('Post data on email found in target without'); + postData(); + return; + } email = getEmail(document.body.innerHTML); if (email !== null) { - _logInfo('Email found in body ' + email); - _logInfo('Post data on email found in the body without observer'); + logInfo('Email found in body ' + email); + logInfo('Post data on email found in the body without observer'); postData(); return; } - + addInputElementsElementListner(); if (conf.fullscan === true) { const bodyObserver = new MutationObserver(debounce(bodyAction, conf.debounce, false)); bodyObserver.observe(document.body, OBSERVER_CONFIG); @@ -196,24 +182,13 @@ function doesInputElementsHaveEmail() { return false; } -function doesFormInputElementsHaveEmail(formElementId) { - const input = document.getElementById(formElementId); - if (input) { - email = getEmail(input.value); - if (email !== null) { - return true; - } - } - return false; -} - function syncCallback() { return { success: function () { - _logInfo('Data synced successfully.'); + logInfo('Data synced successfully.'); }, error: function () { - _logInfo('Data sync failed.'); + logInfo('Data sync failed.'); } } } @@ -222,15 +197,15 @@ function postData() { (getGlobal()).refreshUserIds(); const userIds = (getGlobal()).getUserIds(); if (Object.keys(userIds).length === 0) { - _logInfo('No user ids'); + logInfo('No user ids'); return; } - _logInfo('Users' + userIds); + logInfo('Users' + userIds); const syncPayload = {}; syncPayload.hid = MD5(email).toString(); syncPayload.uids = userIds; const payloadString = JSON.stringify(syncPayload); - _logInfo(payloadString); + logInfo(payloadString); ajax(conf.url, syncCallback(), payloadString, {method: 'POST', withCredentials: true}); } @@ -238,10 +213,6 @@ function associateIds() { if (window.MutationObserver || window.WebKitMutationObserver) { if (conf.target) { handleTargetElement(); - } else if (conf.formElementId) { - addFormInputElementsElementListner(conf.formElementId); - } else if (conf.inputscan) { - addInputElementsElementListner(); } else { handleBodyElements(); } @@ -250,28 +221,20 @@ function associateIds() { export function setConfig(config) { if (!config) { - _logError('Required confirguration not provided'); + logError('Required confirguration not provided'); return; } if (!config.url) { - _logError('The required url is not configured'); + logError('The required url is not configured'); return; } if (typeof config.debounce !== 'number') { config.debounce = CONF_DEFAULT_OBSERVER_DEBOUNCE_MS; - _logInfo('Set default observer debounce to ' + CONF_DEFAULT_OBSERVER_DEBOUNCE_MS); + logInfo('Set default observer debounce to ' + CONF_DEFAULT_OBSERVER_DEBOUNCE_MS); } if (typeof config.fullscan !== 'boolean') { config.fullscan = CONF_DEFAULT_FULL_BODY_SCAN; - _logInfo('Set default fullscan ' + CONF_DEFAULT_FULL_BODY_SCAN); - } - if (typeof config.inputscan !== 'boolean') { - config.inputscan = CONF_DEFAULT_INPUT_SCAN; - _logInfo('Set default input scan ' + CONF_DEFAULT_INPUT_SCAN); - } - - if (typeof config.formElementId == 'string') { - _logInfo('Looking for formElementId ' + config.formElementId); + logInfo('Set default fullscan ' + CONF_DEFAULT_FULL_BODY_SCAN); } conf = config; associateIds(); diff --git a/modules/idImportLibrary.md b/modules/idImportLibrary.md index f91ca984bb3..3dd78ee25d8 100644 --- a/modules/idImportLibrary.md +++ b/modules/idImportLibrary.md @@ -8,8 +8,6 @@ | `url` | Yes | String | N/A | URL endpoint used to post the hashed email and user IDs. | | `debounce` | No | Number | 250 | Time in milliseconds before the email and IDs are fetched. | | `fullscan` | No | Boolean | false | Enable/disable a full page body scan to get email. | -| `formElementId` | No | String | N/A | ID attribute of the input (type=text/email) from which the email can be read. | -| `inputscan` | No | Boolean | N/A | Enable/disable a input element (type=text/email) scan to get email. | ## Example @@ -20,7 +18,5 @@ pbjs.setConfig({ url: 'https://example.com', debounce: 250, fullscan: false, - inputscan: false, - formElementId: "userid" }, }); diff --git a/modules/idxIdSystem.js b/modules/idxIdSystem.js index 908edad4c04..00e8a8bc5e5 100644 --- a/modules/idxIdSystem.js +++ b/modules/idxIdSystem.js @@ -4,7 +4,7 @@ * @module modules/idxIdSystem * @requires module:modules/userId */ -import { isStr, isPlainObject, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -34,7 +34,7 @@ export const idxIdSubmodule = { * @return { Object | string | undefined } */ decode(value) { - const idxVal = value ? isStr(value) ? value : isPlainObject(value) ? value.id : undefined : undefined; + const idxVal = value ? utils.isStr(value) ? value : utils.isPlainObject(value) ? value.id : undefined : undefined; return idxVal ? { 'idx': idxVal } : undefined; @@ -52,7 +52,7 @@ export const idxIdSubmodule = { const idxObj = JSON.parse(idxString); return idxObj && idxObj.idx ? { id: idxObj.idx } : undefined; } catch (error) { - logError(error); + utils.logError(error); } } return undefined; diff --git a/modules/imRtdProvider.js b/modules/imRtdProvider.js deleted file mode 100644 index 7ab19c0e2d6..00000000000 --- a/modules/imRtdProvider.js +++ /dev/null @@ -1,228 +0,0 @@ -/** - * The {@link module:modules/realTimeData} module is required - * The module will fetch real-time data from Intimate Merger - * @module modules/imRtdProvider - * @requires module:modules/realTimeData - */ -import {ajax} from '../src/ajax.js'; -import {config} from '../src/config.js'; -import {getGlobal} from '../src/prebidGlobal.js' -import {getStorageManager} from '../src/storageManager.js'; -import { - deepSetValue, - deepAccess, - timestamp, - mergeDeep, - logError, - logInfo, - isFn -} from '../src/utils.js' -import {submodule} from '../src/hook.js'; - -export const imUidLocalName = '__im_uid'; -export const imVidCookieName = '_im_vid'; -export const imRtdLocalName = '__im_sids'; -export const storage = getStorageManager(); -const submoduleName = 'im'; -const segmentsMaxAge = 3600000; // 1 hour (30 * 60 * 1000) -const uidMaxAge = 1800000; // 30 minites (30 * 60 * 1000) -const vidMaxAge = 97200000000; // 37 months ((365 * 3 + 30) * 24 * 60 * 60 * 1000) - -function setImDataInCookie(value) { - storage.setCookie( - imVidCookieName, - value, - new Date(timestamp() + vidMaxAge).toUTCString(), - 'none' - ); -} - -/** -* @param {string} bidderName -*/ -export function getBidderFunction(bidderName) { - const biddersFunction = { - ix: function (bid, data) { - if (data.im_segments && data.im_segments.length) { - config.setConfig({ - ix: {firstPartyData: {im_segments: data.im_segments}}, - }); - } - return bid - }, - pubmatic: function (bid, data) { - if (data.im_segments && data.im_segments.length) { - const dctr = deepAccess(bid, 'params.dctr'); - deepSetValue( - bid, - 'params.dctr', - `${dctr ? dctr + '|' : ''}im_segments=${data.im_segments.join(',')}` - ); - } - return bid - } - } - return biddersFunction[bidderName] || null; -} - -export function getCustomBidderFunction(config, bidder) { - const overwriteFn = deepAccess(config, `params.overwrites.${bidder}`) - - if (overwriteFn && isFn(overwriteFn)) { - return overwriteFn - } else { - return null - } -} - -/** - * Add real-time data. - * @param {Object} bidConfig - * @param {Object} moduleConfig - * @param {Object} data - */ -export function setRealTimeData(bidConfig, moduleConfig, data) { - const adUnits = bidConfig.adUnits || getGlobal().adUnits; - const utils = {deepSetValue, deepAccess, logInfo, logError, mergeDeep}; - - if (data.im_segments) { - const ortb2 = config.getConfig('ortb2') || {}; - deepSetValue(ortb2, 'user.ext.data.im_segments', data.im_segments); - config.setConfig({ortb2: ortb2}); - - if (moduleConfig.params.setGptKeyValues || !moduleConfig.params.hasOwnProperty('setGptKeyValues')) { - window.googletag = window.googletag || {cmd: []}; - window.googletag.cmd = window.googletag.cmd || []; - window.googletag.cmd.push(() => { - window.googletag.pubads().setTargeting('im_segments', data.im_segments); - }); - } - } - - adUnits.forEach(adUnit => { - adUnit.bids.forEach(bid => { - const bidderFunction = getBidderFunction(bid.bidder); - const overwriteFunction = getCustomBidderFunction(moduleConfig, bid.bidder); - if (overwriteFunction) { - overwriteFunction(bid, data, utils, config); - } else if (bidderFunction) { - bidderFunction(bid, data); - } - }) - }); -} - -/** - * Real-time data retrieval from Intimate Merger - * @param {Object} reqBidsConfigObj - * @param {function} onDone - * @param {Object} moduleConfig - */ -export function getRealTimeData(reqBidsConfigObj, onDone, moduleConfig) { - const cid = deepAccess(moduleConfig, 'params.cid'); - if (!cid) { - logError('imRtdProvider requires a valid cid to be defined'); - onDone(); - return; - } - const sids = storage.getDataFromLocalStorage(imRtdLocalName); - const parsedSids = sids ? sids.split(',') : []; - const mt = storage.getDataFromLocalStorage(`${imRtdLocalName}_mt`); - const localVid = storage.getCookie(imVidCookieName); - let apiUrl = `https://sync6.im-apps.net/${cid}/rtd`; - let expired = true; - let alreadyDone = false; - - if (localVid) { - apiUrl += `?vid=${localVid}`; - setImDataInCookie(localVid); - } - - if (Date.parse(mt) && Date.now() - (new Date(mt)).getTime() < segmentsMaxAge) { - expired = false; - } - - if (sids !== null) { - setRealTimeData(reqBidsConfigObj, moduleConfig, {im_segments: parsedSids}); - onDone(); - alreadyDone = true; - } - - if (expired) { - ajax( - apiUrl, - getApiCallback(reqBidsConfigObj, alreadyDone ? undefined : onDone, moduleConfig), - undefined, - {method: 'GET', withCredentials: true} - ); - } -} - -/** - * Api callback from Intimate Merger - * @param {Object} reqBidsConfigObj - * @param {function} onDone - * @param {Object} moduleConfig - */ -export function getApiCallback(reqBidsConfigObj, onDone, moduleConfig) { - return { - success: function (response, req) { - let parsedResponse = {}; - if (req.status === 200) { - try { - parsedResponse = JSON.parse(response); - } catch (e) { - logError('unable to get Intimate Merger segment data'); - } - - if (parsedResponse.uid) { - const imuid = storage.getDataFromLocalStorage(imUidLocalName); - const imuidMt = storage.getDataFromLocalStorage(`${imUidLocalName}_mt`); - const imuidExpired = Date.parse(imuidMt) && Date.now() - (new Date(imuidMt)).getTime() < uidMaxAge; - if (!imuid || imuidExpired) { - storage.setDataInLocalStorage(imUidLocalName, parsedResponse.uid); - storage.setDataInLocalStorage(`${imUidLocalName}_mt`, new Date(timestamp()).toUTCString()); - } - } - - if (parsedResponse.vid) { - setImDataInCookie(parsedResponse.vid); - } - - if (parsedResponse.segments) { - setRealTimeData(reqBidsConfigObj, moduleConfig, {im_segments: parsedResponse.segments}); - storage.setDataInLocalStorage(imRtdLocalName, parsedResponse.segments); - storage.setDataInLocalStorage(`${imRtdLocalName}_mt`, new Date(timestamp()).toUTCString()); - } - } - if (onDone) { - onDone(); - } - }, - error: function () { - if (onDone) { - onDone(); - } - logError('unable to get Intimate Merger segment data'); - } - } -} - -/** - * Module init - * @param {Object} provider - * @param {Object} userConsent - * @return {boolean} - */ -function init(provider, userConsent) { - return true; -} - -/** @type {RtdSubmodule} */ -export const imRtdSubmodule = { - name: submoduleName, - getBidRequestData: getRealTimeData, - init: init -}; - -submodule('realTimeData', imRtdSubmodule); diff --git a/modules/imRtdProvider.md b/modules/imRtdProvider.md deleted file mode 100644 index 7ece2b996b4..00000000000 --- a/modules/imRtdProvider.md +++ /dev/null @@ -1,41 +0,0 @@ -## Intimate Merger Real-time Data Submodule - -provided by Intimate Merger. - -## Building Prebid with Real-time Data Support - -First, make sure to add the Intimate Merger submodule to your Prebid.js package with: - -`gulp build --modules=rtdModule,imRtdProvider` - -The following configuration parameters are available: - -``` -pbjs.setConfig( - ... - realTimeData: { - auctionDelay: 5000, - dataProviders: [ - { - name: "im", - waitForIt: true, - params: { - cid: 5126, // Set your Intimate Merger Customer ID here for production - setGptKeyValues: true - } - } - ] - } - ... -} -``` - -### Parameter Descriptions for the im Configuration Section - -| Param under dataProviders | Scope | Type | Description | Example | -| --- | --- | --- | --- | --- | -| name | Required | String | The name of this module. | `"im"` | -| waitForIt | Optional | Boolean | Required to ensure that the auction is delayed until prefetch is complete. Defaults to false but recommended to true | `true` | -| params | Required | Object | Details of module params. | | -| params.cid | Required | Number | This is the Customer ID value obtained via Intimate Merger. | `5126` | -| params.setGptKeyValues | Optional | Boolean | This is set targeting for GPT/GAM. Default setting is true. | `true` | diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index b204e81f22c..7e52669d33e 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -1,14 +1,13 @@ -import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import {ajax} from '../src/ajax.js'; -import { createEidsArray } from './userId/eids.js'; const BIDDER_CODE = 'impactify'; const BIDDER_ALIAS = ['imp']; const DEFAULT_CURRENCY = 'USD'; const DEFAULT_VIDEO_WIDTH = 640; -const DEFAULT_VIDEO_HEIGHT = 360; +const DEFAULT_VIDEO_HEIGHT = 480; const ORIGIN = 'https://sonic.impactify.media'; const LOGGER_URI = 'https://logger.impactify.media'; const AUCTIONURI = '/bidder'; @@ -33,24 +32,12 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { id: bidderRequest.auctionId, validBidRequests, cur: [DEFAULT_CURRENCY], - imp: [], - source: {tid: bidderRequest.auctionId} + imp: [] }; // Force impactify debugging parameter - if (window.localStorage.getItem('_im_db_bidder') != null) { - request.test = Number(window.localStorage.getItem('_im_db_bidder')); - } - - // Set Schain in request - let schain = deepAccess(validBidRequests, '0.schain'); - if (schain) request.source.ext = { schain: schain }; - - // Set eids - let bidUserId = deepAccess(validBidRequests, '0.userId'); - let eids = createEidsArray(bidUserId); - if (eids.length) { - deepSetValue(request, 'user.ext.eids', eids); + if (window.localStorage.getItem('_im_db_bidder') == 3) { + request.test = 3; } // Set device/user/site @@ -71,23 +58,23 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { let gdprApplies = 0; if (bidderRequest.gdprConsent) { if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') gdprApplies = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } - deepSetValue(request, 'regs.ext.gdpr', gdprApplies); + utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies); if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); this.syncStore.uspConsent = bidderRequest.uspConsent; } - if (GETCONFIG('coppa') == true) deepSetValue(request, 'regs.coppa', 1); + if (GETCONFIG('coppa') == true) utils.deepSetValue(request, 'regs.coppa', 1); if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // Set buyer uid - deepSetValue(request, 'user.buyeruid', generateUUID()); + utils.deepSetValue(request, 'user.buyeruid', utils.generateUUID()); // Create imps with bids validBidRequests.forEach((bid) => { @@ -119,7 +106,7 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { export const spec = { code: BIDDER_CODE, gvlid: GVLID, - supportedMediaTypes: ['video', 'banner'], + supportedMediaTypes: ['video'], aliases: BIDDER_ALIAS, /** diff --git a/modules/improvedigitalBidAdapter.js b/modules/improvedigitalBidAdapter.js index 1a523c0294f..e73df68b625 100644 --- a/modules/improvedigitalBidAdapter.js +++ b/modules/improvedigitalBidAdapter.js @@ -1,4 +1,4 @@ -import { deepSetValue, logError, _each, getBidRequest, isNumber, isArray, deepAccess, isFn, isPlainObject, logWarn, getBidIdParameter, getUniqueIdentifierStr, isEmpty, isInteger, isStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; @@ -11,7 +11,7 @@ const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js const VIDEO_TARGETING = ['skip', 'skipmin', 'skipafter']; export const spec = { - version: '7.6.0', + version: '7.4.0', code: BIDDER_CODE, gvlid: 253, aliases: ['id'], @@ -45,24 +45,8 @@ export const spec = { libVersion: this.version }; - const gdprConsent = deepAccess(bidderRequest, 'gdprConsent') - if (gdprConsent) { - // GDPR Consent String - if (gdprConsent.consentString) { - requestParameters.gdpr = gdprConsent.consentString; - } - - // Additional Consent String - const additionalConsent = deepAccess(gdprConsent, 'addtlConsent'); - if (additionalConsent && additionalConsent.indexOf('~') !== -1) { - // Google Ad Tech Provider IDs - const atpIds = additionalConsent.substring(additionalConsent.indexOf('~') + 1); - deepSetValue( - requestParameters, - 'user.ext.consented_providers_settings.consented_providers', - atpIds.split('.').map(id => parseInt(id, 10)) - ); - } + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) { + requestParameters.gdpr = bidderRequest.gdprConsent.consentString; } if (bidderRequest && bidderRequest.uspConsent) { @@ -73,28 +57,12 @@ export const spec = { requestParameters.referrer = bidderRequest.refererInfo.referer; } - // Adding first party data - const site = config.getConfig('ortb2.site'); - if (site) { - const pageCategory = site.pagecat || site.cat; - if (pageCategory && isArray(pageCategory)) { - requestParameters.pagecat = pageCategory.filter((category) => { - return category && isStr(category) - }); - } - const genre = deepAccess(site, 'content.genre'); - if (genre && isStr(genre)) { - requestParameters.genre = genre; - } - } - // End of adding first party data - requestParameters.schain = bidRequests[0].schain; if (bidRequests[0].userId) { const eids = createEidsArray(bidRequests[0].userId); if (eids.length) { - deepSetValue(requestParameters, 'user.ext.eids', eids); + utils.deepSetValue(requestParameters, 'user.ext.eids', eids); } } @@ -104,7 +72,7 @@ export const spec = { ); if (requestObj.errors && requestObj.errors.length > 0) { - logError('ID WARNING 0x01'); + utils.logError('ID WARNING 0x01'); } requestObj.requests.forEach(request => request.bidderRequest = bidderRequest); return requestObj.requests; @@ -118,13 +86,13 @@ export const spec = { */ interpretResponse: function (serverResponse, {bidderRequest}) { const bids = []; - _each(serverResponse.body.bid, function (bidObject) { + utils._each(serverResponse.body.bid, function (bidObject) { if (!bidObject.price || bidObject.price === null || bidObject.hasOwnProperty('errorCode') || (!bidObject.adm && !bidObject.native)) { return; } - const bidRequest = getBidRequest(bidObject.id, [bidderRequest]); + const bidRequest = utils.getBidRequest(bidObject.id, [bidderRequest]); const bid = {}; if (bidObject.native) { @@ -164,7 +132,7 @@ export const spec = { // Deal ID. Composite ads can have multiple line items and the ID of the first // dealID line item will be used. - if (isNumber(bidObject.lid) && bidObject.buying_type && bidObject.buying_type !== 'rtb') { + if (utils.isNumber(bidObject.lid) && bidObject.buying_type && bidObject.buying_type !== 'rtb') { bid.dealId = bidObject.lid; } else if (Array.isArray(bidObject.lid) && Array.isArray(bidObject.buying_type) && @@ -213,7 +181,7 @@ export const spec = { const syncs = []; serverResponses.forEach(response => { response.body.bid.forEach(bidObject => { - if (isArray(bidObject.sync)) { + if (utils.isArray(bidObject.sync)) { bidObject.sync.forEach(syncElement => { if (syncs.indexOf(syncElement) === -1) { syncs.push(syncElement); @@ -229,15 +197,15 @@ export const spec = { }; function isInstreamVideo(bid) { - const mediaTypes = Object.keys(deepAccess(bid, 'mediaTypes', {})); - const videoMediaType = deepAccess(bid, 'mediaTypes.video'); - const context = deepAccess(bid, 'mediaTypes.video.context'); + const mediaTypes = Object.keys(utils.deepAccess(bid, 'mediaTypes', {})); + const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); return bid.mediaType === 'video' || (mediaTypes.length === 1 && videoMediaType && context !== 'outstream'); } function isOutstreamVideo(bid) { - const videoMediaType = deepAccess(bid, 'mediaTypes.video'); - const context = deepAccess(bid, 'mediaTypes.video.context'); + const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); return videoMediaType && context === 'outstream'; } @@ -257,7 +225,7 @@ function getVideoTargetingParams(bid) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return null; } const floor = bid.getFloor({ @@ -265,7 +233,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; @@ -291,31 +259,31 @@ function createRenderer(bidRequest) { id: bidRequest.adUnitCode, url: RENDERER_URL, loaded: false, - config: deepAccess(bidRequest, 'renderer.options'), + config: utils.deepAccess(bidRequest, 'renderer.options'), adUnitCode: bidRequest.adUnitCode }); try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; } function getNormalizedBidRequest(bid) { - let adUnitId = getBidIdParameter('adUnitCode', bid) || null; - let placementId = getBidIdParameter('placementId', bid.params) || null; + let adUnitId = utils.getBidIdParameter('adUnitCode', bid) || null; + let placementId = utils.getBidIdParameter('placementId', bid.params) || null; let publisherId = null; let placementKey = null; if (placementId === null) { - publisherId = getBidIdParameter('publisherId', bid.params) || null; - placementKey = getBidIdParameter('placementKey', bid.params) || null; + publisherId = utils.getBidIdParameter('publisherId', bid.params) || null; + placementKey = utils.getBidIdParameter('placementKey', bid.params) || null; } - const keyValues = getBidIdParameter('keyValues', bid.params) || null; - const singleSizeFilter = getBidIdParameter('size', bid.params) || null; - const bidId = getBidIdParameter('bidId', bid); - const transactionId = getBidIdParameter('transactionId', bid); + const keyValues = utils.getBidIdParameter('keyValues', bid.params) || null; + const singleSizeFilter = utils.getBidIdParameter('size', bid.params) || null; + const bidId = utils.getBidIdParameter('bidId', bid); + const transactionId = utils.getBidIdParameter('transactionId', bid); const currency = config.getConfig('currency.adServerCurrency'); let normalizedBidRequest = {}; @@ -364,8 +332,8 @@ function getNormalizedBidRequest(bid) { let bidFloor = getBidFloor(bid); let bidFloorCur = null; if (!bidFloor) { - bidFloor = getBidIdParameter('bidFloor', bid.params); - bidFloorCur = getBidIdParameter('bidFloorCur', bid.params); + bidFloor = utils.getBidIdParameter('bidFloor', bid.params); + bidFloorCur = utils.getBidIdParameter('bidFloorCur', bid.params); } if (bidFloor) { normalizedBidRequest.bidFloor = bidFloor; @@ -376,7 +344,7 @@ function getNormalizedBidRequest(bid) { function getNormalizedNativeAd(rawNative) { const native = {}; - if (!rawNative || !isArray(rawNative.assets)) { + if (!rawNative || !utils.isArray(rawNative.assets)) { return null; } // Assets @@ -507,7 +475,7 @@ export function ImproveDigitalAdServerJSClient(endPoint) { let impressionObjects = []; let impressionObject; - if (isArray(requestObject)) { + if (utils.isArray(requestObject)) { for (let counter = 0; counter < requestObject.length; counter++) { impressionObject = this.createImpressionObject(requestObject[counter]); impressionObjects.push(impressionObject); @@ -608,7 +576,7 @@ export function ImproveDigitalAdServerJSClient(endPoint) { if (requestParameters.requestId) { impressionBidRequestObject.id = requestParameters.requestId; } else { - impressionBidRequestObject.id = getUniqueIdentifierStr(); + impressionBidRequestObject.id = utils.getUniqueIdentifierStr(); } if (requestParameters.domain) { impressionBidRequestObject.domain = requestParameters.domain; @@ -637,12 +605,6 @@ export function ImproveDigitalAdServerJSClient(endPoint) { if (requestParameters.schain) { impressionBidRequestObject.schain = requestParameters.schain; } - if (requestParameters.pagecat) { - impressionBidRequestObject.pagecat = requestParameters.pagecat; - } - if (requestParameters.genre) { - impressionBidRequestObject.genre = requestParameters.genre; - } if (requestParameters.user) { impressionBidRequestObject.user = requestParameters.user; } @@ -663,7 +625,7 @@ export function ImproveDigitalAdServerJSClient(endPoint) { if (placementObject.id) { impressionObject.id = placementObject.id; } else { - impressionObject.id = getUniqueIdentifierStr(); + impressionObject.id = utils.getUniqueIdentifierStr(); } if (placementObject.adTypes) { impressionObject.ad_types = placementObject.adTypes; @@ -692,18 +654,18 @@ export function ImproveDigitalAdServerJSClient(endPoint) { if (placementObject.transactionId) { impressionObject.tid = placementObject.transactionId; } - if (!isEmpty(placementObject.video)) { + if (!utils.isEmpty(placementObject.video)) { const video = Object.assign({}, placementObject.video); // skip must be 0 or 1 if (video.skip !== 1) { delete video.skipmin; delete video.skipafter; if (video.skip !== 0) { - logWarn(`video.skip: invalid value '${video.skip}'. Expected 0 or 1`); + utils.logWarn(`video.skip: invalid value '${video.skip}'. Expected 0 or 1`); delete video.skip; } } - if (!isEmpty(video)) { + if (!utils.isEmpty(video)) { impressionObject.video = video; } } @@ -725,11 +687,11 @@ export function ImproveDigitalAdServerJSClient(endPoint) { // Set of desired creative sizes // Input Format: array of pairs, i.e. [[300, 250], [250, 250]] - if (placementObject.format && isArray(placementObject.format)) { + if (placementObject.format && utils.isArray(placementObject.format)) { const format = placementObject.format .filter(sizePair => sizePair.length === 2 && - isInteger(sizePair[0]) && - isInteger(sizePair[1]) && + utils.isInteger(sizePair[0]) && + utils.isInteger(sizePair[1]) && sizePair[0] >= 0 && sizePair[1] >= 0) .map(sizePair => { diff --git a/modules/imuIdSystem.js b/modules/imuIdSystem.js index 72e81d243a3..da03c63fc8a 100644 --- a/modules/imuIdSystem.js +++ b/modules/imuIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { timestamp, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js' import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -20,7 +20,7 @@ const cookiesMaxAge = 97200000000; // 37 months ((365 * 3 + 30) * 24 * 60 * 60 * export function setImDataInLocalStorage(value) { storage.setDataInLocalStorage(storageKey, value); - storage.setDataInLocalStorage(`${storageKey}_mt`, new Date(timestamp()).toUTCString()); + storage.setDataInLocalStorage(`${storageKey}_mt`, new Date(utils.timestamp()).toUTCString()); } export function removeImDataFromLocalStorage() { @@ -32,7 +32,7 @@ function setImDataInCookie(value) { storage.setCookie( cookieKey, value, - new Date(timestamp() + cookiesMaxAge).toUTCString(), + new Date(utils.timestamp() + cookiesMaxAge).toUTCString(), 'none' ); } @@ -73,7 +73,7 @@ export function getApiCallback(callback) { responseObj = JSON.parse(response); apiSuccessProcess(responseObj); } catch (error) { - logError('User ID - imuid submodule: ' + error); + utils.logError('User ID - imuid submodule: ' + error); } } if (callback && responseObj.uid) { @@ -81,7 +81,7 @@ export function getApiCallback(callback) { } }, error: error => { - logError('User ID - imuid submodule was unable to get data from api: ' + error); + utils.logError('User ID - imuid submodule was unable to get data from api: ' + error); if (callback) { callback(); } @@ -128,7 +128,7 @@ export const imuIdSubmodule = { getId(config) { const configParams = (config && config.params) || {}; if (!configParams || typeof configParams.cid !== 'number') { - logError('User ID - imuid submodule requires a valid cid to be defined'); + utils.logError('User ID - imuid submodule requires a valid cid to be defined'); return undefined; } let apiUrl = getApiUrl(configParams.cid, configParams.url); diff --git a/modules/inmarBidAdapter.js b/modules/inmarBidAdapter.js index 0e056551b35..e1edd935587 100755 --- a/modules/inmarBidAdapter.js +++ b/modules/inmarBidAdapter.js @@ -1,4 +1,4 @@ -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -83,7 +83,7 @@ export const spec = { bidResponses.push(bidResponse); } } catch (error) { - logError('Error while parsing inmar response', error); + utils.logError('Error while parsing inmar response', error); } return bidResponses; }, diff --git a/modules/innityBidAdapter.js b/modules/innityBidAdapter.js index 0a2f701ef64..ab7ee07db4a 100644 --- a/modules/innityBidAdapter.js +++ b/modules/innityBidAdapter.js @@ -1,4 +1,4 @@ -import { parseSizesInput, timestamp } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'innity'; @@ -11,13 +11,13 @@ export const spec = { }, buildRequests: function(validBidRequests, bidderRequest) { return validBidRequests.map(bidRequest => { - let parseSized = parseSizesInput(bidRequest.sizes); + let parseSized = utils.parseSizesInput(bidRequest.sizes); let arrSize = parseSized[0].split('x'); return { method: 'GET', url: ENDPOINT, data: { - cb: timestamp(), + cb: utils.timestamp(), ver: 2, hb: 1, output: 'js', diff --git a/modules/inskinBidAdapter.js b/modules/inskinBidAdapter.js index 781bca90660..5173f1dca63 100644 --- a/modules/inskinBidAdapter.js +++ b/modules/inskinBidAdapter.js @@ -1,4 +1,4 @@ -import { createTrackPixelHtml } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'inskin'; @@ -55,22 +55,6 @@ export const spec = { parallel: true }, validBidRequests[0].params); - if (validBidRequests[0].schain) { - data.rtb = { - schain: validBidRequests[0].schain - }; - } else if (data.publisherId) { - data.rtb = { - schain: { - ext: { - sid: String(data.publisherId) - } - } - }; - } - - delete data.publisherId; - data.keywords = data.keywords || []; const restrictions = []; @@ -293,7 +277,7 @@ function getSize(sizes) { } function retrieveAd(bidId, decision) { - return "`; - break; - } - }); - } - - if (nativeAdm.privacy) { - native.privacyLink = nativeAdm.privacy; - } - - return native; -} - export const spec = { code: BIDDER_CODE, @@ -589,7 +221,7 @@ export const spec = { supportedMediaTypes: SUPPORTED_MEDIA_TYPES, isBidRequestValid: function(bid) { - return !!(bid && !isEmpty(bid)); + return !!(bid && !utils.isEmpty(bid)); }, buildRequests: function(validBidRequests, bidderRequest) { @@ -597,11 +229,11 @@ export const spec = { // Pass the auctionId as ortb2 id // See https://github.com/prebid/Prebid.js/issues/6563 - deepSetValue(payload, 'id', bidderRequest.auctionId); - deepSetValue(payload, 'source.tid', bidderRequest.auctionId); + utils.deepSetValue(payload, 'id', bidderRequest.auctionId); + utils.deepSetValue(payload, 'source.tid', bidderRequest.auctionId); validBidRequests.forEach(validBid => { - let bid = deepClone(validBid); + let bid = utils.deepClone(validBid); // No additional params atm. const imp = createImp(bid); @@ -610,37 +242,37 @@ export const spec = { }); if (validBidRequests[0].schain) { - deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa') === true) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } - if (deepAccess(validBidRequests[0], 'userId')) { - deepSetValue(payload, 'user.ext.eids', createEidsArray(validBidRequests[0].userId)); + if (utils.deepAccess(validBidRequests[0], 'userId')) { + utils.deepSetValue(payload, 'user.ext.eids', createEidsArray(validBidRequests[0].userId)); } // Assign payload.site from refererinfo if (bidderRequest.refererInfo) { if (bidderRequest.refererInfo.reachedTop) { const sitePage = bidderRequest.refererInfo.referer; - deepSetValue(payload, 'site.page', sitePage); - deepSetValue(payload, 'site.domain', parseUrl(sitePage, { + utils.deepSetValue(payload, 'site.page', sitePage); + utils.deepSetValue(payload, 'site.domain', utils.parseUrl(sitePage, { noDecodeWholeURL: true }).hostname); if (canAccessTopWindow()) { - deepSetValue(payload, 'site.ref', getWindowTop().document.referrer); + utils.deepSetValue(payload, 'site.ref', utils.getWindowTop().document.referrer); } } } @@ -648,15 +280,15 @@ export const spec = { // Handle First Party Data (need publisher fpd setup) const fpd = config.getConfig('ortb2') || {}; if (fpd.site) { - mergeDeep(payload, { site: fpd.site }); + utils.mergeDeep(payload, { site: fpd.site }); } if (fpd.user) { - mergeDeep(payload, { user: fpd.user }); + utils.mergeDeep(payload, { user: fpd.user }); } // Here we can handle device.geo prop - const deviceGeo = deepAccess(fpd, 'device.geo'); + const deviceGeo = utils.deepAccess(fpd, 'device.geo'); if (deviceGeo) { - mergeDeep(payload.device, { geo: deviceGeo }); + utils.mergeDeep(payload.device, { geo: deviceGeo }); } const request = { @@ -675,19 +307,19 @@ export const spec = { const bidResponses = []; try { - if (serverResponse.body && serverResponse.body.seatbid && isArray(serverResponse.body.seatbid)) { + if (serverResponse.body && serverResponse.body.seatbid && utils.isArray(serverResponse.body.seatbid)) { const currency = serverResponse.body.cur || DEFAULT_CURRENCY; const referrer = bidRequest.site && bidRequest.site.ref ? bidRequest.site.ref : ''; serverResponse.body.seatbid.forEach(bidderSeat => { - if (!isArray(bidderSeat.bid) || !bidderSeat.bid.length) { + if (!utils.isArray(bidderSeat.bid) || !bidderSeat.bid.length) { return; } bidderSeat.bid.forEach(bid => { let mediaType; // Actually only BANNER is supported, but other types will be added soon. - switch (deepAccess(bid, 'ext.prebid.type')) { + switch (utils.deepAccess(bid, 'ext.prebid.type')) { case 'V': mediaType = VIDEO; break; @@ -700,8 +332,8 @@ export const spec = { const meta = { advertiserDomains: (Array.isArray(bid.adomain) && bid.adomain.length) ? bid.adomain : [], - advertiserName: deepAccess(bid, 'ext.advertiser_name', null), - agencyName: deepAccess(bid, 'ext.agency_name', null), + advertiserName: utils.deepAccess(bid, 'ext.advertiser_name', null), + agencyName: utils.deepAccess(bid, 'ext.agency_name', null), primaryCatId: getPrimaryCatFromResponse(bid.cat), mediaType } @@ -720,38 +352,15 @@ export const spec = { ad: bid.adm, mediaType, burl: bid.burl, - meta: cleanObj(meta) + meta: utils.cleanObj(meta) }; - if (mediaType === NATIVE) { - const native = nativeBidResponseHandler(bid); - if (native) { - newBid.native = native; - } - } - - if (mediaType === VIDEO) { - // Note: - // Mediakeys bid adapter expects a publisher has set his own video player - // in the `mediaTypes.video` configuration object. - - // Mediakeys bidder does not provide inline XML in the bid response - // newBid.vastXml = bid.ext.vast_url; - - // For instream video, disable server cache as vast is generated per bid request - newBid.videoCacheKey = 'no_cache'; - - // The vast URL is server independently and must be fetched before video rendering in the renderer - // appending '&no_cache' is safe and fast as the vast url always have parameters - newBid.vastUrl = bid.ext.vast_url + '&no_cache'; - } - bidResponses.push(newBid); }); }); } } catch (e) { - logError(BIDDER_CODE, e); + utils.logError(BIDDER_CODE, e); } return bidResponses; @@ -764,7 +373,7 @@ export const spec = { const url = bid.burl.replace(/\$\{AUCTION_PRICE\}/, bid.cpm); - triggerPixel(url); + utils.triggerPixel(url); } } diff --git a/modules/mediakeysBidAdapter.md b/modules/mediakeysBidAdapter.md index ec313c2fe3a..75e69659c8a 100644 --- a/modules/mediakeysBidAdapter.md +++ b/modules/mediakeysBidAdapter.md @@ -29,111 +29,3 @@ var adUnits = [ }] }, ``` - -## Native only Ad Unit - -The Mediakeys adapter accepts two optional params for native requests. Please see the [OpenRTB Native Ads Specification](https://www.iab.com/wp-content/uploads/2018/03/OpenRTB-Native-Ads-Specification-Final-1.2.pdf) for valid values. - -``` -var adUnits = [ -{ - code: 'test', - mediaTypes: { - native: { - type: 'image', - } - }, - bids: [{ - bidder: 'mediakeys', - params: { - native: { - context: 1, // ORTB Native Context Type IDs. Default `1`. - plcmttype: 1, // ORTB Native Placement Type IDs. Default `1`. - } - } - }] -}, -``` - -## Video only Ad Unit - -The Mediakeys adapter accepts any valid openRTB 2.5 video property. Properties can be defined at the adUnit `mediaTypes.video` or `bid[].params` level. - -### Outstream context - -``` -var adUnits = [ -{ - code: 'test', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [300, 250], - // additional OpenRTB video params - // placement: 2, - // api: [1], - // … - } - }, - renderer: { - url: 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js', - render: function (bid) { - var bidReqConfig = pbjs.adUnits.find(bidReq => bidReq.bidId === bid.impid); - - if (bidReqConfig && bidReqConfig.mediaTypes && bidReqConfig.mediaTypes.video && bidReqConfig.mediaTypes.video.context === 'outstream') { - var adResponse = fetch(bid.vastUrl).then(resp => resp.text()).then(text => ({ - ad: { - video: { - content: text, - player_width: bid.width || bidReqConfig.mediaTypes.video.playerSize[0], - player_height: bid.height || bidReqConfig.mediaTypes.video.playerSize[1], - } - } - })) - - adResponse.then((ad) => { - bid.renderer.push(() => { - ANOutstreamVideo.renderAd({ - targetId: bid.adUnitCode, - adResponse: ad - }); - }); - }) - } - } - }, - bids: [{ - bidder: 'mediakeys', - params: { - video: { - // additional OpenRTB video params. Will be merged with params defined at mediaTypes level - } - } - }] -}, -``` - -### Instream context - -``` -var adUnits = [ -{ - code: 'test', - mediaTypes: { - video: { - context: 'instream', - playerSize: [300, 250], - // additional OpenRTB video params - // placement: 2, - // api: [1], - // … - } - }, - bids: [{ - bidder: 'mediakeys', - params: { - // additional OpenRTB video params. Will be merged with params defined at mediaTypes level - } - }] -}, -``` diff --git a/modules/medianetAnalyticsAdapter.js b/modules/medianetAnalyticsAdapter.js index e281dde8ad0..cb65a6afc54 100644 --- a/modules/medianetAnalyticsAdapter.js +++ b/modules/medianetAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { triggerPixel, deepAccess, getWindowTop, uniques, groupBy, isEmpty, _map, isPlainObject, logInfo, logError } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { getRefererInfo } from '../src/refererDetection.js'; import { AUCTION_COMPLETED, AUCTION_IN_PROGRESS, getPriceGranularity } from '../src/auction.js'; @@ -42,10 +42,17 @@ const VALID_URL_KEY = ['canonical_url', 'og_url', 'twitter_url']; const DEFAULT_URL_KEY = 'page'; const LOG_TYPE = { + AP: 'AP', + PR: 'PR', APPR: 'APPR', RA: 'RA' }; +const BATCHING = { + SINGLE: 'SINGLE', + MULTI: 'MULTI' +} + let auctions = {}; let config; let pageDetails; @@ -59,6 +66,7 @@ class ErrorLogger { this.project = 'prebidanalytics'; this.dn = pageDetails.domain || ''; this.requrl = pageDetails.requrl || ''; + this.event = this.event; this.pbversion = PREBID_VERSION; this.cid = config.cid || ''; this.rd = additionalData; @@ -66,7 +74,7 @@ class ErrorLogger { send() { let url = EVENT_PIXEL_URL + '?' + formatQS(this); - triggerPixel(url); + utils.triggerPixel(url); } } @@ -81,10 +89,18 @@ class Configure { this.gdprConsent = undefined; this.gdprApplies = undefined; this.uspConsent = undefined; + this.pixelWaitTime = 0; + this.apLoggingPct = 0; + this.prLoggingPct = 0; + this.batching = BATCHING.SINGLE; this.shouldBeLogged = {}; this.mnetDebugConfig = ''; } + set publisherLper(plper) { + this.pubLper = plper; + } + getLoggingData() { return { cid: this.cid, @@ -123,10 +139,24 @@ class Configure { if (!isNaN(parseInt(response.percentage, 10))) { this.loggingPercent = response.percentage; } + + if (!isNaN(parseInt(response.pixelwaittime, 10))) { + this.pixelWaitTime = response.pixelwaittime; + } + + if (!isNaN(parseInt(response.aplper, 10))) { + this.apLoggingPct = response.aplper; + this.batching = BATCHING.MULTI; + } + + if (!isNaN(parseInt(response.prlper, 10))) { + this.prLoggingPct = response.prlper; + this.batching = BATCHING.MULTI; + } } overrideDomainLevelData(response) { - const domain = deepAccess(response, 'domain.' + pageDetails.domain); + const domain = utils.deepAccess(response, 'domain.' + pageDetails.domain); if (domain) { this.setDataFromResponse(domain); } @@ -149,14 +179,14 @@ class Configure { init() { // Forces Logging % to 100% let urlObj = URL.parseUrl(pageDetails.page); - if (deepAccess(urlObj, 'search.medianet_test') || urlObj.hostname === 'localhost') { + if (utils.deepAccess(urlObj, 'search.medianet_test') || urlObj.hostname === 'localhost') { this.loggingPercent = 100; this.ajaxState = CONFIG_PASS; this.debug = true; return; } - if (deepAccess(urlObj, 'search.mnet_setconfig')) { - this.mnetDebugConfig = deepAccess(urlObj, 'search.mnet_setconfig'); + if (utils.deepAccess(urlObj, 'search.mnet_setconfig')) { + this.mnetDebugConfig = utils.deepAccess(urlObj, 'search.mnet_setconfig'); } ajax( this._configURL(), @@ -201,7 +231,7 @@ class PageDetail { _getAttributeFromSelector(selector, attribute) { try { - let doc = getWindowTop().document; + let doc = utils.getWindowTop().document; let element = doc.querySelector(selector); if (element !== null && element[attribute]) { return element[attribute]; @@ -210,7 +240,7 @@ class PageDetail { } _getAbsoluteUrl(url) { - let aTag = getWindowTop().document.createElement('a'); + let aTag = utils.getWindowTop().document.createElement('a'); aTag.href = url; return aTag.href; @@ -238,14 +268,18 @@ class AdSlot { this.context = context; this.adext = adext; this.logged = {}; + this.logged[LOG_TYPE.PR] = false; + this.logged[LOG_TYPE.AP] = false; + this.logged[LOG_TYPE.APPR] = false; this.targeting = undefined; this.medianetPresent = 0; } getShouldBeLogged(logType) { if (!config.shouldBeLogged.hasOwnProperty(logType)) { - config.shouldBeLogged[logType] = isSampled(); + config.shouldBeLogged[logType] = isSampled(logType); } + config.shouldBeLogged[logType] = isSampled(logType); return config.shouldBeLogged[logType]; } @@ -309,7 +343,7 @@ class Bid { bdp: this.cpm, cbdp: this.dfpbd, dfpbd: this.dfpbd, - szs: this.allMediaTypeSizes.join('|'), + szs: this.allMediaTypeSizes.map(sz => sz.join('x')).join('|'), size: this.size, mtype: this.mediaType, dId: this.dealId, @@ -358,8 +392,8 @@ class Auction { flrdata: this._mergeFieldsToLog({ ln: this.floorData.location, skp: this.floorData.skipped, - enfj: deepAccess(this.floorData, 'enforcements.enforceJS'), - enfd: deepAccess(this.floorData, 'enforcements.floorDeals'), + enfj: utils.deepAccess(this.floorData, 'enforcements.enforceJS'), + enfd: utils.deepAccess(this.floorData, 'enforcements.floorDeals'), sr: this.floorData.skipRate, fs: this.floorData.fetchStatus }), @@ -411,7 +445,7 @@ function auctionInitHandler({auctionId, adUnits, timeout, timestamp, bidderReque auctions[auctionId].auctionInitTime = timestamp; } addAddSlots(auctionId, adUnits, timeout); - const floorData = deepAccess(bidderRequests, '0.bids.0.floorData'); + const floorData = utils.deepAccess(bidderRequests, '0.bids.0.floorData'); if (floorData) { auctions[auctionId].floorData = {...floorData}; } @@ -419,10 +453,10 @@ function auctionInitHandler({auctionId, adUnits, timeout, timestamp, bidderReque function addAddSlots(auctionId, adUnits, tmax) { adUnits = adUnits || []; - const groupedAdUnits = groupBy(adUnits, 'code'); + const groupedAdUnits = utils.groupBy(adUnits, 'code'); Object.keys(groupedAdUnits).forEach((adUnitCode) => { const adUnits = groupedAdUnits[adUnitCode]; - const supplyAdCode = deepAccess(adUnits, '0.adUnitCode') || adUnitCode; + const supplyAdCode = utils.deepAccess(adUnits, '0.adUnitCode') || adUnitCode; let context = ''; let adext = {}; @@ -430,20 +464,21 @@ function addAddSlots(auctionId, adUnits, tmax) { const oSizes = {banner: [], video: []}; adUnits.forEach(({mediaTypes, sizes, ext}) => { mediaTypes = mediaTypes || {}; - adext = Object.assign(adext, ext || deepAccess(mediaTypes, 'banner.ext')); - context = deepAccess(mediaTypes, 'video.context') || context; + adext = Object.assign(adext, ext || utils.deepAccess(mediaTypes, 'banner.ext')); + context = utils.deepAccess(mediaTypes, 'video.context') || context; Object.keys(mediaTypes).forEach((mediaType) => mediaTypeMap[mediaType] = 1); const sizeObject = _getSizes(mediaTypes, sizes); sizeObject.banner.forEach(size => oSizes.banner.push(size)); sizeObject.video.forEach(size => oSizes.video.push(size)); }); - adext = isEmpty(adext) ? undefined : adext; - oSizes.banner = oSizes.banner.filter(uniques); - oSizes.video = oSizes.video.filter(uniques); - oSizes.native = mediaTypeMap.native === 1 ? [[1, 1].join('x')] : []; + adext = utils.isEmpty(adext) ? undefined : adext; + oSizes.banner = oSizes.banner.filter(utils.uniques); + oSizes.video = oSizes.video.filter(utils.uniques); + oSizes.native = mediaTypeMap.native === 1 ? [[1, 1]] : []; const allMediaTypeSizes = [].concat(oSizes.banner, oSizes.native, oSizes.video); const mediaTypes = Object.keys(mediaTypeMap).join('|'); + auctions[auctionId].addSlot({adUnitCode, supplyAdCode, mediaTypes, allMediaTypeSizes, context, tmax, adext}); }); } @@ -468,26 +503,22 @@ function bidRequestedHandler({ auctionId, auctionStart, bids, start, uspConsent, const bidObj = new Bid(bidId, bidder, src, start, adUnitCode, mediaTypes && Object.keys(mediaTypes).join('|'), requestSizes); auctions[auctionId].addBid(bidObj); if (bidder === MEDIANET_BIDDER_CODE) { - bidObj.crid = deepAccess(bid, 'params.crid'); - bidObj.pubcrid = deepAccess(bid, 'params.crid'); + bidObj.crid = utils.deepAccess(bid, 'params.crid'); + bidObj.pubcrid = utils.deepAccess(bid, 'params.crid'); auctions[auctionId].adSlots[adUnitCode].medianetPresent = 1; } }); } function _getSizes(mediaTypes, sizes) { - const banner = deepAccess(mediaTypes, 'banner.sizes') || sizes || []; - const native = deepAccess(mediaTypes, 'native') ? [[1, 1]] : []; - const playerSize = deepAccess(mediaTypes, 'video.playerSize') || []; + const banner = utils.deepAccess(mediaTypes, 'banner.sizes') || sizes || []; + const native = utils.deepAccess(mediaTypes, 'native') ? [[1, 1]] : []; + const playerSize = utils.deepAccess(mediaTypes, 'video.playerSize') || []; let video = []; if (playerSize.length === 2) { video = [playerSize] } - return { - banner: banner.map(size => size.join('x')), - native: native.map(size => size.join('x')), - video: video.map(size => size.join('x')) - } + return { banner, native, video } } function bidResponseHandler(bid) { @@ -506,10 +537,10 @@ function bidResponseHandler(bid) { { cpm, width, height, mediaType, timeToRespond, dealId, creativeId }, { adId, currency } ); - bidObj.floorPrice = deepAccess(bid, 'floorData.floorValue'); - bidObj.floorRule = deepAccess(bid, 'floorData.floorRule'); + bidObj.floorPrice = utils.deepAccess(bid, 'floorData.floorValue'); + bidObj.floorRule = utils.deepAccess(bid, 'floorData.floorRule'); bidObj.originalCpm = originalCpm || cpm; - let dfpbd = deepAccess(bid, 'adserverTargeting.hb_pb'); + let dfpbd = utils.deepAccess(bid, 'adserverTargeting.hb_pb'); if (!dfpbd) { let priceGranularity = getPriceGranularity(mediaType, bid); let priceGranularityKey = PRICE_GRANULARITY[priceGranularity]; @@ -562,12 +593,18 @@ function bidTimeoutHandler(timedOutBids) { }) } -function auctionEndHandler({auctionId, auctionEnd}) { +function auctionEndHandler({auctionId, auctionEnd, adUnitCodes}) { if (!(auctions[auctionId] instanceof Auction)) { return; } auctions[auctionId].status = AUCTION_COMPLETED; auctions[auctionId].auctionEndTime = auctionEnd; + + if (config.batching === BATCHING.MULTI) { + adUnitCodes.forEach(function (adUnitCode) { + sendEvent(auctionId, adUnitCode, LOG_TYPE.PR); + }); + } } function setTargetingHandler(params) { @@ -598,15 +635,34 @@ function setTargetingHandler(params) { auctionObj.bids.forEach(bid => { if (bid.bidder === DUMMY_BIDDER && bid.adUnitCode === adunit) { bid.iwb = bidAdIds.length === 0 ? 0 : 1; - bid.width = deepAccess(winningBid, 'width'); - bid.height = deepAccess(winningBid, 'height'); + bid.width = utils.deepAccess(winningBid, 'width'); + bid.height = utils.deepAccess(winningBid, 'height'); } }); - sendEvent(auctionId, adunit, LOG_TYPE.APPR); + sendEvent(auctionId, adunit, getLogType()); } } } +function getLogType() { + if (config.batching === BATCHING.SINGLE) { + return LOG_TYPE.APPR; + } + return LOG_TYPE.AP; +} + +function setBidderDone(params) { + if (config.pixelWaitTime != null && config.pixelWaitTime > 0) { + setTimeout(fireApAfterWait, config.pixelWaitTime, params) + } +} + +function fireApAfterWait(params) { + params.bids.forEach(function (adUnit) { + sendEvent(params.auctionId, adUnit.adUnitCode, LOG_TYPE.AP); + }); +} + function bidWonHandler(bid) { const { requestId, auctionId, adUnitCode } = bid; if (!(auctions[auctionId] instanceof Auction)) { @@ -621,8 +677,20 @@ function bidWonHandler(bid) { sendEvent(auctionId, adUnitCode, LOG_TYPE.RA); } -function isSampled() { - return Math.random() * 100 < parseFloat(config.loggingPercent); +function isSampled(logType) { + return Math.random() * 100 < parseFloat(getLogPercentage(logType)); +} + +function getLogPercentage(logType) { + let logPercentage = config.loggingPercent; + if (config.batching === BATCHING.MULTI) { + if (logType === LOG_TYPE.AP) { + logPercentage = config.apLoggingPct; + } else if (logType === LOG_TYPE.PR) { + logPercentage = config.prLoggingPct; + } + } + return logPercentage; } function isValidAuctionAdSlot(acid, adtag) { @@ -643,8 +711,13 @@ function sendEvent(id, adunit, logType) { function fireApPrLog(auctionId, adUnitName, logType) { const adSlot = auctions[auctionId].adSlots[adUnitName]; if (adSlot.getShouldBeLogged(logType) && !adSlot.logged[logType]) { + if (config.batching === BATCHING.SINGLE) { + adSlot.logged[LOG_TYPE.AP] = true; + adSlot.logged[LOG_TYPE.PR] = true; + } else { + adSlot.logged[logType] = true; + } fireAuctionLog(auctionId, adUnitName, logType); - adSlot.logged[logType] = true; } } @@ -658,7 +731,7 @@ function getCommonLoggingData(acid, adtag) { function fireAuctionLog(acid, adtag, logType) { let commonParams = getCommonLoggingData(acid, adtag); commonParams.lgtp = logType; - let targeting = deepAccess(commonParams, 'targ'); + let targeting = utils.deepAccess(commonParams, 'targ'); Object.keys(commonParams).forEach((key) => (commonParams[key] == null) && delete commonParams[key]); delete commonParams.targ; @@ -686,11 +759,11 @@ function fireAuctionLog(acid, adtag, logType) { } function formatQS(data) { - return _map(data, (value, key) => { + return utils._map(data, (value, key) => { if (value === undefined) { return key + '='; } - if (isPlainObject(value)) { + if (utils.isPlainObject(value)) { value = JSON.stringify(value); } return key + '=' + encodeURIComponent(value); @@ -699,7 +772,7 @@ function formatQS(data) { function firePixel(qs) { logsQueue.push(ENDPOINT + '&' + qs); - triggerPixel(ENDPOINT + '&' + qs); + utils.triggerPixel(ENDPOINT + '&' + qs); } class URL { @@ -740,7 +813,7 @@ let medianetAnalytics = Object.assign(adapter({URL, analyticsType}), { }, track({ eventType, args }) { if (config.debug) { - logInfo(eventType, args); + utils.logInfo(eventType, args); } switch (eventType) { case CONSTANTS.EVENTS.AUCTION_INIT: { @@ -771,6 +844,10 @@ let medianetAnalytics = Object.assign(adapter({URL, analyticsType}), { setTargetingHandler(args); break; } + case CONSTANTS.EVENTS.BIDDER_DONE : { + setBidderDone(args); + break; + } case CONSTANTS.EVENTS.BID_WON: { bidWonHandler(args); break; @@ -782,7 +859,7 @@ medianetAnalytics.originEnableAnalytics = medianetAnalytics.enableAnalytics; medianetAnalytics.enableAnalytics = function (configuration) { if (!configuration || !configuration.options || !configuration.options.cid) { - logError('Media.net Analytics adapter: cid is required.'); + utils.logError('Media.net Analytics adapter: cid is required.'); return; } $$PREBID_GLOBAL$$.medianetGlobals = $$PREBID_GLOBAL$$.medianetGlobals || {}; @@ -791,7 +868,7 @@ medianetAnalytics.enableAnalytics = function (configuration) { pageDetails = new PageDetail(); config = new Configure(configuration.options.cid); - config.pubLper = configuration.options.sampling || ''; + config.publisherLper = configuration.options.sampling || ''; config.init(); configuration.options.sampling = 1; medianetAnalytics.originEnableAnalytics(configuration); diff --git a/modules/medianetBidAdapter.js b/modules/medianetBidAdapter.js index db3921c9a47..3b7e555cc72 100644 --- a/modules/medianetBidAdapter.js +++ b/modules/medianetBidAdapter.js @@ -1,5 +1,5 @@ -import { parseUrl, getWindowTop, isArray, getGptSlotInfoForAdUnitCode, isStr, deepAccess, isEmpty, logError, triggerPixel, buildUrl, isEmptyStr, logInfo } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { getRefererInfo } from '../src/refererDetection.js'; @@ -27,7 +27,7 @@ window.mnet = window.mnet || {}; window.mnet.queue = window.mnet.queue || []; mnData.urlData = { - domain: parseUrl(refererInfo.referer).hostname, + domain: utils.parseUrl(refererInfo.referer).hostname, page: refererInfo.referer, isTop: refererInfo.reachedTop } @@ -78,7 +78,7 @@ function getUrlFromSelector(selector, attribute) { function getAttributeFromSelector(selector, attribute) { try { - let doc = getWindowTop().document; + let doc = utils.getWindowTop().document; let element = doc.querySelector(selector); if (element !== null && element[attribute]) { return element[attribute]; @@ -87,7 +87,7 @@ function getAttributeFromSelector(selector, attribute) { } function getAbsoluteUrl(url) { - let aTag = getWindowTop().document.createElement('a'); + let aTag = utils.getWindowTop().document.createElement('a'); aTag.href = url; return aTag.href; @@ -98,7 +98,7 @@ function filterUrlsByType(urls, type) { } function transformSizes(sizes) { - if (isArray(sizes) && sizes.length === 2 && !isArray(sizes[0])) { + if (utils.isArray(sizes) && sizes.length === 2 && !utils.isArray(sizes[0])) { return [getSize(sizes)]; } @@ -123,8 +123,8 @@ function getCoordinates(adUnitCode) { let element = document.getElementById(adUnitCode); if (!element && adUnitCode.indexOf('/') !== -1) { // now it means that adUnitCode is GAM AdUnitPath - const {divId} = getGptSlotInfoForAdUnitCode(adUnitCode); - if (isStr(divId)) { + const {divId} = utils.getGptSlotInfoForAdUnitCode(adUnitCode); + if (utils.isStr(divId)) { element = document.getElementById(divId); } } @@ -145,11 +145,11 @@ function getCoordinates(adUnitCode) { } function extParams(bidRequest, bidderRequests) { - const params = deepAccess(bidRequest, 'params'); - const gdpr = deepAccess(bidderRequests, 'gdprConsent'); - const uspConsent = deepAccess(bidderRequests, 'uspConsent'); - const userId = deepAccess(bidRequest, 'userId'); - const sChain = deepAccess(bidRequest, 'schain') || {}; + const params = utils.deepAccess(bidRequest, 'params'); + const gdpr = utils.deepAccess(bidderRequests, 'gdprConsent'); + const uspConsent = utils.deepAccess(bidderRequests, 'uspConsent'); + const userId = utils.deepAccess(bidRequest, 'userId'); + const sChain = utils.deepAccess(bidRequest, 'schain') || {}; const windowSize = spec.getWindowSize(); const gdprApplies = !!(gdpr && gdpr.gdprApplies); const uspApplies = !!(uspConsent); @@ -165,7 +165,7 @@ function extParams(bidRequest, bidderRequests) { windowSize.w !== -1 && windowSize.h !== -1 && { screen: windowSize }, userId && { user_id: userId }, $$PREBID_GLOBAL$$.medianetGlobals.analyticsEnabled && { analytics: true }, - !isEmpty(sChain) && {schain: sChain} + !utils.isEmpty(sChain) && {schain: sChain} ); } @@ -179,18 +179,13 @@ function slotParams(bidRequest) { }, all: bidRequest.params }; + let bannerSizes = utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || []; - if (bidRequest.ortb2Imp) { - params.ortb2Imp = bidRequest.ortb2Imp; - } - - let bannerSizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes') || []; - - const videoInMediaType = deepAccess(bidRequest, 'mediaTypes.video') || {}; - const videoInParams = deepAccess(bidRequest, 'params.video') || {}; + const videoInMediaType = utils.deepAccess(bidRequest, 'mediaTypes.video') || {}; + const videoInParams = utils.deepAccess(bidRequest, 'params.video') || {}; const videoCombinedObj = Object.assign({}, videoInParams, videoInMediaType); - if (!isEmpty(videoCombinedObj)) { + if (!utils.isEmpty(videoCombinedObj)) { params.video = videoCombinedObj; } @@ -201,7 +196,7 @@ function slotParams(bidRequest) { try { params.native = JSON.stringify(bidRequest.nativeParams); } catch (e) { - logError((`${BIDDER_CODE} : Incorrect JSON : bidRequest.nativeParams`)); + utils.logError((`${BIDDER_CODE} : Incorrect JSON : bidRequest.nativeParams`)); } } @@ -319,8 +314,8 @@ function isValidBid(bid) { } function fetchCookieSyncUrls(response) { - if (!isEmpty(response) && response[0].body && - response[0].body.ext && isArray(response[0].body.ext.csUrl)) { + if (!utils.isEmpty(response) && response[0].body && + response[0].body.ext && utils.isArray(response[0].body.ext.csUrl)) { return response[0].body.ext.csUrl; } @@ -328,15 +323,15 @@ function fetchCookieSyncUrls(response) { } function getLoggingData(event, data) { - data = (isArray(data) && data) || []; + data = (utils.isArray(data) && data) || []; let params = {}; params.logid = 'kfk'; params.evtid = 'projectevents'; params.project = 'prebid'; - params.acid = deepAccess(data, '0.auctionId') || ''; + params.acid = utils.deepAccess(data, '0.auctionId') || ''; params.cid = $$PREBID_GLOBAL$$.medianetGlobals.cid || ''; - params.crid = data.map((adunit) => deepAccess(adunit, 'params.0.crid') || adunit.adUnitCode).join('|'); + params.crid = data.map((adunit) => utils.deepAccess(adunit, 'params.0.crid') || adunit.adUnitCode).join('|'); params.adunit_count = data.length || 0; params.dn = mnData.urlData.domain || ''; params.requrl = mnData.urlData.page || ''; @@ -354,7 +349,7 @@ function logEvent (event, data) { hostname: EVENT_PIXEL_URL, search: getLoggingData(event, data) }; - triggerPixel(buildUrl(getParams)); + utils.triggerPixel(utils.buildUrl(getParams)); } function clearMnData() { @@ -362,8 +357,8 @@ function clearMnData() { } function addRenderer(bid) { - const videoContext = deepAccess(bid, 'context') || ''; - const vastTimeout = deepAccess(bid, 'vto'); + const videoContext = utils.deepAccess(bid, 'context') || ''; + const vastTimeout = utils.deepAccess(bid, 'vto'); /* Adding renderer only when the context is Outstream and the provider has responded with a renderer. */ @@ -389,7 +384,7 @@ function newVideoRenderer(bid) { mute: bid.mt } const adUnitCode = bid.dfp_id; - const divId = getGptSlotInfoForAdUnitCode(adUnitCode).divId || adUnitCode; + const divId = utils.getGptSlotInfoForAdUnitCode(adUnitCode).divId || adUnitCode; window.mnet.mediaNetoutstreamPlayer(bid, divId, obj); }); }); @@ -410,12 +405,12 @@ export const spec = { */ isBidRequestValid: function(bid) { if (!bid.params) { - logError(`${BIDDER_CODE} : Missing bid parameters`); + utils.logError(`${BIDDER_CODE} : Missing bid parameters`); return false; } - if (!bid.params.cid || !isStr(bid.params.cid) || isEmptyStr(bid.params.cid)) { - logError(`${BIDDER_CODE} : cid should be a string`); + if (!bid.params.cid || !utils.isStr(bid.params.cid) || utils.isEmptyStr(bid.params.cid)) { + utils.logError(`${BIDDER_CODE} : cid should be a string`); return false; } @@ -450,13 +445,13 @@ export const spec = { let validBids = []; if (!serverResponse || !serverResponse.body) { - logInfo(`${BIDDER_CODE} : response is empty`); + utils.logInfo(`${BIDDER_CODE} : response is empty`); return validBids; } let bids = serverResponse.body.bidList; - if (!isArray(bids) || bids.length === 0) { - logInfo(`${BIDDER_CODE} : no bids`); + if (!utils.isArray(bids) || bids.length === 0) { + utils.logInfo(`${BIDDER_CODE} : no bids`); return validBids; } validBids = bids.filter(bid => isValidBid(bid)); diff --git a/modules/medianetRtdProvider.js b/modules/medianetRtdProvider.js index cd86bf891f3..77889db5ff2 100644 --- a/modules/medianetRtdProvider.js +++ b/modules/medianetRtdProvider.js @@ -1,5 +1,5 @@ -import { isStr, isEmptyStr, logError, mergeDeep, isFn, insertElement } from '../src/utils.js'; import { submodule } from '../src/hook.js'; +import * as utils from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -15,8 +15,8 @@ window.mnjs.que = window.mnjs.que || []; function init(config) { const customerId = config.params && config.params.cid; - if (!customerId || !isStr(customerId) || isEmptyStr(customerId)) { - logError(`${SOURCE}: cid should be a string`); + if (!customerId || !utils.isStr(customerId) || utils.isEmptyStr(customerId)) { + utils.logError(`${SOURCE}: cid should be a string`); return false; } @@ -40,8 +40,8 @@ function getBidRequestData(requestBidsProps, callback, config, userConsent) { const success = (adUnitProps, openRtbProps) => { adUnits.forEach(adUnit => { adUnit[OPEN_RTB_FIELD] = adUnit[OPEN_RTB_FIELD] || {}; - mergeDeep(adUnit[OPEN_RTB_FIELD], openRtbProps[adUnit.code]); - mergeDeep(adUnit, adUnitProps[adUnit.code]); + utils.mergeDeep(adUnit[OPEN_RTB_FIELD], openRtbProps[adUnit.code]); + utils.mergeDeep(adUnit, adUnitProps[adUnit.code]); }); callback(); }; @@ -61,7 +61,7 @@ function onAuctionInitEvent(auctionInit) { function getTargetingData(adUnitCode) { const adUnits = getAdUnits(undefined, adUnitCode); let targetingData = {}; - if (window.mnjs.loaded && isFn(window.mnjs.getTargetingData)) { + if (window.mnjs.loaded && utils.isFn(window.mnjs.getTargetingData)) { targetingData = window.mnjs.getTargetingData(adUnitCode, adUnits, SOURCE) || {}; } const targeting = {}; @@ -86,7 +86,7 @@ function loadRtdScript(customerId) { script.type = 'text/javascript'; script.async = true; script.src = getClientUrl(customerId, window.location.hostname); - insertElement(script, window.document, 'head'); + utils.insertElement(script, window.document, 'head'); } function getAdUnits(adUnits, adUnitCodes) { diff --git a/modules/mediasquareBidAdapter.js b/modules/mediasquareBidAdapter.js index 1043c7cc3e6..e442b01a115 100644 --- a/modules/mediasquareBidAdapter.js +++ b/modules/mediasquareBidAdapter.js @@ -7,6 +7,7 @@ const BIDDER_CODE = 'mediasquare'; const BIDDER_URL_PROD = 'https://pbs-front.mediasquare.fr/' const BIDDER_URL_TEST = 'https://bidder-test.mediasquare.fr/' const BIDDER_ENDPOINT_AUCTION = 'msq_prebid'; +const BIDDER_ENDPOINT_SYNC = 'cookie_sync'; const BIDDER_ENDPOINT_WINNING = 'winning'; export const spec = { @@ -131,11 +132,18 @@ export const spec = { * @return {UserSync[]} The user syncs which should be dropped. */ getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { + let params = ''; + let endpoint = document.location.search.match(/msq_test=true/) ? BIDDER_URL_TEST : BIDDER_URL_PROD; if (typeof serverResponses === 'object' && serverResponses != null && serverResponses.length > 0 && serverResponses[0].hasOwnProperty('body') && serverResponses[0].body.hasOwnProperty('cookies') && typeof serverResponses[0].body.cookies === 'object') { return serverResponses[0].body.cookies; } else { - return []; + if (gdprConsent && typeof gdprConsent.consentString === 'string') { params += typeof gdprConsent.gdprApplies === 'boolean' ? `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}` : `&gdpr_consent=${gdprConsent.consentString}`; } + if (uspConsent && typeof uspConsent === 'string') { params += '&uspConsent=' + uspConsent } + return { + type: 'iframe', + url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=iframe' + params + }; } }, diff --git a/modules/merkleIdSystem.js b/modules/merkleIdSystem.js index 352c2d074e8..4ab29ec6f68 100644 --- a/modules/merkleIdSystem.js +++ b/modules/merkleIdSystem.js @@ -5,8 +5,8 @@ * @requires module:modules/userId */ -import { logInfo, logError, logWarn } from '../src/utils.js'; -import * as ajaxLib from '../src/ajax.js'; +import * as utils from '../src/utils.js' +import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js' import {getStorageManager} from '../src/storageManager.js'; @@ -34,7 +34,7 @@ function setCookie(name, value, expires) { } function setSession(storage, response) { - logInfo('Merkle setting session '); + utils.logInfo('Merkle setting session '); if (response && response.c && response.c.value && typeof response.c.value === 'string') { setCookie(SESSION_COOKIE_NAME, response.c.value, storage.expires); } @@ -42,11 +42,11 @@ function setSession(storage, response) { function constructUrl(configParams) { const session = getSession(configParams); - let url = configParams.endpoint + `?vendor=${configParams.vendor}&sv_cid=${configParams.sv_cid}&sv_domain=${configParams.sv_domain}&sv_pubid=${configParams.sv_pubid}`; + let url = ID_URL + `?vendor=${configParams.vendor}&sv_cid=${configParams.sv_cid}&sv_domain=${configParams.sv_domain}&sv_pubid=${configParams.sv_pubid}`; if (session) { url = `${url}&sv_session=${session}`; } - logInfo('Merkle url :' + url); + utils.logInfo('Merkle url :' + url); return url; } @@ -54,31 +54,30 @@ function generateId(configParams, configStorage) { const url = constructUrl(configParams); const resp = function (callback) { - ajaxLib.ajaxBuilder()( - url, - response => { + const callbacks = { + success: response => { let responseObj; if (response) { try { responseObj = JSON.parse(response); setSession(configStorage, responseObj) - logInfo('Merkle responseObj ' + JSON.stringify(responseObj)); + utils.logInfo('Merkle responseObj ' + JSON.stringify(responseObj)); } catch (error) { - logError(error); + utils.logError(error); } } const date = new Date().toUTCString(); responseObj.date = date; - logInfo('Merkle responseObj with date ' + JSON.stringify(responseObj)); + utils.logInfo('Merkle responseObj with date ' + JSON.stringify(responseObj)); callback(responseObj); }, - error => { - logError(`${MODULE_NAME}: merkleId fetch encountered an error`, error); + error: error => { + utils.logError(`${MODULE_NAME}: merkleId fetch encountered an error`, error); callback(); - }, - {method: 'GET', withCredentials: true} - ); + } + }; + ajax(url, callbacks, undefined, {method: 'GET', withCredentials: true}); }; return resp; } @@ -98,7 +97,7 @@ export const merkleIdSubmodule = { */ decode(value) { const id = (value && value.pam_id && typeof value.pam_id.id === 'string') ? value.pam_id : undefined; - logInfo('Merkle id ' + JSON.stringify(id)); + utils.logInfo('Merkle id ' + JSON.stringify(id)); return id ? {'merkleId': id} : undefined; }, /** @@ -109,33 +108,28 @@ export const merkleIdSubmodule = { * @returns {IdResponse|undefined} */ getId(config, consentData) { - logInfo('User ID - merkleId generating id'); + utils.logInfo('User ID - merkleId generating id'); const configParams = (config && config.params) || {}; if (!configParams || typeof configParams.vendor !== 'string') { - logError('User ID - merkleId submodule requires a valid vendor to be defined'); + utils.logError('User ID - merkleId submodule requires a valid vendor to be defined'); return; } if (typeof configParams.sv_cid !== 'string') { - logError('User ID - merkleId submodule requires a valid sv_cid string to be defined'); + utils.logError('User ID - merkleId submodule requires a valid sv_cid string to be defined'); return; } if (typeof configParams.sv_pubid !== 'string') { - logError('User ID - merkleId submodule requires a valid sv_pubid string to be defined'); + utils.logError('User ID - merkleId submodule requires a valid sv_pubid string to be defined'); return; } - if (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) { - logError('User ID - merkleId submodule does not currently handle consent strings'); + utils.logError('User ID - merkleId submodule does not currently handle consent strings'); return; } - if (typeof configParams.endpoint !== 'string') { - logWarn('User ID - merkleId submodule endpoint string is not defined'); - configParams.endpoint = ID_URL - } if (typeof configParams.sv_domain !== 'string') { configParams.sv_domain = merkleIdSubmodule.findRootDomain(); @@ -146,16 +140,11 @@ export const merkleIdSubmodule = { return {callback: resp}; }, extendId: function (config = {}, consentData, storedId) { - logInfo('User ID - merkleId stored id ' + storedId); + utils.logInfo('User ID - merkleId stored id ' + storedId); const configParams = (config && config.params) || {}; - if (typeof configParams.endpoint !== 'string') { - logWarn('User ID - merkleId submodule endpoint string is not defined'); - configParams.endpoint = ID_URL - } - if (consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies) { - logError('User ID - merkleId submodule does not currently handle consent strings'); + utils.logError('User ID - merkleId submodule does not currently handle consent strings'); return; } @@ -169,19 +158,19 @@ export const merkleIdSubmodule = { let refreshInSeconds = DEFAULT_REFRESH; if (configParams && configParams.refreshInSeconds && typeof configParams.refreshInSeconds === 'number') { refreshInSeconds = configParams.refreshInSeconds; - logInfo('User ID - merkleId param refreshInSeconds' + refreshInSeconds); + utils.logInfo('User ID - merkleId param refreshInSeconds' + refreshInSeconds); } const storedDate = new Date(storedId.date); let refreshNeeded = false; if (storedDate) { refreshNeeded = storedDate && (Date.now() - storedDate.getTime() > refreshInSeconds * 1000); if (refreshNeeded) { - logInfo('User ID - merkleId needs refreshing id'); + utils.logInfo('User ID - merkleId needs refreshing id'); const resp = generateId(configParams, configStorage) return {callback: resp}; } } - logInfo('User ID - merkleId not refreshed'); + utils.logInfo('User ID - merkleId not refreshed'); return {id: storedId}; } diff --git a/modules/mgidBidAdapter.js b/modules/mgidBidAdapter.js deleted file mode 100644 index c811a0b2981..00000000000 --- a/modules/mgidBidAdapter.js +++ /dev/null @@ -1,617 +0,0 @@ -import { _each, deepAccess, isPlainObject, isArray, isStr, logInfo, parseUrl, isEmpty, triggerPixel, logWarn, getBidIdParameter, isFn, isNumber } from '../src/utils.js'; -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER, NATIVE} from '../src/mediaTypes.js'; -import {config} from '../src/config.js'; -import { getStorageManager } from '../src/storageManager.js'; - -const GVLID = 358; -const DEFAULT_CUR = 'USD'; -const BIDDER_CODE = 'mgid'; -export const storage = getStorageManager(GVLID, BIDDER_CODE); -const ENDPOINT_URL = 'https://prebid.mgid.com/prebid/'; -const LOG_WARN_PREFIX = '[MGID warn]: '; -const LOG_INFO_PREFIX = '[MGID info]: '; -const NATIVE_ASSETS = { - 'TITLE': { ID: 1, KEY: 'title', TYPE: 0 }, - 'IMAGE': { ID: 2, KEY: 'image', TYPE: 0 }, - 'ICON': { ID: 3, KEY: 'icon', TYPE: 0 }, - 'SPONSOREDBY': { ID: 4, KEY: 'sponsoredBy', TYPE: 1 }, // please note that type of SPONSORED is also 1 - 'DESC': { ID: 5, KEY: 'data', TYPE: 2 }, // please note that type of BODY is also set to 2 - 'PRICE': { ID: 6, KEY: 'price', TYPE: 6 }, - 'SALEPRICE': { ID: 7, KEY: 'saleprice', TYPE: 7 }, - 'DISPLAYURL': { ID: 8, KEY: 'displayurl', TYPE: 11 }, - 'CTA': { ID: 9, KEY: 'cta', TYPE: 12 }, - 'BODY': { ID: 10, KEY: 'body', TYPE: 2 }, // please note that type of DESC is also set to 2 - 'SPONSORED': { ID: 11, KEY: 'sponsored', TYPE: 1 }, // please note that type of SPONSOREDBY is also set to 1 -}; -const NATIVE_ASSET_IMAGE_TYPE = { - 'ICON': 1, - 'IMAGE': 3 -}; -const DEFAULT_IMAGE_WIDTH = 492; -const DEFAULT_IMAGE_HEIGHT = 328; -const DEFAULT_ICON_WIDTH = 50; -const DEFAULT_ICON_HEIGHT = 50; -const DEFAULT_TITLE_LENGTH = 80; - -let isInvalidNativeRequest = false; - -// check if title, image can be added with mandatory field default values -const NATIVE_MINIMUM_REQUIRED_IMAGE_ASSETS = [ - { - id: NATIVE_ASSETS.SPONSOREDBY.ID, - required: true, - data: { - type: 1 - } - }, - { - id: NATIVE_ASSETS.TITLE.ID, - required: true, - }, - { - id: NATIVE_ASSETS.IMAGE.ID, - required: true, - } -]; -let _NATIVE_ASSET_ID_TO_KEY_MAP = {}; -let _NATIVE_ASSET_KEY_TO_ASSET_MAP = {}; - -// loading _NATIVE_ASSET_ID_TO_KEY_MAP -_each(NATIVE_ASSETS, anAsset => { _NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY }); -// loading _NATIVE_ASSET_KEY_TO_ASSET_MAP -_each(NATIVE_ASSETS, anAsset => { _NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset }); - -export const spec = { - VERSION: '1.5', - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, NATIVE], - reId: /^[1-9][0-9]*$/, - NATIVE_ASSET_ID_TO_KEY_MAP: _NATIVE_ASSET_ID_TO_KEY_MAP, - NATIVE_ASSET_KEY_TO_ASSET_MAP: _NATIVE_ASSET_KEY_TO_ASSET_MAP, - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: (bid) => { - const banner = deepAccess(bid, 'mediaTypes.banner'); - const native = deepAccess(bid, 'mediaTypes.native'); - let nativeOk = isPlainObject(native); - if (nativeOk) { - const nativeParams = deepAccess(bid, 'nativeParams'); - let assetsCount = 0; - if (isPlainObject(nativeParams)) { - for (let k in nativeParams) { - let v = nativeParams[k]; - const supportProp = spec.NATIVE_ASSET_KEY_TO_ASSET_MAP.hasOwnProperty(k); - if (supportProp) { - assetsCount++ - } - if (!isPlainObject(v) || (!supportProp && deepAccess(v, 'required'))) { - nativeOk = false; - break; - } - } - } - nativeOk = nativeOk && (assetsCount > 0); - } - let bannerOk = isPlainObject(banner); - if (bannerOk) { - const sizes = deepAccess(banner, 'sizes'); - bannerOk = isArray(sizes) && sizes.length > 0; - for (let f = 0; bannerOk && f < sizes.length; f++) { - bannerOk = sizes[f].length === 2; - } - } - let acc = Number(bid.params.accountId); - let plcmt = Number(bid.params.placementId); - return (bannerOk || nativeOk) && isPlainObject(bid.params) && !!bid.adUnitCode && isStr(bid.adUnitCode) && (plcmt > 0 ? bid.params.placementId.toString().search(spec.reId) === 0 : true) && - !!acc && acc > 0 && bid.params.accountId.toString().search(spec.reId) === 0; - }, - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: (validBidRequests, bidderRequest) => { - logInfo(LOG_INFO_PREFIX + `buildRequests`); - if (validBidRequests.length === 0) { - return; - } - const info = pageInfo(); - const page = info.location || deepAccess(bidderRequest, 'refererInfo.referer') || deepAccess(bidderRequest, 'refererInfo.canonicalUrl'); - const hostname = parseUrl(page).hostname; - let domain = extractDomainFromHost(hostname) || hostname; - const accountId = setOnAny(validBidRequests, 'params.accountId'); - const muid = getLocalStorageSafely('mgMuidn'); - let url = (setOnAny(validBidRequests, 'params.bidUrl') || ENDPOINT_URL) + accountId; - if (isStr(muid) && muid.length > 0) { - url += '?muid=' + muid; - } - const cur = setOnAny(validBidRequests, 'params.currency') || setOnAny(validBidRequests, 'params.cur') || config.getConfig('currency.adServerCurrency') || DEFAULT_CUR; - const secure = window.location.protocol === 'https:' ? 1 : 0; - let imp = []; - validBidRequests.forEach(bid => { - let tagid = deepAccess(bid, 'params.placementId') || 0; - tagid = !tagid ? bid.adUnitCode : tagid + '/' + bid.adUnitCode; - let impObj = { - id: bid.bidId, - tagid, - secure, - }; - const floorData = getBidFloor(bid, cur); - if (floorData.floor) { - impObj.bidfloor = floorData.floor; - } - if (floorData.cur) { - impObj.bidfloorcur = floorData.cur - } - for (let mediaTypes in bid.mediaTypes) { - switch (mediaTypes) { - case BANNER: - impObj.banner = createBannerRequest(bid); - imp.push(impObj); - break; - case NATIVE: - const native = createNativeRequest(bid.nativeParams); - if (!isInvalidNativeRequest) { - impObj.native = { - 'request': native - }; - imp.push(impObj); - } - break; - } - } - }); - - if (imp.length === 0) { - return; - } - - let request = { - id: deepAccess(bidderRequest, 'bidderRequestId'), - site: {domain, page}, - cur: [cur], - geo: {utcoffset: info.timeOffset}, - device: { - ua: navigator.userAgent, - js: 1, - dnt: (navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1' || navigator.msDoNotTrack === '1') ? 1 : 0, - h: screen.height, - w: screen.width, - language: getLanguage() - }, - ext: {mgid_ver: spec.VERSION, prebid_ver: '$prebid.version$'}, - imp - }; - if (bidderRequest && bidderRequest.gdprConsent) { - request.user = {ext: {consent: bidderRequest.gdprConsent.consentString}}; - request.regs = {ext: {gdpr: (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)}} - } - if (info.referrer) { - request.site.ref = info.referrer - } - logInfo(LOG_INFO_PREFIX + `buildRequest:`, request); - return { - method: 'POST', - url: url, - data: JSON.stringify(request), - }; - }, - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: (serverResponse, bidRequests) => { - logInfo(LOG_INFO_PREFIX + `interpretResponse`, serverResponse); - if (serverResponse == null || serverResponse.body == null || serverResponse.body === '' || !isArray(serverResponse.body.seatbid) || !serverResponse.body.seatbid.length) { - return; - } - const returnedBids = []; - const muidn = deepAccess(serverResponse.body, 'ext.muidn') - if (isStr(muidn) && muidn.length > 0) { - setLocalStorageSafely('mgMuidn', muidn) - } - serverResponse.body.seatbid.forEach((bids) => { - bids.bid.forEach((bid) => { - const pbid = prebidBid(bid, serverResponse.body.cur); - if (pbid.mediaType === NATIVE && isEmpty(pbid.native)) { - return; - } - returnedBids.push(pbid); - }) - }); - - logInfo(LOG_INFO_PREFIX + `interpretedResponse`, returnedBids); - return returnedBids; - }, - onBidWon: (bid) => { - const cpm = deepAccess(bid, 'adserverTargeting.hb_pb') || ''; - if (isStr(bid.nurl) && bid.nurl !== '') { - bid.nurl = bid.nurl.replace( - /\${AUCTION_PRICE}/, - cpm - ); - triggerPixel(bid.nurl); - } - if (bid.isBurl) { - if (bid.mediaType === BANNER) { - bid.ad = bid.ad.replace( - /\${AUCTION_PRICE}/, - cpm - ) - } else { - bid.burl = bid.burl.replace( - /\${AUCTION_PRICE}/, - cpm - ); - triggerPixel(bid.burl); - } - } - logInfo(LOG_INFO_PREFIX + `onBidWon`); - }, - getUserSyncs: (syncOptions, serverResponses) => { - logInfo(LOG_INFO_PREFIX + `getUserSyncs`); - } -}; - -registerBidder(spec); - -function setOnAny(collection, key) { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); - if (result) { - return result; - } - } -} - -/** - * Unpack the Server's Bid into a Prebid-compatible one. - * @param serverBid - * @return Bid - */ -function prebidBid(serverBid, cur) { - if (!isStr(cur) || cur === '') { - cur = DEFAULT_CUR; - } - const bid = { - requestId: serverBid.impid, - ad: serverBid.adm, - cpm: serverBid.price, - creativeId: serverBid.adid, - currency: cur, - dealId: serverBid.dealid || '', - width: serverBid.w, - height: serverBid.h, - mediaType: 'banner', - netRevenue: true, - ttl: serverBid.ttl || 300, - nurl: serverBid.nurl || '', - burl: serverBid.burl || '', - isBurl: isStr(serverBid.burl) && serverBid.burl.length > 0, - meta: { advertiserDomains: (isArray(serverBid.adomain) && serverBid.adomain.length > 0 ? serverBid.adomain : []) }, - }; - setMediaType(serverBid, bid); - switch (bid.mediaType) { - case BANNER: - break; - case NATIVE: - parseNativeResponse(serverBid, bid); - break; - } - return bid; -} - -function setMediaType(bid, newBid) { - if (deepAccess(bid, 'ext.crtype') === 'native') { - newBid.mediaType = NATIVE; - } else { - newBid.mediaType = BANNER; - } -} - -function extractDomainFromHost(pageHost) { - if (pageHost == 'localhost') { - return 'localhost' - } - let domain = null; - try { - let domains = /[-\w]+\.([-\w]+|[-\w]{3,}|[-\w]{1,3}\.[-\w]{2})$/i.exec(pageHost); - if (domains != null && domains.length > 0) { - domain = domains[0]; - for (let i = 1; i < domains.length; i++) { - if (domains[i].length > domain.length) { - domain = domains[i]; - } - } - } - } catch (e) { - domain = null; - } - return domain; -} - -function getLanguage() { - const language = navigator.language ? 'language' : 'userLanguage'; - const lang2 = navigator[language].split('-')[0]; - if (lang2.length === 2 || lang2.length === 3) { - return lang2; - } - return ''; -} - -function getLocalStorageSafely(key) { - try { - return storage.getDataFromLocalStorage(key); - } catch (e) { - return null; - } -} - -function setLocalStorageSafely(key, val) { - try { - return storage.setDataInLocalStorage(key, val); - } catch (e) { - return null; - } -} - -function createBannerRequest(bid) { - const sizes = deepAccess(bid, 'mediaTypes.banner.sizes'); - let format = []; - if (sizes.length > 1) { - for (let f = 0; f < sizes.length; f++) { - if (sizes[f].length === 2) { - format.push({w: sizes[f][0], h: sizes[f][1]}); - } - } - } - let r = { - w: sizes && sizes[0][0], - h: sizes && sizes[0][1], - }; - if (format.length) { - r.format = format - } - const pos = deepAccess(bid, 'mediaTypes.banner.pos') || 0 - if (pos) { - r.pos = pos - } - return r -} - -function createNativeRequest(params) { - let nativeRequestObject = { - plcmtcnt: 1, - assets: [] - }; - for (let key in params) { - let assetObj = {}; - if (params.hasOwnProperty(key)) { - if (!(nativeRequestObject.assets && nativeRequestObject.assets.length > 0 && nativeRequestObject.assets.hasOwnProperty(key))) { - switch (key) { - case NATIVE_ASSETS.TITLE.KEY: - assetObj = { - id: NATIVE_ASSETS.TITLE.ID, - required: params[key].required ? 1 : 0, - title: { - len: params[key].len || params[key].length || DEFAULT_TITLE_LENGTH - } - }; - break; - case NATIVE_ASSETS.IMAGE.KEY: - const wmin = params[key].wmin || params[key].minimumWidth || (isArray(params[key].minsizes) && params[key].minsizes.length > 0 ? params[key].minsizes[0] : 0); - const hmin = params[key].hmin || params[key].minimumHeight || (isArray(params[key].minsizes) && params[key].minsizes.length > 1 ? params[key].minsizes[1] : 0); - assetObj = { - id: NATIVE_ASSETS.IMAGE.ID, - required: params[key].required ? 1 : 0, - img: { - type: NATIVE_ASSET_IMAGE_TYPE.IMAGE, - w: params[key].w || params[key].width || (isArray(params[key].sizes) && params[key].sizes.length > 0 ? params[key].sizes[0] : 0), - h: params[key].h || params[key].height || (isArray(params[key].sizes) && params[key].sizes.length > 1 ? params[key].sizes[1] : 0), - mimes: params[key].mimes, - ext: params[key].ext, - } - }; - if (wmin > 0) { - assetObj.img.wmin = wmin; - } - if (hmin > 0) { - assetObj.img.hmin = hmin; - } - if (!assetObj.img.w) { - assetObj.img.w = DEFAULT_IMAGE_WIDTH; - } - if (!assetObj.img.h) { - assetObj.img.h = DEFAULT_IMAGE_HEIGHT; - } - break; - case NATIVE_ASSETS.ICON.KEY: - assetObj = { - id: NATIVE_ASSETS.ICON.ID, - required: params[key].required ? 1 : 0, - img: { - type: NATIVE_ASSET_IMAGE_TYPE.ICON, - w: params[key].w || params[key].width || (isArray(params[key].sizes) && params[key].sizes.length > 0 ? params[key].sizes[0] : 0), - h: params[key].h || params[key].height || (isArray(params[key].sizes) && params[key].sizes.length > 0 ? params[key].sizes[1] : 0), - } - }; - if (!assetObj.img.w) { - assetObj.img.w = DEFAULT_ICON_WIDTH; - } - if (!assetObj.img.h) { - assetObj.img.h = DEFAULT_ICON_HEIGHT; - } - break; - case NATIVE_ASSETS.SPONSORED.KEY: - case NATIVE_ASSETS.SPONSOREDBY.KEY: - case NATIVE_ASSETS.PRICE.KEY: - case NATIVE_ASSETS.SALEPRICE.KEY: - case NATIVE_ASSETS.DESC.KEY: - case NATIVE_ASSETS.BODY.KEY: - case NATIVE_ASSETS.DISPLAYURL.KEY: - case NATIVE_ASSETS.CTA.KEY: - assetObj = commonNativeRequestObject(spec.NATIVE_ASSET_KEY_TO_ASSET_MAP[key], params); - break; - default: - if (params[key].required) { - isInvalidNativeRequest = true; - return; - } - } - } - } - if (assetObj.id) { - nativeRequestObject.assets[nativeRequestObject.assets.length] = assetObj; - } - } - - // for native image adtype prebid has to have few required assests i.e. title,sponsoredBy, image - // if any of these are missing from the request then request will not be sent - let requiredAssetCount = NATIVE_MINIMUM_REQUIRED_IMAGE_ASSETS.length; - let presentrequiredAssetCount = 0; - NATIVE_MINIMUM_REQUIRED_IMAGE_ASSETS.forEach(ele => { - let lengthOfExistingAssets = nativeRequestObject.assets.length; - for (let i = 0; i < lengthOfExistingAssets; i++) { - if (ele.id === nativeRequestObject.assets[i].id) { - presentrequiredAssetCount++; - break; - } else { - if (ele.id === 4 && nativeRequestObject.assets[i].id === 11) { - if (deepAccess(nativeRequestObject.assets[i], 'data.type') === ele.data.type) { - presentrequiredAssetCount++; - break; - } - } - } - } - }); - isInvalidNativeRequest = requiredAssetCount !== presentrequiredAssetCount; - return nativeRequestObject; -} - -function commonNativeRequestObject(nativeAsset, params) { - const key = nativeAsset.KEY; - return { - id: nativeAsset.ID, - required: params[key].required ? 1 : 0, - data: { - type: nativeAsset.TYPE, - len: params[key].len, - ext: params[key].ext - } - }; -} - -function parseNativeResponse(bid, newBid) { - newBid.native = {}; - if (bid.hasOwnProperty('adm')) { - let adm = ''; - try { - adm = JSON.parse(bid.adm); - } catch (ex) { - logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native response for ad response: ' + newBid.adm); - return; - } - if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) { - newBid.mediaType = NATIVE; - for (let i = 0, len = adm.native.assets.length; i < len; i++) { - switch (adm.native.assets[i].id) { - case NATIVE_ASSETS.TITLE.ID: - newBid.native.title = adm.native.assets[i].title && adm.native.assets[i].title.text; - break; - case NATIVE_ASSETS.IMAGE.ID: - newBid.native.image = { - url: adm.native.assets[i].img && adm.native.assets[i].img.url, - height: adm.native.assets[i].img && adm.native.assets[i].img.h, - width: adm.native.assets[i].img && adm.native.assets[i].img.w, - }; - break; - case NATIVE_ASSETS.ICON.ID: - newBid.native.icon = { - url: adm.native.assets[i].img && adm.native.assets[i].img.url, - height: adm.native.assets[i].img && adm.native.assets[i].img.h, - width: adm.native.assets[i].img && adm.native.assets[i].img.w, - }; - break; - case NATIVE_ASSETS.SPONSOREDBY.ID: - case NATIVE_ASSETS.SPONSORED.ID: - case NATIVE_ASSETS.PRICE: - case NATIVE_ASSETS.SALEPRICE.ID: - case NATIVE_ASSETS.DESC.ID: - case NATIVE_ASSETS.BODY.ID: - case NATIVE_ASSETS.DISPLAYURL.ID: - case NATIVE_ASSETS.CTA.ID: - newBid.native[spec.NATIVE_ASSET_ID_TO_KEY_MAP[adm.native.assets[i].id]] = adm.native.assets[i].data && adm.native.assets[i].data.value; - break; - } - } - newBid.native.clickUrl = adm.native.link && adm.native.link.url; - newBid.native.clickTrackers = (adm.native.link && adm.native.link.clicktrackers) || []; - newBid.native.impressionTrackers = adm.native.imptrackers || []; - newBid.native.jstracker = adm.native.jstracker || []; - newBid.width = 0; - newBid.height = 0; - } - } -} - -function pageInfo() { - var w, d, l, r, m, p, t; - for (w = window, d = w.document, l = d.location.href, r = d.referrer, m = 0, t = new Date(); w !== w.parent;) { - try { - p = w.parent; l = p.location.href; r = p.document.referrer; w = p; - } catch (e) { - m = top !== w.parent ? 2 : 1; - break - } - } - return { - location: l, - referrer: r || '', - masked: m, - wWidth: w.innerWidth, - wHeight: w.innerHeight, - date: t.toUTCString(), - timeOffset: t.getTimezoneOffset() - }; -} - -/** - * Get the floor price from bid.params for backward compatibility. - * If not found, then check floor module. - * @param bid A valid bid object - * @returns {*|number} floor price - */ -function getBidFloor(bid, cur) { - let bidFloor = getBidIdParameter('bidfloor', bid.params) || getBidIdParameter('bidFloor', bid.params) || 0; - const reqCur = cur - - if (!bidFloor && isFn(bid.getFloor)) { - const floorObj = bid.getFloor({ - currency: '*', - mediaType: '*', - size: '*' - }); - if (isPlainObject(floorObj) && isNumber(floorObj.floor)) { - if (!floorObj.currency && reqCur !== DEFAULT_CUR) { - floorObj.currency = DEFAULT_CUR - } - if (floorObj.currency && reqCur !== floorObj.currency) { - cur = floorObj.currency - } - bidFloor = floorObj.floor; - } - } - if (reqCur === cur) { - cur = '' - } - return {floor: bidFloor, cur: cur} -} diff --git a/modules/microadBidAdapter.js b/modules/microadBidAdapter.js index 982bd61840a..c78a66aecee 100644 --- a/modules/microadBidAdapter.js +++ b/modules/microadBidAdapter.js @@ -1,6 +1,6 @@ -import { deepAccess, isEmpty, isStr } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'microad'; @@ -82,8 +82,8 @@ export const spec = { } } - const idlEnv = deepAccess(bid, 'userId.idl_env') - if (!isEmpty(idlEnv) && isStr(idlEnv)) { + const idlEnv = utils.deepAccess(bid, 'userId.idl_env') + if (!utils.isEmpty(idlEnv) && utils.isStr(idlEnv)) { params['idl_env'] = idlEnv } diff --git a/modules/missenaBidAdapter.js b/modules/missenaBidAdapter.js deleted file mode 100644 index 30749e977a8..00000000000 --- a/modules/missenaBidAdapter.js +++ /dev/null @@ -1,89 +0,0 @@ -import { formatQS, logInfo } from '../src/utils.js'; -import { BANNER } from '../src/mediaTypes.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'missena'; -const ENDPOINT_URL = 'https://bid.missena.io/'; - -export const spec = { - aliases: [BIDDER_CODE], - code: BIDDER_CODE, - gvlid: 687, - supportedMediaTypes: [BANNER], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function (bid) { - return typeof bid == 'object' && !!bid.params.apiKey; - }, - - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function (validBidRequests, bidderRequest) { - return validBidRequests.map((bidRequest) => { - const payload = { - request_id: bidRequest.bidId, - timeout: bidderRequest.timeout, - }; - - if (bidderRequest && bidderRequest.refererInfo) { - payload.referer = bidderRequest.refererInfo.referer; - payload.referer_canonical = bidderRequest.refererInfo.canonicalUrl; - } - - if (bidderRequest && bidderRequest.gdprConsent) { - payload.consent_string = bidderRequest.gdprConsent.consentString; - payload.consent_required = bidderRequest.gdprConsent.gdprApplies; - } - - return { - method: 'POST', - url: ENDPOINT_URL + '?' + formatQS({ t: bidRequest.params.apiKey }), - data: JSON.stringify(payload), - }; - }); - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function (serverResponse, bidRequest) { - const bidResponses = []; - const response = serverResponse.body; - - if (response && !response.timeout && !!response.ad) { - bidResponses.push(response); - } - - return bidResponses; - }, - - /** - * Register bidder specific code, which will execute if bidder timed out after an auction - * @param {data} Containing timeout specific data - */ - onTimeout: function onTimeout(timeoutData) { - logInfo('Missena - Timeout from adapter', timeoutData); - }, - - /** - * Register bidder specific code, which@ will execute if a bid from this bidder won the auction - * @param {Bid} The bid that won the auction - */ - onBidWon: function (bid) { - logInfo('Missena - Bid won', bid); - }, -}; - -registerBidder(spec); diff --git a/modules/multibid/index.js b/modules/multibid/index.js index ef0771e291f..dd4999b2dca 100644 --- a/modules/multibid/index.js +++ b/modules/multibid/index.js @@ -5,9 +5,7 @@ import {config} from '../../src/config.js'; import {setupBeforeHookFnOnce, getHook} from '../../src/hook.js'; -import { - logWarn, deepAccess, getUniqueIdentifierStr, deepSetValue, groupBy -} from '../../src/utils.js'; +import * as utils from '../../src/utils.js'; import events from '../../src/events.js'; import CONSTANTS from '../../src/constants.json'; import {addBidderRequests} from '../../src/auction.js'; @@ -52,7 +50,7 @@ export function validateMultibid(conf) { let duplicate = conf.filter(entry => { // Check if entry.bidder is not defined or typeof string, filter entry and reset configuration if ((!entry.bidder || typeof entry.bidder !== 'string') && (!entry.bidders || !Array.isArray(entry.bidders))) { - logWarn('Filtering multibid entry. Missing required bidder or bidders property.'); + utils.logWarn('Filtering multibid entry. Missing required bidder or bidders property.'); check = false; return false; } @@ -99,26 +97,26 @@ export function adjustBidderRequestsHook(fn, bidderRequests) { * @param {Object} bid object */ export function addBidResponseHook(fn, adUnitCode, bid) { - let floor = deepAccess(bid, 'floorData.floorValue'); + let floor = utils.deepAccess(bid, 'floorData.floorValue'); if (!config.getConfig('multibid')) resetMultiConfig(); // Checks if multiconfig exists and bid bidderCode exists within config and is an adpod bid // Else checks if multiconfig exists and bid bidderCode exists within config // Else continue with no modifications - if (hasMultibid && multiConfig[bid.bidderCode] && deepAccess(bid, 'video.context') === 'adpod') { + if (hasMultibid && multiConfig[bid.bidderCode] && utils.deepAccess(bid, 'video.context') === 'adpod') { fn.call(this, adUnitCode, bid); } else if (hasMultibid && multiConfig[bid.bidderCode]) { // Set property multibidPrefix on bid if (multiConfig[bid.bidderCode].prefix) bid.multibidPrefix = multiConfig[bid.bidderCode].prefix; bid.originalBidder = bid.bidderCode; // Check if stored bids for auction include adUnitCode.bidder and max limit not reach for ad unit - if (deepAccess(multibidUnits, [adUnitCode, bid.bidderCode])) { + if (utils.deepAccess(multibidUnits, `${adUnitCode}.${bid.bidderCode}`)) { // Store request id under new property originalRequestId, create new unique bidId, // and push bid into multibid stored bids for auction if max not reached and bid cpm above floor if (!multibidUnits[adUnitCode][bid.bidderCode].maxReached && (!floor || floor <= bid.cpm)) { bid.originalRequestId = bid.requestId; - bid.requestId = getUniqueIdentifierStr(); + bid.requestId = utils.getUniqueIdentifierStr(); multibidUnits[adUnitCode][bid.bidderCode].ads.push(bid); let length = multibidUnits[adUnitCode][bid.bidderCode].ads.length; @@ -128,12 +126,12 @@ export function addBidResponseHook(fn, adUnitCode, bid) { fn.call(this, adUnitCode, bid); } else { - logWarn(`Filtering multibid received from bidder ${bid.bidderCode}: ` + ((multibidUnits[adUnitCode][bid.bidderCode].maxReached) ? `Maximum bid limit reached for ad unit code ${adUnitCode}` : 'Bid cpm under floors value.')); + utils.logWarn(`Filtering multibid received from bidder ${bid.bidderCode}: ` + ((multibidUnits[adUnitCode][bid.bidderCode].maxReached) ? `Maximum bid limit reached for ad unit code ${adUnitCode}` : 'Bid cpm under floors value.')); } } else { - if (deepAccess(bid, 'floorData.floorValue')) deepSetValue(multibidUnits, [adUnitCode, bid.bidderCode], {floor: deepAccess(bid, 'floorData.floorValue')}); + if (utils.deepAccess(bid, 'floorData.floorValue')) utils.deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {floor: utils.deepAccess(bid, 'floorData.floorValue')}); - deepSetValue(multibidUnits, [adUnitCode, bid.bidderCode], {ads: [bid]}); + utils.deepSetValue(multibidUnits, `${adUnitCode}.${bid.bidderCode}`, {ads: [bid]}); if (multibidUnits[adUnitCode][bid.bidderCode].ads.length === multiConfig[bid.bidderCode].maxbids) multibidUnits[adUnitCode][bid.bidderCode].maxReached = true; fn.call(this, adUnitCode, bid); @@ -172,11 +170,11 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi if (hasMultibid) { const dealPrioritization = config.getConfig('sendBidsControl.dealPrioritization'); let modifiedBids = []; - let buckets = groupBy(bidsReceived, 'adUnitCode'); + let buckets = utils.groupBy(bidsReceived, 'adUnitCode'); let bids = [].concat.apply([], Object.keys(buckets).reduce((result, slotId) => { let bucketBids = []; // Get bids and group by property originalBidder - let bidsByBidderName = groupBy(buckets[slotId], 'originalBidder'); + let bidsByBidderName = utils.groupBy(buckets[slotId], 'originalBidder'); let adjustedBids = [].concat.apply([], Object.keys(bidsByBidderName).map(key => { // Reset all bidderCodes to original bidder values and sort by CPM return bidsByBidderName[key].sort((bidA, bidB) => { @@ -185,7 +183,7 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi return bidA.cpm > bidB.cpm ? -1 : (bidA.cpm < bidB.cpm ? 1 : 0); }).map((bid, index) => { // For each bid (post CPM sort), set dynamic bidderCode using prefix and index if less than maxbid amount - if (deepAccess(multiConfig, `${bid.bidderCode}.prefix`) && index !== 0 && index < multiConfig[bid.bidderCode].maxbids) { + if (utils.deepAccess(multiConfig, `${bid.bidderCode}.prefix`) && index !== 0 && index < multiConfig[bid.bidderCode].maxbids) { bid.bidderCode = multiConfig[bid.bidderCode].prefix + (index + 1); } @@ -193,7 +191,7 @@ export function targetBidPoolHook(fn, bidsReceived, highestCpmCallback, adUnitBi }) })); // Get adjustedBids by bidderCode and reduce using highestCpmCallback - let bidsByBidderCode = groupBy(adjustedBids, 'bidderCode'); + let bidsByBidderCode = utils.groupBy(adjustedBids, 'bidderCode'); Object.keys(bidsByBidderCode).forEach(key => bucketBids.push(bidsByBidderCode[key].reduce(highestCpmCallback))); // if adUnitBidLimit is set, pass top N number bids if (adUnitBidLimit > 0) { diff --git a/modules/mwOpenLinkIdSystem.js b/modules/mwOpenLinkIdSystem.js index 552223fa73c..b2381836d5d 100644 --- a/modules/mwOpenLinkIdSystem.js +++ b/modules/mwOpenLinkIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { timestamp, logError, deepClone, generateUUID, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -18,20 +18,20 @@ const openLinkID = { const storage = getStorageManager(); function getExpirationDate() { - return (new Date(timestamp() + openLinkID.cookie_expiration)).toGMTString(); + return (new Date(utils.timestamp() + openLinkID.cookie_expiration)).toGMTString(); } function isValidConfig(configParams) { if (!configParams) { - logError('User ID - mwOlId submodule requires configParams'); + utils.logError('User ID - mwOlId submodule requires configParams'); return false; } if (!configParams.accountId) { - logError('User ID - mwOlId submodule requires accountId to be defined'); + utils.logError('User ID - mwOlId submodule requires accountId to be defined'); return false; } if (!configParams.partnerId) { - logError('User ID - mwOlId submodule requires partnerId to be defined'); + utils.logError('User ID - mwOlId submodule requires partnerId to be defined'); return false; } return true; @@ -96,7 +96,7 @@ function register(configParams, olid) { function setID(configParams) { if (!isValidConfig(configParams)) return undefined; const mwOlId = readCookie(); - const newMwOlId = mwOlId ? deepClone(mwOlId) : {eid: generateUUID()}; + const newMwOlId = mwOlId ? utils.deepClone(mwOlId) : {eid: utils.generateUUID()}; writeCookie(newMwOlId); register(configParams, newMwOlId.eid); return { @@ -122,7 +122,7 @@ export const mwOpenLinkIdSubModule = { * @return {(Object|undefined} */ decode(mwOlId) { - const id = mwOlId && isPlainObject(mwOlId) ? mwOlId.eid : undefined; + const id = mwOlId && utils.isPlainObject(mwOlId) ? mwOlId.eid : undefined; return id ? { 'mwOpenLinkId': id } : undefined; }, diff --git a/modules/mytargetBidAdapter.js b/modules/mytargetBidAdapter.js deleted file mode 100644 index f55f2e6b802..00000000000 --- a/modules/mytargetBidAdapter.js +++ /dev/null @@ -1,112 +0,0 @@ -import { _map } from '../src/utils.js'; -import { config } from '../src/config.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'mytarget'; -const BIDDER_URL = '//ad.mail.ru/hbid_prebid/'; -const DEFAULT_CURRENCY = 'RUB'; -const DEFAULT_TTL = 180; - -function buildPlacement(bidRequest) { - let { bidId, params } = bidRequest; - let { placementId, position, response, bidfloor } = params; - let placement = { - placementId, - id: bidId, - position: position || 0, - response: response || 0 - }; - - if (typeof bidfloor !== 'undefined') { - placement.bidfloor = bidfloor; - } - - return placement; -} - -function getSiteName(referrer) { - let sitename = config.getConfig('mytarget.sitename'); - - if (!sitename) { - const parsed = document.createElement('a'); - parsed.href = decodeURIComponent(referrer); - sitename = parsed.hostname; - } - - return sitename; -} - -function generateRandomId() { - return Math.random().toString(16).substring(2); -} - -export const spec = { - code: BIDDER_CODE, - - isBidRequestValid: function(bid) { - return !!bid.params.placementId; - }, - - buildRequests: function(validBidRequests, bidderRequest) { - let referrer = ''; - - if (bidderRequest && bidderRequest.refererInfo) { - referrer = bidderRequest.refererInfo.referer; - } - - const payload = { - places: _map(validBidRequests, buildPlacement), - site: { - sitename: getSiteName(referrer), - page: referrer - }, - settings: { - currency: DEFAULT_CURRENCY, - windowSize: { - width: window.screen.width, - height: window.screen.height - } - } - }; - - return { - method: 'POST', - url: BIDDER_URL, - data: payload, - }; - }, - - interpretResponse: function(serverResponse, bidRequest) { - let { body } = serverResponse; - - if (body.bids) { - return _map(body.bids, (bid) => { - let bidResponse = { - requestId: bid.id, - cpm: bid.price, - width: bid.size.width, - height: bid.size.height, - ttl: bid.ttl || DEFAULT_TTL, - currency: bid.currency || DEFAULT_CURRENCY, - creativeId: bid.creativeId || generateRandomId(), - netRevenue: true, - meta: { - advertiserDomains: bid.adomain && bid.adomain.length > 0 ? bid.adomain : [], - } - } - - if (bid.adm) { - bidResponse.ad = bid.adm; - } else { - bidResponse.adUrl = bid.displayUrl; - } - - return bidResponse; - }); - } - - return []; - } -} - -registerBidder(spec); diff --git a/modules/nativoBidAdapter.js b/modules/nativoBidAdapter.js index c9e6a1f659f..880ff4b6a8e 100644 --- a/modules/nativoBidAdapter.js +++ b/modules/nativoBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isEmpty } from '../src/utils.js' +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER } from '../src/mediaTypes.js' // import { config } from 'src/config' @@ -6,8 +6,6 @@ import { BANNER } from '../src/mediaTypes.js' const BIDDER_CODE = 'nativo' const BIDDER_ENDPOINT = 'https://exchange.postrelease.com/prebid' -const GVLID = 263 - const TIME_TO_LIVE = 360 const SUPPORTED_AD_TYPES = [BANNER] @@ -17,19 +15,8 @@ const adUnitsRequested = {} // Prebid adapter referrence doc: https://docs.prebid.org/dev-docs/bidder-adaptor.html -// Validity checks for optionsl paramters -const validParameter = { - url: (value) => typeof value === 'string', - placementId: (value) => { - const isString = typeof value === 'string' - const isNumber = typeof value === 'number' - return isString || isNumber - }, -} - export const spec = { code: BIDDER_CODE, - gvlid: GVLID, aliases: ['ntv'], // short code supportedMediaTypes: SUPPORTED_AD_TYPES, @@ -40,23 +27,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - // We don't need any specific parameters to make a bid request - // If not parameters are supplied just verify it's the correct bidder code - if (!bid.params) return bid.bidder === BIDDER_CODE - - // Check if any supplied parameters are invalid - const hasInvalidParameters = Object.keys(bid.params).some(key => { - const value = bid.params[key] - const validityCheck = validParameter[key] - - // We don't have a test for this so it's not a paramter we care about - if (!validityCheck) return false - - // Return if the check is not passed - return !validityCheck(value) - }) - - return !hasInvalidParameters + return bid.params && !!bid.params.placementId }, /** @@ -68,37 +39,27 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { - const placementIds = new Set() + const placementIds = [] const placmentBidIdMap = {} let placementId, pageUrl validBidRequests.forEach((request) => { - pageUrl = deepAccess( - request, - 'params.url', - bidderRequest.refererInfo.referer - ) - placementId = deepAccess(request, 'params.placementId') - - if (placementId) { - placementIds.add(placementId) - } - - var key = placementId || request.adUnitCode - placmentBidIdMap[key] = { + pageUrl = pageUrl || request.params.url // Use the first url value found + placementId = request.params.placementId + placementIds.push(placementId) + placmentBidIdMap[placementId] = { bidId: request.bidId, size: getLargestSize(request.sizes), } }) bidRequestMap[bidderRequest.bidderRequestId] = placmentBidIdMap + if (!pageUrl) pageUrl = bidderRequest.refererInfo.referer + // Build adUnit data const adUnitData = { adUnits: validBidRequests.map((adUnit) => { // Track if we've already requested for this ad unit code - adUnitsRequested[adUnit.adUnitCode] = - adUnitsRequested[adUnit.adUnitCode] !== undefined - ? adUnitsRequested[adUnit.adUnitCode] + 1 - : 0 + adUnitsRequested[adUnit.adUnitCode] = adUnitsRequested[adUnit.adUnitCode] !== undefined ? adUnitsRequested[adUnit.adUnitCode]++ : 0 return { adUnitCode: adUnit.adUnitCode, mediaTypes: adUnit.mediaTypes, @@ -108,6 +69,7 @@ export const spec = { // Build QS Params let params = [ + { key: 'ntv_ptd', value: placementIds.toString() }, { key: 'ntv_pb_rid', value: bidderRequest.bidderRequestId }, { key: 'ntv_ppc', @@ -115,22 +77,14 @@ export const spec = { }, { key: 'ntv_dbr', - value: btoa(JSON.stringify(adUnitsRequested)), + value: btoa(JSON.stringify(adUnitsRequested)) }, { key: 'ntv_url', value: encodeURIComponent(pageUrl), - }, + } ] - if (placementIds.size > 0) { - // Convert Set to Array (IE 11 Safe) - const placements = [] - placementIds.forEach((value) => placements.push(value)) - // Append to query string paramters - params.unshift({ key: 'ntv_ptd', value: placements.join(',') }) - } - if (bidderRequest.gdprConsent) { // Put on the beginning of the qs param array params.unshift({ @@ -163,7 +117,7 @@ export const spec = { */ interpretResponse: function (response, request) { // If the bid response was empty, return [] - if (!response || !response.body || isEmpty(response.body)) return [] + if (!response || !response.body || utils.isEmpty(response.body)) return [] try { const body = @@ -178,7 +132,7 @@ export const spec = { let bidResponse, adUnit seatbids.forEach((seatbid) => { seatbid.bid.forEach((bid) => { - adUnit = this.getAdUnitData(body.id, bid) + adUnit = this.getRequestId(body.id, bid.impid) bidResponse = { requestId: adUnit.bidId, cpm: bid.price, @@ -259,7 +213,7 @@ export const spec = { let body serverResponses.forEach((response) => { // If the bid response was empty, return [] - if (!response || !response.body || isEmpty(response.body)) { + if (!response || !response.body || utils.isEmpty(response.body)) { return syncs } @@ -311,16 +265,14 @@ export const spec = { /** * Maps Prebid's bidId to Nativo's placementId values per unique bidderRequestId * @param {String} bidderRequestId - The unique ID value associated with the bidderRequest - * @param {Object} bid - The placement ID value from Nativo + * @param {String} placementId - The placement ID value from Nativo * @returns {String} - The bidId value associated with the corresponding placementId */ - getAdUnitData: function (bidderRequestId, bid) { - var data = deepAccess(bidRequestMap, `${bidderRequestId}.${bid.impid}`) - - if (data) return data - - var unitCode = deepAccess(bid, 'ext.ad_unit_id') - return deepAccess(bidRequestMap, `${bidderRequestId}.${unitCode}`) + getRequestId: function (bidderRequestId, placementId) { + return ( + bidRequestMap[bidderRequestId] && + bidRequestMap[bidderRequestId][placementId] + ) }, } registerBidder(spec) diff --git a/modules/nativoBidAdapter.md b/modules/nativoBidAdapter.md index f83fb45b52e..ec0980aae50 100644 --- a/modules/nativoBidAdapter.md +++ b/modules/nativoBidAdapter.md @@ -29,6 +29,7 @@ var adUnits = [ bids: [{ bidder: 'nativo', params: { + placementId: 1125609, url: 'https://test-sites.internal.nativo.net/testing/prebid_adpater.html' } }] diff --git a/modules/naveggIdSystem.js b/modules/naveggIdSystem.js deleted file mode 100644 index 7bd86879e9d..00000000000 --- a/modules/naveggIdSystem.js +++ /dev/null @@ -1,90 +0,0 @@ -/** - * This module adds naveggId to the User ID module - * The {@link module:modules/userId} module is required - * @module modules/naveggId - * @requires module:modules/userId - */ -import { isStr, isPlainObject, logError } from '../src/utils.js'; -import { submodule } from '../src/hook.js'; -import { getStorageManager } from '../src/storageManager.js'; - -const MODULE_NAME = 'naveggId'; -const OLD_NAVEGG_ID = 'nid'; -const NAVEGG_ID = 'nvggid' - -export const storage = getStorageManager(); - -function readnaveggIdFromLocalStorage() { - return storage.getDataFromLocalStorage(NAVEGG_ID); -} - -function readnaveggIDFromCookie() { - return storage.cookiesAreEnabled ? storage.getCookie(NAVEGG_ID) : null; -} - -function readoldnaveggIDFromCookie() { - return storage.cookiesAreEnabled ? storage.getCookie(OLD_NAVEGG_ID) : null; -} - -function readnvgIDFromCookie() { - return storage.cookiesAreEnabled ? (storage.findSimilarCookies('nvg') ? storage.findSimilarCookies('nvg')[0] : null) : null; -} - -function readnavIDFromCookie() { - return storage.cookiesAreEnabled ? (storage.findSimilarCookies('nav') ? storage.findSimilarCookies('nav')[0] : null) : null; -} - -function readnvgnavFromLocalStorage() { - var i; - const query = '^nvg|^nav'; - for (i in window.localStorage) { - if (i.match(query) || (!query && typeof i === 'string')) { - return storage.getDataFromLocalStorage(i.match(query).input); - } - } -} - -/** @type {Submodule} */ -export const naveggIdSubmodule = { - /** - * used to link submodule with config - * @type {string} - */ - name: MODULE_NAME, - /** - * decode the stored id value for passing to bid requests - * @function - * @param { Object | string | undefined } value - * @return { Object | string | undefined } - */ - decode(value) { - const naveggIdVal = value ? isStr(value) ? value : isPlainObject(value) ? value.id : undefined : undefined; - return naveggIdVal ? { - 'naveggId': naveggIdVal - } : undefined; - }, - /** - * performs action to obtain id and return a value in the callback's response argument - * @function - * @param {SubmoduleConfig} config - * @return {{id: string | undefined } | undefined} - */ - getId() { - let naveggIdStringFromLocalStorage = null; - if (storage.localStorageIsEnabled) { - naveggIdStringFromLocalStorage = readnaveggIdFromLocalStorage() || readnvgnavFromLocalStorage(); - } - - const naveggIdString = naveggIdStringFromLocalStorage || readnaveggIDFromCookie() || readoldnaveggIDFromCookie() || readnvgIDFromCookie() || readnavIDFromCookie(); - - if (typeof naveggIdString == 'string' && naveggIdString) { - try { - return { id: naveggIdString }; - } catch (error) { - logError(error); - } - } - return undefined; - } -}; -submodule('userId', naveggIdSubmodule); diff --git a/modules/naveggIdSystem.md b/modules/naveggIdSystem.md deleted file mode 100644 index f758fbc9d5d..00000000000 --- a/modules/naveggIdSystem.md +++ /dev/null @@ -1,22 +0,0 @@ -## Navegg User ID Submodule - -For assistance setting up your module please contact us at [prebid@navegg.com](prebid@navegg.com). - -### Prebid Params - -Individual params may be set for the IDx Submodule. -``` -pbjs.setConfig({ - userSync: { - userIds: [{ - name: 'naveggId', - }] - } -}); -``` -## Parameter Descriptions for the `userSync` Configuration Section -The below parameters apply only to the naveggID integration. - -| Param under usersync.userIds[] | Scope | Type | Description | Example | -| --- | --- | --- | --- | --- | -| name | Required | String | ID of the module - `"naveggId"` | `"naveggId"` | diff --git a/modules/nextMillenniumBidAdapter.js b/modules/nextMillenniumBidAdapter.js index 4791740bf2f..2101bb34e2b 100644 --- a/modules/nextMillenniumBidAdapter.js +++ b/modules/nextMillenniumBidAdapter.js @@ -1,10 +1,9 @@ -import { isStr, _each, getBidIdParameter } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; const BIDDER_CODE = 'nextMillennium'; const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction'; -const SYNC_ENDPOINT = 'https://statics.nextmillmedia.com/load-cookie.html?v=4'; const TIME_TO_LIVE = 360; export const spec = { @@ -13,48 +12,32 @@ export const spec = { isBidRequestValid: function(bid) { return !!( - bid.params.placement_id && isStr(bid.params.placement_id) + bid.params.placement_id && utils.isStr(bid.params.placement_id) ); }, buildRequests: function(validBidRequests, bidderRequest) { const requests = []; - window.nmmRefreshCounts = window.nmmRefreshCounts || {}; - _each(validBidRequests, function(bid) { - window.nmmRefreshCounts[bid.adUnitCode] = window.nmmRefreshCounts[bid.adUnitCode] || 0; + utils._each(validBidRequests, function(bid) { const postBody = { 'id': bid.auctionId, 'ext': { 'prebid': { 'storedrequest': { - 'id': getBidIdParameter('placement_id', bid.params) + 'id': utils.getBidIdParameter('placement_id', bid.params) } - }, - 'nextMillennium': { - 'refresh_count': window.nmmRefreshCounts[bid.adUnitCode]++, } } } - const gdprConsent = bidderRequest && bidderRequest.gdprConsent; - const uspConsent = bidderRequest && bidderRequest.uspConsent - if (gdprConsent || uspConsent) { - postBody.regs = { ext: {} } - - if (uspConsent) { - postBody.regs.ext.us_privacy = uspConsent; + if (gdprConsent) { + if (typeof gdprConsent.gdprApplies !== 'undefined') { + postBody.gdprApplies = !!gdprConsent.gdprApplies; } - if (gdprConsent) { - if (typeof gdprConsent.gdprApplies !== 'undefined') { - postBody.regs.ext.gdpr = gdprConsent.gdprApplies ? 1 : 0; - } - if (typeof gdprConsent.consentString !== 'undefined') { - postBody.user = { - ext: { consent: gdprConsent.consentString } - } - } + if (typeof gdprConsent.consentString !== 'undefined') { + postBody.consentString = gdprConsent.consentString; } } @@ -77,8 +60,8 @@ export const spec = { const response = serverResponse.body; const bidResponses = []; - _each(response.seatbid, (resp) => { - _each(resp.bid, (bid) => { + utils._each(response.seatbid, (resp) => { + utils._each(resp.bid, (bid) => { bidResponses.push({ requestId: bidRequest.bidId, cpm: bid.price, @@ -97,31 +80,7 @@ export const spec = { }); return bidResponses; - }, - - getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { - if (!syncOptions.iframeEnabled) { - return - } - - let syncurl = gdprConsent && gdprConsent.gdprApplies ? `${SYNC_ENDPOINT}&gdpr=1&gdpr_consent=${gdprConsent.consentString}` : SYNC_ENDPOINT - - let bidders = [] - if (responses) { - _each(responses, (response) => { - _each(Object.keys(response.body.ext.responsetimemillis), b => bidders.push(b)) - }) - } - - if (bidders.length) { - syncurl += `&bidders=${bidders.join(',')}` - } - - return [{ - type: 'iframe', - url: syncurl - }]; - }, + } }; registerBidder(spec); diff --git a/modules/nextrollBidAdapter.js b/modules/nextrollBidAdapter.js deleted file mode 100644 index b5af7ec1486..00000000000 --- a/modules/nextrollBidAdapter.js +++ /dev/null @@ -1,375 +0,0 @@ -import { - deepAccess, - parseUrl, - isNumber, - getBidIdParameter, - isPlainObject, - isFn, - isStr, - replaceAuctionPrice, - isArray, -} from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER, NATIVE } from '../src/mediaTypes.js'; - -import find from 'core-js-pure/features/array/find.js'; - -const BIDDER_CODE = 'nextroll'; -const BIDDER_ENDPOINT = 'https://d.adroll.com/bid/prebid/'; -const ADAPTER_VERSION = 5; - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, NATIVE], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function (bidRequest) { - return bidRequest !== undefined && !!bidRequest.params && !!bidRequest.bidId; - }, - - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function (validBidRequests, bidderRequest) { - let topLocation = parseUrl(deepAccess(bidderRequest, 'refererInfo.referer')); - - return validBidRequests.map((bidRequest) => { - return { - method: 'POST', - options: { - withCredentials: true, - }, - url: BIDDER_ENDPOINT, - data: { - id: bidRequest.bidId, - imp: { - id: bidRequest.bidId, - bidfloor: _getFloor(bidRequest), - banner: _getBanner(bidRequest), - native: _getNative(deepAccess(bidRequest, 'mediaTypes.native')), - ext: { - zone: { - id: getBidIdParameter('zoneId', bidRequest.params) - }, - nextroll: { - adapter_version: ADAPTER_VERSION - } - } - }, - - user: _getUser(validBidRequests), - site: _getSite(bidRequest, topLocation), - seller: _getSeller(bidRequest), - device: _getDevice(bidRequest), - regs: _getRegs(bidderRequest) - } - }; - }); - }, - - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function (serverResponse, bidRequest) { - if (!serverResponse.body) { - return []; - } else { - let response = serverResponse.body - let bids = response.seatbid.reduce((acc, seatbid) => acc.concat(seatbid.bid), []); - return bids.map((bid) => _buildResponse(response, bid)); - } - } -} - -function _getBanner(bidRequest) { - let sizes = _getSizes(bidRequest); - if (sizes === undefined) return undefined; - return {format: sizes}; -} - -function _getNative(mediaTypeNative) { - if (mediaTypeNative === undefined) return undefined; - let assets = _getNativeAssets(mediaTypeNative); - if (assets === undefined || assets.length == 0) return undefined; - return { - request: { - native: { - assets: assets - } - } - }; -} - -/* - id: Unique numeric id for the asset - kind: OpenRTB kind of asset. Supported: title, img and data. - key: Name of property that comes in the mediaType.native object. - type: OpenRTB type for that spefic kind of asset. - required: Overrides the asset required field configured, only overrides when is true. -*/ -const NATIVE_ASSET_MAP = [ - {id: 1, kind: 'title', key: 'title', required: true}, - {id: 2, kind: 'img', key: 'image', type: 3, required: true}, - {id: 3, kind: 'img', key: 'icon', type: 1}, - {id: 4, kind: 'img', key: 'logo', type: 2}, - {id: 5, kind: 'data', key: 'sponsoredBy', type: 1}, - {id: 6, kind: 'data', key: 'body', type: 2} -]; - -const ASSET_KIND_MAP = { - title: _getTitleAsset, - img: _getImageAsset, - data: _getDataAsset, -}; - -function _getAsset(mediaTypeNative, assetMap) { - const asset = mediaTypeNative[assetMap.key]; - if (asset === undefined) return undefined; - const assetFunc = ASSET_KIND_MAP[assetMap.kind]; - return { - id: assetMap.id, - required: (assetMap.required || !!asset.required) ? 1 : 0, - [assetMap.kind]: assetFunc(asset, assetMap) - }; -} - -function _getTitleAsset(title, _assetMap) { - return {len: title.len || 0}; -} - -function _getMinAspectRatio(aspectRatio, property) { - if (!isPlainObject(aspectRatio)) return 1; - - const ratio = aspectRatio['ratio_' + property]; - const min = aspectRatio['min_' + property]; - - if (isNumber(ratio)) return ratio; - if (isNumber(min)) return min; - - return 1; -} - -function _getImageAsset(image, assetMap) { - const sizes = image.sizes; - const aspectRatio = image.aspect_ratios ? image.aspect_ratios[0] : undefined; - - return { - type: assetMap.type, - w: (sizes ? sizes[0] : undefined), - h: (sizes ? sizes[1] : undefined), - wmin: _getMinAspectRatio(aspectRatio, 'width'), - hmin: _getMinAspectRatio(aspectRatio, 'height'), - }; -} - -function _getDataAsset(data, assetMap) { - return { - type: assetMap.type, - len: data.len || 0 - }; -} - -function _getNativeAssets(mediaTypeNative) { - return NATIVE_ASSET_MAP - .map(assetMap => _getAsset(mediaTypeNative, assetMap)) - .filter(asset => asset !== undefined); -} - -function _getUser(requests) { - const id = deepAccess(requests, '0.userId.nextrollId'); - if (id === undefined) { - return; - } - - return { - ext: { - eid: [{ - 'source': 'nextroll', - id - }] - } - }; -} - -function _getFloor(bidRequest) { - if (!isFn(bidRequest.getFloor)) { - return (bidRequest.params.bidfloor) ? bidRequest.params.bidfloor : null; - } - - let floor = bidRequest.getFloor({ - currency: 'USD', - mediaType: '*', - size: '*' - }); - - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { - return floor.floor; - } - return null; -} - -function _buildResponse(bidResponse, bid) { - let response = { - requestId: bidResponse.id, - cpm: bid.price, - width: bid.w, - height: bid.h, - creativeId: bid.crid, - dealId: bidResponse.dealId, - currency: 'USD', - netRevenue: true, - ttl: 300, - meta: { - advertiserDomains: bidResponse.adomain || [] - } - }; - if (isStr(bid.adm)) { - response.mediaType = BANNER; - response.ad = replaceAuctionPrice(bid.adm, bid.price); - } else { - response.mediaType = NATIVE; - response.native = _getNativeResponse(bid.adm, bid.price); - } - return response; -} - -const privacyLink = 'https://info.evidon.com/pub_info/573'; -const privacyIcon = 'https://c.betrad.com/pub/icon1.png'; - -function _getNativeResponse(adm, price) { - let baseResponse = { - clickTrackers: (adm.link && adm.link.clicktrackers) || [], - jstracker: adm.jstracker || [], - clickUrl: replaceAuctionPrice(adm.link.url, price), - impressionTrackers: adm.imptrackers.map(impTracker => replaceAuctionPrice(impTracker, price)), - privacyLink: privacyLink, - privacyIcon: privacyIcon - }; - return adm.assets.reduce((accResponse, asset) => { - const assetMaps = NATIVE_ASSET_MAP.filter(assetMap => assetMap.id === asset.id && asset[assetMap.kind] !== undefined); - if (assetMaps.length === 0) return accResponse; - const assetMap = assetMaps[0]; - accResponse[assetMap.key] = _getAssetResponse(asset, assetMap); - return accResponse; - }, baseResponse); -} - -function _getAssetResponse(asset, assetMap) { - switch (assetMap.kind) { - case 'title': - return asset.title.text; - - case 'img': - return { - url: asset.img.url, - width: asset.img.w, - height: asset.img.h - }; - - case 'data': - return asset.data.value; - } -} - -function _getSite(bidRequest, topLocation) { - return { - page: topLocation.href, - domain: topLocation.hostname, - publisher: { - id: getBidIdParameter('publisherId', bidRequest.params) - } - }; -} - -function _getSeller(bidRequest) { - return { - id: getBidIdParameter('sellerId', bidRequest.params) - }; -} - -function _getSizes(bidRequest) { - if (!isArray(bidRequest.sizes)) { - return undefined; - } - return bidRequest.sizes.filter(_isValidSize).map(size => { - return { - w: size[0], - h: size[1] - } - }); -} - -function _isValidSize(size) { - const isNumber = x => typeof x === 'number'; - return (size.length === 2 && isNumber(size[0]) && isNumber(size[1])); -} - -function _getDevice(_bidRequest) { - return { - ua: navigator.userAgent, - language: navigator['language'], - os: _getOs(navigator.userAgent.toLowerCase()), - osv: _getOsVersion(navigator.userAgent) - }; -} - -function _getRegs(bidderRequest) { - if (!bidderRequest || !bidderRequest.uspConsent) { - return undefined; - } - return { - ext: { - us_privacy: bidderRequest.uspConsent - } - }; -} - -function _getOs(userAgent) { - const osTable = { - 'android': /android/i, - 'ios': /iphone|ipad/i, - 'mac': /mac/i, - 'linux': /linux/i, - 'windows': /windows/i - }; - - return find(Object.keys(osTable), os => { - if (userAgent.match(osTable[os])) { - return os; - } - }) || 'etc'; -} - -function _getOsVersion(userAgent) { - const clientStrings = [ - { s: 'Android', r: /Android/ }, - { s: 'iOS', r: /(iPhone|iPad|iPod)/ }, - { s: 'Mac OS X', r: /Mac OS X/ }, - { s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ }, - { s: 'Linux', r: /(Linux|X11)/ }, - { s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ }, - { s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ }, - { s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ }, - { s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ }, - { s: 'Windows Vista', r: /Windows NT 6.0/ }, - { s: 'Windows Server 2003', r: /Windows NT 5.2/ }, - { s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ }, - { s: 'UNIX', r: /UNIX/ }, - { s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ } - ]; - let cs = find(clientStrings, cs => cs.r.test(userAgent)); - return cs ? cs.s : 'unknown'; -} - -registerBidder(spec); diff --git a/modules/nobidBidAdapter.js b/modules/nobidBidAdapter.js index d10c1d0e430..619b46ecd1f 100644 --- a/modules/nobidBidAdapter.js +++ b/modules/nobidBidAdapter.js @@ -1,4 +1,4 @@ -import { logInfo, deepAccess, logWarn, isArray, getParameterByName } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -7,14 +7,14 @@ import { getStorageManager } from '../src/storageManager.js'; const GVLID = 816; const BIDDER_CODE = 'nobid'; const storage = getStorageManager(GVLID, BIDDER_CODE); -window.nobidVersion = '1.3.2'; +window.nobidVersion = '1.3.1'; window.nobid = window.nobid || {}; window.nobid.bidResponses = window.nobid.bidResponses || {}; window.nobid.timeoutTotal = 0; window.nobid.bidWonTotal = 0; window.nobid.refreshCount = 0; function log(msg, obj) { - logInfo('-NoBid- ' + msg, obj) + utils.logInfo('-NoBid- ' + msg, obj) } function nobidSetCookie(cname, cvalue, hours) { var d = new Date(); @@ -29,7 +29,7 @@ function nobidHasPurpose1Consent(bidderRequest) { let result = true; if (bidderRequest && bidderRequest.gdprConsent) { if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -112,11 +112,11 @@ function nobidBuildRequests(bids, bidderRequest) { var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); return `${width}x${height}`; } catch (e) { - logWarn('Could not parse screen dimensions, error details:', e); + utils.logWarn('Could not parse screen dimensions, error details:', e); } } var getEIDs = function(eids) { - if (isArray(eids) && eids.length > 0) { + if (utils.isArray(eids) && eids.length > 0) { let src = []; eids.forEach((eid) => { let ids = []; @@ -150,9 +150,8 @@ function nobidBuildRequests(bids, bidderRequest) { if (sch) state['schain'] = sch; const cop = coppa(); if (cop) state['coppa'] = cop; - const eids = getEIDs(deepAccess(bids, '0.userIdAsEids')); + const eids = getEIDs(utils.deepAccess(bids, '0.userIdAsEids')); if (eids && eids.length > 0) state['eids'] = eids; - if (config && config.getConfig('ortb2')) state['ortb2'] = config.getConfig('ortb2'); return state; } function newAdunit(adunitObject, adunits) { @@ -229,8 +228,8 @@ function nobidBuildRequests(bids, bidderRequest) { var placementId = bid.params['placementId']; var adType = 'banner'; - const videoMediaType = deepAccess(bid, 'mediaTypes.video'); - const context = deepAccess(bid, 'mediaTypes.video.context'); + const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); if (bid.mediaType === VIDEO || (videoMediaType && (context === 'instream' || context === 'outstream'))) { adType = 'video'; } @@ -364,7 +363,7 @@ export const spec = { buildRequests: function(validBidRequests, bidderRequest) { function resolveEndpoint() { var ret = 'https://ads.servenobid.com/'; - var env = (typeof getParameterByName === 'function') && (getParameterByName('nobid-env')); + var env = (typeof utils.getParameterByName === 'function') && (utils.getParameterByName('nobid-env')); if (!env) ret = 'https://ads.servenobid.com/'; else if (env == 'beta') ret = 'https://beta.servenobid.com/'; else if (env == 'dev') ret = '//localhost:8282/'; @@ -449,7 +448,7 @@ export const spec = { } return syncs; } else { - logWarn('-NoBid- Please enable iframe based user sync.', syncOptions); + utils.logWarn('-NoBid- Please enable iframe based user sync.', syncOptions); return []; } }, diff --git a/modules/novatiqIdSystem.js b/modules/novatiqIdSystem.js index 4c3324d3fc0..fbfa6ca8abc 100644 --- a/modules/novatiqIdSystem.js +++ b/modules/novatiqIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logInfo } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; @@ -47,22 +47,22 @@ export const novatiqIdSubmodule = { const configParams = config.params || {}; const srcId = this.getSrcId(configParams); - logInfo('NOVATIQ Sync request used sourceid param: ' + srcId); + utils.logInfo('NOVATIQ Sync request used sourceid param: ' + srcId); let partnerhost; partnerhost = window.location.hostname; - logInfo('NOVATIQ partner hostname: ' + partnerhost); + utils.logInfo('NOVATIQ partner hostname: ' + partnerhost); const novatiqId = snowflakeId(); const url = 'https://spadsync.com/sync?sptoken=' + novatiqId + '&sspid=' + srcId + '&ssphost=' + partnerhost; ajax(url, undefined, undefined, { method: 'GET', withCredentials: false }); - logInfo('NOVATIQ snowflake: ' + novatiqId); + utils.logInfo('NOVATIQ snowflake: ' + novatiqId); return { 'id': novatiqId } }, getSrcId(configParams) { - logInfo('NOVATIQ Configured sourceid param: ' + configParams.sourceid); + utils.logInfo('NOVATIQ Configured sourceid param: ' + configParams.sourceid); function isHex(str) { var a = parseInt(str, 16); @@ -72,13 +72,13 @@ export const novatiqIdSubmodule = { let srcId; if (typeof configParams.sourceid === 'undefined' || configParams.sourceid === null || configParams.sourceid === '') { srcId = '000'; - logInfo('NOVATIQ sourceid param set to value 000 due to undefined parameter or missing value in config section'); + utils.logInfo('NOVATIQ sourceid param set to value 000 due to undefined parameter or missing value in config section'); } else if (configParams.sourceid.length < 3 || configParams.sourceid.length > 3) { srcId = '001'; - logInfo('NOVATIQ sourceid param set to value 001 due to wrong size in config section 3 chars max e.g. 1ab'); + utils.logInfo('NOVATIQ sourceid param set to value 001 due to wrong size in config section 3 chars max e.g. 1ab'); } else if (isHex(configParams.sourceid) == false) { srcId = '002'; - logInfo('NOVATIQ sourceid param set to value 002 due to wrong format in config section expecting hex value only'); + utils.logInfo('NOVATIQ sourceid param set to value 002 due to wrong format in config section expecting hex value only'); } else { srcId = configParams.sourceid; } diff --git a/modules/oguryBidAdapter.js b/modules/oguryBidAdapter.js index c21eaffa48c..2e5342e6f9e 100644 --- a/modules/oguryBidAdapter.js +++ b/modules/oguryBidAdapter.js @@ -1,16 +1,14 @@ 'use strict'; import { BANNER } from '../src/mediaTypes.js'; -import { getAdUnitSizes, logWarn, isFn, getWindowTop, getWindowSelf } from '../src/utils.js'; +import { getAdUnitSizes, logWarn, isFn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ajax } from '../src/ajax.js' const BIDDER_CODE = 'ogury'; const DEFAULT_TIMEOUT = 1000; const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request'; -const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io'; const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io'; -const ADAPTER_VERSION = '1.2.7'; function isBidRequestValid(bid) { const adUnitSizes = getAdUnitSizes(bid); @@ -25,16 +23,10 @@ function isBidRequestValid(bid) { function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent) { if (!syncOptions.pixelEnabled) return []; - return [ - { - type: 'image', - url: `${MS_COOKIE_SYNC_DOMAIN}/v1/init-sync/bid-switch?iab_string=${(gdprConsent && gdprConsent.consentString) || ''}&source=prebid` - }, - { - type: 'image', - url: `${MS_COOKIE_SYNC_DOMAIN}/ttd/init-sync?iab_string=${(gdprConsent && gdprConsent.consentString) || ''}&source=prebid` - } - ] + return [{ + type: 'image', + url: `${MS_COOKIE_SYNC_DOMAIN}/v1/init-sync/bid-switch?iab_string=${gdprConsent.consentString}&source=prebid` + }] } function buildRequests(validBidRequests, bidderRequest) { @@ -48,19 +40,14 @@ function buildRequests(validBidRequests, bidderRequest) { }, }, site: { - domain: location.hostname, - page: location.href + domain: location.hostname }, user: { ext: { consent: '' } }, - imp: [], - ext: { - adapterversion: ADAPTER_VERSION, - prebidversion: '$prebid.version$' - } + imp: [] }; if (bidderRequest.hasOwnProperty('gdprConsent') && @@ -88,8 +75,7 @@ function buildRequests(validBidRequests, bidderRequest) { bidfloor: getFloor(bidRequest), banner: { format: sizes - }, - ext: bidRequest.params + } }); } }); @@ -128,9 +114,7 @@ function interpretResponse(openRtbBidResponse) { meta: { advertiserDomains: bid.adomain }, - nurl: bid.nurl, - adapterVersion: ADAPTER_VERSION, - prebidVersion: '$prebid.version$' + nurl: bid.nurl }; bidResponse.ad = bid.adm; @@ -153,29 +137,10 @@ function getFloor(bid) { return floorResult.currency === 'USD' ? floorResult.floor : 0; } -function getWindowContext() { - try { - return getWindowTop() - } catch (e) { - return getWindowSelf() - } -} - function onBidWon(bid) { - const w = getWindowContext() - w.OG_PREBID_BID_OBJECT = { - ...(bid && { ...bid }), - } if (bid && bid.hasOwnProperty('nurl') && bid.nurl.length > 0) ajax(bid['nurl'], null); } -function onTimeout(timeoutData) { - ajax(`${TIMEOUT_MONITORING_HOST}/bid_timeout`, null, JSON.stringify(timeoutData[0]), { - method: 'POST', - contentType: 'application/json' - }); -} - export const spec = { code: BIDDER_CODE, supportedMediaTypes: [BANNER], @@ -184,9 +149,7 @@ export const spec = { buildRequests, interpretResponse, getFloor, - onBidWon, - getWindowContext, - onTimeout + onBidWon } registerBidder(spec); diff --git a/modules/oneVideoBidAdapter.js b/modules/oneVideoBidAdapter.js index e0db143dc0f..880f4992614 100644 --- a/modules/oneVideoBidAdapter.js +++ b/modules/oneVideoBidAdapter.js @@ -1,4 +1,4 @@ -import { logError, logWarn, parseSizesInput, generateUUID, isFn, logMessage, isPlainObject, isStr, isNumber, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'oneVideo'; @@ -28,7 +28,7 @@ export const spec = { } // MediaTypes Video / Banner validation if (typeof bid.mediaTypes.video === 'undefined' && typeof bid.mediaTypes.banner === 'undefined') { - logError('Failed validation: adUnit mediaTypes.video OR mediaTypes.banner not declared'); + utils.logError('Failed validation: adUnit mediaTypes.video OR mediaTypes.banner not declared'); return false; }; @@ -36,27 +36,27 @@ export const spec = { // Player size validation if (typeof bid.mediaTypes.video.playerSize === 'undefined') { if (bid.params.video && (typeof bid.params.video.playerWidth === 'undefined' || typeof bid.params.video.playerHeight === 'undefined')) { - logError('Failed validation: Player size not declared in either mediaTypes.playerSize OR bid.params.video.plauerWidth & bid.params.video.playerHeight.'); + utils.logError('Failed validation: Player size not declared in either mediaTypes.playerSize OR bid.params.video.plauerWidth & bid.params.video.playerHeight.'); return false; }; }; // Mimes validation if (typeof bid.mediaTypes.video.mimes === 'undefined') { if (!bid.params.video || typeof bid.params.video.mimes === 'undefined') { - logError('Failed validation: adUnit mediaTypes.mimes OR params.video.mimes not declared'); + utils.logError('Failed validation: adUnit mediaTypes.mimes OR params.video.mimes not declared'); return false; }; }; // Prevend DAP Outstream validation, Banner DAP validation & Multi-Format adUnit support if (bid.mediaTypes.video.context === 'outstream' && bid.params.video && bid.params.video.display === 1) { - logError('Failed validation: Dynamic Ad Placement cannot be used with context Outstream (params.video.display=1)'); + utils.logError('Failed validation: Dynamic Ad Placement cannot be used with context Outstream (params.video.display=1)'); return false; }; }; // Publisher Id (Exchange) validation if (typeof bid.params.pubId === 'undefined') { - logError('Failed validation: Adapter cannot send requests without bid.params.pubId'); + utils.logError('Failed validation: Adapter cannot send requests without bid.params.pubId'); return false; } @@ -106,7 +106,7 @@ export const spec = { response = null; } if (!response || !bid || (!bid.adm && !bid.nurl) || !bid.price) { - logWarn(`No valid bids from ${spec.code} bidder`); + utils.logWarn(`No valid bids from ${spec.code} bidder`); return []; } size = getSize(bidRequest.sizes); @@ -172,7 +172,7 @@ export const spec = { }; function getSize(sizes) { - let parsedSizes = parseSizesInput(sizes); + let parsedSizes = utils.parseSizesInput(sizes); let [ width, height ] = parsedSizes.length ? parsedSizes[0].split('x') : []; return { width: parseInt(width, 10) || undefined, @@ -194,7 +194,7 @@ function getRequestData(bid, consentData, bidRequest) { size: '*' }; let bidData = { - id: generateUUID(), + id: utils.generateUUID(), at: 2, imp: [{ id: '1', @@ -286,7 +286,7 @@ function getRequestData(bid, consentData, bidRequest) { } } - if (isFn(bid.getFloor)) { + if (utils.isFn(bid.getFloor)) { let floorData = bid.getFloor(getFloorRequestObject); bidData.imp[0].bidfloor = floorData.floor; bidData.cur = floorData.currency; @@ -344,7 +344,7 @@ function getRequestData(bid, consentData, bidRequest) { } } if (bid.params.video.e2etest) { - logMessage('E2E test mode enabled: \n The following parameters are being overridden by e2etest mode:\n* bidfloor:null\n* width:300\n* height:250\n* mimes: video/mp4, application/javascript\n* api:2\n* site.page/ref: verizonmedia.com\n* tmax:1000'); + utils.logMessage('E2E test mode enabled: \n The following parameters are being overridden by e2etest mode:\n* bidfloor:null\n* width:300\n* height:250\n* mimes: video/mp4, application/javascript\n* api:2\n* site.page/ref: verizonmedia.com\n* tmax:1000'); bidData.imp[0].bidfloor = null; bidData.imp[0].video.w = 300; bidData.imp[0].video.h = 250; @@ -354,15 +354,15 @@ function getRequestData(bid, consentData, bidRequest) { bidData.site.ref = 'https://verizonmedia.com'; bidData.tmax = 1000; } - if (bid.params.video.custom && isPlainObject(bid.params.video.custom)) { + if (bid.params.video.custom && utils.isPlainObject(bid.params.video.custom)) { bidData.imp[0].ext.custom = {}; for (const key in bid.params.video.custom) { - if (isStr(bid.params.video.custom[key]) || isNumber(bid.params.video.custom[key])) { + if (utils.isStr(bid.params.video.custom[key]) || utils.isNumber(bid.params.video.custom[key])) { bidData.imp[0].ext.custom[key] = bid.params.video.custom[key]; } } } - if (bid.params.video.content && isPlainObject(bid.params.video.content)) { + if (bid.params.video.content && utils.isPlainObject(bid.params.video.content)) { bidData.site.content = {}; const contentStringKeys = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language']; const contentNumberkeys = ['episode', 'prodq', 'context', 'livestream', 'len']; @@ -370,14 +370,14 @@ function getRequestData(bid, consentData, bidRequest) { const contentObjectKeys = ['ext']; for (const contentKey in bid.params.video.content) { if ( - (contentStringKeys.indexOf(contentKey) > -1 && isStr(bid.params.video.content[contentKey])) || - (contentNumberkeys.indexOf(contentKey) > -1 && isNumber(bid.params.video.content[contentKey])) || - (contentObjectKeys.indexOf(contentKey) > -1 && isPlainObject(bid.params.video.content[contentKey])) || - (contentArrayKeys.indexOf(contentKey) > -1 && isArray(bid.params.video.content[contentKey]) && - bid.params.video.content[contentKey].every(catStr => isStr(catStr)))) { + (contentStringKeys.indexOf(contentKey) > -1 && utils.isStr(bid.params.video.content[contentKey])) || + (contentNumberkeys.indexOf(contentKey) > -1 && utils.isNumber(bid.params.video.content[contentKey])) || + (contentObjectKeys.indexOf(contentKey) > -1 && utils.isPlainObject(bid.params.video.content[contentKey])) || + (contentArrayKeys.indexOf(contentKey) > -1 && utils.isArray(bid.params.video.content[contentKey]) && + bid.params.video.content[contentKey].every(catStr => utils.isStr(catStr)))) { bidData.site.content[contentKey] = bid.params.video.content[contentKey]; } else { - logMessage('oneVideo bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined'); + utils.logMessage('oneVideo bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined'); } } } diff --git a/modules/onetagBidAdapter.js b/modules/onetagBidAdapter.js index 5642dce9018..aab68176d87 100644 --- a/modules/onetagBidAdapter.js +++ b/modules/onetagBidAdapter.js @@ -7,7 +7,6 @@ import find from 'core-js-pure/features/array/find.js'; import { getStorageManager } from '../src/storageManager.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { createEidsArray } from './userId/eids.js'; -import { deepClone } from '../src/utils.js'; const ENDPOINT = 'https://onetag-sys.com/prebid-request'; const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/'; @@ -206,8 +205,8 @@ function getPageInfo() { ? topmostFrame.document.referrer : null, ancestorOrigin: - window.location.ancestorOrigins && window.location.ancestorOrigins.length > 0 - ? window.location.ancestorOrigins[window.location.ancestorOrigins.length - 1] + window.location.ancestorOrigins && window.location.ancestorOrigins[0] != null + ? window.location.ancestorOrigins[0] : null, masked: currentFrameNesting, wWidth: topmostFrame.innerWidth, @@ -240,10 +239,15 @@ function requestsToBids(bidRequests) { // Pass parameters // Context: instream - outstream - adpod videoObj['context'] = bidRequest.mediaTypes.video.context; + // MIME Video Types + videoObj['mimes'] = bidRequest.mediaTypes.video.mimes; // Sizes videoObj['playerSize'] = parseVideoSize(bidRequest); // Other params - videoObj['mediaTypeInfo'] = deepClone(bidRequest.mediaTypes.video); + videoObj['protocols'] = bidRequest.mediaTypes.video.protocols; + videoObj['maxDuration'] = bidRequest.mediaTypes.video.maxduration; + videoObj['api'] = bidRequest.mediaTypes.video.api; + videoObj['playbackmethod'] = bidRequest.mediaTypes.video.playbackmethod || []; videoObj['type'] = VIDEO; return videoObj; }); @@ -252,7 +256,6 @@ function requestsToBids(bidRequests) { setGeneralInfo.call(bannerObj, bidRequest); bannerObj['sizes'] = parseSizes(bidRequest); bannerObj['type'] = BANNER; - bannerObj['mediaTypeInfo'] = deepClone(bidRequest.mediaTypes.banner); return bannerObj; }); return videoBidRequests.concat(bannerBidRequests); @@ -347,13 +350,11 @@ function getSizes(sizes) { function getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent) { let syncs = []; let params = ''; - if (gdprConsent) { + if (gdprConsent && typeof gdprConsent.consentString === 'string') { + params += '&gdpr_consent=' + gdprConsent.consentString; if (typeof gdprConsent.gdprApplies === 'boolean') { params += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0); } - if (typeof gdprConsent.consentString === 'string') { - params += '&gdpr_consent=' + gdprConsent.consentString; - } } if (uspConsent && typeof uspConsent === 'string') { params += '&us_privacy=' + uspConsent; diff --git a/modules/onomagicBidAdapter.js b/modules/onomagicBidAdapter.js index 25b0f1a5934..548c0170c05 100644 --- a/modules/onomagicBidAdapter.js +++ b/modules/onomagicBidAdapter.js @@ -1,4 +1,4 @@ -import { getBidIdParameter, _each, isArray, getWindowTop, getUniqueIdentifierStr, parseUrl, logError, logWarn, createTrackPixelHtml, getWindowSelf, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -22,17 +22,17 @@ function buildRequests(bidReqs, bidderRequest) { referrer = bidderRequest.refererInfo.referer; } const onomagicImps = []; - const publisherId = getBidIdParameter('publisherId', bidReqs[0].params); - _each(bidReqs, function (bid) { + const publisherId = utils.getBidIdParameter('publisherId', bidReqs[0].params); + utils._each(bidReqs, function (bid) { let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes; - bidSizes = ((isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes]); - bidSizes = bidSizes.filter(size => isArray(size)); + bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]); + bidSizes = bidSizes.filter(size => utils.isArray(size)); const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})); const element = document.getElementById(bid.adUnitCode); const minSize = _getMinSize(processedSizes); const viewabilityAmount = _isViewabilityMeasurable(element) - ? _getViewability(element, getWindowTop(), minSize) + ? _getViewability(element, utils.getWindowTop(), minSize) : 'na'; const viewabilityAmountRounded = isNaN(viewabilityAmount) ? viewabilityAmount : Math.round(viewabilityAmount); @@ -53,10 +53,10 @@ function buildRequests(bidReqs, bidderRequest) { onomagicImps.push(imp); }); const onomagicBidReq = { - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: onomagicImps, site: { - domain: parseUrl(referrer).host, + domain: utils.parseUrl(referrer).host, page: referrer, publisher: { id: publisherId @@ -77,7 +77,7 @@ function buildRequests(bidReqs, bidderRequest) { options: {contentType: 'text/plain', withCredentials: false} }; } catch (e) { - logError(e, {bidReqs, bidderRequest}); + utils.logError(e, {bidReqs, bidderRequest}); } } @@ -95,7 +95,7 @@ function isBidRequestValid(bid) { function interpretResponse(serverResponse) { if (!serverResponse.body || typeof serverResponse.body != 'object') { - logWarn('Onomagic server returned empty/non-json response: ' + JSON.stringify(serverResponse.body)); + utils.logWarn('Onomagic server returned empty/non-json response: ' + JSON.stringify(serverResponse.body)); return []; } const { body: {id, seatbid} } = serverResponse; @@ -126,7 +126,7 @@ function interpretResponse(serverResponse) { } return onomagicBidResponses; } catch (e) { - logError(e, {id, seatbid}); + utils.logError(e, {id, seatbid}); } } @@ -150,7 +150,7 @@ function _getDeviceType() { function _getAdMarkup(bid) { let adm = bid.adm; if ('nurl' in bid) { - adm += createTrackPixelHtml(bid.nurl); + adm += utils.createTrackPixelHtml(bid.nurl); } return adm; } @@ -160,14 +160,14 @@ function _isViewabilityMeasurable(element) { } function _getViewability(element, topWin, { w, h } = {}) { - return getWindowTop().document.visibilityState === 'visible' + return utils.getWindowTop().document.visibilityState === 'visible' ? _getPercentInView(element, topWin, { w, h }) : 0; } function _isIframe() { try { - return getWindowSelf() !== getWindowTop(); + return utils.getWindowSelf() !== utils.getWindowTop(); } catch (e) { return true; } @@ -247,7 +247,7 @@ function _getPercentInView(element, topWin, { w, h } = {}) { } function _getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return bid.params.bidFloor ? bid.params.bidFloor : null; } @@ -256,7 +256,7 @@ function _getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/ooloAnalyticsAdapter.js b/modules/ooloAnalyticsAdapter.js index 398459d604d..7195d6ac177 100644 --- a/modules/ooloAnalyticsAdapter.js +++ b/modules/ooloAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { _each, deepClone, pick, deepSetValue, getOrigin, logError, logInfo } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js' import adapterManager from '../src/adapterManager.js' import CONSTANTS from '../src/constants.json' +import * as utils from '../src/utils.js' import { ajax } from '../src/ajax.js' import { config } from '../src/config.js' @@ -64,7 +64,7 @@ const onAuctionInit = (args) => { handleCustomFields(auction, AUCTION_INIT, args) - _each(adUnits, adUnit => { + utils._each(adUnits, adUnit => { auction.adUnits[adUnit.code] = { ...adUnit, auctionId, @@ -144,7 +144,7 @@ const onBidWon = (args) => { } const onBidTimeout = (args) => { - _each(args, bid => { + utils._each(args, bid => { const { auctionId, adUnitCode } = bid const bidId = parseBidId(bid) let bidCache = auctions[auctionId].adUnits[adUnitCode].bids[bidId] @@ -172,7 +172,7 @@ const onAuctionEnd = (args) => { } const onAdRenderFailed = (args) => { - const data = deepClone(args) + const data = utils.deepClone(args) data.timestamp = Date.now() if (data.bid) { @@ -232,7 +232,7 @@ function handleEvent(eventType, args) { } function sendEvent(eventType, args, isRaw) { - let data = deepClone(args) + let data = utils.deepClone(args) Object.assign(data, buildCommonDataProperties(), { eventType @@ -268,7 +268,7 @@ function checkEventsQueue() { } function buildAuctionData(auction) { - const auctionData = deepClone(auction) + const auctionData = utils.deepClone(auction) const keysToRemove = ['adUnitCodes', 'auctionStatus', 'bidderRequests', 'bidsReceived', 'noBids', 'winningBids', 'timestamp', 'config'] keysToRemove.forEach(key => { @@ -367,12 +367,12 @@ function handleCustomFields(obj, eventType, args) { const { pickFields, omitFields } = initOptions.serverConfig.events[eventType] if (pickFields && obj && args) { - Object.assign(obj, pick(args, pickFields)) + Object.assign(obj, utils.pick(args, pickFields)) } if (omitFields && obj && args) { omitFields.forEach(field => { - deepSetValue(obj, field, undefined) + utils.deepSetValue(obj, field, undefined) }) } } catch (e) { } @@ -382,7 +382,7 @@ function handleCustomRawFields(obj, omitRawFields) { try { if (omitRawFields && obj) { omitRawFields.forEach(field => { - deepSetValue(obj, field, undefined) + utils.deepSetValue(obj, field, undefined) }) } } catch (e) { } @@ -419,7 +419,7 @@ function sendPage() { screenHeight: window.screen.height, url: window.location.href, protocol: window.location.protocol, - origin: getOrigin(), + origin: utils.getOrigin(), referrer: getTopWindowReferrer(), pbVersion: prebidVersion, } @@ -507,7 +507,7 @@ ooloAdapter.enableAnalytics = function (config) { initOptions = config ? config.options : {} if (!initOptions.pid) { - logError(buildLogMessage('enableAnalytics missing config object with "pid"')) + utils.logError(buildLogMessage('enableAnalytics missing config object with "pid"')) return } @@ -520,9 +520,9 @@ ooloAdapter.enableAnalytics = function (config) { window.addEventListener('load', sendPage) } - logInfo(buildLogMessage('enabled analytics adapter'), config) + utils.logInfo(buildLogMessage('enabled analytics adapter'), config) ooloAdapter.enableAnalytics = function () { - logInfo(buildLogMessage('Analytics adapter already enabled..')) + utils.logInfo(buildLogMessage('Analytics adapter already enabled..')) } } diff --git a/modules/openwebBidAdapter.js b/modules/openwebBidAdapter.js index 9476d2d2914..ef776ea81f5 100644 --- a/modules/openwebBidAdapter.js +++ b/modules/openwebBidAdapter.js @@ -1,4 +1,4 @@ -import { isNumber, deepAccess, isArray, flatten, convertTypes, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; @@ -14,7 +14,7 @@ export const spec = { gvlid: 280, supportedMediaTypes: [VIDEO, BANNER, ADPOD], isBidRequestValid: function (bid) { - return isNumber(deepAccess(bid, 'params.aid')); + return utils.isNumber(utils.deepAccess(bid, 'params.aid')); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -43,9 +43,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - isArray(serverResponses) && serverResponses.forEach((response) => { + utils.isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (isArray(response.body)) { + if (utils.isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -82,26 +82,26 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!isArray(serverResponse)) { + if (!utils.isArray(serverResponse)) { return parseRTBResponse(serverResponse, adapterRequest); } serverResponse.forEach(serverBidResponse => { - bids = flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); + bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, adapterRequest)); }); return bids; }, transformBidParams(params) { - return convertTypes({ + return utils.convertTypes({ 'aid': 'number', }, params); } }; function parseRTBResponse(serverResponse, adapterRequest) { - const isEmptyResponse = !serverResponse || !isArray(serverResponse.bids); + const isEmptyResponse = !serverResponse || !utils.isArray(serverResponse.bids); const bids = []; if (isEmptyResponse) { @@ -126,26 +126,26 @@ function parseRTBResponse(serverResponse, adapterRequest) { function bidToTag(bidRequests, adapterRequest) { // start publisher env const tag = { - Domain: deepAccess(adapterRequest, 'refererInfo.referer') + Domain: utils.deepAccess(adapterRequest, 'refererInfo.referer') }; if (config.getConfig('coppa') === true) { tag.Coppa = 1; } - if (deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { + if (utils.deepAccess(adapterRequest, 'gdprConsent.gdprApplies')) { tag.GDPR = 1; - tag.GDPRConsent = deepAccess(adapterRequest, 'gdprConsent.consentString'); + tag.GDPRConsent = utils.deepAccess(adapterRequest, 'gdprConsent.consentString'); } - if (deepAccess(adapterRequest, 'uspConsent')) { - tag.USP = deepAccess(adapterRequest, 'uspConsent'); + if (utils.deepAccess(adapterRequest, 'uspConsent')) { + tag.USP = utils.deepAccess(adapterRequest, 'uspConsent'); } - if (deepAccess(bidRequests[0], 'schain')) { - tag.Schain = deepAccess(bidRequests[0], 'schain'); + if (utils.deepAccess(bidRequests[0], 'schain')) { + tag.Schain = utils.deepAccess(bidRequests[0], 'schain'); } - if (deepAccess(bidRequests[0], 'userId')) { - tag.UserIds = deepAccess(bidRequests[0], 'userId'); + if (utils.deepAccess(bidRequests[0], 'userId')) { + tag.UserIds = utils.deepAccess(bidRequests[0], 'userId'); } - if (deepAccess(bidRequests[0], 'userIdAsEids')) { - tag.UserEids = deepAccess(bidRequests[0], 'userIdAsEids'); + if (utils.deepAccess(bidRequests[0], 'userIdAsEids')) { + tag.UserEids = utils.deepAccess(bidRequests[0], 'userIdAsEids'); } // end publisher env const bids = [] @@ -164,13 +164,13 @@ function bidToTag(bidRequests, adapterRequest) { * @returns {object} */ function prepareBidRequests(bidReq) { - const mediaType = deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; - const sizes = mediaType === VIDEO ? deepAccess(bidReq, 'mediaTypes.video.playerSize') : deepAccess(bidReq, 'mediaTypes.banner.sizes'); + const mediaType = utils.deepAccess(bidReq, 'mediaTypes.video') ? VIDEO : DISPLAY; + const sizes = mediaType === VIDEO ? utils.deepAccess(bidReq, 'mediaTypes.video.playerSize') : utils.deepAccess(bidReq, 'mediaTypes.banner.sizes'); const bidReqParams = { 'CallbackId': bidReq.bidId, 'Aid': bidReq.params.aid, 'AdType': mediaType, - 'Sizes': parseSizesInput(sizes).join(',') + 'Sizes': utils.parseSizesInput(sizes).join(',') }; bidReqParams.PlacementId = bidReq.adUnitCode; @@ -178,9 +178,9 @@ function prepareBidRequests(bidReq) { bidReqParams.AdmType = 'iframe'; } if (mediaType === VIDEO) { - const context = deepAccess(bidReq, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidReq, 'mediaTypes.video.context'); if (context === ADPOD) { - bidReqParams.Adpod = deepAccess(bidReq, 'mediaTypes.video'); + bidReqParams.Adpod = utils.deepAccess(bidReq, 'mediaTypes.video'); } } return bidReqParams; @@ -192,7 +192,7 @@ function prepareBidRequests(bidReq) { * @returns {object} */ function getMediaType(bidderRequest) { - return deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; + return utils.deepAccess(bidderRequest, 'mediaTypes.video') ? VIDEO : BANNER; } /** @@ -203,7 +203,7 @@ function getMediaType(bidderRequest) { */ function createBid(bidResponse, bidRequest) { const mediaType = getMediaType(bidRequest) - const context = deepAccess(bidRequest, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); const bid = { requestId: bidResponse.requestId, creativeId: bidResponse.cmpId, diff --git a/modules/openxAnalyticsAdapter.js b/modules/openxAnalyticsAdapter.js index f67f8bd0c75..0c01d4b461e 100644 --- a/modules/openxAnalyticsAdapter.js +++ b/modules/openxAnalyticsAdapter.js @@ -1,10 +1,10 @@ -import { logInfo, logError, getWindowLocation, parseQS, logMessage, _each, deepAccess, logWarn, _map, flatten, uniques, isEmpty, parseSizesInput } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; import { ajax } from '../src/ajax.js'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; +const utils = require('../src/utils.js'); export const AUCTION_STATES = { INIT: 'initialized', // auction has initialized @@ -92,7 +92,7 @@ openxAdapter.enableAnalytics = function(adapterConfig = {options: {}}) { // campaign properties defined by config will override utm query parameters analyticsConfig.campaign = {...buildCampaignFromUtmCodes(), ...analyticsConfig.campaign}; - logInfo('OpenX Analytics enabled with config', analyticsConfig); + utils.logInfo('OpenX Analytics enabled with config', analyticsConfig); // override track method with v2 handlers openxAdapter.track = prebidAnalyticsEventHandler; @@ -103,7 +103,7 @@ openxAdapter.enableAnalytics = function(adapterConfig = {options: {}}) { if (pubads.addEventListener) { pubads.addEventListener(SLOT_LOADED, args => { openxAdapter.track({eventType: SLOT_LOADED, args}); - logInfo('OX: SlotOnLoad event triggered'); + utils.logInfo('OX: SlotOnLoad event triggered'); }); } }); @@ -160,9 +160,9 @@ function isValidConfig({options: analyticsOptions}) { let [property, type, required] = failedValidation; if (required) { - logError(`OpenXAnalyticsAdapter: Expected '${property}' to exist and of type '${type}'`); + utils.logError(`OpenXAnalyticsAdapter: Expected '${property}' to exist and of type '${type}'`); } else { - logError(`OpenXAnalyticsAdapter: Expected '${property}' to be type '${type}'`); + utils.logError(`OpenXAnalyticsAdapter: Expected '${property}' to be type '${type}'`); } } @@ -170,8 +170,8 @@ function isValidConfig({options: analyticsOptions}) { } function buildCampaignFromUtmCodes() { - const location = getWindowLocation(); - const queryParams = parseQS(location && location.search); + const location = utils.getWindowLocation(); + const queryParams = utils.parseQS(location && location.search); let campaign = {}; UTM_TAGS.forEach(function(utmKey) { @@ -231,7 +231,7 @@ function detectBrowser() { } function prebidAnalyticsEventHandler({eventType, args}) { - logMessage(eventType, Object.assign({}, args)); + utils.logMessage(eventType, Object.assign({}, args)); switch (eventType) { case AUCTION_INIT: onAuctionInit(args); @@ -401,8 +401,8 @@ function onBidResponse(bidResponse) { } function onBidTimeout(args) { - _each(args, ({auctionId, adUnitCode, bidId: requestId}) => { - let timedOutRequest = deepAccess(auctionMap, + utils._each(args, ({auctionId, adUnitCode, bidId: requestId}) => { + let timedOutRequest = utils.deepAccess(auctionMap, `${auctionId}.adUnitCodeToAdUnitMap.${adUnitCode}.bidRequestsMap.${requestId}`); if (timedOutRequest) { @@ -433,7 +433,7 @@ function onAuctionEnd(endedAuction) { */ function onBidWon(bidResponse) { const { auctionId, adUnitCode, requestId, adId } = bidResponse; - let winningBid = deepAccess(auctionMap, + let winningBid = utils.deepAccess(auctionMap, `${auctionId}.adUnitCodeToAdUnitMap.${adUnitCode}.bidRequestsMap.${requestId}.bids.${adId}`); if (winningBid) { @@ -444,10 +444,10 @@ function onBidWon(bidResponse) { const bidder = auction.adUnitCodeToAdUnitMap[adUnitCode].bidRequestsMap[requestId].bidder; ajax(`${endpoint}?t=win&b=${adId}&a=${analyticsConfig.orgId}&bidder=${bidder}&ts=${auction.startTime}`, () => { - logInfo(`Openx Analytics - Sending complete impression event for ${adId} at ${Date.now()}`) + utils.logInfo(`Openx Analytics - Sending complete impression event for ${adId} at ${Date.now()}`) }); } else { - logInfo(`Openx Analytics - impression event for ${adId} will be sent with auction data`) + utils.logInfo(`Openx Analytics - impression event for ${adId} will be sent with auction data`) } } } @@ -522,7 +522,7 @@ function isAtf(elementId, scrollLeft = 0, scrollTop = 0) { } } } else { - logWarn('OX: DOM element not for id ' + elementId); + utils.logWarn('OX: DOM element not for id ' + elementId); } return isAtf; } @@ -552,7 +552,7 @@ function delayedSend(auction) { let payload = JSON.stringify([buildAuctionPayload(auction)]); ajax(analyticsConfig.endpoint || ENDPOINT, () => { - logInfo(`OpenX Analytics - Sending complete auction at ${Date.now()}`); + utils.logInfo(`OpenX Analytics - Sending complete auction at ${Date.now()}`); }, payload, { contentType: 'application/json' }); }, delayTime); } @@ -579,15 +579,15 @@ function getPathToBidResponseByBidId(bidId) { return []; } - _each(auctionMap, currentAuction => { + utils._each(auctionMap, currentAuction => { // skip completed auctions if (currentAuction.state === AUCTION_STATES.COMPLETED) { return; } - _each(currentAuction.adUnitCodeToAdUnitMap, (currentAdunit) => { - _each(currentAdunit.bidRequestsMap, currentBiddRequest => { - _each(currentBiddRequest.bids, (currentBidResponse, bidResponseId) => { + utils._each(currentAuction.adUnitCodeToAdUnitMap, (currentAdunit) => { + utils._each(currentAdunit.bidRequestsMap, currentBiddRequest => { + utils._each(currentBiddRequest.bids, (currentBidResponse, bidResponseId) => { if (bidId === bidResponseId) { auction = currentAuction; adUnit = currentAdunit; @@ -604,12 +604,12 @@ function getAuctionByGoogleTagSLot(slot) { let slotAdunitCodes = [slot.getSlotElementId(), slot.getAdUnitPath()]; let slotAuction; - _each(auctionMap, auction => { + utils._each(auctionMap, auction => { if (auction.state === AUCTION_STATES.COMPLETED) { return; } - _each(auction.adUnitCodeToAdUnitMap, (bidderRequestIdMap, adUnitCode) => { + utils._each(auction.adUnitCodeToAdUnitMap, (bidderRequestIdMap, adUnitCode) => { if (includes(slotAdunitCodes, adUnitCode)) { slotAuction = auction; } @@ -649,7 +649,7 @@ function buildAuctionPayload(auction) { }; function buildAdUnitsPayload(adUnitCodeToAdUnitMap) { - return _map(adUnitCodeToAdUnitMap, (adUnit) => { + return utils._map(adUnitCodeToAdUnitMap, (adUnit) => { let {code, adPosition} = adUnit; return { @@ -659,7 +659,7 @@ function buildAuctionPayload(auction) { }; function buildBidRequestPayload(bidRequestsMap) { - return _map(bidRequestsMap, (bidRequest) => { + return utils._map(bidRequestsMap, (bidRequest) => { let {bidder, source, bids, mediaTypes, timeLimit, timedOut} = bidRequest; return { bidder, @@ -669,7 +669,7 @@ function buildAuctionPayload(auction) { availableMediaTypes: getMediaTypes(mediaTypes), timeLimit, timedOut, - bidResponses: _map(bidRequest.bids, (bidderBidResponse) => { + bidResponses: utils._map(bidRequest.bids, (bidderBidResponse) => { let { adId, cpm, @@ -716,11 +716,11 @@ function buildAuctionPayload(auction) { } function buildUserIdProviders(userIds) { - return _map(userIds, (userId) => { - return _map(userId, (id, module) => { + return utils._map(userIds, (userId) => { + return utils._map(userId, (id, module) => { return hasUserData(module, id) ? module : false }).filter(module => module); - }).reduce(flatten, []).filter(uniques).sort(); + }).reduce(utils.flatten, []).filter(utils.uniques).sort(); } function hasUserData(module, idOrIdObject) { @@ -728,7 +728,7 @@ function buildAuctionPayload(auction) { switch (module) { case 'digitrustid': - normalizedId = deepAccess(idOrIdObject, 'data.id'); + normalizedId = utils.deepAccess(idOrIdObject, 'data.id'); break; case 'lipb': normalizedId = idOrIdObject.lipbid; @@ -737,17 +737,17 @@ function buildAuctionPayload(auction) { normalizedId = idOrIdObject; } - return !isEmpty(normalizedId); + return !utils.isEmpty(normalizedId); } function getMediaTypeSizes(mediaTypes) { - return _map(mediaTypes, (mediaTypeConfig, mediaType) => { - return parseSizesInput(mediaTypeConfig.sizes) + return utils._map(mediaTypes, (mediaTypeConfig, mediaType) => { + return utils.parseSizesInput(mediaTypeConfig.sizes) .map(size => `${mediaType}_${size}`); - }).reduce(flatten, []); + }).reduce(utils.flatten, []); } function getMediaTypes(mediaTypes) { - return _map(mediaTypes, (mediaTypeConfig, mediaType) => mediaType); + return utils._map(mediaTypes, (mediaTypeConfig, mediaType) => mediaType); } } diff --git a/modules/openxBidAdapter.js b/modules/openxBidAdapter.js index 60b441e2c10..c3f3a7ddf42 100644 --- a/modules/openxBidAdapter.js +++ b/modules/openxBidAdapter.js @@ -1,6 +1,6 @@ -import { deepAccess, convertTypes, isArray, inIframe, _map, deepSetValue, _each, parseSizesInput, parseUrl } from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import includes from 'core-js-pure/features/array/includes.js' @@ -42,12 +42,7 @@ export const USER_ID_CODE_TO_QUERY_ARG = { novatiq: 'novatiqid', // Novatiq ID mwOpenLinkId: 'mwopenlinkid', // MediaWallah OpenLink ID dapId: 'dapid', // Akamai DAP ID - amxId: 'amxid', // AMX RTB ID - kpuid: 'kpuid', // Kinesso ID - publinkId: 'publinkid', // Publisher Link - naveggId: 'naveggid', // Navegg ID - imuid: 'imuid', // IM-UID by Intimate Merger - adtelligentId: 'adtelligentid' // Adtelligent ID + amxId: 'amxid' // AMX RTB ID }; export const spec = { @@ -56,8 +51,8 @@ export const spec = { supportedMediaTypes: SUPPORTED_AD_TYPES, isBidRequestValid: function (bidRequest) { const hasDelDomainOrPlatform = bidRequest.params.delDomain || bidRequest.params.platform; - if (deepAccess(bidRequest, 'mediaTypes.banner') && hasDelDomainOrPlatform) { - return !!bidRequest.params.unit || deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0; + if (utils.deepAccess(bidRequest, 'mediaTypes.banner') && hasDelDomainOrPlatform) { + return !!bidRequest.params.unit || utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0; } return !!(bidRequest.params.unit && hasDelDomainOrPlatform); @@ -92,8 +87,8 @@ export const spec = { getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { if (syncOptions.iframeEnabled || syncOptions.pixelEnabled) { let pixelType = syncOptions.iframeEnabled ? 'iframe' : 'image'; - let url = deepAccess(responses, '0.body.ads.pixels') || - deepAccess(responses, '0.body.pixels') || + let url = utils.deepAccess(responses, '0.body.ads.pixels') || + utils.deepAccess(responses, '0.body.pixels') || generateDefaultSyncUrl(gdprConsent, uspConsent); return [{ @@ -103,7 +98,7 @@ export const spec = { } }, transformBidParams: function(params, isOpenRtb) { - return convertTypes({ + return utils.convertTypes({ 'unit': 'string', 'customFloor': 'number' }, params); @@ -128,7 +123,7 @@ function generateDefaultSyncUrl(gdprConsent, uspConsent) { } function isVideoRequest(bidRequest) { - return (deepAccess(bidRequest, 'mediaTypes.video') && !deepAccess(bidRequest, 'mediaTypes.banner')) || bidRequest.mediaType === VIDEO; + return (utils.deepAccess(bidRequest, 'mediaTypes.video') && !utils.deepAccess(bidRequest, 'mediaTypes.banner')) || bidRequest.mediaType === VIDEO; } function createBannerBidResponses(oxResponseObj, {bids, startTime}) { @@ -220,7 +215,7 @@ function getViewportDimensions(isIfr) { function formatCustomParms(customKey, customParams) { let value = customParams[customKey]; - if (isArray(value)) { + if (utils.isArray(value)) { // if value is an array, join them with commas first value = value.join(','); } @@ -245,7 +240,7 @@ function getMediaTypeFromRequest(serverRequest) { } function buildCommonQueryParamsFromBids(bids, bidderRequest) { - const isInIframe = inIframe(); + const isInIframe = utils.inIframe(); let defaultParams; defaultParams = { @@ -257,18 +252,31 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) { tws: getViewportDimensions(isInIframe), be: 1, bc: bids[0].params.bc || `${BIDDER_CONFIG}_${BIDDER_VERSION}`, - dddid: _map(bids, bid => bid.transactionId).join(','), + dddid: utils._map(bids, bid => bid.transactionId).join(','), nocache: new Date().getTime() }; - const userDataSegments = buildFpdQueryParams('ortb2.user.data'); - if (userDataSegments.length > 0) { - defaultParams.sm = userDataSegments; - } - - const siteContentDataSegments = buildFpdQueryParams('ortb2.site.content.data'); - if (siteContentDataSegments.length > 0) { - defaultParams.scsm = siteContentDataSegments; + const firstPartyData = config.getConfig('ortb2.user.data') + if (Array.isArray(firstPartyData) && firstPartyData.length > 0) { + // extract and merge valid segments by provider/taxonomy + const fpd = firstPartyData + .filter( + data => (Array.isArray(data.segment) && + data.segment.length > 0 && + data.name !== undefined && + data.name.length > 0) + ) + .reduce((acc, data) => { + const name = typeof data.ext === 'object' && data.ext.segtax ? `${data.name}/${data.ext.segtax}` : data.name; + acc[name] = (acc[name] || []).concat(data.segment.map(seg => seg.id)); + return acc; + }, {}) + const sm = Object.keys(fpd) + .map((name, _) => name + ':' + fpd[name].join('|')) + .join(',') + if (sm.length > 0) { + defaultParams.sm = encodeURIComponent(sm); + } } if (bids[0].params.platform) { @@ -296,8 +304,8 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) { } // normalize publisher common id - if (deepAccess(bids[0], 'crumbs.pubcid')) { - deepSetValue(bids[0], 'userId.pubcid', deepAccess(bids[0], 'crumbs.pubcid')); + if (utils.deepAccess(bids[0], 'crumbs.pubcid')) { + utils.deepSetValue(bids[0], 'userId.pubcid', utils.deepAccess(bids[0], 'crumbs.pubcid')); } defaultParams = appendUserIdsToQueryParams(defaultParams, bids[0].userId); @@ -309,37 +317,12 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) { return defaultParams; } -function buildFpdQueryParams(fpdPath) { - const firstPartyData = config.getConfig(fpdPath); - if (!Array.isArray(firstPartyData) || !firstPartyData.length) { - return ''; - } - const fpd = firstPartyData - .filter( - data => (Array.isArray(data.segment) && - data.segment.length > 0 && - data.name !== undefined && - data.name.length > 0) - ) - .reduce((acc, data) => { - const name = typeof data.ext === 'object' && data.ext.segtax ? `${data.name}/${data.ext.segtax}` : data.name; - acc[name] = (acc[name] || []).concat(data.segment.map(seg => seg.id)); - return acc; - }, {}) - return Object.keys(fpd) - .map((name, _) => name + ':' + fpd[name].join('|')) - .join(',') -} - function appendUserIdsToQueryParams(queryParams, userIds) { - _each(userIds, (userIdObjectOrValue, userIdProviderKey) => { + utils._each(userIds, (userIdObjectOrValue, userIdProviderKey) => { const key = USER_ID_CODE_TO_QUERY_ARG[userIdProviderKey]; if (USER_ID_CODE_TO_QUERY_ARG.hasOwnProperty(userIdProviderKey)) { switch (userIdProviderKey) { - case 'merkleId': - queryParams[key] = userIdObjectOrValue.id; - break; case 'flocId': queryParams[key] = userIdObjectOrValue.id; break; @@ -350,7 +333,7 @@ function appendUserIdsToQueryParams(queryParams, userIds) { queryParams[key] = userIdObjectOrValue.lipbid; if (Array.isArray(userIdObjectOrValue.segments) && userIdObjectOrValue.segments.length > 0) { const liveIntentSegments = 'liveintent:' + userIdObjectOrValue.segments.join('|') - queryParams.sm = `${queryParams.sm ? queryParams.sm + ',' : ''}${liveIntentSegments}`; + queryParams.sm = `${queryParams.sm ? queryParams.sm + encodeURIComponent(',') : ''}${encodeURIComponent(liveIntentSegments)}`; } break; case 'parrableId': @@ -388,13 +371,13 @@ function buildOXBannerRequest(bids, bidderRequest) { let customParamsForAllBids = []; let hasCustomParam = false; let queryParams = buildCommonQueryParamsFromBids(bids, bidderRequest); - let auids = _map(bids, bid => bid.params.unit); + let auids = utils._map(bids, bid => bid.params.unit); - queryParams.aus = _map(bids, bid => parseSizesInput(bid.mediaTypes.banner.sizes).join(',')).join('|'); - queryParams.divids = _map(bids, bid => encodeURIComponent(bid.adUnitCode)).join(','); + queryParams.aus = utils._map(bids, bid => utils.parseSizesInput(bid.mediaTypes.banner.sizes).join(',')).join('|'); + queryParams.divids = utils._map(bids, bid => encodeURIComponent(bid.adUnitCode)).join(','); // gpid - queryParams.aucs = _map(bids, function (bid) { - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + queryParams.aucs = utils._map(bids, function (bid) { + let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); return encodeURIComponent(gpid || '') }).join(','); @@ -412,7 +395,7 @@ function buildOXBannerRequest(bids, bidderRequest) { bids.forEach(function (bid) { if (bid.params.customParams) { - let customParamsForBid = _map(Object.keys(bid.params.customParams), customKey => formatCustomParms(customKey, bid.params.customParams)); + let customParamsForBid = utils._map(Object.keys(bid.params.customParams), customKey => formatCustomParms(customKey, bid.params.customParams)); let formattedCustomParams = window.btoa(customParamsForBid.join('&')); hasCustomParam = true; customParamsForAllBids.push(formattedCustomParams); @@ -452,22 +435,22 @@ function buildOXVideoRequest(bid, bidderRequest) { } function generateVideoParameters(bid, bidderRequest) { - const videoMediaType = deepAccess(bid, `mediaTypes.video`); + const videoMediaType = utils.deepAccess(bid, `mediaTypes.video`); let queryParams = buildCommonQueryParamsFromBids([bid], bidderRequest); - let oxVideoConfig = deepAccess(bid, 'params.video') || {}; - let context = deepAccess(bid, 'mediaTypes.video.context'); - let playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); + let oxVideoConfig = utils.deepAccess(bid, 'params.video') || {}; + let context = utils.deepAccess(bid, 'mediaTypes.video.context'); + let playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); let width; let height; // normalize config for video size - if (isArray(bid.sizes) && bid.sizes.length === 2 && !isArray(bid.sizes[0])) { + if (utils.isArray(bid.sizes) && bid.sizes.length === 2 && !utils.isArray(bid.sizes[0])) { width = parseInt(bid.sizes[0], 10); height = parseInt(bid.sizes[1], 10); - } else if (isArray(bid.sizes) && isArray(bid.sizes[0]) && bid.sizes[0].length === 2) { + } else if (utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0]) && bid.sizes[0].length === 2) { width = parseInt(bid.sizes[0][0], 10); height = parseInt(bid.sizes[0][1], 10); - } else if (isArray(playerSize) && playerSize.length === 2) { + } else if (utils.isArray(playerSize) && playerSize.length === 2) { width = parseInt(playerSize[0], 10); height = parseInt(playerSize[1], 10); } @@ -480,7 +463,7 @@ function generateVideoParameters(bid, bidderRequest) { legacyParams = legacyParams.openrtb; } // support for video object or full openrtb object - if (isArray(legacyParams.imp)) { + if (utils.isArray(legacyParams.imp)) { legacyParams = legacyParams.imp[0].video; } Object.keys(legacyParams) @@ -519,7 +502,7 @@ function generateVideoParameters(bid, bidderRequest) { queryParams.vtest = 1; } - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); if (gpid) { queryParams.aucs = encodeURIComponent(gpid) } @@ -534,7 +517,7 @@ function createVideoBidResponses(response, {bid, startTime}) { let bidResponses = []; if (response !== undefined && response.vastUrl !== '' && response.pub_rev > 0) { - let vastQueryParams = parseUrl(response.vastUrl).search || {}; + let vastQueryParams = utils.parseUrl(response.vastUrl).search || {}; let bidResponse = {}; bidResponse.requestId = bid.bidId; if (response.deal_id) { diff --git a/modules/operaadsBidAdapter.js b/modules/operaadsBidAdapter.js index 61ea8cdcb76..85ba25c1404 100644 --- a/modules/operaadsBidAdapter.js +++ b/modules/operaadsBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, isArray, isStr, triggerPixel, deepAccess, deepSetValue, isPlainObject, generateUUID, parseUrl, isFn, getDNT, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js'; @@ -8,7 +8,6 @@ import { OUTSTREAM } from '../src/video.js'; const BIDDER_CODE = 'operaads'; const ENDPOINT = 'https://s.adx.opera.com/ortb/v2/'; -const USER_SYNC_ENDPOINT = 'https://s.adx.opera.com/usersync/page'; const OUTSTREAM_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js'; @@ -71,27 +70,27 @@ export const spec = { */ isBidRequestValid: function (bid) { if (!bid) { - logWarn(BIDDER_CODE, 'Invalid bid,', bid); + utils.logWarn(BIDDER_CODE, 'Invalid bid,', bid); return false; } if (!bid.params) { - logWarn(BIDDER_CODE, 'bid.params is required.') + utils.logWarn(BIDDER_CODE, 'bid.params is required.') return false; } if (!bid.params.placementId) { - logWarn(BIDDER_CODE, 'bid.params.placementId is required.') + utils.logWarn(BIDDER_CODE, 'bid.params.placementId is required.') return false; } if (!bid.params.endpointId) { - logWarn(BIDDER_CODE, 'bid.params.endpointId is required.') + utils.logWarn(BIDDER_CODE, 'bid.params.endpointId is required.') return false; } if (!bid.params.publisherId) { - logWarn(BIDDER_CODE, 'bid.params.publisherId is required.') + utils.logWarn(BIDDER_CODE, 'bid.params.publisherId is required.') return false; } @@ -119,9 +118,9 @@ export const spec = { let bidResponses = []; let serverBody; - if ((serverBody = serverResponse.body) && serverBody.seatbid && isArray(serverBody.seatbid)) { + if ((serverBody = serverResponse.body) && serverBody.seatbid && utils.isArray(serverBody.seatbid)) { serverBody.seatbid.forEach((seatbidder) => { - if (seatbidder.bid && isArray(seatbidder.bid)) { + if (seatbidder.bid && utils.isArray(seatbidder.bid)) { bidResponses = seatbidder.bid.map((bid) => buildBidResponse(bid, bidRequest.originalBidRequest, serverBody)); } }); @@ -138,25 +137,6 @@ export const spec = { * @return {UserSync[]} The user syncs which should be dropped. */ getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) { - if ('iframeEnabled' in syncOptions && syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: USER_SYNC_ENDPOINT - }]; - } - if ('pixelEnabled' in syncOptions && syncOptions.pixelEnabled) { - const pixels = deepAccess(serverResponses, '0.body.pixels') - if (Array.isArray(pixels)) { - const userSyncPixels = [] - for (const pixel of pixels) { - userSyncPixels.push({ - type: 'image', - url: pixel - }) - } - return userSyncPixels; - } - } return []; }, @@ -173,7 +153,7 @@ export const spec = { * @param {Bid} bid The bid that won the auction */ onBidWon: function (bid) { - if (!bid || !isStr(bid.nurl)) { + if (!bid || !utils.isStr(bid.nurl)) { return; } @@ -186,7 +166,7 @@ export const spec = { winCurr = bid.currency; } - triggerPixel( + utils.triggerPixel( bid.nurl .replace(/\$\{AUCTION_PRICE\}/g, winCpm) .replace(/\$\{AUCTION_CURRENCY\}/g, winCurr) @@ -209,53 +189,55 @@ export const spec = { * @returns {Request} */ function buildOpenRtbBidRequest(bidRequest, bidderRequest) { - const pageReferrer = deepAccess(bidderRequest, 'refererInfo.referer'); + const currencies = getCurrencies(bidRequest); + + const pageReferrer = utils.deepAccess(bidderRequest, 'refererInfo.referer'); // build OpenRTB request body const payload = { id: bidderRequest.auctionId, tmax: bidderRequest.timeout || config.getConfig('bidderTimeout'), test: config.getConfig('debug') ? 1 : 0, - imp: createImp(bidRequest), + imp: createImp(bidRequest, currencies[0]), device: getDevice(), site: { - id: String(deepAccess(bidRequest, 'params.publisherId')), + id: String(utils.deepAccess(bidRequest, 'params.publisherId')), domain: getDomain(pageReferrer), page: pageReferrer, ref: window.self === window.top ? document.referrer : '', }, at: 1, bcat: getBcat(bidRequest), - cur: [DEFAULT_CURRENCY], + cur: currencies, regs: { coppa: config.getConfig('coppa') ? 1 : 0, ext: {} }, user: { - buyeruid: getUserId(bidRequest) + id: getUserId(bidRequest) } } - const gdprConsent = deepAccess(bidderRequest, 'gdprConsent'); + const gdprConsent = utils.deepAccess(bidderRequest, 'gdprConsent'); if (!!gdprConsent && gdprConsent.gdprApplies) { - deepSetValue(payload, 'regs.ext.gdpr', 1); - deepSetValue(payload, 'user.ext.consent', gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', 1); + utils.deepSetValue(payload, 'user.ext.consent', gdprConsent.consentString); } - const uspConsent = deepAccess(bidderRequest, 'uspConsent'); + const uspConsent = utils.deepAccess(bidderRequest, 'uspConsent'); if (uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', uspConsent); } - const eids = deepAccess(bidRequest, 'userIdAsEids', []); + const eids = utils.deepAccess(bidRequest, 'userIdAsEids', []); if (eids.length > 0) { - deepSetValue(payload, 'user.eids', eids); + utils.deepSetValue(payload, 'user.eids', eids); } return { method: 'POST', - url: ENDPOINT + String(deepAccess(bidRequest, 'params.publisherId')) + - '?ep=' + String(deepAccess(bidRequest, 'params.endpointId')), + url: ENDPOINT + String(utils.deepAccess(bidRequest, 'params.publisherId')) + + '?ep=' + String(utils.deepAccess(bidRequest, 'params.endpointId')), data: JSON.stringify(payload), options: { contentType: 'application/json', @@ -292,7 +274,7 @@ function buildBidResponse(bid, bidRequest, responseBody) { // OpenRtb Markup Response Object // https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-Native-Ads-Specification-1-1_2016.pdf#5.1 - if (markup && isPlainObject(markup.native)) { + if (markup && utils.isPlainObject(markup.native)) { mediaType = NATIVE; nativeResponse = markup.native; } @@ -301,7 +283,7 @@ function buildBidResponse(bid, bidRequest, responseBody) { const currency = responseBody.cur || DEFAULT_CURRENCY; const cpm = (parseFloat(bid.price) || 0).toFixed(2); - const categories = deepAccess(bid, 'cat', []); + const categories = utils.deepAccess(bid, 'cat', []); const bidResponse = { requestId: bid.impid, @@ -320,14 +302,14 @@ function buildBidResponse(bid, bidRequest, responseBody) { } }; - if (bid.adomain && isArray(bid.adomain) && bid.adomain.length > 0) { + if (bid.adomain && utils.isArray(bid.adomain) && bid.adomain.length > 0) { bidResponse.meta.advertiserDomains = bid.adomain; bidResponse.meta.clickUrl = bid.adomain[0]; } switch (mediaType) { case VIDEO: { - const playerSize = deepAccess(bidRequest, 'mediaTypes.video.playerSize', VIDEO_DEFAULTS.SIZE); + const playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize', VIDEO_DEFAULTS.SIZE); const size = canonicalizeSizesArray(playerSize)[0]; bidResponse.vastXml = bid.adm; @@ -335,7 +317,7 @@ function buildBidResponse(bid, bidRequest, responseBody) { bidResponse.width = bid.w || size[0]; bidResponse.height = bid.h || size[1]; - const context = deepAccess(bidRequest, 'mediaTypes.video.context'); + const context = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); // if outstream video, add a default render for it. if (context === OUTSTREAM) { @@ -378,13 +360,13 @@ function interpretNativeAd(nativeResponse, currency, cpm) { // OpenRtb Link Object // https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-Native-Ads-Specification-1-1_2016.pdf#5.7 - const clickUrl = deepAccess(nativeResponse, 'link.url'); - if (clickUrl && isStr(clickUrl)) { + const clickUrl = utils.deepAccess(nativeResponse, 'link.url'); + if (clickUrl && utils.isStr(clickUrl)) { native.clickUrl = decodeURIComponent(clickUrl); } - const clickTrackers = deepAccess(nativeResponse, 'link.clicktrackers'); - if (clickTrackers && isArray(clickTrackers)) { + const clickTrackers = utils.deepAccess(nativeResponse, 'link.clicktrackers'); + if (clickTrackers && utils.isArray(clickTrackers)) { native.clickTrackers = clickTrackers .filter(Boolean) .map( @@ -394,7 +376,7 @@ function interpretNativeAd(nativeResponse, currency, cpm) { ); } - if (nativeResponse.imptrackers && isArray(nativeResponse.imptrackers)) { + if (nativeResponse.imptrackers && utils.isArray(nativeResponse.imptrackers)) { native.impressionTrackers = nativeResponse.imptrackers .filter(Boolean) .map( @@ -404,16 +386,16 @@ function interpretNativeAd(nativeResponse, currency, cpm) { ); } - if (nativeResponse.jstracker && isStr(nativeResponse.jstracker)) { + if (nativeResponse.jstracker && utils.isStr(nativeResponse.jstracker)) { native.javascriptTrackers = [nativeResponse.jstracker]; } let assets; - if ((assets = nativeResponse.assets) && isArray(assets)) { + if ((assets = nativeResponse.assets) && utils.isArray(assets)) { assets.forEach((asset) => { switch (asset.id) { case NATIVE_DEFAULTS.ASSET_ID.TITLE: { - const title = deepAccess(asset, 'title.text'); + const title = utils.deepAccess(asset, 'title.text'); if (title) { native.title = title; } @@ -440,21 +422,21 @@ function interpretNativeAd(nativeResponse, currency, cpm) { break; } case NATIVE_DEFAULTS.ASSET_ID.BODY: { - const body = deepAccess(asset, 'data.value'); + const body = utils.deepAccess(asset, 'data.value'); if (body) { native.body = body; } break; } case NATIVE_DEFAULTS.ASSET_ID.SPONSORED: { - const sponsoredBy = deepAccess(asset, 'data.value'); + const sponsoredBy = utils.deepAccess(asset, 'data.value'); if (sponsoredBy) { native.sponsoredBy = sponsoredBy; } break; } case NATIVE_DEFAULTS.ASSET_ID.CTA: { - const cta = deepAccess(asset, 'data.value'); + const cta = utils.deepAccess(asset, 'data.value'); if (cta) { native.cta = cta; } @@ -474,19 +456,22 @@ function interpretNativeAd(nativeResponse, currency, cpm) { * @param {Currency} cur * @returns {Imp[]} */ -function createImp(bidRequest) { +function createImp(bidRequest, cur) { const imp = []; + const floor = getBidFloor(bidRequest, cur); + const impItem = { id: bidRequest.bidId, - tagid: String(deepAccess(bidRequest, 'params.placementId')), + tagid: String(utils.deepAccess(bidRequest, 'params.placementId')), + bidfloor: floor, }; - let mediaType, size; + let mediaType; let bannerReq, videoReq, nativeReq; - if ((bannerReq = deepAccess(bidRequest, 'mediaTypes.banner'))) { - size = canonicalizeSizesArray(bannerReq.sizes || BANNER_DEFAULTS.SIZE)[0]; + if ((bannerReq = utils.deepAccess(bidRequest, 'mediaTypes.banner'))) { + const size = canonicalizeSizesArray(bannerReq.sizes || BANNER_DEFAULTS.SIZE)[0]; impItem.banner = { w: size[0], @@ -495,8 +480,8 @@ function createImp(bidRequest) { }; mediaType = BANNER; - } else if ((videoReq = deepAccess(bidRequest, 'mediaTypes.video'))) { - size = canonicalizeSizesArray(videoReq.playerSize || VIDEO_DEFAULTS.SIZE)[0]; + } else if ((videoReq = utils.deepAccess(bidRequest, 'mediaTypes.video'))) { + const size = canonicalizeSizesArray(videoReq.playerSize || VIDEO_DEFAULTS.SIZE)[0]; impItem.video = { w: size[0], @@ -513,7 +498,7 @@ function createImp(bidRequest) { }; mediaType = VIDEO; - } else if ((nativeReq = deepAccess(bidRequest, 'mediaTypes.native'))) { + } else if ((nativeReq = utils.deepAccess(bidRequest, 'mediaTypes.native'))) { const params = bidRequest.nativeParams || nativeReq; const request = { @@ -531,14 +516,6 @@ function createImp(bidRequest) { mediaType = NATIVE; } - const floorDetail = getBidFloor(bidRequest, { - mediaType: mediaType || '*', - size: size || '*' - }) - - impItem.bidfloor = floorDetail.floor; - impItem.bidfloorcur = floorDetail.currency; - if (mediaType) { imp.push(impItem); } @@ -553,7 +530,7 @@ function createImp(bidRequest) { * @returns {Size[][]} */ function canonicalizeSizesArray(sizes) { - if (sizes.length === 2 && !isArray(sizes[0])) { + if (sizes.length === 2 && !utils.isArray(sizes[0])) { return [sizes]; } return sizes; @@ -665,19 +642,19 @@ function mapNativeImage(image, type) { * @returns {String} userId */ function getUserId(bidRequest) { - let sharedId = deepAccess(bidRequest, 'userId.sharedid.id'); + let sharedId = utils.deepAccess(bidRequest, 'userId.sharedid.id'); if (sharedId) { return sharedId; } for (const idModule of ['pubcid', 'tdid']) { - let userId = deepAccess(bidRequest, `userId.${idModule}`); + let userId = utils.deepAccess(bidRequest, `userId.${idModule}`); if (userId) { return userId; } } - return generateUUID(); + return utils.generateUUID(); } /** @@ -690,7 +667,7 @@ function getDomain(referer) { let domain; if (!(domain = config.getConfig('publisherDomain'))) { - const u = parseUrl(referer); + const u = utils.parseUrl(referer); domain = u.hostname; } @@ -701,29 +678,47 @@ function getDomain(referer) { * Get bid floor price * * @param {BidRequest} bid - * @param {Params} params - * @returns {Floor} floor price + * @param {String} cur + * @returns {Number} floor price */ -function getBidFloor(bid, {mediaType = '*', size = '*'}) { - if (isFn(bid.getFloor)) { - const floorInfo = bid.getFloor({ - currency: DEFAULT_CURRENCY, - mediaType, - size +function getBidFloor(bid, cur) { + let floorInfo = {}; + + if (typeof bid.getFloor === 'function') { + floorInfo = bid.getFloor({ + currency: cur, + mediaType: '*', + size: '*' }); + } - if (isPlainObject(floorInfo) && !isNaN(floorInfo.floor)) { - return { - currency: floorInfo.currency || DEFAULT_CURRENCY, - floor: floorInfo.floor - }; - } + return floorInfo.floor || 0.0; +} + +/** + * Get currencies from bid request + * + * @param {BidRequest} bidRequest + * @returns {String[]} currencies + */ +function getCurrencies(bidRequest) { + let currencies = []; + + const pCur = utils.deepAccess(bidRequest, 'params.currency'); + if (pCur) { + currencies = currencies.concat(pCur); } - return { - currency: DEFAULT_CURRENCY, - floor: 0.0 + if (!currencies.length) { + let currency; + if ((currency = config.getConfig('currency')) && currency.adServerCurrency) { + currencies.push(currency.adServerCurrency); + } else { + currencies.push(DEFAULT_CURRENCY); + } } + + return currencies; } /** @@ -735,7 +730,7 @@ function getBidFloor(bid, {mediaType = '*', size = '*'}) { function getBcat(bidRequest) { let bcat = []; - const pBcat = deepAccess(bidRequest, 'params.bcat'); + const pBcat = utils.deepAccess(bidRequest, 'params.bcat'); if (pBcat) { bcat = bcat.concat(pBcat); } @@ -756,7 +751,7 @@ function getDevice() { device.ua = device.ua || navigator.userAgent; device.language = device.language || getLanguage(); device.dnt = typeof device.dnt === 'number' - ? device.dnt : (getDNT() ? 1 : 0); + ? device.dnt : (utils.getDNT() ? 1 : 0); return device; } @@ -779,8 +774,8 @@ function getLanguage() { * @returns */ function createRenderer(bidRequest) { - const globalRenderer = deepAccess(bidRequest, 'renderer'); - const currentRenderer = deepAccess(bidRequest, 'mediaTypes.video.renderer'); + const globalRenderer = utils.deepAccess(bidRequest, 'renderer'); + const currentRenderer = utils.deepAccess(bidRequest, 'mediaTypes.video.renderer'); let url = OUTSTREAM_RENDERER_URL; let config = {}; @@ -815,7 +810,7 @@ function createRenderer(bidRequest) { try { renderer.setRender(render); } catch (e) { - logError(BIDDER_CODE, 'Error calling setRender on renderer', e); + utils.logError(BIDDER_CODE, 'Error calling setRender on renderer', e); } return renderer; } diff --git a/modules/operaadsBidAdapter.md b/modules/operaadsBidAdapter.md index 709c67a04a7..9bfe3e76b88 100644 --- a/modules/operaadsBidAdapter.md +++ b/modules/operaadsBidAdapter.md @@ -16,9 +16,10 @@ Module that connects to OperaAds's demand sources | Name | Scope | Type | Description | Example | ---- | ----- | ---- | ----------- | ------- -| `placementId` | required | String | The Placement Id provided by Opera Ads. | `s5340077725248` -| `endpointId` | required | String | The Endpoint Id provided by Opera Ads. | `ep3425464070464` -| `publisherId` | required | String | The Publisher Id provided by Opera Ads. | `pub3054952966336` +| `placementId` | required | String | The Placement Id provided by Opera Ads. | `s12345678` +| `endpointId` | required | String | The Endpoint Id provided by Opera Ads. | `ep12345678` +| `publisherId` | required | String | The Publisher Id provided by Opera Ads. | `pub12345678` +| `currency` | optional | String or String[] | Currency. | `USD` | `bcat` | optional | String or String[] | The bcat value. | `IAB9-31` ### Bid Video Parameters @@ -65,9 +66,9 @@ var adUnits = [{ bids: [{ bidder: 'operaads', params: { - placementId: 's5340077725248', - endpointId: 'ep3425464070464', - publisherId: 'pub3054952966336' + placementId: 's12345678', + endpointId: 's12345678', + publisherId: 's12345678' } }] }]; @@ -91,9 +92,9 @@ var adUnits = [{ bids: [{ bidder: 'operaads', params: { - placementId: 's5340077725248', - endpointId: 'ep3425464070464', - publisherId: 'pub3054952966336' + placementId: 's12345678', + endpointId: 's12345678', + publisherId: 's12345678' } }] }]; @@ -125,9 +126,9 @@ var adUnits = [{ bids: [{ bidder: 'operaads', params: { - placementId: 's5340077725248', - endpointId: 'ep3425464070464', - publisherId: 'pub3054952966336' + placementId: 's12345678', + endpointId: 's12345678', + publisherId: 's12345678' } }] }]; diff --git a/modules/optimeraRtdProvider.js b/modules/optimeraRtdProvider.js index 024a558baca..1e439b28c94 100644 --- a/modules/optimeraRtdProvider.js +++ b/modules/optimeraRtdProvider.js @@ -18,7 +18,7 @@ * @property {string} device */ -import { logInfo, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { submodule } from '../src/hook.js'; import { ajaxBuilder } from '../src/ajax.js'; @@ -74,7 +74,7 @@ export let fetchScoreFile = true; * Make the request for the Score File. */ export function scoreFileRequest() { - logInfo('Fetch Optimera score file.'); + utils.logInfo('Fetch Optimera score file.'); const ajax = ajaxBuilder(); ajax(scoresURL, { @@ -83,14 +83,14 @@ export function scoreFileRequest() { try { setScores(res); } catch (err) { - logError('Unable to parse Optimera Score File.', err); + utils.logError('Unable to parse Optimera Score File.', err); } } else if (req.status === 403) { - logError('Unable to fetch the Optimera Score File - 403'); + utils.logError('Unable to fetch the Optimera Score File - 403'); } }, error: () => { - logError('Unable to fetch the Optimera Score File.'); + utils.logError('Unable to fetch the Optimera Score File.'); } }); } @@ -108,9 +108,9 @@ export function returnTargetingData(adUnits, config) { } }); } catch (err) { - logError('error', err); + utils.logError('error', err); } - logInfo('Apply Optimera targeting'); + utils.logInfo('Apply Optimera targeting'); return targeting; } @@ -143,7 +143,7 @@ export function init(moduleConfig) { return true; } else { if (!_moduleParams.clientID) { - logError('Optimera clientID is missing in the Optimera RTD configuration.'); + utils.logError('Optimera clientID is missing in the Optimera RTD configuration.'); } return false; } @@ -173,9 +173,7 @@ export function setScoresURL() { } /** - * Set the scores for the device if given. - * Add any any insights to the winddow.optimeraInsights object. - * + * Set the scores for the divice if given. * @param {*} result * @returns {string} JSON string of Optimera Scores. */ @@ -186,13 +184,8 @@ export function setScores(result) { if (device !== 'default' && scores.device[device]) { scores = scores.device[device]; } - logInfo(scores); - if (scores.insights) { - window.optimeraInsights = window.optimeraInsights || {}; - window.optimeraInsights.data = scores.insights; - } } catch (e) { - logError('Optimera score file could not be parsed.'); + utils.logError('Optimera score file could not be parsed.'); } optimeraTargeting = scores; } diff --git a/modules/optoutBidAdapter.js b/modules/optoutBidAdapter.js index d218a65bf90..3a2e672013c 100644 --- a/modules/optoutBidAdapter.js +++ b/modules/optoutBidAdapter.js @@ -1,11 +1,11 @@ -import { deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'optout'; function getDomain(bidderRequest) { - return deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || deepAccess(window, 'location.href'); + return utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || utils.deepAccess(window, 'location.href'); } function getCurrency() { @@ -23,7 +23,7 @@ function hasPurpose1Consent(bidderRequest) { let result = false; if (bidderRequest && bidderRequest.gdprConsent) { if (bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(utils.deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; diff --git a/modules/orbidderBidAdapter.js b/modules/orbidderBidAdapter.js index 111c1876e14..edd44385d52 100644 --- a/modules/orbidderBidAdapter.js +++ b/modules/orbidderBidAdapter.js @@ -1,7 +1,7 @@ -import { isFn, isPlainObject } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; const storageManager = getStorageManager(); @@ -146,7 +146,7 @@ export const spec = { * @returns {float||undefined} */ function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return bid.params.bidfloor; } @@ -155,7 +155,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') { return floor.floor; } return undefined; diff --git a/modules/otmBidAdapter.js b/modules/otmBidAdapter.js deleted file mode 100644 index a0e91a480a2..00000000000 --- a/modules/otmBidAdapter.js +++ /dev/null @@ -1,146 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import {logInfo, logError, getBidIdParameter, _each, getValue, isFn, isPlainObject} from '../src/utils.js'; -import { BANNER } from '../src/mediaTypes.js'; - -const BIDDER_CODE = 'otm'; -const OTM_BID_URL = 'https://ssp.otm-r.com/adjson'; -const DEF_CUR = 'RUB' - -export const spec = { - - code: BIDDER_CODE, - url: OTM_BID_URL, - supportedMediaTypes: [ BANNER ], - - /** - * Determines whether or not the given bid request is valid. - * - * @param {object} bid The bid to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function (bid) { - return !!bid.params.tid; - }, - - /** - * Build bidder requests. - * - * @param validBidRequests - * @param bidderRequest - * @returns {[]} - */ - buildRequests: function (validBidRequests, bidderRequest) { - logInfo('validBidRequests', validBidRequests); - - const bidRequests = []; - let tz = new Date().getTimezoneOffset() - let referrer = ''; - if (bidderRequest && bidderRequest.refererInfo) { - referrer = bidderRequest.refererInfo.referer; - } - - _each(validBidRequests, (bid) => { - let domain = getValue(bid.params, 'domain') || '' - let tid = getValue(bid.params, 'tid') - let cur = getValue(bid.params, 'currency') || DEF_CUR - let bidid = getBidIdParameter('bidId', bid) - let transactionid = getBidIdParameter('transactionId', bid) - let auctionid = getBidIdParameter('auctionId', bid) - let bidfloor = _getBidFloor(bid) - - _each(bid.sizes, size => { - let width = 0; - let height = 0; - if (size.length && typeof size[0] === 'number' && typeof size[1] === 'number') { - width = size[0]; - height = size[1]; - } - bidRequests.push({ - method: 'GET', - url: OTM_BID_URL, - data: { - tz: tz, - w: width, - h: height, - domain: domain, - l: referrer, - s: tid, - cur: cur, - bidid: bidid, - transactionid: transactionid, - auctionid: auctionid, - bidfloor: bidfloor, - }, - }) - }) - }) - return bidRequests; - }, - - /** - * Generate response. - * - * @param serverResponse - * @param request - * @returns {[]|*[]} - */ - interpretResponse: function (serverResponse, request) { - logInfo('serverResponse', serverResponse.body); - - const responsesBody = serverResponse ? serverResponse.body : {}; - const bidResponses = []; - try { - if (responsesBody.length === 0) { - return []; - } - - _each(responsesBody, (bid) => { - if (bid.ad) { - bidResponses.push({ - requestId: bid.bidid, - cpm: bid.cpm, - width: bid.w, - height: bid.h, - creativeId: bid.creativeid, - currency: bid.currency || 'RUB', - netRevenue: true, - ad: bid.ad, - ttl: bid.ttl, - transactionId: bid.transactionid, - meta: { - advertiserDomains: bid.adDomain ? [bid.adDomain] : [] - } - }); - } - }); - } catch (error) { - logError(error); - } - - return bidResponses; - } -}; - -/** - * Get floor value - * @param bid - * @returns {null|*} - * @private - */ -function _getBidFloor(bid) { - if (!isFn(bid.getFloor)) { - return bid.params.bidfloor ? bid.params.bidfloor : 0; - } - - let floor = bid.getFloor({ - currency: DEF_CUR, - mediaType: '*', - size: '*' - }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === DEF_CUR) { - return floor.floor; - } - return 0; -} - -registerBidder(spec); diff --git a/modules/otmBidAdapter.md b/modules/otmBidAdapter.md index e5834da5729..4962d3a8052 100644 --- a/modules/otmBidAdapter.md +++ b/modules/otmBidAdapter.md @@ -1,37 +1,36 @@ # Overview -**Module Name**: OTM Bidder Adapter -**Module Type**: Bidder Adapter -**Maintainer**: e.kretsu@otm-r.com +Module Name: OTM Bidder Adapter +Module Type: Bidder Adapter +Maintainer: ? # Description -OTM Bidder Adapter for Prebid.js. About: https://otm-r.com +You can use this adapter to get a bid from otm-r.com. -Use `otm` as bidder: +About us : http://otm-r.com -# Params -- `tid` required, specific id AdUnit slot. -- `domain` optional, specific custom domain. -- `bidfloor` optional. -## AdUnits configuration example -``` - var adUnits = [{ - code: 'your-slot', //use exactly the same code as your slot div id. - mediaTypes: { - banner: { - sizes: [[320, 480]] - } - }, - bids: [{ - bidder: 'otm', - params: { - tid: 'XXXXX', - domain: 'specific custom domain, if needed', - bidfloor: 20 +# Test Parameters +```javascript + var adUnits = [ + { + code: 'div-otm-example', + sizes: [[320, 480]], + bids: [ + { + bidder: "otm", + params: { + tid: "99", + bidfloor: 20 + } + } + ] } - }] - }]; - + ]; ``` + +Where: + +* tid - A tag id (should have low cardinality) +* bidfloor - Floor price diff --git a/modules/outbrainBidAdapter.js b/modules/outbrainBidAdapter.js index 439570e976e..052122e95f1 100644 --- a/modules/outbrainBidAdapter.js +++ b/modules/outbrainBidAdapter.js @@ -5,7 +5,7 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { NATIVE, BANNER } from '../src/mediaTypes.js'; -import { deepAccess, deepSetValue, replaceAuctionPrice, _map, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { config } from '../src/config.js'; @@ -29,7 +29,7 @@ export const spec = { isBidRequestValid: (bid) => { return ( !!config.getConfig('outbrain.bidderUrl') && - !!deepAccess(bid, 'params.publisher.id') && + !!utils.deepAccess(bid, 'params.publisher.id') && !!(bid.nativeParams || bid.sizes) ); }, @@ -40,7 +40,6 @@ export const spec = { const publisher = setOnAny(validBidRequests, 'params.publisher'); const bcat = setOnAny(validBidRequests, 'params.bcat'); const badv = setOnAny(validBidRequests, 'params.badv'); - const eids = setOnAny(validBidRequests, 'userIdAsEids') const cur = CURRENCY; const endpointUrl = config.getConfig('outbrain.bidderUrl'); const timeout = bidderRequest.timeout; @@ -95,19 +94,15 @@ export const spec = { request.test = 1; } - if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) { - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString) - deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1) + if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) { + utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString) + utils.deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1) } if (bidderRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent) + utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent) } if (config.getConfig('coppa') === true) { - deepSetValue(request, 'regs.coppa', config.getConfig('coppa') & 1) - } - - if (eids) { - deepSetValue(request, 'user.ext.eids', eids); + utils.deepSetValue(request, 'regs.coppa', config.getConfig('coppa') & 1) } return { @@ -182,7 +177,7 @@ export const spec = { // for native requests we put the nurl as an imp tracker, otherwise if the auction takes place on prebid server // the server JS adapter puts the nurl in the adm as a tracking pixel and removes the attribute if (bid.nurl) { - ajax(replaceAuctionPrice(bid.nurl, bid.originalCpm)) + ajax(utils.replaceAuctionPrice(bid.nurl, bid.originalCpm)) } } }; @@ -221,7 +216,7 @@ function parseNative(bid) { function setOnAny(collection, key) { for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); + result = utils.deepAccess(collection[i], key); if (result) { return result; } @@ -233,7 +228,7 @@ function flatten(arr) { } function getNativeAssets(bid) { - return _map(bid.nativeParams, (bidParams, key) => { + return utils._map(bid.nativeParams, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1, @@ -271,16 +266,16 @@ function getNativeAssets(bid) { /* Turn bid request sizes into ut-compatible format */ function transformSizes(requestSizes) { - if (!isArray(requestSizes)) { + if (!utils.isArray(requestSizes)) { return []; } - if (requestSizes.length === 2 && !isArray(requestSizes[0])) { + if (requestSizes.length === 2 && !utils.isArray(requestSizes[0])) { return [{ w: parseInt(requestSizes[0], 10), h: parseInt(requestSizes[1], 10) }]; - } else if (isArray(requestSizes[0])) { + } else if (utils.isArray(requestSizes[0])) { return requestSizes.map(item => ({ w: parseInt(item[0], 10), diff --git a/modules/ozoneBidAdapter.js b/modules/ozoneBidAdapter.js index 3b5147907eb..974fe3a4304 100644 --- a/modules/ozoneBidAdapter.js +++ b/modules/ozoneBidAdapter.js @@ -1,19 +1,19 @@ -import { logInfo, logError, deepAccess, logWarn, deepSetValue, isArray, contains, isStr, mergeDeep } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import {config} from '../src/config.js'; import {getPriceBucketString} from '../src/cpmBucketManager.js'; import { Renderer } from '../src/Renderer.js'; - const BIDDER_CODE = 'ozone'; +// *** PROD *** const ORIGIN = 'https://elb.the-ozone-project.com' // applies only to auction & cookie const AUCTIONURI = '/openrtb2/auction'; const OZONECOOKIESYNC = '/static/load-cookie.html'; const OZONE_RENDERER_URL = 'https://prebid.the-ozone-project.com/ozone-renderer.js'; const ORIGIN_DEV = 'https://test.ozpr.net'; -const OZONEVERSION = '2.7.0'; +const OZONEVERSION = '2.6.0'; export const spec = { gvlid: 524, aliases: [{code: 'lmc', gvlid: 524}, {code: 'newspassid', gvlid: 524}], @@ -41,7 +41,7 @@ export const spec = { this.propertyBag.whitelabel.logId = bidder.toUpperCase(); this.propertyBag.whitelabel.bidder = bidder; let bidderConfig = config.getConfig(bidder) || {}; - logInfo('got bidderConfig: ', JSON.parse(JSON.stringify(bidderConfig))); + utils.logInfo('got bidderConfig: ', JSON.parse(JSON.stringify(bidderConfig))); if (bidderConfig.kvpPrefix) { this.propertyBag.whitelabel.keyPrefix = bidderConfig.kvpPrefix; } @@ -52,7 +52,6 @@ export const spec = { this.propertyBag.whitelabel.auctionUrl = bidderConfig.endpointOverride.origin + AUCTIONURI; this.propertyBag.whitelabel.cookieSyncUrl = bidderConfig.endpointOverride.origin + OZONECOOKIESYNC; } - if (arr.hasOwnProperty('renderer')) { if (arr.renderer.match('%3A%2F%2F')) { this.propertyBag.whitelabel.rendererUrl = decodeURIComponent(arr['renderer']); @@ -72,15 +71,15 @@ export const spec = { } try { if (arr.hasOwnProperty('auction') && arr.auction === 'dev') { - logInfo('GET: auction=dev'); + utils.logInfo('GET: auction=dev'); this.propertyBag.whitelabel.auctionUrl = ORIGIN_DEV + AUCTIONURI; } if (arr.hasOwnProperty('cookiesync') && arr.cookiesync === 'dev') { - logInfo('GET: cookiesync=dev'); + utils.logInfo('GET: cookiesync=dev'); this.propertyBag.whitelabel.cookieSyncUrl = ORIGIN_DEV + OZONECOOKIESYNC; } } catch (e) {} - logInfo('set propertyBag.whitelabel to', this.propertyBag.whitelabel); + utils.logInfo('set propertyBag.whitelabel to', this.propertyBag.whitelabel); }, getAuctionUrl() { return this.propertyBag.whitelabel.auctionUrl; @@ -98,62 +97,62 @@ export const spec = { */ isBidRequestValid(bid) { this.loadWhitelabelData(bid); - logInfo('isBidRequestValid : ', config.getConfig(), bid); + utils.logInfo('isBidRequestValid : ', config.getConfig(), bid); let adUnitCode = bid.adUnitCode; // adunit[n].code - let err1 = 'VALIDATION FAILED : missing {param} : siteId, placementId and publisherId are REQUIRED' + if (!(bid.params.hasOwnProperty('placementId'))) { - logError(err1.replace('{param}', 'placementId'), adUnitCode); + utils.logError('VALIDATION FAILED : missing placementId : siteId, placementId and publisherId are REQUIRED', adUnitCode); return false; } if (!this.isValidPlacementId(bid.params.placementId)) { - logError('VALIDATION FAILED : placementId must be exactly 10 numeric characters', adUnitCode); + utils.logError('VALIDATION FAILED : placementId must be exactly 10 numeric characters', adUnitCode); return false; } if (!(bid.params.hasOwnProperty('publisherId'))) { - logError(err1.replace('{param}', 'publisherId'), adUnitCode); + utils.logError('VALIDATION FAILED : missing publisherId : siteId, placementId and publisherId are REQUIRED', adUnitCode); return false; } if (!(bid.params.publisherId).toString().match(/^[a-zA-Z0-9\-]{12}$/)) { - logError('VALIDATION FAILED : publisherId must be exactly 12 alphanumieric characters including hyphens', adUnitCode); + utils.logError('VALIDATION FAILED : publisherId must be exactly 12 alphanumieric characters including hyphens', adUnitCode); return false; } if (!(bid.params.hasOwnProperty('siteId'))) { - logError(err1.replace('{param}', 'siteId'), adUnitCode); + utils.logError('VALIDATION FAILED : missing siteId : siteId, placementId and publisherId are REQUIRED', adUnitCode); return false; } if (!(bid.params.siteId).toString().match(/^[0-9]{10}$/)) { - logError('VALIDATION FAILED : siteId must be exactly 10 numeric characters', adUnitCode); + utils.logError('VALIDATION FAILED : siteId must be exactly 10 numeric characters', adUnitCode); return false; } if (bid.params.hasOwnProperty('customParams')) { - logError('VALIDATION FAILED : customParams should be renamed to customData', adUnitCode); + utils.logError('VALIDATION FAILED : customParams should be renamed to customData', adUnitCode); return false; } if (bid.params.hasOwnProperty('customData')) { if (!Array.isArray(bid.params.customData)) { - logError('VALIDATION FAILED : customData is not an Array', adUnitCode); + utils.logError('VALIDATION FAILED : customData is not an Array', adUnitCode); return false; } if (bid.params.customData.length < 1) { - logError('VALIDATION FAILED : customData is an array but does not contain any elements', adUnitCode); + utils.logError('VALIDATION FAILED : customData is an array but does not contain any elements', adUnitCode); return false; } if (!(bid.params.customData[0]).hasOwnProperty('targeting')) { - logError('VALIDATION FAILED : customData[0] does not contain "targeting"', adUnitCode); + utils.logError('VALIDATION FAILED : customData[0] does not contain "targeting"', adUnitCode); return false; } if (typeof bid.params.customData[0]['targeting'] != 'object') { - logError('VALIDATION FAILED : customData[0] targeting is not an object', adUnitCode); + utils.logError('VALIDATION FAILED : customData[0] targeting is not an object', adUnitCode); return false; } } if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { if (!bid.mediaTypes[VIDEO].hasOwnProperty('context')) { - logError('No video context key/value in bid. Rejecting bid: ', bid); + utils.logError('No video context key/value in bid. Rejecting bid: ', bid); return false; } if (bid.mediaTypes[VIDEO].context !== 'instream' && bid.mediaTypes[VIDEO].context !== 'outstream') { - logError('video.context is invalid. Only instream/outstream video is supported. Rejecting bid: ', bid); + utils.logError('video.context is invalid. Only instream/outstream video is supported. Rejecting bid: ', bid); return false; } } @@ -173,27 +172,29 @@ export const spec = { this.propertyBag.buildRequestsStart = new Date().getTime(); let whitelabelBidder = this.propertyBag.whitelabel.bidder; // by default = ozone let whitelabelPrefix = this.propertyBag.whitelabel.keyPrefix; - logInfo(`buildRequests time: ${this.propertyBag.buildRequestsStart} v ${OZONEVERSION} validBidRequests`, JSON.parse(JSON.stringify(validBidRequests)), 'bidderRequest', JSON.parse(JSON.stringify(bidderRequest))); + utils.logInfo(`buildRequests time: ${this.propertyBag.buildRequestsStart} v ${OZONEVERSION} validBidRequests`, JSON.parse(JSON.stringify(validBidRequests)), 'bidderRequest', JSON.parse(JSON.stringify(bidderRequest))); + // First check - is there any config to block this request? if (this.blockTheRequest()) { return []; } let htmlParams = {'publisherId': '', 'siteId': ''}; if (validBidRequests.length > 0) { this.cookieSyncBag.userIdObject = Object.assign(this.cookieSyncBag.userIdObject, this.findAllUserIds(validBidRequests[0])); - this.cookieSyncBag.siteId = deepAccess(validBidRequests[0], 'params.siteId'); - this.cookieSyncBag.publisherId = deepAccess(validBidRequests[0], 'params.publisherId'); + this.cookieSyncBag.siteId = utils.deepAccess(validBidRequests[0], 'params.siteId'); + this.cookieSyncBag.publisherId = utils.deepAccess(validBidRequests[0], 'params.publisherId'); htmlParams = validBidRequests[0].params; } - logInfo('cookie sync bag', this.cookieSyncBag); + utils.logInfo('cookie sync bag', this.cookieSyncBag); let singleRequest = this.getWhitelabelConfigItem('ozone.singleRequest'); singleRequest = singleRequest !== false; // undefined & true will be true - logInfo(`config ${whitelabelBidder}.singleRequest : `, singleRequest); + utils.logInfo(`config ${whitelabelBidder}.singleRequest : `, singleRequest); let ozoneRequest = {}; // we only want to set specific properties on this, not validBidRequests[0].params delete ozoneRequest.test; // don't allow test to be set in the config - ONLY use $_GET['pbjs_debug'] + // First party data module : look for ortb2 in setconfig & set the User object. NOTE THAT this should happen before we set the consentString let fpd = config.getConfig('ortb2'); - if (fpd && deepAccess(fpd, 'user')) { - logInfo('added FPD user object'); + if (fpd && utils.deepAccess(fpd, 'user')) { + utils.logInfo('added FPD user object'); ozoneRequest.user = fpd.user; } @@ -202,62 +203,68 @@ export const spec = { const isTestMode = getParams[wlOztestmodeKey] || null; // this can be any string, it's used for testing ads ozoneRequest.device = {'w': window.innerWidth, 'h': window.innerHeight}; let placementIdOverrideFromGetParam = this.getPlacementIdOverrideFromGetParam(); // null or string - let schain = null; + // build the array of params to attach to `imp` let tosendtags = validBidRequests.map(ozoneBidRequest => { var obj = {}; let placementId = placementIdOverrideFromGetParam || this.getPlacementId(ozoneBidRequest); // prefer to use a valid override param, else the bidRequest placement Id obj.id = ozoneBidRequest.bidId; // this causes an error if we change it to something else, even if you update the bidRequest object: "WARNING: Bidder ozone made bid for unknown request ID: mb7953.859498327448. Ignoring." obj.tagid = placementId; obj.secure = window.location.protocol === 'https:' ? 1 : 0; + // is there a banner (or nothing declared, so banner is the default)? let arrBannerSizes = []; if (!ozoneBidRequest.hasOwnProperty('mediaTypes')) { if (ozoneBidRequest.hasOwnProperty('sizes')) { - logInfo('no mediaTypes detected - will use the sizes array in the config root'); + utils.logInfo('no mediaTypes detected - will use the sizes array in the config root'); arrBannerSizes = ozoneBidRequest.sizes; } else { - logInfo('no mediaTypes detected, no sizes array in the config root either. Cannot set sizes for banner type'); + utils.logInfo('no mediaTypes detected, no sizes array in the config root either. Cannot set sizes for banner type'); } } else { if (ozoneBidRequest.mediaTypes.hasOwnProperty(BANNER)) { arrBannerSizes = ozoneBidRequest.mediaTypes[BANNER].sizes; /* Note - if there is a sizes element in the config root it will be pushed into here */ - logInfo('setting banner size from the mediaTypes.banner element for bidId ' + obj.id + ': ', arrBannerSizes); + utils.logInfo('setting banner size from the mediaTypes.banner element for bidId ' + obj.id + ': ', arrBannerSizes); } if (ozoneBidRequest.mediaTypes.hasOwnProperty(VIDEO)) { - logInfo('openrtb 2.5 compliant video'); + utils.logInfo('openrtb 2.5 compliant video'); + // examine all the video attributes in the config, and either put them into obj.video if allowed by IAB2.5 or else in to obj.video.ext if (typeof ozoneBidRequest.mediaTypes[VIDEO] == 'object') { - let childConfig = deepAccess(ozoneBidRequest, 'params.video', {}); + let childConfig = utils.deepAccess(ozoneBidRequest, 'params.video', {}); obj.video = this.unpackVideoConfigIntoIABformat(ozoneBidRequest.mediaTypes[VIDEO], childConfig); obj.video = this.addVideoDefaults(obj.video, ozoneBidRequest.mediaTypes[VIDEO], childConfig); } + // we need to duplicate some of the video values let wh = getWidthAndHeightFromVideoObject(obj.video); - logInfo('setting video object from the mediaTypes.video element: ' + obj.id + ':', obj.video, 'wh=', wh); + utils.logInfo('setting video object from the mediaTypes.video element: ' + obj.id + ':', obj.video, 'wh=', wh); if (wh && typeof wh === 'object') { obj.video.w = wh['w']; obj.video.h = wh['h']; if (playerSizeIsNestedArray(obj.video)) { // this should never happen; it was in the original spec for this change though. - logInfo('setting obj.video.format to be an array of objects'); + utils.logInfo('setting obj.video.format to be an array of objects'); obj.video.ext.format = [wh]; } else { - logInfo('setting obj.video.format to be an object'); + utils.logInfo('setting obj.video.format to be an object'); obj.video.ext.format = wh; } } else { - logWarn('cannot set w, h & format values for video; the config is not right'); + utils.logWarn('cannot set w, h & format values for video; the config is not right'); } } + // Native integration is not complete yet if (ozoneBidRequest.mediaTypes.hasOwnProperty(NATIVE)) { obj.native = ozoneBidRequest.mediaTypes[NATIVE]; - logInfo('setting native object from the mediaTypes.native element: ' + obj.id + ':', obj.native); + utils.logInfo('setting native object from the mediaTypes.native element: ' + obj.id + ':', obj.native); } + // is the publisher specifying floors, and is the floors module enabled? if (ozoneBidRequest.hasOwnProperty('getFloor')) { - logInfo('This bidRequest object has property: getFloor'); + utils.logInfo('This bidRequest object has property: getFloor'); obj.floor = this.getFloorObjectForAuction(ozoneBidRequest); - logInfo('obj.floor is : ', obj.floor); + utils.logInfo('obj.floor is : ', obj.floor); } else { - logInfo('This bidRequest object DOES NOT have property: getFloor'); + utils.logInfo('This bidRequest object DOES NOT have property: getFloor'); } } if (arrBannerSizes.length > 0) { + // build the banner request using banner sizes we found in either possible location: obj.banner = { topframe: 1, w: arrBannerSizes[0][0] || 0, @@ -267,17 +274,20 @@ export const spec = { }) }; } + // these 3 MUST exist - we check them in the validation method obj.placementId = placementId; - deepSetValue(obj, 'ext.prebid', {'storedrequest': {'id': placementId}}); + // build the imp['ext'] object - NOTE - Dont obliterate anything that' already in obj.ext + utils.deepSetValue(obj, 'ext.prebid', {'storedrequest': {'id': placementId}}); + // obj.ext = {'prebid': {'storedrequest': {'id': placementId}}}; obj.ext[whitelabelBidder] = {}; obj.ext[whitelabelBidder].adUnitCode = ozoneBidRequest.adUnitCode; // eg. 'mpu' obj.ext[whitelabelBidder].transactionId = ozoneBidRequest.transactionId; // this is the transactionId PER adUnit, common across bidders for this unit if (ozoneBidRequest.params.hasOwnProperty('customData')) { obj.ext[whitelabelBidder].customData = ozoneBidRequest.params.customData; } - logInfo(`obj.ext.${whitelabelBidder} is `, obj.ext[whitelabelBidder]); + utils.logInfo(`obj.ext.${whitelabelBidder} is `, obj.ext[whitelabelBidder]); if (isTestMode != null) { - logInfo('setting isTestMode to ', isTestMode); + utils.logInfo('setting isTestMode to ', isTestMode); if (obj.ext[whitelabelBidder].hasOwnProperty('customData')) { for (let i = 0; i < obj.ext[whitelabelBidder].customData.length; i++) { obj.ext[whitelabelBidder].customData[i]['targeting'][wlOztestmodeKey] = isTestMode; @@ -287,52 +297,57 @@ export const spec = { obj.ext[whitelabelBidder].customData[0].targeting[wlOztestmodeKey] = isTestMode; } } - if (fpd && deepAccess(fpd, 'site')) { - logInfo('added fpd.site'); - if (deepAccess(obj, 'ext.' + whitelabelBidder + '.customData.0.targeting', false)) { + if (fpd && utils.deepAccess(fpd, 'site')) { + // attach the site fpd into exactly : imp[n].ext.[whitelabel].customData.0.targeting + utils.logInfo('added FPD site object'); + if (utils.deepAccess(obj, 'ext.' + whitelabelBidder + '.customData.0.targeting', false)) { obj.ext[whitelabelBidder].customData[0].targeting = Object.assign(obj.ext[whitelabelBidder].customData[0].targeting, fpd.site); + // let keys = utils.getKeys(fpd.site); + // for (let i = 0; i < keys.length; i++) { + // obj.ext[whitelabelBidder].customData[0].targeting[keys[i]] = fpd.site[keys[i]]; + // } } else { - deepSetValue(obj, 'ext.' + whitelabelBidder + '.customData.0.targeting', fpd.site); + utils.deepSetValue(obj, 'ext.' + whitelabelBidder + '.customData.0.targeting', fpd.site); } } - if (!schain && deepAccess(ozoneBidRequest, 'schain')) { - schain = ozoneBidRequest.schain; - } return obj; }); + // in v 2.0.0 we moved these outside of the individual ad slots let extObj = {}; extObj[whitelabelBidder] = {}; extObj[whitelabelBidder][whitelabelPrefix + '_pb_v'] = OZONEVERSION; extObj[whitelabelBidder][whitelabelPrefix + '_rw'] = placementIdOverrideFromGetParam ? 1 : 0; if (validBidRequests.length > 0) { let userIds = this.cookieSyncBag.userIdObject; // 2021-01-06 - slight optimisation - we've already found this info + // let userIds = this.findAllUserIds(validBidRequests[0]); if (userIds.hasOwnProperty('pubcid')) { extObj[whitelabelBidder].pubcid = userIds.pubcid; } } - extObj[whitelabelBidder].pv = this.getPageId(); // attach the page ID that will be common to all auciton calls for this page if refresh() is called let ozOmpFloorDollars = this.getWhitelabelConfigItem('ozone.oz_omp_floor'); // valid only if a dollar value (typeof == 'number') - logInfo(`${whitelabelPrefix}_omp_floor dollar value = `, ozOmpFloorDollars); + utils.logInfo(`${whitelabelPrefix}_omp_floor dollar value = `, ozOmpFloorDollars); if (typeof ozOmpFloorDollars === 'number') { extObj[whitelabelBidder][whitelabelPrefix + '_omp_floor'] = ozOmpFloorDollars; } else if (typeof ozOmpFloorDollars !== 'undefined') { - logError(`${whitelabelPrefix}_omp_floor is invalid - IF SET then this must be a number, representing dollar value eg. ${whitelabelPrefix}_omp_floor: 1.55. You have it set as a ` + (typeof ozOmpFloorDollars)); + utils.logError(`${whitelabelPrefix}_omp_floor is invalid - IF SET then this must be a number, representing dollar value eg. ${whitelabelPrefix}_omp_floor: 1.55. You have it set as a ` + (typeof ozOmpFloorDollars)); } let ozWhitelistAdserverKeys = this.getWhitelabelConfigItem('ozone.oz_whitelist_adserver_keys'); - let useOzWhitelistAdserverKeys = isArray(ozWhitelistAdserverKeys) && ozWhitelistAdserverKeys.length > 0; + let useOzWhitelistAdserverKeys = utils.isArray(ozWhitelistAdserverKeys) && ozWhitelistAdserverKeys.length > 0; extObj[whitelabelBidder][whitelabelPrefix + '_kvp_rw'] = useOzWhitelistAdserverKeys ? 1 : 0; if (whitelabelBidder != 'ozone') { - logInfo('setting aliases object'); + utils.logInfo('setting aliases object'); extObj.prebid = {aliases: {'ozone': whitelabelBidder}}; } + // 20210413 - adding a set of GET params to pass to auction if (getParams.hasOwnProperty('ozf')) { extObj[whitelabelBidder]['ozf'] = getParams.ozf == 'true' || getParams.ozf == 1 ? 1 : 0; } if (getParams.hasOwnProperty('ozpf')) { extObj[whitelabelBidder]['ozpf'] = getParams.ozpf == 'true' || getParams.ozpf == 1 ? 1 : 0; } if (getParams.hasOwnProperty('ozrp') && getParams.ozrp.match(/^[0-3]$/)) { extObj[whitelabelBidder]['ozrp'] = parseInt(getParams.ozrp); } if (getParams.hasOwnProperty('ozip') && getParams.ozip.match(/^\d+$/)) { extObj[whitelabelBidder]['ozip'] = parseInt(getParams.ozip); } if (this.propertyBag.endpointOverride != null) { extObj[whitelabelBidder]['origin'] = this.propertyBag.endpointOverride; } + // extObj.ortb2 = config.getConfig('ortb2'); // original test location var userExtEids = this.generateEids(validBidRequests); // generate the UserIDs in the correct format for UserId module ozoneRequest.site = { @@ -342,63 +357,64 @@ export const spec = { }; ozoneRequest.test = (getParams.hasOwnProperty('pbjs_debug') && getParams['pbjs_debug'] === 'true') ? 1 : 0; + // this should come as late as possible so it overrides any user.ext.consent value if (bidderRequest && bidderRequest.gdprConsent) { - logInfo('ADDING GDPR info'); - let apiVersion = deepAccess(bidderRequest, 'gdprConsent.apiVersion', 1); + utils.logInfo('ADDING GDPR info'); + let apiVersion = utils.deepAccess(bidderRequest, 'gdprConsent.apiVersion', 1); ozoneRequest.regs = {ext: {gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0, apiVersion: apiVersion}}; - if (deepAccess(ozoneRequest, 'regs.ext.gdpr')) { - deepSetValue(ozoneRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + if (utils.deepAccess(ozoneRequest, 'regs.ext.gdpr')) { + utils.deepSetValue(ozoneRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } else { - logInfo('**** Strange CMP info: bidderRequest.gdprConsent exists BUT bidderRequest.gdprConsent.gdprApplies is false. See bidderRequest logged above. ****'); + utils.logInfo('**** Strange CMP info: bidderRequest.gdprConsent exists BUT bidderRequest.gdprConsent.gdprApplies is false. See bidderRequest logged above. ****'); } } else { - logInfo('WILL NOT ADD GDPR info; no bidderRequest.gdprConsent object'); + utils.logInfo('WILL NOT ADD GDPR info; no bidderRequest.gdprConsent object'); } if (bidderRequest && bidderRequest.uspConsent) { - logInfo('ADDING CCPA info'); - deepSetValue(ozoneRequest, 'user.ext.uspConsent', bidderRequest.uspConsent); + utils.logInfo('ADDING CCPA info'); + utils.deepSetValue(ozoneRequest, 'user.ext.uspConsent', bidderRequest.uspConsent); } else { - logInfo('WILL NOT ADD CCPA info; no bidderRequest.uspConsent.'); - } - if (schain) { // we set this while iterating over the bids - logInfo('schain found'); - deepSetValue(ozoneRequest, 'source.ext.schain', schain); + utils.logInfo('WILL NOT ADD CCPA info; no bidderRequest.uspConsent.'); } + // this is for 2.2.1 + // coppa compliance if (config.getConfig('coppa') === true) { - deepSetValue(ozoneRequest, 'regs.coppa', 1); + utils.deepSetValue(ozoneRequest, 'regs.coppa', 1); } + // return the single request object OR the array: if (singleRequest) { - logInfo('buildRequests starting to generate response for a single request'); + utils.logInfo('buildRequests starting to generate response for a single request'); ozoneRequest.id = bidderRequest.auctionId; // Unique ID of the bid request, provided by the exchange. ozoneRequest.auctionId = bidderRequest.auctionId; // not sure if this should be here? ozoneRequest.imp = tosendtags; ozoneRequest.ext = extObj; - deepSetValue(ozoneRequest, 'source.tid', bidderRequest.auctionId);// RTB 2.5 : tid is Transaction ID that must be common across all participants in this bid request (e.g., potentially multiple exchanges). - deepSetValue(ozoneRequest, 'user.ext.eids', userExtEids); + ozoneRequest.source = {'tid': bidderRequest.auctionId}; // RTB 2.5 : tid is Transaction ID that must be common across all participants in this bid request (e.g., potentially multiple exchanges). + utils.deepSetValue(ozoneRequest, 'user.ext.eids', userExtEids); var ret = { method: 'POST', url: this.getAuctionUrl(), data: JSON.stringify(ozoneRequest), bidderRequest: bidderRequest }; - logInfo('buildRequests request data for single = ', JSON.parse(JSON.stringify(ozoneRequest))); + utils.logInfo('buildRequests request data for single = ', JSON.parse(JSON.stringify(ozoneRequest))); this.propertyBag.buildRequestsEnd = new Date().getTime(); - logInfo(`buildRequests going to return for single at time ${this.propertyBag.buildRequestsEnd} (took ${this.propertyBag.buildRequestsEnd - this.propertyBag.buildRequestsStart}ms): `, ret); + utils.logInfo(`buildRequests going to return for single at time ${this.propertyBag.buildRequestsEnd} (took ${this.propertyBag.buildRequestsEnd - this.propertyBag.buildRequestsStart}ms): `, ret); return ret; } + // not single request - pull apart the tosendtags array & return an array of objects each containing one element in the imp array. let arrRet = tosendtags.map(imp => { - logInfo('buildRequests starting to generate non-single response, working on imp : ', imp); + utils.logInfo('buildRequests starting to generate non-single response, working on imp : ', imp); let ozoneRequestSingle = Object.assign({}, ozoneRequest); imp.ext[whitelabelBidder].pageAuctionId = bidderRequest['auctionId']; // make a note in the ext object of what the original auctionId was, in the bidderRequest object ozoneRequestSingle.id = imp.ext[whitelabelBidder].transactionId; // Unique ID of the bid request, provided by the exchange. ozoneRequestSingle.auctionId = imp.ext[whitelabelBidder].transactionId; // not sure if this should be here? ozoneRequestSingle.imp = [imp]; ozoneRequestSingle.ext = extObj; - deepSetValue(ozoneRequestSingle, 'source.tid', imp.ext[whitelabelBidder].transactionId);// RTB 2.5 : tid is Transaction ID that must be common across all participants in this bid request (e.g., potentially multiple exchanges). - deepSetValue(ozoneRequestSingle, 'user.ext.eids', userExtEids); - logInfo('buildRequests RequestSingle (for non-single) = ', ozoneRequestSingle); + ozoneRequestSingle.source = {'tid': imp.ext[whitelabelBidder].transactionId}; + utils.deepSetValue(ozoneRequestSingle, 'user.ext.eids', userExtEids); + utils.logInfo('buildRequests RequestSingle (for non-single) = ', ozoneRequestSingle); return { method: 'POST', url: this.getAuctionUrl(), @@ -407,7 +423,7 @@ export const spec = { }; }); this.propertyBag.buildRequestsEnd = new Date().getTime(); - logInfo(`buildRequests going to return for non-single at time ${this.propertyBag.buildRequestsEnd} (took ${this.propertyBag.buildRequestsEnd - this.propertyBag.buildRequestsStart}ms): `, arrRet); + utils.logInfo(`buildRequests going to return for non-single at time ${this.propertyBag.buildRequestsEnd} (took ${this.propertyBag.buildRequestsEnd - this.propertyBag.buildRequestsStart}ms): `, arrRet); return arrRet; }, /** @@ -425,11 +441,11 @@ export const spec = { */ getFloorObjectForAuction(bidRequestRef) { const mediaTypesSizes = { - banner: deepAccess(bidRequestRef, 'mediaTypes.banner.sizes', null), - video: deepAccess(bidRequestRef, 'mediaTypes.video.playerSize', null), - native: deepAccess(bidRequestRef, 'mediaTypes.native.image.sizes', null) + banner: utils.deepAccess(bidRequestRef, 'mediaTypes.banner.sizes', null), + video: utils.deepAccess(bidRequestRef, 'mediaTypes.video.playerSize', null), + native: utils.deepAccess(bidRequestRef, 'mediaTypes.native.image.sizes', null) } - logInfo('getFloorObjectForAuction mediaTypesSizes : ', mediaTypesSizes); + utils.logInfo('getFloorObjectForAuction mediaTypesSizes : ', mediaTypesSizes); let ret = {}; if (mediaTypesSizes.banner) { ret.banner = bidRequestRef.getFloor({mediaType: 'banner', currency: 'USD', size: mediaTypesSizes.banner}); @@ -440,7 +456,7 @@ export const spec = { if (mediaTypesSizes.native) { ret.native = bidRequestRef.getFloor({mediaType: 'native', currency: 'USD', size: mediaTypesSizes.native}); } - logInfo('getFloorObjectForAuction returning : ', JSON.parse(JSON.stringify(ret))); + utils.logInfo('getFloorObjectForAuction returning : ', JSON.parse(JSON.stringify(ret))); return ret; }, /** @@ -458,9 +474,10 @@ export const spec = { let startTime = new Date().getTime(); let whitelabelBidder = this.propertyBag.whitelabel.bidder; // by default = ozone let whitelabelPrefix = this.propertyBag.whitelabel.keyPrefix; - logInfo(`interpretResponse time: ${startTime} . Time between buildRequests done and interpretResponse start was ${startTime - this.propertyBag.buildRequestsEnd}ms`); - logInfo(`serverResponse, request`, JSON.parse(JSON.stringify(serverResponse)), JSON.parse(JSON.stringify(request))); + utils.logInfo(`interpretResponse time: ${startTime} . Time between buildRequests done and interpretResponse start was ${startTime - this.propertyBag.buildRequestsEnd}ms`); + utils.logInfo(`serverResponse, request`, JSON.parse(JSON.stringify(serverResponse)), JSON.parse(JSON.stringify(request))); serverResponse = serverResponse.body || {}; + // note that serverResponse.id value is the auction_id we might want to use for reporting reasons. if (!serverResponse.hasOwnProperty('seatbid')) { return []; } @@ -469,48 +486,52 @@ export const spec = { } let arrAllBids = []; let enhancedAdserverTargeting = this.getWhitelabelConfigItem('ozone.enhancedAdserverTargeting'); - logInfo('enhancedAdserverTargeting', enhancedAdserverTargeting); + utils.logInfo('enhancedAdserverTargeting', enhancedAdserverTargeting); if (typeof enhancedAdserverTargeting == 'undefined') { enhancedAdserverTargeting = true; } - logInfo('enhancedAdserverTargeting', enhancedAdserverTargeting); + utils.logInfo('enhancedAdserverTargeting', enhancedAdserverTargeting); + // 2021-03-05 - comment this out for a build without adding adid to the response serverResponse.seatbid = injectAdIdsIntoAllBidResponses(serverResponse.seatbid); // we now make sure that each bid in the bidresponse has a unique (within page) adId attribute. serverResponse.seatbid = this.removeSingleBidderMultipleBids(serverResponse.seatbid); let ozOmpFloorDollars = this.getWhitelabelConfigItem('ozone.oz_omp_floor'); // valid only if a dollar value (typeof == 'number') let addOzOmpFloorDollars = typeof ozOmpFloorDollars === 'number'; let ozWhitelistAdserverKeys = this.getWhitelabelConfigItem('ozone.oz_whitelist_adserver_keys'); - let useOzWhitelistAdserverKeys = isArray(ozWhitelistAdserverKeys) && ozWhitelistAdserverKeys.length > 0; + let useOzWhitelistAdserverKeys = utils.isArray(ozWhitelistAdserverKeys) && ozWhitelistAdserverKeys.length > 0; for (let i = 0; i < serverResponse.seatbid.length; i++) { let sb = serverResponse.seatbid[i]; for (let j = 0; j < sb.bid.length; j++) { let thisRequestBid = this.getBidRequestForBidId(sb.bid[j].impid, request.bidderRequest.bids); - logInfo(`seatbid:${i}, bid:${j} Going to set default w h for seatbid/bidRequest`, sb.bid[j], thisRequestBid); + utils.logInfo(`seatbid:${i}, bid:${j} Going to set default w h for seatbid/bidRequest`, sb.bid[j], thisRequestBid); const {defaultWidth, defaultHeight} = defaultSize(thisRequestBid); let thisBid = ozoneAddStandardProperties(sb.bid[j], defaultWidth, defaultHeight); + // prebid 4.0 compliance thisBid.meta = {advertiserDomains: thisBid.adomain || []}; let videoContext = null; let isVideo = false; - let bidType = deepAccess(thisBid, 'ext.prebid.type'); - logInfo(`this bid type is : ${bidType}`, j); + let bidType = utils.deepAccess(thisBid, 'ext.prebid.type'); + utils.logInfo(`this bid type is : ${bidType}`, j); if (bidType === VIDEO) { isVideo = true; videoContext = this.getVideoContextForBidId(thisBid.bidId, request.bidderRequest.bids); // should be instream or outstream (or null if error) if (videoContext === 'outstream') { - logInfo('going to attach a renderer to OUTSTREAM video : ', j); + utils.logInfo('going to attach a renderer to OUTSTREAM video : ', j); thisBid.renderer = newRenderer(thisBid.bidId); } else { - logInfo('bid is not an outstream video, will not attach a renderer: ', j); + utils.logInfo('bid is not an outstream video, will not attach a renderer: ', j); } } let adserverTargeting = {}; if (enhancedAdserverTargeting) { let allBidsForThisBidid = ozoneGetAllBidsForBidId(thisBid.bidId, serverResponse.seatbid); - logInfo('Going to iterate allBidsForThisBidId', allBidsForThisBidid); + // add all the winning & non-winning bids for this bidId: + utils.logInfo('Going to iterate allBidsForThisBidId', allBidsForThisBidid); Object.keys(allBidsForThisBidid).forEach((bidderName, index, ar2) => { - logInfo(`adding adserverTargeting for ${bidderName} for bidId ${thisBid.bidId}`); + utils.logInfo(`adding adserverTargeting for ${bidderName} for bidId ${thisBid.bidId}`); + // let bidderName = bidderNameWH.split('_')[0]; adserverTargeting[whitelabelPrefix + '_' + bidderName] = bidderName; adserverTargeting[whitelabelPrefix + '_' + bidderName + '_crid'] = String(allBidsForThisBidid[bidderName].crid); adserverTargeting[whitelabelPrefix + '_' + bidderName + '_adv'] = String(allBidsForThisBidid[bidderName].adomain); @@ -525,11 +546,11 @@ export const spec = { if (isVideo) { adserverTargeting[whitelabelPrefix + '_' + bidderName + '_vid'] = videoContext; // outstream or instream } - let flr = deepAccess(allBidsForThisBidid[bidderName], `ext.bidder.${whitelabelBidder}.floor`, null); + let flr = utils.deepAccess(allBidsForThisBidid[bidderName], `ext.bidder.${whitelabelBidder}.floor`, null); if (flr != null) { adserverTargeting[whitelabelPrefix + '_' + bidderName + '_flr'] = flr; } - let rid = deepAccess(allBidsForThisBidid[bidderName], `ext.bidder.${whitelabelBidder}.ruleId`, null); + let rid = utils.deepAccess(allBidsForThisBidid[bidderName], `ext.bidder.${whitelabelBidder}.ruleId`, null); if (rid != null) { adserverTargeting[whitelabelPrefix + '_' + bidderName + '_rid'] = rid; } @@ -539,11 +560,12 @@ export const spec = { }); } else { if (useOzWhitelistAdserverKeys) { - logWarn(`You have set a whitelist of adserver keys but this will be ignored because ${whitelabelBidder}.enhancedAdserverTargeting is set to false. No per-bid keys will be sent to adserver.`); + utils.logWarn(`You have set a whitelist of adserver keys but this will be ignored because ${whitelabelBidder}.enhancedAdserverTargeting is set to false. No per-bid keys will be sent to adserver.`); } else { - logInfo(`${whitelabelBidder}.enhancedAdserverTargeting is set to false, so no per-bid keys will be sent to adserver.`); + utils.logInfo(`${whitelabelBidder}.enhancedAdserverTargeting is set to false, so no per-bid keys will be sent to adserver.`); } } + // also add in the winning bid, to be sent to dfp let {seat: winningSeat, bid: winningBid} = ozoneGetWinnerForRequestBid(thisBid.bidId, serverResponse.seatbid); adserverTargeting[whitelabelPrefix + '_auc_id'] = String(request.bidderRequest.auctionId); adserverTargeting[whitelabelPrefix + '_winner'] = String(winningSeat); @@ -558,7 +580,7 @@ export const spec = { adserverTargeting[whitelabelPrefix + '_size'] = `${winningBid.width}x${winningBid.height}`; } if (useOzWhitelistAdserverKeys) { // delete any un-whitelisted keys - logInfo('Going to filter out adserver targeting keys not in the whitelist: ', ozWhitelistAdserverKeys); + utils.logInfo('Going to filter out adserver targeting keys not in the whitelist: ', ozWhitelistAdserverKeys); Object.keys(adserverTargeting).forEach(function(key) { if (ozWhitelistAdserverKeys.indexOf(key) === -1) { delete adserverTargeting[key]; } }); } thisBid.adserverTargeting = adserverTargeting; @@ -566,20 +588,20 @@ export const spec = { } } let endTime = new Date().getTime(); - logInfo(`interpretResponse going to return at time ${endTime} (took ${endTime - startTime}ms) Time from buildRequests Start -> interpretRequests End = ${endTime - this.propertyBag.buildRequestsStart}ms`, arrAllBids); + utils.logInfo(`interpretResponse going to return at time ${endTime} (took ${endTime - startTime}ms) Time from buildRequests Start -> interpretRequests End = ${endTime - this.propertyBag.buildRequestsStart}ms`, arrAllBids); return arrAllBids; }, /** * Use this to get all config values * Now it's getting complicated with whitelabeling, this simplifies the code for getting config values. - * eg. to get whitelabelled version you just sent the ozone default string like ozone.oz_omp_floor + * eg. to get ozone.oz_omp_floor you just send '_omp_floor' * @param ozoneVersion string like 'ozone.oz_omp_floor' * @return {string|object} */ getWhitelabelConfigItem(ozoneVersion) { if (this.propertyBag.whitelabel.bidder == 'ozone') { return config.getConfig(ozoneVersion); } let whitelabelledSearch = ozoneVersion.replace('ozone', this.propertyBag.whitelabel.bidder); - whitelabelledSearch = whitelabelledSearch.replace('oz_', this.propertyBag.whitelabel.keyPrefix + '_'); + whitelabelledSearch = ozoneVersion.replace('oz_', this.propertyBag.whitelabel.keyPrefix + '_'); return config.getConfig(whitelabelledSearch); }, /** @@ -594,7 +616,7 @@ export const spec = { var bidIds = []; for (let j = 0; j < sb.bid.length; j++) { var candidate = sb.bid[j]; - if (contains(bidIds, candidate.impid)) { + if (utils.contains(bidIds, candidate.impid)) { continue; // we've already fully assessed this impid, found the highest bid from this seat for it } bidIds.push(candidate.impid); @@ -609,8 +631,10 @@ export const spec = { } return ret; }, + // see http://prebid.org/dev-docs/bidder-adaptor.html#registering-user-syncs + // us privacy: https://docs.prebid.org/dev-docs/modules/consentManagementUsp.html getUserSyncs(optionsType, serverResponse, gdprConsent, usPrivacy) { - logInfo('getUserSyncs optionsType', optionsType, 'serverResponse', serverResponse, 'gdprConsent', gdprConsent, 'usPrivacy', usPrivacy, 'cookieSyncBag', this.cookieSyncBag); + utils.logInfo('getUserSyncs optionsType', optionsType, 'serverResponse', serverResponse, 'gdprConsent', gdprConsent, 'usPrivacy', usPrivacy, 'cookieSyncBag', this.cookieSyncBag); if (!serverResponse || serverResponse.length === 0) { return []; } @@ -619,9 +643,14 @@ export const spec = { if (document.location.search.match(/pbjs_debug=true/)) { arrQueryString.push('pbjs_debug=true'); } - arrQueryString.push('gdpr=' + (deepAccess(gdprConsent, 'gdprApplies', false) ? '1' : '0')); - arrQueryString.push('gdpr_consent=' + deepAccess(gdprConsent, 'consentString', '')); + arrQueryString.push('gdpr=' + (utils.deepAccess(gdprConsent, 'gdprApplies', false) ? '1' : '0')); + arrQueryString.push('gdpr_consent=' + utils.deepAccess(gdprConsent, 'consentString', '')); arrQueryString.push('usp_consent=' + (usPrivacy || '')); + // var objKeys = Object.getOwnPropertyNames(this.cookieSyncBag.userIdObject); + // for (let idx in objKeys) { + // let keyname = objKeys[idx]; + // arrQueryString.push(keyname + '=' + this.cookieSyncBag.userIdObject[keyname]); + // } for (let keyname in this.cookieSyncBag.userIdObject) { arrQueryString.push(keyname + '=' + this.cookieSyncBag.userIdObject[keyname]); } @@ -634,7 +663,7 @@ export const spec = { if (strQueryString.length > 0) { strQueryString = '?' + strQueryString; } - logInfo('getUserSyncs going to return cookie sync url : ' + this.getCookieSyncUrl() + strQueryString); + utils.logInfo('getUserSyncs going to return cookie sync url : ' + this.getCookieSyncUrl() + strQueryString); return [{ type: 'iframe', url: this.getCookieSyncUrl() + strQueryString @@ -664,7 +693,7 @@ export const spec = { getVideoContextForBidId(bidId, arrBids) { let requestBid = this.getBidRequestForBidId(bidId, arrBids); if (requestBid != null) { - return deepAccess(requestBid, 'mediaTypes.video.context', 'unknown') + return utils.deepAccess(requestBid, 'mediaTypes.video.context', 'unknown') } return null; }, @@ -675,7 +704,10 @@ export const spec = { */ findAllUserIds(bidRequest) { var ret = {}; + // @todo - what is Neustar fabrick called & where to look for it? If it's a simple value then it will automatically be ok + // it is not in the table 'Bidder Adapter Implementation' on https://docs.prebid.org/dev-docs/modules/userId.html#prebidjs-adapters let searchKeysSingle = ['pubcid', 'tdid', 'idl_env', 'criteoId', 'lotamePanoramaId', 'fabrickId']; + if (bidRequest.hasOwnProperty('userId')) { for (let arrayId in searchKeysSingle) { let key = searchKeysSingle[arrayId]; @@ -683,36 +715,37 @@ export const spec = { if (typeof (bidRequest.userId[key]) == 'string') { ret[key] = bidRequest.userId[key]; } else if (typeof (bidRequest.userId[key]) == 'object') { - logError(`WARNING: findAllUserIds had to use first key in user object to get value for bid.userId key: ${key}. Prebid adapter should be updated.`); + utils.logError(`WARNING: findAllUserIds had to use first key in user object to get value for bid.userId key: ${key}. Prebid adapter should be updated.`); + // fallback - get the value of the first key in the object; this is NOT desirable behaviour ret[key] = bidRequest.userId[key][Object.keys(bidRequest.userId[key])[0]]; // cannot use Object.values } else { - logError(`failed to get string key value for userId : ${key}`); + utils.logError(`failed to get string key value for userId : ${key}`); } } } - let lipbid = deepAccess(bidRequest.userId, 'lipb.lipbid'); + let lipbid = utils.deepAccess(bidRequest.userId, 'lipb.lipbid'); if (lipbid) { ret['lipb'] = {'lipbid': lipbid}; } - let id5id = deepAccess(bidRequest.userId, 'id5id.uid'); + let id5id = utils.deepAccess(bidRequest.userId, 'id5id.uid'); if (id5id) { ret['id5id'] = id5id; } - let parrableId = deepAccess(bidRequest.userId, 'parrableId.eid'); + let parrableId = utils.deepAccess(bidRequest.userId, 'parrableId.eid'); if (parrableId) { ret['parrableId'] = parrableId; } - let sharedid = deepAccess(bidRequest.userId, 'sharedid.id'); + let sharedid = utils.deepAccess(bidRequest.userId, 'sharedid.id'); if (sharedid) { ret['sharedid'] = sharedid; } - let sharedidthird = deepAccess(bidRequest.userId, 'sharedid.third'); + let sharedidthird = utils.deepAccess(bidRequest.userId, 'sharedid.third'); if (sharedidthird) { ret['sharedidthird'] = sharedidthird; } } if (!ret.hasOwnProperty('pubcid')) { - let pubcid = deepAccess(bidRequest, 'crumbs.pubcid'); + let pubcid = utils.deepAccess(bidRequest, 'crumbs.pubcid'); if (pubcid) { ret['pubcid'] = pubcid; // if built with old pubCommonId module } @@ -738,10 +771,10 @@ export const spec = { let arr = this.getGetParametersAsObject(); if (arr.hasOwnProperty(whitelabelPrefix + 'storedrequest')) { if (this.isValidPlacementId(arr[whitelabelPrefix + 'storedrequest'])) { - logInfo(`using GET ${whitelabelPrefix}storedrequest ` + arr[whitelabelPrefix + 'storedrequest'] + ' to replace placementId'); + utils.logInfo(`using GET ${whitelabelPrefix}storedrequest ` + arr[whitelabelPrefix + 'storedrequest'] + ' to replace placementId'); return arr[whitelabelPrefix + 'storedrequest']; } else { - logError(`GET ${whitelabelPrefix}storedrequest FAILED VALIDATION - will not use it`); + utils.logError(`GET ${whitelabelPrefix}storedrequest FAILED VALIDATION - will not use it`); } } return null; @@ -764,9 +797,9 @@ export const spec = { handleTTDId(eids, validBidRequests) { let ttdId = null; let adsrvrOrgId = config.getConfig('adsrvrOrgId'); - if (isStr(deepAccess(validBidRequests, '0.userId.tdid'))) { + if (utils.isStr(utils.deepAccess(validBidRequests, '0.userId.tdid'))) { ttdId = validBidRequests[0].userId.tdid; - } else if (adsrvrOrgId && isStr(adsrvrOrgId.TDID)) { + } else if (adsrvrOrgId && utils.isStr(adsrvrOrgId.TDID)) { ttdId = adsrvrOrgId.TDID; } if (ttdId !== null) { @@ -782,6 +815,7 @@ export const spec = { }); } }, + // Try to use this as the mechanism for reading GET params because it's easy to mock it for tests getGetParametersAsObject() { let items = location.search.substr(1).split('&'); let ret = {}; @@ -797,9 +831,10 @@ export const spec = { * @return {boolean|*[]} true = block the request, else false */ blockTheRequest() { + // if there is an ozone.oz_request = false then quit now. let ozRequest = this.getWhitelabelConfigItem('ozone.oz_request'); if (typeof ozRequest == 'boolean' && !ozRequest) { - logWarn(`Will not allow auction : ${this.propertyBag.whitelabel.keyPrefix}one.${this.propertyBag.whitelabel.keyPrefix}_request is set to false`); + utils.logWarn(`Will not allow auction : ${this.propertyBag.whitelabel.keyPrefix}one.${this.propertyBag.whitelabel.keyPrefix}_request is set to false`); return true; } return false; @@ -847,9 +882,10 @@ export const spec = { ret.ext[key] = objConfig[key]; } } + // handle ext separately, if it exists; we have probably built up an ext object already if (objConfig.hasOwnProperty('ext') && typeof objConfig.ext === 'object') { if (objConfig.hasOwnProperty('ext')) { - ret.ext = mergeDeep(ret.ext, objConfig.ext); + ret.ext = utils.mergeDeep(ret.ext, objConfig.ext); } else { ret.ext = objConfig.ext; } @@ -870,13 +906,14 @@ export const spec = { * @private */ _addVideoDefaults(objRet, objConfig, addIfMissing) { - let context = deepAccess(objConfig, 'context'); + // add inferred values & any default values we want. + let context = utils.deepAccess(objConfig, 'context'); if (context === 'outstream') { objRet.placement = 3; } else if (context === 'instream') { objRet.placement = 1; } - let skippable = deepAccess(objConfig, 'skippable', null); + let skippable = utils.deepAccess(objConfig, 'skippable', null); if (skippable == null) { if (addIfMissing && !objRet.hasOwnProperty('skip')) { objRet.skip = skippable ? 1 : 0; @@ -895,10 +932,12 @@ export const spec = { * @returns seatbid object */ export function injectAdIdsIntoAllBidResponses(seatbid) { - logInfo('injectAdIdsIntoAllBidResponses', seatbid); + utils.logInfo('injectAdIdsIntoAllBidResponses', seatbid); for (let i = 0; i < seatbid.length; i++) { let sb = seatbid[i]; for (let j = 0; j < sb.bid.length; j++) { + // modify the bidId per-bid, so each bid has a unique adId within this response, and dfp can select one. + // 2020-06 we now need a second level of ID because there might be multiple identical impid's within a seatbid! sb.bid[j]['adId'] = `${sb.bid[j]['impid']}-${i}-${spec.propertyBag.whitelabel.keyPrefix}-${j}`; } } @@ -919,7 +958,7 @@ export function checkDeepArray(Arr) { export function defaultSize(thebidObj) { if (!thebidObj) { - logInfo('defaultSize received empty bid obj! going to return fixed default size'); + utils.logInfo('defaultSize received empty bid obj! going to return fixed default size'); return { 'defaultHeight': 250, 'defaultWidth': 300 @@ -946,6 +985,7 @@ export function ozoneGetWinnerForRequestBid(requestBidId, serverResponseSeatBid) let thisSeat = serverResponseSeatBid[j].seat; for (let k = 0; k < theseBids.length; k++) { if (theseBids[k].impid === requestBidId) { + // we've found a matching server response bid for this request bid if ((thisBidWinner == null) || (thisBidWinner.price < theseBids[k].price)) { thisBidWinner = theseBids[k]; winningSeat = thisSeat; @@ -971,6 +1011,7 @@ export function ozoneGetAllBidsForBidId(matchBidId, serverResponseSeatBid) { for (let k = 0; k < theseBids.length; k++) { if (theseBids[k].impid === matchBidId) { if (objBids.hasOwnProperty(thisSeat)) { // > 1 bid for an adunit from a bidder - only use the one with the highest bid + // objBids[`${thisSeat}${theseBids[k].w}x${theseBids[k].h}`] = theseBids[k]; if (objBids[thisSeat]['price'] < theseBids[k].price) { objBids[thisSeat] = theseBids[k]; } @@ -995,14 +1036,15 @@ export function getRoundedBid(price, mediaType) { let theConfigObject = getGranularityObject(mediaType, mediaTypeGranularity, strBuckets, objBuckets); let theConfigKey = getGranularityKeyName(mediaType, mediaTypeGranularity, strBuckets); - logInfo('getRoundedBid. price:', price, 'mediaType:', mediaType, 'configkey:', theConfigKey, 'configObject:', theConfigObject, 'mediaTypeGranularity:', mediaTypeGranularity, 'strBuckets:', strBuckets); + utils.logInfo('getRoundedBid. price:', price, 'mediaType:', mediaType, 'configkey:', theConfigKey, 'configObject:', theConfigObject, 'mediaTypeGranularity:', mediaTypeGranularity, 'strBuckets:', strBuckets); let priceStringsObj = getPriceBucketString( price, theConfigObject, config.getConfig('currency.granularityMultiplier') ); - logInfo('priceStringsObj', priceStringsObj); + utils.logInfo('priceStringsObj', priceStringsObj); + // by default, without any custom granularity set, you get granularity name : 'medium' let granularityNamePriceStringsKeyMapping = { 'medium': 'med', 'custom': 'custom', @@ -1012,7 +1054,7 @@ export function getRoundedBid(price, mediaType) { }; if (granularityNamePriceStringsKeyMapping.hasOwnProperty(theConfigKey)) { let priceStringsKey = granularityNamePriceStringsKeyMapping[theConfigKey]; - logInfo('getRoundedBid: looking for priceStringsKey:', priceStringsKey); + utils.logInfo('getRoundedBid: looking for priceStringsKey:', priceStringsKey); return priceStringsObj[priceStringsKey]; } return priceStringsObj['auto']; @@ -1081,15 +1123,15 @@ export function getWidthAndHeightFromVideoObject(objVideo) { return null; } if (playerSize[0] && typeof playerSize[0] === 'object') { - logInfo('getWidthAndHeightFromVideoObject found nested array inside playerSize.', playerSize[0]); + utils.logInfo('getWidthAndHeightFromVideoObject found nested array inside playerSize.', playerSize[0]); playerSize = playerSize[0]; if (typeof playerSize[0] !== 'number' && typeof playerSize[0] !== 'string') { - logInfo('getWidthAndHeightFromVideoObject found non-number/string type inside the INNER array in playerSize. This is totally wrong - cannot continue.', playerSize[0]); + utils.logInfo('getWidthAndHeightFromVideoObject found non-number/string type inside the INNER array in playerSize. This is totally wrong - cannot continue.', playerSize[0]); return null; } } if (playerSize.length !== 2) { - logInfo('getWidthAndHeightFromVideoObject found playerSize with length of ' + playerSize.length + '. This is totally wrong - cannot continue.'); + utils.logInfo('getWidthAndHeightFromVideoObject found playerSize with length of ' + playerSize.length + '. This is totally wrong - cannot continue.'); return null; } return ({'w': playerSize[0], 'h': playerSize[1]}); @@ -1116,17 +1158,17 @@ export function playerSizeIsNestedArray(objVideo) { * @returns {*} */ function getPlayerSizeFromObject(objVideo) { - logInfo('getPlayerSizeFromObject received object', objVideo); - let playerSize = deepAccess(objVideo, 'playerSize'); + utils.logInfo('getPlayerSizeFromObject received object', objVideo); + let playerSize = utils.deepAccess(objVideo, 'playerSize'); if (!playerSize) { - playerSize = deepAccess(objVideo, 'ext.playerSize'); + playerSize = utils.deepAccess(objVideo, 'ext.playerSize'); } if (!playerSize) { - logError('getPlayerSizeFromObject FAILED: no playerSize in video object or ext', objVideo); + utils.logError('getPlayerSizeFromObject FAILED: no playerSize in video object or ext', objVideo); return null; } if (typeof playerSize !== 'object') { - logError('getPlayerSizeFromObject FAILED: playerSize is not an object/array', objVideo); + utils.logError('getPlayerSizeFromObject FAILED: playerSize is not an object/array', objVideo); return null; } return playerSize; @@ -1137,7 +1179,7 @@ function getPlayerSizeFromObject(objVideo) { */ function newRenderer(adUnitCode, rendererOptions = {}) { let isLoaded = window.ozoneVideo; - logInfo(`newRenderer going to set loaded to ${isLoaded ? 'true' : 'false'}`); + utils.logInfo(`newRenderer going to set loaded to ${isLoaded ? 'true' : 'false'}`); const renderer = Renderer.install({ url: spec.getRendererUrl(), config: rendererOptions, @@ -1147,16 +1189,17 @@ function newRenderer(adUnitCode, rendererOptions = {}) { try { renderer.setRender(outstreamRender); } catch (err) { - logError('Prebid Error when calling setRender on renderer', JSON.parse(JSON.stringify(renderer)), err); + utils.logError('Prebid Error when calling setRender on renderer', JSON.parse(JSON.stringify(renderer)), err); } return renderer; } function outstreamRender(bid) { - logInfo('outstreamRender called. Going to push the call to window.ozoneVideo.outstreamRender(bid) bid =', JSON.parse(JSON.stringify(bid))); + utils.logInfo('outstreamRender called. Going to push the call to window.ozoneVideo.outstreamRender(bid) bid =', JSON.parse(JSON.stringify(bid))); + // push to render queue because ozoneVideo may not be loaded yet bid.renderer.push(() => { window.ozoneVideo.outstreamRender(bid); }); } registerBidder(spec); -logInfo(`*BidAdapter ${OZONEVERSION} was loaded`); +utils.logInfo(`*BidAdapter ${OZONEVERSION} was loaded`); diff --git a/modules/padsquadBidAdapter.js b/modules/padsquadBidAdapter.js index 72449cf28be..24b1d5be3be 100644 --- a/modules/padsquadBidAdapter.js +++ b/modules/padsquadBidAdapter.js @@ -1,5 +1,5 @@ -import { logInfo, deepAccess } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {BANNER} from '../src/mediaTypes.js'; const ENDPOINT_URL = 'https://x.padsquad.com/auction'; @@ -89,12 +89,12 @@ export const spec = { }) }) } else { - logInfo('padsquad.interpretResponse :: no valid responses to interpret'); + utils.logInfo('padsquad.interpretResponse :: no valid responses to interpret'); } return bidResponses; }, getUserSyncs: function (syncOptions, serverResponses) { - logInfo('padsquad.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses); + utils.logInfo('padsquad.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses); let syncs = []; if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { @@ -102,7 +102,7 @@ export const spec = { } serverResponses.forEach(resp => { - const userSync = deepAccess(resp, 'body.ext.usersync'); + const userSync = utils.deepAccess(resp, 'body.ext.usersync'); if (userSync) { let syncDetails = []; Object.keys(userSync).forEach(key => { diff --git a/modules/parrableIdSystem.js b/modules/parrableIdSystem.js index b1553bcb134..1d74061e544 100644 --- a/modules/parrableIdSystem.js +++ b/modules/parrableIdSystem.js @@ -7,7 +7,7 @@ // ci trigger: 1 -import { timestamp, logError, logWarn, isEmpty, contains, inIframe, deepClone, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js' import find from 'core-js-pure/features/array/find.js'; import { ajax } from '../src/ajax.js'; import { submodule } from '../src/hook.js'; @@ -26,7 +26,7 @@ const EXPIRE_COOKIE_DATE = 'Thu, 01 Jan 1970 00:00:00 GMT'; const storage = getStorageManager(PARRABLE_GVLID); function getExpirationDate() { - const oneYearFromNow = new Date(timestamp() + ONE_YEAR_MS); + const oneYearFromNow = new Date(utils.timestamp() + ONE_YEAR_MS); return oneYearFromNow.toGMTString(); } @@ -76,15 +76,15 @@ function serializeParrableId(parrableIdAndParams) { function isValidConfig(configParams) { if (!configParams) { - logError('User ID - parrableId submodule requires configParams'); + utils.logError('User ID - parrableId submodule requires configParams'); return false; } if (!configParams.partners && !configParams.partner) { - logError('User ID - parrableId submodule requires partner list'); + utils.logError('User ID - parrableId submodule requires partner list'); return false; } if (configParams.storage) { - logWarn('User ID - parrableId submodule does not require a storage config'); + utils.logWarn('User ID - parrableId submodule does not require a storage config'); } return true; } @@ -177,28 +177,28 @@ function shouldFilterImpression(configParams, parrableId) { } function isAllowed() { - if (isEmpty(config.allowedZones) && - isEmpty(config.allowedOffsets)) { + if (utils.isEmpty(config.allowedZones) && + utils.isEmpty(config.allowedOffsets)) { return true; } if (isZoneListed(config.allowedZones, zone)) { return true; } - if (contains(config.allowedOffsets, offset)) { + if (utils.contains(config.allowedOffsets, offset)) { return true; } return false; } function isBlocked() { - if (isEmpty(config.blockedZones) && - isEmpty(config.blockedOffsets)) { + if (utils.isEmpty(config.blockedZones) && + utils.isEmpty(config.blockedOffsets)) { return false; } if (isZoneListed(config.blockedZones, zone)) { return true; } - if (contains(config.blockedOffsets, offset)) { + if (utils.contains(config.blockedOffsets, offset)) { return true; } return false; @@ -246,7 +246,7 @@ function fetchId(configParams, gdprConsentData) { trackers, url: refererInfo.referer, prebidVersion: '$prebid.version$', - isIframe: inIframe(), + isIframe: utils.inIframe(), tpcSupport }; @@ -276,7 +276,7 @@ function fetchId(configParams, gdprConsentData) { const callback = function (cb) { const callbacks = { success: response => { - let newParrableId = parrableId ? deepClone(parrableId) : {}; + let newParrableId = parrableId ? utils.deepClone(parrableId) : {}; let newParams = {}; if (response) { try { @@ -301,18 +301,18 @@ function fetchId(configParams, gdprConsentData) { } } } catch (error) { - logError(error); + utils.logError(error); cb(); } writeCookie({ ...newParrableId, ...newParams }); cb(newParrableId); } else { - logError('parrableId: ID fetch returned an empty result'); + utils.logError('parrableId: ID fetch returned an empty result'); cb(); } }, error: error => { - logError(`parrableId: ID fetch encountered an error`, error); + utils.logError(`parrableId: ID fetch encountered an error`, error); cb(); } }; @@ -350,7 +350,7 @@ export const parrableIdSubmodule = { * @return {(Object|undefined} */ decode(parrableId) { - if (parrableId && isPlainObject(parrableId)) { + if (parrableId && utils.isPlainObject(parrableId)) { return { parrableId }; } return undefined; diff --git a/modules/pixfutureBidAdapter.js b/modules/pixfutureBidAdapter.js index e9db875fc2f..e5422f36358 100644 --- a/modules/pixfutureBidAdapter.js +++ b/modules/pixfutureBidAdapter.js @@ -3,7 +3,7 @@ import { getStorageManager } from '../src/storageManager.js'; import { BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import includes from 'core-js-pure/features/array/includes.js'; -import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, deepAccess, isEmpty, transformBidderParamKeywords, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { auctionManager } from '../src/auctionManager.js'; import find from 'core-js-pure/features/array/find.js'; @@ -12,7 +12,7 @@ const storageManager = getStorageManager(); const USER_PARAMS = ['age', 'externalUid', 'segments', 'gender', 'dnt', 'language']; export const spec = { code: 'pixfuture', - hostname: 'https://gosrv.pixfuture.com', + hostname: 'https://prebid-js.pixfuture.com', getHostname() { let ret = this.hostname; @@ -47,13 +47,13 @@ export const spec = { Object.keys(userObjBid.params.user) .filter(param => includes(USER_PARAMS, param)) .forEach((param) => { - let uparam = convertCamelToUnderscore(param); - if (param === 'segments' && isArray(userObjBid.params.user[param])) { + let uparam = utils.convertCamelToUnderscore(param); + if (param === 'segments' && utils.isArray(userObjBid.params.user[param])) { let segs = []; userObjBid.params.user[param].forEach(val => { - if (isNumber(val)) { + if (utils.isNumber(val)) { segs.push({'id': val}); - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { segs.push(val); } }); @@ -77,7 +77,7 @@ export const spec = { }; if (bidderRequest && bidderRequest.uspConsent) { - payload.us_privacy = bidderRequest.uspConsent; + payload.us_privacy = bidderRequest.uspConsent } if (bidderRequest && bidderRequest.refererInfo) { @@ -93,14 +93,14 @@ export const spec = { if (validBidRequests[0].userId) { let eids = []; - addUserId(eids, deepAccess(validBidRequests[0], `userId.flocId.id`), 'chrome.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.criteoId`), 'criteo.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.unifiedId`), 'thetradedesk.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.id5Id`), 'id5.io', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.sharedId`), 'thetradedesk.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.identityLink`), 'liveramp.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.liveIntentId`), 'liveintent.com', null); - addUserId(eids, deepAccess(validBidRequests[0], `userId.fabrickId`), 'home.neustar', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.flocId.id`), 'chrome.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.criteoId`), 'criteo.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.unifiedId`), 'thetradedesk.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.id5Id`), 'id5.io', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.sharedId`), 'thetradedesk.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.identityLink`), 'liveramp.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.liveIntentId`), 'liveintent.com', null); + addUserId(eids, utils.deepAccess(validBidRequests[0], `userId.fabrickId`), 'home.neustar', null); if (eids.length) { payload.eids = eids; @@ -112,7 +112,7 @@ export const spec = { } const ret = { - url: `${hostname}/pixservices`, + url: `${hostname}/`, method: 'POST', options: {withCredentials: false}, data: { @@ -153,16 +153,6 @@ export const spec = { return bids; }, - getUserSyncs: function (syncOptions, bid, gdprConsent) { - var pixid = ''; - if (typeof bid[0] === 'undefined' || bid[0] === null) { pixid = '0'; } else { pixid = bid[0].body.pix_id; } - if (syncOptions.iframeEnabled && hasPurpose1Consent({gdprConsent})) { - return [{ - type: 'iframe', - url: 'https://gosrv.pixfuture.com/cookiesync?adsync=' + gdprConsent.consentString + '&pixid=' + pixid + '&gdprconcent=' + gdprConsent.gdprApplies - }]; - } - } }; function newBid(serverBid, rtbBid, placementId, uuid) { @@ -189,16 +179,6 @@ function newBid(serverBid, rtbBid, placementId, uuid) { return bid; } -function hasPurpose1Consent(bidderRequest) { - let result = true; - if (bidderRequest && bidderRequest.gdprConsent) { - if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - result = !!(deepAccess(bidderRequest.gdprConsent, 'vendorData.purpose.consents.1') === true); - } - } - return result; -} - // Functions related optional parameters function bidToTag(bid) { const tag = {}; @@ -243,8 +223,8 @@ function bidToTag(bid) { if (bid.params.externalImpId) { tag.external_imp_id = bid.params.externalImpId; } - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); + if (!utils.isEmpty(bid.params.keywords)) { + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); @@ -252,7 +232,7 @@ function bidToTag(bid) { tag.keywords = keywords; } - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); if (gpid) { tag.gpid = gpid; } @@ -261,7 +241,7 @@ function bidToTag(bid) { tag.video = Object.assign({}, tag.video, {custom_renderer_present: true}); } - if (bid.params.frameworks && isArray(bid.params.frameworks)) { + if (bid.params.frameworks && utils.isArray(bid.params.frameworks)) { tag['banner_frameworks'] = bid.params.frameworks; } @@ -296,8 +276,8 @@ function transformSizes(requestSizes) { let sizes = []; let sizeObj = {}; - if (isArray(requestSizes) && requestSizes.length === 2 && - !isArray(requestSizes[0])) { + if (utils.isArray(requestSizes) && requestSizes.length === 2 && + !utils.isArray(requestSizes[0])) { sizeObj.width = parseInt(requestSizes[0], 10); sizeObj.height = parseInt(requestSizes[1], 10); sizes.push(sizeObj); @@ -315,7 +295,7 @@ function transformSizes(requestSizes) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return (bid.params.reserve) ? bid.params.reserve : null; } @@ -324,7 +304,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; @@ -337,7 +317,7 @@ function deleteValues(keyPairObj) { } function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); + return !!(utils.isArray(arr) && arr.length > 0); } registerBidder(spec); diff --git a/modules/pixfutureBidAdapter.md b/modules/pixfutureBidAdapter.md index b7911d6c9bb..e5728ededc6 100644 --- a/modules/pixfutureBidAdapter.md +++ b/modules/pixfutureBidAdapter.md @@ -25,130 +25,3 @@ var adUnits = [{ "pix_id": "Abc123" }]; ``` - -# Test Example -... - - - - - - - - - - - -

Basic Prebid.js Example

-
Div-1
-
- -
- -
- -
Div-2
-
- -
- - - - diff --git a/modules/playwireBidAdapter.md b/modules/playwireBidAdapter.md deleted file mode 100644 index dddb57c9bc1..00000000000 --- a/modules/playwireBidAdapter.md +++ /dev/null @@ -1,61 +0,0 @@ -# Overview - -Module Name: Playwire Bidder Adapter -Module Type: Bidder Adapter -Maintainer: grid-tech@themediagrid.com - -# Description - -Module that connects to Grid demand source to fetch bids. -The adapter is GDPR compliant and supports banner and video (instream and outstream). - -# Test Parameters -``` - var adUnits = [ - { - code: 'test-div', - sizes: [[300, 250]], - bids: [ - { - bidder: "playwire", - params: { - uid: '1', - bidFloor: 0.5 - } - } - ] - },{ - code: 'test-div', - sizes: [[728, 90]], - bids: [ - { - bidder: "playwire", - params: { - uid: 2, - keywords: { - brandsafety: ['disaster'], - topic: ['stress', 'fear'] - } - } - } - ] - }, - { - code: 'test-div', - sizes: [[728, 90]], - mediaTypes: { video: { - context: 'instream', - playerSize: [728, 90], - mimes: ['video/mp4'] - }, - bids: [ - { - bidder: "playwire", - params: { - uid: 11 - } - } - ] - } - ]; -``` diff --git a/modules/prebidServerBidAdapter/index.js b/modules/prebidServerBidAdapter/index.js index efe2576efd5..246127e443d 100644 --- a/modules/prebidServerBidAdapter/index.js +++ b/modules/prebidServerBidAdapter/index.js @@ -1,11 +1,6 @@ import Adapter from '../../src/adapter.js'; import { createBid } from '../../src/bidfactory.js'; -import { - getPrebidInternal, logError, isStr, isPlainObject, logWarn, generateUUID, bind, logMessage, - triggerPixel, insertUserSyncIframe, deepAccess, mergeDeep, deepSetValue, cleanObj, parseSizesInput, - getBidRequest, getDefinedParams, createTrackPixelHtml, pick, deepClone, uniques, flatten, isNumber, - isEmpty, isArray, logInfo -} from '../../src/utils.js'; +import * as utils from '../../src/utils.js'; import CONSTANTS from '../../src/constants.json'; import adapterManager from '../../src/adapterManager.js'; import { config } from '../../src/config.js'; @@ -17,6 +12,7 @@ import includes from 'core-js-pure/features/array/includes.js'; import { S2S_VENDORS } from './config.js'; import { ajax } from '../../src/ajax.js'; import find from 'core-js-pure/features/array/find.js'; +import { getPrebidInternal } from '../../src/utils.js'; const getConfig = config.getConfig; @@ -56,7 +52,6 @@ let eidPermissions; * @property {string} [adapter='prebidServer'] adapter code to use for S2S * @property {boolean} [enabled=false] enables S2S bidding * @property {number} [timeout=1000] timeout for S2S bidders - should be lower than `pbjs.requestBids({timeout})` - * @property {number} [syncTimeout=1000] timeout for cookie sync iframe / image rendering * @property {number} [maxBids=1] * @property {AdapterOptions} [adapterOptions] adds arguments to resulting OpenRTB payload to Prebid Server * @property {Object} [syncUrlModifier] @@ -78,7 +73,6 @@ let eidPermissions; */ const s2sDefaultConfig = { timeout: 1000, - syncTimeout: 1000, maxBids: 1, adapter: 'prebidServer', adapterOptions: {}, @@ -106,7 +100,7 @@ function updateConfigDefaultVendor(option) { } }); } else { - logError('Incorrect or unavailable prebid server default vendor option: ' + vendor); + utils.logError('Incorrect or unavailable prebid server default vendor option: ' + vendor); return false; } } @@ -122,7 +116,7 @@ function validateConfigRequiredProps(option) { const keys = Object.keys(option); if (['accountId', 'bidders', 'endpoint'].filter(key => { if (!includes(keys, key)) { - logError(key + ' missing in server to server config'); + utils.logError(key + ' missing in server to server config'); return true; } return false; @@ -135,14 +129,14 @@ function validateConfigRequiredProps(option) { // could be removed later as part of a major release, if we decide to not support the old format function formatUrlParams(option) { ['endpoint', 'syncEndpoint'].forEach((prop) => { - if (isStr(option[prop])) { + if (utils.isStr(option[prop])) { let temp = option[prop]; option[prop] = { p1Consent: temp, noP1Consent: temp }; } - if (isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) { + if (utils.isPlainObject(option[prop]) && (!option[prop].p1Consent || !option[prop].noP1Consent)) { ['p1Consent', 'noP1Consent'].forEach((conUrl) => { if (!option[prop][conUrl]) { - logWarn(`s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios.`); + utils.logWarn(`s2sConfig.${prop}.${conUrl} not defined. PBS request will be skipped in some P1 scenarios.`); } }); } @@ -177,7 +171,7 @@ function setS2sConfig(options) { return true; } } - logWarn('prebidServer: s2s config is disabled'); + utils.logWarn('prebidServer: s2s config is disabled'); return false; }); @@ -204,13 +198,13 @@ function queueSync(bidderCodes, gdprConsent, uspConsent, s2sConfig) { _syncCount++; const payload = { - uuid: generateUUID(), + uuid: utils.generateUUID(), bidders: bidderCodes, account: s2sConfig.accountId }; let userSyncLimit = s2sConfig.userSyncLimit; - if (isNumber(userSyncLimit) && userSyncLimit > 0) { + if (utils.isNumber(userSyncLimit) && userSyncLimit > 0) { payload['limit'] = userSyncLimit; } @@ -238,7 +232,7 @@ function queueSync(bidderCodes, gdprConsent, uspConsent, s2sConfig) { response = JSON.parse(response); doAllSyncs(response.bidder_status, s2sConfig); } catch (e) { - logError(e); + utils.logError(e); } }, jsonPayload, @@ -258,7 +252,7 @@ function doAllSyncs(bidders, s2sConfig) { // if PBS reports this bidder doesn't have an ID, then call the sync and recurse to the next sync entry if (thisSync.no_cookie) { - doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, bind.call(doAllSyncs, null, bidders, s2sConfig), s2sConfig); + doPreBidderSync(thisSync.usersync.type, thisSync.usersync.url, thisSync.bidder, utils.bind.call(doAllSyncs, null, bidders, s2sConfig), s2sConfig); } else { // bidder already has an ID, so just recurse to the next sync entry doAllSyncs(bidders, s2sConfig); @@ -276,9 +270,11 @@ function doAllSyncs(bidders, s2sConfig) { */ function doPreBidderSync(type, url, bidder, done, s2sConfig) { if (s2sConfig.syncUrlModifier && typeof s2sConfig.syncUrlModifier[bidder] === 'function') { - url = s2sConfig.syncUrlModifier[bidder](type, url, bidder); + const newSyncUrl = s2sConfig.syncUrlModifier[bidder](type, url, bidder); + doBidderSync(type, newSyncUrl, bidder, done) + } else { + doBidderSync(type, url, bidder, done) } - doBidderSync(type, url, bidder, done, s2sConfig.syncTimeout) } /** @@ -288,20 +284,19 @@ function doPreBidderSync(type, url, bidder, done, s2sConfig) { * @param {string} url the url to sync * @param {string} bidder name of bidder doing sync for * @param {function} done an exit callback; to signify this pixel has either: finished rendering or something went wrong - * @param {number} timeout: maximum time to wait for rendering in milliseconds */ -function doBidderSync(type, url, bidder, done, timeout) { +function doBidderSync(type, url, bidder, done) { if (!url) { - logError(`No sync url for bidder "${bidder}": ${url}`); + utils.logError(`No sync url for bidder "${bidder}": ${url}`); done(); } else if (type === 'image' || type === 'redirect') { - logMessage(`Invoking image pixel user sync for bidder: "${bidder}"`); - triggerPixel(url, done, timeout); - } else if (type === 'iframe') { - logMessage(`Invoking iframe user sync for bidder: "${bidder}"`); - insertUserSyncIframe(url, done, timeout); + utils.logMessage(`Invoking image pixel user sync for bidder: "${bidder}"`); + utils.triggerPixel(url, done); + } else if (type == 'iframe') { + utils.logMessage(`Invoking iframe user sync for bidder: "${bidder}"`); + utils.insertUserSyncIframe(url, done); } else { - logError(`User sync type "${type}" not supported for bidder: "${bidder}"`); + utils.logError(`User sync type "${type}" not supported for bidder: "${bidder}"`); done(); } } @@ -317,7 +312,7 @@ function doClientSideSyncs(bidders, gdprConsent, uspConsent) { if (clientAdapter && clientAdapter.registerSyncs) { config.runWithBidder( bidder, - bind.call( + utils.bind.call( clientAdapter.registerSyncs, clientAdapter, [], @@ -338,12 +333,12 @@ function _appendSiteAppDevice(request, pageUrl, accountId) { request.app.publisher = {id: accountId} } else { request.site = {}; - if (isPlainObject(config.getConfig('site'))) { + if (utils.isPlainObject(config.getConfig('site'))) { request.site = config.getConfig('site'); } // set publisher.id if not already defined - if (!deepAccess(request.site, 'publisher.id')) { - deepSetValue(request.site, 'publisher.id', accountId); + if (!utils.deepAccess(request.site, 'publisher.id')) { + utils.deepSetValue(request.site, 'publisher.id', accountId); } // set site.page if not already defined if (!request.site.page) { @@ -369,7 +364,13 @@ function addBidderFirstPartyDataToRequest(request) { const fpdConfigs = Object.keys(bidderConfig).reduce((acc, bidder) => { const currBidderConfig = bidderConfig[bidder]; if (currBidderConfig.ortb2) { - const ortb2 = mergeDeep({}, currBidderConfig.ortb2); + const ortb2 = {}; + if (currBidderConfig.ortb2.site) { + ortb2.site = currBidderConfig.ortb2.site; + } + if (currBidderConfig.ortb2.user) { + ortb2.user = currBidderConfig.ortb2.user; + } acc.push({ bidders: [ bidder ], @@ -380,7 +381,7 @@ function addBidderFirstPartyDataToRequest(request) { }, []); if (fpdConfigs.length) { - deepSetValue(request, 'ext.prebid.bidderconfig', fpdConfigs); + utils.deepSetValue(request, 'ext.prebid.bidderconfig', fpdConfigs); } } @@ -447,13 +448,13 @@ let wurlMap = {}; * @param {string} wurl events.winurl passed from prebidServer as wurl */ function addWurl(auctionId, adId, wurl) { - if ([auctionId, adId].every(isStr)) { + if ([auctionId, adId].every(utils.isStr)) { wurlMap[`${auctionId}${adId}`] = wurl; } } function getPbsResponseData(bidderRequests, response, pbsName, pbjsName) { - const bidderValues = deepAccess(response, `ext.${pbsName}`); + const bidderValues = utils.deepAccess(response, `ext.${pbsName}`); if (bidderValues) { Object.keys(bidderValues).forEach(bidder => { let biddersReq = find(bidderRequests, bidderReq => bidderReq.bidderCode === bidder); @@ -469,7 +470,7 @@ function getPbsResponseData(bidderRequests, response, pbsName, pbjsName) { * @param {string} adId generated value set to bidObject.adId by bidderFactory Bid() */ function removeWurl(auctionId, adId) { - if ([auctionId, adId].every(isStr)) { + if ([auctionId, adId].every(utils.isStr)) { wurlMap[`${auctionId}${adId}`] = undefined; } } @@ -479,7 +480,7 @@ function removeWurl(auctionId, adId) { * @return {(string|undefined)} events.winurl which was passed as wurl */ function getWurl(auctionId, adId) { - if ([auctionId, adId].every(isStr)) { + if ([auctionId, adId].every(utils.isStr)) { return wurlMap[`${auctionId}${adId}`]; } } @@ -511,7 +512,7 @@ const OPEN_RTB_PROTOCOL = { } impIds.add(impressionId); - const nativeParams = processNativeAdUnitParams(deepAccess(adUnit, 'mediaTypes.native')); + const nativeParams = processNativeAdUnitParams(utils.deepAccess(adUnit, 'mediaTypes.native')); let nativeAssets; if (nativeParams) { try { @@ -521,32 +522,29 @@ const OPEN_RTB_PROTOCOL = { function newAsset(obj) { return Object.assign({ required: params.required ? 1 : 0 - }, obj ? cleanObj(obj) : {}); + }, obj ? utils.cleanObj(obj) : {}); } switch (type) { case 'image': case 'icon': let imgTypeId = nativeImgIdMap[type]; - let asset = cleanObj({ + let asset = utils.cleanObj({ type: imgTypeId, - w: deepAccess(params, 'sizes.0'), - h: deepAccess(params, 'sizes.1'), - wmin: deepAccess(params, 'aspect_ratios.0.min_width'), - hmin: deepAccess(params, 'aspect_ratios.0.min_height') + w: utils.deepAccess(params, 'sizes.0'), + h: utils.deepAccess(params, 'sizes.1'), + wmin: utils.deepAccess(params, 'aspect_ratios.0.min_width'), + hmin: utils.deepAccess(params, 'aspect_ratios.0.min_height') }); if (!((asset.w && asset.h) || (asset.hmin && asset.wmin))) { throw 'invalid img sizes (must provide sizes or min_height & min_width if using aspect_ratios)'; } if (Array.isArray(params.aspect_ratios)) { // pass aspect_ratios as ext data I guess? - const aspectRatios = params.aspect_ratios - .filter((ar) => ar.ratio_width && ar.ratio_height) - .map(ratio => `${ratio.ratio_width}:${ratio.ratio_height}`); - if (aspectRatios.length > 0) { - asset.ext = { - aspectratios: aspectRatios - } + asset.ext = { + aspectratios: params.aspect_ratios.map( + ratio => `${ratio.ratio_width}:${ratio.ratio_height}` + ) } } assets.push(newAsset({ @@ -577,11 +575,11 @@ const OPEN_RTB_PROTOCOL = { return assets; }, []); } catch (e) { - logError('error creating native request: ' + String(e)) + utils.logError('error creating native request: ' + String(e)) } } - const videoParams = deepAccess(adUnit, 'mediaTypes.video'); - const bannerParams = deepAccess(adUnit, 'mediaTypes.banner'); + const videoParams = utils.deepAccess(adUnit, 'mediaTypes.video'); + const bannerParams = utils.deepAccess(adUnit, 'mediaTypes.banner'); adUnit.bids.forEach(bid => { // OpenRTB response contains imp.id and bidder name. These are @@ -600,7 +598,7 @@ const OPEN_RTB_PROTOCOL = { let mediaTypes = {}; if (bannerParams && bannerParams.sizes) { - const sizes = parseSizesInput(bannerParams.sizes); + const sizes = utils.parseSizesInput(bannerParams.sizes); // get banner sizes in form [{ w: , h: }, ...] const format = sizes.map(size => { @@ -615,10 +613,10 @@ const OPEN_RTB_PROTOCOL = { if (bannerParams.pos) mediaTypes['banner'].pos = bannerParams.pos; } - if (!isEmpty(videoParams)) { + if (!utils.isEmpty(videoParams)) { if (videoParams.context === 'outstream' && !videoParams.renderer && !adUnit.renderer) { // Don't push oustream w/o renderer to request object. - logError('Outstream bid without renderer cannot be sent to Prebid Server.'); + utils.logError('Outstream bid without renderer cannot be sent to Prebid Server.'); } else { if (videoParams.context === 'instream' && !videoParams.hasOwnProperty('placement')) { videoParams.placement = 1; @@ -627,8 +625,8 @@ const OPEN_RTB_PROTOCOL = { mediaTypes['video'] = Object.keys(videoParams).filter(param => param !== 'context') .reduce((result, param) => { if (param === 'playerSize') { - result.w = deepAccess(videoParams, `${param}.0.0`); - result.h = deepAccess(videoParams, `${param}.0.1`); + result.w = utils.deepAccess(videoParams, `${param}.0.0`); + result.h = utils.deepAccess(videoParams, `${param}.0.1`); } else { result[param] = videoParams[param]; } @@ -654,7 +652,7 @@ const OPEN_RTB_PROTOCOL = { ver: '1.2' } } catch (e) { - logError('error creating native request: ' + String(e)) + utils.logError('error creating native request: ' + String(e)) } } @@ -667,11 +665,11 @@ const OPEN_RTB_PROTOCOL = { } acc[bid.bidder] = (s2sConfig.adapterOptions && s2sConfig.adapterOptions[bid.bidder]) ? Object.assign({}, bid.params, s2sConfig.adapterOptions[bid.bidder]) : bid.params; return acc; - }, {...deepAccess(adUnit, 'ortb2Imp.ext')}); + }, {...utils.deepAccess(adUnit, 'ortb2Imp.ext')}); const imp = { id: impressionId, ext, secure: s2sConfig.secure }; - const ortb2 = {...deepAccess(adUnit, 'ortb2Imp.ext.data')}; + const ortb2 = {...utils.deepAccess(adUnit, 'ortb2Imp.ext.data')}; Object.keys(ortb2).forEach(prop => { /** * Prebid AdSlot @@ -679,7 +677,7 @@ const OPEN_RTB_PROTOCOL = { */ if (prop === 'pbadslot') { if (typeof ortb2[prop] === 'string' && ortb2[prop]) { - deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); + utils.deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); } else { // remove pbadslot property if it doesn't meet the spec delete imp.ext.data.pbadslot; @@ -690,13 +688,13 @@ const OPEN_RTB_PROTOCOL = { */ ['name', 'adslot'].forEach(name => { /** @type {(string|undefined)} */ - const value = deepAccess(ortb2, `adserver.${name}`); + const value = utils.deepAccess(ortb2, `adserver.${name}`); if (typeof value === 'string' && value) { - deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); + utils.deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); } }); } else { - deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); + utils.deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); } }); @@ -705,7 +703,7 @@ const OPEN_RTB_PROTOCOL = { // if storedAuctionResponse has been set, pass SRID const storedAuctionResponseBid = find(firstBidRequest.bids, bid => (bid.adUnitCode === adUnit.code && bid.storedAuctionResponse)); if (storedAuctionResponseBid) { - deepSetValue(imp, 'ext.prebid.storedauctionresponse.id', storedAuctionResponseBid.storedAuctionResponse.toString()); + utils.deepSetValue(imp, 'ext.prebid.storedauctionresponse.id', storedAuctionResponseBid.storedAuctionResponse.toString()); } const getFloorBid = find(firstBidRequest.bids, bid => bid.adUnitCode === adUnit.code && typeof bid.getFloor === 'function'); @@ -717,7 +715,7 @@ const OPEN_RTB_PROTOCOL = { currency: config.getConfig('currency.adServerCurrency') || DEFAULT_S2S_CURRENCY, }); } catch (e) { - logError('PBS: getFloor threw an error: ', e); + utils.logError('PBS: getFloor threw an error: ', e); } if (floorInfo && floorInfo.currency && !isNaN(parseFloat(floorInfo.floor))) { imp.bidfloor = parseFloat(floorInfo.floor); @@ -731,11 +729,11 @@ const OPEN_RTB_PROTOCOL = { }); if (!imps.length) { - logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.'); + utils.logError('Request to Prebid Server rejected due to invalid media type(s) in adUnit.'); return; } const request = { - id: firstBidRequest.auctionId, + id: s2sBidRequest.tid, source: {tid: s2sBidRequest.tid}, tmax: s2sConfig.timeout, imp: imps, @@ -755,7 +753,7 @@ const OPEN_RTB_PROTOCOL = { } }; - // This is no longer overwritten unless name and version explicitly overwritten by extPrebid (mergeDeep) + // Sets pbjs version, can be overwritten below if channel exists in s2sConfig.extPrebid request.ext.prebid = Object.assign(request.ext.prebid, {channel: {name: 'pbjs', version: $$PREBID_GLOBAL$$.version}}) // set debug flag if in debug mode @@ -765,7 +763,7 @@ const OPEN_RTB_PROTOCOL = { // s2sConfig video.ext.prebid is passed through openrtb to PBS if (s2sConfig.extPrebid && typeof s2sConfig.extPrebid === 'object') { - request.ext.prebid = mergeDeep(request.ext.prebid, s2sConfig.extPrebid); + request.ext.prebid = Object.assign(request.ext.prebid, s2sConfig.extPrebid); } /** @@ -783,36 +781,36 @@ const OPEN_RTB_PROTOCOL = { _appendSiteAppDevice(request, bidRequests[0].refererInfo.referer, s2sConfig.accountId); // pass schain object if it is present - const schain = deepAccess(bidRequests, '0.bids.0.schain'); + const schain = utils.deepAccess(bidRequests, '0.bids.0.schain'); if (schain) { request.source.ext = { schain: schain }; } - if (!isEmpty(aliases)) { + if (!utils.isEmpty(aliases)) { request.ext.prebid.aliases = {...request.ext.prebid.aliases, ...aliases}; } - const bidUserIdAsEids = deepAccess(bidRequests, '0.bids.0.userIdAsEids'); - if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { - deepSetValue(request, 'user.ext.eids', bidUserIdAsEids); + const bidUserIdAsEids = utils.deepAccess(bidRequests, '0.bids.0.userIdAsEids'); + if (utils.isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { + utils.deepSetValue(request, 'user.ext.eids', bidUserIdAsEids); } - if (isArray(eidPermissions) && eidPermissions.length > 0) { - if (requestedBidders && isArray(requestedBidders)) { + if (utils.isArray(eidPermissions) && eidPermissions.length > 0) { + if (requestedBidders && utils.isArray(requestedBidders)) { eidPermissions.forEach(i => { if (i.bidders) { - i.bidders = i.bidders.filter(bidder => includes(requestedBidders, bidder)) + i.bidders = i.bidders.filter(bidder => requestedBidders.includes(bidder)) } }); } - deepSetValue(request, 'ext.prebid.data.eidpermissions', eidPermissions); + utils.deepSetValue(request, 'ext.prebid.data.eidpermissions', eidPermissions); } const multibid = config.getConfig('multibid'); if (multibid) { - deepSetValue(request, 'ext.prebid.multibid', multibid.reduce((result, i) => { + utils.deepSetValue(request, 'ext.prebid.multibid', multibid.reduce((result, i) => { let obj = {}; Object.keys(i).forEach(key => { @@ -832,26 +830,30 @@ const OPEN_RTB_PROTOCOL = { if (typeof firstBidRequest.gdprConsent.gdprApplies === 'boolean') { gdprApplies = firstBidRequest.gdprConsent.gdprApplies ? 1 : 0; } - deepSetValue(request, 'regs.ext.gdpr', gdprApplies); - deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString); + utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies); + utils.deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString); if (firstBidRequest.gdprConsent.addtlConsent && typeof firstBidRequest.gdprConsent.addtlConsent === 'string') { - deepSetValue(request, 'user.ext.ConsentedProvidersSettings.consented_providers', firstBidRequest.gdprConsent.addtlConsent); + utils.deepSetValue(request, 'user.ext.ConsentedProvidersSettings.consented_providers', firstBidRequest.gdprConsent.addtlConsent); } } // US Privacy (CCPA) support if (firstBidRequest.uspConsent) { - deepSetValue(request, 'regs.ext.us_privacy', firstBidRequest.uspConsent); + utils.deepSetValue(request, 'regs.ext.us_privacy', firstBidRequest.uspConsent); } } if (getConfig('coppa') === true) { - deepSetValue(request, 'regs.coppa', 1); + utils.deepSetValue(request, 'regs.coppa', 1); } const commonFpd = getConfig('ortb2') || {}; - mergeDeep(request, commonFpd); - + if (commonFpd.site) { + utils.mergeDeep(request, {site: commonFpd.site}); + } + if (commonFpd.user) { + utils.mergeDeep(request, {user: commonFpd.user}); + } addBidderFirstPartyDataToRequest(request); return request; @@ -870,7 +872,7 @@ const OPEN_RTB_PROTOCOL = { let bidRequest; let key = `${bid.impid}${seatbid.seat}`; if (bidIdMap[key]) { - bidRequest = getBidRequest( + bidRequest = utils.getBidRequest( bidIdMap[key], bidderRequests ); @@ -887,31 +889,31 @@ const OPEN_RTB_PROTOCOL = { // temporarily leaving attaching it to each bidResponse so no breaking change // BUT: this is a flat map, so it should be only attached to bidderRequest, a the change above does - let serverResponseTimeMs = deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.')); + let serverResponseTimeMs = utils.deepAccess(response, ['ext', 'responsetimemillis', seatbid.seat].join('.')); if (bidRequest && serverResponseTimeMs) { bidRequest.serverResponseTimeMs = serverResponseTimeMs; } // Look for seatbid[].bid[].ext.prebid.bidid and place it in the bidResponse object for use in analytics adapters as 'pbsBidId' - const bidId = deepAccess(bid, 'ext.prebid.bidid'); - if (isStr(bidId)) { + const bidId = utils.deepAccess(bid, 'ext.prebid.bidid'); + if (utils.isStr(bidId)) { bidObject.pbsBidId = bidId; } // store wurl by auctionId and adId so it can be accessed from the BID_WON event handler - if (isStr(deepAccess(bid, 'ext.prebid.events.win'))) { - addWurl(bidRequest.auctionId, bidObject.adId, deepAccess(bid, 'ext.prebid.events.win')); + if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.win'))) { + addWurl(bidRequest.auctionId, bidObject.adId, utils.deepAccess(bid, 'ext.prebid.events.win')); } - let extPrebidTargeting = deepAccess(bid, 'ext.prebid.targeting'); + let extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting'); // If ext.prebid.targeting exists, add it as a property value named 'adserverTargeting' // The removal of hb_winurl and hb_bidid targeting values is temporary // once we get through the transition, this block will be removed. - if (isPlainObject(extPrebidTargeting)) { + if (utils.isPlainObject(extPrebidTargeting)) { // If wurl exists, remove hb_winurl and hb_bidid targeting attributes - if (isStr(deepAccess(bid, 'ext.prebid.events.win'))) { - extPrebidTargeting = getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting) + if (utils.isStr(utils.deepAccess(bid, 'ext.prebid.events.win'))) { + extPrebidTargeting = utils.getDefinedParams(extPrebidTargeting, Object.keys(extPrebidTargeting) .filter(i => (i.indexOf('hb_winurl') === -1 && i.indexOf('hb_bidid') === -1))); } bidObject.adserverTargeting = extPrebidTargeting; @@ -919,7 +921,7 @@ const OPEN_RTB_PROTOCOL = { bidObject.seatBidId = bid.id; - if (deepAccess(bid, 'ext.prebid.type') === VIDEO) { + if (utils.deepAccess(bid, 'ext.prebid.type') === VIDEO) { bidObject.mediaType = VIDEO; let sizes = bidRequest.sizes && bidRequest.sizes[0]; bidObject.playerWidth = sizes[0]; @@ -938,7 +940,7 @@ const OPEN_RTB_PROTOCOL = { if (bid.adm) { bidObject.vastXml = bid.adm; } if (!bidObject.vastUrl && bid.nurl) { bidObject.vastUrl = bid.nurl; } - } else if (deepAccess(bid, 'ext.prebid.type') === NATIVE) { + } else if (utils.deepAccess(bid, 'ext.prebid.type') === NATIVE) { bidObject.mediaType = NATIVE; let adm; if (typeof bid.adm === 'string') { @@ -964,18 +966,18 @@ const OPEN_RTB_PROTOCOL = { }); } - if (isPlainObject(adm) && Array.isArray(adm.assets)) { + if (utils.isPlainObject(adm) && Array.isArray(adm.assets)) { let origAssets = nativeAssetCache[bid.impid]; - bidObject.native = cleanObj(adm.assets.reduce((native, asset) => { + bidObject.native = utils.cleanObj(adm.assets.reduce((native, asset) => { let origAsset = origAssets[asset.id]; - if (isPlainObject(asset.img)) { - native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = pick( + if (utils.isPlainObject(asset.img)) { + native[origAsset.img.type ? nativeImgIdMap[origAsset.img.type] : 'image'] = utils.pick( asset.img, ['url', 'w as width', 'h as height'] ); - } else if (isPlainObject(asset.title)) { + } else if (utils.isPlainObject(asset.title)) { native['title'] = asset.title.text - } else if (isPlainObject(asset.data)) { + } else if (utils.isPlainObject(asset.data)) { nativeDataNames.forEach(dataType => { if (nativeDataIdMap[dataType] === origAsset.data.type) { native[dataType] = asset.data.value; @@ -983,19 +985,19 @@ const OPEN_RTB_PROTOCOL = { }); } return native; - }, cleanObj({ + }, utils.cleanObj({ clickUrl: adm.link, - clickTrackers: deepAccess(adm, 'link.clicktrackers'), + clickTrackers: utils.deepAccess(adm, 'link.clicktrackers'), impressionTrackers: trackers[nativeEventTrackerMethodMap.img], javascriptTrackers: trackers[nativeEventTrackerMethodMap.js] }))); } else { - logError('prebid server native response contained no assets'); + utils.logError('prebid server native response contained no assets'); } } else { // banner if (bid.adm && bid.nurl) { bidObject.ad = bid.adm; - bidObject.ad += createTrackPixelHtml(decodeURIComponent(bid.nurl)); + bidObject.ad += utils.createTrackPixelHtml(decodeURIComponent(bid.nurl)); } else if (bid.adm) { bidObject.ad = bid.adm; } else if (bid.nurl) { @@ -1012,8 +1014,8 @@ const OPEN_RTB_PROTOCOL = { if (bid.burl) { bidObject.burl = bid.burl; } bidObject.currency = (response.cur) ? response.cur : DEFAULT_S2S_CURRENCY; bidObject.meta = {}; - let extPrebidMeta = deepAccess(bid, 'ext.prebid.meta'); - if (extPrebidMeta && isPlainObject(extPrebidMeta)) { bidObject.meta = deepClone(extPrebidMeta); } + let extPrebidMeta = utils.deepAccess(bid, 'ext.prebid.meta'); + if (extPrebidMeta && utils.isPlainObject(extPrebidMeta)) { bidObject.meta = utils.deepClone(extPrebidMeta); } if (bid.adomain) { bidObject.meta.advertiserDomains = bid.adomain; } // the OpenRTB location for "TTL" as understood by Prebid.js is "exp" (expiration). @@ -1036,9 +1038,9 @@ const OPEN_RTB_PROTOCOL = { */ function bidWonHandler(bid) { const wurl = getWurl(bid.auctionId, bid.adId); - if (isStr(wurl)) { - logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`); - triggerPixel(wurl); + if (utils.isStr(wurl)) { + utils.logMessage(`Invoking image pixel for wurl on BID_WIN: "${wurl}"`); + utils.triggerPixel(wurl); // remove from wurl cache, since the wurl url was called removeWurl(bid.auctionId, bid.adId); @@ -1049,7 +1051,7 @@ function hasPurpose1Consent(gdprConsent) { let result = true; if (gdprConsent) { if (gdprConsent.gdprApplies && gdprConsent.apiVersion === 2) { - result = !!(deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true); + result = !!(utils.deepAccess(gdprConsent, 'vendorData.purpose.consents.1') === true); } } return result; @@ -1076,7 +1078,7 @@ export function PrebidServer() { /* Prebid executes this function when the page asks to send out bid requests */ baseAdapter.callBids = function(s2sBidRequest, bidRequests, addBidResponse, done, ajax) { - const adUnits = deepClone(s2sBidRequest.ad_units); + const adUnits = utils.deepClone(s2sBidRequest.ad_units); let { gdprConsent, uspConsent } = getConsentData(bidRequests); // at this point ad units should have a size array either directly or mapped so filter for that @@ -1086,9 +1088,9 @@ export function PrebidServer() { // in case config.bidders contains invalid bidders, we only process those we sent requests for const requestedBidders = validAdUnits - .map(adUnit => adUnit.bids.map(bid => bid.bidder).filter(uniques)) - .reduce(flatten) - .filter(uniques); + .map(adUnit => adUnit.bids.map(bid => bid.bidder).filter(utils.uniques)) + .reduce(utils.flatten) + .filter(utils.uniques); if (Array.isArray(_s2sConfigs)) { if (s2sBidRequest.s2sConfig && s2sBidRequest.s2sConfig.syncEndpoint && getMatchingConsentUrl(s2sBidRequest.s2sConfig.syncEndpoint, gdprConsent)) { @@ -1101,7 +1103,7 @@ export function PrebidServer() { const request = OPEN_RTB_PROTOCOL.buildRequest(s2sBidRequest, bidRequests, validAdUnits, s2sBidRequest.s2sConfig, requestedBidders); const requestJson = request && JSON.stringify(request); - logInfo('BidRequest: ' + requestJson); + utils.logInfo('BidRequest: ' + requestJson); const endpointUrl = getMatchingConsentUrl(s2sBidRequest.s2sConfig.endpoint, gdprConsent); if (request && requestJson && endpointUrl) { ajax( @@ -1114,7 +1116,7 @@ export function PrebidServer() { { contentType: 'text/plain', withCredentials: true } ); } else { - logError('PBS request not made. Check endpoints.'); + utils.logError('PBS request not made. Check endpoints.'); } } }; @@ -1142,11 +1144,11 @@ export function PrebidServer() { bidderRequests.forEach(bidderRequest => events.emit(CONSTANTS.EVENTS.BIDDER_DONE, bidderRequest)); } catch (error) { - logError(error); + utils.logError(error); } if (!result || (result.status && includes(result.status, 'Error'))) { - logError('error parsing response: ', result.status); + utils.logError('error parsing response: ', result.status); } done(); diff --git a/modules/prebidmanagerAnalyticsAdapter.js b/modules/prebidmanagerAnalyticsAdapter.js index a1a0a636e3c..b9a7d79f991 100644 --- a/modules/prebidmanagerAnalyticsAdapter.js +++ b/modules/prebidmanagerAnalyticsAdapter.js @@ -1,4 +1,3 @@ -import { generateUUID, getParameterByName, logError, parseUrl, logInfo } from '../src/utils.js'; import {ajaxBuilder} from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; @@ -12,12 +11,13 @@ const DEFAULT_EVENT_URL = 'https://endpoint.prebidmanager.com/endpoint' const analyticsType = 'endpoint'; const analyticsName = 'Prebid Manager Analytics: '; +var utils = require('../src/utils.js'); var CONSTANTS = require('../src/constants.json'); let ajax = ajaxBuilder(0); var _VERSION = 1; var initOptions = null; -var _pageViewId = generateUUID(); +var _pageViewId = utils.generateUUID(); var _startAuction = 0; var _bidRequestTimeout = 0; let flushInterval; @@ -76,7 +76,7 @@ function collectUtmTagData() { let pmUtmTags = {}; try { utmTags.forEach(function (utmKey) { - let utmValue = getParameterByName(utmKey); + let utmValue = utils.getParameterByName(utmKey); if (utmValue !== '') { newUtm = true; } @@ -95,7 +95,7 @@ function collectUtmTagData() { }); } } catch (e) { - logError(`${analyticsName}Error`, e); + utils.logError(`${analyticsName}Error`, e); pmUtmTags['error_utm'] = 1; } return pmUtmTags; @@ -106,7 +106,7 @@ function collectPageInfo() { domain: window.location.hostname, } if (document.referrer) { - pageInfo.referrerDomain = parseUrl(document.referrer).hostname; + pageInfo.referrerDomain = utils.parseUrl(document.referrer).hostname; } return pageInfo; } @@ -128,7 +128,7 @@ function flush() { ajax( initOptions.url, - () => logInfo(`${analyticsName} sent events batch`), + () => utils.logInfo(`${analyticsName} sent events batch`), _VERSION + ':' + JSON.stringify(data), { contentType: 'text/plain', @@ -215,7 +215,7 @@ function handleEvent(eventType, eventArgs) { function sendEvent(event) { _eventQueue.push(event); - logInfo(`${analyticsName}Event ${event.eventType}:`, event); + utils.logInfo(`${analyticsName}Event ${event.eventType}:`, event); if (event.eventType === CONSTANTS.EVENTS.AUCTION_END) { flush(); diff --git a/modules/priceFloors.js b/modules/priceFloors.js index b55638c1a5c..3555fedbf3a 100644 --- a/modules/priceFloors.js +++ b/modules/priceFloors.js @@ -1,6 +1,6 @@ -import { parseUrl, deepAccess, parseGPTSingleSizeArray, getGptSlotInfoForAdUnitCode, deepSetValue, logWarn, deepClone, getParameterByName, generateUUID, logError, logInfo, isNumber, pick, debugTurnedOn } from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { ajaxBuilder } from '../src/ajax.js'; import events from '../src/events.js'; import CONSTANTS from '../src/constants.json'; @@ -60,23 +60,17 @@ function roundUp(number, precision) { let referrerHostname; function getHostNameFromReferer(referer) { - referrerHostname = parseUrl(referer, {noDecodeWholeURL: true}).hostname; + referrerHostname = utils.parseUrl(referer, {noDecodeWholeURL: true}).hostname; return referrerHostname; } -// First look into bidRequest! -function getGptSlotFromBidRequest(bidRequest) { - const isGam = deepAccess(bidRequest, 'ortb2Imp.ext.data.adserver.name') === 'gam'; - return isGam && bidRequest.ortb2Imp.ext.data.adserver.adslot; -} - /** * @summary floor field types with their matching functions to resolve the actual matched value */ export let fieldMatchingFunctions = { - 'size': (bidRequest, bidResponse) => parseGPTSingleSizeArray(bidResponse.size) || '*', + 'size': (bidRequest, bidResponse) => utils.parseGPTSingleSizeArray(bidResponse.size) || '*', 'mediaType': (bidRequest, bidResponse) => bidResponse.mediaType || 'banner', - 'gptSlot': (bidRequest, bidResponse) => getGptSlotFromBidRequest(bidRequest) || getGptSlotInfoForAdUnitCode(bidRequest.adUnitCode).gptSlot, + 'gptSlot': (bidRequest, bidResponse) => utils.getGptSlotInfoForAdUnitCode(bidRequest.adUnitCode).gptSlot, 'domain': (bidRequest, bidResponse) => referrerHostname || getHostNameFromReferer(getRefererInfo().referer), 'adUnitCode': (bidRequest, bidResponse) => bidRequest.adUnitCode } @@ -101,17 +95,17 @@ function enumeratePossibleFieldValues(floorFields, bidObject, responseObject) { * Generates all possible rule matches and picks the first matching one. */ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {}) { - let fieldValues = enumeratePossibleFieldValues(deepAccess(floorData, 'schema.fields') || [], bidObject, responseObject); + let fieldValues = enumeratePossibleFieldValues(utils.deepAccess(floorData, 'schema.fields') || [], bidObject, responseObject); if (!fieldValues.length) return { matchingFloor: floorData.default }; // look to see if a request for this context was made already let matchingInput = fieldValues.map(field => field[0]).join('-'); // if we already have gotten the matching rule from this matching input then use it! No need to look again - let previousMatch = deepAccess(floorData, `matchingInputs.${matchingInput}`); + let previousMatch = utils.deepAccess(floorData, `matchingInputs.${matchingInput}`); if (previousMatch) { return {...previousMatch}; } - let allPossibleMatches = generatePossibleEnumerations(fieldValues, deepAccess(floorData, 'schema.delimiter') || '|'); + let allPossibleMatches = generatePossibleEnumerations(fieldValues, utils.deepAccess(floorData, 'schema.delimiter') || '|'); let matchingRule = find(allPossibleMatches, hashValue => floorData.values.hasOwnProperty(hashValue)); let matchingData = { @@ -122,7 +116,7 @@ export function getFirstMatchingFloor(floorData, bidObject, responseObject = {}) }; matchingData.matchingFloor = Math.max(matchingData.floorMin, matchingData.floorRuleValue); // save for later lookup if needed - deepSetValue(floorData, `matchingInputs.${matchingInput}`, {...matchingData}); + utils.deepSetValue(floorData, `matchingInputs.${matchingInput}`, {...matchingData}); return matchingData; } @@ -147,7 +141,7 @@ function generatePossibleEnumerations(arrayOfFields, delimiter) { * @summary If a the input bidder has a registered cpmadjustment it returns the input CPM after being adjusted */ export function getBiddersCpmAdjustment(bidderName, inputCpm, bid = {}) { - const adjustmentFunction = deepAccess(getGlobal(), `bidderSettings.${bidderName}.bidCpmAdjustment`) || deepAccess(getGlobal(), 'bidderSettings.standard.bidCpmAdjustment'); + const adjustmentFunction = utils.deepAccess(getGlobal(), `bidderSettings.${bidderName}.bidCpmAdjustment`) || utils.deepAccess(getGlobal(), 'bidderSettings.standard.bidCpmAdjustment'); if (adjustmentFunction) { return parseFloat(adjustmentFunction(inputCpm, {...bid, cpm: inputCpm})); } @@ -167,9 +161,9 @@ export function calculateAdjustedFloor(oldFloor, newFloor) { * @summary gets the prebid set sizes depending on the input mediaType */ const getMediaTypesSizes = { - banner: (bid) => deepAccess(bid, 'mediaTypes.banner.sizes') || [], - video: (bid) => deepAccess(bid, 'mediaTypes.video.playerSize') || [], - native: (bid) => deepAccess(bid, 'mediaTypes.native.image.sizes') ? [deepAccess(bid, 'mediaTypes.native.image.sizes')] : [] + banner: (bid) => utils.deepAccess(bid, 'mediaTypes.banner.sizes') || [], + video: (bid) => utils.deepAccess(bid, 'mediaTypes.video.playerSize') || [], + native: (bid) => utils.deepAccess(bid, 'mediaTypes.native.image.sizes') ? [utils.deepAccess(bid, 'mediaTypes.native.image.sizes')] : [] } /** @@ -208,7 +202,7 @@ export function getFloor(requestParams = {currency: 'USD', mediaType: '*', size: try { floorInfo.matchingFloor = getGlobal().convertCurrency(floorInfo.matchingFloor, floorData.data.currency, currency); } catch (err) { - logWarn(`${MODULE_NAME}: Unable to get currency conversion for getFloor for bidder ${bidRequest.bidder}. You must have currency module enabled with defaultRates in your currency config`); + utils.logWarn(`${MODULE_NAME}: Unable to get currency conversion for getFloor for bidder ${bidRequest.bidder}. You must have currency module enabled with defaultRates in your currency config`); // since we were unable to convert to the bidders requested currency, we send back just the actual floors currency to them currency = floorData.data.currency; } @@ -233,7 +227,7 @@ export function getFloor(requestParams = {currency: 'USD', mediaType: '*', size: * @summary Takes a floorsData object and converts it into a hash map with appropriate keys */ export function getFloorsDataForAuction(floorData, adUnitCode) { - let auctionFloorData = deepClone(floorData); + let auctionFloorData = utils.deepClone(floorData); auctionFloorData.schema.delimiter = floorData.schema.delimiter || '|'; auctionFloorData.values = normalizeRulesForAuction(auctionFloorData, adUnitCode); // default the currency to USD if not passed in @@ -296,10 +290,10 @@ export function updateAdUnitsForAuction(adUnits, floorData, auctionId) { skipped: floorData.skipped, skipRate: floorData.skipRate, floorMin: floorData.floorMin, - modelVersion: deepAccess(floorData, 'data.modelVersion'), - modelWeight: deepAccess(floorData, 'data.modelWeight'), - modelTimestamp: deepAccess(floorData, 'data.modelTimestamp'), - location: deepAccess(floorData, 'data.location', 'noData'), + modelVersion: utils.deepAccess(floorData, 'data.modelVersion'), + modelWeight: utils.deepAccess(floorData, 'data.modelWeight'), + modelTimestamp: utils.deepAccess(floorData, 'data.modelTimestamp'), + location: utils.deepAccess(floorData, 'data.location', 'noData'), floorProvider: floorData.floorProvider, fetchStatus: _floorsConfig.fetchStatus }; @@ -323,27 +317,27 @@ export function pickRandomModel(modelGroups, weightSum) { * @summary Updates the adUnits accordingly and returns the necessary floorsData for the current auction */ export function createFloorsDataForAuction(adUnits, auctionId) { - let resolvedFloorsData = deepClone(_floorsConfig); + let resolvedFloorsData = utils.deepClone(_floorsConfig); // if using schema 2 pick a model here: - if (deepAccess(resolvedFloorsData, 'data.floorsSchemaVersion') === 2) { + if (utils.deepAccess(resolvedFloorsData, 'data.floorsSchemaVersion') === 2) { // merge the models specific stuff into the top level data settings (now it looks like floorsSchemaVersion 1!) let { modelGroups, ...rest } = resolvedFloorsData.data; resolvedFloorsData.data = Object.assign(rest, pickRandomModel(modelGroups, rest.modelWeightSum)); } // if we do not have a floors data set, we will try to use data set on adUnits - let useAdUnitData = Object.keys(deepAccess(resolvedFloorsData, 'data.values') || {}).length === 0; + let useAdUnitData = Object.keys(utils.deepAccess(resolvedFloorsData, 'data.values') || {}).length === 0; if (useAdUnitData) { resolvedFloorsData.data = getFloorDataFromAdUnits(adUnits); } else { resolvedFloorsData.data = getFloorsDataForAuction(resolvedFloorsData.data); } // if we still do not have a valid floor data then floors is not on for this auction, so skip - if (Object.keys(deepAccess(resolvedFloorsData, 'data.values') || {}).length === 0) { + if (Object.keys(utils.deepAccess(resolvedFloorsData, 'data.values') || {}).length === 0) { resolvedFloorsData.skipped = true; } else { // determine the skip rate now - const auctionSkipRate = getParameterByName('pbjs_skipRate') || resolvedFloorsData.skipRate; + const auctionSkipRate = utils.getParameterByName('pbjs_skipRate') || resolvedFloorsData.skipRate; const isSkipped = Math.random() * 100 < parseFloat(auctionSkipRate); resolvedFloorsData.skipped = isSkipped; } @@ -364,7 +358,7 @@ export function continueAuction(hookConfig) { _delayedAuctions = _delayedAuctions.filter(auctionConfig => auctionConfig.timer !== hookConfig.timer); // We need to know the auctionId at this time. So we will use the passed in one or generate and set it ourselves - hookConfig.reqBidsConfigObj.auctionId = hookConfig.reqBidsConfigObj.auctionId || generateUUID(); + hookConfig.reqBidsConfigObj.auctionId = hookConfig.reqBidsConfigObj.auctionId || utils.generateUUID(); // now we do what we need to with adUnits and save the data object to be used for getFloor and enforcement calls _floorDataForAuction[hookConfig.reqBidsConfigObj.auctionId] = createFloorsDataForAuction(hookConfig.reqBidsConfigObj.adUnits || getGlobal().adUnits, hookConfig.reqBidsConfigObj.auctionId); @@ -378,7 +372,7 @@ function validateSchemaFields(fields) { if (Array.isArray(fields) && fields.length > 0 && fields.every(field => allowedFields.indexOf(field) !== -1)) { return true; } - logError(`${MODULE_NAME}: Fields recieved do not match allowed fields`); + utils.logError(`${MODULE_NAME}: Fields recieved do not match allowed fields`); return false; } @@ -406,7 +400,7 @@ function validateRules(floorsData, numFields, delimiter) { function modelIsValid(model) { // schema.fields has only allowed attributes - if (!validateSchemaFields(deepAccess(model, 'schema.fields'))) { + if (!validateSchemaFields(utils.deepAccess(model, 'schema.fields'))) { return false; } return validateRules(model, model.schema.fields.length, model.schema.delimiter || '|') @@ -446,7 +440,7 @@ export function isFloorsDataValid(floorsData) { } floorsData.floorsSchemaVersion = floorsData.floorsSchemaVersion || 1; if (typeof floorsSchemaValidation[floorsData.floorsSchemaVersion] !== 'function') { - logError(`${MODULE_NAME}: Unknown floorsSchemaVersion: `, floorsData.floorsSchemaVersion); + utils.logError(`${MODULE_NAME}: Unknown floorsSchemaVersion: `, floorsData.floorsSchemaVersion); return false; } return floorsSchemaValidation[floorsData.floorsSchemaVersion](floorsData); @@ -457,13 +451,13 @@ export function isFloorsDataValid(floorsData) { */ export function parseFloorData(floorsData, location) { if (floorsData && typeof floorsData === 'object' && isFloorsDataValid(floorsData)) { - logInfo(`${MODULE_NAME}: A ${location} set the auction floor data set to `, floorsData); + utils.logInfo(`${MODULE_NAME}: A ${location} set the auction floor data set to `, floorsData); return { ...floorsData, location }; } - logError(`${MODULE_NAME}: The floors data did not contain correct values`, floorsData); + utils.logError(`${MODULE_NAME}: The floors data did not contain correct values`, floorsData); } /** @@ -484,7 +478,7 @@ export function requestBidsHook(fn, reqBidsConfigObj) { // If auction delay > 0 AND we are fetching -> Then wait until it finishes if (_floorsConfig.auctionDelay > 0 && fetching) { hookConfig.timer = setTimeout(() => { - logWarn(`${MODULE_NAME}: Fetch attempt did not return in time for auction`); + utils.logWarn(`${MODULE_NAME}: Fetch attempt did not return in time for auction`); _floorsConfig.fetchStatus = 'timeout'; continueAuction(hookConfig); }, _floorsConfig.auctionDelay); @@ -526,7 +520,7 @@ export function handleFetchResponse(fetchResponse) { // set .data to it _floorsConfig.data = fetchData; // set skipRate override if necessary - _floorsConfig.skipRate = isNumber(fetchData.skipRate) ? fetchData.skipRate : _floorsConfig.skipRate; + _floorsConfig.skipRate = utils.isNumber(fetchData.skipRate) ? fetchData.skipRate : _floorsConfig.skipRate; _floorsConfig.floorProvider = fetchData.floorProvider || _floorsConfig.floorProvider; } @@ -537,7 +531,7 @@ export function handleFetchResponse(fetchResponse) { function handleFetchError(status) { fetching = false; _floorsConfig.fetchStatus = 'error'; - logError(`${MODULE_NAME}: Fetch errored with: `, status); + utils.logError(`${MODULE_NAME}: Fetch errored with: `, status); // if any auctions are waiting for fetch to finish, we need to continue them! resumeDelayedAuctions(); @@ -553,13 +547,13 @@ export function generateAndHandleFetch(floorEndpoint) { // default to GET and we only support GET for now let requestMethod = floorEndpoint.method || 'GET'; if (requestMethod !== 'GET') { - logError(`${MODULE_NAME}: 'GET' is the only request method supported at this time!`); + utils.logError(`${MODULE_NAME}: 'GET' is the only request method supported at this time!`); } else { ajax(floorEndpoint.url, { success: handleFetchResponse, error: handleFetchError }, null, { method: 'GET' }); fetching = true; } } else if (fetching) { - logWarn(`${MODULE_NAME}: A fetch is already occuring. Skipping.`); + utils.logWarn(`${MODULE_NAME}: A fetch is already occuring. Skipping.`); } } @@ -580,14 +574,14 @@ function addFieldOverrides(overrides) { * @summary This is the function which controls what happens during a pbjs.setConfig({...floors: {}}) is called */ export function handleSetFloorsConfig(config) { - _floorsConfig = pick(config, [ + _floorsConfig = utils.pick(config, [ 'floorMin', 'enabled', enabled => enabled !== false, // defaults to true 'auctionDelay', auctionDelay => auctionDelay || 0, - 'floorProvider', floorProvider => deepAccess(config, 'data.floorProvider', floorProvider), + 'floorProvider', floorProvider => utils.deepAccess(config, 'data.floorProvider', floorProvider), 'endpoint', endpoint => endpoint || {}, - 'skipRate', () => !isNaN(deepAccess(config, 'data.skipRate')) ? config.data.skipRate : config.skipRate || 0, - 'enforcement', enforcement => pick(enforcement || {}, [ + 'skipRate', () => !isNaN(utils.deepAccess(config, 'data.skipRate')) ? config.data.skipRate : config.skipRate || 0, + 'enforcement', enforcement => utils.pick(enforcement || {}, [ 'enforceJS', enforceJS => enforceJS !== false, // defaults to true 'enforcePBS', enforcePBS => enforcePBS === true, // defaults to false 'floorDeals', floorDeals => floorDeals === true, // defaults to false @@ -613,11 +607,11 @@ export function handleSetFloorsConfig(config) { getGlobal().requestBids.before(requestBidsHook, 50); // if user has debug on then we want to allow the debugging module to run before this, assuming they are testing priceFloors // debugging is currently set at 5 priority - getHook('addBidResponse').before(addBidResponseHook, debugTurnedOn() ? 4 : 50); + getHook('addBidResponse').before(addBidResponseHook, utils.debugTurnedOn() ? 4 : 50); addedFloorsHook = true; } } else { - logInfo(`${MODULE_NAME}: Turning off module`); + utils.logInfo(`${MODULE_NAME}: Turning off module`); _floorsConfig = {}; _floorDataForAuction = {}; @@ -653,8 +647,8 @@ function addFloorDataToBid(floorData, floorInfo, bid, adjustedCpm) { * @summary takes the enforcement flags and the bid itself and determines if it should be floored */ function shouldFloorBid(floorData, floorInfo, bid) { - let enforceJS = deepAccess(floorData, 'enforcement.enforceJS') !== false; - let shouldFloorDeal = deepAccess(floorData, 'enforcement.floorDeals') === true || !bid.dealId; + let enforceJS = utils.deepAccess(floorData, 'enforcement.enforceJS') !== false; + let shouldFloorDeal = utils.deepAccess(floorData, 'enforcement.floorDeals') === true || !bid.dealId; let bidBelowFloor = bid.floorData.cpmAfterAdjustments < floorInfo.matchingFloor; return enforceJS && (bidBelowFloor && shouldFloorDeal); } @@ -675,7 +669,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { let floorInfo = getFirstMatchingFloor(floorData.data, {...matchingBidRequest}, {...bid, size: [bid.width, bid.height]}); if (!floorInfo.matchingFloor) { - logWarn(`${MODULE_NAME}: unable to determine a matching price floor for bidResponse`, bid); + utils.logWarn(`${MODULE_NAME}: unable to determine a matching price floor for bidResponse`, bid); return fn.call(this, adUnitCode, bid); } @@ -691,7 +685,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { try { adjustedCpm = getGlobal().convertCurrency(bid.cpm, bidResponseCurrency.toUpperCase(), floorCurrency); } catch (err) { - logError(`${MODULE_NAME}: Unable do get currency conversion for bidResponse to Floor Currency. Do you have Currency module enabled? ${bid}`); + utils.logError(`${MODULE_NAME}: Unable do get currency conversion for bidResponse to Floor Currency. Do you have Currency module enabled? ${bid}`); return fn.call(this, adUnitCode, bid); } } @@ -707,7 +701,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { // bid fails floor -> throw it out // create basic bid no-bid with necessary data fro analytics adapters let flooredBid = createBid(CONSTANTS.STATUS.NO_BID, matchingBidRequest); - Object.assign(flooredBid, pick(bid, [ + Object.assign(flooredBid, utils.pick(bid, [ 'floorData', 'width', 'height', @@ -720,7 +714,7 @@ export function addBidResponseHook(fn, adUnitCode, bid) { flooredBid.status = CONSTANTS.BID_STATUS.BID_REJECTED; // if floor not met update bid with 0 cpm so it is not included downstream and marked as no-bid flooredBid.cpm = 0; - logWarn(`${MODULE_NAME}: ${flooredBid.bidderCode}'s Bid Response for ${adUnitCode} was rejected due to floor not met`, bid); + utils.logWarn(`${MODULE_NAME}: ${flooredBid.bidderCode}'s Bid Response for ${adUnitCode} was rejected due to floor not met`, bid); return fn.call(this, adUnitCode, flooredBid); } return fn.call(this, adUnitCode, bid); diff --git a/modules/proxistoreBidAdapter.js b/modules/proxistoreBidAdapter.js index 42a98bcdb09..8b191c70e75 100644 --- a/modules/proxistoreBidAdapter.js +++ b/modules/proxistoreBidAdapter.js @@ -1,11 +1,10 @@ -import { isFn, isPlainObject } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'proxistore'; const PROXISTORE_VENDOR_ID = 418; const COOKIE_BASE_URL = 'https://abs.proxistore.com/v3/rtb/prebid/multi'; -const COOKIE_LESS_URL = - 'https://abs.cookieless-proxistore.com/v3/rtb/prebid/multi'; +const COOKIE_LESS_URL = 'https://abs.cookieless-proxistore.com/v3/rtb/prebid/multi'; function _createServerRequest(bidRequests, bidderRequest) { var sizeIds = []; @@ -171,7 +170,9 @@ function interpretResponse(serverResponse, bidRequest) { } function _assignFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { + // eslint-disable-next-line no-console + console.log(bid.params.bidFloor); return bid.params.bidFloor ? bid.params.bidFloor : null; } const floor = bid.getFloor({ @@ -180,7 +181,11 @@ function _assignFloor(bid) { size: '*', }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'EUR') { + if ( + utils.isPlainObject(floor) && + !isNaN(floor.floor) && + floor.currency === 'EUR' + ) { return floor.floor; } return null; @@ -191,7 +196,6 @@ export const spec = { isBidRequestValid: isBidRequestValid, buildRequests: buildRequests, interpretResponse: interpretResponse, - gvlid: PROXISTORE_VENDOR_ID, }; registerBidder(spec); diff --git a/modules/pubCommonId.js b/modules/pubCommonId.js index 6ecf0723aae..427f775c44b 100644 --- a/modules/pubCommonId.js +++ b/modules/pubCommonId.js @@ -3,7 +3,7 @@ * stored in the page's domain. When the module is included, an id is generated if needed, * persisted as a cookie, and automatically appended to all the bidRequest as bid.crumbs.pubcid. */ -import { logMessage, parseUrl, buildUrl, triggerPixel, generateUUID, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import events from '../src/events.js'; import CONSTANTS from '../src/constants.json'; @@ -44,7 +44,7 @@ export function setStorageItem(key, val, expires) { storage.setDataInLocalStorage(key, val); } catch (e) { - logMessage(e); + utils.logMessage(e); } } @@ -74,7 +74,7 @@ export function getStorageItem(key) { } } } catch (e) { - logMessage(e); + utils.logMessage(e); } return val; @@ -89,7 +89,7 @@ export function removeStorageItem(key) { storage.removeDataFromLocalStorage(key + EXP_SUFFIX); storage.removeDataFromLocalStorage(key); } catch (e) { - logMessage(e); + utils.logMessage(e); } } @@ -141,13 +141,13 @@ function queuePixelCallback(pixelUrl, id) { id = id || ''; // Use pubcid as a cache buster - const urlInfo = parseUrl(pixelUrl); + const urlInfo = utils.parseUrl(pixelUrl); urlInfo.search.id = encodeURIComponent('pubcid:' + id); - const targetUrl = buildUrl(urlInfo); + const targetUrl = utils.buildUrl(urlInfo); events.on(CONSTANTS.EVENTS.AUCTION_END, function auctionEndHandler() { events.off(CONSTANTS.EVENTS.AUCTION_END, auctionEndHandler); - triggerPixel(targetUrl); + utils.triggerPixel(targetUrl); }); return true; @@ -177,7 +177,7 @@ export function requestBidHook(next, config) { if (typeof window[PUB_COMMON] === 'object') { // If the page includes its own pubcid object, then use that instead. pubcid = window[PUB_COMMON].getId(); - logMessage(PUB_COMMON + ': pubcid = ' + pubcid); + utils.logMessage(PUB_COMMON + ': pubcid = ' + pubcid); } else { // Otherwise get the existing cookie pubcid = readValue(ID_NAME); @@ -190,7 +190,7 @@ export function requestBidHook(next, config) { } // Generate a new id if (!pubcid) { - pubcid = generateUUID(); + pubcid = utils.generateUUID(); } // Update the cookie/storage with the latest expiration date writeValue(ID_NAME, pubcid, pubcidConfig.interval); @@ -205,14 +205,14 @@ export function requestBidHook(next, config) { } } - logMessage('pbjs: pubcid = ' + pubcid); + utils.logMessage('pbjs: pubcid = ' + pubcid); } // Append pubcid to each bid object, which will be incorporated // into bid requests later. if (adUnits && pubcid) { adUnits.forEach((unit) => { - if (unit.bids && isArray(unit.bids)) { + if (unit.bids && utils.isArray(unit.bids)) { unit.bids.forEach((bid) => { Object.assign(bid, {crumbs: {pubcid}}); }); diff --git a/modules/pubProvidedIdSystem.js b/modules/pubProvidedIdSystem.js index 669d223c57f..0b2175f57cb 100644 --- a/modules/pubProvidedIdSystem.js +++ b/modules/pubProvidedIdSystem.js @@ -6,7 +6,7 @@ */ import {submodule} from '../src/hook.js'; -import { logInfo, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const MODULE_NAME = 'pubProvidedId'; @@ -27,7 +27,7 @@ export const pubProvidedIdSubmodule = { */ decode(value) { const res = value ? {pubProvidedId: value} : undefined; - logInfo('PubProvidedId: Decoded value ' + JSON.stringify(res)); + utils.logInfo('PubProvidedId: Decoded value ' + JSON.stringify(res)); return res; }, @@ -40,7 +40,7 @@ export const pubProvidedIdSubmodule = { getId(config) { const configParams = (config && config.params) || {}; let res = []; - if (isArray(configParams.eids)) { + if (utils.isArray(configParams.eids)) { res = res.concat(configParams.eids); } if (typeof configParams.eidsFunction === 'function') { diff --git a/modules/pubgeniusBidAdapter.js b/modules/pubgeniusBidAdapter.js index 28c4fdefd42..89dea545434 100644 --- a/modules/pubgeniusBidAdapter.js +++ b/modules/pubgeniusBidAdapter.js @@ -16,7 +16,7 @@ import { } from '../src/utils.js'; const BIDDER_VERSION = '1.1.0'; -const BASE_URL = 'https://auction.adpearl.io'; +const BASE_URL = 'https://ortb.adpearl.io'; export const spec = { code: 'pubgenius', diff --git a/modules/publinkIdSystem.js b/modules/publinkIdSystem.js deleted file mode 100644 index 990227e7cfe..00000000000 --- a/modules/publinkIdSystem.js +++ /dev/null @@ -1,144 +0,0 @@ -/** - * This module adds the PublinkId to the User ID module - * The {@link module:modules/userId} module is required - * @module modules/publinkIdSystem - * @requires module:modules/userId - */ - -import {submodule} from '../src/hook.js'; -import {getStorageManager} from '../src/storageManager.js'; -import {ajax} from '../src/ajax.js'; -import { parseUrl, buildUrl, logError } from '../src/utils.js'; -import {uspDataHandler} from '../src/adapterManager.js'; - -const MODULE_NAME = 'publinkId'; -const GVLID = 24; -const PUBLINK_COOKIE = '_publink'; -const PUBLINK_S2S_COOKIE = '_publink_srv'; - -export const storage = getStorageManager(GVLID); - -function isHex(s) { - return /^[A-F0-9]+$/i.test(s); -} - -function publinkIdUrl(params, consentData) { - let url = parseUrl('https://proc.ad.cpe.dotomi.com/cvx/client/sync/publink'); - url.search = { - deh: params.e, - mpn: 'Prebid.js', - mpv: '$prebid.version$', - }; - - if (consentData) { - url.search.gdpr = (consentData.gdprApplies) ? 1 : 0; - url.search.gdpr_consent = consentData.consentString; - } - - if (params.site_id) { url.search.sid = params.site_id; } - - if (params.api_key) { url.search.apikey = params.api_key; } - - const usPrivacyString = uspDataHandler.getConsentData(); - if (usPrivacyString && typeof usPrivacyString === 'string') { - url.search.us_privacy = usPrivacyString; - } - - return buildUrl(url); -} - -function makeCallback(config = {}, consentData) { - return function(prebidCallback) { - const options = {method: 'GET', withCredentials: true}; - let handleResponse = function(responseText, xhr) { - if (xhr.status === 200) { - let response = JSON.parse(responseText); - if (response) { - prebidCallback(response.publink); - } - } - }; - - if (config.params && config.params.e) { - if (isHex(config.params.e)) { - ajax(publinkIdUrl(config.params, consentData), handleResponse, undefined, options); - } else { - logError('params.e must be a hex string'); - } - } - }; -} - -function getlocalValue() { - let result; - function getData(key) { - let value; - if (storage.hasLocalStorage()) { - value = storage.getDataFromLocalStorage(key); - } - if (!value) { - value = storage.getCookie(key); - } - - if (typeof value === 'string') { - // if it's a json object parse it and return the publink value, otherwise assume the value is the id - if (value.charAt(0) === '{') { - try { - const obj = JSON.parse(value); - if (obj) { - return obj.publink; - } - } catch (e) { - logError(e); - } - } else { - return value; - } - } - } - result = getData(PUBLINK_S2S_COOKIE); - if (!result) { - result = getData(PUBLINK_COOKIE); - } - return result; -} - -/** @type {Submodule} */ -export const publinkIdSubmodule = { - /** - * used to link submodule with config - * @type {string} - */ - name: MODULE_NAME, - gvlid: GVLID, - - /** - * decode the stored id value for passing to bid requests - * @function - * @param {string} publinkId encrypted userid - * @returns {{publinkId: string} | undefined} - */ - decode(publinkId) { - return {publinkId: publinkId}; - }, - - /** - * performs action to obtain id - * Use a publink cookie first if it is present, otherwise use prebids copy, if neither are available callout to get a new id - * @function - * @param {SubmoduleConfig} [config] Config object with params and storage properties - * @param {ConsentData|undefined} consentData GDPR consent - * @param {(Object|undefined)} storedId Previously cached id - * @returns {IdResponse} - */ - getId: function(config, consentData, storedId) { - const localValue = getlocalValue(); - if (localValue) { - return {id: localValue}; - } - if (!storedId) { - return {callback: makeCallback(config, consentData)}; - } - } -}; -submodule('userId', publinkIdSubmodule); diff --git a/modules/publinkIdSystem.md b/modules/publinkIdSystem.md deleted file mode 100644 index 263ce490529..00000000000 --- a/modules/publinkIdSystem.md +++ /dev/null @@ -1,33 +0,0 @@ -## Publink User ID Submodule - -Publink user id module - -## Configuration Descriptions for the `userId` Configuration Section - -| Param Name | Required | Type | Description | Example | -| --- | --- | --- | --- | --- | -| name | Yes | String | module identifier | `"publinkId"` | -| params.e | Yes | String | hashed email address | `"7D320454942620664D96EF78ED4E3A2A"` | -| params.api_key | Yes | String | api key for access | `"7ab62359-bdc0-4095-b573-ef474fb55d24"` | -| params.site_id | Yes | String | site identifier | `"123456"` | - - -### Example configuration for Publink -``` -pbjs.setConfig({ - userSync: { - userIds: [{ - name: "publinkId", - storage: { - name: "pbjs_publink", - type: "html5" - }, - params: { - e: "7D320454942620664D96EF78ED4E3A2A", // example hashed email (md5) - site_id: "123456", // provided by Epsilon - api_key: "7ab62359-bdc0-4095-b573-ef474fb55d2" // provided by Epsilon - } - }], - } - }); -``` diff --git a/modules/pubmaticAnalyticsAdapter.js b/modules/pubmaticAnalyticsAdapter.js index f69fb20e5d5..9aa40a2282d 100755 --- a/modules/pubmaticAnalyticsAdapter.js +++ b/modules/pubmaticAnalyticsAdapter.js @@ -1,9 +1,9 @@ -import { _each, pick, logWarn, isStr, isArray, logError } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import { ajax } from '../src/ajax.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; /// /////////// CONSTANTS ////////////// @@ -69,7 +69,7 @@ function setMediaTypes(types, bid) { if (typeof types === 'object') { if (!bid.sizes) { bid.dimensions = []; - _each(types, (type) => + utils._each(types, (type) => bid.dimensions = bid.dimensions.concat( type.sizes.map(sizeToDimensions) ) @@ -81,13 +81,13 @@ function setMediaTypes(types, bid) { } function copyRequiredBidDetails(bid) { - return pick(bid, [ + return utils.pick(bid, [ 'bidder', 'bidId', 'status', () => NO_BID, // default a bid to NO_BID until response is recieved or bid is timed out 'finalSource as source', 'params', - 'adUnit', () => pick(bid, [ + 'adUnit', () => utils.pick(bid, [ 'adUnitCode', 'transactionId', 'sizes as dimensions', sizes => sizes.map(sizeToDimensions), @@ -115,7 +115,7 @@ function setBidStatus(bid, args) { } function parseBidResponse(bid) { - return pick(bid, [ + return utils.pick(bid, [ 'bidPriceUSD', () => { // todo: check whether currency cases are handled here if (typeof bid.currency === 'string' && bid.currency.toUpperCase() === CURRENCY_USD) { @@ -125,7 +125,7 @@ function parseBidResponse(bid) { if (typeof bid.getCpmInNewCurrency === 'function') { return window.parseFloat(Number(bid.getCpmInNewCurrency(CURRENCY_USD)).toFixed(BID_PRECISION)); } - logWarn(LOG_PRE_FIX + 'Could not determine the Net cpm in USD for the bid thus using bid.cpm', bid); + utils.logWarn(LOG_PRE_FIX + 'Could not determine the Net cpm in USD for the bid thus using bid.cpm', bid); return bid.cpm }, 'bidGrossCpmUSD', () => { @@ -136,7 +136,7 @@ function parseBidResponse(bid) { if (typeof getGlobal().convertCurrency === 'function') { return window.parseFloat(Number(getGlobal().convertCurrency(bid.originalCpm, bid.originalCurrency, CURRENCY_USD)).toFixed(BID_PRECISION)); } - logWarn(LOG_PRE_FIX + 'Could not determine the Gross cpm in USD for the bid, thus using bid.originalCpm', bid); + utils.logWarn(LOG_PRE_FIX + 'Could not determine the Gross cpm in USD for the bid, thus using bid.originalCpm', bid); return bid.originalCpm }, 'dealId', @@ -154,7 +154,7 @@ function parseBidResponse(bid) { 'mi', 'regexPattern', () => bid.regexPattern || undefined, 'partnerImpId', // partner impression ID - 'dimensions', () => pick(bid, [ + 'dimensions', () => utils.pick(bid, [ 'width', 'height' ]) @@ -171,7 +171,7 @@ function getDevicePlatform() { var deviceType = 3; try { var ua = navigator.userAgent; - if (ua && isStr(ua) && ua.trim() != '') { + if (ua && utils.isStr(ua) && ua.trim() != '') { ua = ua.toLowerCase().trim(); var isMobileRegExp = new RegExp('(mobi|tablet|ios).*'); if (ua.match(isMobileRegExp)) { @@ -200,21 +200,6 @@ function getAdapterNameForAlias(aliasName) { return adapterManager.aliasRegistry[aliasName] || aliasName; } -function getAdDomain(bidResponse) { - if (bidResponse.meta && bidResponse.meta.advertiserDomains) { - let adomain = bidResponse.meta.advertiserDomains[0] - if (adomain) { - try { - let hostname = (new URL(adomain)); - return hostname.hostname.replace('www.', ''); - } catch (e) { - logWarn(LOG_PRE_FIX + 'Adomain URL (Not a proper URL):', adomain); - return adomain.replace('www.', ''); - } - } - } -} - function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) { highestBid = (highestBid && highestBid.length > 0) ? highestBid[0] : null; return Object.keys(adUnit.bids).reduce(function(partnerBids, bidId) { @@ -233,7 +218,6 @@ function gatherPartnerBidsForAdUnitForLogger(adUnit, adUnitId, highestBid) { 'dc': bid.bidResponse ? (bid.bidResponse.dealChannel || EMPTY_STRING) : EMPTY_STRING, 'l1': bid.bidResponse ? bid.clientLatencyTimeMs : 0, 'l2': 0, - 'adv': bid.bidResponse ? getAdDomain(bid.bidResponse) || undefined : undefined, 'ss': (s2sBidders.indexOf(bid.bidder) > -1) ? 1 : 0, 't': (bid.status == ERROR && bid.error.code == TIMEOUT_ERROR) ? 1 : 0, 'wb': (highestBid && highestBid.requestId === bid.bidId ? 1 : 0), @@ -341,9 +325,9 @@ function executeBidWonLoggerCall(auctionId, adUnitId) { function auctionInitHandler(args) { s2sBidders = (function() { let s2sConf = config.getConfig('s2sConfig'); - return (s2sConf && isArray(s2sConf.bidders)) ? s2sConf.bidders : []; + return (s2sConf && utils.isArray(s2sConf.bidders)) ? s2sConf.bidders : []; }()); - let cacheEntry = pick(args, [ + let cacheEntry = utils.pick(args, [ 'timestamp', 'timeout', 'bidderDonePendingCount', () => args.bidderRequests.length, @@ -369,7 +353,7 @@ function bidRequestedHandler(args) { function bidResponseHandler(args) { let bid = cache.auctions[args.auctionId].adUnitCodes[args.adUnitCode].bids[args.requestId]; if (!bid) { - logError(LOG_PRE_FIX + 'Could not find associated bid request for bid response with requestId: ', args.requestId); + utils.logError(LOG_PRE_FIX + 'Could not find associated bid request for bid response with requestId: ', args.requestId); return; } bid.source = formatSource(bid.source || args.source); @@ -420,7 +404,7 @@ function bidTimeoutHandler(args) { code: TIMEOUT_ERROR }; } else { - logWarn(LOG_PRE_FIX + 'bid not found'); + utils.logWarn(LOG_PRE_FIX + 'bid not found'); } }); } @@ -440,17 +424,17 @@ let pubmaticAdapter = Object.assign({}, baseAdapter, { profileId = Number(conf.options.profileId) || DEFAULT_PROFILE_ID; profileVersionId = Number(conf.options.profileVersionId) || DEFAULT_PROFILE_VERSION_ID; } else { - logError(LOG_PRE_FIX + 'Config not found.'); + utils.logError(LOG_PRE_FIX + 'Config not found.'); error = true; } if (!publisherId) { - logError(LOG_PRE_FIX + 'Missing publisherId(Number).'); + utils.logError(LOG_PRE_FIX + 'Missing publisherId(Number).'); error = true; } if (error) { - logError(LOG_PRE_FIX + 'Not collecting data due to error(s).'); + utils.logError(LOG_PRE_FIX + 'Not collecting data due to error(s).'); } else { baseAdapter.enableAnalytics.call(this, conf); } diff --git a/modules/pubmaticBidAdapter.js b/modules/pubmaticBidAdapter.js index 366a0326054..f6e6e67444a 100644 --- a/modules/pubmaticBidAdapter.js +++ b/modules/pubmaticBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn, _each, isBoolean, isStr, isArray, inIframe, mergeDeep, deepAccess, isNumber, deepSetValue, logInfo, logError, deepClone, convertTypes } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js'; import {config} from '../src/config.js'; @@ -11,14 +11,12 @@ const USER_SYNC_URL_IFRAME = 'https://ads.pubmatic.com/AdServer/js/user_sync.htm const USER_SYNC_URL_IMAGE = 'https://image8.pubmatic.com/AdServer/ImgSync?p='; const DEFAULT_CURRENCY = 'USD'; const AUCTION_TYPE = 1; -const GROUPM_ALIAS = {code: 'groupm', gvlid: 98}; const UNDEFINED = undefined; const DEFAULT_WIDTH = 0; const DEFAULT_HEIGHT = 0; const PREBID_NATIVE_HELP_LINK = 'http://prebid.org/dev-docs/show-native-ads.html'; const PUBLICATION = 'pubmatic'; // Your publication on Blue Billywig, potentially with environment (e.g. publication.bbvms.com or publication.test.bbvms.com) const RENDERER_URL = 'https://pubmatic.bbvms.com/r/'.concat('$RENDERER', '.js'); // URL of the renderer application -const MSG_VIDEO_PLACEMENT_MISSING = 'Video.Placement param missing'; const CUSTOM_PARAMS = { 'kadpageurl': '', // Custom page url 'gender': '', // User gender @@ -126,7 +124,7 @@ const BB_RENDERER = { else if (bid.vastUrl) config.vastUrl = bid.vastUrl; if (!bid.vastXml && !bid.vastUrl) { - logWarn(`${LOG_WARN_PREFIX}: No vastXml or vastUrl on bid, bailing...`); + utils.logWarn(`${LOG_WARN_PREFIX}: No vastXml or vastUrl on bid, bailing...`); return; } @@ -144,7 +142,7 @@ const BB_RENDERER = { } if (renderer) renderer.bootstrap(config, ele); - else logWarn(`${LOG_WARN_PREFIX}: Couldn't find a renderer with ${rendererId}`); + else utils.logWarn(`${LOG_WARN_PREFIX}: Couldn't find a renderer with ${rendererId}`); }, newRenderer: function(rendererCode, adUnitCode) { var rendererUrl = RENDERER_URL.replace('$RENDERER', rendererCode); @@ -157,7 +155,7 @@ const BB_RENDERER = { try { renderer.setRender(BB_RENDERER.outstreamRender); } catch (err) { - logWarn(`${LOG_WARN_PREFIX}: Error tying to setRender on renderer`, err); + utils.logWarn(`${LOG_WARN_PREFIX}: Error tying to setRender on renderer`, err); } return renderer; @@ -182,9 +180,9 @@ let NATIVE_ASSET_ID_TO_KEY_MAP = {}; let NATIVE_ASSET_KEY_TO_ASSET_MAP = {}; // loading NATIVE_ASSET_ID_TO_KEY_MAP -_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY }); +utils._each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY }); // loading NATIVE_ASSET_KEY_TO_ASSET_MAP -_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset }); +utils._each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset }); function _getDomainFromURL(url) { let anchor = document.createElement('a'); @@ -193,8 +191,8 @@ function _getDomainFromURL(url) { } function _parseSlotParam(paramName, paramValue) { - if (!isStr(paramValue)) { - paramValue && logWarn(LOG_WARN_PREFIX + 'Ignoring param key: ' + paramName + ', expects string-value, found ' + typeof paramValue); + if (!utils.isStr(paramValue)) { + paramValue && utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param key: ' + paramName + ', expects string-value, found ' + typeof paramValue); return UNDEFINED; } @@ -215,11 +213,11 @@ function _parseSlotParam(paramName, paramValue) { } function _cleanSlot(slotName) { - if (isStr(slotName)) { + if (utils.isStr(slotName)) { return slotName.replace(/^\s+/g, '').replace(/\s+$/g, ''); } if (slotName) { - logWarn(BIDDER_CODE + ': adSlot must be a string. Ignoring adSlot'); + utils.logWarn(BIDDER_CODE + ': adSlot must be a string. Ignoring adSlot'); } return ''; } @@ -245,7 +243,7 @@ function _parseAdSlot(bid) { // i.e size is specified in adslot, so consider that and ignore sizes array splits = splits[1].split('x'); if (splits.length != 2) { - logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format'); + utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format'); return; } bid.params.width = parseInt(splits[0], 10); @@ -296,10 +294,10 @@ function _handleCustomParams(params, conf) { value = entry.f(value, conf); } - if (isStr(value)) { + if (utils.isStr(value)) { conf[key] = value; } else { - logWarn(LOG_WARN_PREFIX + 'Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value); + utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value); } } } @@ -336,22 +334,22 @@ function _checkParamDataType(key, value, datatype) { var functionToExecute; switch (datatype) { case DATA_TYPES.BOOLEAN: - functionToExecute = isBoolean; + functionToExecute = utils.isBoolean; break; case DATA_TYPES.NUMBER: - functionToExecute = isNumber; + functionToExecute = utils.isNumber; break; case DATA_TYPES.STRING: - functionToExecute = isStr; + functionToExecute = utils.isStr; break; case DATA_TYPES.ARRAY: - functionToExecute = isArray; + functionToExecute = utils.isArray; break; } if (functionToExecute(value)) { return value; } - logWarn(LOG_WARN_PREFIX + errMsg); + utils.logWarn(LOG_WARN_PREFIX + errMsg); return UNDEFINED; } @@ -388,7 +386,7 @@ function _createNativeRequest(params) { } }; } else { - logWarn(LOG_WARN_PREFIX + 'Error: Title Length is required for native ad: ' + JSON.stringify(params)); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Title Length is required for native ad: ' + JSON.stringify(params)); } break; case NATIVE_ASSETS.IMAGE.KEY: @@ -407,7 +405,7 @@ function _createNativeRequest(params) { } }; } else { - logWarn(LOG_WARN_PREFIX + 'Error: Image sizes is required for native ad: ' + JSON.stringify(params)); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Image sizes is required for native ad: ' + JSON.stringify(params)); } break; case NATIVE_ASSETS.ICON.KEY: @@ -422,7 +420,7 @@ function _createNativeRequest(params) { } }; } else { - logWarn(LOG_WARN_PREFIX + 'Error: Icon sizes is required for native ad: ' + JSON.stringify(params)); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Icon sizes is required for native ad: ' + JSON.stringify(params)); }; break; case NATIVE_ASSETS.VIDEO.KEY: @@ -502,13 +500,13 @@ function _createBannerRequest(bid) { var sizes = bid.mediaTypes.banner.sizes; var format = []; var bannerObj; - if (sizes !== UNDEFINED && isArray(sizes)) { + if (sizes !== UNDEFINED && utils.isArray(sizes)) { bannerObj = {}; if (!bid.params.width && !bid.params.height) { if (sizes.length === 0) { // i.e. since bid.params does not have width or height, and length of sizes is 0, need to ignore this banner imp bannerObj = UNDEFINED; - logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); return bannerObj; } else { bannerObj.w = parseInt(sizes[0][0], 10); @@ -531,44 +529,36 @@ function _createBannerRequest(bid) { } } bannerObj.pos = 0; - bannerObj.topframe = inIframe() ? 0 : 1; + bannerObj.topframe = utils.inIframe() ? 0 : 1; } else { - logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); bannerObj = UNDEFINED; } return bannerObj; } -export function checkVideoPlacement(videoData, adUnitCode) { - // Check for video.placement property. If property is missing display log message. - if (!deepAccess(videoData, 'placement')) { - logWarn(MSG_VIDEO_PLACEMENT_MISSING + ' for ' + adUnitCode); - }; -} - function _createVideoRequest(bid) { - var videoData = mergeDeep(deepAccess(bid.mediaTypes, 'video'), bid.params.video); + var videoData = utils.mergeDeep(utils.deepAccess(bid.mediaTypes, 'video'), bid.params.video); var videoObj; if (videoData !== UNDEFINED) { videoObj = {}; - checkVideoPlacement(videoData, bid.adUnitCode); for (var key in VIDEO_CUSTOM_PARAMS) { if (videoData.hasOwnProperty(key)) { videoObj[key] = _checkParamDataType(key, videoData[key], VIDEO_CUSTOM_PARAMS[key]); } } // read playersize and assign to h and w. - if (isArray(bid.mediaTypes.video.playerSize[0])) { + if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0][0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[0][1], 10); - } else if (isNumber(bid.mediaTypes.video.playerSize[0])) { + } else if (utils.isNumber(bid.mediaTypes.video.playerSize[0])) { videoObj.w = parseInt(bid.mediaTypes.video.playerSize[0], 10); videoObj.h = parseInt(bid.mediaTypes.video.playerSize[1], 10); } } else { videoObj = UNDEFINED; - logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Video config params missing for adunit: ' + bid.params.adUnit + ' with mediaType set as video. Ignoring video impression in the adunit.'); } return videoObj; } @@ -576,19 +566,19 @@ function _createVideoRequest(bid) { // support for PMP deals function _addPMPDealsInImpression(impObj, bid) { if (bid.params.deals) { - if (isArray(bid.params.deals)) { + if (utils.isArray(bid.params.deals)) { bid.params.deals.forEach(function(dealId) { - if (isStr(dealId) && dealId.length > 3) { + if (utils.isStr(dealId) && dealId.length > 3) { if (!impObj.pmp) { impObj.pmp = { private_auction: 0, deals: [] }; } impObj.pmp.deals.push({ id: dealId }); } else { - logWarn(LOG_WARN_PREFIX + 'Error: deal-id present in array bid.params.deals should be a strings with more than 3 charaters length, deal-id ignored: ' + dealId); + utils.logWarn(LOG_WARN_PREFIX + 'Error: deal-id present in array bid.params.deals should be a strings with more than 3 charaters length, deal-id ignored: ' + dealId); } }); } else { - logWarn(LOG_WARN_PREFIX + 'Error: bid.params.deals should be an array of strings.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: bid.params.deals should be an array of strings.'); } } } @@ -598,7 +588,7 @@ function _addDealCustomTargetings(imp, bid) { var dctrLen; if (bid.params.dctr) { dctr = bid.params.dctr; - if (isStr(dctr) && dctr.length > 0) { + if (utils.isStr(dctr) && dctr.length > 0) { var arr = dctr.split('|'); dctr = ''; arr.forEach(val => { @@ -610,36 +600,11 @@ function _addDealCustomTargetings(imp, bid) { } imp.ext['key_val'] = dctr.trim() } else { - logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value'); + utils.logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value'); } } } -function _addJWPlayerSegmentData(imp, bid, isS2S) { - var jwSegData = (bid.rtd && bid.rtd.jwplayer && bid.rtd.jwplayer.targeting) || undefined; - var jwPlayerData = ''; - const jwMark = 'jw-'; - - if (jwSegData === undefined || jwSegData === '' || !jwSegData.hasOwnProperty('segments')) return; - - var maxLength = jwSegData.segments.length; - - jwPlayerData += jwMark + 'id=' + jwSegData.content.id; // add the content id first - - for (var i = 0; i < maxLength; i++) { - jwPlayerData += '|' + jwMark + jwSegData.segments[i] + '=1'; - } - - var ext; - - if (isS2S) { - (imp.dctr === undefined || imp.dctr.length == 0) ? imp.dctr = jwPlayerData : imp.dctr += '|' + jwPlayerData; - } else { - ext = imp.ext; - ext && ext.key_val === undefined ? ext.key_val = jwPlayerData : ext.key_val += '|' + jwPlayerData; - } -} - function _createImpressionObject(bid, conf) { var impObj = {}; var bannerObj; @@ -662,7 +627,6 @@ function _createImpressionObject(bid, conf) { _addPMPDealsInImpression(impObj, bid); _addDealCustomTargetings(impObj, bid); - _addJWPlayerSegmentData(impObj, bid); if (bid.hasOwnProperty('mediaTypes')) { for (mediaTypes in bid.mediaTypes) { switch (mediaTypes) { @@ -677,7 +641,7 @@ function _createImpressionObject(bid, conf) { if (!isInvalidNativeRequest) { impObj.native = nativeObj; } else { - logWarn(LOG_WARN_PREFIX + 'Error: Error in Native adunit ' + bid.params.adUnit + '. Ignoring the adunit. Refer to ' + PREBID_NATIVE_HELP_LINK + ' for more details.'); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Error in Native adunit ' + bid.params.adUnit + '. Ignoring the adunit. Refer to ' + PREBID_NATIVE_HELP_LINK + ' for more details.'); } break; case VIDEO: @@ -695,9 +659,9 @@ function _createImpressionObject(bid, conf) { pos: 0, w: bid.params.width, h: bid.params.height, - topframe: inIframe() ? 0 : 1 + topframe: utils.inIframe() ? 0 : 1 }; - if (isArray(sizes) && sizes.length > 1) { + if (utils.isArray(sizes) && sizes.length > 1) { sizes = sizes.splice(1, sizes.length - 1); sizes.forEach(size => { format.push({ @@ -720,31 +684,31 @@ function _createImpressionObject(bid, conf) { } function _addImpressionFPD(imp, bid) { - const ortb2 = {...deepAccess(bid, 'ortb2Imp.ext.data')}; + const ortb2 = {...utils.deepAccess(bid, 'ortb2Imp.ext.data')}; Object.keys(ortb2).forEach(prop => { /** * Prebid AdSlot * @type {(string|undefined)} */ if (prop === 'pbadslot') { - if (typeof ortb2[prop] === 'string' && ortb2[prop]) deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); + if (typeof ortb2[prop] === 'string' && ortb2[prop]) utils.deepSetValue(imp, 'ext.data.pbadslot', ortb2[prop]); } else if (prop === 'adserver') { /** * Copy GAM AdUnit and Name to imp */ ['name', 'adslot'].forEach(name => { /** @type {(string|undefined)} */ - const value = deepAccess(ortb2, `adserver.${name}`); + const value = utils.deepAccess(ortb2, `adserver.${name}`); if (typeof value === 'string' && value) { - deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); + utils.deepSetValue(imp, `ext.data.adserver.${name.toLowerCase()}`, value); // copy GAM ad unit id as imp[].ext.dfp_ad_unit_code if (name === 'adslot') { - deepSetValue(imp, `ext.dfp_ad_unit_code`, value); + utils.deepSetValue(imp, `ext.dfp_ad_unit_code`, value); } } }); } else { - deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); + utils.deepSetValue(imp, `ext.data.${prop}`, ortb2[prop]); } }); } @@ -755,53 +719,27 @@ function _addFloorFromFloorModule(impObj, bid) { if (typeof bid.getFloor === 'function' && !config.getConfig('pubmatic.disableFloors')) { [BANNER, VIDEO, NATIVE].forEach(mediaType => { if (impObj.hasOwnProperty(mediaType)) { - let sizesArray = []; - - if (mediaType === 'banner') { - if (impObj[mediaType].w && impObj[mediaType].h) { - sizesArray.push([impObj[mediaType].w, impObj[mediaType].h]); - } - if (isArray(impObj[mediaType].format)) { - impObj[mediaType].format.forEach(size => sizesArray.push([size.w, size.h])); - } - } - - if (sizesArray.length === 0) { - sizesArray.push('*') + let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: '*' }); + if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) { + let mediaTypeFloor = parseFloat(floorInfo.floor); + bidFloor = (bidFloor == -1 ? mediaTypeFloor : Math.min(mediaTypeFloor, bidFloor)) } - - sizesArray.forEach(size => { - let floorInfo = bid.getFloor({ currency: impObj.bidfloorcur, mediaType: mediaType, size: size }); - logInfo(LOG_WARN_PREFIX, 'floor from floor module returned for mediatype:', mediaType, ' and size:', size, ' is: currency', floorInfo.currency, 'floor', floorInfo.floor); - if (typeof floorInfo === 'object' && floorInfo.currency === impObj.bidfloorcur && !isNaN(parseInt(floorInfo.floor))) { - let mediaTypeFloor = parseFloat(floorInfo.floor); - logInfo(LOG_WARN_PREFIX, 'floor from floor module:', mediaTypeFloor, 'previous floor value', bidFloor, 'Min:', Math.min(mediaTypeFloor, bidFloor)); - if (bidFloor === -1) { - bidFloor = mediaTypeFloor; - } else { - bidFloor = Math.min(mediaTypeFloor, bidFloor) - } - logInfo(LOG_WARN_PREFIX, 'new floor value:', bidFloor); - } - }); } }); } // get highest from impObj.bidfllor and floor from floor module // as we are using Math.max, it is ok if we have not got any floor from floorModule, then value of bidFloor will be -1 if (impObj.bidfloor) { - logInfo(LOG_WARN_PREFIX, 'floor from floor module:', bidFloor, 'impObj.bidfloor', impObj.bidfloor, 'Max:', Math.max(bidFloor, impObj.bidfloor)); bidFloor = Math.max(bidFloor, impObj.bidfloor) } // assign value only if bidFloor is > 0 impObj.bidfloor = ((!isNaN(bidFloor) && bidFloor > 0) ? bidFloor : UNDEFINED); - logInfo(LOG_WARN_PREFIX, 'new impObj.bidfloor value:', impObj.bidfloor); } function _getFlocId(validBidRequests, flocFormat) { var flocIdObject = null; - var flocId = deepAccess(validBidRequests, '0.userId.flocId'); + var flocId = utils.deepAccess(validBidRequests, '0.userId.flocId'); if (flocId && flocId.id) { switch (flocFormat) { case FLOC_FORMAT.SEGMENT: @@ -852,7 +790,7 @@ function _handleFlocId(payload, validBidRequests) { } function _handleEids(payload, validBidRequests) { - let bidUserIdAsEids = deepAccess(validBidRequests, '0.userIdAsEids'); + let bidUserIdAsEids = utils.deepAccess(validBidRequests, '0.userIdAsEids'); let flocObject = _getFlocId(validBidRequests, FLOC_FORMAT.EID); if (flocObject) { if (!bidUserIdAsEids) { @@ -860,17 +798,17 @@ function _handleEids(payload, validBidRequests) { } bidUserIdAsEids.push(flocObject); } - if (isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { - deepSetValue(payload, 'user.eids', bidUserIdAsEids); + if (utils.isArray(bidUserIdAsEids) && bidUserIdAsEids.length > 0) { + utils.deepSetValue(payload, 'user.eids', bidUserIdAsEids); } } function _checkMediaType(bid, newBid) { // Create a regex here to check the strings - if (bid.ext && bid.ext['bidtype'] != undefined) { - newBid.mediaType = MEDIATYPE[bid.ext.bidtype]; + if (bid.ext && bid.ext['BidType'] != undefined) { + newBid.mediaType = MEDIATYPE[bid.ext.BidType]; } else { - logInfo(LOG_WARN_PREFIX + 'bid.ext.bidtype does not exist, checking alternatively for mediaType') + utils.logInfo(LOG_WARN_PREFIX + 'bid.ext.BidType does not exist, checking alternatively for mediaType') var adm = bid.adm; var admStr = ''; var videoRegex = new RegExp(/VAST\s+version/); @@ -885,7 +823,7 @@ function _checkMediaType(bid, newBid) { newBid.mediaType = NATIVE; } } catch (e) { - logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + adm); } } } @@ -898,7 +836,7 @@ function _parseNativeResponse(bid, newBid) { try { adm = JSON.parse(bid.adm.replace(/\\/g, '')); } catch (ex) { - logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); + utils.logWarn(LOG_WARN_PREFIX + 'Error: Cannot parse native reponse for ad response: ' + newBid.adm); return; } if (adm && adm.native && adm.native.assets && adm.native.assets.length > 0) { @@ -958,7 +896,7 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) { if (typeof category === 'string') { // only strings return true; } else { - logWarn(LOG_WARN_PREFIX + 'bcat: Each category should be a string, ignoring category: ' + category); + utils.logWarn(LOG_WARN_PREFIX + 'bcat: Each category should be a string, ignoring category: ' + category); return false; } }) @@ -967,11 +905,11 @@ function _blockedIabCategoriesValidation(payload, blockedIabCategories) { if (category.length > 3) { return arr.indexOf(category) === index; // unique value only } else { - logWarn(LOG_WARN_PREFIX + 'bcat: Each category should have a value of a length of more than 3 characters, ignoring category: ' + category) + utils.logWarn(LOG_WARN_PREFIX + 'bcat: Each category should have a value of a length of more than 3 characters, ignoring category: ' + category) } }); if (blockedIabCategories.length > 0) { - logWarn(LOG_WARN_PREFIX + 'bcat: Selected: ', blockedIabCategories); + utils.logWarn(LOG_WARN_PREFIX + 'bcat: Selected: ', blockedIabCategories); payload.bcat = blockedIabCategories; } } @@ -994,7 +932,7 @@ function _assignRenderer(newBid, request) { } function isNonEmptyArray(test) { - if (isArray(test) === true) { + if (utils.isArray(test) === true) { if (test.length > 0) { return true; } @@ -1006,7 +944,6 @@ export const spec = { code: BIDDER_CODE, gvlid: 76, supportedMediaTypes: [BANNER, VIDEO, NATIVE], - aliases: [GROUPM_ALIAS], /** * Determines whether or not the given bid request is valid. Valid bid request must have placementId and hbid * @@ -1015,27 +952,27 @@ export const spec = { */ isBidRequestValid: bid => { if (bid && bid.params) { - if (!isStr(bid.params.publisherId)) { - logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric (wrap it in quotes in your config). Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid)); + if (!utils.isStr(bid.params.publisherId)) { + utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric (wrap it in quotes in your config). Call to OpenBid will not be sent for ad unit: ' + JSON.stringify(bid)); return false; } // video ad validation if (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(VIDEO)) { // bid.mediaTypes.video.mimes OR bid.params.video.mimes should be present and must be a non-empty array - let mediaTypesVideoMimes = deepAccess(bid.mediaTypes, 'video.mimes'); - let paramsVideoMimes = deepAccess(bid, 'params.video.mimes'); + let mediaTypesVideoMimes = utils.deepAccess(bid.mediaTypes, 'video.mimes'); + let paramsVideoMimes = utils.deepAccess(bid, 'params.video.mimes'); if (isNonEmptyArray(mediaTypesVideoMimes) === false && isNonEmptyArray(paramsVideoMimes) === false) { - logWarn(LOG_WARN_PREFIX + 'Error: For video ads, bid.mediaTypes.video.mimes OR bid.params.video.mimes should be present and must be a non-empty array. Call to OpenBid will not be sent for ad unit:' + JSON.stringify(bid)); + utils.logWarn(LOG_WARN_PREFIX + 'Error: For video ads, bid.mediaTypes.video.mimes OR bid.params.video.mimes should be present and must be a non-empty array. Call to OpenBid will not be sent for ad unit:' + JSON.stringify(bid)); return false; } if (!bid.mediaTypes[VIDEO].hasOwnProperty('context')) { - logError(`${LOG_WARN_PREFIX}: no context specified in bid. Rejecting bid: `, bid); + utils.logError(`${LOG_WARN_PREFIX}: no context specified in bid. Rejecting bid: `, bid); return false; } if (bid.mediaTypes[VIDEO].context === 'outstream' && - !isStr(bid.params.outstreamAU) && + !utils.isStr(bid.params.outstreamAU) && !bid.hasOwnProperty('renderer') && !bid.mediaTypes[VIDEO].hasOwnProperty('renderer')) { // we are here since outstream ad-unit is provided without outstreamAU and renderer @@ -1045,10 +982,10 @@ export const spec = { if (bid.mediaTypes.hasOwnProperty(BANNER) || bid.mediaTypes.hasOwnProperty(NATIVE)) { delete bid.mediaTypes[VIDEO]; - logWarn(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting mediatype Video of bid: `, bid); + utils.logWarn(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting mediatype Video of bid: `, bid); return true; } else { - logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid); + utils.logError(`${LOG_WARN_PREFIX}: for "outstream" bids either outstreamAU parameter must be provided or ad unit supplied renderer is required. Rejecting bid: `, bid); return false; } } @@ -1077,7 +1014,7 @@ export const spec = { var blockedIabCategories = []; validBidRequests.forEach(originalBid => { - bid = deepClone(originalBid); + bid = utils.deepClone(originalBid); bid.params.adSlot = bid.params.adSlot || ''; _parseAdSlot(bid); if (bid.params.hasOwnProperty('video')) { @@ -1086,7 +1023,7 @@ export const spec = { // If we have a native mediaType configured alongside banner, its ok if the banner size is not set in width and height // The corresponding banner imp object will not be generated, but we still want the native object to be sent, hence the following check if (!(bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty(NATIVE)) && bid.params.width === 0 && bid.params.height === 0) { - logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid)); + utils.logWarn(LOG_WARN_PREFIX + 'Skipping the non-standard adslot: ', bid.params.adSlot, JSON.stringify(bid)); return; } } @@ -1096,14 +1033,14 @@ export const spec = { if (bidCurrency === '') { bidCurrency = bid.params.currency || UNDEFINED; } else if (bid.params.hasOwnProperty('currency') && bidCurrency !== bid.params.currency) { - logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); + utils.logWarn(LOG_WARN_PREFIX + 'Currency specifier ignored. Only one currency permitted.'); } bid.params.currency = bidCurrency; // check if dctr is added to more than 1 adunit - if (bid.params.hasOwnProperty('dctr') && isStr(bid.params.dctr)) { + if (bid.params.hasOwnProperty('dctr') && utils.isStr(bid.params.dctr)) { dctrArr.push(bid.params.dctr); } - if (bid.params.hasOwnProperty('bcat') && isArray(bid.params.bcat)) { + if (bid.params.hasOwnProperty('bcat') && utils.isArray(bid.params.bcat)) { blockedIabCategories = blockedIabCategories.concat(bid.params.bcat); } var impObj = _createImpressionObject(bid, conf); @@ -1146,7 +1083,7 @@ export const spec = { } // passing transactionId in source.tid - deepSetValue(payload, 'source.tid', conf.transactionId); + utils.deepSetValue(payload, 'source.tid', conf.transactionId); // test bids if (window.location.href.indexOf('pubmaticTest=true') !== -1) { @@ -1155,23 +1092,23 @@ export const spec = { // adding schain object if (validBidRequests[0].schain) { - deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } // Attaching GDPR Consent Params if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // coppa compliance if (config.getConfig('coppa') === true) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } _handleEids(payload, validBidRequests); @@ -1180,10 +1117,10 @@ export const spec = { // First Party Data const commonFpd = config.getConfig('ortb2') || {}; if (commonFpd.site) { - mergeDeep(payload, {site: commonFpd.site}); + utils.mergeDeep(payload, {site: commonFpd.site}); } if (commonFpd.user) { - mergeDeep(payload, {user: commonFpd.user}); + utils.mergeDeep(payload, {user: commonFpd.user}); } // Note: Do not move this block up @@ -1221,12 +1158,12 @@ export const spec = { let parsedRequest = JSON.parse(request.data); let parsedReferrer = parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : ''; try { - if (response.body && response.body.seatbid && isArray(response.body.seatbid)) { + if (response.body && response.body.seatbid && utils.isArray(response.body.seatbid)) { // Supporting multiple bid responses for same adSize respCur = response.body.cur || respCur; response.body.seatbid.forEach(seatbidder => { seatbidder.bid && - isArray(seatbidder.bid) && + utils.isArray(seatbidder.bid) && seatbidder.bid.forEach(bid => { let newBid = { requestId: bid.impid, @@ -1292,7 +1229,7 @@ export const spec = { }); } } catch (error) { - logError(error); + utils.logError(error); } return bidResponses; }, @@ -1338,10 +1275,8 @@ export const spec = { * @param {Boolean} isOpenRtb boolean to check openrtb2 protocol * @return {Object} params bid params */ - - transformBidParams: function (params, isOpenRtb, adUnit, bidRequests) { - _addJWPlayerSegmentData(params, adUnit.bids[0], true); - return convertTypes({ + transformBidParams: function (params, isOpenRtb) { + return utils.convertTypes({ 'publisherId': 'string', 'adSlot': 'string' }, params); diff --git a/modules/pubmaticBidAdapter.md b/modules/pubmaticBidAdapter.md index baf58177505..e9d93d79758 100644 --- a/modules/pubmaticBidAdapter.md +++ b/modules/pubmaticBidAdapter.md @@ -25,7 +25,7 @@ var adUnits = [ bidder: 'pubmatic', params: { publisherId: '156209', // required, must be a string, not an integer or other js type. - outstreamAU: 'renderer_test_pubmatic', // required if mediaTypes-> video-> context is 'outstream' and optional if renderer is defined in adUnits or in mediaType video. This value can be get by BlueBillyWig Team. + oustreamAU: 'renderer_test_pubmatic', // required if mediaTypes-> video-> context is 'outstream' and optional if renderer is defined in adUnits or in mediaType video. This value can be get by BlueBillyWig Team. adSlot: 'pubmatic_test2', // optional, must be a string, not an integer or other js type. pmzoneid: 'zone1, zone11', // optional lat: '40.712775', // optional diff --git a/modules/pubperfAnalyticsAdapter.js b/modules/pubperfAnalyticsAdapter.js index 9282d5814c0..800ea1cd550 100644 --- a/modules/pubperfAnalyticsAdapter.js +++ b/modules/pubperfAnalyticsAdapter.js @@ -4,7 +4,7 @@ import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; var pubperfAdapter = adapter({ global: 'pubperf_pbjs', @@ -16,11 +16,11 @@ pubperfAdapter.originEnableAnalytics = pubperfAdapter.enableAnalytics; pubperfAdapter.enableAnalytics = config => { if (!config || !config.provider || config.provider !== 'pubperf') { - logError('expected config.provider to equal pubperf'); + utils.logError('expected config.provider to equal pubperf'); return; } if (!window['pubperf_pbjs']) { - logError( + utils.logError( `Make sure that Pubperf tag from https://www.pubperf.com is included before the Prebid configuration.` ); return; diff --git a/modules/pubwiseAnalyticsAdapter.js b/modules/pubwiseAnalyticsAdapter.js index 006d6da7eb7..fe217454b88 100644 --- a/modules/pubwiseAnalyticsAdapter.js +++ b/modules/pubwiseAnalyticsAdapter.js @@ -1,9 +1,9 @@ -import { getParameterByName, logInfo, generateUUID, debugTurnedOn } from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import { getStorageManager } from '../src/storageManager.js'; +const utils = require('../src/utils.js'); const storage = getStorageManager(); /**** @@ -76,7 +76,7 @@ function enrichWithUTM(dataBag) { let newUtm = false; try { for (let prop in utmKeys) { - utmKeys[prop] = getParameterByName(prop); + utmKeys[prop] = utils.getParameterByName(prop); if (utmKeys[prop]) { newUtm = true; dataBag[prop] = utmKeys[prop]; @@ -192,7 +192,7 @@ function markEnabled() { } function pwInfo(info, context) { - logInfo(`${analyticsName} ` + info, context); + utils.logInfo(`${analyticsName} ` + info, context); } function filterBidResponse(data) { @@ -304,7 +304,7 @@ pubwiseAnalytics.storeSessionID = function (userSessID) { // ensure a session exists, if not make one, always store it pubwiseAnalytics.ensureSession = function () { if (sessionExpired() === true || userSessionID() === null || userSessionID() === '') { - let generatedId = generateUUID(); + let generatedId = utils.generateUUID(); expireUtmData(); this.storeSessionID(generatedId); sessionData.sessionId = generatedId; @@ -320,10 +320,10 @@ pubwiseAnalytics.enableAnalytics = function (config) { configOptions = Object.assign(configOptions, config.options); // take the PBJS debug for our debug setting if no PW debug is defined if (configOptions.debug === null) { - configOptions.debug = debugTurnedOn(); + configOptions.debug = utils.debugTurnedOn(); } markEnabled(); - sessionData.activationId = generateUUID(); + sessionData.activationId = utils.generateUUID(); this.ensureSession(); pubwiseAnalytics.adapterEnableAnalytics(config); }; diff --git a/modules/pubwiseBidAdapter.js b/modules/pubwiseBidAdapter.js index a1b9ffb56a0..f450a8bede8 100644 --- a/modules/pubwiseBidAdapter.js +++ b/modules/pubwiseBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, isStr, deepClone, isArray, deepSetValue, inIframe, logMessage, logInfo, logWarn, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; @@ -81,9 +81,9 @@ let NATIVE_ASSET_KEY_TO_ASSET_MAP = {}; // together allows traversal of NATIVE_ASSETS_LIST in any direction // id -> key -_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY }); +utils._each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_ID_TO_KEY_MAP[anAsset.ID] = anAsset.KEY }); // key -> asset -_each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset }); +utils._each(NATIVE_ASSETS, anAsset => { NATIVE_ASSET_KEY_TO_ASSET_MAP[anAsset.KEY] = anAsset }); export const spec = { code: BIDDER_CODE, @@ -99,7 +99,7 @@ export const spec = { // siteId is required if (bid.params && bid.params.siteId) { // it must be a string - if (!isStr(bid.params.siteId)) { + if (!utils.isStr(bid.params.siteId)) { _logWarn('siteId is required for bid', bid); return false; } @@ -127,7 +127,7 @@ export const spec = { var blockedIabCategories = []; validBidRequests.forEach(originalBid => { - bid = deepClone(originalBid); + bid = utils.deepClone(originalBid); bid.params.adSlot = bid.params.adSlot || ''; _parseAdSlot(bid); @@ -136,7 +136,7 @@ export const spec = { bidCurrency = bid.params.currency || UNDEFINED; bid.params.currency = bidCurrency; - if (bid.params.hasOwnProperty('bcat') && isArray(bid.params.bcat)) { + if (bid.params.hasOwnProperty('bcat') && utils.isArray(bid.params.bcat)) { blockedIabCategories = blockedIabCategories.concat(bid.params.bcat); } @@ -180,27 +180,27 @@ export const spec = { } // passing transactionId in source.tid - deepSetValue(payload, 'source.tid', conf.transactionId); + utils.deepSetValue(payload, 'source.tid', conf.transactionId); // schain if (validBidRequests[0].schain) { - deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } // gdpr consent if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // ccpa on the root object if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // if coppa is in effect then note it if (config.getConfig('coppa') === true) { - deepSetValue(payload, 'regs.coppa', 1); + utils.deepSetValue(payload, 'regs.coppa', 1); } var options = {contentType: 'text/plain'} @@ -230,12 +230,12 @@ export const spec = { // let parsedReferrer = parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : ''; // try { - if (response.body && response.body.seatbid && isArray(response.body.seatbid)) { + if (response.body && response.body.seatbid && utils.isArray(response.body.seatbid)) { // Supporting multiple bid responses for same adSize respCur = response.body.cur || respCur; response.body.seatbid.forEach(seatbidder => { seatbidder.bid && - isArray(seatbidder.bid) && + utils.isArray(seatbidder.bid) && seatbidder.bid.forEach(bid => { let newBid = { requestId: bid.impid, @@ -388,7 +388,7 @@ function _handleCustomParams(params, conf) { value = entry.f(value, conf); } - if (isStr(value)) { + if (utils.isStr(value)) { conf[key] = value; } else { _logWarn('Ignoring param : ' + key + ' with value : ' + CUSTOM_PARAMS[key] + ', expects string-value, found ' + typeof value); @@ -469,7 +469,7 @@ function _createImpressionObject(bid, conf) { } function _parseSlotParam(paramName, paramValue) { - if (!isStr(paramValue)) { + if (!utils.isStr(paramValue)) { paramValue && _logWarn('Ignoring param key: ' + paramName + ', expects string-value, found ' + typeof paramValue); return UNDEFINED; } @@ -520,7 +520,7 @@ function _parseAdSlot(bid) { } function _cleanSlotName(slotName) { - if (isStr(slotName)) { + if (utils.isStr(slotName)) { return slotName.replace(/^\s+/g, '').replace(/\s+$/g, ''); } return ''; @@ -705,7 +705,7 @@ function _createBannerRequest(bid) { var sizes = bid.mediaTypes.banner.sizes; var format = []; var bannerObj; - if (sizes !== UNDEFINED && isArray(sizes)) { + if (sizes !== UNDEFINED && utils.isArray(sizes)) { bannerObj = {}; if (!bid.params.width && !bid.params.height) { if (sizes.length === 0) { @@ -734,7 +734,7 @@ function _createBannerRequest(bid) { } } bannerObj.pos = 0; - bannerObj.topframe = inIframe() ? 0 : 1; + bannerObj.topframe = utils.inIframe() ? 0 : 1; } else { _logWarn('Error: mediaTypes.banner.size missing for adunit: ' + bid.params.adUnit + '. Ignoring the banner impression in the adunit.'); bannerObj = UNDEFINED; @@ -745,22 +745,22 @@ function _createBannerRequest(bid) { // various error levels are not always used // eslint-disable-next-line no-unused-vars function _logMessage(textValue, objectValue) { - logMessage('PubWise: ' + textValue, objectValue); + utils.logMessage('PubWise: ' + textValue, objectValue); } // eslint-disable-next-line no-unused-vars function _logInfo(textValue, objectValue) { - logInfo('PubWise: ' + textValue, objectValue); + utils.logInfo('PubWise: ' + textValue, objectValue); } // eslint-disable-next-line no-unused-vars function _logWarn(textValue, objectValue) { - logWarn('PubWise: ' + textValue, objectValue); + utils.logWarn('PubWise: ' + textValue, objectValue); } // eslint-disable-next-line no-unused-vars function _logError(textValue, objectValue) { - logError('PubWise: ' + textValue, objectValue); + utils.logError('PubWise: ' + textValue, objectValue); } // function _decorateLog() { diff --git a/modules/pubxBidAdapter.js b/modules/pubxBidAdapter.js index 18d2bb11404..c7b63d3f7f7 100644 --- a/modules/pubxBidAdapter.js +++ b/modules/pubxBidAdapter.js @@ -1,5 +1,5 @@ -import { deepSetValue } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'pubx'; const BID_ENDPOINT = 'https://api.primecaster.net/adlogue/api/slot/bid'; @@ -43,7 +43,7 @@ export const spec = { ad: body.adm }; if (body.adomains) { - deepSetValue(bidResponse, 'meta.advertiserDomains', Array.isArray(body.adomains) ? body.adomains : [body.adomains]); + utils.deepSetValue(bidResponse, 'meta.advertiserDomains', Array.isArray(body.adomains) ? body.adomains : [body.adomains]); } bidResponses.push(bidResponse); } else {}; diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index 0031ff5539b..98b4dec1dca 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { deepAccess, getGptSlotInfoForAdUnitCode, parseSizesInput, getWindowLocation, buildUrl } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; const emptyUrl = ''; const analyticsType = 'endpoint'; @@ -21,14 +21,6 @@ let events = { deviceDetail: {} }; -function getStorage() { - try { - return window.top['sessionStorage']; - } catch (e) { - return null; - } -} - var pubxaiAnalyticsAdapter = Object.assign(adapter( { emptyUrl, @@ -42,7 +34,7 @@ var pubxaiAnalyticsAdapter = Object.assign(adapter( events.auctionInit = args; events.floorDetail = {}; events.bids = []; - const floorData = deepAccess(args, 'bidderRequests.0.bids.0.floorData'); + const floorData = utils.deepAccess(args, 'bidderRequests.0.bids.0.floorData'); if (typeof floorData !== 'undefined') { Object.assign(events.floorDetail, floorData); } @@ -65,7 +57,7 @@ function mapBidResponse(bidResponse, status) { if (typeof bidResponse !== 'undefined') { let bid = { adUnitCode: bidResponse.adUnitCode, - gptSlotCode: getGptSlotInfoForAdUnitCode(bidResponse.adUnitCode).gptSlot || null, + gptSlotCode: utils.getGptSlotInfoForAdUnitCode(bidResponse.adUnitCode).gptSlot || null, auctionId: bidResponse.auctionId, bidderCode: bidResponse.bidder, cpm: bidResponse.cpm, @@ -85,7 +77,7 @@ function mapBidResponse(bidResponse, status) { Object.assign(bid, { bidId: status === 'timeout' ? bidResponse.bidId : bidResponse.requestId, renderStatus: status === 'timeout' ? 3 : 2, - sizes: parseSizesInput(bidResponse.size).toString(), + sizes: utils.parseSizesInput(bidResponse.size).toString(), }); events.bids.push(bid); } else { @@ -93,7 +85,7 @@ function mapBidResponse(bidResponse, status) { bidId: bidResponse.requestId, floorProvider: events.floorDetail ? events.floorDetail.floorProvider : null, isWinningBid: true, - placementId: bidResponse.params ? deepAccess(bidResponse, 'params.0.placementId') : null, + placementId: bidResponse.params ? utils.deepAccess(bidResponse, 'params.0.placementId') : null, renderedSize: bidResponse.size, renderStatus: 4 }); @@ -139,8 +131,7 @@ pubxaiAnalyticsAdapter.shouldFireEventRequest = function (samplingRate = 1) { function send(data, status) { if (pubxaiAnalyticsAdapter.shouldFireEventRequest(initOptions.samplingRate)) { - let location = getWindowLocation(); - const storage = getStorage(); + let location = utils.getWindowLocation(); data.initOptions = initOptions; if (typeof data !== 'undefined' && typeof data.auctionInit !== 'undefined') { Object.assign(data.pageDetail, { @@ -151,13 +142,6 @@ function send(data, status) { }); data.initOptions.auctionId = data.auctionInit.auctionId; delete data.auctionInit; - - data.pmcDetail = {} - Object.assign(data.pmcDetail, { - bidDensity: storage ? storage.getItem('pbx:dpbid') : null, - maxBid: storage ? storage.getItem('pbx:mxbid') : null, - auctionId: storage ? storage.getItem('pbx:aucid') : null, - }); } data.deviceDetail = {}; Object.assign(data.deviceDetail, { @@ -166,8 +150,7 @@ function send(data, status) { deviceOS: getOS(), browser: getBrowser() }); - - let pubxaiAnalyticsRequestUrl = buildUrl({ + let pubxaiAnalyticsRequestUrl = utils.buildUrl({ protocol: 'https', hostname: (initOptions && initOptions.hostName) || defaultHost, pathname: status == 'bidwon' ? winningBidPath : auctionPath, diff --git a/modules/pulsepointBidAdapter.js b/modules/pulsepointBidAdapter.js index 7aa3ad6088c..adea33fc3b9 100644 --- a/modules/pulsepointBidAdapter.js +++ b/modules/pulsepointBidAdapter.js @@ -1,5 +1,5 @@ /* eslint dot-notation:0, quote-props:0 */ -import { convertTypes, deepAccess, isArray, logError, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; @@ -77,7 +77,7 @@ export const spec = { } }, transformBidParams: function(params, isOpenRtb) { - return convertTypes({ + return utils.convertTypes({ 'cf': 'string', 'cp': 'number', 'ct': 'number' @@ -124,8 +124,8 @@ function bidResponseAvailable(request, response) { }; if (idToImpMap[id].video) { // for outstream, a renderer is specified - if (idToSlotConfig[id] && deepAccess(idToSlotConfig[id], 'mediaTypes.video.context') === 'outstream') { - bid.renderer = outstreamRenderer(deepAccess(idToSlotConfig[id], 'renderer.options'), deepAccess(idToBidMap[id], 'ext.outstream')); + if (idToSlotConfig[id] && utils.deepAccess(idToSlotConfig[id], 'mediaTypes.video.context') === 'outstream') { + bid.renderer = outstreamRenderer(utils.deepAccess(idToSlotConfig[id], 'renderer.options'), utils.deepAccess(idToBidMap[id], 'ext.outstream')); } bid.vastXml = idToBidMap[id].adm; bid.mediaType = 'video'; @@ -178,9 +178,9 @@ function banner(slot) { * Produce openrtb format objects based on the sizes configured for the slot. */ function parseSizes(slot) { - const sizes = deepAccess(slot, 'mediaTypes.banner.sizes'); - if (sizes && isArray(sizes)) { - return sizes.filter(sz => isArray(sz) && sz.length === 2).map(sz => ({ + const sizes = utils.deepAccess(slot, 'mediaTypes.banner.sizes'); + if (sizes && utils.isArray(sizes)) { + return sizes.filter(sz => utils.isArray(sz) && sz.length === 2).map(sz => ({ w: sz[0], h: sz[1] })); @@ -387,7 +387,7 @@ function parse(rawResponse) { return JSON.parse(rawResponse); } } catch (ex) { - logError('pulsepointLite.safeParse', 'ERROR', ex); + utils.logError('pulsepointLite.safeParse', 'ERROR', ex); } return null; } @@ -421,18 +421,12 @@ function user(bidRequest, bidderRequest) { if (bidRequest) { if (bidRequest.userId) { ext.eids = []; - addExternalUserId(ext.eids, bidRequest.userId.pubcid, 'pubcid.org'); + addExternalUserId(ext.eids, bidRequest.userId.pubcid, 'pubcommon'); addExternalUserId(ext.eids, bidRequest.userId.britepoolid, 'britepool.com'); - addExternalUserId(ext.eids, bidRequest.userId.criteoId, 'criteo.com'); - addExternalUserId(ext.eids, bidRequest.userId.idl_env, 'liveramp.com'); - addExternalUserId(ext.eids, deepAccess(bidRequest, 'userId.id5id.uid'), 'id5-sync.com', deepAccess(bidRequest, 'userId.id5id.ext')); - addExternalUserId(ext.eids, deepAccess(bidRequest, 'userId.parrableId.eid'), 'parrable.com'); - addExternalUserId(ext.eids, bidRequest.userId.fabrickId, 'neustar.biz'); - addExternalUserId(ext.eids, deepAccess(bidRequest, 'userId.haloId.haloId'), 'audigent.com'); - addExternalUserId(ext.eids, bidRequest.userId.merkleId, 'merkleinc.com'); - addExternalUserId(ext.eids, bidRequest.userId.lotamePanoramaId, 'crwdcntrl.net'); - addExternalUserId(ext.eids, bidRequest.userId.connectid, 'verizonmedia.com'); - addExternalUserId(ext.eids, deepAccess(bidRequest, 'userId.uid2.id'), 'uidapi.com'); + addExternalUserId(ext.eids, bidRequest.userId.criteoId, 'criteo'); + addExternalUserId(ext.eids, bidRequest.userId.idl_env, 'identityLink'); + addExternalUserId(ext.eids, utils.deepAccess(bidRequest, 'userId.id5id.uid'), 'id5-sync.com', utils.deepAccess(bidRequest, 'userId.id5id.ext')); + addExternalUserId(ext.eids, utils.deepAccess(bidRequest, 'userId.parrableId.eid'), 'parrable.com'); // liveintent if (bidRequest.userId.lipb && bidRequest.userId.lipb.lipbid) { addExternalUserId(ext.eids, bidRequest.userId.lipb.lipbid, 'liveintent.com'); @@ -532,7 +526,7 @@ function nativeResponse(imp, bid) { function bidFloor(slot) { let floor = slot.params.bidfloor; - if (isFn(slot.getFloor)) { + if (utils.isFn(slot.getFloor)) { const floorData = slot.getFloor({ mediaType: slot.mediaTypes.banner ? 'banner' : slot.mediaTypes.video ? 'video' : 'Native', size: '*', diff --git a/modules/pxyzBidAdapter.js b/modules/pxyzBidAdapter.js index e144eb84a01..9baff4d1533 100644 --- a/modules/pxyzBidAdapter.js +++ b/modules/pxyzBidAdapter.js @@ -1,6 +1,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; -import { logInfo, logError, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'pxyz'; const URL = 'https://ads.playground.xyz/host-config/prebid?v=2'; @@ -61,15 +61,15 @@ export const spec = { if (bidderRequest && bidderRequest.gdprConsent) { const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; const consentString = bidderRequest.gdprConsent.consentString; - logInfo(`PXYZ: GDPR applies ${gdpr}`); - logInfo(`PXYZ: GDPR consent string ${consentString}`); + utils.logInfo(`PXYZ: GDPR applies ${gdpr}`); + utils.logInfo(`PXYZ: GDPR consent string ${consentString}`); payload.Regs.ext.gdpr = gdpr; payload.User = { ext: { consent: consentString } }; } // CCPA if (bidderRequest && bidderRequest.uspConsent) { - logInfo(`PXYZ: USP Consent ${bidderRequest.uspConsent}`); + utils.logInfo(`PXYZ: USP Consent ${bidderRequest.uspConsent}`); payload.Regs.ext['us_privacy'] = bidderRequest.uspConsent; } @@ -95,14 +95,14 @@ export const spec = { let errorMessage = `in response for ${bidderRequest.bidderCode} adapter`; if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; - logError(errorMessage); + utils.logError(errorMessage); } return bids; } - if (!isArray(serverResponse.seatbid)) { + if (!utils.isArray(serverResponse.seatbid)) { let errorMessage = `in response for ${bidderRequest.bidderCode} adapter `; - logError(errorMessage += 'Malformed seatbid response'); + utils.logError(errorMessage += 'Malformed seatbid response'); return bids; } diff --git a/modules/quantcastBidAdapter.js b/modules/quantcastBidAdapter.js index e168339426d..ecb5ad3176e 100644 --- a/modules/quantcastBidAdapter.js +++ b/modules/quantcastBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, logInfo, logError, isEmpty, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { config } from '../src/config.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -24,8 +24,8 @@ export const QUANTCAST_FPA = '__qca'; export const storage = getStorageManager(QUANTCAST_VENDOR_ID, BIDDER_CODE); function makeVideoImp(bid) { - const videoInMediaType = deepAccess(bid, 'mediaTypes.video') || {}; - const videoInParams = deepAccess(bid, 'params.video') || {}; + const videoInMediaType = utils.deepAccess(bid, 'mediaTypes.video') || {}; + const videoInParams = utils.deepAccess(bid, 'params.video') || {}; const video = Object.assign({}, videoInParams, videoInMediaType); if (video.playerSize) { @@ -142,10 +142,10 @@ export const spec = { */ buildRequests(bidRequests, bidderRequest) { const bids = bidRequests || []; - const gdprConsent = deepAccess(bidderRequest, 'gdprConsent') || {}; - const uspConsent = deepAccess(bidderRequest, 'uspConsent'); - const referrer = deepAccess(bidderRequest, 'refererInfo.referer'); - const page = deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || deepAccess(window, 'location.href'); + const gdprConsent = utils.deepAccess(bidderRequest, 'gdprConsent') || {}; + const uspConsent = utils.deepAccess(bidderRequest, 'uspConsent'); + const referrer = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + const page = utils.deepAccess(bidderRequest, 'refererInfo.canonicalUrl') || config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); const domain = getDomain(page); // Check for GDPR consent for purpose 1, and drop request if consent has not been given @@ -153,11 +153,11 @@ export const spec = { if (gdprConsent.gdprApplies) { if (gdprConsent.vendorData) { if (gdprConsent.apiVersion === 1 && !checkTCFv1(gdprConsent.vendorData)) { - logInfo(`${BIDDER_CODE}: No purpose 1 consent for TCF v1`); + utils.logInfo(`${BIDDER_CODE}: No purpose 1 consent for TCF v1`); return; } if (gdprConsent.apiVersion === 2 && !checkTCFv2(gdprConsent.vendorData)) { - logInfo(`${BIDDER_CODE}: No purpose 1 consent for TCF v2`); + utils.logInfo(`${BIDDER_CODE}: No purpose 1 consent for TCF v2`); return; } } @@ -174,7 +174,7 @@ export const spec = { imp = makeBannerImp(bid); } else { // Unsupported mediaType - logInfo(`${BIDDER_CODE}: No supported mediaTypes found in ${JSON.stringify(bid.mediaTypes)}`); + utils.logInfo(`${BIDDER_CODE}: No supported mediaTypes found in ${JSON.stringify(bid.mediaTypes)}`); return; } } else { @@ -231,18 +231,18 @@ export const spec = { */ interpretResponse(serverResponse) { if (serverResponse === undefined) { - logError('Server Response is undefined'); + utils.logError('Server Response is undefined'); return []; } const response = serverResponse['body']; if (response === undefined || !response.hasOwnProperty('bids')) { - logError('Sub-optimal JSON received from Quantcast server'); + utils.logError('Sub-optimal JSON received from Quantcast server'); return []; } - if (isEmpty(response.bids)) { + if (utils.isEmpty(response.bids)) { // Shortcut response handling if no bids are present return []; } @@ -271,7 +271,7 @@ export const spec = { result['dealId'] = dealId; } - if (meta !== undefined && meta.advertiserDomains && isArray(meta.advertiserDomains)) { + if (meta !== undefined && meta.advertiserDomains && utils.isArray(meta.advertiserDomains)) { result.meta = {}; result.meta.advertiserDomains = meta.advertiserDomains; } @@ -289,11 +289,11 @@ export const spec = { const syncs = [] if (!hasUserSynced && syncOptions.pixelEnabled) { const responseWithUrl = find(serverResponses, serverResponse => - deepAccess(serverResponse.body, 'userSync.url') + utils.deepAccess(serverResponse.body, 'userSync.url') ); if (responseWithUrl) { - const url = deepAccess(responseWithUrl.body, 'userSync.url') + const url = utils.deepAccess(responseWithUrl.body, 'userSync.url') syncs.push({ type: 'image', url: url diff --git a/modules/radsBidAdapter.js b/modules/radsBidAdapter.js index fee5daa3fb4..5cc88440629 100644 --- a/modules/radsBidAdapter.js +++ b/modules/radsBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -216,7 +216,7 @@ function prepareExtraParams(params, payload, bidderRequest, bidRequest) { * @returns {boolean} True if it's a banner bid */ function isBannerRequest(bid) { - return bid.mediaType === 'banner' || !!deepAccess(bid, 'mediaTypes.banner') || !isVideoRequest(bid); + return bid.mediaType === 'banner' || !!utils.deepAccess(bid, 'mediaTypes.banner') || !isVideoRequest(bid); } /** @@ -226,7 +226,7 @@ function isBannerRequest(bid) { * @returns {boolean} True if it's a video bid */ function isVideoRequest(bid) { - return bid.mediaType === 'video' || !!deepAccess(bid, 'mediaTypes.video'); + return bid.mediaType === 'video' || !!utils.deepAccess(bid, 'mediaTypes.video'); } /** @@ -236,7 +236,7 @@ function isVideoRequest(bid) { * @returns {object} True if it's a video bid */ function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); } /** @@ -246,7 +246,7 @@ function getVideoSizes(bid) { * @returns {object} True if it's a video bid */ function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); + return parseSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); } /** diff --git a/modules/realvuAnalyticsAdapter.js b/modules/realvuAnalyticsAdapter.js index 832e907893c..5540d136dea 100644 --- a/modules/realvuAnalyticsAdapter.js +++ b/modules/realvuAnalyticsAdapter.js @@ -3,9 +3,11 @@ import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import { getStorageManager } from '../src/storageManager.js'; -import { logMessage, logError } from '../src/utils.js'; + const storage = getStorageManager(); +const utils = require('../src/utils.js'); + let realvuAnalyticsAdapter = adapter({ global: 'realvuAnalytics', handler: 'on', @@ -399,7 +401,7 @@ export let lib = { // @if NODE_ENV='debug' let now = new Date(); let msg = (now.getTime() - time0) / 1000 + ' RENDERED ' + a.unit_id; - logMessage(msg); + utils.logMessage(msg); // @endif let rpt = z.bids_rpt(a, true); z.track(a, 'rend', rpt); @@ -883,7 +885,7 @@ realvuAnalyticsAdapter.originEnableAnalytics = realvuAnalyticsAdapter.enableAnal realvuAnalyticsAdapter.enableAnalytics = function (config) { _options = config.options; if (typeof (_options.partnerId) == 'undefined' || _options.partnerId == '') { - logError('Missed realvu.com partnerId parameter', 101, 'Missed partnerId parameter'); + utils.logError('Missed realvu.com partnerId parameter', 101, 'Missed partnerId parameter'); } realvuAnalyticsAdapter.originEnableAnalytics(config); return _options.partnerId; @@ -903,7 +905,7 @@ realvuAnalyticsAdapter.track = function ({eventType, args}) { ' creativei_id=' + args.creative_id; } // msg += '\nargs=' + JSON.stringify(args) + '
'; - logMessage(msg); + utils.logMessage(msg); // @endif const boost = window.top1.realvu_aa; @@ -933,7 +935,7 @@ realvuAnalyticsAdapter.track = function ({eventType, args}) { realvuAnalyticsAdapter.checkIn = function (bid, partnerId) { // find (or add if not registered yet) the unit in boost if (typeof (partnerId) == 'undefined' || partnerId == '') { - logError('Missed realvu.com partnerId parameter', 102, 'Missed partnerId parameter'); + utils.logError('Missed realvu.com partnerId parameter', 102, 'Missed partnerId parameter'); } let a = window.top1.realvu_aa.check({ unit_id: bid.adUnitCode, diff --git a/modules/reconciliationRtdProvider.js b/modules/reconciliationRtdProvider.js index fc5f0ab621a..f8636862d4c 100644 --- a/modules/reconciliationRtdProvider.js +++ b/modules/reconciliationRtdProvider.js @@ -18,7 +18,7 @@ import { submodule } from '../src/hook.js'; import { ajaxBuilder } from '../src/ajax.js'; -import { isGptPubadsDefined, timestamp, generateUUID, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import find from 'core-js-pure/features/array/find.js'; /** @type {Object} */ @@ -52,7 +52,7 @@ function handleAdMessage(e) { } if (data.type === MessageType.IMPRESSION_REQUEST) { - if (isGptPubadsDefined()) { + if (utils.isGptPubadsDefined()) { // 1. Find the last iframed window before window.top where the tracker was injected // (the tracker could be injected in nested iframes) const adWin = getTopIFrameWin(e.source); @@ -65,7 +65,7 @@ function handleAdMessage(e) { adDeliveryId = adSlot.getTargeting('RSDK_ADID'); adDeliveryId = adDeliveryId.length ? adDeliveryId[0] - : `${timestamp()}-${generateUUID()}`; + : `${utils.timestamp()}-${utils.generateUUID()}`; } } } @@ -136,7 +136,7 @@ export function getTopIFrameWin(win, topWin) { * @return {Object[]} slot GoogleTag slots */ function getAllSlots() { - return isGptPubadsDefined() && window.googletag.pubads().getSlots(); + return utils.isGptPubadsDefined() && window.googletag.pubads().getSlots(); } /** @@ -246,7 +246,7 @@ function getReconciliationData(adUnitsCodes) { const adSlot = getSlotByCode(adUnitCode); const adUnitId = adSlot ? adSlot.getAdUnitPath() : adUnitCode; - const adDeliveryId = `${timestamp()}-${generateUUID()}`; + const adDeliveryId = `${utils.timestamp()}-${utils.generateUUID()}`; dataToReturn[adUnitCode] = { RSDK_AUID: adUnitId, @@ -287,7 +287,7 @@ function init(moduleConfig) { _moduleParams = Object.assign({}, DEFAULT_PARAMS, params); initListeners(); } else { - logError('missing params for Reconciliation provider'); + utils.logError('missing params for Reconciliation provider'); } return true; } diff --git a/modules/relaidoBidAdapter.js b/modules/relaidoBidAdapter.js index 128fd72996b..14effa263a3 100644 --- a/modules/relaidoBidAdapter.js +++ b/modules/relaidoBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, logWarn, getBidIdParameter, parseQueryStringParameters, triggerPixel, generateUUID, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { Renderer } from '../src/Renderer.js'; @@ -6,112 +6,89 @@ import { getStorageManager } from '../src/storageManager.js'; const BIDDER_CODE = 'relaido'; const BIDDER_DOMAIN = 'api.relaido.jp'; -const ADAPTER_VERSION = '1.0.7'; +const ADAPTER_VERSION = '1.0.5'; const DEFAULT_TTL = 300; const UUID_KEY = 'relaido_uuid'; const storage = getStorageManager(); function isBidRequestValid(bid) { - if (!deepAccess(bid, 'params.placementId')) { - logWarn('placementId param is reqeuired.'); + if (!utils.deepAccess(bid, 'params.placementId')) { + utils.logWarn('placementId param is reqeuired.'); return false; } if (hasVideoMediaType(bid) && isVideoValid(bid)) { return true; } else { - logWarn('Invalid mediaType video.'); + utils.logWarn('Invalid mediaType video.'); } if (hasBannerMediaType(bid) && isBannerValid(bid)) { return true; } else { - logWarn('Invalid mediaType banner.'); + utils.logWarn('Invalid mediaType banner.'); } return false; } function buildRequests(validBidRequests, bidderRequest) { - const bids = []; - let imuid = null; - let bidDomain = null; - let bidder = null; - let count = null; + let bidRequests = []; for (let i = 0; i < validBidRequests.length; i++) { const bidRequest = validBidRequests[i]; + const placementId = utils.getBidIdParameter('placementId', bidRequest.params); + const bidDomain = bidRequest.params.domain || BIDDER_DOMAIN; + const bidUrl = `https://${bidDomain}/bid/v1/prebid/${placementId}`; + const uuid = getUuid(); let mediaType = ''; let width = 0; let height = 0; if (hasVideoMediaType(bidRequest) && isVideoValid(bidRequest)) { - const playerSize = getValidSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize')); + const playerSize = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize')); width = playerSize[0][0]; height = playerSize[0][1]; mediaType = VIDEO; } else if (hasBannerMediaType(bidRequest) && isBannerValid(bidRequest)) { - const sizes = getValidSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes')); + const sizes = getValidSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes')); width = sizes[0][0]; height = sizes[0][1]; mediaType = BANNER; } - if (!imuid) { - const pickImuid = deepAccess(bidRequest, 'userId.imuid'); - if (pickImuid) { - imuid = pickImuid; - } - } - - if (!bidDomain) { - bidDomain = bidRequest.params.domain; - } - - if (!bidder) { - bidder = bidRequest.bidder - } - - if (!bidder) { - bidder = bidRequest.bidder - } - - if (!count) { - count = bidRequest.bidRequestsCount; - } - - bids.push({ - bid_id: bidRequest.bidId, - placement_id: getBidIdParameter('placementId', bidRequest.params), - transaction_id: bidRequest.transactionId, - bidder_request_id: bidRequest.bidderRequestId, + let payload = { + version: ADAPTER_VERSION, + timeout_ms: bidderRequest.timeout, ad_unit_code: bidRequest.adUnitCode, auction_id: bidRequest.auctionId, - player: bidRequest.params.player, + bidder: bidRequest.bidder, + bidder_request_id: bidRequest.bidderRequestId, + bid_requests_count: bidRequest.bidRequestsCount, + bid_id: bidRequest.bidId, + transaction_id: bidRequest.transactionId, + media_type: mediaType, + uuid: uuid, width: width, - height: height, - media_type: mediaType + height: height + }; + + // It may not be encoded, so add it at the end of the payload + payload.ref = bidderRequest.refererInfo.referer; + + bidRequests.push({ + method: 'GET', + url: bidUrl, + data: payload, + options: { + withCredentials: true + }, + bidId: bidRequest.bidId, + player: bidRequest.params.player, + width: payload.width, + height: payload.height, + mediaType: payload.media_type }); } - - const data = JSON.stringify({ - version: ADAPTER_VERSION, - bids: bids, - timeout_ms: bidderRequest.timeout, - bidder: bidder, - bid_requests_count: count, - uuid: getUuid(), - pv: '$prebid.version$', - imuid: imuid, - ref: bidderRequest.refererInfo.referer - }) - - return { - method: 'POST', - url: `https://${bidDomain || BIDDER_DOMAIN}/bid/v1/sprebid`, - options: { - withCredentials: true - }, - data: data - }; + return bidRequests; } function interpretResponse(serverResponse, bidRequest) { @@ -122,38 +99,34 @@ function interpretResponse(serverResponse, bidRequest) { } const playerUrl = bidRequest.player || body.playerUrl; - - for (const res of body.ads) { - let bidResponse = { - requestId: res.bidId, - width: res.width, - height: res.height, - cpm: res.price, - currency: res.currency, - creativeId: res.creativeId, - dealId: body.dealId || '', - ttl: body.ttl || DEFAULT_TTL, - netRevenue: true, - mediaType: res.mediaType || VIDEO, - meta: { - advertiserDomains: res.adomain || [], - mediaType: VIDEO - } - }; - - if (bidResponse.mediaType === VIDEO) { - bidResponse.vastXml = res.vast; - bidResponse.renderer = newRenderer(res.bidId, playerUrl); - } else { - const playerTag = createPlayerTag(playerUrl); - const renderTag = createRenderTag(res.width, res.height, res.vast); - bidResponse.ad = `
${playerTag}${renderTag}
`; + const mediaType = bidRequest.mediaType || VIDEO; + + let bidResponse = { + requestId: bidRequest.bidId, + width: bidRequest.width, + height: bidRequest.height, + cpm: body.price, + currency: body.currency, + creativeId: body.creativeId, + dealId: body.dealId || '', + ttl: body.ttl || DEFAULT_TTL, + netRevenue: true, + mediaType: mediaType, + meta: { + advertiserDomains: body.adomain || [], + mediaType: VIDEO } - bidResponses.push(bidResponse); + }; + if (mediaType === VIDEO) { + bidResponse.vastXml = body.vast; + bidResponse.renderer = newRenderer(bidRequest.bidId, playerUrl); + } else { + const playerTag = createPlayerTag(playerUrl); + const renderTag = createRenderTag(bidRequest.width, bidRequest.height, body.vast); + bidResponse.ad = `
${playerTag}${renderTag}
`; } + bidResponses.push(bidResponse); - // eslint-disable-next-line no-console - console.log(JSON.stringify(bidResponses)); return bidResponses; } @@ -163,7 +136,7 @@ function getUserSyncs(syncOptions, serverResponses) { } let syncUrl = `https://${BIDDER_DOMAIN}/tr/v1/prebid/sync.html`; if (serverResponses.length > 0) { - syncUrl = deepAccess(serverResponses, '0.body.syncUrl') || syncUrl; + syncUrl = utils.deepAccess(serverResponses, '0.body.syncUrl') || syncUrl; } return [{ type: 'iframe', @@ -172,34 +145,34 @@ function getUserSyncs(syncOptions, serverResponses) { } function onBidWon(bid) { - let query = parseQueryStringParameters({ - placement_id: deepAccess(bid, 'params.0.placementId'), - creative_id: deepAccess(bid, 'creativeId'), - price: deepAccess(bid, 'cpm'), - auction_id: deepAccess(bid, 'auctionId'), - bid_id: deepAccess(bid, 'requestId'), - ad_id: deepAccess(bid, 'adId'), - ad_unit_code: deepAccess(bid, 'adUnitCode'), + let query = utils.parseQueryStringParameters({ + placement_id: utils.deepAccess(bid, 'params.0.placementId'), + creative_id: utils.deepAccess(bid, 'creativeId'), + price: utils.deepAccess(bid, 'cpm'), + auction_id: utils.deepAccess(bid, 'auctionId'), + bid_id: utils.deepAccess(bid, 'requestId'), + ad_id: utils.deepAccess(bid, 'adId'), + ad_unit_code: utils.deepAccess(bid, 'adUnitCode'), ref: window.location.href, }).replace(/\&$/, ''); - const bidDomain = deepAccess(bid, 'params.0.domain') || BIDDER_DOMAIN; + const bidDomain = utils.deepAccess(bid, 'params.0.domain') || BIDDER_DOMAIN; const burl = `https://${bidDomain}/tr/v1/prebid/win.gif?${query}`; - triggerPixel(burl); + utils.triggerPixel(burl); } function onTimeout(data) { - let query = parseQueryStringParameters({ - placement_id: deepAccess(data, '0.params.0.placementId'), - timeout: deepAccess(data, '0.timeout'), - auction_id: deepAccess(data, '0.auctionId'), - bid_id: deepAccess(data, '0.bidId'), - ad_unit_code: deepAccess(data, '0.adUnitCode'), + let query = utils.parseQueryStringParameters({ + placement_id: utils.deepAccess(data, '0.params.0.placementId'), + timeout: utils.deepAccess(data, '0.timeout'), + auction_id: utils.deepAccess(data, '0.auctionId'), + bid_id: utils.deepAccess(data, '0.bidId'), + ad_unit_code: utils.deepAccess(data, '0.adUnitCode'), version: ADAPTER_VERSION, ref: window.location.href, }).replace(/\&$/, ''); - const bidDomain = deepAccess(data, '0.params.0.domain') || BIDDER_DOMAIN; + const bidDomain = utils.deepAccess(data, '0.params.0.domain') || BIDDER_DOMAIN; const timeoutUrl = `https://${bidDomain}/tr/v1/prebid/timeout.gif?${query}`; - triggerPixel(timeoutUrl); + utils.triggerPixel(timeoutUrl); } function createPlayerTag(playerUrl) { @@ -226,7 +199,7 @@ function newRenderer(bidId, playerUrl) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('renderer.setRender Error', err); + utils.logWarn('renderer.setRender Error', err); } return renderer; } @@ -247,7 +220,7 @@ function isBannerValid(bid) { if (!isMobile()) { return false; } - const sizes = getValidSizes(deepAccess(bid, 'mediaTypes.banner.sizes')); + const sizes = getValidSizes(utils.deepAccess(bid, 'mediaTypes.banner.sizes')); if (sizes.length > 0) { return true; } @@ -255,9 +228,9 @@ function isBannerValid(bid) { } function isVideoValid(bid) { - const playerSize = getValidSizes(deepAccess(bid, 'mediaTypes.video.playerSize')); + const playerSize = getValidSizes(utils.deepAccess(bid, 'mediaTypes.video.playerSize')); if (playerSize.length > 0) { - const context = deepAccess(bid, 'mediaTypes.video.context'); + const context = utils.deepAccess(bid, 'mediaTypes.video.context'); if (context && context === 'outstream') { return true; } @@ -268,7 +241,7 @@ function isVideoValid(bid) { function getUuid() { const id = storage.getCookie(UUID_KEY) if (id) return id; - const newId = generateUUID(); + const newId = utils.generateUUID(); storage.setCookie(UUID_KEY, newId); return newId; } @@ -282,18 +255,18 @@ export function isMobile() { } function hasBannerMediaType(bid) { - return !!deepAccess(bid, 'mediaTypes.banner'); + return !!utils.deepAccess(bid, 'mediaTypes.banner'); } function hasVideoMediaType(bid) { - return !!deepAccess(bid, 'mediaTypes.video'); + return !!utils.deepAccess(bid, 'mediaTypes.video'); } function getValidSizes(sizes) { let result = []; - if (sizes && isArray(sizes) && sizes.length > 0) { + if (sizes && utils.isArray(sizes) && sizes.length > 0) { for (let i = 0; i < sizes.length; i++) { - if (isArray(sizes[i]) && sizes[i].length == 2) { + if (utils.isArray(sizes[i]) && sizes[i].length == 2) { const width = sizes[i][0]; const height = sizes[i][1]; if (width == 1 && height == 1) { diff --git a/modules/resetdigitalBidAdapter.js b/modules/resetdigitalBidAdapter.js index 255ee32629c..7591c3391a0 100644 --- a/modules/resetdigitalBidAdapter.js +++ b/modules/resetdigitalBidAdapter.js @@ -1,7 +1,8 @@ -import { timestamp, deepAccess, getOrigin } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import {getOrigin} from '../src/utils.js'; const BIDDER_CODE = 'resetdigital'; export const spec = { @@ -19,7 +20,7 @@ export const spec = { ? config.getConfig('userSync').syncsPerBidder : 5 const payload = { - start_time: timestamp(), + start_time: utils.timestamp(), language: window.navigator.userLanguage || window.navigator.language, site: { domain: getOrigin(), @@ -50,7 +51,7 @@ export const spec = { imp_id: req.transactionId, sizes: req.sizes, force_bid: req.params.forceBid, - media_types: deepAccess(req, 'mediaTypes') + media_types: utils.deepAccess(req, 'mediaTypes') }); } diff --git a/modules/revcontentBidAdapter.js b/modules/revcontentBidAdapter.js index 0888e5ad1b4..777060a5eb6 100644 --- a/modules/revcontentBidAdapter.js +++ b/modules/revcontentBidAdapter.js @@ -3,7 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; -import { triggerPixel, isFn, deepAccess, getAdUnitSizes, parseGPTSingleSizeArrayToRtbSize, _map } from '../src/utils.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'revcontent'; const NATIVE_PARAMS = { @@ -160,7 +160,7 @@ export const spec = { }, onBidWon: function (bid) { if (bid.nurl) { - triggerPixel(bid.nurl); + utils.triggerPixel(bid.nurl); } return true; } @@ -215,14 +215,14 @@ function extractHostname(url) { function buildImp(bid, id) { let bidfloor; - if (isFn(bid.getFloor)) { + if (utils.isFn(bid.getFloor)) { bidfloor = bid.getFloor({ currency: 'USD', mediaType: '*', size: '*' }).floor; } else { - bidfloor = deepAccess(bid, `params.bidfloor`) || 0.1; + bidfloor = utils.deepAccess(bid, `params.bidfloor`) || 0.1; } let imp = { @@ -236,17 +236,17 @@ function buildImp(bid, id) { secure: '1' }; - let bannerReq = deepAccess(bid, `mediaTypes.banner`); - let nativeReq = deepAccess(bid, `mediaTypes.native`); + let bannerReq = utils.deepAccess(bid, `mediaTypes.banner`); + let nativeReq = utils.deepAccess(bid, `mediaTypes.native`); if (bannerReq) { - let sizes = getAdUnitSizes(bid); + let sizes = utils.getAdUnitSizes(bid); imp.banner = { w: sizes[0][0], h: sizes[0][1], - format: sizes.map(wh => parseGPTSingleSizeArrayToRtbSize(wh)), + format: sizes.map(wh => utils.parseGPTSingleSizeArrayToRtbSize(wh)), } } else if (nativeReq) { - const assets = _map(bid.nativeParams, (bidParams, key) => { + const assets = utils._map(bid.nativeParams, (bidParams, key) => { const props = NATIVE_PARAMS[key]; const asset = { required: bidParams.required & 1 diff --git a/modules/rhythmoneBidAdapter.js b/modules/rhythmoneBidAdapter.js index d0e399ab7e3..36b2c369213 100644 --- a/modules/rhythmoneBidAdapter.js +++ b/modules/rhythmoneBidAdapter.js @@ -1,7 +1,6 @@ - 'use strict'; -import { deepAccess, getDNT, parseSizesInput, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; @@ -42,13 +41,13 @@ function RhythmOneBidAdapter() { impObj.bidfloor = 0; impObj.secure = isSecure; - if (deepAccess(BRs[i], 'mediaTypes.banner') || deepAccess(BRs[i], 'mediaType') === 'banner') { + if (utils.deepAccess(BRs[i], 'mediaTypes.banner') || utils.deepAccess(BRs[i], 'mediaType') === 'banner') { let banner = frameBanner(BRs[i]); if (banner) { impObj.banner = banner; } } - if (deepAccess(BRs[i], 'mediaTypes.video') || deepAccess(BRs[i], 'mediaType') === 'video') { + if (utils.deepAccess(BRs[i], 'mediaTypes.video') || utils.deepAccess(BRs[i], 'mediaType') === 'video') { impObj.video = frameVideo(BRs[i]); } if (!(impObj.banner || impObj.video)) { @@ -86,7 +85,7 @@ function RhythmOneBidAdapter() { return { ua: navigator.userAgent, ip: '', // Empty Ip string is required, server gets the ip from HTTP header - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, } } @@ -106,7 +105,7 @@ function RhythmOneBidAdapter() { if (adUnit.mediaTypes && adUnit.mediaTypes.banner) { sizeList = adUnit.mediaTypes.banner.sizes; } - var sizeStringList = parseSizesInput(sizeList); + var sizeStringList = utils.parseSizesInput(sizeList); var format = []; sizeStringList.forEach(function(size) { if (size) { @@ -130,9 +129,9 @@ function RhythmOneBidAdapter() { function frameVideo(bid) { var size = []; - if (deepAccess(bid, 'mediaTypes.video.playerSize')) { + if (utils.deepAccess(bid, 'mediaTypes.video.playerSize')) { var dimensionSet = bid.mediaTypes.video.playerSize; - if (isArray(bid.mediaTypes.video.playerSize[0])) { + if (utils.isArray(bid.mediaTypes.video.playerSize[0])) { dimensionSet = bid.mediaTypes.video.playerSize[0]; } var validSize = getValidSizeSet(dimensionSet) @@ -141,15 +140,15 @@ function RhythmOneBidAdapter() { } } return { - mimes: deepAccess(bid, 'mediaTypes.video.mimes') || SUPPORTED_VIDEO_MIMES, - protocols: deepAccess(bid, 'mediaTypes.video.protocols') || SUPPORTED_VIDEO_PROTOCOLS, + mimes: utils.deepAccess(bid, 'mediaTypes.video.mimes') || SUPPORTED_VIDEO_MIMES, + protocols: utils.deepAccess(bid, 'mediaTypes.video.protocols') || SUPPORTED_VIDEO_PROTOCOLS, w: size[0], h: size[1], - startdelay: deepAccess(bid, 'mediaTypes.video.startdelay') || 0, - skip: deepAccess(bid, 'mediaTypes.video.skip') || 0, - playbackmethod: deepAccess(bid, 'mediaTypes.video.playbackmethod') || SUPPORTED_VIDEO_PLAYBACK_METHODS, - delivery: deepAccess(bid, 'mediaTypes.video.delivery') || SUPPORTED_VIDEO_DELIVERY, - api: deepAccess(bid, 'mediaTypes.video.api') || SUPPORTED_VIDEO_API, + startdelay: utils.deepAccess(bid, 'mediaTypes.video.startdelay') || 0, + skip: utils.deepAccess(bid, 'mediaTypes.video.skip') || 0, + playbackmethod: utils.deepAccess(bid, 'mediaTypes.video.playbackmethod') || SUPPORTED_VIDEO_PLAYBACK_METHODS, + delivery: utils.deepAccess(bid, 'mediaTypes.video.delivery') || SUPPORTED_VIDEO_DELIVERY, + api: utils.deepAccess(bid, 'mediaTypes.video.api') || SUPPORTED_VIDEO_API, } } @@ -171,14 +170,14 @@ function RhythmOneBidAdapter() { device: frameDevice(), user: { ext: { - consent: deepAccess(bidderRequest, 'gdprConsent.gdprApplies') ? bidderRequest.gdprConsent.consentString : '' + consent: utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') ? bidderRequest.gdprConsent.consentString : '' } }, at: 1, tmax: 1000, regs: { ext: { - gdpr: deepAccess(bidderRequest, 'gdprConsent.gdprApplies') ? Boolean(bidderRequest.gdprConsent.gdprApplies & 1) : false + gdpr: utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') ? Boolean(bidderRequest.gdprConsent.gdprApplies & 1) : false } } }; diff --git a/modules/richaudienceBidAdapter.js b/modules/richaudienceBidAdapter.js index 0f62e988249..4b556e83236 100755 --- a/modules/richaudienceBidAdapter.js +++ b/modules/richaudienceBidAdapter.js @@ -1,7 +1,7 @@ -import {isEmpty, deepAccess, isStr} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import * as utils from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; const BIDDER_CODE = 'richaudience'; @@ -52,17 +52,17 @@ export const spec = { videoData: raiGetVideoInfo(bid), scr_rsl: raiGetResolution(), cpuc: (typeof window.navigator != 'undefined' ? window.navigator.hardwareConcurrency : null), - kws: (!isEmpty(bid.params.keywords) ? bid.params.keywords : null), - schain: bid.schain + kws: (!utils.isEmpty(bid.params.keywords) ? bid.params.keywords : null) }; REFERER = (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null) payload.gdpr_consent = ''; - payload.gdpr = bidderRequest.gdprConsent.gdprApplies; + payload.gdpr = null; if (bidderRequest && bidderRequest.gdprConsent) { payload.gdpr_consent = bidderRequest.gdprConsent.consentString; + payload.gdpr = bidderRequest.gdprConsent.gdprApplies; } var payloadString = JSON.stringify(payload); @@ -220,19 +220,19 @@ function raiSetEids(bid) { let eids = []; if (bid && bid.userId) { - raiSetUserId(bid, eids, 'id5-sync.com', deepAccess(bid, `userId.id5id.uid`)); - raiSetUserId(bid, eids, 'pubcommon', deepAccess(bid, `userId.pubcid`)); - raiSetUserId(bid, eids, 'criteo.com', deepAccess(bid, `userId.criteoId`)); - raiSetUserId(bid, eids, 'liveramp.com', deepAccess(bid, `userId.idl_env`)); - raiSetUserId(bid, eids, 'liveintent.com', deepAccess(bid, `userId.lipb.lipbid`)); - raiSetUserId(bid, eids, 'adserver.org', deepAccess(bid, `userId.tdid`)); + raiSetUserId(bid, eids, 'id5-sync.com', utils.deepAccess(bid, `userId.id5id.uid`)); + raiSetUserId(bid, eids, 'pubcommon', utils.deepAccess(bid, `userId.pubcid`)); + raiSetUserId(bid, eids, 'criteo.com', utils.deepAccess(bid, `userId.criteoId`)); + raiSetUserId(bid, eids, 'liveramp.com', utils.deepAccess(bid, `userId.idl_env`)); + raiSetUserId(bid, eids, 'liveintent.com', utils.deepAccess(bid, `userId.lipb.lipbid`)); + raiSetUserId(bid, eids, 'adserver.org', utils.deepAccess(bid, `userId.tdid`)); } return eids; } function raiSetUserId(bid, eids, source, value) { - if (isStr(value)) { + if (utils.isStr(value)) { eids.push({ userId: value, source: source @@ -296,7 +296,7 @@ function raiGetFloor(bid, config) { } else if (typeof bid.getFloor == 'function') { let floorSpec = bid.getFloor({ currency: config.getConfig('currency.adServerCurrency'), - mediaType: typeof bid.mediaTypes['banner'] == 'object' ? 'banner' : 'video', + mediaType: bid.mediaType.banner ? 'banner' : 'video', size: '*' }) diff --git a/modules/riseBidAdapter.js b/modules/riseBidAdapter.js index 70777fe03f2..6887805b854 100644 --- a/modules/riseBidAdapter.js +++ b/modules/riseBidAdapter.js @@ -1,11 +1,11 @@ -import { logWarn, isArray, isFn, deepAccess, isEmpty, contains, timestamp, getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; const SUPPORTED_AD_TYPES = [VIDEO]; const BIDDER_CODE = 'rise'; -const ADAPTER_VERSION = '5.0.0'; +const BIDDER_VERSION = '4.0.1'; const TTL = 360; const CURRENCY = 'USD'; const SELLER_ENDPOINT = 'https://hb.yellowblue.io/'; @@ -20,21 +20,10 @@ const SUPPORTED_SYNC_METHODS = { export const spec = { code: BIDDER_CODE, - gvlid: 1043, - version: ADAPTER_VERSION, + version: BIDDER_VERSION, supportedMediaTypes: SUPPORTED_AD_TYPES, isBidRequestValid: function(bidRequest) { - if (!bidRequest.params) { - logWarn('no params have been set to Rise adapter'); - return false; - } - - if (!bidRequest.params.org) { - logWarn('org is a mandatory param for Rise adapter'); - return false; - } - - return true; + return !!(bidRequest.params.org); }, buildRequests: function (bidRequests, bidderRequest) { if (bidRequests.length === 0) { @@ -82,7 +71,7 @@ export const spec = { url: response.body.userSyncURL }); } - if (syncOptions.pixelEnabled && isArray(response.body.userSyncPixels)) { + if (syncOptions.pixelEnabled && utils.isArray(response.body.userSyncPixels)) { const pixels = response.body.userSyncPixels.map(pixel => { return { type: 'image', @@ -104,7 +93,7 @@ registerBidder(spec); * @returns {Number} */ function getFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return 0; } let floorResult = bid.getFloor({ @@ -112,7 +101,7 @@ function getFloor(bid) { mediaType: VIDEO, size: '*' }); - return floorResult.currency === CURRENCY && floorResult.floor ? floorResult.floor : 0; + return floorResult.currency === CURRENCY ? floorResult.floor : 0; } /** @@ -137,7 +126,7 @@ function buildVideoRequest(bid, bidderRequest) { * @returns {Array} */ function getSizes(bid) { - if (deepAccess(bid, 'mediaTypes.video.sizes')) { + if (utils.deepAccess(bid, 'mediaTypes.video.sizes')) { return bid.mediaTypes.video.sizes[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { return bid.sizes[0]; @@ -151,7 +140,7 @@ function getSizes(bid) { * @returns {string} */ function getSupplyChain(schainObject) { - if (isEmpty(schainObject)) { + if (utils.isEmpty(schainObject)) { return ''; } let scStr = `${schainObject.ver},${schainObject.complete}`; @@ -159,7 +148,7 @@ function getSupplyChain(schainObject) { scStr += '!'; scStr += `${getEncodedValIfNotEmpty(node.asi)},`; scStr += `${getEncodedValIfNotEmpty(node.sid)},`; - scStr += `${node.hp ? encodeURIComponent(node.hp) : ''},`; + scStr += `${getEncodedValIfNotEmpty(node.hp)},`; scStr += `${getEncodedValIfNotEmpty(node.rid)},`; scStr += `${getEncodedValIfNotEmpty(node.name)},`; scStr += `${getEncodedValIfNotEmpty(node.domain)}`; @@ -173,7 +162,7 @@ function getSupplyChain(schainObject) { * @returns {string} */ function getEncodedValIfNotEmpty(val) { - return !isEmpty(val) ? encodeURIComponent(val) : ''; + return !utils.isEmpty(val) ? encodeURIComponent(val) : ''; } /** @@ -203,8 +192,8 @@ function isSyncMethodAllowed(syncRule, bidderCode) { return false; } const isInclude = syncRule.filter === 'include'; - const bidders = isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; - return isInclude && contains(bidders, bidderCode); + const bidders = utils.isArray(syncRule.bidders) ? syncRule.bidders : [bidderCode]; + return isInclude && utils.contains(bidders, bidderCode); } /** @@ -218,27 +207,6 @@ function getEndpoint(testMode) { : SELLER_ENDPOINT + MODES.PRODUCTION; } -/** - * get device type - * @param uad {ua} - * @returns {string} - */ -function getDeviceType(ua) { - if (/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i - .test(ua.toLowerCase())) { - return '5'; - } - if (/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i - .test(ua.toLowerCase())) { - return '4'; - } - if (/smart[-_\s]?tv|hbbtv|appletv|googletv|hdmi|netcast|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b/i - .test(ua.toLowerCase())) { - return '3'; - } - return '1'; -} - /** * Generate query parameters for the request * @param bid {bid} @@ -246,83 +214,31 @@ function getDeviceType(ua) { * @returns {Object} */ function generateParameters(bid, bidderRequest) { - const {params} = bid; const timeout = config.getConfig('bidderTimeout'); - const {syncEnabled, filterSettings} = config.getConfig('userSync') || {}; - const [width, height] = getSizes(bid); - const {bidderCode} = bidderRequest; + const { syncEnabled, filterSettings } = config.getConfig('userSync') || {}; + const [ width, height ] = getSizes(bid); + const { params } = bid; + const { bidderCode } = bidderRequest; const domain = window.location.hostname; - // fix floor price in case of NAN - if (isNaN(params.floorPrice)) { - params.floorPrice = 0; - } - const requestParams = { - wrapper_type: 'prebidjs', - wrapper_vendor: '$$PREBID_GLOBAL$$', - wrapper_version: '$prebid.version$', - adapter_version: ADAPTER_VERSION, - auction_start: timestamp(), - ad_unit_code: getBidIdParameter('adUnitCode', bid), + auction_start: utils.timestamp(), + ad_unit_code: utils.getBidIdParameter('adUnitCode', bid), tmax: timeout, width: width, height: height, publisher_id: params.org, floor_price: Math.max(getFloor(bid), params.floorPrice), ua: navigator.userAgent, - bid_id: getBidIdParameter('bidId', bid), - bidder_request_id: getBidIdParameter('bidderRequestId', bid), - transaction_id: getBidIdParameter('transactionId', bid), - session_id: getBidIdParameter('auctionId', bid), + bid_id: utils.getBidIdParameter('bidId', bid), + bidder_request_id: utils.getBidIdParameter('bidderRequestId', bid), + transaction_id: utils.getBidIdParameter('transactionId', bid), + session_id: utils.getBidIdParameter('auctionId', bid), publisher_name: domain, site_domain: domain, - dnt: (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0, - device_type: getDeviceType(navigator.userAgent) + bidder_version: BIDDER_VERSION }; - const userIdsParam = getBidIdParameter('userId', bid); - if (userIdsParam) { - requestParams.userIds = JSON.stringify(userIdsParam); - } - - const ortb2Metadata = config.getConfig('ortb2') || {}; - if (ortb2Metadata.site) { - requestParams.site_metadata = JSON.stringify(ortb2Metadata.site); - } - if (ortb2Metadata.user) { - requestParams.user_metadata = JSON.stringify(ortb2Metadata.user); - } - - const playbackMethod = deepAccess(bid, 'mediaTypes.video.playbackmethod'); - if (playbackMethod) { - requestParams.playback_method = playbackMethod; - } - const placement = deepAccess(bid, 'mediaTypes.video.placement'); - if (placement) { - requestParams.placement = placement; - } - const pos = deepAccess(bid, 'mediaTypes.video.pos'); - if (pos) { - requestParams.pos = pos; - } - const minduration = deepAccess(bid, 'mediaTypes.video.minduration'); - if (minduration) { - requestParams.min_duration = minduration; - } - const maxduration = deepAccess(bid, 'mediaTypes.video.maxduration'); - if (maxduration) { - requestParams.max_duration = maxduration; - } - const skip = deepAccess(bid, 'mediaTypes.video.skip'); - if (skip) { - requestParams.skip = skip; - } - const linearity = deepAccess(bid, 'mediaTypes.video.linearity'); - if (linearity) { - requestParams.linearity = linearity; - } - if (params.placementId) { requestParams.placement_id = params.placementId; } @@ -352,8 +268,8 @@ function generateParameters(bid, bidderRequest) { } if (bidderRequest && bidderRequest.refererInfo) { - requestParams.referrer = deepAccess(bidderRequest, 'refererInfo.referer'); - requestParams.page_url = config.getConfig('pageUrl') || deepAccess(window, 'location.href'); + requestParams.referrer = utils.deepAccess(bidderRequest, 'refererInfo.referer'); + requestParams.page_url = config.getConfig('pageUrl') || utils.deepAccess(window, 'location.href'); } return requestParams; diff --git a/modules/riseBidAdapter.md b/modules/riseBidAdapter.md index 83f8adfd645..6251b92e0a9 100644 --- a/modules/riseBidAdapter.md +++ b/modules/riseBidAdapter.md @@ -13,7 +13,7 @@ Module that connects to Rise's demand sources. The Rise adapter requires setup and approval from the Rise. Please reach out to prebid-rise-engage@risecodes.com to create an Rise account. -The adapter supports Video(instream). +The adapter supports Video(instream). For the integration, Rise returns content as vastXML and requires the publisher to define the cache url in config passed to Prebid for it to be valid in the auction. # Bid Parameters ## Video @@ -22,6 +22,7 @@ The adapter supports Video(instream). | ---- | ----- | ---- | ----------- | ------- | `org` | required | String | Rise publisher Id provided by your Rise representative | "56f91cd4d3e3660002000033" | `floorPrice` | optional | Number | Minimum price in USD. Misuse of this parameter can impact revenue | 2.00 +| `ifa` | optional | String | The ID for advertisers (also referred to as "IDFA") | "XXX-XXX" | `placementId` | optional | String | A unique placement identifier | "12345678" | `testMode` | optional | Boolean | This activates the test mode | false @@ -42,6 +43,7 @@ var adUnits = [ params: { org: '56f91cd4d3e3660002000033', // Required floorPrice: 2.00, // Optional + ifa: 'XXX-XXX', // Optional placementId: '12345678', // Optional testMode: false // Optional } diff --git a/modules/roxotAnalyticsAdapter.js b/modules/roxotAnalyticsAdapter.js index c9245d4ae08..b6857d69f45 100644 --- a/modules/roxotAnalyticsAdapter.js +++ b/modules/roxotAnalyticsAdapter.js @@ -1,4 +1,3 @@ -import { deepClone, getParameterByName, logInfo, logError } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; @@ -8,6 +7,7 @@ import { getStorageManager } from '../src/storageManager.js'; const storage = getStorageManager(); +const utils = require('../src/utils.js'); let ajax = ajaxBuilder(0); const DEFAULT_EVENT_URL = 'pa.rxthdr.com/v3'; @@ -153,7 +153,7 @@ function buildBidderRequest(auction, bidRequest) { function buildBidAfterTimeout(adUnitAuction, args) { return { - 'auction': deepClone(adUnitAuction), + 'auction': utils.deepClone(adUnitAuction), 'adUnit': extractAdUnitCode(args), 'bidder': extractBidder(args), 'cpm': args.cpm, @@ -170,7 +170,7 @@ function buildBidAfterTimeout(adUnitAuction, args) { function buildImpression(adUnitAuction, args) { return { 'isNew': checkIsNewFlag() ? 1 : 0, - 'auction': deepClone(adUnitAuction), + 'auction': utils.deepClone(adUnitAuction), 'adUnit': extractAdUnitCode(args), 'bidder': extractBidder(args), 'cpm': args.cpm, @@ -342,7 +342,7 @@ roxotAdapter.originEnableAnalytics = roxotAdapter.enableAnalytics; roxotAdapter.enableAnalytics = function (config) { if (this.initConfig(config)) { - _logInfo('Analytics adapter enabled', initOptions); + logInfo('Analytics adapter enabled', initOptions); roxotAdapter.originEnableAnalytics(config); } }; @@ -351,7 +351,7 @@ roxotAdapter.buildUtmTagData = function () { let utmTagData = {}; let utmTagsDetected = false; utmTags.forEach(function (utmTagKey) { - let utmTagValue = getParameterByName(utmTagKey); + let utmTagValue = utils.getParameterByName(utmTagKey); if (utmTagValue !== '') { utmTagsDetected = true; } @@ -374,11 +374,11 @@ roxotAdapter.buildUtmTagData = function () { roxotAdapter.initConfig = function (config) { let isCorrectConfig = true; initOptions = {}; - initOptions.options = deepClone(config.options); + initOptions.options = utils.deepClone(config.options); initOptions.publisherId = initOptions.options.publisherId || (initOptions.options.publisherIds[0]) || null; if (!initOptions.publisherId) { - _logError('"options.publisherId" is empty'); + logError('"options.publisherId" is empty'); isCorrectConfig = false; } @@ -407,7 +407,7 @@ function registerEvent(eventType, eventName, data) { sendEventCache.push(eventData); - _logInfo('Register event', eventData); + logInfo('Register event', eventData); (typeof initOptions.serverConfig === 'undefined') ? checkEventAfterTimeout() : checkSendEvent(); } @@ -427,7 +427,7 @@ function checkSendEvent() { let event = sendEventCache.shift(); let isNeedSend = initOptions.serverConfig[event.eventType] || 0; if (Number(isNeedSend) === 0) { - _logInfo('Skip event ' + event.eventName, event); + logInfo('Skip event ' + event.eventName, event); continue; } sendEvent(event.eventType, event.eventName, event.data); @@ -454,7 +454,7 @@ function sendEvent(eventType, eventName, data) { ajax( url, function () { - _logInfo(eventName + ' sent', eventData); + logInfo(eventName + ' sent', eventData); }, JSON.stringify(eventData), { @@ -490,12 +490,12 @@ function loadServerConfig() { ); } -function _logInfo(message, meta) { - logInfo(buildLogMessage(message), meta); +function logInfo(message, meta) { + utils.logInfo(buildLogMessage(message), meta); } -function _logError(message) { - logError(buildLogMessage(message)); +function logError(message) { + utils.logError(buildLogMessage(message)); } function buildLogMessage(message) { diff --git a/modules/rtbhouseBidAdapter.js b/modules/rtbhouseBidAdapter.js index 40389b1e1e0..036bdfaebeb 100644 --- a/modules/rtbhouseBidAdapter.js +++ b/modules/rtbhouseBidAdapter.js @@ -1,4 +1,4 @@ -import { isArray, deepAccess, getOrigin, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -82,7 +82,7 @@ export const spec = { }, interpretResponse: function (serverResponse, originalRequest) { const responseBody = serverResponse.body; - if (!isArray(responseBody)) { + if (!utils.isArray(responseBody)) { return []; } @@ -145,7 +145,7 @@ function mapImpression(slot) { */ function mapBanner(slot) { if (slot.mediaType === 'banner' || - deepAccess(slot, 'mediaTypes.banner') || + utils.deepAccess(slot, 'mediaTypes.banner') || (!slot.mediaType && !slot.mediaTypes)) { var sizes = slot.sizes || slot.mediaTypes.banner.sizes; return { @@ -165,26 +165,16 @@ function mapBanner(slot) { * @returns {object} Site by OpenRTB 2.5 §3.2.13 */ function mapSite(slot, bidderRequest) { - let pubId = 'unknown'; - let channel = null; - if (slot && slot.length > 0) { - pubId = slot[0].params.publisherId; - channel = slot[0].params.channel && - slot[0].params.channel - .toString() - .slice(0, 50); - } - let siteData = { + const pubId = slot && slot.length > 0 + ? slot[0].params.publisherId + : 'unknown'; + return { publisher: { id: pubId.toString(), }, page: bidderRequest.refererInfo.referer, - name: getOrigin() - }; - if (channel) { - siteData.channel = channel; + name: utils.getOrigin() } - return siteData; } /** @@ -208,7 +198,7 @@ function mapSchain(schain) { return null; } if (!validateSchain(schain)) { - logError('RTB House: required schain params missing'); + utils.logError('RTB House: required schain params missing'); return null; } return schain; @@ -233,7 +223,7 @@ function validateSchain(schain) { * @returns {object} Request by OpenRTB Native Ads 1.1 §4 */ function mapNative(slot) { - if (slot.mediaType === 'native' || deepAccess(slot, 'mediaTypes.native')) { + if (slot.mediaType === 'native' || utils.deepAccess(slot, 'mediaTypes.native')) { return { request: { assets: mapNativeAssets(slot) @@ -248,7 +238,7 @@ function mapNative(slot) { * @returns {array} Request Assets by OpenRTB Native Ads 1.1 §4.2 */ function mapNativeAssets(slot) { - const params = slot.nativeParams || deepAccess(slot, 'mediaTypes.native'); + const params = slot.nativeParams || utils.deepAccess(slot, 'mediaTypes.native'); const assets = []; if (params.title) { assets.push({ diff --git a/modules/rtbsapeBidAdapter.js b/modules/rtbsapeBidAdapter.js index d58b3a1f240..f5c648d5234 100644 --- a/modules/rtbsapeBidAdapter.js +++ b/modules/rtbsapeBidAdapter.js @@ -1,8 +1,9 @@ -import { deepAccess, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {OUTSTREAM} from '../src/video.js'; import {Renderer} from '../src/Renderer.js'; +import {triggerPixel} from '../src/utils.js'; const BIDDER_CODE = 'rtbsape'; const ENDPOINT = 'https://ssp-rtb.sape.ru/prebid'; @@ -67,7 +68,7 @@ export const spec = { .filter(bid => typeof (bid.meta || {}).advertiserDomains !== 'undefined') .map(bid => { let requestBid = bids[bid.requestId]; - let context = deepAccess(requestBid, 'mediaTypes.video.context'); + let context = utils.deepAccess(requestBid, 'mediaTypes.video.context'); if (context === OUTSTREAM && (bid.vastUrl || bid.vastXml)) { let renderer = Renderer.install({ @@ -76,7 +77,7 @@ export const spec = { loaded: false }); - let muted = deepAccess(requestBid, 'params.video.playerMuted'); + let muted = utils.deepAccess(requestBid, 'params.video.playerMuted'); if (typeof muted === 'undefined') { muted = true; } diff --git a/modules/rtdModule/index.js b/modules/rtdModule/index.js index 67326e7d887..e235868f791 100644 --- a/modules/rtdModule/index.js +++ b/modules/rtdModule/index.js @@ -42,10 +42,10 @@ * @function? * @summary modify bid request data * @name RtdSubmodule#getBidRequestData - * @param {Object} reqBidsConfigObj - * @param {function} callback * @param {SubmoduleConfig} config * @param {UserConsentData} userConsent + * @param {Object} reqBidsConfigObj + * @param {function} callback */ /** @@ -98,15 +98,6 @@ * @param {UserConsentData} userConsent */ -/** - * @function? - * @summary on bid requested event - * @name RtdSubmodule#onBidRequestEvent - * @param {Object} data - * @param {SubmoduleConfig} config - * @param {UserConsentData} userConsent - */ - /** * @interface ModuleConfig */ @@ -152,7 +143,7 @@ import {config} from '../../src/config.js'; import {module} from '../../src/hook.js'; -import {logError, logInfo, logWarn} from '../../src/utils.js'; +import * as utils from '../../src/utils.js'; import events from '../../src/events.js'; import CONSTANTS from '../../src/constants.json'; import {gdprDataHandler, uspDataHandler} from '../../src/adapterManager.js'; @@ -173,55 +164,17 @@ let _dataProviders = []; let _userConsent; /** - * Register a RTD submodule. - * + * enable submodule in User ID * @param {RtdSubmodule} submodule - * @returns {function()} a de-registration function that will unregister the module when called. */ export function attachRealTimeDataProvider(submodule) { registeredSubModules.push(submodule); - return function detach() { - const idx = registeredSubModules.indexOf(submodule) - if (idx >= 0) { - registeredSubModules.splice(idx, 1); - initSubModules(); - } - } } -/** - * call each sub module event function by config order - */ -const setEventsListeners = (function () { - let registered = false; - return function setEventsListeners() { - if (!registered) { - Object.entries({ - [CONSTANTS.EVENTS.AUCTION_INIT]: ['onAuctionInitEvent'], - [CONSTANTS.EVENTS.AUCTION_END]: ['onAuctionEndEvent', getAdUnitTargeting], - [CONSTANTS.EVENTS.BID_RESPONSE]: ['onBidResponseEvent'], - [CONSTANTS.EVENTS.BID_REQUESTED]: ['onBidRequestEvent'] - }).forEach(([ev, [handler, preprocess]]) => { - events.on(ev, (args) => { - preprocess && preprocess(args); - subModules.forEach(sm => { - try { - sm[handler] && sm[handler](args, sm.config, _userConsent) - } catch (e) { - logError(`RTD provider '${sm.name}': error in '${handler}':`, e); - } - }); - }) - }); - registered = true; - } - } -})(); - export function init(config) { const confListener = config.getConfig(MODULE_NAME, ({realTimeData}) => { if (!realTimeData.dataProviders) { - logError('missing parameters for real time module'); + utils.logError('missing parameters for real time module'); return; } confListener(); // unsubscribe config listener @@ -256,7 +209,22 @@ function initSubModules() { } }); subModules = subModulesByOrder; - logInfo(`Real time data module enabled, using submodules: ${subModules.map((m) => m.name).join(', ')}`); +} + +/** + * call each sub module event function by config order + */ +function setEventsListeners() { + events.on(CONSTANTS.EVENTS.AUCTION_INIT, (args) => { + subModules.forEach(sm => { sm.onAuctionInitEvent && sm.onAuctionInitEvent(args, sm.config, _userConsent) }) + }); + events.on(CONSTANTS.EVENTS.AUCTION_END, (args) => { + getAdUnitTargeting(args); + subModules.forEach(sm => { sm.onAuctionEndEvent && sm.onAuctionEndEvent(args, sm.config, _userConsent) }) + }); + events.on(CONSTANTS.EVENTS.BID_RESPONSE, (args) => { + subModules.forEach(sm => { sm.onBidResponseEvent && sm.onBidResponseEvent(args, sm.config, _userConsent) }) + }); } /** @@ -346,7 +314,7 @@ export function getAdUnitTargeting(auction) { if (smTargeting && typeof smTargeting === 'object') { targeting.push(smTargeting); } else { - logWarn('invalid getTargetingData response for sub module', relevantSubModules[i].name); + utils.logWarn('invalid getTargetingData response for sub module', relevantSubModules[i].name); } } // place data on auction adUnits diff --git a/modules/rubiconAnalyticsAdapter.js b/modules/rubiconAnalyticsAdapter.js index 5b17048cbd3..0d47bee235f 100644 --- a/modules/rubiconAnalyticsAdapter.js +++ b/modules/rubiconAnalyticsAdapter.js @@ -1,9 +1,9 @@ -import { generateUUID, mergeDeep, deepAccess, parseUrl, logError, pick, isEmpty, logWarn, debugTurnedOn, parseQS, getWindowLocation, isAdUnitCodeMatchingSlot, isNumber, isGptPubadsDefined, _each, deepSetValue } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; import { ajax } from '../src/ajax.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; import { getGlobal } from '../src/prebidGlobal.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -43,7 +43,7 @@ const { } = CONSTANTS; let serverConfig; -config.getConfig('s2sConfig', ({ s2sConfig }) => { +config.getConfig('s2sConfig', ({s2sConfig}) => { serverConfig = s2sConfig; }); @@ -60,23 +60,23 @@ const cache = { const BID_REJECTED_IPF = 'rejected-ipf'; export let rubiConf = { - pvid: generateUUID().slice(0, 8), + pvid: utils.generateUUID().slice(0, 8), analyticsEventDelay: 0 }; // we are saving these as global to this module so that if a pub accidentally overwrites the entire // rubicon object, then we do not lose other data config.getConfig('rubicon', config => { - mergeDeep(rubiConf, config.rubicon); - if (deepAccess(config, 'rubicon.updatePageView') === true) { - rubiConf.pvid = generateUUID().slice(0, 8) + utils.mergeDeep(rubiConf, config.rubicon); + if (utils.deepAccess(config, 'rubicon.updatePageView') === true) { + rubiConf.pvid = utils.generateUUID().slice(0, 8) } }); export function getHostNameFromReferer(referer) { try { - rubiconAdapter.referrerHostname = parseUrl(referer, { noDecodeWholeURL: true }).hostname; + rubiconAdapter.referrerHostname = utils.parseUrl(referer, {noDecodeWholeURL: true}).hostname; } catch (e) { - logError('Rubicon Analytics: Unable to parse hostname from supplied url: ', referer, e); + utils.logError('Rubicon Analytics: Unable to parse hostname from supplied url: ', referer, e); rubiconAdapter.referrerHostname = ''; } return rubiconAdapter.referrerHostname @@ -90,7 +90,7 @@ function stringProperties(obj) { } else if (typeof value !== 'string') { value = String(value); } - newObj[prop] = value || undefined; + newObj[prop] = value; return newObj; }, {}); } @@ -117,10 +117,10 @@ function formatSource(src) { function sendMessage(auctionId, bidWonId, trigger) { function formatBid(bid) { - return pick(bid, [ + return utils.pick(bid, [ 'bidder', 'bidderDetail', - 'bidId', bidId => deepAccess(bid, 'bidResponse.pbsBidId') || deepAccess(bid, 'bidResponse.seatBidId') || bidId, + 'bidId', bidId => utils.deepAccess(bid, 'bidResponse.pbsBidId') || utils.deepAccess(bid, 'bidResponse.seatBidId') || bidId, 'status', 'error', 'source', (source, bid) => { @@ -133,7 +133,7 @@ function sendMessage(auctionId, bidWonId, trigger) { 'clientLatencyMillis', 'serverLatencyMillis', 'params', - 'bidResponse', bidResponse => bidResponse ? pick(bidResponse, [ + 'bidResponse', bidResponse => bidResponse ? utils.pick(bidResponse, [ 'bidPriceUSD', 'dealId', 'dimensions', @@ -146,13 +146,13 @@ function sendMessage(auctionId, bidWonId, trigger) { ]); } function formatBidWon(bid) { - return Object.assign(formatBid(bid), pick(bid.adUnit, [ + return Object.assign(formatBid(bid), utils.pick(bid.adUnit, [ 'adUnitCode', 'transactionId', 'videoAdFormat', () => bid.videoAdFormat, 'mediaTypes' ]), { - adserverTargeting: !isEmpty(cache.targeting[bid.adUnit.adUnitCode]) ? stringProperties(cache.targeting[bid.adUnit.adUnitCode]) : undefined, + adserverTargeting: !utils.isEmpty(cache.targeting[bid.adUnit.adUnitCode]) ? stringProperties(cache.targeting[bid.adUnit.adUnitCode]) : undefined, bidwonStatus: 'success', // hard-coded for now accountId, siteId: bid.siteId, @@ -187,13 +187,13 @@ function sendMessage(auctionId, bidWonId, trigger) { let bid = auctionCache.bids[bidId]; let adUnit = adUnits[bid.adUnit.adUnitCode]; if (!adUnit) { - adUnit = adUnits[bid.adUnit.adUnitCode] = pick(bid.adUnit, [ + adUnit = adUnits[bid.adUnit.adUnitCode] = utils.pick(bid.adUnit, [ 'adUnitCode', 'transactionId', 'mediaTypes', 'dimensions', - 'adserverTargeting', () => !isEmpty(cache.targeting[bid.adUnit.adUnitCode]) ? stringProperties(cache.targeting[bid.adUnit.adUnitCode]) : undefined, - 'gam', gam => !isEmpty(gam) ? gam : undefined, + 'adserverTargeting', () => !utils.isEmpty(cache.targeting[bid.adUnit.adUnitCode]) ? stringProperties(cache.targeting[bid.adUnit.adUnitCode]) : undefined, + 'gam', gam => !utils.isEmpty(gam) ? gam : undefined, 'pbAdSlot', 'pattern' ]); @@ -203,10 +203,10 @@ function sendMessage(auctionId, bidWonId, trigger) { // Add site and zone id if not there and if we found a rubicon bidder if ((!adUnit.siteId || !adUnit.zoneId) && rubiconAliases.indexOf(bid.bidder) !== -1) { - if (deepAccess(bid, 'params.accountId') == accountId) { + if (utils.deepAccess(bid, 'params.accountId') == accountId) { adUnit.accountId = parseInt(accountId); - adUnit.siteId = parseInt(deepAccess(bid, 'params.siteId')); - adUnit.zoneId = parseInt(deepAccess(bid, 'params.zoneId')); + adUnit.siteId = parseInt(utils.deepAccess(bid, 'params.siteId')); + adUnit.zoneId = parseInt(utils.deepAccess(bid, 'params.zoneId')); } } @@ -229,7 +229,7 @@ function sendMessage(auctionId, bidWonId, trigger) { // This allows the bidWon events to have these params even in the case of a delayed render Object.keys(auctionCache.bids).forEach(function (bidId) { let adCode = auctionCache.bids[bidId].adUnit.adUnitCode; - Object.assign(auctionCache.bids[bidId], pick(adUnitMap[adCode], ['accountId', 'siteId', 'zoneId'])); + Object.assign(auctionCache.bids[bidId], utils.pick(adUnitMap[adCode], ['accountId', 'siteId', 'zoneId'])); }); let auction = { @@ -243,20 +243,20 @@ function sendMessage(auctionId, bidWonId, trigger) { // pick our of top level floor data we want to send! if (auctionCache.floorData) { if (auctionCache.floorData.location === 'noData') { - auction.floors = pick(auctionCache.floorData, [ + auction.floors = utils.pick(auctionCache.floorData, [ 'location', 'fetchStatus', 'floorProvider as provider' ]); } else { - auction.floors = pick(auctionCache.floorData, [ + auction.floors = utils.pick(auctionCache.floorData, [ 'location', 'modelVersion as modelName', 'modelWeight', 'modelTimestamp', 'skipped', - 'enforcement', () => deepAccess(auctionCache.floorData, 'enforcements.enforceJS'), - 'dealsEnforced', () => deepAccess(auctionCache.floorData, 'enforcements.floorDeals'), + 'enforcement', () => utils.deepAccess(auctionCache.floorData, 'enforcements.enforceJS'), + 'dealsEnforced', () => utils.deepAccess(auctionCache.floorData, 'enforcements.floorDeals'), 'skipRate', 'fetchStatus', 'floorMin', @@ -267,7 +267,7 @@ function sendMessage(auctionId, bidWonId, trigger) { // gather gdpr info if (auctionCache.gdprConsent) { - auction.gdpr = pick(auctionCache.gdprConsent, [ + auction.gdpr = utils.pick(auctionCache.gdprConsent, [ 'gdprApplies as applies', 'consentString', 'apiVersion as version' @@ -276,13 +276,13 @@ function sendMessage(auctionId, bidWonId, trigger) { // gather session info if (auctionCache.session) { - message.session = pick(auctionCache.session, [ + message.session = utils.pick(auctionCache.session, [ 'id', 'pvid', 'start', 'expires' ]); - if (!isEmpty(auctionCache.session.fpkvs)) { + if (!utils.isEmpty(auctionCache.session.fpkvs)) { message.fpkvs = Object.keys(auctionCache.session.fpkvs).map(key => { return { key, value: auctionCache.session.fpkvs[key] }; }); @@ -294,7 +294,7 @@ function sendMessage(auctionId, bidWonId, trigger) { } if (auctionCache.userIds.length) { - auction.user = { ids: auctionCache.userIds }; + auction.user = {ids: auctionCache.userIds}; } message.auctions = [auction]; @@ -329,14 +329,14 @@ function sendMessage(auctionId, bidWonId, trigger) { } function adUnitIsOnlyInstream(adUnit) { - return adUnit.mediaTypes && Object.keys(adUnit.mediaTypes).length === 1 && deepAccess(adUnit, 'mediaTypes.video.context') === 'instream'; + return adUnit.mediaTypes && Object.keys(adUnit.mediaTypes).length === 1 && utils.deepAccess(adUnit, 'mediaTypes.video.context') === 'instream'; } function getBidPrice(bid) { // get the cpm from bidResponse let cpm; let currency; - if (bid.status === BID_REJECTED && deepAccess(bid, 'floorData.cpmAfterAdjustments')) { + if (bid.status === BID_REJECTED && utils.deepAccess(bid, 'floorData.cpmAfterAdjustments')) { // if bid was rejected and bid.floorData.cpmAfterAdjustments use it cpm = bid.floorData.cpmAfterAdjustments; currency = bid.floorData.floorCurrency; @@ -356,7 +356,7 @@ function getBidPrice(bid) { try { return Number(prebidGlobal.convertCurrency(cpm, currency, 'USD')); } catch (err) { - logWarn('Rubicon Analytics Adapter: Could not determine the bidPriceUSD of the bid ', bid); + utils.logWarn('Rubicon Analytics Adapter: Could not determine the bidPriceUSD of the bid ', bid); } } @@ -367,7 +367,7 @@ export function parseBidResponse(bid, previousBidResponse, auctionFloorData) { if (previousBidResponse && previousBidResponse.bidPriceUSD > responsePrice) { return previousBidResponse; } - return pick(bid, [ + return utils.pick(bid, [ 'bidPriceUSD', () => responsePrice, 'dealId', 'status', @@ -375,16 +375,16 @@ export function parseBidResponse(bid, previousBidResponse, auctionFloorData) { 'dimensions', () => { const width = bid.width || bid.playerWidth; const height = bid.height || bid.playerHeight; - return (width && height) ? { width, height } : undefined; + return (width && height) ? {width, height} : undefined; }, // Handling use case where pbs sends back 0 or '0' bidIds - 'pbsBidId', pbsBidId => pbsBidId == 0 ? generateUUID() : pbsBidId, - 'seatBidId', seatBidId => seatBidId == 0 ? generateUUID() : seatBidId, - 'floorValue', () => deepAccess(bid, 'floorData.floorValue'), - 'floorRuleValue', () => deepAccess(bid, 'floorData.floorRuleValue'), - 'floorRule', () => debugTurnedOn() ? deepAccess(bid, 'floorData.floorRule') : undefined, + 'pbsBidId', pbsBidId => pbsBidId == 0 ? utils.generateUUID() : pbsBidId, + 'seatBidId', seatBidId => seatBidId == 0 ? utils.generateUUID() : seatBidId, + 'floorValue', () => utils.deepAccess(bid, 'floorData.floorValue'), + 'floorRuleValue', () => utils.deepAccess(bid, 'floorData.floorRuleValue'), + 'floorRule', () => utils.debugTurnedOn() ? utils.deepAccess(bid, 'floorData.floorRule') : undefined, 'adomains', () => { - let adomains = deepAccess(bid, 'meta.advertiserDomains'); + let adomains = utils.deepAccess(bid, 'meta.advertiserDomains'); return Array.isArray(adomains) && adomains.length > 0 ? adomains.slice(0, 10) : undefined } ]); @@ -397,7 +397,7 @@ function getUtmParams() { let search; try { - search = parseQS(getWindowLocation().search); + search = utils.parseQS(utils.getWindowLocation().search); } catch (e) { search = {}; } @@ -445,7 +445,7 @@ function getRpaCookie() { try { return JSON.parse(window.atob(encodedCookie)); } catch (e) { - logError(`Rubicon Analytics: Unable to decode ${COOKIE_NAME} value: `, e); + utils.logError(`Rubicon Analytics: Unable to decode ${COOKIE_NAME} value: `, e); } } return {}; @@ -455,7 +455,7 @@ function setRpaCookie(decodedCookie) { try { storage.setDataInLocalStorage(COOKIE_NAME, window.btoa(JSON.stringify(decodedCookie))); } catch (e) { - logError(`Rubicon Analytics: Unable to encode ${COOKIE_NAME} value: `, e); + utils.logError(`Rubicon Analytics: Unable to encode ${COOKIE_NAME} value: `, e); } } @@ -468,7 +468,7 @@ function updateRpaCookie() { decodedRpaCookie.expires < currentTime ) { decodedRpaCookie = { - id: generateUUID(), + id: utils.generateUUID(), start: currentTime, expires: currentTime + END_EXPIRE_TIME, // six hours later, } @@ -476,7 +476,7 @@ function updateRpaCookie() { // possible that decodedRpaCookie is undefined, and if it is, we probably are blocked by storage or some other exception if (Object.keys(decodedRpaCookie).length) { decodedRpaCookie.lastSeen = currentTime; - decodedRpaCookie.fpkvs = { ...decodedRpaCookie.fpkvs, ...getFpkvs() }; + decodedRpaCookie.fpkvs = {...decodedRpaCookie.fpkvs, ...getFpkvs()}; decodedRpaCookie.pvid = rubiConf.pvid; setRpaCookie(decodedRpaCookie) } @@ -485,7 +485,7 @@ function updateRpaCookie() { function subscribeToGamSlots() { window.googletag.pubads().addEventListener('slotRenderEnded', event => { - const isMatchingAdSlot = isAdUnitCodeMatchingSlot(event.slot); + const isMatchingAdSlot = utils.isAdUnitCodeMatchingSlot(event.slot); // loop through auctions and adUnits and mark the info Object.keys(cache.auctions).forEach(auctionId => { (Object.keys(cache.auctions[auctionId].bids) || []).forEach(bidId => { @@ -495,12 +495,12 @@ function subscribeToGamSlots() { // mark this adUnit as having been rendered by gam cache.auctions[auctionId].gamHasRendered[bid.adUnit.adUnitCode] = true; - bid.adUnit.gam = pick(event, [ + bid.adUnit.gam = utils.pick(event, [ // these come in as `null` from Gpt, which when stringified does not get removed // so set explicitly to undefined when not a number - 'advertiserId', advertiserId => isNumber(advertiserId) ? advertiserId : undefined, - 'creativeId', creativeId => isNumber(event.sourceAgnosticCreativeId) ? event.sourceAgnosticCreativeId : isNumber(creativeId) ? creativeId : undefined, - 'lineItemId', lineItemId => isNumber(event.sourceAgnosticLineItemId) ? event.sourceAgnosticLineItemId : isNumber(lineItemId) ? lineItemId : undefined, + 'advertiserId', advertiserId => utils.isNumber(advertiserId) ? advertiserId : undefined, + 'creativeId', creativeId => utils.isNumber(event.sourceAgnosticCreativeId) ? event.sourceAgnosticCreativeId : utils.isNumber(creativeId) ? creativeId : undefined, + 'lineItemId', lineItemId => utils.isNumber(event.sourceAgnosticLineItemId) ? event.sourceAgnosticLineItemId : utils.isNumber(lineItemId) ? lineItemId : undefined, 'adSlot', () => event.slot.getAdUnitPath(), 'isSlotEmpty', () => event.isEmpty || undefined ]); @@ -520,7 +520,7 @@ function subscribeToGamSlots() { }); } -let baseAdapter = adapter({ analyticsType: 'endpoint' }); +let baseAdapter = adapter({analyticsType: 'endpoint'}); let rubiconAdapter = Object.assign({}, baseAdapter, { MODULE_INITIALIZED_TIME: Date.now(), referrerHostname: '', @@ -535,7 +535,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { if (config.options.endpoint) { this.getUrl = () => config.options.endpoint; } else { - logError('required endpoint missing from rubicon analytics'); + utils.logError('required endpoint missing from rubicon analytics'); error = true; } if (typeof config.options.sampling !== 'undefined') { @@ -543,7 +543,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { } if (typeof config.options.samplingFactor !== 'undefined') { if (typeof config.options.sampling !== 'undefined') { - logWarn('Both options.samplingFactor and options.sampling enabled in rubicon analytics, defaulting to samplingFactor'); + utils.logWarn('Both options.samplingFactor and options.sampling enabled in rubicon analytics, defaulting to samplingFactor'); } samplingFactor = parseFloat(config.options.samplingFactor); config.options.sampling = 1 / samplingFactor; @@ -553,10 +553,10 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { let validSamplingFactors = [1, 10, 20, 40, 100]; if (validSamplingFactors.indexOf(samplingFactor) === -1) { error = true; - logError('invalid samplingFactor for rubicon analytics: ' + samplingFactor + ', must be one of ' + validSamplingFactors.join(', ')); + utils.logError('invalid samplingFactor for rubicon analytics: ' + samplingFactor + ', must be one of ' + validSamplingFactors.join(', ')); } else if (!accountId) { error = true; - logError('required accountId missing for rubicon analytics'); + utils.logError('required accountId missing for rubicon analytics'); } if (!error) { @@ -570,38 +570,38 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { cache.gpt.registered = false; baseAdapter.disableAnalytics.apply(this, arguments); }, - track({ eventType, args }) { + track({eventType, args}) { switch (eventType) { case AUCTION_INIT: // set the rubicon aliases setRubiconAliases(adapterManager.aliasRegistry); - let cacheEntry = pick(args, [ + let cacheEntry = utils.pick(args, [ 'timestamp', 'timeout' ]); cacheEntry.bids = {}; cacheEntry.bidsWon = {}; cacheEntry.gamHasRendered = {}; - cacheEntry.referrer = deepAccess(args, 'bidderRequests.0.refererInfo.referer'); - const floorData = deepAccess(args, 'bidderRequests.0.bids.0.floorData'); + cacheEntry.referrer = utils.deepAccess(args, 'bidderRequests.0.refererInfo.referer'); + const floorData = utils.deepAccess(args, 'bidderRequests.0.bids.0.floorData'); if (floorData) { - cacheEntry.floorData = { ...floorData }; + cacheEntry.floorData = {...floorData}; } - cacheEntry.gdprConsent = deepAccess(args, 'bidderRequests.0.gdprConsent'); + cacheEntry.gdprConsent = utils.deepAccess(args, 'bidderRequests.0.gdprConsent'); cacheEntry.session = storage.localStorageIsEnabled() && updateRpaCookie(); - cacheEntry.userIds = Object.keys(deepAccess(args, 'bidderRequests.0.bids.0.userId', {})).map(id => { - return { provider: id, hasId: true } + cacheEntry.userIds = Object.keys(utils.deepAccess(args, 'bidderRequests.0.bids.0.userId', {})).map(id => { + return {provider: id, hasId: true} }); cache.auctions[args.auctionId] = cacheEntry; // register to listen to gpt events if not done yet - if (!cache.gpt.registered && isGptPubadsDefined()) { + if (!cache.gpt.registered && utils.isGptPubadsDefined()) { subscribeToGamSlots(); cache.gpt.registered = true; } else if (!cache.gpt.registered) { cache.gpt.registered = true; window.googletag = window.googletag || {}; window.googletag.cmd = window.googletag.cmd || []; - window.googletag.cmd.push(function () { + window.googletag.cmd.push(function() { subscribeToGamSlots(); }); } @@ -615,7 +615,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { cache.auctions[args.auctionId].gamHasRendered[bid.adUnitCode] = false; } - memo[bid.bidId] = pick(bid, [ + memo[bid.bidId] = utils.pick(bid, [ 'bidder', bidder => bidder.toLowerCase(), 'bidId', 'status', () => 'no-bid', // default a bid to no-bid until response is recieved or bid is timed out @@ -624,7 +624,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { switch (bid.bidder) { // specify bidder params we want here case 'rubicon': - return pick(params, [ + return utils.pick(params, [ 'accountId', 'siteId', 'zoneId' @@ -640,9 +640,9 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { 204: 'mid-roll', 205: 'post-roll', 207: 'vertical' - })[deepAccess(bid, 'params.video.size_id')]; + })[utils.deepAccess(bid, 'params.video.size_id')]; } else { - let startdelay = parseInt(deepAccess(bid, 'params.video.startdelay'), 10); + let startdelay = parseInt(utils.deepAccess(bid, 'params.video.startdelay'), 10); if (!isNaN(startdelay)) { if (startdelay > 0) { return 'mid-roll'; @@ -655,7 +655,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { } } }, - 'adUnit', () => pick(bid, [ + 'adUnit', () => utils.pick(bid, [ 'adUnitCode', 'transactionId', 'sizes as dimensions', sizes => sizes.map(sizeToDimensions), @@ -669,7 +669,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { if (typeof types === 'object') { if (!bid.sizes) { bid.dimensions = []; - _each(types, (type) => + utils._each(types, (type) => bid.dimensions = bid.dimensions.concat( type.sizes.map(sizeToDimensions) ) @@ -680,12 +680,12 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { return ['banner']; }, 'gam', () => { - if (deepAccess(bid, 'ortb2Imp.ext.data.adserver.name') === 'gam') { - return { adSlot: bid.ortb2Imp.ext.data.adserver.adslot } + if (utils.deepAccess(bid, 'ortb2Imp.ext.data.adserver.name') === 'gam') { + return {adSlot: bid.ortb2Imp.ext.data.adserver.adslot} } }, - 'pbAdSlot', () => deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'), - 'pattern', () => deepAccess(bid, 'ortb2Imp.ext.data.aupname') + 'pbAdSlot', () => utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'), + 'pattern', () => utils.deepAccess(bid, 'ortb2Imp.ext.data.aupname') ]) ]); return memo; @@ -695,22 +695,22 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { let auctionEntry = cache.auctions[args.auctionId]; if (!auctionEntry.bids[args.requestId] && args.originalRequestId) { - auctionEntry.bids[args.requestId] = { ...auctionEntry.bids[args.originalRequestId] }; + auctionEntry.bids[args.requestId] = {...auctionEntry.bids[args.originalRequestId]}; auctionEntry.bids[args.requestId].bidId = args.requestId; auctionEntry.bids[args.requestId].bidderDetail = args.targetingBidder; } let bid = auctionEntry.bids[args.requestId]; // If floor resolved gptSlot but we have not yet, then update the adUnit to have the adSlot name - if (!deepAccess(bid, 'adUnit.gam.adSlot') && deepAccess(args, 'floorData.matchedFields.gptSlot')) { - deepSetValue(bid, 'adUnit.gam.adSlot', args.floorData.matchedFields.gptSlot); + if (!utils.deepAccess(bid, 'adUnit.gam.adSlot') && utils.deepAccess(args, 'floorData.matchedFields.gptSlot')) { + utils.deepSetValue(bid, 'adUnit.gam.adSlot', args.floorData.matchedFields.gptSlot); } // if we have not set enforcements yet set it - if (!deepAccess(auctionEntry, 'floorData.enforcements') && deepAccess(args, 'floorData.enforcements')) { - auctionEntry.floorData.enforcements = { ...args.floorData.enforcements }; + if (!utils.deepAccess(auctionEntry, 'floorData.enforcements') && utils.deepAccess(args, 'floorData.enforcements')) { + auctionEntry.floorData.enforcements = {...args.floorData.enforcements}; } if (!bid) { - logError('Rubicon Anlytics Adapter Error: Could not find associated bid request for bid response with requestId: ', args.requestId); + utils.logError('Rubicon Anlytics Adapter Error: Could not find associated bid request for bid response with requestId: ', args.requestId); break; } bid.source = formatSource(bid.source || args.source); @@ -733,7 +733,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { bid.bidResponse = parseBidResponse(args, bid.bidResponse); break; case BIDDER_DONE: - const serverError = deepAccess(args, 'serverErrors.0'); + const serverError = utils.deepAccess(args, 'serverErrors.0'); const serverResponseTimeMs = args.serverResponseTimeMs; args.bids.forEach(bid => { let cachedBid = cache.auctions[bid.auctionId].bids[bid.bidId || bid.requestId]; @@ -803,7 +803,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, { bid.status = 'error'; bid.error = { code: 'timeout-error', - description: 'prebid.js timeout' // will help us diff if timeout was set by PBS or PBJS + message: 'marked by prebid.js as timeout' // will help us diff if timeout was set by PBS or PBJS }; } }); diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index 28e491900f8..354289a1823 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -1,4 +1,4 @@ -import { mergeDeep, _each, logError, deepAccess, deepSetValue, isStr, isNumber, logWarn, convertTypes, isArray, parseSizesInput, logMessage, formatQS } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; @@ -15,7 +15,7 @@ let rubiConf = {}; // we are saving these as global to this module so that if a pub accidentally overwrites the entire // rubicon object, then we do not lose other data config.getConfig('rubicon', config => { - mergeDeep(rubiConf, config.rubicon); + utils.mergeDeep(rubiConf, config.rubicon); }); const GVLID = 52; @@ -110,19 +110,9 @@ var sizeMap = { 548: '500x1000', 550: '980x480', 552: '300x200', - 558: '640x640', - 562: '300x431', - 564: '320x431', - 566: '320x300', - 568: '300x150', - 570: '300x125', - 572: '250x350', - 574: '620x891', - 576: '610x877', - 578: '980x552', - 580: '505x656' + 558: '640x640' }; -_each(sizeMap, (item, key) => sizeMap[item] = key); +utils._each(sizeMap, (item, key) => sizeMap[item] = key); export const spec = { code: 'rubicon', @@ -140,7 +130,7 @@ export const spec = { for (let i = 0, props = ['accountId', 'siteId', 'zoneId']; i < props.length; i++) { bid.params[props[i]] = parseInt(bid.params[props[i]]) if (isNaN(bid.params[props[i]])) { - logError('Rubicon: wrong format of accountId or siteId or zoneId.') + utils.logError('Rubicon: wrong format of accountId or siteId or zoneId.') return false } } @@ -180,7 +170,7 @@ export const spec = { ext: { [bidRequest.bidder]: bidRequest.params }, - video: deepAccess(bidRequest, 'mediaTypes.video') || {} + video: utils.deepAccess(bidRequest, 'mediaTypes.video') || {} }], ext: { prebid: { @@ -217,7 +207,7 @@ export const spec = { let modules = (getGlobal()).installedModules; if (modules && (!modules.length || modules.indexOf('rubiconAnalyticsAdapter') !== -1)) { - deepSetValue(data, 'ext.prebid.analytics', {'rubicon': {'client-analytics': true}}); + utils.deepSetValue(data, 'ext.prebid.analytics', {'rubicon': {'client-analytics': true}}); } let bidFloor; @@ -230,11 +220,11 @@ export const spec = { size: parseSizes(bidRequest, 'video') }); } catch (e) { - logError('Rubicon: getFloor threw an error: ', e); + utils.logError('Rubicon: getFloor threw an error: ', e); } bidFloor = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? parseFloat(floorInfo.floor) : undefined; } else { - bidFloor = parseFloat(deepAccess(bidRequest, 'params.floor')); + bidFloor = parseFloat(utils.deepAccess(bidRequest, 'params.floor')); } if (!isNaN(bidFloor)) { data.imp[0].bidfloor = bidFloor; @@ -253,36 +243,36 @@ export const spec = { gdprApplies = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; } - deepSetValue(data, 'regs.ext.gdpr', gdprApplies); - deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(data, 'regs.ext.gdpr', gdprApplies); + utils.deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } if (bidderRequest.uspConsent) { - deepSetValue(data, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(data, 'regs.ext.us_privacy', bidderRequest.uspConsent); } - const eids = deepAccess(bidderRequest, 'bids.0.userIdAsEids'); + const eids = utils.deepAccess(bidderRequest, 'bids.0.userIdAsEids'); if (eids && eids.length) { - deepSetValue(data, 'user.ext.eids', eids); + utils.deepSetValue(data, 'user.ext.eids', eids); } // set user.id value from config value const configUserId = config.getConfig('user.id'); if (configUserId) { - deepSetValue(data, 'user.id', configUserId); + utils.deepSetValue(data, 'user.id', configUserId); } if (config.getConfig('coppa') === true) { - deepSetValue(data, 'regs.coppa', 1); + utils.deepSetValue(data, 'regs.coppa', 1); } if (bidRequest.schain && hasValidSupplyChainParams(bidRequest.schain)) { - deepSetValue(data, 'source.ext.schain', bidRequest.schain); + utils.deepSetValue(data, 'source.ext.schain', bidRequest.schain); } const multibid = config.getConfig('multibid'); if (multibid) { - deepSetValue(data, 'ext.prebid.multibid', multibid.reduce((result, i) => { + utils.deepSetValue(data, 'ext.prebid.multibid', multibid.reduce((result, i) => { let obj = {}; Object.keys(i).forEach(key => { @@ -299,11 +289,11 @@ export const spec = { // if storedAuctionResponse has been set, pass SRID if (bidRequest.storedAuctionResponse) { - deepSetValue(data.imp[0], 'ext.prebid.storedauctionresponse.id', bidRequest.storedAuctionResponse.toString()); + utils.deepSetValue(data.imp[0], 'ext.prebid.storedauctionresponse.id', bidRequest.storedAuctionResponse.toString()); } // set ext.prebid.auctiontimestamp using auction time - deepSetValue(data.imp[0], 'ext.prebid.auctiontimestamp', bidderRequest.auctionStart); + utils.deepSetValue(data.imp[0], 'ext.prebid.auctiontimestamp', bidderRequest.auctionStart); return { method: 'POST', @@ -322,14 +312,14 @@ export const spec = { url: `https://${rubiConf.bannerHost || 'fastlane'}.rubiconproject.com/a/api/fastlane.json`, data: spec.getOrderedParams(bidParams).reduce((paramString, key) => { const propValue = bidParams[key]; - return ((isStr(propValue) && propValue !== '') || isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString; + return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString; }, '') + `slots=1&rand=${Math.random()}`, bidRequest }; })); } else { // single request requires bids to be grouped by site id into a single request - // note: groupBy wasn't used because deep property access was needed + // note: utils.groupBy wasn't used because deep property access was needed const nonVideoRequests = bidRequests.filter(bidRequest => bidType(bidRequest) === 'banner'); const groupedBidRequests = nonVideoRequests.reduce((groupedBids, bid) => { (groupedBids[bid.params['siteId']] = groupedBids[bid.params['siteId']] || []).push(bid); @@ -353,7 +343,7 @@ export const spec = { url: `https://${rubiConf.bannerHost || 'fastlane'}.rubiconproject.com/a/api/fastlane.json`, data: spec.getOrderedParams(combinedSlotParams).reduce((paramString, key) => { const propValue = combinedSlotParams[key]; - return ((isStr(propValue) && propValue !== '') || isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString; + return ((utils.isStr(propValue) && propValue !== '') || utils.isNumber(propValue)) ? `${paramString}${encodeParam(key, propValue)}&` : paramString; }, '') + `slots=${bidsInGroup.length}&rand=${Math.random()}`, bidRequest: bidsInGroup }); @@ -485,7 +475,7 @@ export const spec = { size: '*' }); } catch (e) { - logError('Rubicon: getFloor threw an error: ', e); + utils.logError('Rubicon: getFloor threw an error: ', e); } data['rp_hard_floor'] = typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseInt(floorInfo.floor)) ? floorInfo.floor : undefined; } @@ -493,7 +483,7 @@ export const spec = { // add p_pos only if specified and valid // For SRA we need to explicitly put empty semi colons so AE treats it as empty, instead of copying the latter value let posMapping = {1: 'atf', 3: 'btf'}; - let pos = posMapping[deepAccess(bidRequest, 'mediaTypes.banner.pos')] || ''; + let pos = posMapping[utils.deepAccess(bidRequest, 'mediaTypes.banner.pos')] || ''; data['p_pos'] = (params.position === 'atf' || params.position === 'btf') ? params.position : pos; // pass publisher provided userId if configured @@ -532,7 +522,7 @@ export const spec = { } } } catch (e) { - logWarn('Rubicon: error reading eid:', eid, e); + utils.logWarn('Rubicon: error reading eid:', eid, e); } }); } @@ -605,9 +595,9 @@ export const spec = { // video response from PBS Java openRTB if (responseObj.seatbid) { - const responseErrors = deepAccess(responseObj, 'ext.errors.rubicon'); + const responseErrors = utils.deepAccess(responseObj, 'ext.errors.rubicon'); if (Array.isArray(responseErrors) && responseErrors.length > 0) { - logWarn('Rubicon: Error in video response'); + utils.logWarn('Rubicon: Error in video response'); } const bids = []; responseObj.seatbid.forEach(seatbid => { @@ -620,8 +610,8 @@ export const spec = { bidderCode: seatbid.seat, ttl: 300, netRevenue: rubiConf.netRevenue !== false, // If anything other than false, netRev is true - width: bid.w || deepAccess(bidRequest, 'mediaTypes.video.w') || deepAccess(bidRequest, 'params.video.playerWidth'), - height: bid.h || deepAccess(bidRequest, 'mediaTypes.video.h') || deepAccess(bidRequest, 'params.video.playerHeight'), + width: bid.w || utils.deepAccess(bidRequest, 'mediaTypes.video.w') || utils.deepAccess(bidRequest, 'params.video.playerWidth'), + height: bid.h || utils.deepAccess(bidRequest, 'mediaTypes.video.h') || utils.deepAccess(bidRequest, 'params.video.playerHeight'), }; if (bid.id) { @@ -633,22 +623,22 @@ export const spec = { } if (bid.adomain) { - deepSetValue(bidObject, 'meta.advertiserDomains', Array.isArray(bid.adomain) ? bid.adomain : [bid.adomain]); + utils.deepSetValue(bidObject, 'meta.advertiserDomains', Array.isArray(bid.adomain) ? bid.adomain : [bid.adomain]); } - if (deepAccess(bid, 'ext.bidder.rp.advid')) { - deepSetValue(bidObject, 'meta.advertiserId', bid.ext.bidder.rp.advid); + if (utils.deepAccess(bid, 'ext.bidder.rp.advid')) { + utils.deepSetValue(bidObject, 'meta.advertiserId', bid.ext.bidder.rp.advid); } - let serverResponseTimeMs = deepAccess(responseObj, 'ext.responsetimemillis.rubicon'); + let serverResponseTimeMs = utils.deepAccess(responseObj, 'ext.responsetimemillis.rubicon'); if (bidRequest && serverResponseTimeMs) { bidRequest.serverResponseTimeMs = serverResponseTimeMs; } - if (deepAccess(bid, 'ext.prebid.type') === VIDEO) { + if (utils.deepAccess(bid, 'ext.prebid.type') === VIDEO) { bidObject.mediaType = VIDEO; - deepSetValue(bidObject, 'meta.mediaType', VIDEO); - const extPrebidTargeting = deepAccess(bid, 'ext.prebid.targeting'); + utils.deepSetValue(bidObject, 'meta.mediaType', VIDEO); + const extPrebidTargeting = utils.deepAccess(bid, 'ext.prebid.targeting'); // If ext.prebid.targeting exists, add it as a property value named 'adserverTargeting' if (extPrebidTargeting && typeof extPrebidTargeting === 'object') { @@ -670,12 +660,12 @@ export const spec = { if (bid.nurl) { bidObject.vastUrl = bid.nurl; } if (!bidObject.vastUrl && bid.nurl) { bidObject.vastUrl = bid.nurl; } - const videoContext = deepAccess(bidRequest, 'mediaTypes.video.context'); + const videoContext = utils.deepAccess(bidRequest, 'mediaTypes.video.context'); if (videoContext.toLowerCase() === 'outstream') { bidObject.renderer = outstreamRenderer(bidObject); } } else { - logWarn('Rubicon: video response received non-video media type'); + utils.logWarn('Rubicon: video response received non-video media type'); } bids.push(bidObject); @@ -754,7 +744,7 @@ export const spec = { bids.push(bid); } else { - logError(`Rubicon: bidRequest undefined at index position:${i}`, bidRequest, responseObj); + utils.logError(`Rubicon: bidRequest undefined at index position:${i}`, bidRequest, responseObj); } return bids; @@ -765,23 +755,21 @@ export const spec = { getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { if (!hasSynced && syncOptions.iframeEnabled) { // data is only assigned if params are available to pass to syncEndpoint - let params = {}; + let params = ''; - if (gdprConsent) { + if (gdprConsent && typeof gdprConsent.consentString === 'string') { + // add 'gdpr' only if 'gdprApplies' is defined if (typeof gdprConsent.gdprApplies === 'boolean') { - params['gdpr'] = Number(gdprConsent.gdprApplies); - } - if (typeof gdprConsent.consentString === 'string') { - params['gdpr_consent'] = gdprConsent.consentString; + params += `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + params += `?gdpr_consent=${gdprConsent.consentString}`; } } if (uspConsent) { - params['us_privacy'] = encodeURIComponent(uspConsent); + params += `${params ? '&' : '?'}us_privacy=${encodeURIComponent(uspConsent)}`; } - params = Object.keys(params).length ? `?${formatQS(params)}` : ''; - hasSynced = true; return { type: 'iframe', @@ -796,7 +784,7 @@ export const spec = { * @return {Object} params bid params */ transformBidParams: function(params, isOpenRtb) { - return convertTypes({ + return utils.convertTypes({ 'accountId': 'number', 'siteId': 'number', 'zoneId': 'number' @@ -887,7 +875,7 @@ function outstreamRenderer(rtbBid) { try { renderer.setRender(renderBid); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; @@ -902,7 +890,7 @@ function parseSizes(bid, mediaType) { params.video.playerWidth, params.video.playerHeight ]; - } else if (Array.isArray(deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { + } else if (Array.isArray(utils.deepAccess(bid, 'mediaTypes.video.playerSize')) && bid.mediaTypes.video.playerSize.length === 1) { size = bid.mediaTypes.video.playerSize[0]; } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0 && Array.isArray(bid.sizes[0]) && bid.sizes[0].length > 1) { size = bid.sizes[0]; @@ -914,12 +902,12 @@ function parseSizes(bid, mediaType) { let sizes = []; if (Array.isArray(params.sizes)) { sizes = params.sizes; - } else if (typeof deepAccess(bid, 'mediaTypes.banner.sizes') !== 'undefined') { + } else if (typeof utils.deepAccess(bid, 'mediaTypes.banner.sizes') !== 'undefined') { sizes = mapSizes(bid.mediaTypes.banner.sizes); } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { sizes = mapSizes(bid.sizes) } else { - logWarn('Rubicon: no sizes are setup or found'); + utils.logWarn('Rubicon: no sizes are setup or found'); } return masSizeOrdering(sizes); @@ -948,11 +936,7 @@ function appendSiteAppDevice(data, bidRequest, bidderRequest) { if (bidRequest.params.video.language) { ['site', 'device'].forEach(function(param) { if (data[param]) { - if (param === 'site') { - data[param].content = Object.assign({language: bidRequest.params.video.language}, data[param].content) - } else { - data[param] = Object.assign({language: bidRequest.params.video.language}, data[param]) - } + data[param].content = Object.assign({language: bidRequest.params.video.language}, data[param].content) } }); } @@ -990,18 +974,16 @@ function applyFPD(bidRequest, mediaType, data) { site: {ext: {data: {...bidRequest.params.inventory}}} }; - if (bidRequest.params.keywords) BID_FPD.site.keywords = (isArray(bidRequest.params.keywords)) ? bidRequest.params.keywords.join(',') : bidRequest.params.keywords; - - let fpd = mergeDeep({}, config.getConfig('ortb2') || {}, BID_FPD); - let impData = deepAccess(bidRequest.ortb2Imp, 'ext.data') || {}; + if (bidRequest.params.keywords) BID_FPD.site.keywords = (utils.isArray(bidRequest.params.keywords)) ? bidRequest.params.keywords.join(',') : bidRequest.params.keywords; - const gpid = deepAccess(bidRequest, 'ortb2Imp.ext.gpid'); + let fpd = utils.mergeDeep({}, config.getConfig('ortb2') || {}, BID_FPD); + let impData = utils.deepAccess(bidRequest.ortb2Imp, 'ext.data') || {}; const SEGTAX = {user: [4], site: [1, 2, 5, 6]}; const MAP = {user: 'tg_v.', site: 'tg_i.', adserver: 'tg_i.dfp_ad_unit_code', pbadslot: 'tg_i.pbadslot', keywords: 'kw'}; const validate = function(prop, key, parentName) { if (key === 'data' && Array.isArray(prop)) { - return prop.filter(name => name.segment && deepAccess(name, 'ext.segtax') && SEGTAX[parentName] && - SEGTAX[parentName].indexOf(deepAccess(name, 'ext.segtax')) !== -1).map(value => { + return prop.filter(name => name.segment && utils.deepAccess(name, 'ext.segtax') && SEGTAX[parentName] && + SEGTAX[parentName].indexOf(utils.deepAccess(name, 'ext.segtax')) !== -1).map(value => { let segments = value.segment.filter(obj => obj.id).reduce((result, obj) => { result.push(obj.id); return result; @@ -1009,12 +991,12 @@ function applyFPD(bidRequest, mediaType, data) { if (segments.length > 0) return segments.toString(); }).toString(); } else if (typeof prop === 'object' && !Array.isArray(prop)) { - logWarn('Rubicon: Filtered FPD key: ', key, ': Expected value to be string, integer, or an array of strings/ints'); + utils.logWarn('Rubicon: Filtered FPD key: ', key, ': Expected value to be string, integer, or an array of strings/ints'); } else if (typeof prop !== 'undefined') { return (Array.isArray(prop)) ? prop.filter(value => { if (typeof value !== 'object' && typeof value !== 'undefined') return value.toString(); - logWarn('Rubicon: Filtered value: ', value, 'for key', key, ': Expected value to be string, integer, or an array of strings/ints'); + utils.logWarn('Rubicon: Filtered value: ', value, 'for key', key, ': Expected value to be string, integer, or an array of strings/ints'); }).toString() : prop.toString(); } }; @@ -1024,6 +1006,16 @@ function applyFPD(bidRequest, mediaType, data) { data[loc] = (data[loc]) ? data[loc].concat(',', val) : val; } + Object.keys(impData).forEach((key) => { + if (key === 'adserver') { + ['name', 'adslot'].forEach(prop => { + if (impData[key][prop]) impData[key][prop] = impData[key][prop].toString().replace(/^\/+/, ''); + }); + } else if (key === 'pbadslot') { + impData[key] = impData[key].toString().replace(/^\/+/, ''); + } + }); + if (mediaType === BANNER) { ['site', 'user'].forEach(name => { Object.keys(fpd[name]).forEach((key) => { @@ -1039,32 +1031,14 @@ function applyFPD(bidRequest, mediaType, data) { }); }); Object.keys(impData).forEach((key) => { - if (key !== 'adserver') { - addBannerData(impData[key], 'site', key); - } else if (impData[key].name === 'gam') { - addBannerData(impData[key].adslot, name, key) - } + (key === 'adserver') ? addBannerData(impData[key].adslot, name, key) : addBannerData(impData[key], 'site', key); }); - - // add in gpid - if (gpid) { - data['p_gpid'] = gpid; - } - - // only send one of pbadslot or dfp adunit code (prefer pbadslot) - if (data['tg_i.pbadslot']) { - delete data['tg_i.dfp_ad_unit_code']; - } } else { if (Object.keys(impData).length) { - mergeDeep(data.imp[0].ext, {data: impData}); - } - // add in gpid - if (gpid) { - data.imp[0].ext.gpid = gpid; + utils.mergeDeep(data.imp[0].ext, {data: impData}); } - mergeDeep(data, fpd); + utils.mergeDeep(data, fpd); } } @@ -1073,7 +1047,7 @@ function applyFPD(bidRequest, mediaType, data) { * @returns {*} */ function mapSizes(sizes) { - return parseSizesInput(sizes) + return utils.parseSizesInput(sizes) // map sizes while excluding non-matches .reduce((result, size) => { let mappedSize = parseInt(sizeMap[size], 10); @@ -1091,10 +1065,10 @@ function mapSizes(sizes) { * @returns {boolean} */ export function hasVideoMediaType(bidRequest) { - if (typeof deepAccess(bidRequest, 'params.video') !== 'object') { + if (typeof utils.deepAccess(bidRequest, 'params.video') !== 'object') { return false; } - return (typeof deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined'); + return (typeof utils.deepAccess(bidRequest, `mediaTypes.${VIDEO}`) !== 'undefined'); } /** @@ -1108,9 +1082,9 @@ function bidType(bid, log = false) { if (hasVideoMediaType(bid)) { // Removed legacy mediaType support. new way using mediaTypes.video object is now required // We require either context as instream or outstream - if (['outstream', 'instream'].indexOf(deepAccess(bid, `mediaTypes.${VIDEO}.context`)) === -1) { + if (['outstream', 'instream'].indexOf(utils.deepAccess(bid, `mediaTypes.${VIDEO}.context`)) === -1) { if (log) { - logError('Rubicon: mediaTypes.video.context must be outstream or instream'); + utils.logError('Rubicon: mediaTypes.video.context must be outstream or instream'); } return; } @@ -1118,13 +1092,13 @@ function bidType(bid, log = false) { // we require playerWidth and playerHeight to come from one of params.playerWidth/playerHeight or mediaTypes.video.playerSize or adUnit.sizes if (parseSizes(bid, 'video').length < 2) { if (log) { - logError('Rubicon: could not determine the playerSize of the video'); + utils.logError('Rubicon: could not determine the playerSize of the video'); } return; } if (log) { - logMessage('Rubicon: making video request for adUnit', bid.adUnitCode); + utils.logMessage('Rubicon: making video request for adUnit', bid.adUnitCode); } return 'video'; } else { @@ -1132,14 +1106,14 @@ function bidType(bid, log = false) { // if we cannot determine them, we reject it! if (parseSizes(bid, 'banner').length === 0) { if (log) { - logError('Rubicon: could not determine the sizes for banner request'); + utils.logError('Rubicon: could not determine the sizes for banner request'); } return; } // everything looks good for banner so lets do it if (log) { - logMessage('Rubicon: making banner request for adUnit', bid.adUnitCode); + utils.logMessage('Rubicon: making banner request for adUnit', bid.adUnitCode); } return 'banner'; } @@ -1171,13 +1145,13 @@ export function masSizeOrdering(sizes) { export function determineRubiconVideoSizeId(bid) { // If we have size_id in the bid then use it - let rubiconSizeId = parseInt(deepAccess(bid, 'params.video.size_id')); + let rubiconSizeId = parseInt(utils.deepAccess(bid, 'params.video.size_id')); if (!isNaN(rubiconSizeId)) { return rubiconSizeId; } // otherwise 203 for outstream and 201 for instream // When this function is used we know it has to be one of outstream or instream - return deepAccess(bid, `mediaTypes.${VIDEO}.context`) === 'outstream' ? 203 : 201; + return utils.deepAccess(bid, `mediaTypes.${VIDEO}.context`) === 'outstream' ? 203 : 201; } /** @@ -1220,9 +1194,9 @@ export function hasValidVideoParams(bid) { } // loop through each param and verify it has the correct Object.keys(requiredParams).forEach(function(param) { - if (Object.prototype.toString.call(deepAccess(bid, 'mediaTypes.video.' + param)) !== requiredParams[param]) { + if (Object.prototype.toString.call(utils.deepAccess(bid, 'mediaTypes.video.' + param)) !== requiredParams[param]) { isValid = false; - logError('Rubicon: mediaTypes.video.' + param + ' is required and must be of type: ' + requiredParams[param]); + utils.logError('Rubicon: mediaTypes.video.' + param + ' is required and must be of type: ' + requiredParams[param]); } }) return isValid; @@ -1241,7 +1215,7 @@ export function hasValidSupplyChainParams(schain) { if (!status) return status; return requiredFields.every(field => node.hasOwnProperty(field)); }, true); - if (!isValid) logError('Rubicon: required schain params missing'); + if (!isValid) utils.logError('Rubicon: required schain params missing'); return isValid; } diff --git a/modules/saambaaBidAdapter.js b/modules/saambaaBidAdapter.js deleted file mode 100644 index 2810853532d..00000000000 --- a/modules/saambaaBidAdapter.js +++ /dev/null @@ -1,420 +0,0 @@ -import { deepAccess, isFn, generateUUID, parseUrl, isEmpty, parseSizesInput } from '../src/utils.js'; -import { config } from '../src/config.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { VIDEO, BANNER } from '../src/mediaTypes.js'; -import find from 'core-js-pure/features/array/find.js'; -import includes from 'core-js-pure/features/array/includes.js'; - -const ADAPTER_VERSION = '1.0'; -const BIDDER_CODE = 'saambaa'; - -export const VIDEO_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid='; -export const BANNER_ENDPOINT = 'https://nep.advangelists.com/xp/get?pubid='; -export const OUTSTREAM_SRC = 'https://player-cdn.beachfrontmedia.com/playerapi/loader/outstream.js'; -export const VIDEO_TARGETING = ['mimes', 'playbackmethod', 'maxduration', 'skip', 'playerSize', 'context']; -export const DEFAULT_MIMES = ['video/mp4', 'application/javascript']; - -let pubid = ''; - -export const spec = { - code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], - - isBidRequestValid(bidRequest) { - if (typeof bidRequest != 'undefined') { - if (bidRequest.bidder !== BIDDER_CODE && typeof bidRequest.params === 'undefined') { return false; } - if (bidRequest === '' || bidRequest.params.placement === '' || bidRequest.params.pubid === '') { return false; } - return true; - } else { return false; } - }, - - buildRequests(bids, bidderRequest) { - let requests = []; - let videoBids = bids.filter(bid => isVideoBidValid(bid)); - let bannerBids = bids.filter(bid => isBannerBidValid(bid)); - videoBids.forEach(bid => { - pubid = getVideoBidParam(bid, 'pubid'); - requests.push({ - method: 'POST', - url: VIDEO_ENDPOINT + pubid, - data: createVideoRequestData(bid, bidderRequest), - bidRequest: bid - }); - }); - - bannerBids.forEach(bid => { - pubid = getBannerBidParam(bid, 'pubid'); - - requests.push({ - method: 'POST', - url: BANNER_ENDPOINT + pubid, - data: createBannerRequestData(bid, bidderRequest), - bidRequest: bid - }); - }); - return requests; - }, - - interpretResponse(serverResponse, {bidRequest}) { - let response = serverResponse.body; - if (response !== null && isEmpty(response) == false) { - if (isVideoBid(bidRequest)) { - let bidResponse = { - requestId: response.id, - bidderCode: BIDDER_CODE, - cpm: response.seatbid[0].bid[0].price, - width: response.seatbid[0].bid[0].w, - height: response.seatbid[0].bid[0].h, - ttl: response.seatbid[0].bid[0].ttl || 60, - creativeId: response.seatbid[0].bid[0].crid, - currency: response.cur, - meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain }, - mediaType: VIDEO, - netRevenue: true - } - - if (response.seatbid[0].bid[0].adm) { - bidResponse.vastXml = response.seatbid[0].bid[0].adm; - bidResponse.adResponse = { - content: response.seatbid[0].bid[0].adm - }; - } else { - bidResponse.vastUrl = response.seatbid[0].bid[0].nurl; - } - - return bidResponse; - } else { - return { - requestId: response.id, - bidderCode: BIDDER_CODE, - cpm: response.seatbid[0].bid[0].price, - width: response.seatbid[0].bid[0].w, - height: response.seatbid[0].bid[0].h, - ad: response.seatbid[0].bid[0].adm, - ttl: response.seatbid[0].bid[0].ttl || 60, - creativeId: response.seatbid[0].bid[0].crid, - currency: response.cur, - meta: { 'advertiserDomains': response.seatbid[0].bid[0].adomain }, - mediaType: BANNER, - netRevenue: true - } - } - } - } -}; - -function isBannerBid(bid) { - return deepAccess(bid, 'mediaTypes.banner') || !isVideoBid(bid); -} - -function isVideoBid(bid) { - return deepAccess(bid, 'mediaTypes.video'); -} - -function getBannerBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {}; - return floorInfo.floor || getBannerBidParam(bid, 'bidfloor'); -} - -function getVideoBidFloor(bid) { - let floorInfo = isFn(bid.getFloor) ? bid.getFloor({ currency: 'USD', mediaType: 'video', size: '*' }) : {}; - return floorInfo.floor || getVideoBidParam(bid, 'bidfloor'); -} - -function isVideoBidValid(bid) { - return isVideoBid(bid) && getVideoBidParam(bid, 'pubid') && getVideoBidParam(bid, 'placement'); -} - -function isBannerBidValid(bid) { - return isBannerBid(bid) && getBannerBidParam(bid, 'pubid') && getBannerBidParam(bid, 'placement'); -} - -function getVideoBidParam(bid, key) { - return deepAccess(bid, 'params.video.' + key) || deepAccess(bid, 'params.' + key); -} - -function getBannerBidParam(bid, key) { - return deepAccess(bid, 'params.banner.' + key) || deepAccess(bid, 'params.' + key); -} - -function isMobile() { - return (/(ios|ipod|ipad|iphone|android)/i).test(navigator.userAgent); -} - -function isConnectedTV() { - return (/(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i).test(navigator.userAgent); -} - -function getDoNotTrack() { - return navigator.doNotTrack === '1' || window.doNotTrack === '1' || navigator.msDoNoTrack === '1' || navigator.doNotTrack === 'yes'; -} - -function findAndFillParam(o, key, value) { - try { - if (typeof value === 'function') { - o[key] = value(); - } else { - o[key] = value; - } - } catch (ex) {} -} - -function getOsVersion() { - let clientStrings = [ - { s: 'Android', r: /Android/ }, - { s: 'iOS', r: /(iPhone|iPad|iPod)/ }, - { s: 'Mac OS X', r: /Mac OS X/ }, - { s: 'Mac OS', r: /(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ }, - { s: 'Linux', r: /(Linux|X11)/ }, - { s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ }, - { s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ }, - { s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ }, - { s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ }, - { s: 'Windows Vista', r: /Windows NT 6.0/ }, - { s: 'Windows Server 2003', r: /Windows NT 5.2/ }, - { s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ }, - { s: 'UNIX', r: /UNIX/ }, - { s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ } - ]; - let cs = find(clientStrings, cs => cs.r.test(navigator.userAgent)); - return cs ? cs.s : 'unknown'; -} - -function getFirstSize(sizes) { - return (sizes && sizes.length) ? sizes[0] : { w: undefined, h: undefined }; -} - -function parseSizes(sizes) { - return parseSizesInput(sizes).map(size => { - let [ width, height ] = size.split('x'); - return { - w: parseInt(width, 10) || undefined, - h: parseInt(height, 10) || undefined - }; - }); -} - -function getVideoSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.video.playerSize') || bid.sizes); -} - -function getBannerSizes(bid) { - return parseSizes(deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes); -} - -function getTopWindowReferrer() { - try { - return window.top.document.referrer; - } catch (e) { - return ''; - } -} - -function getVideoTargetingParams(bid) { - const result = {}; - const excludeProps = ['playerSize', 'context', 'w', 'h']; - Object.keys(Object(bid.mediaTypes.video)) - .filter(key => !includes(excludeProps, key)) - .forEach(key => { - result[ key ] = bid.mediaTypes.video[ key ]; - }); - Object.keys(Object(bid.params.video)) - .filter(key => includes(VIDEO_TARGETING, key)) - .forEach(key => { - result[ key ] = bid.params.video[ key ]; - }); - return result; -} - -function createVideoRequestData(bid, bidderRequest) { - let topLocation = getTopWindowLocation(bidderRequest); - let topReferrer = getTopWindowReferrer(); - - // if size is explicitly given via adapter params - let paramSize = getVideoBidParam(bid, 'size'); - let sizes = []; - let coppa = config.getConfig('coppa'); - - if (typeof paramSize !== 'undefined' && paramSize != '') { - sizes = parseSizes(paramSize); - } else { - sizes = getVideoSizes(bid); - } - const firstSize = getFirstSize(sizes); - let floor = (getVideoBidFloor(bid) == null || typeof getVideoBidFloor(bid) == 'undefined') ? 0.5 : getVideoBidFloor(bid); - let video = getVideoTargetingParams(bid); - const o = { - 'device': { - 'langauge': (global.navigator.language).split('-')[0], - 'dnt': (global.navigator.doNotTrack === 1 ? 1 : 0), - 'devicetype': isMobile() ? 4 : isConnectedTV() ? 3 : 2, - 'js': 1, - 'os': getOsVersion() - }, - 'at': 2, - 'site': {}, - 'tmax': 3000, - 'cur': ['USD'], - 'id': bid.bidId, - 'imp': [], - 'regs': { - 'ext': { - } - }, - 'user': { - 'ext': { - } - } - }; - - o.site['page'] = topLocation.href; - o.site['domain'] = topLocation.hostname; - o.site['search'] = topLocation.search; - o.site['domain'] = topLocation.hostname; - o.site['ref'] = topReferrer; - o.site['mobile'] = isMobile() ? 1 : 0; - const secure = topLocation.protocol.indexOf('https') === 0 ? 1 : 0; - - o.device['dnt'] = getDoNotTrack() ? 1 : 0; - - findAndFillParam(o.site, 'name', function() { - return global.top.document.title; - }); - - findAndFillParam(o.device, 'h', function() { - return global.screen.height; - }); - findAndFillParam(o.device, 'w', function() { - return global.screen.width; - }); - - let placement = getVideoBidParam(bid, 'placement'); - - for (let j = 0; j < sizes.length; j++) { - o.imp.push({ - 'id': '' + j, - 'displaymanager': '' + BIDDER_CODE, - 'displaymanagerver': '' + ADAPTER_VERSION, - 'tagId': placement, - 'bidfloor': floor, - 'bidfloorcur': 'USD', - 'secure': secure, - 'video': Object.assign({ - 'id': generateUUID(), - 'pos': 0, - 'w': firstSize.w, - 'h': firstSize.h, - 'mimes': DEFAULT_MIMES - }, video) - - }); - } - if (coppa) { - o.regs.ext = {'coppa': 1}; - } - if (bidderRequest && bidderRequest.gdprConsent) { - let { gdprApplies, consentString } = bidderRequest.gdprConsent; - o.regs.ext = {'gdpr': gdprApplies ? 1 : 0}; - o.user.ext = {'consent': consentString}; - } - - return o; -} - -function getTopWindowLocation(bidderRequest) { - let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); -} - -function createBannerRequestData(bid, bidderRequest) { - let topLocation = getTopWindowLocation(bidderRequest); - let topReferrer = getTopWindowReferrer(); - - // if size is explicitly given via adapter params - - let paramSize = getBannerBidParam(bid, 'size'); - let sizes = []; - let coppa = config.getConfig('coppa'); - if (typeof paramSize !== 'undefined' && paramSize != '') { - sizes = parseSizes(paramSize); - } else { - sizes = getBannerSizes(bid); - } - - let floor = (getBannerBidFloor(bid) == null || typeof getBannerBidFloor(bid) == 'undefined') ? 0.1 : getBannerBidFloor(bid); - const o = { - 'device': { - 'langauge': (global.navigator.language).split('-')[0], - 'dnt': (global.navigator.doNotTrack === 1 ? 1 : 0), - 'devicetype': isMobile() ? 4 : isConnectedTV() ? 3 : 2, - 'js': 1 - }, - 'at': 2, - 'site': {}, - 'tmax': 3000, - 'cur': ['USD'], - 'id': bid.bidId, - 'imp': [], - 'regs': { - 'ext': { - } - }, - 'user': { - 'ext': { - } - } - }; - - o.site['page'] = topLocation.href; - o.site['domain'] = topLocation.hostname; - o.site['search'] = topLocation.search; - o.site['domain'] = topLocation.hostname; - o.site['ref'] = topReferrer; - o.site['mobile'] = isMobile() ? 1 : 0; - const secure = topLocation.protocol.indexOf('https') === 0 ? 1 : 0; - - o.device['dnt'] = getDoNotTrack() ? 1 : 0; - - findAndFillParam(o.site, 'name', function() { - return global.top.document.title; - }); - - findAndFillParam(o.device, 'h', function() { - return global.screen.height; - }); - findAndFillParam(o.device, 'w', function() { - return global.screen.width; - }); - - let placement = getBannerBidParam(bid, 'placement'); - for (let j = 0; j < sizes.length; j++) { - let size = sizes[j]; - - o.imp.push({ - 'id': '' + j, - 'displaymanager': '' + BIDDER_CODE, - 'displaymanagerver': '' + ADAPTER_VERSION, - 'tagId': placement, - 'bidfloor': floor, - 'bidfloorcur': 'USD', - 'secure': secure, - 'banner': { - 'id': generateUUID(), - 'pos': 0, - 'w': size['w'], - 'h': size['h'] - } - }); - } - if (coppa) { - o.regs.ext = {'coppa': 1}; - } - if (bidderRequest && bidderRequest.gdprConsent) { - let { gdprApplies, consentString } = bidderRequest.gdprConsent; - o.regs.ext = {'gdpr': gdprApplies ? 1 : 0}; - o.user.ext = {'consent': consentString}; - } - - return o; -} -registerBidder(spec); diff --git a/modules/saambaaBidAdapter.md b/modules/saambaaBidAdapter.md index d58e3f0abfa..2d391da7628 100755 --- a/modules/saambaaBidAdapter.md +++ b/modules/saambaaBidAdapter.md @@ -1,66 +1,69 @@ -# Overview - -``` -Module Name: Saambaa Bidder Adapter -Module Type: Bidder Adapter -Maintainer: matt.voigt@saambaa.com -``` - -# Description - -Connects to Saambaa exchange for bids. - -Saambaa bid adapter supports Banner and Video ads currently. - -For more informatio - -# Sample Display Ad Unit: For Publishers -```javascript - -var displayAdUnit = [ -{ - code: 'display', - mediaTypes: { - banner: { - sizes: [[300, 250],[320, 50]] - } - } - bids: [{ - bidder: 'saambaa', - params: { - pubid: '121ab139faf7ac67428a23f1d0a9a71b', - placement: 1234, - size: '320x50' - } - }] -}]; -``` - -# Sample Video Ad Unit: For Publishers -```javascript - -var videoAdUnit = { - code: 'video', - sizes: [320,480], - mediaTypes: { - video: { - playerSize : [[320, 480]], - context: 'instream', - skip: 1, - mimes : ['video/mp4', 'application/javascript'], - playbackmethod : [2,6], - maxduration: 30 - } - }, - bids: [ - { - bidder: 'saambaa', - params: { - pubid: '121ab139faf7ac67428a23f1d0a9a71b', - placement: 1234, - size: "320x480" - } - } - ] - }; +# Overview + +``` +Module Name: Saambaa Bidder Adapter +Module Type: Bidder Adapter +Maintainer: matt.voigt@saambaa.com +``` + +# Description + +Connects to Saambaa exchange for bids. + +Saambaa bid adapter supports Banner and Video ads currently. + +For more informatio + +# Sample Display Ad Unit: For Publishers +```javascript + +var displayAdUnit = [ +{ + code: 'display', + mediaTypes: { + banner: { + sizes: [[300, 250],[320, 50]] + } + } + bids: [{ + bidder: 'saambaa', + params: { + pubid: '121ab139faf7ac67428a23f1d0a9a71b', + placement: 1234, + size: '320x50' + } + }] +}]; +``` + +# Sample Video Ad Unit: For Publishers +```javascript + +var videoAdUnit = { + code: 'video', + sizes: [320,480], + mediaTypes: { + video: { + playerSize : [[320, 480]], + context: 'instream' + } + }, + bids: [ + { + bidder: 'saambaa', + params: { + pubid: '121ab139faf7ac67428a23f1d0a9a71b', + placement: 1234, + size: "320x480", + video: { + id: 123, + skip: 1, + mimes : ['video/mp4', 'application/javascript'], + playbackmethod : [2,6], + maxduration: 30 + } + } + } + ] + }; ``` \ No newline at end of file diff --git a/modules/scaleableAnalyticsAdapter.js b/modules/scaleableAnalyticsAdapter.js index d7379462e0d..955a08c065a 100644 --- a/modules/scaleableAnalyticsAdapter.js +++ b/modules/scaleableAnalyticsAdapter.js @@ -4,7 +4,7 @@ import { ajax } from '../src/ajax.js'; import CONSTANTS from '../src/constants.json'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; -import { logMessage } from '../src/utils.js'; +import * as utils from '../src/utils.js'; // Object.entries polyfill const entries = Object.entries || function(obj) { @@ -62,7 +62,7 @@ scaleableAnalytics.enableAnalytics = config => { scaleableAnalytics.originEnableAnalytics(config); scaleableAnalytics.enableAnalytics = function _enable() { - return logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`); + return utils.logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`); }; } diff --git a/modules/seedingAllianceBidAdapter.js b/modules/seedingAllianceBidAdapter.js deleted file mode 100755 index b7aec0f8881..00000000000 --- a/modules/seedingAllianceBidAdapter.js +++ /dev/null @@ -1,231 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -'use strict'; - -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { NATIVE } from '../src/mediaTypes.js'; -import { _map, deepSetValue, isEmpty, deepAccess } from '../src/utils.js'; -import { config } from '../src/config.js'; - -const BIDDER_CODE = 'seedingAlliance'; -const DEFAULT_CUR = 'EUR'; -const ENDPOINT_URL = 'https://b.nativendo.de/cds/rtb/bid?format=openrtb2.5&ssp=nativendo'; - -const NATIVE_ASSET_IDS = {0: 'title', 1: 'body', 2: 'sponsoredBy', 3: 'image', 4: 'cta', 5: 'icon'}; - -const NATIVE_PARAMS = { - title: { - id: 0, - name: 'title' - }, - - body: { - id: 1, - name: 'data', - type: 2 - }, - - sponsoredBy: { - id: 2, - name: 'data', - type: 1 - }, - - image: { - id: 3, - type: 3, - name: 'img' - }, - - cta: { - id: 4, - type: 12, - name: 'data' - }, - - icon: { - id: 5, - type: 1, - name: 'img' - } -}; - -export const spec = { - code: BIDDER_CODE, - - supportedMediaTypes: [NATIVE], - - isBidRequestValid: function(bid) { - return !!bid.params.adUnitId; - }, - - buildRequests: (validBidRequests, bidderRequest) => { - const pt = setOnAny(validBidRequests, 'params.pt') || setOnAny(validBidRequests, 'params.priceType') || 'net'; - const tid = validBidRequests[0].transactionId; - const cur = [config.getConfig('currency.adServerCurrency') || DEFAULT_CUR]; - let url = bidderRequest.refererInfo.referer; - - const imp = validBidRequests.map((bid, id) => { - const assets = _map(bid.nativeParams, (bidParams, key) => { - const props = NATIVE_PARAMS[key]; - - const asset = { - required: bidParams.required & 1 - }; - - if (props) { - asset.id = props.id; - - let w, h; - - if (bidParams.sizes) { - w = bidParams.sizes[0]; - h = bidParams.sizes[1]; - } - - asset[props.name] = { - len: bidParams.len, - type: props.type, - w, - h - }; - - return asset; - } - }) - .filter(Boolean); - - if (bid.params.url) { - url = bid.params.url; - } - - return { - id: String(id + 1), - tagid: bid.params.adUnitId, - tid: tid, - pt: pt, - native: { - request: { - assets - } - } - }; - }); - - const request = { - id: bidderRequest.auctionId, - site: { - page: url - }, - device: { - ua: navigator.userAgent - }, - cur, - imp, - user: {}, - regs: { - ext: { - gdpr: 0 - } - } - }; - - if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(request, 'regs.ext.gdpr', (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean' && bidderRequest.gdprConsent.gdprApplies) ? 1 : 0); - } - - return { - method: 'POST', - url: ENDPOINT_URL, - data: JSON.stringify(request), - options: { - contentType: 'application/json' - }, - bids: validBidRequests - }; - }, - - interpretResponse: function(serverResponse, { bids }) { - if (isEmpty(serverResponse.body)) { - return []; - } - - const { seatbid, cur } = serverResponse.body; - - const bidResponses = (typeof seatbid != 'undefined') ? flatten(seatbid.map(seat => seat.bid)).reduce((result, bid) => { - result[bid.impid - 1] = bid; - return result; - }, []) : []; - - return bids - .map((bid, id) => { - const bidResponse = bidResponses[id]; - - if (bidResponse) { - return { - requestId: bid.bidId, - cpm: bidResponse.price, - creativeId: bidResponse.crid, - ttl: 1000, - netRevenue: (!bid.netRevenue || bid.netRevenue === 'net'), - currency: cur, - mediaType: NATIVE, - bidderCode: BIDDER_CODE, - native: parseNative(bidResponse), - meta: { - advertiserDomains: bidResponse.adomain && bidResponse.adomain.length > 0 ? bidResponse.adomain : [] - } - }; - } - }) - .filter(Boolean); - } -}; - -registerBidder(spec); - -function parseNative(bid) { - const {assets, link, imptrackers} = bid.adm.native; - - if (link.clicktrackers) { - link.clicktrackers.forEach(function (clicktracker, index) { - link.clicktrackers[index] = clicktracker.replace(/\$\{AUCTION_PRICE\}/, bid.price); - }); - } - if (imptrackers) { - imptrackers.forEach(function (imptracker, index) { - imptrackers[index] = imptracker.replace(/\$\{AUCTION_PRICE\}/, bid.price); - }); - } - - const result = { - url: link.url, - clickUrl: link.url, - clickTrackers: link.clicktrackers || undefined, - impressionTrackers: imptrackers || undefined - }; - - assets.forEach(asset => { - const kind = NATIVE_ASSET_IDS[asset.id]; - const content = kind && asset[NATIVE_PARAMS[kind].name]; - - if (content) { - result[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h }; - } - }); - - return result; -} - -function setOnAny(collection, key) { - for (let i = 0, result; i < collection.length; i++) { - result = deepAccess(collection[i], key); - if (result) { - return result; - } - } -} - -function flatten(arr) { - return [].concat(...arr); -} diff --git a/modules/seedtagBidAdapter.js b/modules/seedtagBidAdapter.js index bae27d41028..8b7629df211 100644 --- a/modules/seedtagBidAdapter.js +++ b/modules/seedtagBidAdapter.js @@ -1,4 +1,4 @@ -import { isArray, _map, triggerPixel } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { VIDEO, BANNER } from '../src/mediaTypes.js' @@ -13,11 +13,6 @@ const ALLOWED_PLACEMENTS = { banner: true, video: true } - -// Global Vendor List Id -// https://iabeurope.eu/vendor-list-tcf-v2-0/ -const GVLID = 157; - const mediaTypesMap = { [BANNER]: 'display', [VIDEO]: 'video' @@ -67,13 +62,13 @@ function hasMandatoryVideoParams(bid) { const videoParams = getVideoParams(bid) return hasVideoMediaType(bid) && !!videoParams.playerSize && - isArray(videoParams.playerSize) && + utils.isArray(videoParams.playerSize) && videoParams.playerSize.length > 0; } function buildBidRequest(validBidRequest) { const params = validBidRequest.params; - const mediaTypes = _map( + const mediaTypes = utils._map( Object.keys(validBidRequest.mediaTypes), function (pbjsType) { return mediaTypesMap[pbjsType]; @@ -150,8 +145,8 @@ function buildBidResponse(seedtagBid) { export function getTimeoutUrl (data) { let queryParams = ''; if ( - isArray(data) && data[0] && - isArray(data[0].params) && data[0].params[0] + utils.isArray(data) && data[0] && + utils.isArray(data[0].params) && data[0].params[0] ) { const params = data[0].params[0]; queryParams = @@ -163,7 +158,6 @@ export function getTimeoutUrl (data) { export const spec = { code: BIDDER_CODE, - gvlid: GVLID, aliases: [SEEDTAG_ALIAS], supportedMediaTypes: [BANNER, VIDEO], /** @@ -192,7 +186,7 @@ export const spec = { timeout: bidderRequest.timeout, version: '$prebid.version$', connectionType: getConnectionType(), - bidRequests: _map(validBidRequests, buildBidRequest) + bidRequests: utils._map(validBidRequests, buildBidRequest) }; if (payload.cmp) { @@ -217,8 +211,8 @@ export const spec = { */ interpretResponse: function(serverResponse) { const serverBody = serverResponse.body; - if (serverBody && serverBody.bids && isArray(serverBody.bids)) { - return _map(serverBody.bids, function(bid) { + if (serverBody && serverBody.bids && utils.isArray(serverBody.bids)) { + return utils._map(serverBody.bids, function(bid) { return buildBidResponse(bid); }); } else { @@ -249,7 +243,7 @@ export const spec = { */ onTimeout(data) { const url = getTimeoutUrl(data); - triggerPixel(url); + utils.triggerPixel(url); }, /** @@ -258,7 +252,7 @@ export const spec = { */ onBidWon: function (bid) { if (bid && bid.nurl) { - triggerPixel(bid.nurl); + utils.triggerPixel(bid.nurl); } } } diff --git a/modules/sharedIdSystem.js b/modules/sharedIdSystem.js index 32a96100d43..2e3abd6b1a2 100644 --- a/modules/sharedIdSystem.js +++ b/modules/sharedIdSystem.js @@ -5,13 +5,13 @@ * @requires module:modules/userId */ -import { parseUrl, buildUrl, triggerPixel, logInfo, hasDeviceAccess, generateUUID } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {submodule} from '../src/hook.js'; import { coppaDataHandler } from '../src/adapterManager.js'; import {getStorageManager} from '../src/storageManager.js'; const GVLID = 887; -export const storage = getStorageManager(GVLID, 'pubCommonId'); +const storage = getStorageManager(GVLID, 'pubCommonId'); const COOKIE = 'cookie'; const LOCAL_STORAGE = 'html5'; const OPTOUT_NAME = '_pubcid_optout'; @@ -53,12 +53,12 @@ function queuePixelCallback(pixelUrl, id = '', callback) { } // Use pubcid as a cache buster - const urlInfo = parseUrl(pixelUrl); + const urlInfo = utils.parseUrl(pixelUrl); urlInfo.search.id = encodeURIComponent('pubcid:' + id); - const targetUrl = buildUrl(urlInfo); + const targetUrl = utils.buildUrl(urlInfo); return function () { - triggerPixel(targetUrl); + utils.triggerPixel(targetUrl); }; } @@ -89,10 +89,10 @@ export const sharedIdSystemSubmodule = { */ decode(value, config) { if (hasOptedOut()) { - logInfo('PubCommonId decode: Has opted-out'); + utils.logInfo('PubCommonId decode: Has opted-out'); return undefined; } - logInfo(' Decoded value PubCommonId ' + value); + utils.logInfo(' Decoded value PubCommonId ' + value); const idObj = {'pubcid': value}; return idObj; }, @@ -106,13 +106,13 @@ export const sharedIdSystemSubmodule = { */ getId: function (config = {}, consentData, storedId) { if (hasOptedOut()) { - logInfo('PubCommonId: Has opted-out'); + utils.logInfo('PubCommonId: Has opted-out'); return; } const coppa = coppaDataHandler.getCoppa(); if (coppa) { - logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); + utils.logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); return; } const {params: {create = true, pixelUrl} = {}} = config; @@ -126,7 +126,7 @@ export const sharedIdSystemSubmodule = { } catch (e) { } - if (!newId) newId = (create && hasDeviceAccess()) ? generateUUID() : undefined; + if (!newId) newId = (create && utils.hasDeviceAccess()) ? utils.generateUUID() : undefined; } const pixelCallback = queuePixelCallback(pixelUrl, newId); @@ -153,12 +153,12 @@ export const sharedIdSystemSubmodule = { */ extendId: function(config = {}, consentData, storedId) { if (hasOptedOut()) { - logInfo('PubCommonId: Has opted-out'); + utils.logInfo('PubCommonId: Has opted-out'); return {id: undefined}; } const coppa = coppaDataHandler.getCoppa(); if (coppa) { - logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); + utils.logInfo('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); return; } const {params: {extend = false, pixelUrl} = {}} = config; @@ -171,33 +171,7 @@ export const sharedIdSystemSubmodule = { return {id: storedId}; } } - }, - - domainOverride: function () { - const domainElements = document.domain.split('.'); - const cookieName = `_gd${Date.now()}`; - for (let i = 0, topDomain, testCookie; i < domainElements.length; i++) { - const nextDomain = domainElements.slice(i).join('.'); - - // write test cookie - storage.setCookie(cookieName, '1', undefined, undefined, nextDomain); - - // read test cookie to verify domain was valid - testCookie = storage.getCookie(cookieName); - - // delete test cookie - storage.setCookie(cookieName, '', 'Thu, 01 Jan 1970 00:00:01 GMT', undefined, nextDomain); - - if (testCookie === '1') { - // cookie was written successfully using test domain so the topDomain is updated - topDomain = nextDomain; - } else { - // cookie failed to write using test domain so exit by returning the topDomain - return topDomain; - } - } } - }; submodule('userId', sharedIdSystemSubmodule); diff --git a/modules/sharethroughAnalyticsAdapter.js b/modules/sharethroughAnalyticsAdapter.js index 4f065cbca23..5147b2a4275 100644 --- a/modules/sharethroughAnalyticsAdapter.js +++ b/modules/sharethroughAnalyticsAdapter.js @@ -1,6 +1,6 @@ -import { tryAppendQueryString } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; +const utils = require('../src/utils.js'); const emptyUrl = ''; const analyticsType = 'endpoint'; @@ -42,18 +42,18 @@ var sharethroughAdapter = Object.assign(adapter( fireLoseBeacon(winningBidderCode, winningCPM, arid, type) { let loseBeaconUrl = this.STR_BEACON_HOST; - loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerBidderCode', winningBidderCode); - loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'winnerCpm', winningCPM); - loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'arid', arid); - loseBeaconUrl = tryAppendQueryString(loseBeaconUrl, 'type', type); + loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'winnerBidderCode', winningBidderCode); + loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'winnerCpm', winningCPM); + loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'arid', arid); + loseBeaconUrl = utils.tryAppendQueryString(loseBeaconUrl, 'type', type); loseBeaconUrl = this.appendEnvFields(loseBeaconUrl); this.fireBeacon(loseBeaconUrl); }, appendEnvFields(url) { - url = tryAppendQueryString(url, 'hbVersion', '$prebid.version$'); - url = tryAppendQueryString(url, 'strVersion', STR_VERSION); - url = tryAppendQueryString(url, 'hbSource', 'prebid'); + url = utils.tryAppendQueryString(url, 'hbVersion', '$prebid.version$'); + url = utils.tryAppendQueryString(url, 'strVersion', STR_VERSION); + url = utils.tryAppendQueryString(url, 'hbSource', 'prebid'); return url; }, diff --git a/modules/sharethroughBidAdapter.js b/modules/sharethroughBidAdapter.js index 06cc81324cf..967d8194607 100644 --- a/modules/sharethroughBidAdapter.js +++ b/modules/sharethroughBidAdapter.js @@ -1,183 +1,123 @@ -import { deepAccess, generateUUID, inIframe } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import { createEidsArray } from './userId/eids.js'; -const VERSION = '4.1.0'; +const VERSION = '3.4.1'; const BIDDER_CODE = 'sharethrough'; -const SUPPLY_ID = 'WYu2BXv1'; - -const STR_ENDPOINT = `https://btlr.sharethrough.com/universal/v1?supply_id=${SUPPLY_ID}`; +const STR_ENDPOINT = 'https://btlr.sharethrough.com/WYu2BXv1/v1'; +const DEFAULT_SIZE = [1, 1]; // this allows stubbing of utility function that is used internally by the sharethrough adapter export const sharethroughInternal = { - getProtocol, + b64EncodeUnicode, + handleIframe, + isLockedInFrame, + getProtocol }; export const sharethroughAdapterSpec = { code: BIDDER_CODE, - supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: bid => !!bid.params.pkey && bid.bidder === BIDDER_CODE, buildRequests: (bidRequests, bidderRequest) => { - const timeout = config.getConfig('bidderTimeout'); - const firstPartyData = config.getConfig('ortb2') || {}; - - const nonHttp = sharethroughInternal.getProtocol().indexOf('http') < 0; - const secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1); - - const req = { - id: generateUUID(), - at: 1, - cur: ['USD'], - tmax: timeout, - site: { - domain: window.location.hostname, - page: window.location.href, - ref: deepAccess(bidderRequest, 'refererInfo.referer'), - ...firstPartyData.site, - }, - device: { - ua: navigator.userAgent, - language: navigator.language, - js: 1, - dnt: navigator.doNotTrack === '1' ? 1 : 0, - h: window.screen.height, - w: window.screen.width, - }, - regs: { - coppa: config.getConfig('coppa') === true ? 1 : 0, - ext: {}, - }, - source: { - ext: { - version: '$prebid.version$', - str: VERSION, - schain: bidRequests[0].schain, - }, - }, - bcat: bidRequests[0].params.bcat || [], - badv: bidRequests[0].params.badv || [], - test: 0, - }; - - req.user = nullish(firstPartyData.user, {}); - if (!req.user.ext) req.user.ext = {}; - req.user.ext.eids = userIdAsEids(bidRequests[0]); - - if (bidderRequest.gdprConsent) { - const gdprApplies = bidderRequest.gdprConsent.gdprApplies === true; - req.regs.ext.gdpr = gdprApplies ? 1 : 0; - if (gdprApplies) { - req.user.ext.consent = bidderRequest.gdprConsent.consentString; + return bidRequests.map(bidRequest => { + let query = { + placement_key: bidRequest.params.pkey, + bidId: bidRequest.bidId, + consent_required: false, + instant_play_capable: canAutoPlayHTML5Video(), + hbSource: 'prebid', + hbVersion: '$prebid.version$', + strVersion: VERSION, + }; + + const gpid = utils.deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot'); + if (gpid) { + query.gpid = gpid; } - } - if (bidderRequest.uspConsent) { - req.regs.ext.us_privacy = bidderRequest.uspConsent; - } + Object.assign(query, handleUniversalIds(bidRequest)); - const imps = bidRequests.map(bidReq => { - const impression = {}; + const nonHttp = sharethroughInternal.getProtocol().indexOf('http') < 0; + query.secure = nonHttp || (sharethroughInternal.getProtocol().indexOf('https') > -1); - const gpid = deepAccess(bidReq, 'ortb2Imp.ext.data.pbadslot'); - if (gpid) { - impression.ext = { gpid: gpid }; + if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) { + query.consent_string = bidderRequest.gdprConsent.consentString; } - const videoRequest = deepAccess(bidReq, 'mediaTypes.video'); - - if (videoRequest) { - // default playerSize, only change this if we know width and height are properly defined in the request - let [w, h] = [640, 360]; - if (videoRequest.playerSize && videoRequest.playerSize[0] && videoRequest.playerSize[1]) { - [w, h] = videoRequest.playerSize; - } - - impression.video = { - pos: nullish(videoRequest.pos, 0), - topframe: inIframe() ? 0 : 1, - skip: nullish(videoRequest.skip, 0), - linearity: nullish(videoRequest.linearity, 1), - minduration: nullish(videoRequest.minduration, 5), - maxduration: nullish(videoRequest.maxduration, 60), - playbackmethod: videoRequest.playbackmethod || [2], - api: getVideoApi(videoRequest), - mimes: videoRequest.mimes || ['video/mp4'], - protocols: getVideoProtocols(videoRequest), - w, - h, - startdelay: nullish(videoRequest.startdelay, 0), - skipmin: nullish(videoRequest.skipmin, 0), - skipafter: nullish(videoRequest.skipafter, 0), - placement: videoRequest.context === 'instream' ? 1 : +deepAccess(videoRequest, 'placement', 4), - }; - - if (videoRequest.delivery) impression.video.delivery = videoRequest.delivery; - if (videoRequest.companiontype) impression.video.companiontype = videoRequest.companiontype; - if (videoRequest.companionad) impression.video.companionad = videoRequest.companionad; - } else { - impression.banner = { - pos: deepAccess(bidReq, 'mediaTypes.banner.pos', 0), - topframe: inIframe() ? 0 : 1, - format: bidReq.sizes.map(size => ({ w: +size[0], h: +size[1] })), - }; + if (bidderRequest && bidderRequest.gdprConsent) { + query.consent_required = !!bidderRequest.gdprConsent.gdprApplies; } - return { - id: bidReq.bidId, - tagid: String(bidReq.params.pkey), - secure: secure ? 1 : 0, - bidfloor: getBidRequestFloor(bidReq), - ...impression, + if (bidderRequest && bidderRequest.uspConsent) { + query.us_privacy = bidderRequest.uspConsent + } + + if (config.getConfig('coppa') === true) { + query.coppa = true + } + + if (bidRequest.schain) { + query.schain = JSON.stringify(bidRequest.schain); + } + + const floor = getFloor(bidRequest); + if (floor) { + query.bidfloor = floor; + } + + if (bidRequest.params.badv) { + query.badv = bidRequest.params.badv; + } + + if (bidRequest.params.bcat) { + query.bcat = bidRequest.params.bcat; + } + + // Data that does not need to go to the server, + // but we need as part of interpretResponse() + const strData = { + skipIframeBusting: bidRequest.params.iframe, + iframeSize: bidRequest.params.iframeSize, + sizes: bidRequest.sizes }; - }).filter(imp => !!imp); - return imps.map(impression => { return { method: 'POST', url: STR_ENDPOINT, - data: { - ...req, - imp: [impression], - }, + data: query, + strData: strData }; - }); + }) }, interpretResponse: ({ body }, req) => { - if (!body || !body.seatbid || body.seatbid.length === 0 || !body.seatbid[0].bid || body.seatbid[0].bid.length === 0) { + if (!body || !body.creatives || !body.creatives.length) { return []; } - return body.seatbid[0].bid.map(bid => { - const response = { - requestId: bid.impid, - width: +bid.w, - height: +bid.h, - cpm: +bid.price, - creativeId: bid.crid, - dealId: bid.dealid || null, - mediaType: req.data.imp[0].video ? VIDEO : BANNER, - currency: body.cur || 'USD', - netRevenue: true, - ttl: 360, - ad: bid.adm, - nurl: bid.nurl, - meta: { - advertiserDomains: bid.adomain || [], - }, - }; - - if (response.mediaType === VIDEO) { - response.ttl = 3600; - response.vastXml = bid.adm; - } + const creative = body.creatives[0]; + let size = DEFAULT_SIZE; + if (req.strData.iframeSize || req.strData.sizes.length) { + size = req.strData.iframeSize + ? req.strData.iframeSize + : getLargestSize(req.strData.sizes); + } - return response; - }); + return [{ + requestId: req.data.bidId, + width: size[0], + height: size[1], + cpm: creative.cpm, + creativeId: creative.creative.creative_key, + dealId: creative.creative.deal_id, + currency: 'USD', + netRevenue: true, + ttl: 360, + meta: { advertiserDomains: creative.creative && creative.creative.adomain ? creative.creative.adomain : [] }, + ad: generateAd(body, req) + }]; }, getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => { @@ -198,73 +138,175 @@ export const sharethroughAdapterSpec = { }, // Empty implementation for prebid core to be able to find it - onTimeout: (data) => { - }, + onTimeout: (data) => {}, // Empty implementation for prebid core to be able to find it - onBidWon: (bid) => { - }, + onBidWon: (bid) => {}, // Empty implementation for prebid core to be able to find it - onSetTargeting: (bid) => { - }, + onSetTargeting: (bid) => {} }; -function getVideoApi({ api }) { - let defaultValue = [2]; - if (api && Array.isArray(api) && api.length > 0) { - return api; - } else { - return defaultValue; +function handleUniversalIds(bidRequest) { + if (!bidRequest.userId) return {}; + + const universalIds = {}; + + const ttd = utils.deepAccess(bidRequest, 'userId.tdid'); + if (ttd) universalIds.ttduid = ttd; + + const pubc = utils.deepAccess(bidRequest, 'userId.pubcid') || utils.deepAccess(bidRequest, 'crumbs.pubcid'); + if (pubc) universalIds.pubcid = pubc; + + const idl = utils.deepAccess(bidRequest, 'userId.idl_env'); + if (idl) universalIds.idluid = idl; + + const id5 = utils.deepAccess(bidRequest, 'userId.id5id.uid'); + if (id5) { + universalIds.id5uid = { id: id5 }; + const id5link = utils.deepAccess(bidRequest, 'userId.id5id.ext.linkType'); + if (id5link) universalIds.id5uid.linkType = id5link; } + + const lipb = utils.deepAccess(bidRequest, 'userId.lipb.lipbid'); + if (lipb) universalIds.liuid = lipb; + + return universalIds; } -function getVideoProtocols({ protocols }) { - let defaultValue = [2, 3, 5, 6, 7, 8]; - if (protocols && Array.isArray(protocols) && protocols.length > 0) { - return protocols; +function getLargestSize(sizes) { + function area(size) { + return size[0] * size[1]; + } + + return sizes.reduce((prev, current) => { + if (area(current) > area(prev)) { + return current + } else { + return prev + } + }); +} + +function generateAd(body, req) { + const strRespId = `str_response_${req.data.bidId}`; + + let adMarkup = ` +
+
+ + `; + + if (req.strData.skipIframeBusting) { + // Don't break out of iframe + adMarkup = adMarkup + ``; } else { - return defaultValue; + // Add logic to the markup that detects whether or not in top level document is accessible + // this logic will deploy sfp.js and/or iframe buster script(s) as appropriate + adMarkup = adMarkup + ` + + `; } + + return adMarkup; } -function getBidRequestFloor(bid) { - let floor = null; - if (typeof bid.getFloor === 'function') { - const floorInfo = bid.getFloor({ - currency: 'USD', - mediaType: bid.mediaTypes && bid.mediaTypes.video ? 'video' : 'banner', - size: bid.sizes.map(size => ({ w: size[0], h: size[1] })), - }); - if (typeof floorInfo === 'object' && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { - floor = parseFloat(floorInfo.floor); +function handleIframe () { + // only load iframe buster JS if we can access the top level document + // if we are 'locked in' to this frame then no point trying to bust out: we may as well render in the frame instead + var iframeBusterLoaded = false; + if (!window.lockedInFrame) { + var sfpIframeBusterJs = document.createElement('script'); + sfpIframeBusterJs.src = 'https://native.sharethrough.com/assets/sfp-set-targeting.js'; + sfpIframeBusterJs.type = 'text/javascript'; + try { + window.document.getElementsByTagName('body')[0].appendChild(sfpIframeBusterJs); + iframeBusterLoaded = true; + } catch (e) { + utils.logError('Trouble writing frame buster script, error details:', e); } } - return floor !== null ? floor : bid.params.floor; -} -function userIdAsEids(bidRequest) { - const eids = createEidsArray(deepAccess(bidRequest, 'userId')) || []; + var clientJsLoaded = (!iframeBusterLoaded) ? !!(window.STR && window.STR.Tag) : !!(window.top.STR && window.top.STR.Tag); + if (!clientJsLoaded) { + var sfpJs = document.createElement('script'); + sfpJs.src = 'https://native.sharethrough.com/assets/sfp.js'; + sfpJs.type = 'text/javascript'; - const flocData = deepAccess(bidRequest, 'userId.flocId'); - const isFlocIdValid = flocData && flocData.id && flocData.version; - if (isFlocIdValid) { - eids.push({ - source: 'chrome.com', - uids: [{ id: flocData.id, atype: 1, ext: { ver: flocData.version } }], - }); + // only add sfp js to window.top if iframe busting successfully loaded; otherwise, add to iframe + try { + if (iframeBusterLoaded) { + window.top.document.getElementsByTagName('body')[0].appendChild(sfpJs); + } else { + window.document.getElementsByTagName('body')[0].appendChild(sfpJs); + } + } catch (e) { + utils.logError('Trouble writing sfp script, error details:', e); + } } +} - return eids; +// determines if we are capable of busting out of the iframe we are in +// if we catch a DOMException when trying to access top-level document, it means we're stuck in the frame we're in +function isLockedInFrame () { + window.lockedInFrame = false; + try { + window.lockedInFrame = !window.top.document; + } catch (e) { + window.lockedInFrame = (e instanceof DOMException); + } +} + +// See https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_Unicode_Problem +function b64EncodeUnicode(str) { + return btoa( + encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, + function toSolidBytes(match, p1) { + return String.fromCharCode('0x' + p1); + })); +} + +function canAutoPlayHTML5Video() { + const userAgent = navigator.userAgent; + if (!userAgent) return false; + + const isAndroid = /Android/i.test(userAgent); + const isiOS = /iPhone|iPad|iPod/i.test(userAgent); + const chromeVersion = parseInt((/Chrome\/([0-9]+)/.exec(userAgent) || [0, 0])[1]); + const chromeiOSVersion = parseInt((/CriOS\/([0-9]+)/.exec(userAgent) || [0, 0])[1]); + const safariVersion = parseInt((/Version\/([0-9]+)/.exec(userAgent) || [0, 0])[1]); + + if ( + (isAndroid && chromeVersion >= 53) || + (isiOS && (safariVersion >= 10 || chromeiOSVersion >= 53)) || + !(isAndroid || isiOS) + ) { + return true; + } else { + return false; + } } function getProtocol() { - return window.location.protocol; + return document.location.protocol; } -// stub for ?? operator -function nullish(input, def) { - return input === null || input === undefined ? def : input; +function getFloor(bid) { + if (utils.isFn(bid.getFloor)) { + const floorInfo = bid.getFloor({ + currency: 'USD', + mediaType: 'banner', + size: bid.sizes.map(size => ({ w: size[0], h: size[1] })) + }); + if (utils.isPlainObject(floorInfo) && !isNaN(floorInfo.floor) && floorInfo.currency === 'USD') { + return parseFloat(floorInfo.floor); + } + } + return null; } registerBidder(sharethroughAdapterSpec); diff --git a/modules/sharethroughBidAdapter.md b/modules/sharethroughBidAdapter.md index 218ef353d4e..396b8164577 100644 --- a/modules/sharethroughBidAdapter.md +++ b/modules/sharethroughBidAdapter.md @@ -23,74 +23,22 @@ Module that connects to Sharethrough's demand sources // REQUIRED - The placement key pkey: 'LuB3vxGGFrBZJa6tifXW4xgK', + // OPTIONAL - Render Sharethrough creative in an iframe, defaults to false + iframe: true, + + // OPTIONAL - If iframeSize is provided, we'll use this size for the iframe + // otherwise we'll grab the largest size from the sizes array + // This is ignored if iframe: false + iframeSize: [250, 250], + // OPTIONAL - Blocked Advertiser Domains badv: ['domain1.com', 'domain2.com'], // OPTIONAL - Blocked Categories (IAB codes) bcat: ['IAB1-1', 'IAB1-2'], - - // OPTIONAL - default bid floor, if not specified in bid request (USD) - floor: 0.1, } } ] } ]; ``` - -# Sample Instream Video Ad Unit: For Publishers -``` -var adVideoAdUnits = [ -{ - code: 'test-div-video', - mediaTypes: { - video: { - // CANNOT be 'outstream' - context: 'instream', - placement: 1, - delivery: 1, - companiontype: 'companion type', - companionad: 'companion ad', - // default values shown below this point - pos: 0, - skip: 0, - linearity: 1, - minduration: 5, - maxduration: 60, - playbackmethod: [2], - api: [2], - mimes: ['video/mp4'], - protocols: [2, 3, 5, 6, 7, 8], - playerSize: [640, 360], - startdelay: 0, - skipmin: 0, - skipafter: 0, - }, - }, - bids: [{ - bidder: 'sharethrough', - params: { - pkey: 'pkey1' - } - }] -}] -``` - -# Sample Banner Ad Unit: For Publishers -``` -var adUnits = [ -{ - code: 'test-div-video', - mediaTypes: { - banner: { - pos: 0, // default - }, - }, - bids: [{ - bidder: 'sharethrough', - params: { - pkey: 'pkey1' - } - }] -}] -``` diff --git a/modules/showheroes-bsBidAdapter.js b/modules/showheroes-bsBidAdapter.js index 4c8fb812edc..8d94a8e508b 100644 --- a/modules/showheroes-bsBidAdapter.js +++ b/modules/showheroes-bsBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, getBidIdParameter, getWindowTop, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -32,18 +32,18 @@ export const spec = { let adUnits = []; const pageURL = validBidRequests[0].params.contentPageUrl || bidderRequest.refererInfo.referer; const isStage = !!validBidRequests[0].params.stage; - const isOutstream = deepAccess(validBidRequests[0], 'mediaTypes.video.context') === 'outstream'; - const isCustomRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.customRender'); - const isNodeRender = deepAccess(validBidRequests[0], 'params.outstreamOptions.slot') || deepAccess(validBidRequests[0], 'params.outstreamOptions.iframe'); - const isNativeRender = deepAccess(validBidRequests[0], 'renderer'); - const outstreamOptions = deepAccess(validBidRequests[0], 'params.outstreamOptions'); + const isOutstream = utils.deepAccess(validBidRequests[0], 'mediaTypes.video.context') === 'outstream'; + const isCustomRender = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.customRender'); + const isNodeRender = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.slot') || utils.deepAccess(validBidRequests[0], 'params.outstreamOptions.iframe'); + const isNativeRender = utils.deepAccess(validBidRequests[0], 'renderer'); + const outstreamOptions = utils.deepAccess(validBidRequests[0], 'params.outstreamOptions'); const isBanner = !!validBidRequests[0].mediaTypes.banner || (isOutstream && !(isCustomRender || isNativeRender || isNodeRender)); const defaultSchain = validBidRequests[0].schain || {}; validBidRequests.forEach((bid) => { const videoSizes = getVideoSizes(bid); const bannerSizes = getBannerSizes(bid); - const vpaidMode = getBidIdParameter('vpaidMode', bid.params); + const vpaidMode = utils.getBidIdParameter('vpaidMode', bid.params); const makeBids = (type, size) => { let context = ''; @@ -52,7 +52,7 @@ export const spec = { if (type === BANNER) { streamType = 5; } else { - context = deepAccess(bid, 'mediaTypes.video.context'); + context = utils.deepAccess(bid, 'mediaTypes.video.context'); if (vpaidMode && context === 'instream') { streamType = 1; } @@ -61,24 +61,15 @@ export const spec = { } } - const consentData = bidderRequest.gdprConsent || {}; - - const gdprConsent = { - apiVersion: consentData.apiVersion || 2, - gdprApplies: consentData.gdprApplies || 0, - consentString: consentData.consentString || '', - } - return { type: streamType, - adUnitCode: bid.adUnitCode, bidId: bid.bidId, mediaType: type, context: context, - playerId: getBidIdParameter('playerId', bid.params), + playerId: utils.getBidIdParameter('playerId', bid.params), auctionId: bidderRequest.auctionId, bidderCode: BIDDER_CODE, - gdprConsent: gdprConsent, + gdprConsent: bidderRequest.gdprConsent, start: +new Date(), timeout: 3000, size: { @@ -109,7 +100,7 @@ export const spec = { 'adapterVersion': 2, 'pageURL': encodeURIComponent(pageURL), 'vastCacheEnabled': (!!config.getConfig('cache') && !isBanner && !outstreamOptions) || false, - 'isDesktop': getWindowTop().document.documentElement.clientWidth > 700, + 'isDesktop': utils.getWindowTop().document.documentElement.clientWidth > 700, 'xmlAndTag': !!(isOutstream && isCustomRender) || false, 'stage': isStage || undefined }, @@ -168,7 +159,6 @@ function createBids(bidRes, reqData) { let bidUnit = {}; bidUnit.cpm = bid.cpm; bidUnit.requestId = bid.bidId; - bidUnit.adUnitCode = reqBid.adUnitCode; bidUnit.currency = bid.currency; bidUnit.mediaType = bid.mediaType || VIDEO; bidUnit.ttl = TTL; @@ -193,8 +183,7 @@ function createBids(bidRes, reqData) { } else if (bid.context === 'outstream') { const renderer = Renderer.install({ id: bid.bidId, - url: 'https://static.showheroes.com/renderer.js', - adUnitCode: reqBid.adUnitCode, + url: '//', config: { playerId: reqBid.playerId, width: bid.size.width, @@ -203,9 +192,9 @@ function createBids(bidRes, reqData) { vastXml: bid.vastXml, debug: reqData.debug, isStage: !!reqData.meta.stage, - customRender: getBidIdParameter('customRender', currentBidParams.outstreamOptions), - slot: getBidIdParameter('slot', currentBidParams.outstreamOptions), - iframe: getBidIdParameter('iframe', currentBidParams.outstreamOptions), + customRender: utils.getBidIdParameter('customRender', currentBidParams.outstreamOptions), + slot: utils.getBidIdParameter('slot', currentBidParams.outstreamOptions), + iframe: utils.getBidIdParameter('iframe', currentBidParams.outstreamOptions), } }); renderer.setRender(outstreamRender); @@ -223,7 +212,7 @@ function outstreamRender(bid) { bid.renderer.config.customRender(bid, embedCode); } else { try { - const inIframe = getBidIdParameter('iframe', bid.renderer.config); + const inIframe = utils.getBidIdParameter('iframe', bid.renderer.config); if (inIframe && window.document.getElementById(inIframe).nodeName === 'IFRAME') { const iframe = window.document.getElementById(inIframe); let framedoc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document); @@ -231,20 +220,20 @@ function outstreamRender(bid) { return; } - const slot = getBidIdParameter('slot', bid.renderer.config) || bid.adUnitCode; + const slot = utils.getBidIdParameter('slot', bid.renderer.config) || bid.adUnitCode; if (slot && window.document.getElementById(slot)) { window.document.getElementById(slot).appendChild(embedCode); } else if (slot) { - logError('[ShowHeroes][renderer] Error: spot not found'); + utils.logError('[ShowHeroes][renderer] Error: spot not found'); } } catch (err) { - logError('[ShowHeroes][renderer] Error:' + err.message) + utils.logError('[ShowHeroes][renderer] Error:' + err.message) } } } function createOutstreamEmbedCode(bid) { - const isStage = getBidIdParameter('isStage', bid.renderer.config); + const isStage = utils.getBidIdParameter('isStage', bid.renderer.config); const urls = getEnvURLs(isStage); const fragment = window.document.createDocumentFragment(); @@ -256,9 +245,9 @@ function createOutstreamEmbedCode(bid) { const spot = window.document.createElement('div'); spot.setAttribute('class', 'showheroes-spot'); - spot.setAttribute('data-player', getBidIdParameter('playerId', bid.renderer.config)); - spot.setAttribute('data-debug', getBidIdParameter('debug', bid.renderer.config)); - spot.setAttribute('data-ad-vast-tag', getBidIdParameter('vastUrl', bid.renderer.config)); + spot.setAttribute('data-player', utils.getBidIdParameter('playerId', bid.renderer.config)); + spot.setAttribute('data-debug', utils.getBidIdParameter('debug', bid.renderer.config)); + spot.setAttribute('data-ad-vast-tag', utils.getBidIdParameter('vastUrl', bid.renderer.config)); spot.setAttribute('data-stream-type', 'outstream'); fragment.appendChild(spot); @@ -286,11 +275,11 @@ function getBannerHtml (bid, reqBid, reqData) { } function getVideoSizes(bidRequest) { - return formatSizes(deepAccess(bidRequest, 'mediaTypes.video.playerSize') || []); + return formatSizes(utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') || []); } function getBannerSizes(bidRequest) { - return formatSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes') || []); + return formatSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || []); } function formatSizes(sizes) { diff --git a/modules/sigmoidAnalyticsAdapter.js b/modules/sigmoidAnalyticsAdapter.js index da0ca9e38e5..303fbbc8995 100644 --- a/modules/sigmoidAnalyticsAdapter.js +++ b/modules/sigmoidAnalyticsAdapter.js @@ -5,10 +5,11 @@ import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; import { getStorageManager } from '../src/storageManager.js'; -import { generateUUID, logInfo, logError } from '../src/utils.js'; const storage = getStorageManager(); +const utils = require('../src/utils.js'); + const url = 'https://kinesis.us-east-1.amazonaws.com/'; const analyticsType = 'endpoint'; @@ -55,7 +56,7 @@ function buildSessionIdTimeoutLocalStorageKey() { function updateSessionId() { if (isSessionIdTimeoutExpired()) { - let newSessionId = generateUUID(); + let newSessionId = utils.generateUUID(); storage.setDataInLocalStorage(buildSessionIdLocalStorageKey(), newSessionId); } initOptions.sessionId = getSessionId(); @@ -205,7 +206,7 @@ sigmoidAdapter.originEnableAnalytics = sigmoidAdapter.enableAnalytics; sigmoidAdapter.enableAnalytics = function (config) { initOptions = config.options; initOptions.utmTagData = this.buildUtmTagData(); - logInfo('Sigmoid Analytics enabled with config', initOptions); + utils.logInfo('Sigmoid Analytics enabled with config', initOptions); sigmoidAdapter.originEnableAnalytics(config); }; @@ -245,7 +246,7 @@ function send(eventType, data, sendDataType) { AWS.config.credentials.get(function(err) { // attach event listener if (err) { - logError(err); + utils.logError(err); return; } // create kinesis service object diff --git a/modules/sirdataRtdProvider.js b/modules/sirdataRtdProvider.js index 344357bcb62..373468b2f14 100644 --- a/modules/sirdataRtdProvider.js +++ b/modules/sirdataRtdProvider.js @@ -7,7 +7,7 @@ * @requires module:modules/realTimeData */ import {getGlobal} from '../src/prebidGlobal.js'; -import { deepAccess, logError, deepEqual, deepSetValue, isEmpty, mergeDeep } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {submodule} from '../src/hook.js'; import {ajax} from '../src/ajax.js'; import findIndex from 'core-js-pure/features/array/find-index.js'; @@ -44,7 +44,7 @@ export function getSegmentsAndCategories(reqBidsConfigObj, onDone, moduleConfig, } // default global endpoint is cookie-based if no rules falls into cookieless or consent has been given or GDPR doesn't apply - if (!sirdataDomain || !gdprApplies || (deepAccess(userConsent, 'gdpr.vendorData.vendor.consents') && userConsent.gdpr.vendorData.vendor.consents[53] && userConsent.gdpr.vendorData.purpose.consents[1] && userConsent.gdpr.vendorData.purpose.consents[4])) { + if (!sirdataDomain || !gdprApplies || (utils.deepAccess(userConsent, 'gdpr.vendorData.vendor.consents') && userConsent.gdpr.vendorData.vendor.consents[53] && userConsent.gdpr.vendorData.purpose.consents[1] && userConsent.gdpr.vendorData.purpose.consents[4])) { sirdataDomain = 'sddan.com'; sendWithCredentials = true; } @@ -64,7 +64,7 @@ export function getSegmentsAndCategories(reqBidsConfigObj, onDone, moduleConfig, } } catch (e) { onDone(); - logError('unable to parse Sirdata data' + e); + utils.logError('unable to parse Sirdata data' + e); } } else if (req.status === 204) { onDone(); @@ -72,7 +72,7 @@ export function getSegmentsAndCategories(reqBidsConfigObj, onDone, moduleConfig, }, error: function () { onDone(); - logError('unable to get Sirdata data'); + utils.logError('unable to get Sirdata data'); } }, null, @@ -89,18 +89,18 @@ export function setGlobalOrtb2(segments, categories) { try { let addOrtb2 = {}; let testGlobal = getGlobal().getConfig('ortb2') || {}; - if (!deepAccess(testGlobal, 'user.ext.data.sd_rtd') || !deepEqual(testGlobal.user.ext.data.sd_rtd, segments)) { - deepSetValue(addOrtb2, 'user.ext.data.sd_rtd', segments || {}); + if (!utils.deepAccess(testGlobal, 'user.ext.data.sd_rtd') || !utils.deepEqual(testGlobal.user.ext.data.sd_rtd, segments)) { + utils.deepSetValue(addOrtb2, 'user.ext.data.sd_rtd', segments || {}); } - if (!deepAccess(testGlobal, 'site.ext.data.sd_rtd') || !deepEqual(testGlobal.site.ext.data.sd_rtd, categories)) { - deepSetValue(addOrtb2, 'site.ext.data.sd_rtd', categories || {}); + if (!utils.deepAccess(testGlobal, 'site.ext.data.sd_rtd') || !utils.deepEqual(testGlobal.site.ext.data.sd_rtd, categories)) { + utils.deepSetValue(addOrtb2, 'site.ext.data.sd_rtd', categories || {}); } - if (!isEmpty(addOrtb2)) { - let ortb2 = {ortb2: mergeDeep({}, testGlobal, addOrtb2)}; + if (!utils.isEmpty(addOrtb2)) { + let ortb2 = {ortb2: utils.mergeDeep({}, testGlobal, addOrtb2)}; getGlobal().setConfig(ortb2); } } catch (e) { - logError(e) + utils.logError(e) } return true; @@ -109,19 +109,19 @@ export function setGlobalOrtb2(segments, categories) { export function setBidderOrtb2(bidder, segments, categories) { try { let addOrtb2 = {}; - let testBidder = deepAccess(config.getBidderConfig(), bidder + '.ortb2') || {}; - if (!deepAccess(testBidder, 'user.ext.data.sd_rtd') || !deepEqual(testBidder.user.ext.data.sd_rtd, segments)) { - deepSetValue(addOrtb2, 'user.ext.data.sd_rtd', segments || {}); + let testBidder = utils.deepAccess(config.getBidderConfig(), bidder + '.ortb2') || {}; + if (!utils.deepAccess(testBidder, 'user.ext.data.sd_rtd') || !utils.deepEqual(testBidder.user.ext.data.sd_rtd, segments)) { + utils.deepSetValue(addOrtb2, 'user.ext.data.sd_rtd', segments || {}); } - if (!deepAccess(testBidder, 'site.ext.data.sd_rtd') || !deepEqual(testBidder.site.ext.data.sd_rtd, categories)) { - deepSetValue(addOrtb2, 'site.ext.data.sd_rtd', categories || {}); + if (!utils.deepAccess(testBidder, 'site.ext.data.sd_rtd') || !utils.deepEqual(testBidder.site.ext.data.sd_rtd, categories)) { + utils.deepSetValue(addOrtb2, 'site.ext.data.sd_rtd', categories || {}); } - if (!isEmpty(addOrtb2)) { - let ortb2 = {ortb2: mergeDeep({}, testBidder, addOrtb2)}; + if (!utils.isEmpty(addOrtb2)) { + let ortb2 = {ortb2: utils.mergeDeep({}, testBidder, addOrtb2)}; getGlobal().setBidderConfig({ bidders: [bidder], config: ortb2 }); } } catch (e) { - logError(e) + utils.logError(e) } return true; @@ -132,7 +132,7 @@ export function loadCustomFunction (todo, adUnit, list, data, bid) { if (typeof todo == 'function') { todo(adUnit, list, data, bid); } - } catch (e) { logError(e); } + } catch (e) { utils.logError(e); } return true; } @@ -148,14 +148,14 @@ export function getSegAndCatsArray(data, minScore) { } } } - } catch (e) { logError(e); } + } catch (e) { utils.logError(e); } try { if (data && data.segments) { for (let segId in data.segments) { sirdataData.segments.push(data.segments[segId].toString()); } } - } catch (e) { logError(e); } + } catch (e) { utils.logError(e); } return sirdataData; } @@ -165,7 +165,7 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { const globalMinScore = moduleConfig.params.hasOwnProperty('contextualMinRelevancyScore') ? moduleConfig.params.contextualMinRelevancyScore : 30; var sirdataData = getSegAndCatsArray(data, globalMinScore); - if (!sirdataData || (sirdataData.segments.length < 1 && sirdataData.categories.length < 1)) { logError('no cats'); onDone(); return adUnits; } + if (!sirdataData || (sirdataData.segments.length < 1 && sirdataData.categories.length < 1)) { utils.logError('no cats'); onDone(); return adUnits; } const sirdataList = sirdataData.segments.concat(sirdataData.categories); @@ -191,7 +191,7 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { n.setTargeting('sd_rtd', sirdataList.concat(curationData.segments).concat(curationData.categories)); } }) - } catch (e) { logError(e); } + } catch (e) { utils.logError(e); } } // Bid targeting level for FPD non-generic biders @@ -199,8 +199,8 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { var indexFound = false; adUnits.forEach(adUnit => { - if (!biddersParamsExist && !deepAccess(adUnit, 'ortb2Imp.ext.data.sd_rtd')) { - deepSetValue(adUnit, 'ortb2Imp.ext.data.sd_rtd', sirdataList); + if (!biddersParamsExist && !utils.deepAccess(adUnit, 'ortb2Imp.ext.data.sd_rtd')) { + utils.deepSetValue(adUnit, 'ortb2Imp.ext.data.sd_rtd', sirdataList); } adUnit.hasOwnProperty('bids') && adUnit.bids.forEach(bid => { @@ -236,7 +236,7 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { if (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('customFunction')) { loadCustomFunction(moduleConfig.params.bidders[bidderIndex].customFunction, adUnit, sirdataList.concat(curationData.segments).concat(curationData.categories), data, bid); } else { - deepSetValue(bid, 'params.keywords.sd_rtd', sirdataList.concat(curationData.segments).concat(curationData.categories)); + utils.deepSetValue(bid, 'params.keywords.sd_rtd', sirdataList.concat(curationData.segments).concat(curationData.categories)); } break; @@ -259,7 +259,7 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { target.push('sd_rtd=' + entry); } }); - deepSetValue(bid, 'params.target', target.join(';')); + utils.deepSetValue(bid, 'params.target', target.join(';')); } break; @@ -313,7 +313,7 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { if (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('customFunction')) { loadCustomFunction(moduleConfig.params.bidders[bidderIndex].customFunction, adUnit, sirdataList.concat(curationData.segments).concat(curationData.categories), data, bid); } else { - deepSetValue(bid, 'ortb2.user.ext.data', {segments: sirdataData.segments.concat(curationData.segments), contextual_categories: {...data.contextual_categories, ...data.shared_taxonomy[curationId].contextual_categories}}); + utils.deepSetValue(bid, 'ortb2.user.ext.data', {segments: sirdataData.segments.concat(curationData.segments), contextual_categories: {...data.contextual_categories, ...data.shared_taxonomy[curationId].contextual_categories}}); } break; @@ -372,16 +372,16 @@ export function addSegmentData(adUnits, data, moduleConfig, onDone) { default: if (!biddersParamsExist || indexFound) { - if (!deepAccess(bid, 'ortb2.site.ext.data.sd_rtd')) { - deepSetValue(bid, 'ortb2.site.ext.data.sd_rtd', sirdataData.categories); + if (!utils.deepAccess(bid, 'ortb2.site.ext.data.sd_rtd')) { + utils.deepSetValue(bid, 'ortb2.site.ext.data.sd_rtd', sirdataData.categories); } - if (!deepAccess(bid, 'ortb2.user.ext.data.sd_rtd')) { - deepSetValue(bid, 'ortb2.user.ext.data.sd_rtd', sirdataData.segments); + if (!utils.deepAccess(bid, 'ortb2.user.ext.data.sd_rtd')) { + utils.deepSetValue(bid, 'ortb2.user.ext.data.sd_rtd', sirdataData.segments); } } } } - } catch (e) { logError(e) } + } catch (e) { utils.logError(e) } }) }); diff --git a/modules/sizeMappingV2.js b/modules/sizeMappingV2.js index 95f0eea4075..ffd242e57ac 100644 --- a/modules/sizeMappingV2.js +++ b/modules/sizeMappingV2.js @@ -4,7 +4,7 @@ * rendering. Read full API documentation on Prebid.org, http://prebid.org/dev-docs/modules/sizeMappingV2.html */ -import { isArray, logError, isArrayOfNums, deepClone, logWarn, getWindowTop, deepEqual, logInfo, isValidMediaTypes, deepAccess, getDefinedParams, getUniqueIdentifierStr, flatten } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { processNativeAdUnitParams } from '../src/native.js'; import { adunitCounter } from '../src/adUnits.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -66,7 +66,7 @@ export function isUsingNewSizeMapping(adUnits) { }); // checks for the presence of sizeConfig property at the adUnit.bids[].bidder object - adUnit.bids && isArray(adUnit.bids) && adUnit.bids.forEach(bidder => { + adUnit.bids && utils.isArray(adUnit.bids) && adUnit.bids.forEach(bidder => { if (bidder.sizeConfig) { if (isUsingSizeMappingBool === false) { isUsingSizeMappingBool = true; @@ -108,7 +108,7 @@ export function checkAdUnitSetupHook(adUnits) { If they do not, return 'false'. */ if (!(includes(keys, 'minViewPort') && includes(keys, propertyName))) { - logError(`Ad unit ${adUnitCode}: Missing required property 'minViewPort' or 'sizes' from 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); + utils.logError(`Ad unit ${adUnitCode}: Missing required property 'minViewPort' or 'sizes' from 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); isValid = false; return; } @@ -117,8 +117,8 @@ export function checkAdUnitSetupHook(adUnits) { Verify that 'config.minViewPort' property is in [width, height] format. If not, return false. */ - if (!isArrayOfNums(config.minViewPort, 2)) { - logError(`Ad unit ${adUnitCode}: Invalid declaration of 'minViewPort' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); + if (!utils.isArrayOfNums(config.minViewPort, 2)) { + utils.logError(`Ad unit ${adUnitCode}: Invalid declaration of 'minViewPort' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); isValid = false return; } @@ -141,7 +141,7 @@ export function checkAdUnitSetupHook(adUnits) { showError = true; } if (showError) { - logError(`Ad unit ${adUnitCode}: Invalid declaration of '${propertyName}' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); + utils.logError(`Ad unit ${adUnitCode}: Invalid declaration of '${propertyName}' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); return; } } @@ -152,13 +152,13 @@ export function checkAdUnitSetupHook(adUnits) { */ if (mediaType === 'native') { if (typeof config[propertyName] !== 'boolean') { - logError(`Ad unit ${adUnitCode}: Invalid declaration of 'active' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); + utils.logError(`Ad unit ${adUnitCode}: Invalid declaration of 'active' in 'mediaTypes.${mediaType}.sizeConfig[${index}]'. ${conditionalLogMessages[mediaType]}`); isValid = false; } } }); } else { - logError(`Ad unit ${adUnitCode}: Invalid declaration of 'sizeConfig' in 'mediaTypes.${mediaType}.sizeConfig'. ${conditionalLogMessages[mediaType]}`); + utils.logError(`Ad unit ${adUnitCode}: Invalid declaration of 'sizeConfig' in 'mediaTypes.${mediaType}.sizeConfig'. ${conditionalLogMessages[mediaType]}`); isValid = false; return isValid; } @@ -172,13 +172,13 @@ export function checkAdUnitSetupHook(adUnits) { const mediaTypes = adUnit.mediaTypes; let validatedBanner, validatedVideo, validatedNative; - if (!bids || !isArray(bids)) { - logError(`Detected adUnit.code '${adUnit.code}' did not have 'adUnit.bids' defined or 'adUnit.bids' is not an array. Removing adUnit from auction.`); + if (!bids || !utils.isArray(bids)) { + utils.logError(`Detected adUnit.code '${adUnit.code}' did not have 'adUnit.bids' defined or 'adUnit.bids' is not an array. Removing adUnit from auction.`); return; } if (!mediaTypes || Object.keys(mediaTypes).length === 0) { - logError(`Detected adUnit.code '${adUnit.code}' did not have a 'mediaTypes' object defined. This is a required field for the auction, so this adUnit has been removed.`); + utils.logError(`Detected adUnit.code '${adUnit.code}' did not have a 'mediaTypes' object defined. This is a required field for the auction, so this adUnit has been removed.`); return; } if (mediaTypes.banner) { @@ -187,7 +187,7 @@ export function checkAdUnitSetupHook(adUnits) { validatedBanner = adUnitSetupChecks.validateBannerMediaType(adUnit); } else if (mediaTypes.banner.sizeConfig) { // Ad unit is using the 'sizeConfig' property, 'mediaTypes.banner.sizeConfig'. Apply the new checks! - validatedBanner = deepClone(adUnit); + validatedBanner = utils.deepClone(adUnit); const isBannerValid = validateSizeConfig('banner', mediaTypes.banner.sizeConfig, adUnit.code); if (!isBannerValid) { delete validatedBanner.mediaTypes.banner; @@ -204,8 +204,8 @@ export function checkAdUnitSetupHook(adUnits) { } } else { // Ad unit is invalid since it's mediaType property does not have either 'sizes' or 'sizeConfig' declared. - logError(`Ad unit ${adUnit.code}: 'mediaTypes.banner' does not contain either 'sizes' or 'sizeConfig' property. Removing 'mediaTypes.banner' from ad unit.`); - validatedBanner = deepClone(adUnit); + utils.logError(`Ad unit ${adUnit.code}: 'mediaTypes.banner' does not contain either 'sizes' or 'sizeConfig' property. Removing 'mediaTypes.banner' from ad unit.`); + validatedBanner = utils.deepClone(adUnit); delete validatedBanner.mediaTypes.banner; } } @@ -216,7 +216,7 @@ export function checkAdUnitSetupHook(adUnits) { validatedVideo = validatedBanner ? adUnitSetupChecks.validateVideoMediaType(validatedBanner) : adUnitSetupChecks.validateVideoMediaType(adUnit); } else if (mediaTypes.video.sizeConfig) { // Ad unit is using the 'sizeConfig' property, 'mediaTypes.video.sizeConfig'. Apply the new checks! - validatedVideo = validatedBanner || deepClone(adUnit); + validatedVideo = validatedBanner || utils.deepClone(adUnit); const isVideoValid = validateSizeConfig('video', mediaTypes.video.sizeConfig, adUnit.code); if (!isVideoValid) { delete validatedVideo.mediaTypes.video.sizeConfig; @@ -274,7 +274,7 @@ export function checkBidderSizeConfigFormat(sizeConfig) { const keys = Object.keys(config); if ((includes(keys, 'minViewPort') && includes(keys, 'relevantMediaTypes')) && - isArrayOfNums(config.minViewPort, 2) && + utils.isArrayOfNums(config.minViewPort, 2) && Array.isArray(config.relevantMediaTypes) && config.relevantMediaTypes.length > 0 && (config.relevantMediaTypes.length > 1 ? (config.relevantMediaTypes.every(mt => (includes(['banner', 'video', 'native'], mt)))) @@ -322,14 +322,14 @@ export function isLabelActivated(bidOrAdUnit, activeLabels, adUnitCode, adUnitIn let labelOperator; const labelsFound = Object.keys(bidOrAdUnit).filter(prop => prop === 'labelAny' || prop === 'labelAll'); if (labelsFound && labelsFound.length > 1) { - logWarn(`Size Mapping V2:: ${(bidOrAdUnit.code) + utils.logWarn(`Size Mapping V2:: ${(bidOrAdUnit.code) ? (`Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Ad unit has multiple label operators. Using the first declared operator: ${labelsFound[0]}`) : (`Ad Unit: ${adUnitCode}(${adUnitInstance}), Bidder: ${bidOrAdUnit.bidder} => Bidder has multiple label operators. Using the first declared operator: ${labelsFound[0]}`)}`); } labelOperator = labelsFound[0]; if (labelOperator && !activeLabels) { - logWarn(`Size Mapping V2:: ${(bidOrAdUnit.code) + utils.logWarn(`Size Mapping V2:: ${(bidOrAdUnit.code) ? (`Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Found '${labelOperator}' on ad unit, but 'labels' is not set. Did you pass 'labels' to pbjs.requestBids() ?`) : (`Ad Unit: ${adUnitCode}(${adUnitInstance}), Bidder: ${bidOrAdUnit.bidder} => Found '${labelOperator}' on bidder, but 'labels' is not set. Did you pass 'labels' to pbjs.requestBids() ?`)}`); return true; @@ -337,13 +337,13 @@ export function isLabelActivated(bidOrAdUnit, activeLabels, adUnitCode, adUnitIn if (labelOperator === 'labelAll' && Array.isArray(bidOrAdUnit[labelOperator])) { if (bidOrAdUnit.labelAll.length === 0) { - logWarn(`Size Mapping V2:: Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Ad unit has declared property 'labelAll' with an empty array.`); + utils.logWarn(`Size Mapping V2:: Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Ad unit has declared property 'labelAll' with an empty array.`); return true; } return bidOrAdUnit.labelAll.every(label => includes(activeLabels, label)); } else if (labelOperator === 'labelAny' && Array.isArray(bidOrAdUnit[labelOperator])) { if (bidOrAdUnit.labelAny.length === 0) { - logWarn(`Size Mapping V2:: Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Ad unit has declared property 'labelAny' with an empty array.`); + utils.logWarn(`Size Mapping V2:: Ad Unit: ${bidOrAdUnit.code}(${adUnitInstance}) => Ad unit has declared property 'labelAny' with an empty array.`); return true; } return bidOrAdUnit.labelAny.some(label => includes(activeLabels, label)); @@ -363,7 +363,7 @@ export function getFilteredMediaTypes(mediaTypes) { activeViewportHeight, transformedMediaTypes; - transformedMediaTypes = deepClone(mediaTypes); + transformedMediaTypes = utils.deepClone(mediaTypes); let activeSizeBucket = { banner: undefined, @@ -372,10 +372,10 @@ export function getFilteredMediaTypes(mediaTypes) { } try { - activeViewportWidth = getWindowTop().innerWidth; - activeViewportHeight = getWindowTop().innerHeight; + activeViewportWidth = utils.getWindowTop().innerWidth; + activeViewportHeight = utils.getWindowTop().innerHeight; } catch (e) { - logWarn(`SizeMappingv2:: Unfriendly iframe blocks viewport size to be evaluated correctly`); + utils.logWarn(`SizeMappingv2:: Unfriendly iframe blocks viewport size to be evaluated correctly`); activeViewportWidth = window.innerWidth; activeViewportHeight = window.innerHeight; } @@ -490,7 +490,7 @@ export function getAdUnitDetail(auctionId, adUnit, labels) { const adUnitsForAuction = sizeMappingInternalStore.getAuctionDetail(auctionId).adUnits; // check if the adUnit exists already in the sizeMappingInterStore (check for equivalence of 'code' && 'mediaTypes' properties) - const adUnitDetail = adUnitsForAuction.filter(adUnitDetail => adUnitDetail.adUnitCode === adUnit.code && deepEqual(adUnitDetail.mediaTypes, adUnit.mediaTypes)); + const adUnitDetail = adUnitsForAuction.filter(adUnitDetail => adUnitDetail.adUnitCode === adUnit.code && utils.deepEqual(adUnitDetail.mediaTypes, adUnit.mediaTypes)); if (adUnitDetail.length > 0) { adUnitDetail[0].cacheHits++; @@ -514,7 +514,7 @@ export function getAdUnitDetail(auctionId, adUnit, labels) { // set adUnitDetail in sizeMappingInternalStore against the correct 'auctionId'. sizeMappingInternalStore.setAuctionDetail(auctionId, adUnitDetail); - isLabelActivated && logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Active size buckets after filtration: `, sizeBucketToSizeMap); + isLabelActivated && utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Active size buckets after filtration: `, sizeBucketToSizeMap); return adUnitDetail; } @@ -522,13 +522,13 @@ export function getAdUnitDetail(auctionId, adUnit, labels) { export function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, labels, src }) { return adUnits.reduce((result, adUnit) => { - if (adUnit.mediaTypes && isValidMediaTypes(adUnit.mediaTypes)) { + if (adUnit.mediaTypes && utils.isValidMediaTypes(adUnit.mediaTypes)) { const { activeViewport, transformedMediaTypes, instance: adUnitInstance, isLabelActivated, cacheHits } = internal.getAdUnitDetail(auctionId, adUnit, labels); if (isLabelActivated) { // check if adUnit has any active media types remaining, if not drop the adUnit from auction, // else proceed to evaluate the bids object. if (Object.keys(transformedMediaTypes).length === 0) { - cacheHits === 0 && logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Ad unit disabled since there are no active media types after sizeConfig filtration.`); + cacheHits === 0 && utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Ad unit disabled since there are no active media types after sizeConfig filtration.`); return result; } result @@ -536,19 +536,19 @@ export function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, label .reduce((bids, bid) => { if (internal.isLabelActivated(bid, labels, adUnit.code, adUnitInstance)) { // handle native params - const nativeParams = adUnit.nativeParams || deepAccess(adUnit, 'mediaTypes.native'); + const nativeParams = adUnit.nativeParams || utils.deepAccess(adUnit, 'mediaTypes.native'); if (nativeParams) { bid = Object.assign({}, bid, { nativeParams: processNativeAdUnitParams(nativeParams) }); } - bid = Object.assign({}, bid, getDefinedParams(adUnit, ['mediaType', 'renderer'])); + bid = Object.assign({}, bid, utils.getDefinedParams(adUnit, ['mediaType', 'renderer'])); if (bid.sizeConfig) { const relevantMediaTypes = internal.getRelevantMediaTypesForBidder(bid.sizeConfig, activeViewport); if (relevantMediaTypes.length === 0) { - logError(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bidderCode} => 'sizeConfig' is not configured properly. This bidder won't be eligible for sizeConfig checks and will remail active.`); + utils.logError(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bidderCode} => 'sizeConfig' is not configured properly. This bidder won't be eligible for sizeConfig checks and will remail active.`); bid = Object.assign({}, bid); } else if (relevantMediaTypes[0] !== 'none') { const bidderMediaTypes = Object @@ -562,20 +562,20 @@ export function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, label if (Object.keys(bidderMediaTypes).length > 0) { bid = Object.assign({}, bid, { mediaTypes: bidderMediaTypes }); } else { - logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => 'relevantMediaTypes' does not match with any of the active mediaTypes at the Ad Unit level. This bidder is disabled.`); + utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => 'relevantMediaTypes' does not match with any of the active mediaTypes at the Ad Unit level. This bidder is disabled.`); return bids; } } else { - logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => 'relevantMediaTypes' is set to 'none' in sizeConfig for current viewport size. This bidder is disabled.`); + utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => 'relevantMediaTypes' is set to 'none' in sizeConfig for current viewport size. This bidder is disabled.`); return bids; } } bids.push(Object.assign({}, bid, { adUnitCode: adUnit.code, transactionId: adUnit.transactionId, - sizes: deepAccess(transformedMediaTypes, 'banner.sizes') || deepAccess(transformedMediaTypes, 'video.playerSize') || [], + sizes: utils.deepAccess(transformedMediaTypes, 'banner.sizes') || utils.deepAccess(transformedMediaTypes, 'video.playerSize') || [], mediaTypes: bid.mediaTypes || transformedMediaTypes, - bidId: bid.bid_id || getUniqueIdentifierStr(), + bidId: bid.bid_id || utils.getUniqueIdentifierStr(), bidderRequestId, auctionId, src, @@ -585,17 +585,17 @@ export function getBids({ bidderCode, auctionId, bidderRequestId, adUnits, label })); return bids; } else { - logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => Label check for this bidder has failed. This bidder is disabled.`); + utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}), Bidder: ${bid.bidder} => Label check for this bidder has failed. This bidder is disabled.`); return bids; } }, [])); } else { - cacheHits === 0 && logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Ad unit is disabled due to failing label check.`); + cacheHits === 0 && utils.logInfo(`Size Mapping V2:: Ad Unit: ${adUnit.code}(${adUnitInstance}) => Ad unit is disabled due to failing label check.`); } } else { - logWarn(`Size Mapping V2:: Ad Unit: ${adUnit.code} => Ad unit has declared invalid 'mediaTypes' or has not declared a 'mediaTypes' property`); + utils.logWarn(`Size Mapping V2:: Ad Unit: ${adUnit.code} => Ad unit has declared invalid 'mediaTypes' or has not declared a 'mediaTypes' property`); return result; } return result; - }, []).reduce(flatten, []).filter(val => val !== ''); + }, []).reduce(utils.flatten, []).filter(val => val !== ''); } diff --git a/modules/slimcutBidAdapter.js b/modules/slimcutBidAdapter.js deleted file mode 100644 index c2592137fd8..00000000000 --- a/modules/slimcutBidAdapter.js +++ /dev/null @@ -1,121 +0,0 @@ -import { getValue, parseSizesInput, getBidIdParameter } from '../src/utils.js'; -import { - registerBidder -} from '../src/adapters/bidderFactory.js'; -import { - ajax -} from '../src/ajax.js'; -const BIDDER_CODE = 'slimcut'; -const ENDPOINT_URL = 'https://sb.freeskreen.com/pbr'; -export const spec = { - code: BIDDER_CODE, - aliases: ['scm'], - supportedMediaTypes: ['video', 'banner'], - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function(bid) { - let isValid = false; - if (typeof bid.params !== 'undefined' && !isNaN(parseInt(getValue(bid.params, 'placementId'))) && parseInt(getValue(bid.params, 'placementId')) > 0) { - isValid = true; - } - return isValid; - }, - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function(validBidRequests, bidderRequest) { - const bids = validBidRequests.map(buildRequestObject); - const payload = { - referrer: getReferrerInfo(bidderRequest), - data: bids, - deviceWidth: screen.width - }; - let gdpr = bidderRequest.gdprConsent; - if (bidderRequest && gdpr) { - let isCmp = (typeof gdpr.gdprApplies === 'boolean') - let isConsentString = (typeof gdpr.consentString === 'string') - payload.gdpr_iab = { - consent: isConsentString ? gdpr.consentString : '', - status: isCmp ? gdpr.gdprApplies : -1 - }; - } - const payloadString = JSON.stringify(payload); - return { - method: 'POST', - url: ENDPOINT_URL, - data: payloadString, - }; - }, - /** - * Unpack the response from the server into a list of bids. - * - * @param {*} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function(serverResponse, request) { - const bidResponses = []; - serverResponse = serverResponse.body; - if (serverResponse.responses) { - serverResponse.responses.forEach(function(bid) { - const bidResponse = { - cpm: bid.cpm, - width: bid.width, - height: bid.height, - currency: bid.currency, - netRevenue: bid.netRevenue, - ttl: bid.ttl, - ad: bid.ad, - requestId: bid.requestId, - creativeId: bid.creativeId, - transactionId: bid.tranactionId, - winUrl: bid.winUrl, - meta: { - advertiserDomains: bid.adomain || [] - } - }; - bidResponses.push(bidResponse); - }); - } - return bidResponses; - }, - getUserSyncs: function(syncOptions, serverResponses) { - if (syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: 'https://sb.freeskreen.com/async_usersync.html' - }]; - } - return []; - }, - onBidWon: function(bid) { - ajax(bid.winUrl + bid.cpm, null); - } -} -function buildRequestObject(bid) { - const reqObj = {}; - let placementId = getValue(bid.params, 'placementId'); - reqObj.sizes = parseSizesInput(bid.sizes); - reqObj.bidId = getBidIdParameter('bidId', bid); - reqObj.bidderRequestId = getBidIdParameter('bidderRequestId', bid); - reqObj.placementId = parseInt(placementId); - reqObj.adUnitCode = getBidIdParameter('adUnitCode', bid); - reqObj.auctionId = getBidIdParameter('auctionId', bid); - reqObj.transactionId = getBidIdParameter('transactionId', bid); - return reqObj; -} -function getReferrerInfo(bidderRequest) { - let ref = window.location.href; - if (bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer) { - ref = bidderRequest.refererInfo.referer; - } - return ref; -} - -registerBidder(spec); diff --git a/modules/smaatoBidAdapter.js b/modules/smaatoBidAdapter.js index 68334aed0ab..700fcf17785 100644 --- a/modules/smaatoBidAdapter.js +++ b/modules/smaatoBidAdapter.js @@ -1,11 +1,11 @@ -import { deepAccess, getDNT, deepSetValue, logInfo, logError, isEmpty, getAdUnitSizes, fill, chunk, getMaxValueFromArray, getMinValueFromArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {config} from '../src/config.js'; import {ADPOD, BANNER, VIDEO} from '../src/mediaTypes.js'; const BIDDER_CODE = 'smaato'; const SMAATO_ENDPOINT = 'https://prebid.ad.smaato.net/oapi/prebid'; -const SMAATO_CLIENT = 'prebid_js_$prebid.version$_1.6' +const SMAATO_CLIENT = 'prebid_js_$prebid.version$_1.4' const CURRENCY = 'USD'; const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { @@ -17,7 +17,7 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { site: { id: window.location.hostname, publisher: { - id: deepAccess(bidRequest, 'params.publisherId') + id: utils.deepAccess(bidRequest, 'params.publisherId') }, domain: window.location.hostname, page: window.location.href, @@ -26,7 +26,7 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { device: { language: (navigator && navigator.language) ? navigator.language.split('-')[0] : '', ua: navigator.userAgent, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, h: screen.height, w: screen.width }, @@ -37,11 +37,6 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { user: { ext: {} }, - source: { - ext: { - schain: bidRequest.schain - } - }, ext: { client: SMAATO_CLIENT } @@ -52,34 +47,34 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { Object.assign(requestTemplate.site, ortb2.site); if (bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies === true) { - deepSetValue(requestTemplate, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); - deepSetValue(requestTemplate, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(requestTemplate, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + utils.deepSetValue(requestTemplate, 'user.ext.consent', bidderRequest.gdprConsent.consentString); } if (bidderRequest.uspConsent !== undefined) { - deepSetValue(requestTemplate, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(requestTemplate, 'regs.ext.us_privacy', bidderRequest.uspConsent); } - if (deepAccess(bidRequest, 'params.app')) { - const geo = deepAccess(bidRequest, 'params.app.geo'); - deepSetValue(requestTemplate, 'device.geo', geo); - const ifa = deepAccess(bidRequest, 'params.app.ifa') - deepSetValue(requestTemplate, 'device.ifa', ifa); + if (utils.deepAccess(bidRequest, 'params.app')) { + const geo = utils.deepAccess(bidRequest, 'params.app.geo'); + utils.deepSetValue(requestTemplate, 'device.geo', geo); + const ifa = utils.deepAccess(bidRequest, 'params.app.ifa') + utils.deepSetValue(requestTemplate, 'device.ifa', ifa); } - const eids = deepAccess(bidRequest, 'userIdAsEids'); + const eids = utils.deepAccess(bidRequest, 'userIdAsEids'); if (eids && eids.length) { - deepSetValue(requestTemplate, 'user.ext.eids', eids); + utils.deepSetValue(requestTemplate, 'user.ext.eids', eids); } let requests = []; - if (deepAccess(bidRequest, 'mediaTypes.banner')) { + if (utils.deepAccess(bidRequest, 'mediaTypes.banner')) { const bannerRequest = Object.assign({}, requestTemplate, createBannerImp(bidRequest)); requests.push(bannerRequest); } - const videoMediaType = deepAccess(bidRequest, 'mediaTypes.video'); + const videoMediaType = utils.deepAccess(bidRequest, 'mediaTypes.video'); if (videoMediaType) { if (videoMediaType.context === ADPOD) { const adPodRequest = Object.assign({}, requestTemplate, createAdPodImp(bidRequest, videoMediaType)); @@ -95,7 +90,7 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => { } const buildServerRequest = (validBidRequest, data) => { - logInfo('[SMAATO] OpenRTB Request:', data); + utils.logInfo('[SMAATO] OpenRTB Request:', data); return { method: 'POST', url: validBidRequest.params.endpoint || SMAATO_ENDPOINT, @@ -119,47 +114,47 @@ export const spec = { */ isBidRequestValid: (bid) => { if (typeof bid.params !== 'object') { - logError('[SMAATO] Missing params object'); + utils.logError('[SMAATO] Missing params object'); return false; } if (typeof bid.params.publisherId !== 'string') { - logError('[SMAATO] Missing mandatory publisherId param'); + utils.logError('[SMAATO] Missing mandatory publisherId param'); return false; } - if (deepAccess(bid, 'mediaTypes.video.context') === ADPOD) { - logInfo('[SMAATO] Verifying adpod bid request'); + if (utils.deepAccess(bid, 'mediaTypes.video.context') === ADPOD) { + utils.logInfo('[SMAATO] Verifying adpod bid request'); if (typeof bid.params.adbreakId !== 'string') { - logError('[SMAATO] Missing for adpod request mandatory adbreakId param'); + utils.logError('[SMAATO] Missing for adpod request mandatory adbreakId param'); return false; } if (bid.params.adspaceId) { - logError('[SMAATO] The adspaceId param is not allowed in an adpod bid request'); + utils.logError('[SMAATO] The adspaceId param is not allowed in an adpod bid request'); return false; } } else { - logInfo('[SMAATO] Verifying a non adpod bid request'); + utils.logInfo('[SMAATO] Verifying a non adpod bid request'); if (typeof bid.params.adspaceId !== 'string') { - logError('[SMAATO] Missing mandatory adspaceId param'); + utils.logError('[SMAATO] Missing mandatory adspaceId param'); return false; } if (bid.params.adbreakId) { - logError('[SMAATO] The adbreakId param is only allowed in an adpod bid request'); + utils.logError('[SMAATO] The adbreakId param is only allowed in an adpod bid request'); return false; } } - logInfo('[SMAATO] Verification done, all good'); + utils.logInfo('[SMAATO] Verification done, all good'); return true; }, buildRequests: (validBidRequests, bidderRequest) => { - logInfo('[SMAATO] Client version:', SMAATO_CLIENT); + utils.logInfo('[SMAATO] Client version:', SMAATO_CLIENT); return validBidRequests.map((validBidRequest) => { const openRtbBidRequests = buildOpenRtbBidRequest(validBidRequest, bidderRequest); @@ -174,19 +169,19 @@ export const spec = { */ interpretResponse: (serverResponse, bidRequest) => { // response is empty (HTTP 204) - if (isEmpty(serverResponse.body)) { - logInfo('[SMAATO] Empty response body HTTP 204, no bids'); + if (utils.isEmpty(serverResponse.body)) { + utils.logInfo('[SMAATO] Empty response body HTTP 204, no bids'); return []; // no bids } const serverResponseHeaders = serverResponse.headers; const smtExpires = serverResponseHeaders.get('X-SMT-Expires'); - logInfo('[SMAATO] Expires:', smtExpires); + utils.logInfo('[SMAATO] Expires:', smtExpires); const ttlInSec = smtExpires ? Math.floor((smtExpires - Date.now()) / 1000) : 300; const response = serverResponse.body; - logInfo('[SMAATO] OpenRTB Response:', response); + utils.logInfo('[SMAATO] OpenRTB Response:', response); const smtAdType = serverResponseHeaders.get('X-SMT-ADTYPE'); const bids = []; @@ -200,7 +195,7 @@ export const spec = { ttl: ttlInSec, creativeId: bid.crid, dealId: bid.dealid || null, - netRevenue: deepAccess(bid, 'ext.net', true), + netRevenue: utils.deepAccess(bid, 'ext.net', true), currency: response.cur, meta: { advertiserDomains: bid.adomain, @@ -209,7 +204,7 @@ export const spec = { } }; - const videoContext = deepAccess(JSON.parse(bidRequest.data).imp[0], 'video.ext.context') + const videoContext = utils.deepAccess(JSON.parse(bidRequest.data).imp[0], 'video.ext.context') if (videoContext === ADPOD) { resultingBid.vastXml = bid.adm; resultingBid.mediaType = VIDEO; @@ -239,14 +234,14 @@ export const spec = { bids.push(resultingBid); break; default: - logInfo('[SMAATO] Invalid ad type:', smtAdType); + utils.logInfo('[SMAATO] Invalid ad type:', smtAdType); } } resultingBid.meta.mediaType = resultingBid.mediaType; }); }); - logInfo('[SMAATO] Prebid bids:', bids); + utils.logInfo('[SMAATO] Prebid bids:', bids); return bids; }, @@ -297,14 +292,13 @@ const createRichmediaAd = (adm) => { }; function createBannerImp(bidRequest) { - const adUnitSizes = getAdUnitSizes(bidRequest); + const adUnitSizes = utils.getAdUnitSizes(bidRequest); const sizes = adUnitSizes.map((size) => ({w: size[0], h: size[1]})); return { imp: [{ id: bidRequest.bidId, - tagid: deepAccess(bidRequest, 'params.adspaceId'), + tagid: utils.deepAccess(bidRequest, 'params.adspaceId'), bidfloor: getBidFloor(bidRequest, BANNER, adUnitSizes), - instl: deepAccess(bidRequest.ortb2Imp, 'instl'), banner: { w: sizes[0].w, h: sizes[0].h, @@ -318,9 +312,8 @@ function createVideoImp(bidRequest, videoMediaType) { return { imp: [{ id: bidRequest.bidId, - tagid: deepAccess(bidRequest, 'params.adspaceId'), + tagid: utils.deepAccess(bidRequest, 'params.adspaceId'), bidfloor: getBidFloor(bidRequest, VIDEO, videoMediaType.playerSize), - instl: deepAccess(bidRequest.ortb2Imp, 'instl'), video: { mimes: videoMediaType.mimes, minduration: videoMediaType.minduration, @@ -342,13 +335,12 @@ function createVideoImp(bidRequest, videoMediaType) { } function createAdPodImp(bidRequest, videoMediaType) { - const tagid = deepAccess(bidRequest, 'params.adbreakId') + const tagid = utils.deepAccess(bidRequest, 'params.adbreakId') const bce = config.getConfig('adpod.brandCategoryExclusion') let imp = { id: bidRequest.bidId, tagid: tagid, bidfloor: getBidFloor(bidRequest, VIDEO, videoMediaType.playerSize), - instl: deepAccess(bidRequest.ortb2Imp, 'instl'), video: { w: videoMediaType.playerSize[0][0], h: videoMediaType.playerSize[0][1], @@ -367,13 +359,13 @@ function createAdPodImp(bidRequest, videoMediaType) { } const numberOfPlacements = getAdPodNumberOfPlacements(videoMediaType) - let imps = fill(imp, numberOfPlacements) + let imps = utils.fill(imp, numberOfPlacements) const durationRangeSec = videoMediaType.durationRangeSec if (videoMediaType.requireExactDuration) { // equal distribution of numberOfPlacement over all available durations const divider = Math.ceil(numberOfPlacements / durationRangeSec.length) - const chunked = chunk(imps, divider) + const chunked = utils.chunk(imps, divider) // each configured duration is set as min/maxduration for a subset of requests durationRangeSec.forEach((duration, index) => { @@ -386,7 +378,7 @@ function createAdPodImp(bidRequest, videoMediaType) { }); } else { // all maxdurations should be the same - const maxDuration = getMaxValueFromArray(durationRangeSec); + const maxDuration = utils.getMaxValueFromArray(durationRangeSec); imps.map((imp, index) => { const sequence = index + 1; imp.video.maxduration = maxDuration @@ -401,7 +393,7 @@ function createAdPodImp(bidRequest, videoMediaType) { function getAdPodNumberOfPlacements(videoMediaType) { const {adPodDurationSec, durationRangeSec, requireExactDuration} = videoMediaType - const minAllowedDuration = getMinValueFromArray(durationRangeSec) + const minAllowedDuration = utils.getMinValueFromArray(durationRangeSec) const numberOfPlacements = Math.floor(adPodDurationSec / minAllowedDuration) return requireExactDuration @@ -431,7 +423,7 @@ const addOptionalAdpodParameters = (request, videoMediaType) => { content.livestream = videoMediaType.contentMode === 'live' ? 1 : 0 } - if (!isEmpty(content)) { + if (!utils.isEmpty(content)) { request.site.content = content } } diff --git a/modules/smartadserverBidAdapter.js b/modules/smartadserverBidAdapter.js index d6e1c8de452..a7b609bca20 100644 --- a/modules/smartadserverBidAdapter.js +++ b/modules/smartadserverBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, deepClone, logError, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; import { createEidsArray } from './userId/eids.js'; @@ -170,8 +170,8 @@ export const spec = { payload.us_privacy = bidderRequest.uspConsent; } - const videoMediaType = deepAccess(bid, 'mediaTypes.video'); - const bannerMediaType = deepAccess(bid, 'mediaTypes.banner'); + const videoMediaType = utils.deepAccess(bid, 'mediaTypes.video'); + const bannerMediaType = utils.deepAccess(bid, 'mediaTypes.banner'); const isAdUnitContainingVideo = videoMediaType && (videoMediaType.context === 'instream' || videoMediaType.context === 'outstream'); if (!isAdUnitContainingVideo && bannerMediaType) { payload.sizes = spec.adaptBannerSizes(bannerMediaType.sizes); @@ -182,7 +182,7 @@ export const spec = { } else if (isAdUnitContainingVideo && bannerMediaType) { // If there are video and banner media types in the ad unit, we clone the payload // to create a specific one for video. - let videoPayload = deepClone(payload); + let videoPayload = utils.deepClone(payload); spec.fillPayloadForVideoBidRequest(videoPayload, videoMediaType, bid.params.video); bidRequests.push(spec.createServerRequest(videoPayload, bid.params.domain)); @@ -238,7 +238,7 @@ export const spec = { bidResponses.push(bidResponse); } } catch (error) { - logError('Error while parsing smart server response', error); + utils.logError('Error while parsing smart server response', error); } return bidResponses; }, @@ -251,7 +251,7 @@ export const spec = { * @return {number} Floor price */ getBidFloor: function (bid, currency) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return DEFAULT_FLOOR; } @@ -261,7 +261,7 @@ export const spec = { size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor)) { + if (utils.isPlainObject(floor) && !isNaN(floor.floor)) { return floor.floor; } diff --git a/modules/smartxBidAdapter.js b/modules/smartxBidAdapter.js index 00c962445d9..c29708c8420 100644 --- a/modules/smartxBidAdapter.js +++ b/modules/smartxBidAdapter.js @@ -1,4 +1,4 @@ -import { logError, deepAccess, isArray, getBidIdParameter, getDNT, generateUUID, isEmpty, _each, logMessage, logWarn, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; @@ -22,37 +22,37 @@ export const spec = { */ isBidRequestValid: function (bid) { if (bid && typeof bid.params !== 'object') { - logError(BIDDER_CODE + ': params is not defined or is incorrect in the bidder settings.'); + utils.logError(BIDDER_CODE + ': params is not defined or is incorrect in the bidder settings.'); return false; } - if (!deepAccess(bid, 'mediaTypes.video')) { - logError(BIDDER_CODE + ': mediaTypes.video is not present in the bidder settings.'); + if (!utils.deepAccess(bid, 'mediaTypes.video')) { + utils.logError(BIDDER_CODE + ': mediaTypes.video is not present in the bidder settings.'); return false; } - const playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); - if (!playerSize || !isArray(playerSize)) { - logError(BIDDER_CODE + ': mediaTypes.video.playerSize is not defined in the bidder settings.'); + const playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); + if (!playerSize || !utils.isArray(playerSize)) { + utils.logError(BIDDER_CODE + ': mediaTypes.video.playerSize is not defined in the bidder settings.'); return false; } - if (!getBidIdParameter('tagId', bid.params)) { - logError(BIDDER_CODE + ': tagId is not present in bidder params'); + if (!utils.getBidIdParameter('tagId', bid.params)) { + utils.logError(BIDDER_CODE + ': tagId is not present in bidder params'); return false; } - if (!getBidIdParameter('publisherId', bid.params)) { - logError(BIDDER_CODE + ': publisherId is not present in bidder params'); + if (!utils.getBidIdParameter('publisherId', bid.params)) { + utils.logError(BIDDER_CODE + ': publisherId is not present in bidder params'); return false; } - if (!getBidIdParameter('siteId', bid.params)) { - logError(BIDDER_CODE + ': siteId is not present in bidder params'); + if (!utils.getBidIdParameter('siteId', bid.params)) { + utils.logError(BIDDER_CODE + ': siteId is not present in bidder params'); return false; } - if (deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { - if (!getBidIdParameter('outstream_options', bid.params)) { - logError(BIDDER_CODE + ': outstream_options parameter is not defined'); + if (utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') { + if (!utils.getBidIdParameter('outstream_options', bid.params)) { + utils.logError(BIDDER_CODE + ': outstream_options parameter is not defined'); return false; } - if (!getBidIdParameter('slot', bid.params.outstream_options)) { - logError(BIDDER_CODE + ': slot parameter is not defined in outstream_options object in the configuration'); + if (!utils.getBidIdParameter('slot', bid.params.outstream_options)) { + utils.logError(BIDDER_CODE + ': slot parameter is not defined in outstream_options object in the configuration'); return false; } } @@ -71,33 +71,33 @@ export const spec = { const isPageSecure = !!page.match(/^https:/) const smartxRequests = bidRequests.map(function (bid) { - const tagId = getBidIdParameter('tagId', bid.params); - const publisherId = getBidIdParameter('publisherId', bid.params); + const tagId = utils.getBidIdParameter('tagId', bid.params); + const publisherId = utils.getBidIdParameter('publisherId', bid.params); const bidfloor = getBidFloor(bid) || 0; - const bidfloorcur = getBidIdParameter('bidfloorcur', bid.params) || 'EUR'; - const siteId = getBidIdParameter('siteId', bid.params); - const domain = getBidIdParameter('domain', bid.params); - const cat = getBidIdParameter('cat', bid.params) || ['']; + const bidfloorcur = utils.getBidIdParameter('bidfloorcur', bid.params) || 'EUR'; + const siteId = utils.getBidIdParameter('siteId', bid.params); + const domain = utils.getBidIdParameter('domain', bid.params); + const cat = utils.getBidIdParameter('cat', bid.params) || ['']; let pubcid = null; - const playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); + const playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); const contentWidth = playerSize[0][0]; const contentHeight = playerSize[0][1]; - const secure = +(isPageSecure || (getBidIdParameter('secure', bid.params) ? 1 : 0)); + const secure = +(isPageSecure || (utils.getBidIdParameter('secure', bid.params) ? 1 : 0)); const ext = { sdk_name: 'Prebid 1+' }; - const mimes = getBidIdParameter('mimes', bid.params) || ['application/javascript', 'video/mp4', 'video/webm']; - const linearity = getBidIdParameter('linearity', bid.params) || 1; - const minduration = getBidIdParameter('minduration', bid.params) || 0; - const maxduration = getBidIdParameter('maxduration', bid.params) || 500; - const startdelay = getBidIdParameter('startdelay', bid.params) || 0; - const minbitrate = getBidIdParameter('minbitrate', bid.params) || 0; - const maxbitrate = getBidIdParameter('maxbitrate', bid.params) || 3500; - const delivery = getBidIdParameter('delivery', bid.params) || [2]; - const pos = getBidIdParameter('pos', bid.params) || 1; - const api = getBidIdParameter('api', bid.params) || [2]; - const protocols = getBidIdParameter('protocols', bid.params) || [2, 3, 5, 6]; - var contextcustom = deepAccess(bid, 'mediaTypes.video.context'); + const mimes = utils.getBidIdParameter('mimes', bid.params) || ['application/javascript', 'video/mp4', 'video/webm']; + const linearity = utils.getBidIdParameter('linearity', bid.params) || 1; + const minduration = utils.getBidIdParameter('minduration', bid.params) || 0; + const maxduration = utils.getBidIdParameter('maxduration', bid.params) || 500; + const startdelay = utils.getBidIdParameter('startdelay', bid.params) || 0; + const minbitrate = utils.getBidIdParameter('minbitrate', bid.params) || 0; + const maxbitrate = utils.getBidIdParameter('maxbitrate', bid.params) || 3500; + const delivery = utils.getBidIdParameter('delivery', bid.params) || [2]; + const pos = utils.getBidIdParameter('pos', bid.params) || 1; + const api = utils.getBidIdParameter('api', bid.params) || [2]; + const protocols = utils.getBidIdParameter('protocols', bid.params) || [2, 3, 5, 6]; + var contextcustom = utils.deepAccess(bid, 'mediaTypes.video.context'); var placement = 1; if (contextcustom === 'outstream') { @@ -141,18 +141,18 @@ export const spec = { const device = { h: screen.height, w: screen.width, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, language: navigator[language].split('-')[0], make: navigator.vendor ? navigator.vendor : '', ua: navigator.userAgent }; - const at = getBidIdParameter('at', bid.params) || 2; + const at = utils.getBidIdParameter('at', bid.params) || 2; - const cur = getBidIdParameter('cur', bid.params) || ['EUR']; + const cur = utils.getBidIdParameter('cur', bid.params) || ['EUR']; const requestPayload = { - id: generateUUID(), + id: utils.generateUUID(), imp: smartxReq, site: { id: siteId, @@ -161,20 +161,11 @@ export const spec = { domain: domain, publisher: { id: publisherId - }, - content: { - ext: { - prebid: { - name: 'pbjs', - version: '$prebid.version$' - } - } } }, device: device, at: at, - cur: cur, - ext: {} + cur: cur }; const userExt = {}; @@ -197,16 +188,14 @@ export const spec = { } // Only add the user object if it's not empty - if (!isEmpty(userExt)) { + if (!utils.isEmpty(userExt)) { requestPayload.user = { ext: userExt }; } - // requestPayload.user.ext.ver = pbjs.version; - // Targeting - if (getBidIdParameter('data', bid.params.user)) { + if (utils.getBidIdParameter('data', bid.params.user)) { var targetingarr = []; for (var i = 0; i < bid.params.user.data.length; i++) { var isemq = (bid.params.user.data[i].name) || 'empty'; @@ -257,9 +246,9 @@ export const spec = { interpretResponse: function (serverResponse, bidderRequest) { const bidResponses = []; const serverResponseBody = serverResponse.body; - if (serverResponseBody && isArray(serverResponseBody.seatbid)) { - _each(serverResponseBody.seatbid, function (bids) { - _each(bids.bid, function (smartxBid) { + if (serverResponseBody && utils.isArray(serverResponseBody.seatbid)) { + utils._each(serverResponseBody.seatbid, function (bids) { + utils._each(bids.bid, function (smartxBid) { let currentBidRequest = {}; for (let i in bidderRequest.bidRequest.bids) { if (smartxBid.impid == bidderRequest.bidRequest.bids[i].bidId) { @@ -270,7 +259,7 @@ export const spec = { * Make sure currency and price are the right ones * TODO: what about the pre_market_bid partners sizes? */ - _each(currentBidRequest.params.pre_market_bids, function (pmb) { + utils._each(currentBidRequest.params.pre_market_bids, function (pmb) { if (pmb.deal_id == smartxBid.id) { smartxBid.price = pmb.price; serverResponseBody.cur = pmb.currency; @@ -296,10 +285,10 @@ export const spec = { bid.meta.advertiserDomains = smartxBid.adomain; } - const context = deepAccess(currentBidRequest, 'mediaTypes.video.context'); + const context = utils.deepAccess(currentBidRequest, 'mediaTypes.video.context'); if (context === 'outstream') { - const playersize = deepAccess(currentBidRequest, 'mediaTypes.video.playerSize'); + const playersize = utils.deepAccess(currentBidRequest, 'mediaTypes.video.playerSize'); const renderer = Renderer.install({ id: 0, url: 'https://dco.smartclip.net/?plc=7777778', @@ -307,27 +296,27 @@ export const spec = { adText: 'SmartX Outstream Video Ad via Prebid.js', player_width: playersize[0][0], player_height: playersize[0][1], - content_page_url: deepAccess(bidderRequest, 'data.site.page'), - ad_mute: +!!deepAccess(currentBidRequest, 'params.ad_mute'), - hide_skin: +!!deepAccess(currentBidRequest, 'params.hide_skin'), - outstream_options: deepAccess(currentBidRequest, 'params.outstream_options') + content_page_url: utils.deepAccess(bidderRequest, 'data.site.page'), + ad_mute: +!!utils.deepAccess(currentBidRequest, 'params.ad_mute'), + hide_skin: +!!utils.deepAccess(currentBidRequest, 'params.hide_skin'), + outstream_options: utils.deepAccess(currentBidRequest, 'params.outstream_options') } }); try { renderer.setRender(createOutstreamConfig); renderer.setEventHandlers({ impression: function impression() { - return logMessage('SmartX outstream video impression event'); + return utils.logMessage('SmartX outstream video impression event'); }, loaded: function loaded() { - return logMessage('SmartX outstream video loaded event'); + return utils.logMessage('SmartX outstream video loaded event'); }, ended: function ended() { - return logMessage('SmartX outstream renderer video event'); + return utils.logMessage('SmartX outstream renderer video event'); } }); } catch (err) { - logWarn('Prebid Error calling setRender or setEventHandlers on renderer', err); + utils.logWarn('Prebid Error calling setRender or setEventHandlers on renderer', err); } bid.renderer = renderer; } @@ -340,21 +329,25 @@ export const spec = { } function createOutstreamConfig(bid) { - let confMinAdWidth = getBidIdParameter('minAdWidth', bid.renderer.config.outstream_options) || 290; - let confMaxAdWidth = getBidIdParameter('maxAdWidth', bid.renderer.config.outstream_options) || 900; - let confStartOpen = getBidIdParameter('startOpen', bid.renderer.config.outstream_options) - let confEndingScreen = getBidIdParameter('endingScreen', bid.renderer.config.outstream_options) - let confTitle = getBidIdParameter('title', bid.renderer.config.outstream_options); - let confSkipOffset = getBidIdParameter('skipOffset', bid.renderer.config.outstream_options); - let confDesiredBitrate = getBidIdParameter('desiredBitrate', bid.renderer.config.outstream_options); - let confVisibilityThreshold = getBidIdParameter('visibilityThreshold', bid.renderer.config.outstream_options); - let elementId = getBidIdParameter('slot', bid.renderer.config.outstream_options) || bid.adUnitCode; - - logMessage('[SMARTX][renderer] Handle SmartX outstream renderer'); + const confMinAdWidth = utils.getBidIdParameter('minAdWidth', bid.renderer.config.outstream_options) || 290; + const confMaxAdWidth = utils.getBidIdParameter('maxAdWidth', bid.renderer.config.outstream_options) || 900; + const confStartOpen = utils.getBidIdParameter('startOpen', bid.renderer.config.outstream_options); + const confEndingScreen = utils.getBidIdParameter('endingScreen', bid.renderer.config.outstream_options); + const confTitle = utils.getBidIdParameter('title', bid.renderer.config.outstream_options); + const confSkipOffset = utils.getBidIdParameter('skipOffset', bid.renderer.config.outstream_options); + const confDesiredBitrate = utils.getBidIdParameter('desiredBitrate', bid.renderer.config.outstream_options); + const elementId = utils.getBidIdParameter('slot', bid.renderer.config.outstream_options) || bid.adUnitCode; + + utils.logMessage('[SMARTX][renderer] Handle SmartX outstream renderer'); var smartPlayObj = { minAdWidth: confMinAdWidth, maxAdWidth: confMaxAdWidth, + title: confTitle, + skipOffset: confSkipOffset, + startOpen: confStartOpen, + endingScreen: confEndingScreen, + desiredBitrate: confDesiredBitrate, onStartCallback: function (m, n) { try { window.sc_smartIntxtStart(n); @@ -372,43 +365,15 @@ function createOutstreamConfig(bid) { }, }; - if (confStartOpen == 'true') { - smartPlayObj.startOpen = true; - } else if (confStartOpen == 'false') { - smartPlayObj.startOpen = false; - } - - if (confEndingScreen == 'true') { - smartPlayObj.endingScreen = true; - } else if (confEndingScreen == 'false') { - smartPlayObj.endingScreen = false; - } - - if (confTitle || (typeof bid.renderer.config.outstream_options.title == 'string' && bid.renderer.config.outstream_options.title == '')) { - smartPlayObj.title = confTitle; - } - - if (confSkipOffset) { - smartPlayObj.skipOffset = confSkipOffset; - } - - if (confDesiredBitrate) { - smartPlayObj.desiredBitrate = confDesiredBitrate; - } - - if (confVisibilityThreshold) { - smartPlayObj.visibilityThreshold = confVisibilityThreshold; - } - smartPlayObj.adResponse = bid.vastContent; const divID = '[id="' + elementId + '"]'; try { // eslint-disable-next-line - let _outstreamPlayer = new OutstreamPlayer(divID, smartPlayObj); + let _outstreamPlayer = new OutstreamPlayer(divID, smartPlayObj); } catch (e) { - logError('[SMARTX][renderer] Error caught: ' + e); + utils.logError('[SMARTX][renderer] Error caught: ' + e); } return smartPlayObj; } @@ -420,17 +385,17 @@ function createOutstreamConfig(bid) { * @returns {*|number} floor price */ function getBidFloor(bid) { - let floor = getBidIdParameter('bidfloor', bid.params); - let floorcur = getBidIdParameter('bidfloorcur', bid.params) || 'EUR'; + let floor = utils.getBidIdParameter('bidfloor', bid.params); + let floorcur = utils.getBidIdParameter('bidfloorcur', bid.params) || 'EUR'; - if (!floor && isFn(bid.getFloor)) { + if (!floor && utils.isFn(bid.getFloor)) { const floorObj = bid.getFloor({ currency: floorcur, mediaType: '*', size: '*' }); - if (isPlainObject(floorObj) && !isNaN(floorObj.floor) && floorObj.currency === floorcur) { + if (utils.isPlainObject(floorObj) && !isNaN(floorObj.floor) && floorObj.currency === floorcur) { floor = floorObj.floor; } } diff --git a/modules/smartxBidAdapter.md b/modules/smartxBidAdapter.md index 853f06d6baf..223e51763b9 100644 --- a/modules/smartxBidAdapter.md +++ b/modules/smartxBidAdapter.md @@ -38,8 +38,8 @@ This adapter requires setup and approval from the smartclip team. maxAdWidth: 900, title: '', skipOffset: 0, - startOpen: 'true', - endingScreen: 'true', + startOpen: true, + endingScreen: true, desiredBitrate: 800, }, } @@ -73,8 +73,8 @@ This adapter requires setup and approval from the smartclip team. maxAdWidth: 900, title: '', skipOffset: 0, - startOpen: 'true', - endingScreen: 'true', + startOpen: true, + endingScreen: true, desiredBitrate: 800, }, user: { diff --git a/modules/smartyadsBidAdapter.js b/modules/smartyadsBidAdapter.js index b999d02b059..610617155ed 100644 --- a/modules/smartyadsBidAdapter.js +++ b/modules/smartyadsBidAdapter.js @@ -1,11 +1,11 @@ -import { logMessage } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'smartyads'; -const AD_URL = 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'; -const URL_SYNC = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a'; +const AD_URL = 'https://ssp-nj.webtradehub.com/?c=o&m=multi'; +const URL_SYNC = 'https://ssp-nj.webtradehub.com/?c=o&m=cookie'; function isBidResponseValid(bid) { if (!bid.requestId || !bid.cpm || !bid.creativeId || @@ -29,7 +29,7 @@ export const spec = { supportedMediaTypes: [BANNER, VIDEO, NATIVE], isBidRequestValid: (bid) => { - return Boolean(bid.bidId && bid.params && !isNaN(bid.params.sourceid) && !isNaN(bid.params.accountid) && bid.params.host == 'prebid'); + return Boolean(bid.bidId && bid.params && !isNaN(bid.params.placementId)); }, buildRequests: (validBidRequests = [], bidderRequest) => { @@ -40,7 +40,7 @@ export const spec = { winTop = window.top; } catch (e) { location = winTop.location; - logMessage(e); + utils.logMessage(e); }; let placements = []; let request = { @@ -68,11 +68,10 @@ export const spec = { let bid = validBidRequests[i]; let traff = bid.params.traffic || BANNER placements.push({ - placementId: bid.params.sourceid, + placementId: bid.params.placementId, bidId: bid.bidId, sizes: bid.mediaTypes && bid.mediaTypes[traff] && bid.mediaTypes[traff].sizes ? bid.mediaTypes[traff].sizes : [], - traffic: traff, - publisherId: bid.params.accountid + traffic: traff }); if (bid.schain) { placements.schain = bid.schain; @@ -97,23 +96,11 @@ export const spec = { return response; }, - getUserSyncs: (syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '') => { - let syncs = []; - let { gdprApplies, consentString = '' } = gdprConsent; - - if (syncOptions.iframeEnabled) { - syncs.push({ - type: 'iframe', - url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&type=iframe&us_privacy=${uspConsent}` - }); - } else { - syncs.push({ - type: 'image', - url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&type=image&us_privacy=${uspConsent}` - }); - } - - return syncs + getUserSyncs: (syncOptions, serverResponses) => { + return [{ + type: 'image', + url: URL_SYNC + }]; } }; diff --git a/modules/smartyadsBidAdapter.md b/modules/smartyadsBidAdapter.md index f078d905e62..4fe4d51a2e6 100644 --- a/modules/smartyadsBidAdapter.md +++ b/modules/smartyadsBidAdapter.md @@ -23,9 +23,7 @@ Module that connects to SmartyAds' demand sources { bidder: 'smartyads', params: { - host: 'prebid', - sourceid: '0', - accountid: '0', + placementId: 0, traffic: 'native' } } @@ -43,9 +41,7 @@ Module that connects to SmartyAds' demand sources { bidder: 'smartyads', params: { - host: 'prebid', - sourceid: '0', - accountid: '0', + placementId: 0, traffic: 'banner' } } @@ -64,9 +60,7 @@ Module that connects to SmartyAds' demand sources { bidder: 'smartyads', params: { - host: 'prebid', - sourceid: '0', - accountid: '0', + placementId: 0, traffic: 'video' } } diff --git a/modules/smilewantedBidAdapter.js b/modules/smilewantedBidAdapter.js index 73bd6101670..65f166566fe 100644 --- a/modules/smilewantedBidAdapter.js +++ b/modules/smilewantedBidAdapter.js @@ -1,4 +1,4 @@ -import { isArray, logError, logWarn, isFn, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -108,13 +108,13 @@ export const spec = { } bidResponse.meta = {}; - if (response.meta && response.meta.advertiserDomains && isArray(response.meta.advertiserDomains)) { + if (response.meta && response.meta.advertiserDomains && utils.isArray(response.meta.advertiserDomains)) { bidResponse.meta.advertiserDomains = response.meta.advertiserDomains; } bidResponses.push(bidResponse); } } catch (error) { - logError('Error while parsing smilewanted response', error); + utils.logError('Error while parsing smilewanted response', error); } return bidResponses; }, @@ -170,7 +170,7 @@ function newRenderer(bidRequest, bidResponse) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on newRenderer', err); + utils.logWarn('Prebid Error calling setRender on newRenderer', err); } return renderer; } @@ -197,13 +197,13 @@ function outstreamRender(bid) { * @returns {*|number} floor price */ function getBidFloor(bid) { - if (isFn(bid.getFloor)) { + if (utils.isFn(bid.getFloor)) { const floorInfo = bid.getFloor({ currency: 'USD', mediaType: 'banner', size: bid.sizes.map(size => ({ w: size[0], h: size[1] })) }); - if (isPlainObject(floorInfo) && !isNaN(floorInfo.floor) && floorInfo.currency === 'USD') { + if (utils.isPlainObject(floorInfo) && !isNaN(floorInfo.floor) && floorInfo.currency === 'USD') { return parseFloat(floorInfo.floor); } } diff --git a/modules/sonobiAnalyticsAdapter.js b/modules/sonobiAnalyticsAdapter.js index 0de6647149a..d69276e915c 100644 --- a/modules/sonobiAnalyticsAdapter.js +++ b/modules/sonobiAnalyticsAdapter.js @@ -1,9 +1,9 @@ -import { deepClone, logInfo, logError } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; import {ajaxBuilder} from '../src/ajax.js'; +const utils = require('../src/utils.js'); let ajax = ajaxBuilder(0); const DEFAULT_EVENT_URL = 'apex.go.sonobi.com/keymaker'; @@ -91,7 +91,7 @@ function addToAuctionQueue(auctionId, id) { if (item.bidid !== id) { return true; } return auction.stats[id].data.p !== item.p; }); - auction.queue.push(deepClone(auction.stats[id].data)); + auction.queue.push(utils.deepClone(auction.stats[id].data)); if (!auction.qTimeout) { auction.qTimeout = setTimeout(() => { sendQueue(auctionId); @@ -102,18 +102,18 @@ function updateBidStats(auctionId, id, data) { let auction = auctionCache[auctionId]; auction.stats[id].data = {...auction.stats[id].data, ...data}; addToAuctionQueue(auctionId, id); - _logInfo('Updated Bid Stats: ', auction.stats[id]); + logInfo('Updated Bid Stats: ', auction.stats[id]); return auction.stats[id]; } function handleOtherEvents(eventType, args) { - _logInfo('Other Event: ' + eventType, args); + logInfo('Other Event: ' + eventType, args); } function handlerAuctionInit(args) { auctionCache[args.auctionId] = buildAuctionEntity(args); deleteOldAuctions(); - _logInfo('Auction Init', args); + logInfo('Auction Init', args); } function handlerBidRequested(args) { let auction = auctionCache[args.auctionId]; @@ -127,14 +127,14 @@ function handlerBidRequested(args) { addToAuctionQueue(args.auctionId, built.bidid); }) - _logInfo('Bids Requested ', data); + logInfo('Bids Requested ', data); } function handlerBidAdjustment(args) { - _logInfo('Bid Adjustment', args); + logInfo('Bid Adjustment', args); } function handlerBidderDone(args) { - _logInfo('Bidder Done', args); + logInfo('Bidder Done', args); } function handlerAuctionEnd(args) { @@ -152,24 +152,24 @@ function handlerAuctionEnd(args) { updateBidStats(args.auctionId, bidId, {response: 4}); } }) - _logInfo('Auction End', args); - _logInfo('Auction Cache', auctionCache[args.auctionId].stats); + logInfo('Auction End', args); + logInfo('Auction Cache', auctionCache[args.auctionId].stats); } function handlerBidWon(args) { let {auctionId, requestId} = args; let res = updateBidStats(auctionId, requestId, {p: 3, response: 6}); - _logInfo('Bid Won ', args); - _logInfo('Bid Update Result: ', res); + logInfo('Bid Won ', args); + logInfo('Bid Update Result: ', res); } function handlerBidResponse(args) { let {auctionId, requestId, cpm, size, timeToRespond} = args; updateBidStats(auctionId, requestId, {bid: cpm, s: size, jsLatency: timeToRespond, latency: timeToRespond, p: 2, response: 9}); - _logInfo('Bid Response ', args); + logInfo('Bid Response ', args); } function handlerBidTimeout(args) { let {auctionId, bidId} = args; - _logInfo('Bid Timeout ', args); + logInfo('Bid Timeout ', args); updateBidStats(auctionId, bidId, {p: 2, response: 0, latency: args.timeout, jsLatency: args.timeout}); } let sonobiAdapter = Object.assign(adapter({url: DEFAULT_EVENT_URL, analyticsType}), { @@ -211,7 +211,7 @@ sonobiAdapter.originEnableAnalytics = sonobiAdapter.enableAnalytics; sonobiAdapter.enableAnalytics = function (config) { if (this.initConfig(config)) { - _logInfo('Analytics adapter enabled', initOptions); + logInfo('Analytics adapter enabled', initOptions); sonobiAdapter.originEnableAnalytics(config); } }; @@ -219,17 +219,17 @@ sonobiAdapter.enableAnalytics = function (config) { sonobiAdapter.initConfig = function (config) { let isCorrectConfig = true; initOptions = {}; - initOptions.options = deepClone(config.options); + initOptions.options = utils.deepClone(config.options); initOptions.pubId = initOptions.options.pubId || null; initOptions.siteId = initOptions.options.siteId || null; initOptions.delay = initOptions.options.delay || QUEUE_TIMEOUT_DEFAULT; if (!initOptions.pubId) { - _logError('"options.pubId" is empty'); + logError('"options.pubId" is empty'); isCorrectConfig = false; } if (!initOptions.siteId) { - _logError('"options.siteId" is empty'); + logError('"options.siteId" is empty'); isCorrectConfig = false; } @@ -247,7 +247,7 @@ sonobiAdapter.sendData = function (auction, data) { let url = 'https://' + initOptions.server + '?pageviewid=' + auction.id + '&corscred=1&pubId=' + initOptions.pubId + '&siteId=' + initOptions.siteId; ajax( url, - function () { _logInfo('Auction [' + auction.id + '] sent ', data); }, + function () { logInfo('Auction [' + auction.id + '] sent ', data); }, JSON.stringify(data), { method: 'POST', @@ -257,12 +257,12 @@ sonobiAdapter.sendData = function (auction, data) { ); } -function _logInfo(message, meta) { - logInfo(buildLogMessage(message), meta); +function logInfo(message, meta) { + utils.logInfo(buildLogMessage(message), meta); } -function _logError(message) { - logError(buildLogMessage(message)); +function logError(message) { + utils.logError(buildLogMessage(message)); } function buildLogMessage(message) { diff --git a/modules/sonobiBidAdapter.js b/modules/sonobiBidAdapter.js index c5fc07320d8..2edcdca1a51 100644 --- a/modules/sonobiBidAdapter.js +++ b/modules/sonobiBidAdapter.js @@ -83,15 +83,8 @@ export const spec = { 'lib_name': 'prebid', 'lib_v': '$prebid.version$', 'us': 0, - }; - const fpd = config.getConfig('ortb2'); - - if (fpd) { - payload.fpd = JSON.stringify(fpd); - } - if (config.getConfig('userSync') && config.getConfig('userSync').syncsPerBidder) { payload.us = config.getConfig('userSync').syncsPerBidder; } @@ -237,7 +230,6 @@ export const spec = { delete bids.width; delete bids.height; } else if (mediaType === 'outstream' && bidRequest) { - delete bids.ad; // Some pubs expect bids.ad to be a vast xml structure, we have a vatUrl so lets delete this. bids.mediaType = 'video'; bids.vastUrl = createCreative(bidResponse.sbi_dc, bid.sbi_aid); bids.renderer = newRenderer(bidRequest.adUnitCode, bids, deepAccess( diff --git a/modules/sortableAnalyticsAdapter.js b/modules/sortableAnalyticsAdapter.js index 76d3ca63d69..73ce1393c23 100644 --- a/modules/sortableAnalyticsAdapter.js +++ b/modules/sortableAnalyticsAdapter.js @@ -1,7 +1,7 @@ -import { logInfo, getParameterByName, getOldestHighestCpmBid } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; +import * as utils from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import {getGlobal} from '../src/prebidGlobal.js'; import { config } from '../src/config.js'; @@ -160,7 +160,7 @@ function getSessionParams() { sessionParams = paramsFromStorage && stillValid(paramsFromStorage) ? paramsFromStorage : null; } sessionParams = sessionParams || {'created': +new Date(), 'sessionId': generateRandomId()}; - const urlParams = UTM_PARAMS.map(getParameterByName); + const urlParams = UTM_PARAMS.map(utils.getParameterByName); if (UTM_PARAMS.every(key => !sessionParams[key])) { UTM_PARAMS.forEach((v, i) => sessionParams[v] = urlParams[i] || sessionParams[v]); sessionParams.created = +new Date(); @@ -318,7 +318,7 @@ function sendEvents(events) { 'method': 'POST', 'withCredentials': true }; - const onSend = () => logInfo('Sortable Analytics data sent'); + const onSend = () => utils.logInfo('Sortable Analytics data sent'); ajax(url, onSend, JSON.stringify(mergedEvents), options); } @@ -444,7 +444,7 @@ function handleAuctionEnd(event) { const events = Object.keys(adUnits).map(adUnitCode => { const bidderKeys = Object.keys(auction.adUnits[adUnitCode].bids); const bids = bidderKeys.map(bidderCode => auction.adUnits[adUnitCode].bids[bidderCode]); - const highestBid = bids.length ? bids.reduce(getOldestHighestCpmBid) : null; + const highestBid = bids.length ? bids.reduce(utils.getOldestHighestCpmBid) : null; return bidderKeys.map(bidderCode => { const bid = auction.adUnits[adUnitCode].bids[bidderCode]; if (highestBid && highestBid.cpm) { @@ -507,7 +507,7 @@ sortableAnalyticsAdapter.originEnableAnalytics = sortableAnalyticsAdapter.enable sortableAnalyticsAdapter.enableAnalytics = function (setupConfig) { if (this.initConfig(setupConfig)) { - logInfo('Sortable Analytics adapter enabled'); + utils.logInfo('Sortable Analytics adapter enabled'); sortableAnalyticsAdapter.originEnableAnalytics(setupConfig); } }; diff --git a/modules/sortableBidAdapter.js b/modules/sortableBidAdapter.js index 15246a10eab..906369eccc3 100644 --- a/modules/sortableBidAdapter.js +++ b/modules/sortableBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, logError, isFn, isPlainObject, isNumber, isStr, deepAccess, parseUrl, _map, getUniqueIdentifierStr, createTrackPixelHtml } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; @@ -55,7 +55,7 @@ function buildNativeRequest(nativeMediaType) { assets.push(setAssetRequired(sponsoredBy, {data: {type: 1}})); } - _each(assets, (asset, id) => asset.id = id); + utils._each(assets, (asset, id) => asset.id = id); return { ver: '1', request: JSON.stringify({ @@ -70,7 +70,7 @@ function tryParseNativeResponse(adm) { try { native = JSON.parse(adm); } catch (e) { - logError('Sortable bid adapter unable to parse native bid response:\n\n' + e); + utils.logError('Sortable bid adapter unable to parse native bid response:\n\n' + e); } return native && native.native; } @@ -92,7 +92,7 @@ function interpretNativeResponse(response) { if (response.link) { native.clickUrl = response.link.url; } - _each(response.assets, asset => { + utils._each(response.assets, asset => { switch (asset.id) { case 1: native.title = asset.title.text; @@ -118,9 +118,9 @@ function interpretNativeResponse(response) { } function transformSyncs(responses, type, syncs) { - _each(responses, res => { + utils._each(responses, res => { if (res.body && res.body.ext && res.body.ext.sync_dsps && res.body.ext.sync_dsps.length) { - _each(res.body.ext.sync_dsps, sync => { + utils._each(res.body.ext.sync_dsps, sync => { if (sync[0] === type && sync[1]) { syncs.push({type, url: sync[1]}); } @@ -130,7 +130,7 @@ function transformSyncs(responses, type, syncs) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return bid.params.floor ? bid.params.floor : null; } @@ -141,7 +141,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; @@ -155,36 +155,36 @@ export const spec = { const sortableConfig = config.getConfig('sortable'); const haveSiteId = (sortableConfig && !!sortableConfig.siteId) || bid.params.siteId; const floor = getBidFloor(bid); - const validFloor = !floor || isNumber(floor); + const validFloor = !floor || utils.isNumber(floor); const validKeywords = !bid.params.keywords || - (isPlainObject(bid.params.keywords) && + (utils.isPlainObject(bid.params.keywords) && Object.keys(bid.params.keywords).every(key => - isStr(key) && isStr(bid.params.keywords[key]) + utils.isStr(key) && utils.isStr(bid.params.keywords[key]) )) const isBanner = !bid.mediaTypes || bid.mediaTypes[BANNER] || !(bid.mediaTypes[NATIVE] || bid.mediaTypes[VIDEO]); - const bannerSizes = isBanner ? deepAccess(bid, `mediaType.${BANNER}.sizes`) || bid.sizes : null; + const bannerSizes = isBanner ? utils.deepAccess(bid, `mediaType.${BANNER}.sizes`) || bid.sizes : null; return !!(bid.params.tagId && haveSiteId && validFloor && validKeywords && (!isBanner || - (bannerSizes && bannerSizes.length > 0 && bannerSizes.every(sizeArr => sizeArr.length == 2 && sizeArr.every(num => isNumber(num)))))); + (bannerSizes && bannerSizes.length > 0 && bannerSizes.every(sizeArr => sizeArr.length == 2 && sizeArr.every(num => utils.isNumber(num)))))); }, buildRequests: function(validBidReqs, bidderRequest) { const sortableConfig = config.getConfig('sortable') || {}; const globalSiteId = sortableConfig.siteId; - let loc = parseUrl(bidderRequest.refererInfo.referer); + let loc = utils.parseUrl(bidderRequest.refererInfo.referer); - const sortableImps = _map(validBidReqs, bid => { + const sortableImps = utils._map(validBidReqs, bid => { const rv = { id: bid.bidId, tagid: bid.params.tagId, ext: {} }; - const bannerMediaType = deepAccess(bid, `mediaTypes.${BANNER}`); - const nativeMediaType = deepAccess(bid, `mediaTypes.${NATIVE}`); - const videoMediaType = deepAccess(bid, `mediaTypes.${VIDEO}`); + const bannerMediaType = utils.deepAccess(bid, `mediaTypes.${BANNER}`); + const nativeMediaType = utils.deepAccess(bid, `mediaTypes.${NATIVE}`); + const videoMediaType = utils.deepAccess(bid, `mediaTypes.${VIDEO}`); if (bannerMediaType || !(nativeMediaType || videoMediaType)) { const bannerSizes = (bannerMediaType && bannerMediaType.sizes) || bid.sizes; rv.banner = { - format: _map(bannerSizes, ([width, height]) => ({w: width, h: height})) + format: utils._map(bannerSizes, ([width, height]) => ({w: width, h: height})) }; } if (nativeMediaType) { @@ -193,9 +193,9 @@ export const spec = { if (videoMediaType && videoMediaType.context === 'instream') { const video = {placement: 1}; video.mimes = videoMediaType.mimes || []; - video.minduration = deepAccess(bid, 'params.video.minduration') || 10; - video.maxduration = deepAccess(bid, 'params.video.maxduration') || 60; - const startDelay = deepAccess(bid, 'params.video.startdelay'); + video.minduration = utils.deepAccess(bid, 'params.video.minduration') || 10; + video.maxduration = utils.deepAccess(bid, 'params.video.maxduration') || 60; + const startDelay = utils.deepAccess(bid, 'params.video.startdelay'); if (startDelay != null) { video.startdelay = startDelay; } @@ -223,18 +223,17 @@ export const spec = { rv.ext.keywords = bid.params.keywords; } if (bid.params.bidderParams) { - _each(bid.params.bidderParams, (params, partner) => { + utils._each(bid.params.bidderParams, (params, partner) => { rv.ext[partner] = params; }); } - rv.ext.gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); return rv; }); const gdprConsent = bidderRequest && bidderRequest.gdprConsent; const bidUserId = validBidReqs[0].userId; const eids = createEidsArray(bidUserId); const sortableBidReq = { - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: sortableImps, source: { ext: { @@ -291,8 +290,8 @@ export const spec = { const { body: {id, seatbid} } = serverResponse; const sortableBids = []; if (id && seatbid) { - _each(seatbid, seatbid => { - _each(seatbid.bid, bid => { + utils._each(seatbid, seatbid => { + utils._each(seatbid.bid, bid => { const bidObj = { requestId: bid.impid, cpm: parseFloat(bid.price), @@ -309,7 +308,7 @@ export const spec = { } }; if (bid.adm) { - const adFormat = deepAccess(bid, 'ext.ad_format') + const adFormat = utils.deepAccess(bid, 'ext.ad_format') if (adFormat === 'native') { let native = tryParseNativeResponse(bid.adm); if (!native) { @@ -324,7 +323,7 @@ export const spec = { bidObj.mediaType = BANNER; bidObj.ad = bid.adm; if (bid.nurl) { - bidObj.ad += createTrackPixelHtml(decodeURIComponent(bid.nurl)); + bidObj.ad += utils.createTrackPixelHtml(decodeURIComponent(bid.nurl)); } } } else if (bid.nurl) { diff --git a/modules/sovrnAnalyticsAdapter.js b/modules/sovrnAnalyticsAdapter.js index aee7ddd2690..0d2576edb05 100644 --- a/modules/sovrnAnalyticsAdapter.js +++ b/modules/sovrnAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { logError, timestamp } from '../src/utils.js'; import adapter from '../src/AnalyticsAdapter.js' import adaptermanager from '../src/adapterManager.js' import CONSTANTS from '../src/constants.json' import {ajaxBuilder} from '../src/ajax.js' +import * as utils from '../src/utils.js' import {config} from '../src/config.js' import find from 'core-js-pure/features/array/find.js' import includes from 'core-js-pure/features/array/includes.js' @@ -112,7 +112,7 @@ sovrnAnalyticsAdapter.enableAnalytics = function (config) { if (config && config.options && (config.options.sovrnId || config.options.affiliateId)) { sovrnId = config.options.sovrnId || config.options.affiliateId; } else { - logError('Need Sovrn Id to log auction results. Please contact a Sovrn representative if you do not know your Sovrn Id.') + utils.logError('Need Sovrn Id to log auction results. Please contact a Sovrn representative if you do not know your Sovrn Id.') return } sovrnAnalyticsAdapter.sovrnId = sovrnId; @@ -149,7 +149,7 @@ class BidWinner { * Sends the auction to the the ingest server */ send() { - this.body.ts = timestamp() + this.body.ts = utils.timestamp() ajax( pbaUrl, null, @@ -269,7 +269,7 @@ class AuctionData { Object.keys(maxBids).forEach(unit => { maxBids[unit].isAuctionWinner = true }) - this.auction.ts = timestamp() + this.auction.ts = utils.timestamp() ajax( pbaUrl, () => { @@ -311,7 +311,7 @@ class LogError { if (ErrorEvent.data && this.error.data.ad) { delete this.error.data.ad } - this.error.ts = timestamp() + this.error.ts = utils.timestamp() ajax( pbaUrl, null, diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 38788036ce0..70883f151b4 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import { BANNER } from '../src/mediaTypes.js' import { createEidsArray } from './userId/eids.js'; @@ -32,7 +32,7 @@ export const spec = { let tpid = [] let criteoId; - _each(bidReqs, function (bid) { + utils._each(bidReqs, function (bid) { if (!eids && bid.userId) { eids = createEidsArray(bid.userId) eids.forEach(function (id) { @@ -48,18 +48,18 @@ export const spec = { if (bid.schain) { schain = schain || bid.schain } - iv = iv || getBidIdParameter('iv', bid.params) + iv = iv || utils.getBidIdParameter('iv', bid.params) let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes - bidSizes = ((isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes]) - bidSizes = bidSizes.filter(size => isArray(size)) + bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]) + bidSizes = bidSizes.filter(size => utils.isArray(size)) const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({ currency: 'USD', mediaType: 'banner', size: '*' }) : {} - floorInfo.floor = floorInfo.floor || getBidIdParameter('bidfloor', bid.params) + floorInfo.floor = floorInfo.floor || utils.getBidIdParameter('bidfloor', bid.params) const imp = { adunitcode: bid.adUnitCode, @@ -69,13 +69,13 @@ export const spec = { w: 1, h: 1, }, - tagid: String(getBidIdParameter('tagid', bid.params)), + tagid: String(utils.getBidIdParameter('tagid', bid.params)), bidfloor: floorInfo.floor } - imp.ext = getBidIdParameter('ext', bid.ortb2Imp) || undefined + imp.ext = utils.getBidIdParameter('ext', bid.ortb2Imp) || undefined - const segmentsString = getBidIdParameter('segments', bid.params) + const segmentsString = utils.getBidIdParameter('segments', bid.params) if (segmentsString) { imp.ext = imp.ext || {} imp.ext.deals = segmentsString.split(',').map(deal => deal.trim()) @@ -83,15 +83,15 @@ export const spec = { sovrnImps.push(imp) }) - const fpd = deepClone(config.getConfig('ortb2')) + const fpd = utils.deepClone(config.getConfig('ortb2')) const site = fpd.site || {} site.page = bidderRequest.refererInfo.referer // clever trick to get the domain - site.domain = parseUrl(site.page).hostname + site.domain = utils.parseUrl(site.page).hostname const sovrnBidReq = { - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: sovrnImps, site: site, user: fpd.user || {} @@ -106,18 +106,18 @@ export const spec = { } if (bidderRequest.gdprConsent) { - deepSetValue(sovrnBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); - deepSetValue(sovrnBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString) + utils.deepSetValue(sovrnBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); + utils.deepSetValue(sovrnBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString) } if (bidderRequest.uspConsent) { - deepSetValue(sovrnBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(sovrnBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (eids) { - deepSetValue(sovrnBidReq, 'user.ext.eids', eids) - deepSetValue(sovrnBidReq, 'user.ext.tpid', tpid) + utils.deepSetValue(sovrnBidReq, 'user.ext.eids', eids) + utils.deepSetValue(sovrnBidReq, 'user.ext.tpid', tpid) if (criteoId) { - deepSetValue(sovrnBidReq, 'user.ext.prebid_criteoid', criteoId) + utils.deepSetValue(sovrnBidReq, 'user.ext.prebid_criteoid', criteoId) } } @@ -131,7 +131,7 @@ export const spec = { options: {contentType: 'text/plain'} } } catch (e) { - logError('Could not build bidrequest, error deatils:', e); + utils.logError('Could not build bidrequest, error deatils:', e); } }, @@ -167,7 +167,7 @@ export const spec = { } return sovrnBidResponses } catch (e) { - logError('Could not intrepret bidresponse, error deatils:', e); + utils.logError('Could not intrepret bidresponse, error deatils:', e); } }, @@ -176,7 +176,7 @@ export const spec = { const tracks = [] if (serverResponses && serverResponses.length !== 0) { if (syncOptions.iframeEnabled) { - const iidArr = serverResponses.filter(resp => deepAccess(resp, 'body.ext.iid')) + const iidArr = serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.iid')) .map(resp => resp.body.ext.iid); const params = []; if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { @@ -196,7 +196,7 @@ export const spec = { } if (syncOptions.pixelEnabled) { - serverResponses.filter(resp => deepAccess(resp, 'body.ext.sync.pixels')) + serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.sync.pixels')) .reduce((acc, resp) => acc.concat(resp.body.ext.sync.pixels), []) .map(pixel => pixel.url) .forEach(url => tracks.push({ type: 'image', url })) diff --git a/modules/spotxBidAdapter.js b/modules/spotxBidAdapter.js index 7d5865684a7..e18c0d3ba3e 100644 --- a/modules/spotxBidAdapter.js +++ b/modules/spotxBidAdapter.js @@ -1,4 +1,4 @@ -import { logError, deepAccess, isArray, getBidIdParameter, getDNT, deepSetValue, isEmpty, _each, logMessage, logWarn, isBoolean, isNumber, isPlainObject, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { Renderer } from '../src/Renderer.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; @@ -24,34 +24,34 @@ export const spec = { */ isBidRequestValid: function(bid) { if (bid && typeof bid.params !== 'object') { - logError(BIDDER_CODE + ': params is not defined or is incorrect in the bidder settings.'); + utils.logError(BIDDER_CODE + ': params is not defined or is incorrect in the bidder settings.'); return false; } - if (!deepAccess(bid, 'mediaTypes.video')) { - logError(BIDDER_CODE + ': mediaTypes.video is not present in the bidder settings.'); + if (!utils.deepAccess(bid, 'mediaTypes.video')) { + utils.logError(BIDDER_CODE + ': mediaTypes.video is not present in the bidder settings.'); return false; } - const playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); - if (!playerSize || !isArray(playerSize)) { - logError(BIDDER_CODE + ': mediaTypes.video.playerSize is not defined in the bidder settings.'); + const playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); + if (!playerSize || !utils.isArray(playerSize)) { + utils.logError(BIDDER_CODE + ': mediaTypes.video.playerSize is not defined in the bidder settings.'); return false; } - if (!getBidIdParameter('channel_id', bid.params)) { - logError(BIDDER_CODE + ': channel_id is not present in bidder params'); + if (!utils.getBidIdParameter('channel_id', bid.params)) { + utils.logError(BIDDER_CODE + ': channel_id is not present in bidder params'); return false; } - if (deepAccess(bid, 'mediaTypes.video.context') == 'outstream' || deepAccess(bid, 'params.ad_unit') == 'outstream') { - if (!getBidIdParameter('outstream_function', bid.params)) { - if (!getBidIdParameter('outstream_options', bid.params)) { - logError(BIDDER_CODE + ': please define outstream_options parameter or override the default SpotX outstream rendering by defining your own Outstream function using field outstream_function.'); + if (utils.deepAccess(bid, 'mediaTypes.video.context') == 'outstream' || utils.deepAccess(bid, 'params.ad_unit') == 'outstream') { + if (!utils.getBidIdParameter('outstream_function', bid.params)) { + if (!utils.getBidIdParameter('outstream_options', bid.params)) { + utils.logError(BIDDER_CODE + ': please define outstream_options parameter or override the default SpotX outstream rendering by defining your own Outstream function using field outstream_function.'); return false; } - if (!getBidIdParameter('slot', bid.params.outstream_options)) { - logError(BIDDER_CODE + ': please define parameter slot in outstream_options object in the configuration.'); + if (!utils.getBidIdParameter('slot', bid.params.outstream_options)) { + utils.logError(BIDDER_CODE + ': please define parameter slot in outstream_options object in the configuration.'); return false; } } @@ -75,54 +75,54 @@ export const spec = { const siteId = ''; const spotxRequests = bidRequests.map(function(bid) { let page; - if (getBidIdParameter('page', bid.params)) { - page = getBidIdParameter('page', bid.params); + if (utils.getBidIdParameter('page', bid.params)) { + page = utils.getBidIdParameter('page', bid.params); } else if (config.getConfig('pageUrl')) { page = config.getConfig('pageUrl'); } else { page = referer; } - const channelId = getBidIdParameter('channel_id', bid.params); + const channelId = utils.getBidIdParameter('channel_id', bid.params); let pubcid = null; - const playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); + const playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); const contentWidth = playerSize[0][0]; const contentHeight = playerSize[0][1]; - const secure = isPageSecure || (getBidIdParameter('secure', bid.params) ? 1 : 0); + const secure = isPageSecure || (utils.getBidIdParameter('secure', bid.params) ? 1 : 0); const ext = { sdk_name: 'Prebid 1+', versionOrtb: ORTB_VERSION }; - if (getBidIdParameter('hide_skin', bid.params) != '') { - ext.hide_skin = +!!getBidIdParameter('hide_skin', bid.params); + if (utils.getBidIdParameter('hide_skin', bid.params) != '') { + ext.hide_skin = +!!utils.getBidIdParameter('hide_skin', bid.params); } - if (getBidIdParameter('ad_volume', bid.params) != '') { - ext.ad_volume = getBidIdParameter('ad_volume', bid.params); + if (utils.getBidIdParameter('ad_volume', bid.params) != '') { + ext.ad_volume = utils.getBidIdParameter('ad_volume', bid.params); } - if (getBidIdParameter('ad_unit', bid.params) != '') { - ext.ad_unit = getBidIdParameter('ad_unit', bid.params); + if (utils.getBidIdParameter('ad_unit', bid.params) != '') { + ext.ad_unit = utils.getBidIdParameter('ad_unit', bid.params); } - if (getBidIdParameter('outstream_options', bid.params) != '') { - ext.outstream_options = getBidIdParameter('outstream_options', bid.params); + if (utils.getBidIdParameter('outstream_options', bid.params) != '') { + ext.outstream_options = utils.getBidIdParameter('outstream_options', bid.params); } - if (getBidIdParameter('outstream_function', bid.params) != '') { - ext.outstream_function = getBidIdParameter('outstream_function', bid.params); + if (utils.getBidIdParameter('outstream_function', bid.params) != '') { + ext.outstream_function = utils.getBidIdParameter('outstream_function', bid.params); } - if (getBidIdParameter('custom', bid.params) != '') { - ext.custom = getBidIdParameter('custom', bid.params); + if (utils.getBidIdParameter('custom', bid.params) != '') { + ext.custom = utils.getBidIdParameter('custom', bid.params); } - if (getBidIdParameter('pre_market_bids', bid.params) != '' && isArray(getBidIdParameter('pre_market_bids', bid.params))) { - const preMarketBids = getBidIdParameter('pre_market_bids', bid.params); + if (utils.getBidIdParameter('pre_market_bids', bid.params) != '' && utils.isArray(utils.getBidIdParameter('pre_market_bids', bid.params))) { + const preMarketBids = utils.getBidIdParameter('pre_market_bids', bid.params); ext.pre_market_bids = []; for (let i in preMarketBids) { const preMarketBid = preMarketBids[i]; @@ -150,7 +150,7 @@ export const spec = { } } - const mimes = getBidIdParameter('mimes', bid.params) || ['application/javascript', 'video/mp4', 'video/webm']; + const mimes = utils.getBidIdParameter('mimes', bid.params) || ['application/javascript', 'video/mp4', 'video/webm']; const spotxReq = { id: bid.bidId, @@ -163,38 +163,24 @@ export const spec = { } }; - if (isFn(bid.getFloor)) { - let floorInfo = bid.getFloor({ - currency: 'USD', - mediaType: 'video', - size: '*' - }); - - if (floorInfo.currency === 'USD') { - spotxReq.bidfloor = floorInfo.floor; - } - } else if (getBidIdParameter('price_floor', bid.params) != '') { - spotxReq.bidfloor = getBidIdParameter('price_floor', bid.params); - } - - if (getBidIdParameter('start_delay', bid.params) != '') { - spotxReq.video.startdelay = 0 + Boolean(getBidIdParameter('start_delay', bid.params)); + if (utils.getBidIdParameter('start_delay', bid.params) != '') { + spotxReq.video.startdelay = 0 + Boolean(utils.getBidIdParameter('start_delay', bid.params)); } - if (getBidIdParameter('min_duration', bid.params) != '') { - spotxReq.video.minduration = getBidIdParameter('min_duration', bid.params); + if (utils.getBidIdParameter('min_duration', bid.params) != '') { + spotxReq.video.minduration = utils.getBidIdParameter('min_duration', bid.params); } - if (getBidIdParameter('max_duration', bid.params) != '') { - spotxReq.video.maxduration = getBidIdParameter('max_duration', bid.params); + if (utils.getBidIdParameter('max_duration', bid.params) != '') { + spotxReq.video.maxduration = utils.getBidIdParameter('max_duration', bid.params); } - if (getBidIdParameter('placement_type', bid.params) != '') { - spotxReq.video.ext.placement = getBidIdParameter('placement_type', bid.params); + if (utils.getBidIdParameter('placement_type', bid.params) != '') { + spotxReq.video.ext.placement = utils.getBidIdParameter('placement_type', bid.params); } - if (getBidIdParameter('position', bid.params) != '') { - spotxReq.video.ext.pos = getBidIdParameter('position', bid.params); + if (utils.getBidIdParameter('position', bid.params) != '') { + spotxReq.video.ext.pos = utils.getBidIdParameter('position', bid.params); } if (bid.crumbs && bid.crumbs.pubcid) { @@ -205,7 +191,7 @@ export const spec = { const device = { h: screen.height, w: screen.width, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, language: navigator[language].split('-')[0], make: navigator.vendor ? navigator.vendor : '', ua: navigator.userAgent @@ -231,13 +217,13 @@ export const spec = { requestPayload['ext']['wrap_response'] = 0; } - if (getBidIdParameter('number_of_ads', bid.params)) { - requestPayload['ext']['number_of_ads'] = getBidIdParameter('number_of_ads', bid.params); + if (utils.getBidIdParameter('number_of_ads', bid.params)) { + requestPayload['ext']['number_of_ads'] = utils.getBidIdParameter('number_of_ads', bid.params); } const userExt = {}; - if (getBidIdParameter('spotx_all_google_consent', bid.params) == 1) { + if (utils.getBidIdParameter('spotx_all_google_consent', bid.params) == 1) { userExt['consented_providers_settings'] = GOOGLE_CONSENT; } @@ -246,16 +232,16 @@ export const spec = { userExt.consent = bidderRequest.gdprConsent.consentString; if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') { - deepSetValue(requestPayload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(requestPayload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } } if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(requestPayload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(requestPayload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } // ID5 fied - if (deepAccess(bid, 'userId.id5id.uid')) { + if (utils.deepAccess(bid, 'userId.id5id.uid')) { userExt.eids = userExt.eids || []; userExt.eids.push( { @@ -298,7 +284,7 @@ export const spec = { } // Only add the user object if it's not empty - if (!isEmpty(userExt)) { + if (!utils.isEmpty(userExt)) { requestPayload.user = { ext: userExt }; } const urlQueryParams = 'src_sys=prebid' @@ -323,9 +309,9 @@ export const spec = { const bidResponses = []; const serverResponseBody = serverResponse.body; - if (serverResponseBody && isArray(serverResponseBody.seatbid)) { - _each(serverResponseBody.seatbid, function(bids) { - _each(bids.bid, function(spotxBid) { + if (serverResponseBody && utils.isArray(serverResponseBody.seatbid)) { + utils._each(serverResponseBody.seatbid, function(bids) { + utils._each(bids.bid, function(spotxBid) { let currentBidRequest = {}; for (let i in bidderRequest.bidRequest.bids) { if (spotxBid.impid == bidderRequest.bidRequest.bids[i].bidId) { @@ -337,7 +323,7 @@ export const spec = { * Make sure currency and price are the right ones * TODO: what about the pre_market_bid partners sizes? */ - _each(currentBidRequest.params.pre_market_bids, function(pmb) { + utils._each(currentBidRequest.params.pre_market_bids, function(pmb) { if (pmb.deal_id == spotxBid.id) { spotxBid.price = pmb.price; serverResponseBody.cur = pmb.currency; @@ -371,10 +357,10 @@ export const spec = { bid.meta.advertiserDomains = spotxBid.adomain; } - const context1 = deepAccess(currentBidRequest, 'mediaTypes.video.context'); - const context2 = deepAccess(currentBidRequest, 'params.ad_unit'); + const context1 = utils.deepAccess(currentBidRequest, 'mediaTypes.video.context'); + const context2 = utils.deepAccess(currentBidRequest, 'params.ad_unit'); if (context1 == 'outstream' || context2 == 'outstream') { - const playersize = deepAccess(currentBidRequest, 'mediaTypes.video.playerSize'); + const playersize = utils.deepAccess(currentBidRequest, 'mediaTypes.video.playerSize'); const renderer = Renderer.install({ id: 0, url: '/', @@ -382,11 +368,11 @@ export const spec = { adText: 'SpotX Outstream Video Ad via Prebid.js', player_width: playersize[0][0], player_height: playersize[0][1], - content_page_url: deepAccess(bidderRequest, 'data.site.page'), - ad_mute: +!!deepAccess(currentBidRequest, 'params.ad_mute'), - hide_skin: +!!deepAccess(currentBidRequest, 'params.hide_skin'), - outstream_options: deepAccess(currentBidRequest, 'params.outstream_options'), - outstream_function: deepAccess(currentBidRequest, 'params.outstream_function') + content_page_url: utils.deepAccess(bidderRequest, 'data.site.page'), + ad_mute: +!!utils.deepAccess(currentBidRequest, 'params.ad_mute'), + hide_skin: +!!utils.deepAccess(currentBidRequest, 'params.hide_skin'), + outstream_options: utils.deepAccess(currentBidRequest, 'params.outstream_options'), + outstream_function: utils.deepAccess(currentBidRequest, 'params.outstream_function') } }); @@ -394,17 +380,17 @@ export const spec = { renderer.setRender(outstreamRender); renderer.setEventHandlers({ impression: function impression() { - return logMessage('SpotX outstream video impression event'); + return utils.logMessage('SpotX outstream video impression event'); }, loaded: function loaded() { - return logMessage('SpotX outstream video loaded event'); + return utils.logMessage('SpotX outstream video loaded event'); }, ended: function ended() { - logMessage('SpotX outstream renderer video event'); + utils.logMessage('SpotX outstream renderer video event'); } }); } catch (err) { - logWarn('Prebid Error calling setRender or setEventHandlers on renderer', err); + utils.logWarn('Prebid Error calling setRender or setEventHandlers on renderer', err); } bid.renderer = renderer; } @@ -419,8 +405,8 @@ export const spec = { } function createOutstreamScript(bid) { - const slot = getBidIdParameter('slot', bid.renderer.config.outstream_options); - logMessage('[SPOTX][renderer] Handle SpotX outstream renderer'); + const slot = utils.getBidIdParameter('slot', bid.renderer.config.outstream_options); + utils.logMessage('[SPOTX][renderer] Handle SpotX outstream renderer'); const script = window.document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://js.spotx.tv/easi/v1/' + bid.channel_id + '.js'; @@ -430,8 +416,8 @@ function createOutstreamScript(bid) { dataSpotXParams['data-spotx_content_page_url'] = bid.renderer.config.content_page_url; dataSpotXParams['data-spotx_ad_unit'] = 'incontent'; - logMessage('[SPOTX][renderer] Default behavior'); - if (getBidIdParameter('ad_mute', bid.renderer.config.outstream_options)) { + utils.logMessage('[SPOTX][renderer] Default behavior'); + if (utils.getBidIdParameter('ad_mute', bid.renderer.config.outstream_options)) { dataSpotXParams['data-spotx_ad_mute'] = '1'; } dataSpotXParams['data-spotx_collapse'] = '0'; @@ -439,9 +425,9 @@ function createOutstreamScript(bid) { dataSpotXParams['data-spotx_blocked_autoplay_override_mode'] = '1'; dataSpotXParams['data-spotx_video_slot_can_autoplay'] = '1'; - const playersizeAutoAdapt = getBidIdParameter('playersize_auto_adapt', bid.renderer.config.outstream_options); - if (playersizeAutoAdapt && isBoolean(playersizeAutoAdapt) && playersizeAutoAdapt === true) { - const ratio = bid.width && isNumber(bid.width) && bid.height && isNumber(bid.height) ? bid.width / bid.height : 4 / 3; + const playersizeAutoAdapt = utils.getBidIdParameter('playersize_auto_adapt', bid.renderer.config.outstream_options); + if (playersizeAutoAdapt && utils.isBoolean(playersizeAutoAdapt) && playersizeAutoAdapt === true) { + const ratio = bid.width && utils.isNumber(bid.width) && bid.height && utils.isNumber(bid.height) ? bid.width / bid.height : 4 / 3; const slotClientWidth = window.document.getElementById(slot).clientWidth; let playerWidth = bid.renderer.config.player_width; let playerHeight = bid.renderer.config.player_height; @@ -463,13 +449,13 @@ function createOutstreamScript(bid) { dataSpotXParams['data-spotx_content_height'] = '' + contentHeight; } - const customOverride = getBidIdParameter('custom_override', bid.renderer.config.outstream_options); - if (customOverride && isPlainObject(customOverride)) { - logMessage('[SPOTX][renderer] Custom behavior.'); + const customOverride = utils.getBidIdParameter('custom_override', bid.renderer.config.outstream_options); + if (customOverride && utils.isPlainObject(customOverride)) { + utils.logMessage('[SPOTX][renderer] Custom behavior.'); for (let name in customOverride) { if (customOverride.hasOwnProperty(name)) { if (name === 'channel_id' || name === 'vast_url' || name === 'content_page_url' || name === 'ad_unit') { - logWarn('[SPOTX][renderer] Custom behavior: following option cannot be overridden: ' + name); + utils.logWarn('[SPOTX][renderer] Custom behavior: following option cannot be overridden: ' + name); } else { dataSpotXParams['data-spotx_' + name] = customOverride[name]; } @@ -492,7 +478,7 @@ function outstreamRender(bid) { bid.renderer.config.outstream_function(bid, script); } else { try { - const inIframe = getBidIdParameter('in_iframe', bid.renderer.config.outstream_options); + const inIframe = utils.getBidIdParameter('in_iframe', bid.renderer.config.outstream_options); if (inIframe && window.document.getElementById(inIframe).nodeName == 'IFRAME') { const rawframe = window.document.getElementById(inIframe); let framedoc = rawframe.contentDocument; @@ -501,7 +487,7 @@ function outstreamRender(bid) { } framedoc.body.appendChild(script); } else { - const slot = getBidIdParameter('slot', bid.renderer.config.outstream_options); + const slot = utils.getBidIdParameter('slot', bid.renderer.config.outstream_options); if (slot && window.document.getElementById(slot)) { window.document.getElementById(slot).appendChild(script); } else { @@ -509,7 +495,7 @@ function outstreamRender(bid) { } } } catch (err) { - logError('[SPOTX][renderer] Error:' + err.message) + utils.logError('[SPOTX][renderer] Error:' + err.message) } } } diff --git a/modules/sspBCBidAdapter.js b/modules/sspBCBidAdapter.js index c8f3c138ce4..15e0baa811f 100644 --- a/modules/sspBCBidAdapter.js +++ b/modules/sspBCBidAdapter.js @@ -1,7 +1,7 @@ -import { isArray, deepAccess, logWarn, parseUrl } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import { BANNER } from '../src/mediaTypes.js'; import strIncludes from 'core-js-pure/features/string/includes.js'; const BIDDER_CODE = 'sspBC'; @@ -9,13 +9,11 @@ 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.3'; +const BIDDER_VERSION = '5.0'; const W = window; const { navigator } = W; const oneCodeDetection = {}; -const adUnitsCalled = {}; const adSizesCalled = {}; -const pageView = {}; var consentApiVersion; /** @@ -24,7 +22,7 @@ var consentApiVersion; */ const getNotificationPayload = bidData => { if (bidData) { - const bids = isArray(bidData) ? bidData : [bidData]; + const bids = utils.isArray(bidData) ? bidData : [bidData]; if (bids.length > 0) { const result = { requestId: undefined, @@ -33,7 +31,7 @@ const getNotificationPayload = bidData => { slotId: [], } bids.forEach(bid => { - let params = isArray(bid.params) ? bid.params[0] : bid.params; + let params = utils.isArray(bid.params) ? bid.params[0] : bid.params; params = params || {}; // check for stored detection @@ -72,7 +70,6 @@ const cookieSupport = () => { }; const applyClientHints = ortbRequest => { - const { location } = document; const { connection = {}, deviceMemory, userAgentData = {} } = navigator; const viewport = W.visualViewport || false; const segments = []; @@ -88,16 +85,6 @@ 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]; @@ -113,14 +100,6 @@ const applyClientHints = ortbRequest => { id: '12', name: 'NetInfo', segment: segments, - }, { - id: '7', - name: 'pvid', - segment: [ - { - value: `${pageView.id}` - } - ] }]; ortbRequest.user = Object.assign(ortbRequest.user, { data }); @@ -143,14 +122,13 @@ const applyGdpr = (bidderRequest, ortbRequest) => { /** * Get value for first occurence of key within the collection */ -const setOnAny = (collection, key) => collection.reduce((prev, next) => prev || deepAccess(next, key), false); +const setOnAny = (collection, key) => collection.reduce((prev, next) => prev || utils.deepAccess(next, key), false); /** * Send payload to notification endpoint */ const sendNotification = payload => { ajax(NOTIFY_URL, null, JSON.stringify(payload), { - contentType: 'application/json', withCredentials: false, method: 'POST', crossOrigin: true @@ -163,7 +141,7 @@ const sendNotification = payload => { */ const mapBanner = slot => { if (slot.mediaType === 'banner' || - deepAccess(slot, 'mediaTypes.banner') || + utils.deepAccess(slot, 'mediaTypes.banner') || (!slot.mediaType && !slot.mediaTypes)) { const format = slot.sizes.map(size => ({ w: size[0], @@ -177,108 +155,6 @@ const mapBanner = slot => { } } -/** - * @param {string} paramName Native parameter name - * @param {object} paramValue Native parameter value - * @returns {object} native asset object that conforms to ortb native ads spec - */ -const mapAsset = (paramName, paramValue) => { - let asset; - switch (paramName) { - case 'title': - asset = { - id: 0, - required: paramValue.required, - title: { len: paramValue.len } - } - break; - case 'cta': - asset = { - id: 1, - required: paramValue.required, - data: { type: 12 } - } - break; - case 'icon': - asset = { - id: 2, - required: paramValue.required, - img: { type: 1, w: paramValue.sizes[0], h: paramValue.sizes[1] } - } - break; - case 'image': - asset = { - id: 3, - required: paramValue.required, - img: { type: 3, w: paramValue.sizes[0], h: paramValue.sizes[1] } - } - break; - case 'body': - asset = { - id: 4, - required: paramValue.required, - data: { type: 2 } - } - break; - case 'sponsoredBy': - asset = { - id: 5, - required: paramValue.required, - data: { type: 1 } - } - break; - } - return asset; -} - -/** - * @param {object} slot Ad Unit Params by Prebid - * @returns {object} native object that conforms to ortb native ads spec - */ -const mapNative = slot => { - const native = deepAccess(slot, 'mediaTypes.native'); - let assets; - if (native) { - const nativeParams = Object.keys(native); - assets = []; - nativeParams.forEach(par => { - const newAsset = mapAsset(par, native[par]); - if (newAsset) { assets.push(newAsset) }; - }); - } - return assets ? { request: JSON.stringify({ native: { assets } }) } : undefined; -} - -var mapVideo = slot => { - var video = deepAccess(slot, 'mediaTypes.video'); - var videoParamsUsed = ['api', 'context', 'linearity', 'maxduration', 'mimes', 'protocols']; - var videoAssets; - - if (video) { - var videoParams = Object.keys(video); - var playerSize = video.playerSize; - videoAssets = {}; // player width / height - - if (playerSize) { - var maxSize = playerSize.reduce(function (prev, next) { - return next[0] >= prev[0] && next[1] >= prev[1] ? next : prev; - }, [1, 1]); - videoAssets.w = maxSize[0]; - videoAssets.h = maxSize[1]; - } // remaining supported params - - videoParams.forEach(function (par) { - if (videoParamsUsed.indexOf(par) >= 0) { - videoAssets[par] = video[par]; - } - - ; - }); - } - - return videoAssets; -}; - const mapImpression = slot => { const { adUnitCode, bidId, params = {}, ortb2Imp = {} } = slot; const { id, siteId } = params; @@ -289,109 +165,32 @@ 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'; - - 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); + adSizesCalled[slotSize] = adSizesCalled[slotSize] ? adSizesCalled[slotSize] + 1 : 1; + ext.data = Object.assign({ pbsize: `${slotSize}_${adSizesCalled[slotSize]}` }, ext.data); const imp = { id: id && siteId ? id : 'bidid-' + bidId, banner: mapBanner(slot), - native: mapNative(slot), - video: mapVideo(slot), + // native: mapNative(slot), tagid: adUnitCode, ext, }; // Check floorprices for this imp if (typeof slot.getFloor === 'function') { - var bannerFloor = 0; - var nativeFloor = 0; - var videoFloor = 0; // sspBC adapter accepts only floor per imp - check for maximum value for requested ad types and sizes - + let bannerFloor = 0; + // sspBC adapter accepts only floor per imp - check for maximum value for requested ad types and sizes if (slot.sizes.length) { - bannerFloor = slot.sizes.reduce(function (prev, next) { - var currentFloor = slot.getFloor({ - mediaType: 'banner', - size: next - }).floor; + bannerFloor = slot.sizes.reduce((prev, next) => { + const currentFloor = slot.getFloor({ mediaType: 'banner', size: next }).floor; return prev > currentFloor ? prev : currentFloor; }, 0); } - - nativeFloor = slot.getFloor({ - mediaType: 'native' - }); - videoFloor = slot.getFloor({ - mediaType: 'video' - }); - imp.bidfloor = Math.max(bannerFloor, nativeFloor, videoFloor); + imp.bidfloor = bannerFloor; } return imp; } -const isVideoAd = bid => { - const xmlTester = new RegExp(/^<\?xml/); - return bid.adm && bid.adm.match(xmlTester); -} - -const isNativeAd = bid => { - const xmlTester = new RegExp(/^{['"]native['"]/); - - return bid.adm && bid.adm.match(xmlTester); -} - -const parseNative = nativeData => { - const result = {}; - nativeData.assets.forEach(asset => { - const id = parseInt(asset.id); - switch (id) { - case 0: - result.title = asset.title.text; - break; - case 1: - result.cta = asset.data.value; - break; - case 2: - result.icon = { - url: asset.img.url, - width: asset.img.w, - height: asset.img.h, - }; - break; - case 3: - result.image = { - url: asset.img.url, - width: asset.img.w, - height: asset.img.h, - }; - break; - case 4: - result.body = asset.data.value; - break; - case 5: - result.sponsoredBy = asset.data.value; - break; - - default: - logWarn('Unrecognized native asset', asset); - } - }); - result.clickUrl = nativeData.link.url; - result.impressionTrackers = nativeData.imptrackers; - - if (isArray(nativeData.jstracker)) { - result.javascriptTrackers = nativeData.jstracker; - } else if (nativeData.jstracker) { - result.javascriptTrackers = [nativeData.jstracker]; - } - return result; -} - const renderCreative = (site, auctionId, bid, seat, request) => { let gam; @@ -426,7 +225,7 @@ const renderCreative = (site, auctionId, bid, seat, request) => { gam.targeting = {}; } } catch (err) { - logWarn('Could not parse adm data', bid.adm); + utils.logWarn('Could not parse adm data', bid.adm); } } @@ -444,7 +243,6 @@ const renderCreative = (site, auctionId, bid, seat, request) => { - - - `; -} - -registerBidder(spec); diff --git a/modules/targetVideoBidAdapter.md b/modules/targetVideoBidAdapter.md deleted file mode 100644 index 557c9f94410..00000000000 --- a/modules/targetVideoBidAdapter.md +++ /dev/null @@ -1,34 +0,0 @@ -# Overview - -``` -Module Name: Target Video Bid Adapter -Module Type: Bidder Adapter -Maintainer: grajzer@gmail.com -``` - -# Description - -Connects to Appnexus exchange for bids. - -TargetVideo bid adapter supports Banner. - -# Test Parameters -``` -var adUnits = [ - // Banner adUnit - { - code: 'banner-div', - mediaTypes: { - banner: { - sizes: [[640, 480], [300, 250]], - } - }, - bids: [{ - bidder: 'targetVideo', - params: { - placementId: 13232361 - } - }] - } -]; -``` diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 4bea8858d98..5e6062e5483 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -1,6 +1,6 @@ -import { getValue, logError, deepAccess, getBidIdParameter, parseSizesInput, isArray } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; +import * as utils from '../src/utils.js'; const BIDDER_CODE = 'teads'; const GVL_ID = 132; @@ -27,13 +27,13 @@ export const spec = { isBidRequestValid: function(bid) { let isValid = false; if (typeof bid.params !== 'undefined') { - let isValidPlacementId = _validateId(getValue(bid.params, 'placementId')); - let isValidPageId = _validateId(getValue(bid.params, 'pageId')); + let isValidPlacementId = _validateId(utils.getValue(bid.params, 'placementId')); + let isValidPageId = _validateId(utils.getValue(bid.params, 'pageId')); isValid = isValidPlacementId && isValidPageId; } if (!isValid) { - logError('Teads placementId and pageId parameters are required. Bid aborted.'); + utils.logError('Teads placementId and pageId parameters are required. Bid aborted.'); } return isValid; }, @@ -54,8 +54,8 @@ export const spec = { data: bids, deviceWidth: screen.width, hb_version: '$prebid.version$', - ...getFLoCParameters(deepAccess(validBidRequests, '0.userId.flocId')), - ...getUnifiedId2Parameter(deepAccess(validBidRequests, '0.userId.uid2')), + ...getFLoCParameters(utils.deepAccess(validBidRequests, '0.userId.flocId')), + ...getUnifiedId2Parameter(utils.deepAccess(validBidRequests, '0.userId.uid2')), ...getFirstPartyTeadsIdParameter() }; @@ -188,37 +188,35 @@ function isGlobalConsent(gdprData, apiVersion) { function buildRequestObject(bid) { const reqObj = {}; - let placementId = getValue(bid.params, 'placementId'); - let pageId = getValue(bid.params, 'pageId'); - const gpid = deepAccess(bid, 'ortb2Imp.ext.gpid'); + let placementId = utils.getValue(bid.params, 'placementId'); + let pageId = utils.getValue(bid.params, 'pageId'); reqObj.sizes = getSizes(bid); - reqObj.bidId = getBidIdParameter('bidId', bid); - reqObj.bidderRequestId = getBidIdParameter('bidderRequestId', bid); + reqObj.bidId = utils.getBidIdParameter('bidId', bid); + reqObj.bidderRequestId = utils.getBidIdParameter('bidderRequestId', bid); reqObj.placementId = parseInt(placementId, 10); reqObj.pageId = parseInt(pageId, 10); - reqObj.adUnitCode = getBidIdParameter('adUnitCode', bid); - reqObj.auctionId = getBidIdParameter('auctionId', bid); - reqObj.transactionId = getBidIdParameter('transactionId', bid); - if (gpid) { reqObj.gpid = gpid; } + reqObj.adUnitCode = utils.getBidIdParameter('adUnitCode', bid); + reqObj.auctionId = utils.getBidIdParameter('auctionId', bid); + reqObj.transactionId = utils.getBidIdParameter('transactionId', bid); return reqObj; } function getSizes(bid) { - return parseSizesInput(concatSizes(bid)); + return utils.parseSizesInput(concatSizes(bid)); } function concatSizes(bid) { - let playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); - let videoSizes = deepAccess(bid, 'mediaTypes.video.sizes'); - let bannerSizes = deepAccess(bid, 'mediaTypes.banner.sizes'); + let playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); + let videoSizes = utils.deepAccess(bid, 'mediaTypes.video.sizes'); + let bannerSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes'); - if (isArray(bannerSizes) || isArray(playerSize) || isArray(videoSizes)) { + if (utils.isArray(bannerSizes) || utils.isArray(playerSize) || utils.isArray(videoSizes)) { let mediaTypesSizes = [bannerSizes, videoSizes, playerSize]; return mediaTypesSizes .reduce(function(acc, currSize) { - if (isArray(currSize)) { - if (isArray(currSize[0])) { + if (utils.isArray(currSize)) { + if (utils.isArray(currSize[0])) { currSize.forEach(function (childSize) { acc.push(childSize); }) diff --git a/modules/telariaBidAdapter.js b/modules/telariaBidAdapter.js index c55ecdcfbc6..b2904045144 100644 --- a/modules/telariaBidAdapter.js +++ b/modules/telariaBidAdapter.js @@ -1,8 +1,8 @@ -import { logError, isEmpty, deepAccess, triggerPixel, logWarn, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {createBid as createBidFactory} from '../src/bidfactory.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {VIDEO} from '../src/mediaTypes.js'; -import CONSTANTS from '../src/constants.json'; +import {STATUS} from '../src/constants.json'; const BIDDER_CODE = 'telaria'; const DOMAIN = 'tremorhub.com'; @@ -73,7 +73,7 @@ export const spec = { } }); } catch (error) { - logError(error); + utils.logError(error); width = 0; height = 0; } @@ -83,10 +83,10 @@ export const spec = { if (bidResult && bidResult.error) { errorMessage += `: ${bidResult.error}`; } - logError(errorMessage); - } else if (!isEmpty(bidResult.seatbid)) { + utils.logError(errorMessage); + } else if (!utils.isEmpty(bidResult.seatbid)) { bidResult.seatbid[0].bid.forEach(tag => { - bids.push(createBid(CONSTANTS.STATUS.GOOD, bidderRequest, tag, width, height, BIDDER_CODE)); + bids.push(createBid(STATUS.GOOD, bidderRequest, tag, width, height, BIDDER_CODE)); }); } @@ -102,7 +102,7 @@ export const spec = { getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; if (syncOptions.pixelEnabled && serverResponses.length) { - (deepAccess(serverResponses, '0.body.ext.telaria.userSync') || []).forEach(url => syncs.push({type: 'image', url: url})); + (utils.deepAccess(serverResponses, '0.body.ext.telaria.userSync') || []).forEach(url => syncs.push({type: 'image', url: url})); } return syncs; }, @@ -114,7 +114,7 @@ export const spec = { onTimeout: function (timeoutData) { let url = getTimeoutUrl(timeoutData); if (url) { - triggerPixel(url); + utils.triggerPixel(url); } } }; @@ -135,7 +135,7 @@ function getEncodedValIfNotEmpty(val) { * @returns {string} */ function getSupplyChainAsUrlParam(schainObject) { - if (isEmpty(schainObject)) { + if (utils.isEmpty(schainObject)) { return ''; } @@ -157,22 +157,22 @@ function getSupplyChainAsUrlParam(schainObject) { function getUrlParams(params, schainFromBidRequest) { let urlSuffix = ''; - if (!isEmpty(params)) { + if (!utils.isEmpty(params)) { for (let key in params) { - if (key !== 'schain' && params.hasOwnProperty(key) && !isEmpty(params[key])) { + if (key !== 'schain' && params.hasOwnProperty(key) && !utils.isEmpty(params[key])) { urlSuffix += `&${key}=${params[key]}`; } } - urlSuffix += getSupplyChainAsUrlParam(!isEmpty(schainFromBidRequest) ? schainFromBidRequest : params['schain']); + urlSuffix += getSupplyChainAsUrlParam(!utils.isEmpty(schainFromBidRequest) ? schainFromBidRequest : params['schain']); } return urlSuffix; } export const getTimeoutUrl = function(timeoutData) { - let params = deepAccess(timeoutData, '0.params.0'); + let params = utils.deepAccess(timeoutData, '0.params.0'); - if (!isEmpty(params)) { + if (!utils.isEmpty(params)) { let url = `https://${EVENTS_ENDPOINT}`; params = Object.assign({ @@ -195,14 +195,14 @@ export const getTimeoutUrl = function(timeoutData) { * @returns {string} */ function generateUrl(bid, bidderRequest) { - let playerSize = deepAccess(bid, 'mediaTypes.video.playerSize'); + let playerSize = utils.deepAccess(bid, 'mediaTypes.video.playerSize'); if (!playerSize) { - logWarn(`Although player size isn't required it is highly recommended`); + utils.logWarn(`Although player size isn't required it is highly recommended`); } let width, height; if (playerSize) { - if (isArray(playerSize) && (playerSize.length === 2) && (!isNaN(playerSize[0]) && !isNaN(playerSize[1]))) { + if (utils.isArray(playerSize) && (playerSize.length === 2) && (!isNaN(playerSize[0]) && !isNaN(playerSize[1]))) { width = playerSize[0]; height = playerSize[1]; } else if (typeof playerSize === 'object') { @@ -211,8 +211,8 @@ function generateUrl(bid, bidderRequest) { } } - let supplyCode = deepAccess(bid, 'params.supplyCode'); - let adCode = deepAccess(bid, 'params.adCode'); + let supplyCode = utils.deepAccess(bid, 'params.supplyCode'); + let adCode = utils.deepAccess(bid, 'params.adCode'); if (supplyCode && adCode) { let url = `https://${supplyCode}.${TAG_ENDPOINT}?adCode=${adCode}`; diff --git a/modules/temedyaBidAdapter.js b/modules/temedyaBidAdapter.js index 76a6234c095..4577fb295cd 100644 --- a/modules/temedyaBidAdapter.js +++ b/modules/temedyaBidAdapter.js @@ -1,4 +1,4 @@ -import { parseSizesInput, parseQueryStringParameters, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER, NATIVE } from '../src/mediaTypes.js'; @@ -36,7 +36,7 @@ export const spec = { requestid: req.bidId }; if (mediaType === 'display') { - data.sizes = parseSizesInput( + data.sizes = utils.parseSizesInput( req.mediaTypes && req.mediaTypes.banner && req.mediaTypes.banner.sizes ).join('|') } @@ -44,7 +44,7 @@ export const spec = { return { method: ENDPOINT_METHOD, url: ENDPOINT_URL, - data: parseQueryStringParameters(data), + data: utils.parseQueryStringParameters(data), options: { withCredentials: false, requestId: req.bidId, mediaType: mediaType } }; }); @@ -128,7 +128,7 @@ export const spec = { } return bidResponses; } catch (err) { - logError(err); + utils.logError(err); return []; } }, diff --git a/modules/terceptAnalyticsAdapter.js b/modules/terceptAnalyticsAdapter.js index 748e512bd42..54da2bd06d2 100644 --- a/modules/terceptAnalyticsAdapter.js +++ b/modules/terceptAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { parseSizesInput, getWindowLocation, buildUrl } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; const emptyUrl = ''; const analyticsType = 'endpoint'; @@ -56,7 +56,7 @@ function mapBidRequests(params) { requestId: bid.bidderRequestId, auctionId: bid.auctionId, transactionId: bid.transactionId, - sizes: parseSizesInput(bid.mediaTypes.banner.sizes).toString(), + sizes: utils.parseSizesInput(bid.mediaTypes.banner.sizes).toString(), renderStatus: 1, requestTimestamp: params.auctionStart }); @@ -110,13 +110,13 @@ function mapBidResponse(bidResponse, status) { } function send(data, status) { - let location = getWindowLocation(); + let location = utils.getWindowLocation(); if (typeof data !== 'undefined' && typeof data.auctionInit !== 'undefined') { Object.assign(data.auctionInit, { host: location.host, path: location.pathname, search: location.search }); } data.initOptions = initOptions; - let terceptAnalyticsRequestUrl = buildUrl({ + let terceptAnalyticsRequestUrl = utils.buildUrl({ protocol: 'https', hostname: (initOptions && initOptions.hostName) || defaultHostName, pathname: (initOptions && initOptions.pathName) || defaultPathName, diff --git a/modules/theAdxBidAdapter.js b/modules/theAdxBidAdapter.js index d7a79fe74d0..91e36077e88 100644 --- a/modules/theAdxBidAdapter.js +++ b/modules/theAdxBidAdapter.js @@ -1,4 +1,4 @@ -import { logInfo, isEmpty, deepAccess, parseUrl, getDNT, parseSizesInput, _map } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER, NATIVE, @@ -125,7 +125,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - logInfo('theadx.isBidRequestValid', bid); + utils.logInfo('theadx.isBidRequestValid', bid); let res = false; if (bid && bid.params) { res = !!(bid.params.pid && bid.params.tagId); @@ -141,10 +141,10 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests, bidderRequest) { - logInfo('theadx.buildRequests', 'validBidRequests', validBidRequests, 'bidderRequest', bidderRequest); + utils.logInfo('theadx.buildRequests', 'validBidRequests', validBidRequests, 'bidderRequest', bidderRequest); let results = []; const requestType = 'POST'; - if (!isEmpty(validBidRequests)) { + if (!utils.isEmpty(validBidRequests)) { results = validBidRequests.map( bidRequest => { return { @@ -176,7 +176,7 @@ export const spec = { * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: (serverResponse, request) => { - logInfo('theadx.interpretResponse', 'serverResponse', serverResponse, ' request', request); + utils.logInfo('theadx.interpretResponse', 'serverResponse', serverResponse, ' request', request); let responses = []; @@ -185,8 +185,8 @@ export const spec = { let seatBids = responseBody.seatbid; - if (!(isEmpty(seatBids) || - isEmpty(seatBids[0].bid))) { + if (!(utils.isEmpty(seatBids) || + utils.isEmpty(seatBids[0].bid))) { let seatBid = seatBids[0]; let bid = seatBid.bid[0]; @@ -280,7 +280,7 @@ export const spec = { * @return {UserSync[]} The user syncs which should be dropped. */ getUserSyncs: function (syncOptions, serverResponses) { - logInfo('theadx.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses) + utils.logInfo('theadx.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses) const syncs = []; if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { @@ -288,8 +288,8 @@ export const spec = { } serverResponses.forEach(resp => { - const syncIframeUrls = deepAccess(resp, 'body.ext.sync.iframe'); - const syncImageUrls = deepAccess(resp, 'body.ext.sync.image'); + const syncIframeUrls = utils.deepAccess(resp, 'body.ext.sync.iframe'); + const syncImageUrls = utils.deepAccess(resp, 'body.ext.sync.image'); if (syncOptions.iframeEnabled && syncIframeUrls) { syncIframeUrls.forEach(syncIframeUrl => { syncs.push({ @@ -314,7 +314,7 @@ export const spec = { } let buildSiteComponent = (bidRequest, bidderRequest) => { - let loc = parseUrl(bidderRequest.refererInfo.referer, { + let loc = utils.parseUrl(bidderRequest.refererInfo.referer, { decodeSearchAsString: true }); @@ -353,7 +353,7 @@ let buildDeviceComponent = (bidRequest, bidderRequest) => { language: ('language' in navigator) ? navigator.language : null, ua: ('userAgent' in navigator) ? navigator.userAgent : null, devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2, - dnt: getDNT() ? 1 : 0, + dnt: utils.getDNT() ? 1 : 0, }; // Include connection info if available const CONNECTION = navigator.connection || navigator.webkitConnection; @@ -383,14 +383,14 @@ let extractValidSize = (bidRequest, bidderRequest) => { } else { requestedSizes = mediaTypes.video.sizes; } - } else if (!isEmpty(bidRequest.sizes)) { + } else if (!utils.isEmpty(bidRequest.sizes)) { requestedSizes = bidRequest.sizes } // Ensure the size array is normalized - let conformingSize = parseSizesInput(requestedSizes); + let conformingSize = utils.parseSizesInput(requestedSizes); - if (!isEmpty(conformingSize) && conformingSize[0] != null) { + if (!utils.isEmpty(conformingSize) && conformingSize[0] != null) { // Currently only the first size is utilized let splitSizes = conformingSize[0].split('x'); @@ -423,7 +423,7 @@ let generateBannerComponent = (bidRequest, bidderRequest) => { } let generateNativeComponent = (bidRequest, bidderRequest) => { - const assets = _map(bidRequest.mediaTypes.native, (bidParams, key) => { + const assets = utils._map(bidRequest.mediaTypes.native, (bidParams, key) => { const props = NATIVEPROBS[key]; const asset = { required: bidParams.required & 1, diff --git a/modules/timeoutRtdProvider.js b/modules/timeoutRtdProvider.js deleted file mode 100644 index 323a5291e2d..00000000000 --- a/modules/timeoutRtdProvider.js +++ /dev/null @@ -1,181 +0,0 @@ - -import { submodule } from '../src/hook.js'; -import * as ajax from '../src/ajax.js'; -import { logInfo, deepAccess, logError } from '../src/utils.js'; -import { getGlobal } from '../src/prebidGlobal.js'; - -const SUBMODULE_NAME = 'timeout'; - -// this allows the stubbing of functions during testing -export const timeoutRtdFunctions = { - getDeviceType, - getConnectionSpeed, - checkVideo, - calculateTimeoutModifier, - handleTimeoutIncrement -}; - -const entries = Object.entries || function(obj) { - const ownProps = Object.keys(obj); - let i = ownProps.length; - let resArray = new Array(i); - while (i--) { resArray[i] = [ownProps[i], obj[ownProps[i]]]; } - return resArray; -}; - -function getDeviceType() { - const userAgent = window.navigator.userAgent.toLowerCase(); - if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(userAgent))) { - return 5; // tablet - } - if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(userAgent))) { - return 4; // mobile - } - return 2; // personal computer -} - -function checkVideo(adUnits) { - return adUnits.some((adUnit) => { - return adUnit.mediaTypes && adUnit.mediaTypes.video; - }); -} - -function getConnectionSpeed() { - const connection = window.navigator.connection || window.navigator.mozConnection || window.navigator.webkitConnection || {} - const connectionType = connection.type || connection.effectiveType; - - switch (connectionType) { - case 'slow-2g': - case '2g': - return 'slow'; - - case '3g': - return 'medium'; - - case 'bluetooth': - case 'cellular': - case 'ethernet': - case 'wifi': - case 'wimax': - case '4g': - return 'fast'; - } - - return 'unknown'; -} -/** - * Calculate the time to be added to the timeout - * @param {Array} adUnits - * @param {Object} rules - * @return {int} - */ -function calculateTimeoutModifier(adUnits, rules) { - logInfo('Timeout rules', rules); - let timeoutModifier = 0; - let toAdd = 0; - - if (rules.includesVideo) { - const hasVideo = timeoutRtdFunctions.checkVideo(adUnits); - toAdd = rules.includesVideo[hasVideo] || 0; - logInfo(`Adding ${toAdd} to timeout for includesVideo ${hasVideo}`) - timeoutModifier += toAdd; - } - - if (rules.numAdUnits) { - const numAdUnits = adUnits.length; - if (rules.numAdUnits[numAdUnits]) { - timeoutModifier += rules.numAdUnits[numAdUnits]; - } else { - for (const [rangeStr, timeoutVal] of entries(rules.numAdUnits)) { - const [lowerBound, upperBound] = rangeStr.split('-'); - if (parseInt(lowerBound) <= numAdUnits && numAdUnits <= parseInt(upperBound)) { - logInfo(`Adding ${timeoutVal} to timeout for numAdUnits ${numAdUnits}`) - timeoutModifier += timeoutVal; - break; - } - } - } - } - - if (rules.deviceType) { - const deviceType = timeoutRtdFunctions.getDeviceType(); - toAdd = rules.deviceType[deviceType] || 0; - logInfo(`Adding ${toAdd} to timeout for deviceType ${deviceType}`) - timeoutModifier += toAdd; - } - - if (rules.connectionSpeed) { - const connectionSpeed = timeoutRtdFunctions.getConnectionSpeed(); - toAdd = rules.connectionSpeed[connectionSpeed] || 0; - logInfo(`Adding ${toAdd} to timeout for connectionSpeed ${connectionSpeed}`) - timeoutModifier += toAdd; - } - - logInfo('timeout Modifier calculated', timeoutModifier); - return timeoutModifier; -} - -/** - * - * @param {Object} reqBidsConfigObj - * @param {function} callback - * @param {Object} config - * @param {Object} userConsent - */ -function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) { - logInfo('Timeout rtd config', config); - const timeoutUrl = deepAccess(config, 'params.endpoint.url'); - if (timeoutUrl) { - logInfo('Timeout url', timeoutUrl); - ajax.ajaxBuilder()(timeoutUrl, { - success: function(response) { - try { - const rules = JSON.parse(response); - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules); - } catch (e) { - logError('Error parsing json response from timeout provider.') - } - callback(); - }, - error: function(errorStatus) { - logError('Timeout request error!', errorStatus); - callback(); - } - }); - } else if (deepAccess(config, 'params.rules')) { - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, deepAccess(config, 'params.rules')); - callback(); - } else { - logInfo('No timeout endpoint or timeout rules found. Exiting timeout rtd module'); - callback(); - } -} - -/** - * Gets the timeout modifier, adds it to the bidder timeout, and sets it to reqBidsConfigObj - * @param {Object} reqBidsConfigObj - * @param {Object} rules - */ -function handleTimeoutIncrement(reqBidsConfigObj, rules) { - const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; - const timeoutModifier = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules); - const bidderTimeout = getGlobal().getConfig('bidderTimeout'); - reqBidsConfigObj.timeout = bidderTimeout + timeoutModifier; -} - -/** @type {RtdSubmodule} */ -export const timeoutSubmodule = { - /** - * used to link submodule with realTimeData - * @type {string} - */ - name: SUBMODULE_NAME, - init: () => true, - getBidRequestData, -}; - -function registerSubModule() { - submodule('realTimeData', timeoutSubmodule); -} - -registerSubModule(); diff --git a/modules/timeoutRtdProvider.md b/modules/timeoutRtdProvider.md deleted file mode 100644 index 49d1e1fc70a..00000000000 --- a/modules/timeoutRtdProvider.md +++ /dev/null @@ -1,151 +0,0 @@ - --- - layout: page_v2 - title: Timeout Rtd Module - description: Module for managing timeouts in real time - page_type: module - module_type: rtd - module_code : example - enable_download : true - sidebarType : 1 - --- - -## Overview -The timeout RTD module enables publishers to set rules that determine the timeout based on -certain features. It supports rule sets dynamically retrieved from a timeout provider as well as rules -set directly via configuration. -Build the timeout RTD module into the Prebid.js package with: -``` -gulp build --modules=timeoutRtdProvider,rtdModule... -``` - -## Configuration -The module is configured in the realTimeData.dataProviders object. The module will override -`bidderTimeout` in the pbjs config. - -### Timeout Data Provider interface -The timeout RTD module provides an interface of dynamically fetching timeout rules from -a data provider just before the auction begins. The endpoint url is set in the config just as in -the example below, and the timeout data will be used when making bid requests. - -``` -pbjs.setConfig({ - ... - "realTimeData": { - "dataProviders": [{ - "name": 'timeout', - "params": { - "endpoint": { - "url": "http://{cdn-link}.json" - } - } - } - ]}, - - // This value below will be modified by the timeout RTD module if it successfully - // fetches the timeout data. - "bidderTimeout": 1500, - ... -}); -``` - -Sample Endpoint Response: -``` -{ - "rules": { - "includesVideo": { - "true": 200, - "false": 50 - }, - "numAdUnits" : { - "1-5": 100, - "6-10": 200, - "11-15": 300 - }, - "deviceType": { - "2": 50, - "4": 100, - "5": 200 - }, - "connectionSpeed": { - "slow": 200, - "medium": 100, - "fast": 50, - "unknown": 10 - }, -} -``` - -### Rule Handling: -The rules retrieved from the endpoint will be used to add time to the `bidderTimeout` based on certain features such as -the user's deviceType, connection speed, etc. These rules can also be configured statically on page via a `rules` object. -Note that the timeout Module will ignore the static rules if an endpoint url is provided. The timeout rules follow the -format: -``` -{ - '': { - '': - } -} -``` -See bottom of page for examples. - -Currently supported features: - -|Name |Description | Keys | Example -| :------------ | :------------ | :------------ |:------------ | -| includesVideo | Adds time to the timeout based on whether there is a video ad unit in the auction or not | 'true'/'false'| { "true": 200, "false": 50 } | -| numAdUnits | Adds time based on the number of ad units. Ranges in the format `'lowerbound-upperbound` are accepted. This range is inclusive | numbers or number ranges | {"1": 50, "2-5": 100, "6-10": 200} | -| deviceType | Adds time based on device type| 2, 4, or 5| {"2": 50, "4": 100} | -| connectionSpeed | Adds time based on connection speed. `connectionSpeed` defaults to 'unknown' if connection speed cannot be determined | slow, medium, fast, or unknown | { "slow": 200} | - -If there are multiple rules set, all of them would be used and any that apply will be added to the base timeout. For example, if the rules object contains: -``` -{ - "includesVideo": { - "true": 200, - "false": 50 - }, - "numAdUnits" : { - "1-3": 100, - "4-5": 200 - } -} -``` -and there are 3 ad units in the auction, all of which are banner, then the timeout to be added will be 150 milliseconds (50 for `includesVideo[false]` + 100 for `numAdUnits['1-3']`). - -Full example: -``` -pbjs.setConfig({ - ... - "realTimeData": { - "dataProviders": [{ - "name": 'timeout', - "params": { - "rules": { - "includesVideo": { - "true": 200, - "false": 50 - }, - "numAdUnits" : { - "1-5": 100, - "6-10": 200, - "11-15": 300 - }, - "deviceType": { - "2": 50, - "4": 100, - "5": 200 - }, - "connectionSpeed": { - "slow": 200, - "medium": 100, - "fast": 50, - "unknown": 10 - }, - } - } - ]} - ... - // The timeout RTD module will add time to `bidderTimeout` based on the rules set above. - "bidderTimeout": 1500, -``` diff --git a/modules/tpmnBidAdapter.js b/modules/tpmnBidAdapter.js index 006357cd4b9..ec9d30c0e29 100644 --- a/modules/tpmnBidAdapter.js +++ b/modules/tpmnBidAdapter.js @@ -1,6 +1,6 @@ /* eslint-disable no-tabs */ import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { parseUrl, deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER } from '../src/mediaTypes.js'; export const ADAPTER_VERSION = '1'; @@ -72,7 +72,7 @@ registerBidder(spec); * Creates site description object */ function createSite(refInfo) { - let url = parseUrl(refInfo.referer); + let url = utils.parseUrl(refInfo.referer); let site = { 'domain': url.hostname, 'page': url.protocol + '://' + url.hostname + url.pathname @@ -102,7 +102,7 @@ function parseSizes(sizes) { } function getBannerSizes(bidRequest) { - return parseSizes(deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes); + return parseSizes(utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes); } function bidToRequest(bid) { diff --git a/modules/trionBidAdapter.js b/modules/trionBidAdapter.js index dd1624f90d7..e9e030ce33f 100644 --- a/modules/trionBidAdapter.js +++ b/modules/trionBidAdapter.js @@ -1,4 +1,4 @@ -import { getBidIdParameter, parseSizesInput, tryAppendQueryString } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -112,11 +112,11 @@ function getPublisherUrl() { } function buildTrionUrlParams(bid, bidderRequest) { - var pubId = getBidIdParameter('pubId', bid.params); - var sectionId = getBidIdParameter('sectionId', bid.params); + var pubId = utils.getBidIdParameter('pubId', bid.params); + var sectionId = utils.getBidIdParameter('sectionId', bid.params); var url = getPublisherUrl(); var bidSizes = getBidSizesFromBidRequest(bid); - var sizes = parseSizesInput(bidSizes).join(','); + var sizes = utils.parseSizesInput(bidSizes).join(','); var isAutomated = (navigator && navigator.webdriver) ? '1' : '0'; var isHidden = (document.hidden) ? '1' : '0'; var visibilityState = encodeURIComponent(document.visibilityState); @@ -131,10 +131,10 @@ function buildTrionUrlParams(bid, bidderRequest) { setStorageData(BASE_KEY + 'lps', pubId + ':' + sectionId); var trionUrl = ''; - trionUrl = tryAppendQueryString(trionUrl, 'bidId', bid.bidId); - trionUrl = tryAppendQueryString(trionUrl, 'pubId', pubId); - trionUrl = tryAppendQueryString(trionUrl, 'sectionId', sectionId); - trionUrl = tryAppendQueryString(trionUrl, 'vers', '$prebid.version$'); + trionUrl = utils.tryAppendQueryString(trionUrl, 'bidId', bid.bidId); + trionUrl = utils.tryAppendQueryString(trionUrl, 'pubId', pubId); + trionUrl = utils.tryAppendQueryString(trionUrl, 'sectionId', sectionId); + trionUrl = utils.tryAppendQueryString(trionUrl, 'vers', '$prebid.version$'); if (url) { trionUrl += 'url=' + url + '&'; } @@ -142,22 +142,22 @@ function buildTrionUrlParams(bid, bidderRequest) { trionUrl += 'sizes=' + sizes + '&'; } if (intT) { - trionUrl = tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT)); + trionUrl = utils.tryAppendQueryString(trionUrl, 'int_t', encodeURIComponent(intT)); } - trionUrl = tryAppendQueryString(trionUrl, 'tr_wd', isAutomated); - trionUrl = tryAppendQueryString(trionUrl, 'tr_hd', isHidden); - trionUrl = tryAppendQueryString(trionUrl, 'tr_vs', visibilityState); + trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_wd', isAutomated); + trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_hd', isHidden); + trionUrl = utils.tryAppendQueryString(trionUrl, 'tr_vs', visibilityState); if (bidderRequest && bidderRequest.gdprConsent) { var gdpr = bidderRequest.gdprConsent; if (gdpr) { if (gdpr.consentString) { - trionUrl = tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString)); + trionUrl = utils.tryAppendQueryString(trionUrl, 'gdprc', encodeURIComponent(gdpr.consentString)); } - trionUrl = tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0)); + trionUrl = utils.tryAppendQueryString(trionUrl, 'gdpr', (gdpr.gdprApplies ? 1 : 0)); } } if (bidderRequest && bidderRequest.uspConsent) { - trionUrl = tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent)); + trionUrl = utils.tryAppendQueryString(trionUrl, 'usp', encodeURIComponent(bidderRequest.uspConsent)); } // remove the trailing "&" if (trionUrl.lastIndexOf('&') === trionUrl.length - 1) { diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index 215769e9812..e8d248eea03 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -1,13 +1,11 @@ -import { tryAppendQueryString, logMessage, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; const GVLID = 28; const BIDDER_CODE = 'triplelift'; const STR_ENDPOINT = 'https://tlx.3lift.com/header/auction?'; -const BANNER_TIME_TO_LIVE = 300; -const INSTREAM_TIME_TO_LIVE = 3600; let gdprApplies = true; let consentString = null; @@ -23,41 +21,41 @@ export const tripleliftAdapterSpec = { let tlCall = STR_ENDPOINT; let data = _buildPostBody(bidRequests); - tlCall = tryAppendQueryString(tlCall, 'lib', 'prebid'); - tlCall = tryAppendQueryString(tlCall, 'v', '$prebid.version$'); + tlCall = utils.tryAppendQueryString(tlCall, 'lib', 'prebid'); + tlCall = utils.tryAppendQueryString(tlCall, 'v', '$prebid.version$'); if (bidderRequest && bidderRequest.refererInfo) { let referrer = bidderRequest.refererInfo.referer; - tlCall = tryAppendQueryString(tlCall, 'referrer', referrer); + tlCall = utils.tryAppendQueryString(tlCall, 'referrer', referrer); } if (bidderRequest && bidderRequest.timeout) { - tlCall = tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout); + tlCall = utils.tryAppendQueryString(tlCall, 'tmax', bidderRequest.timeout); } if (bidderRequest && bidderRequest.gdprConsent) { if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') { gdprApplies = bidderRequest.gdprConsent.gdprApplies; - tlCall = tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString()); + tlCall = utils.tryAppendQueryString(tlCall, 'gdpr', gdprApplies.toString()); } if (typeof bidderRequest.gdprConsent.consentString !== 'undefined') { consentString = bidderRequest.gdprConsent.consentString; - tlCall = tryAppendQueryString(tlCall, 'cmp_cs', consentString); + tlCall = utils.tryAppendQueryString(tlCall, 'cmp_cs', consentString); } } if (bidderRequest && bidderRequest.uspConsent) { - tlCall = tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent); + tlCall = utils.tryAppendQueryString(tlCall, 'us_privacy', bidderRequest.uspConsent); } if (config.getConfig('coppa') === true) { - tlCall = tryAppendQueryString(tlCall, 'coppa', true); + tlCall = utils.tryAppendQueryString(tlCall, 'coppa', true); } if (tlCall.lastIndexOf('&') === tlCall.length - 1) { tlCall = tlCall.substring(0, tlCall.length - 1); } - logMessage('tlCall request built: ' + tlCall); + utils.logMessage('tlCall request built: ' + tlCall); return { method: 'POST', @@ -81,17 +79,17 @@ export const tripleliftAdapterSpec = { let syncEndpoint = 'https://eb2.3lift.com/sync?'; if (syncType === 'image') { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'px', 1); - syncEndpoint = tryAppendQueryString(syncEndpoint, 'src', 'prebid'); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'px', 1); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'src', 'prebid'); } if (consentString !== null) { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies); - syncEndpoint = tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'gdpr', gdprApplies); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'cmp_cs', consentString); } if (usPrivacy) { - syncEndpoint = tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy); + syncEndpoint = utils.tryAppendQueryString(syncEndpoint, 'us_privacy', usPrivacy); } return [{ @@ -124,7 +122,7 @@ function _buildPostBody(bidRequests) { } else if (bidRequest.mediaTypes.banner) { imp.banner = { format: _sizes(bidRequest.sizes) }; }; - if (!isEmpty(bidRequest.ortb2Imp)) { + if (!utils.isEmpty(bidRequest.ortb2Imp)) { imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp); } return imp; @@ -145,7 +143,7 @@ function _buildPostBody(bidRequests) { let ext = _getExt(schain, globalFpd); - if (!isEmpty(ext)) { + if (!utils.isEmpty(ext)) { data.ext = ext; } return data; @@ -200,10 +198,10 @@ function _getGlobalFpd() { _addEntries(context, fpdContext); _addEntries(user, fpdUser); - if (!isEmpty(context)) { + if (!utils.isEmpty(context)) { fpd.context = context; } - if (!isEmpty(user)) { + if (!utils.isEmpty(user)) { fpd.user = user; } return fpd; @@ -215,7 +213,7 @@ function _getAdUnitFpd(adUnitFpd) { _addEntries(context, adUnitFpd.ext); - if (!isEmpty(context)) { + if (!utils.isEmpty(context)) { fpd.context = context; } @@ -223,7 +221,7 @@ function _getAdUnitFpd(adUnitFpd) { } function _addEntries(target, source) { - if (!isEmpty(source)) { + if (!utils.isEmpty(source)) { Object.keys(source).forEach(key => { if (source[key] != null) { target[key] = source[key]; @@ -234,10 +232,10 @@ function _addEntries(target, source) { function _getExt(schain, fpd) { let ext = {}; - if (!isEmpty(schain)) { + if (!utils.isEmpty(schain)) { ext.schain = { ...schain }; } - if (!isEmpty(fpd)) { + if (!utils.isEmpty(fpd)) { ext.fpd = { ...fpd }; } return ext; @@ -262,36 +260,19 @@ function getPubCommonEids(bidRequest) { function getEids(bidRequest, type, source, rtiPartner) { return bidRequest .map(getUserId(type)) // bids -> userIds of a certain type - .filter(filterEids(type)) // filter out unqualified userIds + .filter((x) => !!x) // filter out null userIds .map(formatEid(source, rtiPartner)); // userIds -> eid objects } -const filterEids = type => (userId, i, arr) => { - let isValidUserId = - !!userId && // is not null nor empty - (isStr(userId) - ? !!userId - : isPlainObject(userId) && // or, is object - !isArray(userId) && // not an array - !isEmpty(userId) && // is not empty - userId.id && // contains nested id field - isStr(userId.id) && // nested id field is a string - !!userId.id); // that is not empty - if (!isValidUserId && arr[0] !== undefined) { - logWarn(`Triplelift: invalid ${type} userId format`); - } - return isValidUserId; -}; - function getUserId(type) { - return bid => bid && bid.userId && bid.userId[type]; + return (bid) => (bid && bid.userId && bid.userId[type]); } function formatEid(source, rtiPartner) { - return (userId) => ({ + return (id) => ({ source, uids: [{ - id: userId.id ? userId.id : userId, + id, ext: { rtiPartner } }] }); @@ -330,7 +311,7 @@ function _buildResponseObject(bidderRequest, bid) { creativeId: creativeId, dealId: dealId, currency: 'USD', - ttl: BANNER_TIME_TO_LIVE, + ttl: 300, tl_source: bid.tl_source, meta: {} }; @@ -338,7 +319,6 @@ function _buildResponseObject(bidderRequest, bid) { if (_isInstreamBidRequest(breq)) { bidResponse.vastXml = bid.ad; bidResponse.mediaType = 'video'; - bidResponse.ttl = INSTREAM_TIME_TO_LIVE; }; if (bid.advertiser_name) { diff --git a/modules/truereachBidAdapter.js b/modules/truereachBidAdapter.js index a0244e3a349..fadc952b5fb 100755 --- a/modules/truereachBidAdapter.js +++ b/modules/truereachBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, getUniqueIdentifierStr } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -13,7 +13,7 @@ export const spec = { isBidRequestValid: function (bidRequest) { return (bidRequest.params.site_id && bidRequest.params.bidfloor && - deepAccess(bidRequest, 'mediaTypes.banner') && (deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0)); + utils.deepAccess(bidRequest, 'mediaTypes.banner') && (utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes.length') > 0)); }, buildRequests: function (validBidRequests, bidderRequest) { @@ -23,7 +23,7 @@ export const spec = { let queryParams = buildCommonQueryParamsFromBids(validBidRequests, bidderRequest); - let siteId = deepAccess(validBidRequests[0], 'params.site_id'); + let siteId = utils.deepAccess(validBidRequests[0], 'params.site_id'); let url = BIDDER_URL + siteId + '?hb=1&transactionId=' + validBidRequests[0].transactionId; @@ -121,7 +121,7 @@ function buildCommonQueryParamsFromBids(validBidRequests, bidderRequest) { let page = window.location.host + window.location.pathname + location.search + location.hash; let defaultParams = { - id: getUniqueIdentifierStr(), + id: utils.getUniqueIdentifierStr(), imp: [ { id: validBidRequests[0].bidId, diff --git a/modules/trustxBidAdapter.js b/modules/trustxBidAdapter.js index 31be2814bba..66574e4fe57 100644 --- a/modules/trustxBidAdapter.js +++ b/modules/trustxBidAdapter.js @@ -1,13 +1,15 @@ -import { isEmpty, deepAccess, logError, logWarn, parseGPTSingleSizeArrayToRtbSize } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import { VIDEO, BANNER } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'trustx'; -const ENDPOINT_URL = 'https://grid.bidswitch.net/hbjson?sp=trustx'; +const ENDPOINT_URL = 'https://sofia.trustx.org/hb'; +const NEW_ENDPOINT_URL = 'https://grid.bidswitch.net/hbjson?sp=trustx'; +const ADDITIONAL_SYNC_URL = 'https://x.bidswitch.net/sync?ssp=themediagrid'; const TIME_TO_LIVE = 360; -const ADAPTER_SYNC_URL = 'https://x.bidswitch.net/sync?ssp=themediagrid'; +const ADAPTER_SYNC_URL = 'https://sofia.trustx.org/push_sync'; const RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js'; const LOG_ERROR_MESS = { @@ -37,226 +39,40 @@ export const spec = { * Make a server request from the list of BidRequests. * * @param {BidRequest[]} validBidRequests - an array of bids - * @param {bidderRequest} bidderRequest bidder request object + * @param {bidderRequest} - bidder request object * @return ServerRequest Info describing the request to the server. */ buildRequests: function(validBidRequests, bidderRequest) { - if (!validBidRequests.length) { - return null; - } - let pageKeywords = null; - let jwpseg = null; - let permutiveseg = null; - let content = null; - let schain = null; - let userId = null; - let userIdAsEids = null; - let user = null; - let userExt = null; - let {bidderRequestId, auctionId, gdprConsent, uspConsent, timeout, refererInfo} = bidderRequest || {}; - - const referer = refererInfo ? encodeURIComponent(refererInfo.referer) : ''; - const imp = []; - const bidsMap = {}; - - validBidRequests.forEach((bid) => { - if (!bidderRequestId) { - bidderRequestId = bid.bidderRequestId; - } - if (!auctionId) { - auctionId = bid.auctionId; - } - if (!schain) { - schain = bid.schain; - } - if (!userId) { - userId = bid.userId; - } - if (!userIdAsEids) { - userIdAsEids = bid.userIdAsEids; - } - const {params: {uid, keywords}, mediaTypes, bidId, adUnitCode, rtd, ortb2Imp} = bid; - bidsMap[bidId] = bid; - const bidFloor = _getFloor(mediaTypes || {}, bid); - if (rtd) { - const jwTargeting = rtd.jwplayer && rtd.jwplayer.targeting; - if (jwTargeting) { - if (!jwpseg && jwTargeting.segments) { - jwpseg = jwTargeting.segments; - } - if (!content && jwTargeting.content) { - content = jwTargeting.content; - } - } - const permutiveTargeting = rtd.p_standard && rtd.p_standard.targeting; - if (!permutiveseg && permutiveTargeting && permutiveTargeting.segments) { - permutiveseg = permutiveTargeting.segments; - } - } - let impObj = { - id: bidId && bidId.toString(), - tagid: uid.toString(), - ext: { - divid: adUnitCode && adUnitCode.toString() - } - }; - - if (ortb2Imp && ortb2Imp.ext && ortb2Imp.ext.data) { - impObj.ext.data = ortb2Imp.ext.data; - if (impObj.ext.data.adserver && impObj.ext.data.adserver.adslot) { - impObj.ext.gpid = impObj.ext.data.adserver.adslot.toString(); - } else { - impObj.ext.gpid = ortb2Imp.ext.data.pbadslot && ortb2Imp.ext.data.pbadslot.toString(); - } - } - - if (!isEmpty(keywords)) { - if (!pageKeywords) { - pageKeywords = keywords; - } - impObj.ext.bidder = { keywords }; - } - - if (bidFloor) { - impObj.bidfloor = bidFloor; - } - - if (!mediaTypes || mediaTypes[BANNER]) { - const banner = createBannerRequest(bid, mediaTypes ? mediaTypes[BANNER] : {}); - if (banner) { - impObj.banner = banner; - } - } - if (mediaTypes && mediaTypes[VIDEO]) { - const video = createVideoRequest(bid, mediaTypes[VIDEO]); - if (video) { - impObj.video = video; - } - } - - if (impObj.banner || impObj.video) { - imp.push(impObj); + const bids = validBidRequests || []; + const newFormatBids = []; + const oldFormatBids = []; + const requests = []; + bids.forEach(bid => { + if (bid.params.useNewFormat) { + newFormatBids.push(bid); + } else { + oldFormatBids.push(bid); } }); - - const source = { - tid: auctionId && auctionId.toString(), - ext: { - wrapper: 'Prebid_js', - wrapper_version: '$prebid.version$' + if (newFormatBids.length) { + const newFormatRequests = newFormatRequest(newFormatBids, bidderRequest); + if (newFormatRequests) { + requests.push(newFormatRequests); } - }; - - if (schain) { - source.ext.schain = schain; } - - const bidderTimeout = config.getConfig('bidderTimeout') || timeout; - const tmax = timeout ? Math.min(bidderTimeout, timeout) : bidderTimeout; - - let request = { - id: bidderRequestId && bidderRequestId.toString(), - site: { - page: referer - }, - tmax, - source, - imp - }; - - if (content) { - request.site.content = content; - } - - const userData = []; - addSegments('iow_labs_pub_data', 'jwpseg', jwpseg, userData); - addSegments('permutive', 'p_standard', permutiveseg, userData, 'permutive.com'); - - if (userData.length) { - user = { - data: userData - }; - } - - if (gdprConsent && gdprConsent.consentString) { - userExt = {consent: gdprConsent.consentString}; - } - - if (userIdAsEids && userIdAsEids.length) { - userExt = userExt || {}; - userExt.eids = [...userIdAsEids]; - } - - if (userExt && Object.keys(userExt).length) { - user = user || {}; - user.ext = userExt; - } - - if (user) { - request.user = user; - } - - const userKeywords = deepAccess(config.getConfig('ortb2.user'), 'keywords') || null; - const siteKeywords = deepAccess(config.getConfig('ortb2.site'), 'keywords') || null; - - if (userKeywords) { - pageKeywords = pageKeywords || {}; - pageKeywords.user = pageKeywords.user || {}; - pageKeywords.user.ortb2 = [ - { - name: 'keywords', - keywords: userKeywords.split(','), - } - ]; - } - if (siteKeywords) { - pageKeywords = pageKeywords || {}; - pageKeywords.site = pageKeywords.site || {}; - pageKeywords.site.ortb2 = [ - { - name: 'keywords', - keywords: siteKeywords.split(','), - } - ]; - } - - if (pageKeywords) { - pageKeywords = reformatKeywords(pageKeywords); - if (pageKeywords) { - request.ext = { - keywords: pageKeywords - }; - } - } - - if (gdprConsent && gdprConsent.gdprApplies) { - request.regs = { - ext: { - gdpr: gdprConsent.gdprApplies ? 1 : 0 - } - } - } - - if (uspConsent) { - if (!request.regs) { - request.regs = {ext: {}}; + if (oldFormatBids.length) { + const oldFormatRequests = oldFormatRequest(oldFormatBids, bidderRequest); + if (oldFormatRequests) { + requests.push(oldFormatRequests); } - request.regs.ext.us_privacy = uspConsent; } - - return { - method: 'POST', - url: ENDPOINT_URL, - data: JSON.stringify(request), - bidsMap - }; + return requests; }, /** * Unpack the response from the server into a list of bids. * * @param {*} serverResponse A successful response from the server. * @param {*} bidRequest - * @param {*} RendererConst * @return {Bid[]} An array of bids which were nested inside the server. */ interpretResponse: function(serverResponse, bidRequest, RendererConst = Renderer) { @@ -275,17 +91,17 @@ export const spec = { _addBidResponse(_getBidFromResponse(respItem), bidRequest, bidResponses, RendererConst); }); } - if (errorMessage) logError(errorMessage); + if (errorMessage) utils.logError(errorMessage); return bidResponses; }, getUserSyncs: function(syncOptions, responses, gdprConsent, uspConsent) { if (syncOptions.pixelEnabled) { + const syncsPerBidder = config.getConfig('userSync.syncsPerBidder'); let params = []; - if (gdprConsent) { + if (gdprConsent && typeof gdprConsent.consentString === 'string') { if (typeof gdprConsent.gdprApplies === 'boolean') { - params.push(`gdpr=${Number(gdprConsent.gdprApplies)}`); - } - if (typeof gdprConsent.consentString === 'string') { + params.push(`gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`); + } else { params.push(`gdpr_consent=${gdprConsent.consentString}`); } } @@ -293,21 +109,38 @@ export const spec = { params.push(`us_privacy=${uspConsent}`); } const stringParams = params.join('&'); - return { + const syncs = [{ type: 'image', - url: ADAPTER_SYNC_URL + stringParams - }; + url: ADAPTER_SYNC_URL + (stringParams ? `?${stringParams}` : '') + }]; + if (syncsPerBidder > 1) { + syncs.push({ + type: 'image', + url: ADDITIONAL_SYNC_URL + (stringParams ? `&${stringParams}` : '') + }); + } + return syncs; } } } +function isPopulatedArray(arr) { + return !!(utils.isArray(arr) && arr.length > 0); +} + +function deleteValues(keyPairObj) { + if (isPopulatedArray(keyPairObj.value) && keyPairObj.value[0] === '') { + delete keyPairObj.value; + } +} + function _getBidFromResponse(respItem) { if (!respItem) { - logError(LOG_ERROR_MESS.emptySeatbid); + utils.logError(LOG_ERROR_MESS.emptySeatbid); } else if (!respItem.bid) { - logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); + utils.logError(LOG_ERROR_MESS.hasNoArrayOfBids + JSON.stringify(respItem)); } else if (!respItem.bid[0]) { - logError(LOG_ERROR_MESS.noBid); + utils.logError(LOG_ERROR_MESS.noBid); } return respItem && respItem.bid && respItem.bid[0]; } @@ -316,10 +149,25 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst) { if (!serverBid) return; let errorMessage; if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid); - if (!serverBid.adm && !serverBid.nurl) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); + if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); else { - const { bidsMap } = bidRequest; - const bid = bidsMap[serverBid.impid]; + const { bidsMap, priceType, newFormat } = bidRequest; + let bid; + let slot; + if (newFormat) { + bid = bidsMap[serverBid.impid]; + } else { + const awaitingBids = bidsMap[serverBid.auid]; + if (awaitingBids) { + const sizeId = `${serverBid.w}x${serverBid.h}`; + if (awaitingBids[sizeId]) { + slot = awaitingBids[sizeId][0]; + bid = slot.bids.shift(); + } + } else { + errorMessage = LOG_ERROR_MESS.noPlacementCode + serverBid.auid; + } + } if (!errorMessage && bid) { const bidResponse = { @@ -329,7 +177,7 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst) { height: serverBid.h, creativeId: serverBid.auid, // bid.bidId, currency: 'USD', - netRevenue: false, + netRevenue: newFormat ? false : priceType !== 'gross', ttl: TIME_TO_LIVE, dealId: serverBid.dealid, meta: { @@ -337,15 +185,11 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst) { }, }; if (serverBid.content_type === 'video') { - if (serverBid.adm) { - bidResponse.vastXml = serverBid.adm; - bidResponse.adResponse = { - content: bidResponse.vastXml - }; - } else if (serverBid.nurl) { - bidResponse.vastUrl = serverBid.nurl; - } + bidResponse.vastXml = serverBid.adm; bidResponse.mediaType = VIDEO; + bidResponse.adResponse = { + content: bidResponse.vastXml + }; if (!bid.renderer && (!bid.mediaTypes || !bid.mediaTypes.video || bid.mediaTypes.video.context === 'outstream')) { bidResponse.renderer = createRenderer(bidResponse, { id: bid.bidId, @@ -359,9 +203,24 @@ function _addBidResponse(serverBid, bidRequest, bidResponses, RendererConst) { bidResponses.push(bidResponse); } + + if (slot && !slot.bids.length) { + slot.parents.forEach(({parent, key, uid}) => { + const index = parent[key].indexOf(slot); + if (index > -1) { + parent[key].splice(index, 1); + } + if (!parent[key].length) { + delete parent[key]; + if (!utils.getKeys(parent).length) { + delete bidsMap[uid]; + } + } + }); + } } if (errorMessage) { - logError(errorMessage); + utils.logError(errorMessage); } } @@ -384,7 +243,7 @@ function createRenderer (bid, rendererParams, RendererConst) { try { rendererInst.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return rendererInst; @@ -395,7 +254,7 @@ function createVideoRequest(bid, mediaType) { const size = (playerSize || bid.sizes || [])[0]; if (!size) return; - let result = parseGPTSingleSizeArrayToRtbSize(size); + let result = utils.parseGPTSingleSizeArrayToRtbSize(size); if (mimes) { result.mimes = mimes; @@ -417,8 +276,8 @@ function createBannerRequest(bid, mediaType) { const sizes = mediaType.sizes || bid.sizes; if (!sizes || !sizes.length) return; - let format = sizes.map((size) => parseGPTSingleSizeArrayToRtbSize(size)); - let result = parseGPTSingleSizeArrayToRtbSize(sizes[0]); + let format = sizes.map((size) => utils.parseGPTSingleSizeArrayToRtbSize(size)); + let result = utils.parseGPTSingleSizeArrayToRtbSize(sizes[0]); if (format.length) { result.format = format @@ -430,10 +289,9 @@ function addSegments(name, segName, segments, data, bidConfigName) { if (segments && segments.length) { data.push({ name: name, - segment: segments - .map((seg) => seg && (seg.id || seg)) - .filter((seg) => seg && (typeof seg === 'string' || typeof seg === 'number')) - .map((seg) => ({ name: segName, value: seg.toString() })) + segment: segments.map((seg) => { + return {name: segName, value: seg}; + }) }); } else if (bidConfigName) { const configData = config.getConfig('ortb2.user.data'); @@ -447,60 +305,14 @@ function addSegments(name, segName, segments, data, bidConfigName) { if (segData && segData.length) { data.push({ name: name, - segment: segData - .map((seg) => seg && (seg.id || seg)) - .filter((seg) => seg && (typeof seg === 'string' || typeof seg === 'number')) - .map((seg) => ({ name: segName, value: seg.toString() })) + segment: segData.map((seg) => { + return {name: segName, value: seg}; + }) }); } } } -function reformatKeywords(pageKeywords) { - const formatedPageKeywords = {}; - Object.keys(pageKeywords).forEach((name) => { - const keywords = pageKeywords[name]; - if (keywords) { - if (name === 'site' || name === 'user') { - const formatedKeywords = {}; - Object.keys(keywords).forEach((pubName) => { - if (Array.isArray(keywords[pubName])) { - const formatedPublisher = []; - keywords[pubName].forEach((pubItem) => { - if (typeof pubItem === 'object' && pubItem.name) { - const formatedPubItem = { name: pubItem.name, segments: [] }; - Object.keys(pubItem).forEach((key) => { - if (Array.isArray(pubItem[key])) { - pubItem[key].forEach((keyword) => { - if (keyword) { - if (typeof keyword === 'string') { - formatedPubItem.segments.push({ name: key, value: keyword }); - } else if (key === 'segments' && typeof keyword.name === 'string' && typeof keyword.value === 'string') { - formatedPubItem.segments.push(keyword); - } - } - }); - } - }); - if (formatedPubItem.segments.length) { - formatedPublisher.push(formatedPubItem); - } - } - }); - if (formatedPublisher.length) { - formatedKeywords[pubName] = formatedPublisher; - } - } - }); - formatedPageKeywords[name] = formatedKeywords; - } else { - formatedPageKeywords[name] = keywords; - } - } - }); - return Object.keys(formatedPageKeywords).length && formatedPageKeywords; -} - /** * Gets bidfloor * @param {Object} mediaTypes @@ -528,4 +340,319 @@ function _getFloor (mediaTypes, bid) { return floor; } +function newFormatRequest(validBidRequests, bidderRequest) { + if (!validBidRequests.length) { + return null; + } + let pageKeywords = null; + let jwpseg = null; + let permutiveseg = null; + let content = null; + let schain = null; + let userId = null; + let userIdAsEids = null; + let user = null; + let userExt = null; + let {bidderRequestId, auctionId, gdprConsent, uspConsent, timeout, refererInfo} = bidderRequest || {}; + + const referer = refererInfo ? encodeURIComponent(refererInfo.referer) : ''; + const imp = []; + const bidsMap = {}; + + validBidRequests.forEach((bid) => { + if (!bidderRequestId) { + bidderRequestId = bid.bidderRequestId; + } + if (!auctionId) { + auctionId = bid.auctionId; + } + if (!schain) { + schain = bid.schain; + } + if (!userId) { + userId = bid.userId; + } + if (!userIdAsEids) { + userIdAsEids = bid.userIdAsEids; + } + const {params: {uid, keywords}, mediaTypes, bidId, adUnitCode, rtd} = bid; + bidsMap[bidId] = bid; + if (!pageKeywords && !utils.isEmpty(keywords)) { + pageKeywords = utils.transformBidderParamKeywords(keywords); + } + const bidFloor = _getFloor(mediaTypes || {}, bid); + if (rtd) { + const jwTargeting = rtd.jwplayer && rtd.jwplayer.targeting; + if (jwTargeting) { + if (!jwpseg && jwTargeting.segments) { + jwpseg = jwTargeting.segments; + } + if (!content && jwTargeting.content) { + content = jwTargeting.content; + } + } + const permutiveTargeting = rtd.p_standard && rtd.p_standard.targeting; + if (!permutiveseg && permutiveTargeting && permutiveTargeting.segments) { + permutiveseg = permutiveTargeting.segments; + } + } + let impObj = { + id: bidId, + tagid: uid.toString(), + ext: { + divid: adUnitCode + } + }; + + if (bidFloor) { + impObj.bidfloor = bidFloor; + } + + if (!mediaTypes || mediaTypes[BANNER]) { + const banner = createBannerRequest(bid, mediaTypes ? mediaTypes[BANNER] : {}); + if (banner) { + impObj.banner = banner; + } + } + if (mediaTypes && mediaTypes[VIDEO]) { + const video = createVideoRequest(bid, mediaTypes[VIDEO]); + if (video) { + impObj.video = video; + } + } + + if (impObj.banner || impObj.video) { + imp.push(impObj); + } + }); + + const source = { + tid: auctionId, + ext: { + wrapper: 'Prebid_js', + wrapper_version: '$prebid.version$' + } + }; + + if (schain) { + source.ext.schain = schain; + } + + const bidderTimeout = config.getConfig('bidderTimeout') || timeout; + const tmax = timeout ? Math.min(bidderTimeout, timeout) : bidderTimeout; + + let request = { + id: bidderRequestId, + site: { + page: referer + }, + tmax, + source, + imp + }; + + if (content) { + request.site.content = content; + } + + const userData = []; + addSegments('iow_labs_pub_data', 'jwpseg', jwpseg, userData); + addSegments('permutive', 'p_standard', permutiveseg, userData, 'permutive.com'); + + if (userData.length) { + user = { + data: userData + }; + } + + if (gdprConsent && gdprConsent.consentString) { + userExt = {consent: gdprConsent.consentString}; + } + + if (userIdAsEids && userIdAsEids.length) { + userExt = userExt || {}; + userExt.eids = [...userIdAsEids]; + } + + if (userExt && Object.keys(userExt).length) { + user = user || {}; + user.ext = userExt; + } + + if (user) { + request.user = user; + } + + const configKeywords = utils.transformBidderParamKeywords({ + 'user': utils.deepAccess(config.getConfig('ortb2.user'), 'keywords') || null, + 'context': utils.deepAccess(config.getConfig('ortb2.site'), 'keywords') || null + }); + + if (configKeywords.length) { + pageKeywords = (pageKeywords || []).concat(configKeywords); + } + + if (pageKeywords && pageKeywords.length > 0) { + pageKeywords.forEach(deleteValues); + } + + if (pageKeywords) { + request.ext = { + keywords: pageKeywords + }; + } + + if (gdprConsent && gdprConsent.gdprApplies) { + request.regs = { + ext: { + gdpr: gdprConsent.gdprApplies ? 1 : 0 + } + } + } + + if (uspConsent) { + if (!request.regs) { + request.regs = {ext: {}}; + } + request.regs.ext.us_privacy = uspConsent; + } + + return { + method: 'POST', + url: NEW_ENDPOINT_URL, + data: JSON.stringify(request), + newFormat: true, + bidsMap + }; +} + +function oldFormatRequest(validBidRequests, bidderRequest) { + const auids = []; + const bidsMap = {}; + const slotsMapByUid = {}; + const sizeMap = {}; + const bids = validBidRequests || []; + let priceType = 'net'; + let jwpseg = null; + let permutiveseg = null; + let pageKeywords; + let reqId; + + bids.forEach(bid => { + if (bid.params.priceType === 'gross') { + priceType = 'gross'; + } + reqId = bid.bidderRequestId; + const {params: {uid}, adUnitCode, rtd} = bid; + auids.push(uid); + const sizesId = utils.parseSizesInput(bid.sizes); + + if (!pageKeywords && !utils.isEmpty(bid.params.keywords)) { + const keywords = utils.transformBidderParamKeywords(bid.params.keywords); + + if (keywords.length > 0) { + keywords.forEach(deleteValues); + } + pageKeywords = keywords; + } + + if (rtd) { + const jwTargeting = rtd.jwplayer && rtd.jwplayer.targeting; + if (jwTargeting) { + if (!jwpseg && jwTargeting.segments) { + jwpseg = jwTargeting.segments; + } + } + const permutiveTargeting = rtd.p_standard && rtd.p_standard.targeting; + if (!permutiveseg && permutiveTargeting && permutiveTargeting.segments) { + permutiveseg = permutiveTargeting.segments; + } + } + + if (!slotsMapByUid[uid]) { + slotsMapByUid[uid] = {}; + } + const slotsMap = slotsMapByUid[uid]; + if (!slotsMap[adUnitCode]) { + slotsMap[adUnitCode] = {adUnitCode, bids: [bid], parents: []}; + } else { + slotsMap[adUnitCode].bids.push(bid); + } + const slot = slotsMap[adUnitCode]; + + sizesId.forEach((sizeId) => { + sizeMap[sizeId] = true; + if (!bidsMap[uid]) { + bidsMap[uid] = {}; + } + + if (!bidsMap[uid][sizeId]) { + bidsMap[uid][sizeId] = [slot]; + } else { + bidsMap[uid][sizeId].push(slot); + } + slot.parents.push({parent: bidsMap[uid], key: sizeId, uid}); + }); + }); + + const segmentsData = []; + addSegments('iow_labs_pub_data', 'jwpseg', jwpseg, segmentsData); + addSegments('permutive', 'p_standard', permutiveseg, segmentsData, 'permutive.com'); + + if (segmentsData.length) { + if (!pageKeywords) { + pageKeywords = []; + } + segmentsData.forEach(({segment}) => { + if (segment.length) { + pageKeywords.push({ + key: segment[0].name, + value: segment.map(({value}) => value) + }); + } + }); + } + + const payload = { + pt: priceType, + auids: auids.join(','), + sizes: utils.getKeys(sizeMap).join(','), + r: reqId, + wrapperType: 'Prebid_js', + wrapperVersion: '$prebid.version$' + }; + + if (pageKeywords) { + payload.keywords = JSON.stringify(pageKeywords); + } + + if (bidderRequest) { + if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) { + payload.u = bidderRequest.refererInfo.referer; + } + if (bidderRequest.timeout) { + payload.wtimeout = bidderRequest.timeout; + } + if (bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent.consentString) { + payload.gdpr_consent = bidderRequest.gdprConsent.consentString; + } + payload.gdpr_applies = + (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') + ? Number(bidderRequest.gdprConsent.gdprApplies) : 1; + } + if (bidderRequest.uspConsent) { + payload.us_privacy = bidderRequest.uspConsent; + } + } + + return { + method: 'GET', + url: ENDPOINT_URL, + data: utils.parseQueryStringParameters(payload).replace(/\&$/, ''), + bidsMap, + priceType + }; +} + registerBidder(spec); diff --git a/modules/trustxBidAdapter.md b/modules/trustxBidAdapter.md index f29d47eaf36..e891df8f161 100644 --- a/modules/trustxBidAdapter.md +++ b/modules/trustxBidAdapter.md @@ -14,55 +14,36 @@ TrustX Bid Adapter supports Banner and Video (instream and outstream). var adUnits = [ { code: 'test-div', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, + sizes: [[300, 250]], bids: [ { bidder: "trustx", params: { - uid: '58851', + uid: '44', + priceType: 'gross' // by default is 'net' } } ] },{ code: 'test-div', - mediaTypes: { - banner: { - sizes: [[728, 90],[300, 250]], - } - }, + sizes: [[728, 90]], bids: [ { bidder: "trustx", params: { - uid: 58851, + uid: 45, + priceType: 'gross', keywords: { - site: { - publisher: { - name: 'someKeywordsName', - brandsafety: ['disaster'], - topic: ['stress', 'fear'] - } - } + brandsafety: ['disaster'], + topic: ['stress', 'fear'] } } } ] },{ code: 'test-div', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 360], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1 - } - }, + sizes: [[640, 360]], + mediaTypes: { video: {} }, bids: [ { bidder: "trustx", @@ -71,6 +52,18 @@ TrustX Bid Adapter supports Banner and Video (instream and outstream). } } ] + },{ + code: 'test-div', + sizes: [[300, 250]], + bids: [ + { + bidder: "trustx", + params: { + uid: '58851', + useNewFormat: true + } + } + ] } ]; ``` diff --git a/modules/turktelekomBidAdapter.md b/modules/turktelekomBidAdapter.md new file mode 100644 index 00000000000..360e7f95230 --- /dev/null +++ b/modules/turktelekomBidAdapter.md @@ -0,0 +1,49 @@ +# Overview + +Module Name: Türk Telekom Bidder Adapter +Module Type: Bidder Adapter +Maintainer: turktelssp@gmail.com + +# Description + +Module that connects to Türk Telekom demand source to fetch bids. +Türk Telekom Bid Adapter supports Banner and Video (instream and outstream). + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + mediaTypes: { + banner: { + sizes: [[300, 250], [300,600]] + } + }, + bids: [ + { + bidder: "turktelekom", + params: { + uid: 17, + priceType: 'gross' // by default is 'net' + } + } + ] + },{ + code: 'test-div', + mediaTypes: { + video: { + playerSize: [[640, 360]], + context: 'instream' + } + }, + bids: [ + { + bidder: "turktelekom", + params: { + uid: 19 + } + } + ] + } + ]; +``` \ No newline at end of file diff --git a/modules/ucfunnelBidAdapter.js b/modules/ucfunnelBidAdapter.js index 8b85f1ebad3..69cbbc697fc 100644 --- a/modules/ucfunnelBidAdapter.js +++ b/modules/ucfunnelBidAdapter.js @@ -1,8 +1,8 @@ -import { generateUUID, _each } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; import { config } from '../src/config.js'; +import * as utils from '../src/utils.js'; const storage = getStorageManager(); const COOKIE_NAME = 'ucf_uid'; const VER = 'ADGENT_PREBID-2018011501'; @@ -283,7 +283,7 @@ function getRequestData(bid, bidderRequest) { ucfUid = storage.getCookie(COOKIE_NAME); bidData.ucfUid = ucfUid; } else { - ucfUid = generateUUID(); + ucfUid = utils.generateUUID(); bidData.ucfUid = ucfUid; storage.setCookie(COOKIE_NAME, ucfUid); } @@ -335,7 +335,7 @@ function getRequestData(bid, bidderRequest) { function addUserId(bidData, userId) { bidData['eids'] = ''; - _each(userId, (userIdObjectOrValue, userIdProviderKey) => { + utils._each(userId, (userIdObjectOrValue, userIdProviderKey) => { switch (userIdProviderKey) { case 'haloId': if (userIdObjectOrValue.haloId) { diff --git a/modules/uid2IdSystem.js b/modules/uid2IdSystem.js index c0cd9166784..053b57cb76d 100644 --- a/modules/uid2IdSystem.js +++ b/modules/uid2IdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logInfo } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {submodule} from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -28,11 +28,11 @@ function getStorage() { const storage = getStorage(); -const _logInfo = createLogInfo(LOG_PRE_FIX); +const logInfo = createLogInfo(LOG_PRE_FIX); function createLogInfo(prefix) { return function (...strings) { - logInfo(prefix + ' ', ...strings); + utils.logInfo(prefix + ' ', ...strings); } } @@ -48,7 +48,7 @@ function encodeId(value) { id: value } result.uid2 = bidIds; - _logInfo('Decoded value ' + JSON.stringify(result)); + logInfo('Decoded value ' + JSON.stringify(result)); return result; } return undefined; @@ -85,9 +85,9 @@ export const uid2IdSubmodule = { * @returns {uid2Id} */ getId(config, consentData) { - _logInfo('Creating UID 2.0'); + logInfo('Creating UID 2.0'); let value = readCookie() || readFromLocalStorage(); - _logInfo('The advertising token: ' + value); + logInfo('The advertising token: ' + value); return {id: value} }, diff --git a/modules/underdogmediaBidAdapter.js b/modules/underdogmediaBidAdapter.js index 2ca4de7a555..6268774bc12 100644 --- a/modules/underdogmediaBidAdapter.js +++ b/modules/underdogmediaBidAdapter.js @@ -1,4 +1,4 @@ -import { logMessage, flatten, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'underdogmedia'; @@ -7,7 +7,7 @@ const UDM_VENDOR_ID = '159'; const prebidVersion = '$prebid.version$'; let USER_SYNCED = false; -logMessage(`Initializing UDM Adapter. PBJS Version: ${prebidVersion} with adapter version: ${UDM_ADAPTER_VERSION} Updated 20191028`); +utils.logMessage(`Initializing UDM Adapter. PBJS Version: ${prebidVersion} with adapter version: ${UDM_ADAPTER_VERSION} Updated 20191028`); // helper function for testing user syncs export function resetUserSync() { @@ -29,7 +29,7 @@ export const spec = { validBidRequests.forEach(bidParam => { let bidParamSizes = bidParam.mediaTypes && bidParam.mediaTypes.banner && bidParam.mediaTypes.banner.sizes ? bidParam.mediaTypes.banner.sizes : bidParam.sizes; - sizes = flatten(sizes, parseSizesInput(bidParamSizes)); + sizes = utils.flatten(sizes, utils.parseSizesInput(bidParamSizes)); siteId = bidParam.params.siteId; }); @@ -99,7 +99,7 @@ export const spec = { var sizeNotFound = true; const bidParamSizes = bidParam.mediaTypes && bidParam.mediaTypes.banner && bidParam.mediaTypes.banner.sizes ? bidParam.mediaTypes.banner.sizes : bidParam.sizes - parseSizesInput(bidParamSizes).forEach(size => { + utils.parseSizesInput(bidParamSizes).forEach(size => { if (size === mid.width + 'x' + mid.height) { sizeNotFound = false; } diff --git a/modules/undertoneBidAdapter.js b/modules/undertoneBidAdapter.js index fda6f47b2af..14a765206b6 100644 --- a/modules/undertoneBidAdapter.js +++ b/modules/undertoneBidAdapter.js @@ -85,29 +85,18 @@ export const spec = { const vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); const vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); const pageSizeArray = vw == 0 || vh == 0 ? null : [vw, vh]; - const commons = { - 'adapterVersion': '$prebid.version$', - 'uids': validBidRequests[0].userId, - 'pageSize': pageSizeArray - }; - if (validBidRequests[0].schain) { - commons.schain = validBidRequests[0].schain; - } const payload = { 'x-ut-hb-params': [], - 'commons': commons + 'commons': { + 'adapterVersion': '$prebid.version$', + 'uids': validBidRequests[0].userId, + 'pageSize': pageSizeArray + } }; const referer = bidderRequest.refererInfo.referer; - const canonicalUrl = getCanonicalUrl(); - if (referer) { - commons.referrer = referer; - } - if (canonicalUrl) { - commons.canonicalUrl = canonicalUrl; - } const hostname = parseUrl(referer).hostname; let domain = extractDomainFromHost(hostname); - const pageUrl = canonicalUrl || referer; + const pageUrl = getCanonicalUrl() || referer; const pubid = validBidRequests[0].params.publisherId; let reqUrl = `${URL}?pid=${pubid}&domain=${domain}`; diff --git a/modules/undertoneBidAdapter.md b/modules/undertoneBidAdapter.md index 8e0b234fd7a..8ac84b77bd8 100644 --- a/modules/undertoneBidAdapter.md +++ b/modules/undertoneBidAdapter.md @@ -1,13 +1,9 @@ # Overview ``` -Module Name: Undertone Bidder Adapter +Module Name: Example Bidder Adapter Module Type: Bidder Adapter Maintainer: RampProgrammatic@perion.com -gdpr_supported: true -usp_supported: true -schain_supported: true -media_types: video, native ``` # Description diff --git a/modules/unicornBidAdapter.js b/modules/unicornBidAdapter.js index 0209c808979..e74c4425626 100644 --- a/modules/unicornBidAdapter.js +++ b/modules/unicornBidAdapter.js @@ -1,4 +1,4 @@ -import { logInfo, deepAccess, generateUUID } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {BANNER} from '../src/mediaTypes.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {getStorageManager} from '../src/storageManager.js'; @@ -8,7 +8,7 @@ const BIDDER_CODE = 'unicorn'; const UNICORN_ENDPOINT = 'https://ds.uncn.jp/pb/0/bid.json'; const UNICORN_DEFAULT_CURRENCY = 'JPY'; const UNICORN_PB_COOKIE_KEY = '__pb_unicorn_aud'; -const UNICORN_PB_VERSION = '1.1'; +const UNICORN_PB_VERSION = '1.0'; /** * Placement ID and Account ID are required. @@ -39,8 +39,8 @@ export const buildRequests = (validBidRequests, bidderRequest) => { * @returns {string} */ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { - logInfo('[UNICORN] buildOpenRtbBidRequestPayload.validBidRequests:', validBidRequests); - logInfo('[UNICORN] buildOpenRtbBidRequestPayload.bidderRequest:', bidderRequest); + utils.logInfo('[UNICORN] buildOpenRtbBidRequestPayload.validBidRequests:', validBidRequests); + utils.logInfo('[UNICORN] buildOpenRtbBidRequestPayload.bidderRequest:', bidderRequest); const imp = validBidRequests.map(br => { return { id: br.bidId, @@ -49,7 +49,7 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { w: br.sizes[0][0], h: br.sizes[0][1] }, - tagid: deepAccess(br, 'params.placementId') || br.adUnitCode, + tagid: utils.deepAccess(br, 'params.placementId') || br.adUnitCode, secure: 1, bidfloor: parseFloat(0) }; @@ -58,11 +58,11 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { id: bidderRequest.auctionId, at: 1, imp, - cur: [UNICORN_DEFAULT_CURRENCY], + cur: UNICORN_DEFAULT_CURRENCY, site: { - id: deepAccess(validBidRequests[0], 'params.mediaId') || '', + id: utils.deepAccess(validBidRequests[0], 'params.mediaId') || '', publisher: { - id: String(deepAccess(validBidRequests[0], 'params.publisherId') || 0) + id: utils.deepAccess(validBidRequests[0], 'params.publisherId') || 0 }, domain: window.location.hostname, page: window.location.href, @@ -75,7 +75,7 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { user: { id: getUid() }, - bcat: deepAccess(validBidRequests[0], 'params.bcat') || [], + bcat: utils.deepAccess(validBidRequests[0], 'params.bcat') || [], source: { ext: { stype: 'prebid_uncn', @@ -84,16 +84,16 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) { } }, ext: { - accountId: deepAccess(validBidRequests[0], 'params.accountId') + accountId: utils.deepAccess(validBidRequests[0], 'params.accountId') } }; - logInfo('[UNICORN] OpenRTB Formatted Request:', request); + utils.logInfo('[UNICORN] OpenRTB Formatted Request:', request); return JSON.stringify(request); } const interpretResponse = (serverResponse, request) => { - logInfo('[UNICORN] interpretResponse.serverResponse:', serverResponse); - logInfo('[UNICORN] interpretResponse.request:', request); + utils.logInfo('[UNICORN] interpretResponse.serverResponse:', serverResponse); + utils.logInfo('[UNICORN] interpretResponse.request:', request); const res = serverResponse.body; var bids = [] if (res) { @@ -119,7 +119,7 @@ const interpretResponse = (serverResponse, request) => { }) }); } - logInfo('[UNICORN] interpretResponse bids:', bids); + utils.logInfo('[UNICORN] interpretResponse bids:', bids); return bids; }; @@ -132,7 +132,7 @@ const getUid = () => { return JSON.parse(ck)['uid']; } else { const newCk = { - uid: generateUUID() + uid: utils.generateUUID() }; const expireIn = new Date(Date.now() + 24 * 60 * 60 * 10000).toUTCString(); storage.setCookie(UNICORN_PB_COOKIE_KEY, JSON.stringify(newCk), expireIn); diff --git a/modules/unifiedIdSystem.js b/modules/unifiedIdSystem.js index 8ec5fcd3f90..bc033f37992 100644 --- a/modules/unifiedIdSystem.js +++ b/modules/unifiedIdSystem.js @@ -5,7 +5,7 @@ * @requires module:modules/userId */ -import { logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js' @@ -40,7 +40,7 @@ export const unifiedIdSubmodule = { getId(config) { const configParams = (config && config.params) || {}; if (!configParams || (typeof configParams.partner !== 'string' && typeof configParams.url !== 'string')) { - logError('User ID - unifiedId submodule requires either partner or url to be defined'); + utils.logError('User ID - unifiedId submodule requires either partner or url to be defined'); return; } // use protocol relative urls for http or https @@ -54,13 +54,13 @@ export const unifiedIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - logError(error); + utils.logError(error); } } callback(responseObj); }, error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; diff --git a/modules/unrulyBidAdapter.js b/modules/unrulyBidAdapter.js index 99fbe63aeb4..d04192acf15 100644 --- a/modules/unrulyBidAdapter.js +++ b/modules/unrulyBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {Renderer} from '../src/Renderer.js' import {registerBidder} from '../src/adapters/bidderFactory.js' import {VIDEO, BANNER} from '../src/mediaTypes.js' @@ -41,7 +41,7 @@ const addBidFloorInfo = (validBid) => { }; const RemoveDuplicateSizes = (validBid) => { - let bannerMediaType = deepAccess(validBid, 'mediaTypes.banner'); + let bannerMediaType = utils.deepAccess(validBid, 'mediaTypes.banner'); if (bannerMediaType) { let seenSizes = {}; let newSizesArray = []; @@ -87,12 +87,12 @@ const handleBidResponseByMediaType = (bids) => { bids.forEach((bid) => { let parsedBidResponse; - let bidMediaType = deepAccess(bid, 'meta.mediaType'); + let bidMediaType = utils.deepAccess(bid, 'meta.mediaType'); if (bidMediaType && bidMediaType.toLowerCase() === 'banner') { bid.mediaType = BANNER; parsedBidResponse = handleBannerBid(bid); } else if (bidMediaType && bidMediaType.toLowerCase() === 'video') { - let context = deepAccess(bid, 'meta.videoContext'); + let context = utils.deepAccess(bid, 'meta.videoContext'); bid.mediaType = VIDEO; if (context === 'instream') { parsedBidResponse = handleInStreamBid(bid); @@ -111,7 +111,7 @@ const handleBidResponseByMediaType = (bids) => { const handleBannerBid = (bid) => { if (!bid.ad) { - logError(new Error('UnrulyBidAdapter: Missing ad config.')); + utils.logError(new Error('UnrulyBidAdapter: Missing ad config.')); return; } @@ -120,7 +120,7 @@ const handleBannerBid = (bid) => { const handleInStreamBid = (bid) => { if (!(bid.vastUrl || bid.vastXml)) { - logError(new Error('UnrulyBidAdapter: Missing vastUrl or vastXml config.')); + utils.logError(new Error('UnrulyBidAdapter: Missing vastUrl or vastXml config.')); return; } @@ -128,19 +128,19 @@ const handleInStreamBid = (bid) => { }; const handleOutStreamBid = (bid) => { - const hasConfig = !!deepAccess(bid, 'ext.renderer.config'); - const hasSiteId = !!deepAccess(bid, 'ext.renderer.config.siteId'); + const hasConfig = !!utils.deepAccess(bid, 'ext.renderer.config'); + const hasSiteId = !!utils.deepAccess(bid, 'ext.renderer.config.siteId'); if (!hasConfig) { - logError(new Error('UnrulyBidAdapter: Missing renderer config.')); + utils.logError(new Error('UnrulyBidAdapter: Missing renderer config.')); return; } if (!hasSiteId) { - logError(new Error('UnrulyBidAdapter: Missing renderer siteId.')); + utils.logError(new Error('UnrulyBidAdapter: Missing renderer siteId.')); return; } - const exchangeRenderer = deepAccess(bid, 'ext.renderer'); + const exchangeRenderer = utils.deepAccess(bid, 'ext.renderer'); configureUniversalTag(exchangeRenderer, bid.requestId); configureRendererQueue(); @@ -152,7 +152,7 @@ const handleOutStreamBid = (bid) => { bid, { renderer: rendererInstance, - adUnitCode: deepAccess(bid, 'ext.adUnitCode') + adUnitCode: utils.deepAccess(bid, 'ext.adUnitCode') } ); @@ -165,8 +165,8 @@ const handleOutStreamBid = (bid) => { }; const isMediaTypesValid = (bid) => { - const mediaTypeVideoData = deepAccess(bid, 'mediaTypes.video'); - const mediaTypeBannerData = deepAccess(bid, 'mediaTypes.banner'); + const mediaTypeVideoData = utils.deepAccess(bid, 'mediaTypes.video'); + const mediaTypeBannerData = utils.deepAccess(bid, 'mediaTypes.banner'); let isValid = !!(mediaTypeVideoData || mediaTypeBannerData); if (isValid && mediaTypeVideoData) { isValid = isVideoMediaTypeValid(mediaTypeVideoData); @@ -194,7 +194,7 @@ export const adapter = { code: 'unruly', supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - let siteId = deepAccess(bid, 'params.siteId'); + let siteId = utils.deepAccess(bid, 'params.siteId'); let isBidValid = siteId && isMediaTypesValid(bid); return !!isBidValid; }, @@ -202,7 +202,7 @@ export const adapter = { buildRequests: function (validBidRequests, bidderRequest) { let endPoint = 'https://targeting.unrulymedia.com/unruly_prebid'; if (validBidRequests[0]) { - endPoint = deepAccess(validBidRequests[0], 'params.endpoint') || endPoint; + endPoint = utils.deepAccess(validBidRequests[0], 'params.endpoint') || endPoint; } const url = endPoint; diff --git a/modules/userId/eids.js b/modules/userId/eids.js index a290371b36d..71267616662 100644 --- a/modules/userId/eids.js +++ b/modules/userId/eids.js @@ -1,4 +1,4 @@ -import { pick, isFn, isStr, isPlainObject, deepAccess } from '../../src/utils.js'; +import * as utils from '../../src/utils.js'; // Each user-id sub-module is expected to mention respective config here const USER_IDS_CONFIG = { @@ -11,12 +11,6 @@ const USER_IDS_CONFIG = { atype: 1 }, - // naveggId - 'naveggId': { - source: 'navegg.com', - atype: 1 - }, - // pubCommonId 'pubcid': { source: 'pubcid.org', @@ -64,7 +58,7 @@ const USER_IDS_CONFIG = { return null; }, getUidExt: function(parrableId) { - const extendedData = pick(parrableId, [ + const extendedData = utils.pick(parrableId, [ 'ibaOptout', 'ccpaOptout' ]); @@ -181,18 +175,15 @@ const USER_IDS_CONFIG = { source: 'neustar.biz', atype: 1 }, - // MediaWallah OpenLink 'mwOpenLinkId': { source: 'mediawallahscript.com', atype: 1 }, - 'tapadId': { source: 'tapad.com', atype: 1 }, - // Novatiq Snowflake 'novatiq': { getValue: function(data) { @@ -201,7 +192,6 @@ const USER_IDS_CONFIG = { source: 'novatiq.com', atype: 1 }, - 'uid2': { source: 'uidapi.com', atype: 3, @@ -209,61 +199,37 @@ const USER_IDS_CONFIG = { return data.id; } }, - + 'deepintentId': { + source: 'deepintent.com', + atype: 3 + }, // Akamai Data Activation Platform (DAP) 'dapId': { source: 'akamai.com', atype: 1 }, - - 'deepintentId': { - source: 'deepintent.com', - atype: 3 - }, - // Admixer Id 'admixerId': { source: 'admixer.net', atype: 3 }, - // Adtelligent Id 'adtelligentId': { source: 'adtelligent.com', atype: 3 }, - amxId: { source: 'amxrtb.com', atype: 1, }, - - 'publinkId': { - source: 'epsilon.com', - atype: 3 - }, - 'kpuid': { source: 'kpuid.com', atype: 3 }, - 'imuid': { source: 'intimatemerger.com', atype: 1 - }, - - // Yahoo ConnectID - 'connectId': { - source: 'yahoo.com', - atype: 3 - }, - - // Adquery ID - 'qid': { - source: 'adquery.io', - atype: 1 - }, + } }; // this function will create an eid object for the given UserId sub-module @@ -272,11 +238,11 @@ function createEidObject(userIdData, subModuleKey) { if (conf && userIdData) { let eid = {}; eid.source = conf['source']; - const value = isFn(conf['getValue']) ? conf['getValue'](userIdData) : userIdData; - if (isStr(value)) { + const value = utils.isFn(conf['getValue']) ? conf['getValue'](userIdData) : userIdData; + if (utils.isStr(value)) { const uid = { id: value, atype: conf['atype'] }; // getUidExt - if (isFn(conf['getUidExt'])) { + if (utils.isFn(conf['getUidExt'])) { const uidExt = conf['getUidExt'](userIdData); if (uidExt) { uid.ext = uidExt; @@ -284,7 +250,7 @@ function createEidObject(userIdData, subModuleKey) { } eid.uids = [uid]; // getEidExt - if (isFn(conf['getEidExt'])) { + if (utils.isFn(conf['getEidExt'])) { const eidExt = conf['getEidExt'](userIdData); if (eidExt) { eid.ext = eidExt; @@ -321,11 +287,11 @@ export function createEidsArray(bidRequestUserId) { */ export function buildEidPermissions(submodules) { let eidPermissions = []; - submodules.filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length) + submodules.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length) .forEach(i => { Object.keys(i.idObj).forEach(key => { - if (deepAccess(i, 'config.bidders') && Array.isArray(i.config.bidders) && - deepAccess(USER_IDS_CONFIG, key + '.source')) { + if (utils.deepAccess(i, 'config.bidders') && Array.isArray(i.config.bidders) && + utils.deepAccess(USER_IDS_CONFIG, key + '.source')) { eidPermissions.push( { source: USER_IDS_CONFIG[key].source, diff --git a/modules/userId/eids.md b/modules/userId/eids.md index 679bf5ffe27..ab454c54d30 100644 --- a/modules/userId/eids.md +++ b/modules/userId/eids.md @@ -21,14 +21,6 @@ userIdAsEids = [ }] }, - { - source: 'navegg.com', - uids: [{ - id: 'naveggId', - atype: 1 - }] - }, - { source: 'neustar.biz', uids: [{ @@ -184,17 +176,17 @@ userIdAsEids = [ }] }, { - source: 'akamai.com', + source: 'admixer.net', uids: [{ id: 'some-random-id-value', - atype: 1 + atype: 3 }] }, { - source: 'admixer.net', + source: 'akamai.com', uids: [{ id: 'some-random-id-value', - atype: 3 + atype: 1 }] }, { @@ -210,13 +202,6 @@ userIdAsEids = [ id: 'some-random-id-value', atype: 3 }] - }, - { - source: 'yahoo.com', - uids: [{ - id: 'some-random-id-value', - atype: 3 - }] } ] ``` diff --git a/modules/userId/index.js b/modules/userId/index.js index 42fff2cd16c..a6a824fe89e 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -133,16 +133,14 @@ import find from 'core-js-pure/features/array/find.js'; import { config } from '../../src/config.js'; import events from '../../src/events.js'; +import * as utils from '../../src/utils.js'; import { getGlobal } from '../../src/prebidGlobal.js'; import { gdprDataHandler } from '../../src/adapterManager.js'; import CONSTANTS from '../../src/constants.json'; import { module, hook } from '../../src/hook.js'; import { createEidsArray, buildEidPermissions } from './eids.js'; import { getCoreStorageManager } from '../../src/storageManager.js'; -import { - getPrebidInternal, isPlainObject, logError, isArray, cyrb53Hash, deepAccess, timestamp, delayExecution, logInfo, isFn, - logWarn, isEmptyStr, isNumber, isGptPubadsDefined -} from '../../src/utils.js'; +import {getPrebidInternal} from '../../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const MODULE_NAME = 'User ID'; @@ -184,9 +182,6 @@ export let syncDelay; /** @type {(number|undefined)} */ export let auctionDelay; -/** @type {(string|undefined)} */ -let ppidSource; - /** @param {Submodule[]} submodules */ export function setSubmoduleRegistry(submodules) { submoduleRegistry = submodules; @@ -204,7 +199,7 @@ export function setStoredValue(submodule, value) { const domainOverride = (typeof submodule.submodule.domainOverride === 'function') ? submodule.submodule.domainOverride() : null; try { - const valueStr = isPlainObject(value) ? JSON.stringify(value) : value; + const valueStr = utils.isPlainObject(value) ? JSON.stringify(value) : value; const expiresStr = (new Date(Date.now() + (storage.expires * (60 * 60 * 24 * 1000)))).toUTCString(); if (storage.type === COOKIE) { coreStorage.setCookie(storage.name, valueStr, expiresStr, 'Lax', domainOverride); @@ -219,13 +214,13 @@ export function setStoredValue(submodule, value) { } } } catch (error) { - logError(error); + utils.logError(error); } } function setPrebidServerEidPermissions(initializedSubmodules) { let setEidPermissions = getPrebidInternal().setEidPermissions; - if (typeof setEidPermissions === 'function' && isArray(initializedSubmodules)) { + if (typeof setEidPermissions === 'function' && utils.isArray(initializedSubmodules)) { setEidPermissions(buildEidPermissions(initializedSubmodules)); } } @@ -258,7 +253,7 @@ function getStoredValue(storage, key = undefined) { storedValue = JSON.parse(storedValue); } } catch (e) { - logError(e); + utils.logError(e); } return storedValue; } @@ -283,7 +278,7 @@ function makeStoredConsentDataHash(consentData) { storedConsentData.apiVersion = consentData.apiVersion; } - return cyrb53Hash(JSON.stringify(storedConsentData)); + return utils.cyrb53Hash(JSON.stringify(storedConsentData)); } /** @@ -295,7 +290,7 @@ export function setStoredConsentData(consentData) { const expiresStr = (new Date(Date.now() + (CONSENT_DATA_COOKIE_STORAGE_CONFIG.expires * (60 * 60 * 24 * 1000)))).toUTCString(); coreStorage.setCookie(CONSENT_DATA_COOKIE_STORAGE_CONFIG.name, makeStoredConsentDataHash(consentData), expiresStr, 'Lax'); } catch (error) { - logError(error); + utils.logError(error); } } @@ -307,7 +302,7 @@ function getStoredConsentData() { try { return coreStorage.getCookie(CONSENT_DATA_COOKIE_STORAGE_CONFIG.name); } catch (e) { - logError(e); + utils.logError(e); } } @@ -337,10 +332,10 @@ function hasGDPRConsent(consentData) { if (!consentData.consentString) { return false; } - if (consentData.apiVersion === 1 && deepAccess(consentData, 'vendorData.purposeConsents.1') === false) { + if (consentData.apiVersion === 1 && utils.deepAccess(consentData, 'vendorData.purposeConsents.1') === false) { return false; } - if (consentData.apiVersion === 2 && deepAccess(consentData, 'vendorData.purpose.consents.1') === false) { + if (consentData.apiVersion === 2 && utils.deepAccess(consentData, 'vendorData.purpose.consents.1') === false) { return false; } } @@ -368,7 +363,7 @@ export function findRootDomain(fullDomain = window.location.hostname) { const TEST_COOKIE_VALUE = 'writeable'; do { rootDomain = domainParts.slice(startIndex).join('.'); - let expirationDate = new Date(timestamp() + 10 * 1000).toUTCString(); + let expirationDate = new Date(utils.timestamp() + 10 * 1000).toUTCString(); // Write a test cookie coreStorage.setCookie( @@ -408,7 +403,7 @@ export function findRootDomain(fullDomain = window.location.hostname) { function processSubmoduleCallbacks(submodules, cb) { let done = () => {}; if (cb) { - done = delayExecution(() => { + done = utils.delayExecution(() => { clearTimeout(timeoutID); cb(); }, submodules.length); @@ -423,7 +418,7 @@ function processSubmoduleCallbacks(submodules, cb) { // cache decoded value (this is copied to every adUnit bid) submodule.idObj = submodule.submodule.decode(idObj, submodule.config); } else { - logInfo(`${MODULE_NAME}: ${submodule.submodule.name} - request id responded with an empty value`); + utils.logInfo(`${MODULE_NAME}: ${submodule.submodule.name} - request id responded with an empty value`); } done(); }); @@ -441,7 +436,7 @@ function getCombinedSubmoduleIds(submodules) { if (!Array.isArray(submodules) || !submodules.length) { return {}; } - const combinedSubmoduleIds = submodules.filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length).reduce((carry, i) => { + const combinedSubmoduleIds = submodules.filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length).reduce((carry, i) => { Object.keys(i.idObj).forEach(key => { carry[key] = i.idObj[key]; }); @@ -461,8 +456,8 @@ function getCombinedSubmoduleIdsForBidder(submodules, bidder) { return {}; } return submodules - .filter(i => !i.config.bidders || !isArray(i.config.bidders) || includes(i.config.bidders, bidder)) - .filter(i => isPlainObject(i.idObj) && Object.keys(i.idObj).length) + .filter(i => !i.config.bidders || !utils.isArray(i.config.bidders) || includes(i.config.bidders, bidder)) + .filter(i => utils.isPlainObject(i.idObj) && Object.keys(i.idObj).length) .reduce((carry, i) => { Object.keys(i.idObj).forEach(key => { carry[key] = i.idObj[key]; @@ -480,7 +475,7 @@ function addIdDataToAdUnitBids(adUnits, submodules) { return; } adUnits.forEach(adUnit => { - if (adUnit.bids && isArray(adUnit.bids)) { + if (adUnit.bids && utils.isArray(adUnit.bids)) { adUnit.bids.forEach(bid => { const combinedSubmoduleIds = getCombinedSubmoduleIdsForBidder(submodules, bid.bidder); if (Object.keys(combinedSubmoduleIds).length) { @@ -505,7 +500,7 @@ function initializeSubmodulesAndExecuteCallbacks(continueAuction) { if (initializedSubmodules.length) { setPrebidServerEidPermissions(initializedSubmodules); // list of submodules that have callbacks that need to be executed - const submodulesWithCallbacks = initializedSubmodules.filter(item => isFn(item.callback)); + const submodulesWithCallbacks = initializedSubmodules.filter(item => utils.isFn(item.callback)); if (submodulesWithCallbacks.length) { if (continueAuction && auctionDelay > 0) { @@ -518,7 +513,7 @@ function initializeSubmodulesAndExecuteCallbacks(continueAuction) { continueAuction(); } } - logInfo(`${MODULE_NAME} - auction delayed by ${auctionDelay} at most to fetch ids`); + utils.logInfo(`${MODULE_NAME} - auction delayed by ${auctionDelay} at most to fetch ids`); timeoutID = setTimeout(continueCallback, auctionDelay); processSubmoduleCallbacks(submodulesWithCallbacks, continueCallback); @@ -560,26 +555,6 @@ export function requestBidsHook(fn, reqBidsConfigObj) { initializeSubmodulesAndExecuteCallbacks(function () { // pass available user id data to bid adapters addIdDataToAdUnitBids(reqBidsConfigObj.adUnits || getGlobal().adUnits, initializedSubmodules); - - // userSync.ppid should be one of the 'source' values in getUserIdsAsEids() eg pubcid.org or id5-sync.com - const matchingUserId = ppidSource && (getUserIdsAsEids() || []).find(userID => userID.source === ppidSource); - if (matchingUserId && typeof deepAccess(matchingUserId, 'uids.0.id') === 'string') { - const ppidValue = matchingUserId.uids[0].id.replace(/[\W_]/g, ''); - if (ppidValue.length >= 32 && ppidValue.length <= 150) { - if (isGptPubadsDefined()) { - window.googletag.pubads().setPublisherProvidedId(ppidValue); - } else { - window.googletag = window.googletag || {}; - window.googletag.cmd = window.googletag.cmd || []; - window.googletag.cmd.push(function() { - window.googletag.pubads().setPublisherProvidedId(ppidValue); - }); - } - } else { - logWarn(`User ID - Googletag Publisher Provided ID for ${ppidSource} is not between 32 and 150 characters - ${ppidValue}`); - } - } - // calling fn allows prebid to continue processing fn.call(this, reqBidsConfigObj); }); @@ -621,7 +596,7 @@ function refreshUserIds(options, callback) { // gdpr consent with purpose one is required, otherwise exit immediately let {userIdModules, hasValidated} = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { - logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); + utils.logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); return; } @@ -636,7 +611,7 @@ function refreshUserIds(options, callback) { continue; } - logInfo(`${MODULE_NAME} - refreshing ${submodule.submodule.name}`); + utils.logInfo(`${MODULE_NAME} - refreshing ${submodule.submodule.name}`); populateSubmoduleId(submodule, consentData, storedConsentData, true); updateInitializedSubmodules(submodule); @@ -644,7 +619,7 @@ function refreshUserIds(options, callback) { setPrebidServerEidPermissions(initializedSubmodules); } - if (isFn(submodule.callback)) { + if (utils.isFn(submodule.callback)) { callbackSubmodules.push(submodule); } } @@ -688,7 +663,7 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef response = submodule.submodule.extendId(submodule.config, consentData, storedId); } - if (isPlainObject(response)) { + if (utils.isPlainObject(response)) { if (response.id) { // A getId/extendId result assumed to be valid user id data, which should be saved to users local storage or cookies setStoredValue(submodule, response.id); @@ -710,7 +685,7 @@ function populateSubmoduleId(submodule, consentData, storedConsentData, forceRef submodule.idObj = submodule.config.value; } else { const response = submodule.submodule.getId(submodule.config, consentData, undefined); - if (isPlainObject(response)) { + if (utils.isPlainObject(response)) { if (typeof response.callback === 'function') { submodule.callback = response.callback; } if (response.id) { submodule.idObj = submodule.submodule.decode(response.id, submodule.config); } } @@ -726,7 +701,7 @@ function initSubmodules(submodules, consentData) { // gdpr consent with purpose one is required, otherwise exit immediately let { userIdModules, hasValidated } = validateGdprEnforcement(submodules, consentData); if (!hasValidated && !hasGDPRConsent(consentData)) { - logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); + utils.logWarn(`${MODULE_NAME} - gdpr permission not valid for local storage or cookies, exit module`); return []; } @@ -771,17 +746,17 @@ function getValidSubmoduleConfigs(configRegistry, submoduleRegistry, activeStora } return configRegistry.reduce((carry, config) => { // every submodule config obj must contain a valid 'name' - if (!config || isEmptyStr(config.name)) { + if (!config || utils.isEmptyStr(config.name)) { return carry; } // Validate storage config contains 'type' and 'name' properties with non-empty string values // 'type' must be a value currently enabled in the browser if (config.storage && - !isEmptyStr(config.storage.type) && - !isEmptyStr(config.storage.name) && + !utils.isEmptyStr(config.storage.type) && + !utils.isEmptyStr(config.storage.name) && activeStorageTypes.indexOf(config.storage.type) !== -1) { carry.push(config); - } else if (isPlainObject(config.value)) { + } else if (utils.isPlainObject(config.value)) { carry.push(config); } else if (!config.storage && !config.value) { carry.push(config); @@ -818,7 +793,7 @@ function updateSubmodules() { if (!addedUserIdHook && submodules.length) { // priority value 40 will load after consentManagement with a priority of 50 getGlobal().requestBids.before(requestBidsHook, 40); - logInfo(`${MODULE_NAME} - usersync config updated for ${submodules.length} submodules: `, submodules.map(a => a.submodule.name)); + utils.logInfo(`${MODULE_NAME} - usersync config updated for ${submodules.length} submodules: `, submodules.map(a => a.submodule.name)); addedUserIdHook = true; } } @@ -840,7 +815,6 @@ export function attachIdSystem(submodule) { * @param {{getConfig:function}} config */ export function init(config) { - ppidSource = undefined; submodules = []; configRegistry = []; addedUserIdHook = false; @@ -854,23 +828,22 @@ export function init(config) { // exit immediately if opt out cookie or local storage keys exists. if (validStorageTypes.indexOf(COOKIE) !== -1 && coreStorage.getCookie(PBJS_USER_ID_OPTOUT_NAME)) { - logInfo(`${MODULE_NAME} - opt-out cookie found, exit module`); + utils.logInfo(`${MODULE_NAME} - opt-out cookie found, exit module`); return; } if (validStorageTypes.indexOf(LOCAL_STORAGE) !== -1 && coreStorage.getDataFromLocalStorage(PBJS_USER_ID_OPTOUT_NAME)) { - logInfo(`${MODULE_NAME} - opt-out localStorage found, exit module`); + utils.logInfo(`${MODULE_NAME} - opt-out localStorage found, exit module`); return; } // listen for config userSyncs to be set - config.getConfig('userSync', conf => { + config.getConfig(conf => { // Note: support for 'usersync' was dropped as part of Prebid.js 4.0 const userSync = conf.userSync; - ppidSource = userSync.ppid; if (userSync && userSync.userIds) { configRegistry = userSync.userIds; - syncDelay = isNumber(userSync.syncDelay) ? userSync.syncDelay : DEFAULT_SYNC_DELAY; - auctionDelay = isNumber(userSync.auctionDelay) ? userSync.auctionDelay : NO_AUCTION_DELAY; + syncDelay = utils.isNumber(userSync.syncDelay) ? userSync.syncDelay : DEFAULT_SYNC_DELAY; + auctionDelay = utils.isNumber(userSync.auctionDelay) ? userSync.auctionDelay : NO_AUCTION_DELAY; updateSubmodules(); } }); diff --git a/modules/userId/userId.md b/modules/userId/userId.md index 6364de8ea79..11bf74e5d87 100644 --- a/modules/userId/userId.md +++ b/modules/userId/userId.md @@ -285,26 +285,6 @@ pbjs.setConfig({ params: { cid: 5126 // Set your Intimate Merger Customer ID here for production } - }, - { - name: 'connectId', - params: { - pixelId: 58776, - he: '0bef996248d63cea1529cb86de31e9547a712d9f380146e98bbd39beec70355a' - }, - storage: { - name: 'connectId', - type: 'html5', - expires: 15 - } - } - { - name: "qid", - storage: { - type: "html5", - name: "qid", - expires: 365 - } }], syncDelay: 5000 } @@ -336,9 +316,6 @@ pbjs.setConfig({ { name: "novatiq", value: { "snowflake": "81b001ec-8914-488c-a96e-8c220d4ee08895ef" } - }, - { - name: 'naveggId', }], syncDelay: 5000 } diff --git a/modules/validationFpdModule/config.js b/modules/validationFpdModule/config.js index c87265fa1df..f6adfea70eb 100644 --- a/modules/validationFpdModule/config.js +++ b/modules/validationFpdModule/config.js @@ -85,21 +85,7 @@ export const ORTB_MAP = { }, publisher: { type: TYPES.object, - isArray: false, - children: { - id: { type: TYPES.string }, - name: { type: TYPES.string }, - cat: { - type: TYPES.object, - isArray: true, - childType: TYPES.string - }, - domain: { type: TYPES.string }, - ext: { - type: TYPES.object, - isArray: false - } - } + isArray: false }, } }, @@ -135,15 +121,5 @@ export const ORTB_MAP = { } } } - }, - bcat: { - type: TYPES.object, - isArray: true, - childType: TYPES.string - }, - badv: { - type: TYPES.object, - isArray: true, - childType: TYPES.string } } diff --git a/modules/validationFpdModule/index.js b/modules/validationFpdModule/index.js index 2db170c1bd1..c23f7e09316 100644 --- a/modules/validationFpdModule/index.js +++ b/modules/validationFpdModule/index.js @@ -3,7 +3,7 @@ * @module modules/firstPartyData */ import { config } from '../../src/config.js'; -import { isEmpty, isNumber, logWarn, deepAccess } from '../../src/utils.js'; +import * as utils from '../../src/utils.js'; import { ORTB_MAP } from './config.js'; import { submodule } from '../../src/hook.js'; import { getStorageManager } from '../../src/storageManager.js'; @@ -19,9 +19,9 @@ let optout; function isEmptyData(data) { let check = true; - if (typeof data === 'object' && !isEmpty(data)) { + if (typeof data === 'object' && !utils.isEmpty(data)) { check = false; - } else if (typeof data !== 'object' && (isNumber(data) || data)) { + } else if (typeof data !== 'object' && (utils.isNumber(data) || data)) { check = false; } @@ -42,7 +42,7 @@ function getRequiredData(obj, required, parent, i) { required.forEach(key => { if (!obj[key] || isEmptyData(obj[key])) { check = false; - logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: missing required property ${key}`); + utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: missing required property ${key}`); } }); @@ -91,22 +91,21 @@ export function filterArrayData(arr, child, path, parent) { return true; } - logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); + utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); }).filter((index, i) => { let requiredCheck = true; - let mapping = deepAccess(ORTB_MAP, path); + let mapping = utils.deepAccess(ORTB_MAP, path); if (mapping && mapping.required) requiredCheck = getRequiredData(index, mapping.required, parent, i); if (requiredCheck) return true; }).reduce((result, value, i) => { let typeBool = false; - let mapping = deepAccess(ORTB_MAP, path); + let mapping = utils.deepAccess(ORTB_MAP, path); switch (child.type) { case 'string': result.push(value); - typeBool = true; break; case 'object': if (mapping && mapping.children) { @@ -126,7 +125,7 @@ export function filterArrayData(arr, child, path, parent) { break; } - if (!typeBool) logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); + if (!typeBool) utils.logWarn(`Filtered ${parent}[] value at index ${i} in ortb2 data: expected type ${child.type}`); return result; }, []); @@ -146,26 +145,26 @@ export function validateFpd(fpd, path = '', parent = '') { // Filter out imp property if exists let validObject = Object.assign({}, Object.keys(fpd).filter(key => { - let mapping = deepAccess(ORTB_MAP, path + key); + let mapping = utils.deepAccess(ORTB_MAP, path + key); if (!mapping || !mapping.invalid) return key; - logWarn(`Filtered ${parent}${key} property in ortb2 data: invalid property`); + utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: invalid property`); }).filter(key => { - let mapping = deepAccess(ORTB_MAP, path + key); + let mapping = utils.deepAccess(ORTB_MAP, path + key); // let typeBool = false; let typeBool = (mapping) ? typeValidation(fpd[key], {type: mapping.type, isArray: mapping.isArray}) : true; if (typeBool || !mapping) return key; - logWarn(`Filtered ${parent}${key} property in ortb2 data: expected type ${(mapping.isArray) ? 'array' : mapping.type}`); + utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: expected type ${(mapping.isArray) ? 'array' : mapping.type}`); }).reduce((result, key) => { - let mapping = deepAccess(ORTB_MAP, path + key); + let mapping = utils.deepAccess(ORTB_MAP, path + key); let modified = {}; if (mapping) { if (mapping.optoutApplies && optout) { - logWarn(`Filtered ${parent}${key} data: pubcid optout found`); + utils.logWarn(`Filtered ${parent}${key} data: pubcid optout found`); return result; } @@ -176,7 +175,7 @@ export function validateFpd(fpd, path = '', parent = '') { // Check if modified data has data and return (!isEmptyData(modified)) ? result[key] = modified - : logWarn(`Filtered ${parent}${key} property in ortb2 data: empty data found`); + : utils.logWarn(`Filtered ${parent}${key} property in ortb2 data: empty data found`); } else { result[key] = fpd[key]; } diff --git a/modules/vdoaiBidAdapter.js b/modules/vdoaiBidAdapter.js index 40e3b3322a7..4bf5a27c002 100644 --- a/modules/vdoaiBidAdapter.js +++ b/modules/vdoaiBidAdapter.js @@ -1,4 +1,4 @@ -import { getAdUnitSizes } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; @@ -32,7 +32,7 @@ export const spec = { } return validBidRequests.map(bidRequest => { - const sizes = getAdUnitSizes(bidRequest); + const sizes = utils.getAdUnitSizes(bidRequest); const payload = { placementId: bidRequest.params.placementId, sizes: sizes, diff --git a/modules/ventes.md b/modules/ventes.md deleted file mode 100644 index 5f0f571ecd8..00000000000 --- a/modules/ventes.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -layout: bidder -title: ventes -description: Prebid ventes Bidder Adapter -pbjs: false -biddercode: ventes -gdpr_supported: false -usp_supported: false -media_types: banner -coppa_supported: false -schain_supported: false -dchain_supported: false -prebid_member: false ---- - -### BidParams -{: .table .table-bordered .table-striped } -| Name | Scope | Description | Example | Type | -|-----------------|----------|-----------------------------------------------------------|----------------------------------------------|---------------| -| `placementId` | required | Placement ID from Ventes Avenues | `'VA-062-0013-0183'` | `string` | -| `publisherId` | required | Publisher ID from Ventes Avenues | `'VA-062'` | `string` | -| `user` | optional | Object that specifies information about an external user. | `user: { age: 25, gender: 0, dnt: true}` | `object` | -| `app` | optional | Object containing mobile app parameters. | `app : { id: 'app-id'}` | `object` | - -#### User Object - -{: .table .table-bordered .table-striped } -| Name | Description | Example | Type | -|-------------------|-------------------------------------------------------------------------------------------|-----------------------|-----------------------| -| `age` | The age of the user. | `35` | `integer` | -| `externalUid` | Specifies a string that corresponds to an external user ID for this user. | `'1234567890abcdefg'` | `string` | -| `segments` | Specifies the segments to which the user belongs. | `[1, 2]` | `Array` | -| `gender` | Specifies the gender of the user. Allowed values: Unknown: `0`; Male: `1`; Female: `2` | `1` | `integer` | -| `dnt` | Do not track flag. Indicates if tracking cookies should be disabled for this auction | `true` | `boolean` | -| `language` | Two-letter ANSI code for this user's language. | `EN` | `string` | - - -### Ad Unit Setup for Banner -```javascript -var adUnits = [ -{ - code: 'test-hb-ad-11111-1', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bids: [{ - bidder: 'ventes', - params: { - placementId: 'VA-062-0013-0183', - publisherId: '5cebea3c9eea646c7b623d5e', - IABCategories: "['IAB1', 'IAB5']", - device:{ - ip: '123.145.167.189', - ifa:"AEBE52E7-03EE-455A-B3C4-E57283966239", - }, - app: { - id: "agltb3B1Yi1pbmNyDAsSA0FwcBiJkfIUDA", - name: "Yahoo Weather", - bundle: 'com.kiloo.subwaysurf', - storeurl: 'https://play.google.com/store/apps/details?id=com.kiloo.subwaysurf&hl=en', - domain: 'somoaudience.com', - } - } - }] - } -] -``` diff --git a/modules/ventesBidAdapter.js b/modules/ventesBidAdapter.js deleted file mode 100644 index a9de52a86ba..00000000000 --- a/modules/ventesBidAdapter.js +++ /dev/null @@ -1,410 +0,0 @@ -import { - BANNER, - NATIVE, - VIDEO -} from '../src/mediaTypes.js'; -import { - convertCamelToUnderscore, - isStr, - isArray, - isNumber, - isPlainObject, - replaceAuctionPrice -} from '../src/utils.js'; -import find from 'core-js-pure/features/array/find.js'; -import { - registerBidder -} from '../src/adapters/bidderFactory.js'; - -const BID_METHOD = 'POST'; -const BIDDER_URL = 'http://13.234.201.146:8088/va/ad'; - -const DOMAIN_REGEX = new RegExp('//([^/]*)'); - -function groupBy(values, key) { - const groups = values.reduce((acc, value) => { - const groupId = value[key]; - - if (!acc[groupId]) acc[groupId] = []; - acc[groupId].push(value); - - return acc; - }, {}); - - return Object - .keys(groups) - .map(id => ({ - id, - key, - values: groups[id] - })); -} - -function validateMediaTypes(mediaTypes, allowedMediaTypes) { - if (!isPlainObject(mediaTypes)) return false; - if (!allowedMediaTypes.some(mediaType => mediaType in mediaTypes)) return false; - - if (isBanner(mediaTypes)) { - if (!validateBanner(mediaTypes.banner)) return false; - } - return true; -} - -function isBanner(mediaTypes) { - return isPlainObject(mediaTypes) && isPlainObject(mediaTypes.banner); -} - -function validateBanner(banner) { - return isPlainObject(banner) && - isArray(banner.sizes) && - (banner.sizes.length > 0) && - banner.sizes.every(validateMediaSizes); -} - -function validateMediaSizes(mediaSize) { - return isArray(mediaSize) && - (mediaSize.length === 2) && - mediaSize.every(size => (isNumber(size) && size >= 0)); -} - -function hasUserInfo(bid) { - return !!bid.params.user; -} - -function validateParameters(parameters) { - if (!(parameters.placementId)) { - return false; - } - if (!(parameters.publisherId)) { - return false; - } - - return true; -} - -function extractSiteDomainFromURL(url) { - if (!url || !isStr(url)) return null; - - const domain = url.match(DOMAIN_REGEX); - - if (isArray(domain) && domain.length === 2) return domain[1]; - - return null; -} - -function generateSiteFromAdUnitContext(bidRequests, adUnitContext) { - if (!adUnitContext || !adUnitContext.refererInfo) return null; - - const domain = extractSiteDomainFromURL(adUnitContext.refererInfo.referer); - const publisherId = bidRequests[0].params.publisherId; - - if (!domain) return null; - - return { - page: adUnitContext.refererInfo.referer, - domain: domain, - name: domain, - publisher: { - id: publisherId - } - }; -} - -function validateServerRequest(serverRequest) { - return isPlainObject(serverRequest) && - isPlainObject(serverRequest.data) && - isArray(serverRequest.data.imp) -} - -function createServerRequestFromAdUnits(adUnits, bidRequestId, adUnitContext) { - return { - method: BID_METHOD, - url: BIDDER_URL, - data: generateBidRequestsFromAdUnits(adUnits, bidRequestId, adUnitContext), - options: { - contentType: 'application/json', - withCredentials: false, - } - } -} - -function generateBidRequestsFromAdUnits(bidRequests, bidRequestId, adUnitContext) { - const userObjBid = find(bidRequests, hasUserInfo); - let userObj = {}; - if (userObjBid) { - Object.keys(userObjBid.params.user) - .forEach((param) => { - let uparam = convertCamelToUnderscore(param); - if (param === 'segments' && isArray(userObjBid.params.user[param])) { - let segs = []; - userObjBid.params.user[param].forEach(val => { - if (isNumber(val)) { - segs.push({ - 'id': val - }); - } else if (isPlainObject(val)) { - segs.push(val); - } - }); - userObj[uparam] = segs; - } else if (param !== 'segments') { - userObj[uparam] = userObjBid.params.user[param]; - } - }); - } - - const deviceObjBid = find(bidRequests, hasDeviceInfo); - let deviceObj; - if (deviceObjBid && deviceObjBid.params && deviceObjBid.params.device) { - deviceObj = {}; - Object.keys(deviceObjBid.params.device) - .forEach(param => deviceObj[param] = deviceObjBid.params.device[param]); - if (!deviceObjBid.hasOwnProperty('ua')) { - deviceObj.ua = navigator.userAgent; - } - if (!deviceObjBid.hasOwnProperty('language')) { - deviceObj.language = navigator.language; - } - } else { - deviceObj = {}; - deviceObj.ua = navigator.userAgent; - deviceObj.language = navigator.language; - } - - const payload = {} - payload.id = bidRequestId - payload.at = 1 - payload.cur = ['USD'] - payload.imp = bidRequests.reduce(generateImpressionsFromAdUnit, []) - const appDeviceObjBid = find(bidRequests, hasAppInfo); - if (!appDeviceObjBid) { - payload.site = generateSiteFromAdUnitContext(bidRequests, adUnitContext) - } else { - let appIdObj; - if (appDeviceObjBid && appDeviceObjBid.params && appDeviceObjBid.params.app && appDeviceObjBid.params.app.id) { - appIdObj = {}; - Object.keys(appDeviceObjBid.params.app) - .forEach(param => appIdObj[param] = appDeviceObjBid.params.app[param]); - } - payload.app = appIdObj; - } - payload.device = deviceObj; - payload.user = userObj - return payload -} - -function generateImpressionsFromAdUnit(acc, adUnit) { - const { - bidId, - mediaTypes, - params - } = adUnit; - const { - placementId - } = params; - const pmp = {}; - - if (placementId) pmp.deals = [{ id: placementId }] - - const imps = Object - .keys(mediaTypes) - .reduce((acc, mediaType) => { - const data = mediaTypes[mediaType]; - const impId = `${bidId}`; - - if (mediaType === 'banner') return acc.concat(generateBannerFromAdUnit(impId, data, params)); - }, []); - - return acc.concat(imps); -} - -function generateBannerFromAdUnit(impId, data, params) { - const { - position, - placementId - } = params; - const pos = position || 0; - const pmp = {}; - const ext = { - placementId - }; - - if (placementId) pmp.deals = [{ id: placementId }] - - return data.sizes.map(([w, h]) => ({ - id: `${impId}`, - banner: { - format: [{ - w, - h - }], - w, - h, - pos - }, - pmp, - ext, - tagid: placementId - })); -} - -function validateServerResponse(serverResponse) { - return isPlainObject(serverResponse) && - isPlainObject(serverResponse.body) && - isStr(serverResponse.body.cur) && - isArray(serverResponse.body.seatbid); -} - -function seatBidsToAds(seatBid, bidResponse, serverRequest) { - return seatBid.bid - .filter(bid => validateBids(bid)) - .map(bid => generateAdFromBid(bid, bidResponse)); -} - -function validateBids(bid) { - if (!isPlainObject(bid)) return false; - if (!isStr(bid.impid)) return false; - if (!isStr(bid.crid)) return false; - if (!isNumber(bid.price)) return false; - if (!isNumber(bid.w)) return false; - if (!isNumber(bid.h)) return false; - if (!bid.adm) return false; - if (bid.adm) { - if (!isStr(bid.adm)) return false; - } - return true; -} - -function getMediaType(adm) { - const videoRegex = new RegExp(/VAST\s+version/); - - if (videoRegex.test(adm)) { - return VIDEO; - } - - const markup = safeJSONparse(adm.replace(/\\/g, '')); - - if (markup && isPlainObject(markup.native)) { - return NATIVE; - } - - return BANNER; -} - -function safeJSONparse(...args) { - try { - return JSON.parse(...args); - } catch (_) { - return undefined; - } -} - -function generateAdFromBid(bid, bidResponse) { - const mediaType = getMediaType(bid.adm); - const base = { - requestId: bid.impid, - cpm: bid.price, - currency: bidResponse.cur, - ttl: 10, - creativeId: bid.crid, - mediaType: mediaType, - netRevenue: true - }; - - if (bid.adomain) { - base.meta = { - advertiserDomains: bid.adomain - }; - } - - const size = getSizeFromBid(bid); - const creative = getCreativeFromBid(bid); - - return { - ...base, - height: size.height, - width: size.width, - ad: creative.markup, - adUrl: creative.markupUrl, - renderer: creative.renderer - }; -} - -function getSizeFromBid(bid) { - if (isNumber(bid.w) && isNumber(bid.h)) { - return { - width: bid.w, - height: bid.h - }; - } - return { - width: null, - height: null - }; -} - -function getCreativeFromBid(bid) { - const shouldUseAdMarkup = !!bid.adm; - const price = bid.price; - return { - markup: shouldUseAdMarkup ? replaceAuctionPrice(bid.adm, price) : null, - markupUrl: !shouldUseAdMarkup ? replaceAuctionPrice(bid.nurl, price) : null - }; -} - -function hasDeviceInfo(bid) { - if (bid.params) { - return !!bid.params.device - } -} - -function hasAppInfo(bid) { - if (bid.params) { - return !!bid.params.app - } -} - -const venavenBidderSpec = { - code: 'ventes', - supportedMediaTypes: [BANNER], - isBidRequestValid(adUnit) { - const allowedBidderCodes = [this.code]; - - return isPlainObject(adUnit) && - allowedBidderCodes.indexOf(adUnit.bidder) !== -1 && - isStr(adUnit.adUnitCode) && - isStr(adUnit.bidderRequestId) && - isStr(adUnit.bidId) && - validateMediaTypes(adUnit.mediaTypes, this.supportedMediaTypes) && - validateParameters(adUnit.params); - }, - buildRequests(bidRequests, bidderRequest) { - if (!bidRequests) return null; - - return groupBy(bidRequests, 'bidderRequestId').map(group => { - const bidRequestId = group.id; - const adUnits = groupBy(group.values, 'bidId').map((group) => { - const length = group.values.length; - return length > 0 && group.values[length - 1] - }); - - return createServerRequestFromAdUnits(adUnits, bidRequestId, bidderRequest) - }); - }, - interpretResponse(serverResponse, serverRequest) { - if (!validateServerRequest(serverRequest)) return []; - if (!validateServerResponse(serverResponse)) return []; - - const bidResponse = serverResponse.body; - - return bidResponse.seatbid - .filter(seatBid => isPlainObject(seatBid) && isArray(seatBid.bid)) - .reduce((acc, seatBid) => acc.concat(seatBidsToAds(seatBid, bidResponse, serverRequest)), []); - } -}; - -registerBidder(venavenBidderSpec); - -export { - venavenBidderSpec as spec -}; diff --git a/modules/ventesBidAdapter.md b/modules/ventesBidAdapter.md deleted file mode 100644 index c79ef080cd1..00000000000 --- a/modules/ventesBidAdapter.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -layout: bidder -title: ventes -description: Prebid ventes Bidder Adapter -pbjs: false -biddercode: ventes -gdpr_supported: false -usp_supported: false -media_types: banner -coppa_supported: false -schain_supported: false -dchain_supported: false -prebid_member: false ---- - -### BidParams -{: .table .table-bordered .table-striped } -| Name | Scope | Description | Example | Type | -|-----------------|----------|-----------------------------------------------------------|----------------------------------------------|---------------| -| `placementId` | required | Placement ID from Ventes Avenues | `'VA-062-0013-0183'` | `string` | -| `publisherId` | required | Publisher ID from Ventes Avenues | `'VA-062'` | `string` | -| `user` | optional | Object that specifies information about an external user. | `user: { age: 25, gender: 0, dnt: true}` | `object` | -| `app` | required | Object containing mobile app parameters. | `app : { id: 'app-id'}` | `object` | -| `device` | required | Object containing device info mandatory for mobile devices| `device : { ifa: 'device-id'}` | `object` | - -#### User Object - -{: .table .table-bordered .table-striped } -| Name | Description | Example | Type | -|-------------------|-------------------------------------------------------------------------------------------|-----------------------|-----------------------| -| `age` | The age of the user. | `35` | `integer` | -| `externalUid` | Specifies a string that corresponds to an external user ID for this user. | `'1234567890abcdefg'` | `string` | -| `segments` | Specifies the segments to which the user belongs. | `[1, 2]` | `Array` | -| `gender` | Specifies the gender of the user. Allowed values: Unknown: `0`; Male: `1`; Female: `2` | `1` | `integer` | -| `dnt` | Do not track flag. Indicates if tracking cookies should be disabled for this auction | `true` | `boolean` | -| `language` | Two-letter ANSI code for this user's language. | `EN` | `string` | - - -### Ad Unit Setup for Banner through mobile devices -```javascript -var adUnits = [ -{ - code: 'test-hb-ad-11111-1', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bids: [{ - bidder: 'ventes', - params: { - placementId: 'VA-062-0013-0183', - publisherId: '5cebea3c9eea646c7b623d5e', - IABCategories: "['IAB1', 'IAB5']", - device:{ - ifa:"AEBE52E7-03EE-455A-B3C4-E57283966239", - }, - app: { - id: "agltb3B1Yi1pbmNyDAsSA0FwcBiJkfIUDA", - name: "Yahoo Weather", - bundle: 'com.kiloo.subwaysurf', - storeurl: 'https://play.google.com/store/apps/details?id=com.kiloo.subwaysurf&hl=en', - domain: 'somoaudience.com', - } - } - }] - } -] -``` - -### Ad Unit Setup for Banner through Websites -```javascript -var adUnits = [ -{ - code: 'test-hb-ad-11111-1', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bids: [{ - bidder: 'ventes', - params: { - placementId: 'VA-002-0007-0799', - publisherId: '5cebea3c9eea646c7b623d5e', - } - }] - } -] diff --git a/modules/verizonMediaIdSystem.js b/modules/verizonMediaIdSystem.js index 280a6c47894..ca395087d2d 100644 --- a/modules/verizonMediaIdSystem.js +++ b/modules/verizonMediaIdSystem.js @@ -7,7 +7,7 @@ import {ajax} from '../src/ajax.js'; import {submodule} from '../src/hook.js'; -import { logError, formatQS } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const MODULE_NAME = 'verizonMediaId'; @@ -51,7 +51,7 @@ export const verizonMediaIdSubmodule = { const params = config.params || {}; if (!params || typeof params.he !== 'string' || (typeof params.pixelId === 'undefined' && typeof params.endpoint === 'undefined')) { - logError('The verizonMediaId submodule requires the \'he\' and \'pixelId\' parameters to be defined.'); + utils.logError('The verizonMediaId submodule requires the \'he\' and \'pixelId\' parameters to be defined.'); return; } @@ -75,18 +75,18 @@ export const verizonMediaIdSubmodule = { try { responseObj = JSON.parse(response); } catch (error) { - logError(error); + utils.logError(error); } } callback(responseObj); }, error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + utils.logError(`${MODULE_NAME}: ID fetch encountered an error`, error); callback(); } }; const endpoint = VMCID_ENDPOINT.replace(PLACEHOLDER, params.pixelId); - let url = `${params.endpoint || endpoint}?${formatQS(data)}`; + let url = `${params.endpoint || endpoint}?${utils.formatQS(data)}`; verizonMediaIdSubmodule.getAjaxFn()(url, callbacks, null, {method: 'GET', withCredentials: true}); }; return {callback: resp}; diff --git a/modules/vidazooBidAdapter.js b/modules/vidazooBidAdapter.js index 0e7b4ee63b2..3fb94870d3f 100644 --- a/modules/vidazooBidAdapter.js +++ b/modules/vidazooBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, deepAccess, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -94,7 +94,7 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { data: data }; - _each(ext, (value, key) => { + utils._each(ext, (value, key) => { dto.data['ext.' + key] = value; }); @@ -103,13 +103,13 @@ function buildRequest(bid, topWindowUrl, sizes, bidderRequest) { function appendUserIdsToRequestPayload(payloadRef, userIds) { let key; - _each(userIds, (userId, idSystemProviderName) => { + utils._each(userIds, (userId, idSystemProviderName) => { if (SUPPORTED_ID_SYSTEMS[idSystemProviderName]) { key = `uid.${idSystemProviderName}`; switch (idSystemProviderName) { case 'digitrustid': - payloadRef[key] = deepAccess(userId, 'data.id'); + payloadRef[key] = utils.deepAccess(userId, 'data.id'); break; case 'lipb': payloadRef[key] = userId.lipbid; @@ -131,7 +131,7 @@ function buildRequests(validBidRequests, bidderRequest) { const topWindowUrl = bidderRequest.refererInfo.referer; const requests = []; validBidRequests.forEach(validBidRequest => { - const sizes = parseSizesInput(validBidRequest.sizes); + const sizes = utils.parseSizesInput(validBidRequest.sizes); const request = buildRequest(validBidRequest, topWindowUrl, sizes, bidderRequest); requests.push(request); }); diff --git a/modules/videobyteBidAdapter.js b/modules/videobyteBidAdapter.js index 6e99b5bc42a..076329d1c8b 100644 --- a/modules/videobyteBidAdapter.js +++ b/modules/videobyteBidAdapter.js @@ -1,5 +1,5 @@ -import { logMessage, logError, deepAccess, isFn, isPlainObject, isStr, isNumber, isArray, deepSetValue } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {VIDEO} from '../src/mediaTypes.js'; const BIDDER_CODE = 'videobyte'; @@ -27,7 +27,7 @@ export const spec = { code: BIDDER_CODE, supportedMediaTypes: [VIDEO], VERSION: '1.0.0', - ENDPOINT: 'https://x.videobyte.com/ortbhb', + ENDPOINT: 'https://x.videobyte.com/ortb/', /** * Determines whether or not the given bid request is valid. @@ -53,22 +53,13 @@ export const spec = { return bidRequests.map(bidRequest => { const {params} = bidRequest; let pubId = params.pubId; - const placementId = params.placementId; - const nId = params.nid; if (bidRequest.params.video && bidRequest.params.video.e2etest) { - logMessage('E2E test mode enabled'); + utils.logMessage('E2E test mode enabled'); pubId = 'e2etest' } - let baseEndpoint = spec.ENDPOINT + '?pid=' + pubId; - if (placementId) { - baseEndpoint += '&placementId=' + placementId - } - if (nId) { - baseEndpoint += '&nid=' + nId - } return { method: 'POST', - url: baseEndpoint, + url: spec.ENDPOINT + pubId, data: JSON.stringify(buildRequestData(bidRequest, bidderRequest)), } }); @@ -106,6 +97,8 @@ export const spec = { }; bidResponses.push(bidResponse) } + } else { + utils.logError('invalid server response received'); } return bidResponses; }, @@ -125,7 +118,7 @@ export const spec = { } serverResponses.forEach(resp => { - const userSync = deepAccess(resp, 'body.ext.usersync'); + const userSync = utils.deepAccess(resp, 'body.ext.usersync'); if (userSync) { let syncDetails = []; Object.keys(userSync).forEach(key => { @@ -159,8 +152,8 @@ export const spec = { function buildRequestData(bidRequest, bidderRequest) { const {params} = bidRequest; - const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {}); - const videoBidderParams = deepAccess(bidRequest, 'params.video', {}); + const videoAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); + const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {}); const videoParams = { ...videoAdUnit, @@ -201,7 +194,7 @@ function buildRequestData(bidRequest, bidderRequest) { size: '*' }; let floorData = bidRequest.params - if (isFn(bidRequest.getFloor)) { + if (utils.isFn(bidRequest.getFloor)) { floorData = bidRequest.getFloor(bidFloorRequest); } else { if (params.bidfloor) { @@ -233,41 +226,41 @@ function buildRequestData(bidRequest, bidderRequest) { }; // content - if (videoParams.content && isPlainObject(videoParams.content)) { + if (videoParams.content && utils.isPlainObject(videoParams.content)) { openrtbRequest.site.content = {}; - const contentStringKeys = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language', 'url']; + const contentStringKeys = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language']; const contentNumberkeys = ['episode', 'prodq', 'context', 'livestream', 'len']; const contentArrayKeys = ['cat']; const contentObjectKeys = ['ext']; for (const contentKey in videoBidderParams.content) { if ( - (contentStringKeys.indexOf(contentKey) > -1 && isStr(videoParams.content[contentKey])) || - (contentNumberkeys.indexOf(contentKey) > -1 && isNumber(videoParams.content[contentKey])) || - (contentObjectKeys.indexOf(contentKey) > -1 && isPlainObject(videoParams.content[contentKey])) || - (contentArrayKeys.indexOf(contentKey) > -1 && isArray(videoParams.content[contentKey]) && - videoParams.content[contentKey].every(catStr => isStr(catStr)))) { + (contentStringKeys.indexOf(contentKey) > -1 && utils.isStr(videoParams.content[contentKey])) || + (contentNumberkeys.indexOf(contentKey) > -1 && utils.isNumber(videoParams.content[contentKey])) || + (contentObjectKeys.indexOf(contentKey) > -1 && utils.isPlainObject(videoParams.content[contentKey])) || + (contentArrayKeys.indexOf(contentKey) > -1 && utils.isArray(videoParams.content[contentKey]) && + videoParams.content[contentKey].every(catStr => utils.isStr(catStr)))) { openrtbRequest.site.content[contentKey] = videoParams.content[contentKey]; } else { - logMessage('videobyte bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined'); + utils.logMessage('videobyte bid adapter validation error: ', contentKey, ' is either not supported is OpenRTB V2.5 or value is undefined'); } } } // adding schain object if (bidRequest.schain) { - deepSetValue(openrtbRequest, 'source.ext.schain', bidRequest.schain); + utils.deepSetValue(openrtbRequest, 'source.ext.schain', bidRequest.schain); openrtbRequest.source.ext.schain.nodes[0].rid = openrtbRequest.id; } // Attaching GDPR Consent Params if (bidderRequest.gdprConsent) { - deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest.uspConsent) { - deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); } return openrtbRequest; } @@ -278,12 +271,12 @@ function validateVideo(bidRequest) { } if (!bidRequest.params.pubId) { - logError('failed validation: pubId not declared'); + utils.logError('failed validation: publisher id not declared'); return false; } - const videoAdUnit = deepAccess(bidRequest, 'mediaTypes.video', {}); - const videoBidderParams = deepAccess(bidRequest, 'params.video', {}); + const videoAdUnit = utils.deepAccess(bidRequest, 'mediaTypes.video', {}); + const videoBidderParams = utils.deepAccess(bidRequest, 'params.video', {}); if (videoBidderParams && videoBidderParams.e2etest) { return true; @@ -295,16 +288,16 @@ function validateVideo(bidRequest) { }; if (!videoParams.context) { - logError('failed validation: context id not declared'); + utils.logError('failed validation: context id not declared'); return false; } if (videoParams.context !== 'instream') { - logError('failed validation: only context instream is supported '); + utils.logError('failed validation: only context instream is supported '); return false; } if (typeof videoParams.playerSize === 'undefined' || !Array.isArray(videoParams.playerSize) || !Array.isArray(videoParams.playerSize[0])) { - logError('failed validation: player size not declared or is not in format [[w,h]]'); + utils.logError('failed validation: player size not declared or is not in format [[w,h]]'); return false; } diff --git a/modules/videobyteBidAdapter.md b/modules/videobyteBidAdapter.md index d0037b0972a..fc2b0bce4b5 100644 --- a/modules/videobyteBidAdapter.md +++ b/modules/videobyteBidAdapter.md @@ -49,55 +49,6 @@ Module that connects to VideoByte's demand sources ] ``` -## Instream Video adUnit with placement, nid and content params -``` - var adUnits = [ - { - code: 'video1', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4', 'application/javascript'], - protocols: [2,5], - api: [2], - position: 1, - delivery: [2], - minduration: 10, - maxduration: 30, - placement: 1, - playbackmethod: [1,5], - protocols: [2,5], - api: [2], - } - }, - bids: [ - { - bidder: 'videobyte', - params: { - bidfloor: 0.5, - pubId: 'e2etest', - placementId: '1234567', - nid: '1234', - video: { - content:{ - id: "uuid", - url: "https://videobyte.com/awesome-video.mp4", - title: "Awesome video", - genre: "Comedy", - language: "en", - season: "1", - series: "1", - - } - } - } - } - ] - } - ] -``` - # End To End testing mode By passing bid.params.video.e2etest = true you will be able to receive a test creative diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js index 61ecd55a2ef..c307fc3e865 100644 --- a/modules/videoreachBidAdapter.js +++ b/modules/videoreachBidAdapter.js @@ -1,5 +1,5 @@ -import { getValue, getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +const utils = require('../src/utils.js'); const BIDDER_CODE = 'videoreach'; const ENDPOINT_URL = 'https://a.videoreach.com/hb/'; const GVLID = 547; @@ -17,12 +17,12 @@ export const spec = { let data = { data: validBidRequests.map(function(bid) { return { - TagId: getValue(bid.params, 'TagId'), - adUnitCode: getBidIdParameter('adUnitCode', bid), - bidId: getBidIdParameter('bidId', bid), - bidderRequestId: getBidIdParameter('bidderRequestId', bid), - auctionId: getBidIdParameter('auctionId', bid), - transactionId: getBidIdParameter('transactionId', bid) + TagId: utils.getValue(bid.params, 'TagId'), + adUnitCode: utils.getBidIdParameter('adUnitCode', bid), + bidId: utils.getBidIdParameter('bidId', bid), + bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), + auctionId: utils.getBidIdParameter('auctionId', bid), + transactionId: utils.getBidIdParameter('transactionId', bid) } }) }; diff --git a/modules/vidoomyBidAdapter.js b/modules/vidoomyBidAdapter.js index 64145b2c6b4..b579de8618b 100644 --- a/modules/vidoomyBidAdapter.js +++ b/modules/vidoomyBidAdapter.js @@ -1,44 +1,31 @@ -import { logError, deepAccess, parseSizesInput } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import * as utils from '../src/utils.js'; import { Renderer } from '../src/Renderer.js'; import { INSTREAM, OUTSTREAM } from '../src/video.js'; const ENDPOINT = `https://d.vidoomy.com/api/rtbserver/prebid/`; const BIDDER_CODE = 'vidoomy'; const GVLID = 380; - -const COOKIE_SYNC_FALLBACK_URLS = [ - 'https://x.bidswitch.net/sync?ssp=vidoomy', - 'https://ib.adnxs.com/getuid?https%3A%2F%2Fa-prebid.vidoomy.com%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D{{GDPR}}%26gdpr_consent%3D{{GDPR_CONSENT}}%26uid%3D%24UID', - 'https://pixel-sync.sitescout.com/dmp/pixelSync?nid=120&redir=https%3A%2F%2Fa.vidoomy.com%2Fapi%2Frtbserver%2Fcookie%3Fi%3DCEN%26uid%3D%7BuserId%7D', - 'https://sync.1rx.io/usersync2/vidoomy?redir=https%3A%2F%2Fa.vidoomy.com%2Fapi%2Frtbserver%2Fcookie%3Fi%3DUN%26uid%3D%5BRX_UUID%5D', - 'https://rtb.openx.net/sync/prebid?gdpr={{GDPR}}&gdpr_consent={{GDPR_CONSENT}}&r=https%3A%2F%2Fa-prebid.vidoomy.com%2Fsetuid%3Fbidder%3Dopenx%26uid%3D$%7BUID%7D', - 'https://ads.pubmatic.com/AdServer/js/user_sync.html?gdpr={{GDPR}}&gdpr_consent={{GDPR_CONSENT}}&us_privacy=&predirect=https%3A%2F%2Fa-prebid.vidoomy.com%2Fsetuid%3Fbidder%3Dpubmatic%26gdpr%3D{{GDPR}}%26gdpr_consent%3D{{GDPR_CONSENT}}%26uid%3D', - 'https://cm.adform.net/cookie?redirect_url=https%3A%2F%2Fa-prebid.vidoomy.com%2Fsetuid%3Fbidder%3Dadf%26gdpr%3D{{GDPR}}%26gdpr_consent%3D{{GDPR_CONSENT}}%26uid%3D%24UID', - 'https://ups.analytics.yahoo.com/ups/58531/occ?gdpr={{GDPR}}&gdpr_consent={{GDPR_CONSENT}}', - 'https://ap.lijit.com/pixel?redir=https%3A%2F%2Fa-prebid.vidoomy.com%2Fsetuid%3Fbidder%3Dsovrn%26gdpr%3D{{GDPR}}%26gdpr_consent%3D{{GDPR_CONSENT}}%26uid%3D%24UID' -]; - const isBidRequestValid = bid => { if (!bid.params) { - logError(BIDDER_CODE + ': bid.params should be non-empty'); + utils.logError(BIDDER_CODE + ': bid.params should be non-empty'); return false; } if (!+bid.params.pid) { - logError(BIDDER_CODE + ': bid.params.pid should be non-empty Number'); + utils.logError(BIDDER_CODE + ': bid.params.pid should be non-empty Number'); return false; } if (!+bid.params.id) { - logError(BIDDER_CODE + ': bid.params.id should be non-empty Number'); + utils.logError(BIDDER_CODE + ': bid.params.id should be non-empty Number'); return false; } if (bid.params && bid.params.mediaTypes && bid.params.mediaTypes.video && bid.params.mediaTypes.video.context === INSTREAM && !bid.params.mediaTypes.video.playerSize) { - logError(BIDDER_CODE + ': bid.params.mediaType.video should have a playerSize property to tell player size when is INSTREAM'); + utils.logError(BIDDER_CODE + ': bid.params.mediaType.video should have a playerSize property to tell player size when is INSTREAM'); return false; } @@ -46,14 +33,14 @@ const isBidRequestValid = bid => { }; const isBidResponseValid = bid => { - if (!bid || !bid.requestId || !bid.cpm || !bid.ttl || !bid.currency) { + if (!bid.requestId || !bid.cpm || !bid.ttl || !bid.currency) { return false; } switch (bid.mediaType) { case BANNER: return Boolean(bid.width && bid.height && bid.ad); case VIDEO: - return Boolean(bid.vastUrl || bid.vastXml); + return Boolean(bid.vastUrl); default: return false; } @@ -62,50 +49,56 @@ const isBidResponseValid = bid => { const buildRequests = (validBidRequests, bidderRequest) => { const serverRequests = validBidRequests.map(bid => { let adType = BANNER; - let sizes; + let w, h; if (bid.mediaTypes && bid.mediaTypes[BANNER] && bid.mediaTypes[BANNER].sizes) { - sizes = bid.mediaTypes[BANNER].sizes; + [w, h] = bid.mediaTypes[BANNER].sizes[0]; adType = BANNER; } else if (bid.mediaTypes && bid.mediaTypes[VIDEO] && bid.mediaTypes[VIDEO].playerSize) { - sizes = bid.mediaTypes[VIDEO].playerSize; + [w, h] = bid.mediaTypes[VIDEO].playerSize; adType = VIDEO; } - const [w, h] = (parseSizesInput(sizes)[0] || '0x0').split('x'); - - const aElement = document.createElement('a'); - aElement.href = (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) || top.location.href; - const hostname = aElement.hostname - - const videoContext = deepAccess(bid, 'mediaTypes.video.context'); - - const queryParams = { - id: bid.params.id, - adtype: adType, - auc: bid.adUnitCode, - w, - h, - pos: parseInt(bid.params.position) || 1, - ua: navigator.userAgent, - l: navigator.language && navigator.language.indexOf('-') !== -1 ? navigator.language.split('-')[0] : '', - dt: /Mobi/.test(navigator.userAgent) ? 2 : 1, - pid: bid.params.pid, - requestId: bid.bidId, - d: getDomainWithoutSubdomain(hostname), // 'vidoomy.com', - sp: encodeURIComponent(aElement.href), - usp: bidderRequest.uspConsent || '', - coppa: !!config.getConfig('coppa'), - videoContext: videoContext || '' - }; + let host = ''; + try { + host = bidderRequest.refererInfo.referer.split('#')[0].replace(/^(https\:\/\/|http\:\/\/)|(\/)$/g, '').split('/')[0]; + } catch (eBidRequest) { + try { + host = window.location.href.replace(/^(https\:\/\/|http\:\/\/)|(\/)$/g, '').split('/')[0]; + } catch (eLocationHref) { + host = window.location.href; + } + } + const hostname = host.split(':')[0]; + + const videoContext = utils.deepAccess(bid, 'mediaTypes.video.context'); + + const queryParams = []; + queryParams.push(['id', bid.params.id]); + queryParams.push(['adtype', adType]); + queryParams.push(['w', w]); + queryParams.push(['h', h]); + queryParams.push(['pos', parseInt(bid.params.position) || 1]); + queryParams.push(['ua', navigator.userAgent]); + queryParams.push(['l', navigator.language && navigator.language.indexOf('-') !== -1 ? navigator.language.split('-')[0] : '']); + queryParams.push(['dt', /Mobi/.test(navigator.userAgent) ? 2 : 1]); + queryParams.push(['pid', bid.params.pid]); + queryParams.push(['requestId', bid.bidId]); + queryParams.push(['d', hostname]); + queryParams.push(['sp', encodeURIComponent(bidderRequest.refererInfo.referer)]); if (bidderRequest.gdprConsent) { - queryParams.gdpr = bidderRequest.gdprConsent.gdprApplies; - queryParams.gdprcs = bidderRequest.gdprConsent.consentString; + queryParams.push(['gdpr', bidderRequest.gdprConsent.gdprApplies]); + queryParams.push(['gdprcs', bidderRequest.gdprConsent.consentString]); } + queryParams.push(['usp', bidderRequest.uspConsent || '']); + queryParams.push(['coppa', !!config.getConfig('coppa')]); + + const rawQueryParams = queryParams.map(qp => qp.join('=')).join('&'); + const url = `${ENDPOINT}?${rawQueryParams}`; return { method: 'GET', - url: ENDPOINT, - data: queryParams + url: url, + data: {videoContext} } }); return serverRequests; @@ -127,9 +120,8 @@ const render = (bid) => { const interpretResponse = (serverResponse, bidRequest) => { try { let responseBody = serverResponse.body; - if (!responseBody) return; if (responseBody.mediaType === 'video') { - responseBody.ad = responseBody.vastUrl || responseBody.vastXml; + responseBody.ad = responseBody.vastUrl; const videoContext = bidRequest.data.videoContext; if (videoContext === OUTSTREAM) { @@ -145,12 +137,13 @@ const interpretResponse = (serverResponse, bidRequest) => { responseBody.renderer = renderer; } catch (e) { - responseBody.ad = responseBody.vastUrl || responseBody.vastXml; - logError(BIDDER_CODE + ': error while installing renderer to show outstream ad'); + responseBody.ad = responseBody.vastUrl; + utils.logError(BIDDER_CODE + ': error while installing renderer to show outstream ad'); } } } const bid = { + vastUrl: responseBody.vastUrl, ad: responseBody.ad, renderer: responseBody.renderer, mediaType: responseBody.mediaType, @@ -179,42 +172,22 @@ const interpretResponse = (serverResponse, bidRequest) => { secondaryCatIds: responseBody.meta.secondaryCatIds } }; - if (responseBody.vastUrl) { - bid.vastUrl = responseBody.vastUrl; - } else if (responseBody.vastXml) { - bid.vastXml = responseBody.vastXml; - } const bids = []; if (isBidResponseValid(bid)) { bids.push(bid); } else { - logError(BIDDER_CODE + ': server returns invalid response'); + utils.logError(BIDDER_CODE + ': server returns invalid response'); } return bids; } catch (e) { - logError(BIDDER_CODE + ': error parsing server response to Prebid format'); + utils.logError(BIDDER_CODE + ': error parsing server response to Prebid format'); return []; } }; -function getUserSyncs (syncOptions, responses, gdprConsent, uspConsent) { - if (syncOptions.iframeEnabled || syncOptions.pixelEnabled) { - const pixelType = syncOptions.pixelEnabled ? 'image' : 'iframe'; - const urls = deepAccess(responses, '0.body.pixels') || COOKIE_SYNC_FALLBACK_URLS; - - return [].concat(urls).map(url => ({ - type: pixelType, - url: url - .replace('{{GDPR}}', gdprConsent ? (gdprConsent.gdprApplies ? '1' : '0') : '0') - .replace('{{GDPR_CONSENT}}', gdprConsent ? encodeURIComponent(gdprConsent.consentString) : '') - .replace('{{USP_CONSENT}}', uspConsent ? encodeURIComponent(uspConsent) : '') - })); - } -}; - export const spec = { code: BIDDER_CODE, supportedMediaTypes: [BANNER, VIDEO], @@ -222,19 +195,6 @@ export const spec = { buildRequests, interpretResponse, gvlid: GVLID, - getUserSyncs, }; registerBidder(spec); - -function getDomainWithoutSubdomain (hostname) { - const parts = hostname.split('.'); - const newParts = []; - for (let i = parts.length - 1; i >= 0; i--) { - newParts.push(parts[i]); - if (newParts.length !== 1 && parts[i].length > 3) { - break; - } - } - return newParts.reverse().join('.'); -} diff --git a/modules/viewdeosDXBidAdapter.js b/modules/viewdeosDXBidAdapter.js index e3d02938c5b..212759642f5 100644 --- a/modules/viewdeosDXBidAdapter.js +++ b/modules/viewdeosDXBidAdapter.js @@ -1,4 +1,4 @@ -import { deepAccess, isArray, flatten, logError, parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {VIDEO, BANNER} from '../src/mediaTypes.js'; import {Renderer} from '../src/Renderer.js'; @@ -16,7 +16,7 @@ export const spec = { gvlid: 924, supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { - return !!deepAccess(bid, 'params.aid'); + return !!utils.deepAccess(bid, 'params.aid'); }, getUserSyncs: function (syncOptions, serverResponses) { const syncs = []; @@ -43,9 +43,9 @@ export const spec = { } if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) { - isArray(serverResponses) && serverResponses.forEach((response) => { + utils.isArray(serverResponses) && serverResponses.forEach((response) => { if (response.body) { - if (isArray(response.body)) { + if (utils.isArray(response.body)) { response.body.forEach(b => { addSyncs(b); }) @@ -81,12 +81,12 @@ export const spec = { serverResponse = serverResponse.body; let bids = []; - if (!isArray(serverResponse)) { + if (!utils.isArray(serverResponse)) { return parseRTBResponse(serverResponse, bidderRequest); } serverResponse.forEach(serverBidResponse => { - bids = flatten(bids, parseRTBResponse(serverBidResponse, bidderRequest)); + bids = utils.flatten(bids, parseRTBResponse(serverBidResponse, bidderRequest)); }); return bids; @@ -94,7 +94,7 @@ export const spec = { }; function parseRTBResponse(serverResponse, bidderRequest) { - const isInvalidValidResp = !serverResponse || !isArray(serverResponse.bids); + const isInvalidValidResp = !serverResponse || !utils.isArray(serverResponse.bids); const bids = []; @@ -102,7 +102,7 @@ function parseRTBResponse(serverResponse, bidderRequest) { const extMessage = serverResponse && serverResponse.ext && serverResponse.ext.message ? `: ${serverResponse.ext.message}` : ''; const errorMessage = `in response for ${bidderRequest.bidderCode} adapter ${extMessage}`; - logError(errorMessage); + utils.logError(errorMessage); return bids; } @@ -125,15 +125,15 @@ function parseRTBResponse(serverResponse, bidderRequest) { function bidToTag(bidRequests, bidderRequest) { const tag = { - domain: deepAccess(bidderRequest, 'refererInfo.referer') + domain: utils.deepAccess(bidderRequest, 'refererInfo.referer') }; - if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) { + if (utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) { tag.gdpr = 1; - tag.gdpr_consent = deepAccess(bidderRequest, 'gdprConsent.consentString'); + tag.gdpr_consent = utils.deepAccess(bidderRequest, 'gdprConsent.consentString'); } - if (deepAccess(bidderRequest, 'bidderRequest.uspConsent')) { + if (utils.deepAccess(bidderRequest, 'bidderRequest.uspConsent')) { tag.us_privacy = bidderRequest.uspConsent; } @@ -151,14 +151,14 @@ function bidToTag(bidRequests, bidderRequest) { * @returns {object} */ function prepareRTBRequestParams(_index, bid) { - const mediaType = deepAccess(bid, 'mediaTypes.video') ? VIDEO : DISPLAY; + const mediaType = utils.deepAccess(bid, 'mediaTypes.video') ? VIDEO : DISPLAY; const index = !_index ? '' : `${_index + 1}`; - const sizes = bid.sizes ? bid.sizes : (mediaType === VIDEO ? deepAccess(bid, 'mediaTypes.video.playerSize') : deepAccess(bid, 'mediaTypes.banner.sizes')); + const sizes = bid.sizes ? bid.sizes : (mediaType === VIDEO ? utils.deepAccess(bid, 'mediaTypes.video.playerSize') : utils.deepAccess(bid, 'mediaTypes.banner.sizes')); return { ['callbackId' + index]: bid.bidId, ['aid' + index]: bid.params.aid, ['ad_type' + index]: mediaType, - ['sizes' + index]: parseSizesInput(sizes).join() + ['sizes' + index]: utils.parseSizesInput(sizes).join() }; } @@ -168,8 +168,8 @@ function prepareRTBRequestParams(_index, bid) { * @returns {object} */ function getMediaType(bidderRequest) { - const videoMediaType = deepAccess(bidderRequest, 'mediaTypes.video'); - const context = deepAccess(bidderRequest, 'mediaTypes.video.context'); + const videoMediaType = utils.deepAccess(bidderRequest, 'mediaTypes.video'); + const context = utils.deepAccess(bidderRequest, 'mediaTypes.video.context'); return !videoMediaType ? DISPLAY : context === OUTSTREAM ? OUTSTREAM : VIDEO; } diff --git a/modules/visxBidAdapter.js b/modules/visxBidAdapter.js index af8672ea233..535beb8af3c 100644 --- a/modules/visxBidAdapter.js +++ b/modules/visxBidAdapter.js @@ -1,22 +1,21 @@ -import { triggerPixel, parseSizesInput, deepAccess, logError, getGptSlotInfoForAdUnitCode } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { INSTREAM as VIDEO_INSTREAM } from '../src/video.js'; +const { parseSizesInput, getKeys, logError, deepAccess } = utils; const BIDDER_CODE = 'visx'; const GVLID = 154; const BASE_URL = 'https://t.visx.net'; -const DEBUG_URL = 'https://t-stage.visx.net'; -const ENDPOINT_PATH = '/hb_post'; +const ENDPOINT_URL = BASE_URL + '/hb'; const TIME_TO_LIVE = 360; const DEFAULT_CUR = 'EUR'; -const ADAPTER_SYNC_PATH = '/push_sync'; -const TRACK_TIMEOUT_PATH = '/track/bid_timeout'; +const ADAPTER_SYNC_URL = BASE_URL + '/push_sync'; +const TRACK_TIMEOUT_URL = BASE_URL + '/track/bid_timeout'; const LOG_ERROR_MESS = { noAuid: 'Bid from response has no auid parameter - ', noAdm: 'Bid from response has no adm parameter - ', noBid: 'Array of bid objects is empty', - noImpId: 'Bid from response has no impid parameter - ', noPlacementCode: 'Can\'t find in requested bids the bid with auid - ', emptyUids: 'Uids should not be empty', emptySeatbid: 'Seatbid array from response has an empty item', @@ -29,6 +28,7 @@ const LOG_ERROR_MESS = { videoMissing: 'Bid request videoType property is missing - ' }; const currencyWhiteList = ['EUR', 'USD', 'GBP', 'PLN']; +const RE_EMPTY_OR_ONLY_COMMAS = /^,*$/; export const spec = { code: BIDDER_CODE, gvlid: GVLID, @@ -47,53 +47,89 @@ export const spec = { buildRequests: function(validBidRequests, bidderRequest) { const auids = []; const bidsMap = {}; + const slotsMapByUid = {}; + const sizeMap = {}; const bids = validBidRequests || []; const currency = config.getConfig(`currency.bidderCurrencyDefault.${BIDDER_CODE}`) || config.getConfig('currency.adServerCurrency') || DEFAULT_CUR; - let reqId; let payloadSchain; let payloadUserId; - let payloadUserEids; - let timeout; + const videoTypes = _initVideoTypes(bids); if (currencyWhiteList.indexOf(currency) === -1) { logError(LOG_ERROR_MESS.notAllowedCurrency + currency); return; } - const imp = []; - bids.forEach(bid => { reqId = bid.bidderRequestId; - - const impObj = buildImpObject(bid); - if (impObj) { - imp.push(impObj); - bidsMap[bid.bidId] = bid; - } - - const { params: { uid }, schain, userId, userIdAsEids } = bid; - + const {params: {uid}, adUnitCode, schain, userId} = bid; + auids.push(uid); if (!payloadSchain && schain) { payloadSchain = schain; } - if (!payloadUserEids && userIdAsEids) { - payloadUserEids = userIdAsEids; - } - if (!payloadUserId && userId) { payloadUserId = userId; } - auids.push(uid); + const sizesId = parseSizesInput(bid.sizes); + + if (!slotsMapByUid[uid]) { + slotsMapByUid[uid] = {}; + } + const slotsMap = slotsMapByUid[uid]; + if (!slotsMap[adUnitCode]) { + slotsMap[adUnitCode] = {adUnitCode, bids: [bid], parents: []}; + } else { + slotsMap[adUnitCode].bids.push(bid); + } + const slot = slotsMap[adUnitCode]; + + sizesId.forEach((sizeId) => { + sizeMap[sizeId] = true; + if (!bidsMap[uid]) { + bidsMap[uid] = {}; + } + + if (!bidsMap[uid][sizeId]) { + bidsMap[uid][sizeId] = [slot]; + } else { + bidsMap[uid][sizeId].push(slot); + } + slot.parents.push({parent: bidsMap[uid], key: sizeId, uid}); + }); }); - const payload = {}; + const payload = { + pt: 'net', + auids: auids.join(','), + sizes: getKeys(sizeMap).join(','), + r: reqId, + cur: currency, + wrapperType: 'Prebid_js', + wrapperVersion: '$prebid.version$', + ...videoTypes + }; + + if (payloadSchain) { + payload.schain = JSON.stringify(payloadSchain); + } + + if (payloadUserId) { + if (payloadUserId.tdid) { + payload.tdid = payloadUserId.tdid; + } + if (payloadUserId.id5id && payloadUserId.id5id.uid) { + payload.id5 = payloadUserId.id5id.uid; + } + if (payloadUserId.digitrustid && payloadUserId.digitrustid.data && payloadUserId.digitrustid.data.id) { + payload.dtid = payloadUserId.digitrustid.data.id; + } + } if (bidderRequest) { - timeout = bidderRequest.timeout; if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) { payload.u = bidderRequest.refererInfo.referer; } @@ -107,50 +143,19 @@ export const spec = { } } - const bidderTimeout = Number(config.getConfig('bidderTimeout')) || timeout; - const tmax = timeout ? Math.min(bidderTimeout, timeout) : bidderTimeout; - const source = { - ext: { - wrapperType: 'Prebid_js', - wrapperVersion: '$prebid.version$', - ...(payloadSchain && { schain: payloadSchain }) - } - }; - const user = { - ext: { - ...(payloadUserEids && { eids: payloadUserEids }), - ...(payload.gdpr_consent && { consent: payload.gdpr_consent }) - } - }; - const regs = ('gdpr_applies' in payload) && { - ext: { - gdpr: payload.gdpr_applies - } - }; - - const request = { - id: reqId, - imp, - tmax, - cur: [currency], - source, - site: { page: payload.u }, - ...(Object.keys(user.ext).length && { user }), - ...(regs && { regs }) - }; - return { - method: 'POST', - url: buildUrl(ENDPOINT_PATH) + '?auids=' + encodeURIComponent(auids.join(',')), - data: request, - bidsMap + method: 'GET', + url: ENDPOINT_URL, + data: payload, + bidsMap: bidsMap, }; }, interpretResponse: function(serverResponse, bidRequest) { serverResponse = serverResponse && serverResponse.body; const bidResponses = []; + const bidsWithoutSizeMatching = []; const bidsMap = bidRequest.bidsMap; - const currency = bidRequest.data.cur[0]; + const currency = bidRequest.data.cur; let errorMessage; @@ -161,107 +166,50 @@ export const spec = { if (!errorMessage && serverResponse.seatbid) { serverResponse.seatbid.forEach(respItem => { - _addBidResponse(_getBidFromResponse(respItem), bidsMap, currency, bidResponses); + _addBidResponse(_getBidFromResponse(respItem), bidsMap, currency, bidResponses, bidsWithoutSizeMatching); + }); + bidsWithoutSizeMatching.forEach(serverBid => { + _addBidResponse(serverBid, bidsMap, currency, bidResponses); }); } if (errorMessage) logError(errorMessage); return bidResponses; }, getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { - var query = []; - if (gdprConsent) { - if (gdprConsent.consentString) { - query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString)); + if (syncOptions.pixelEnabled) { + var query = []; + if (gdprConsent) { + if (gdprConsent.consentString) { + query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString)); + } + query.push('gdpr_applies=' + encodeURIComponent( + (typeof gdprConsent.gdprApplies === 'boolean') + ? Number(gdprConsent.gdprApplies) : 1)); } - query.push('gdpr_applies=' + encodeURIComponent( - (typeof gdprConsent.gdprApplies === 'boolean') - ? Number(gdprConsent.gdprApplies) : 1)); - } - if (syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: buildUrl(ADAPTER_SYNC_PATH) + '?iframe=1' + (query.length ? '&' + query.join('&') : '') - }]; - } else if (syncOptions.pixelEnabled) { return [{ type: 'image', - url: buildUrl(ADAPTER_SYNC_PATH) + (query.length ? '?' + query.join('&') : '') + url: ADAPTER_SYNC_URL + (query.length ? '?' + query.join('&') : '') }]; } }, onSetTargeting: function(bid) { // Call '/track/pending' with the corresponding bid.requestId if (bid.ext && bid.ext.events && bid.ext.events.pending) { - triggerPixel(bid.ext.events.pending); + utils.triggerPixel(bid.ext.events.pending); } }, onBidWon: function(bid) { // Call '/track/win' with the corresponding bid.requestId if (bid.ext && bid.ext.events && bid.ext.events.win) { - triggerPixel(bid.ext.events.win); + utils.triggerPixel(bid.ext.events.win); } }, onTimeout: function(timeoutData) { // Call '/track/bid_timeout' with timeout data - triggerPixel(buildUrl(TRACK_TIMEOUT_PATH) + '//' + JSON.stringify(timeoutData)); + utils.triggerPixel(TRACK_TIMEOUT_URL + '?data=' + JSON.stringify(timeoutData)); } }; -function buildUrl(path) { - return (config.getConfig('devMode') ? DEBUG_URL : BASE_URL) + path; -} - -function makeBanner(bannerParams) { - const bannerSizes = bannerParams && bannerParams.sizes; - if (bannerSizes) { - const sizes = parseSizesInput(bannerSizes); - if (sizes.length) { - const format = sizes.map(size => { - const [ width, height ] = size.split('x'); - const w = parseInt(width, 10); - const h = parseInt(height, 10); - return { w, h }; - }); - - return { format }; - } - } -} - -function makeVideo(videoParams = {}) { - const video = Object.keys(videoParams).filter((param) => param !== 'context' && param !== 'playerSize') - .reduce((result, param) => { - result[param] = videoParams[param]; - return result; - }, { w: deepAccess(videoParams, 'playerSize.0.0'), h: deepAccess(videoParams, 'playerSize.0.1') }); - - if (video.w && video.h) { - return video; - } -} - -function buildImpObject(bid) { - const { params: { uid }, bidId, mediaTypes, sizes, adUnitCode } = bid; - const video = mediaTypes && _isVideoBid(bid) && _isValidVideoBid(bid) && makeVideo(mediaTypes.video); - const banner = makeBanner((mediaTypes && mediaTypes.banner) || (!video && { sizes })); - const impObject = { - id: bidId, - ...(banner && { banner }), - ...(video && { video }), - ext: { - bidder: { uid: Number(uid) }, - } - }; - - if (impObject.banner) { - impObject.ext.bidder.adslotExists = _isAdSlotExists(adUnitCode); - } - - if (impObject.ext.bidder.uid && (impObject.banner || impObject.video)) { - return impObject; - } -} - function _getBidFromResponse(respItem) { if (!respItem) { logError(LOG_ERROR_MESS.emptySeatbid); @@ -273,52 +221,69 @@ function _getBidFromResponse(respItem) { return respItem && respItem.bid && respItem.bid[0]; } -function _addBidResponse(serverBid, bidsMap, currency, bidResponses) { +function _addBidResponse(serverBid, bidsMap, currency, bidResponses, bidsWithoutSizeMatching) { if (!serverBid) return; let errorMessage; if (!serverBid.auid) errorMessage = LOG_ERROR_MESS.noAuid + JSON.stringify(serverBid); - if (!serverBid.impid) errorMessage = LOG_ERROR_MESS.noImpId + JSON.stringify(serverBid); if (!serverBid.adm) errorMessage = LOG_ERROR_MESS.noAdm + JSON.stringify(serverBid); else { const reqCurrency = currency || DEFAULT_CUR; - const bid = bidsMap[serverBid.impid]; - if (bid) { + const awaitingBids = bidsMap[serverBid.auid]; + if (awaitingBids) { if (serverBid.cur && serverBid.cur !== reqCurrency) { errorMessage = LOG_ERROR_MESS.currencyMismatch + reqCurrency + ' - ' + serverBid.cur; } else { - const bidResponse = { - requestId: bid.bidId, - cpm: serverBid.price, - width: serverBid.w, - height: serverBid.h, - creativeId: serverBid.auid, - currency: reqCurrency, - netRevenue: true, - ttl: TIME_TO_LIVE, - dealId: serverBid.dealid, - meta: { - advertiserDomains: serverBid.advertiserDomains ? serverBid.advertiserDomains : [], - mediaType: serverBid.mediaType - }, - }; - - if (serverBid.ext && serverBid.ext.prebid) { - bidResponse.ext = serverBid.ext.prebid; - } - - const visxTargeting = deepAccess(serverBid, 'ext.prebid.targeting'); - if (visxTargeting) { - bidResponse.adserverTargeting = visxTargeting; - } - - if (!_isVideoInstreamBid(bid)) { - bidResponse.ad = serverBid.adm; + const sizeId = bidsWithoutSizeMatching ? `${serverBid.w}x${serverBid.h}` : Object.keys(awaitingBids)[0]; + if (awaitingBids[sizeId]) { + const slot = awaitingBids[sizeId][0]; + + const bid = slot.bids.shift(); + const bidResponse = { + requestId: bid.bidId, + cpm: serverBid.price, + width: serverBid.w, + height: serverBid.h, + creativeId: serverBid.auid, + currency: reqCurrency, + netRevenue: true, + ttl: TIME_TO_LIVE, + dealId: serverBid.dealid, + meta: { + advertiserDomains: serverBid.advertiserDomains ? serverBid.advertiserDomains : [], + mediaType: serverBid.mediaType + }, + }; + + if (serverBid.ext && serverBid.ext.prebid) { + bidResponse.ext = serverBid.ext.prebid; + } + + if (!_isVideoInstreamBid(bid)) { + bidResponse.ad = serverBid.adm; + } else { + bidResponse.vastXml = serverBid.adm; + bidResponse.mediaType = 'video'; + } + + bidResponses.push(bidResponse); + + if (!slot.bids.length) { + slot.parents.forEach(({parent, key, uid}) => { + const index = parent[key].indexOf(slot); + if (index > -1) { + parent[key].splice(index, 1); + } + if (!parent[key].length) { + delete parent[key]; + if (!getKeys(parent).length) { + delete bidsMap[uid]; + } + } + }); + } } else { - bidResponse.vastXml = serverBid.adm; - bidResponse.mediaType = 'video'; + bidsWithoutSizeMatching && bidsWithoutSizeMatching.push(serverBid); } - - bidResponses.push(bidResponse); } } else { errorMessage = LOG_ERROR_MESS.noPlacementCode + serverBid.auid; @@ -356,20 +321,89 @@ function _isValidVideoBid(bid, logErrors = false) { } result = false; } + if (!videoMediaType.mimes) { + if (logErrors) { + logError(LOG_ERROR_MESS.videoMissing + 'mimes'); + } + result = false; + } + if (!videoMediaType.protocols) { + if (logErrors) { + logError(LOG_ERROR_MESS.videoMissing + 'protocols'); + } + result = false; + } return result; } -function _isAdSlotExists(adUnitCode) { - if (document.getElementById(adUnitCode)) { - return true; +function _initVideoTypes(bids) { + const result = {}; + let _playerSize = []; + let _protocols = []; + let _api = []; + let _mimes = []; + let _minduration = []; + let _maxduration = []; + let _skip = []; + if (bids && bids.length) { + bids.forEach(function (bid) { + const mediaTypes = deepAccess(bid, 'mediaTypes.video', {}); + let bidPlayerSize = ''; + let bidProtocols = ''; + let bidApi = ''; + let bidMimes = ''; + let bidMinduration = null; + let bidMaxduration = null; + let bidSkip = null; + if (_isVideoBid(bid) && _isValidVideoBid(bid)) { + bidPlayerSize = parseSizesInput(deepAccess(mediaTypes, 'playerSize', [])).join('|'); + bidProtocols = deepAccess(mediaTypes, 'protocols', []).join('|'); + bidApi = deepAccess(mediaTypes, 'api', []).join('|'); + bidMimes = deepAccess(mediaTypes, 'mimes', []).join('|'); + bidMinduration = deepAccess(mediaTypes, 'minduration', null); + bidMaxduration = deepAccess(mediaTypes, 'maxduration', null); + bidSkip = deepAccess(mediaTypes, 'skip', null); + } + _playerSize.push(bidPlayerSize); + _protocols.push(bidProtocols); + _api.push(bidApi); + _mimes.push(bidMimes); + _minduration.push(bidMinduration); + _maxduration.push(bidMaxduration); + _skip.push(bidSkip); + }); } - - const gptAdSlot = getGptSlotInfoForAdUnitCode(adUnitCode); - if (gptAdSlot && gptAdSlot.divId && document.getElementById(gptAdSlot.divId)) { - return true; + _playerSize = _playerSize.join(','); + _protocols = _protocols.join(','); + _api = _api.join(','); + _mimes = _mimes.join(','); + _minduration = _minduration.join(','); + _maxduration = _maxduration.join(','); + _skip = _skip.join(','); + + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_playerSize)) { + result.playerSize = _playerSize; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_protocols)) { + result.protocols = _protocols; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_api)) { + result.api = _api; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_mimes)) { + result.mimes = _mimes; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_minduration)) { + result.minduration = _minduration; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_maxduration)) { + result.maxduration = _maxduration; + } + if (!RE_EMPTY_OR_ONLY_COMMAS.test(_skip)) { + result.skip = _skip; } - return false; + return result; } registerBidder(spec); diff --git a/modules/visxBidAdapter.md b/modules/visxBidAdapter.md index 34ebe9bb937..9578f7cc4a7 100644 --- a/modules/visxBidAdapter.md +++ b/modules/visxBidAdapter.md @@ -3,7 +3,7 @@ ``` Module Name: YOC VIS.X Bidder Adapter Module Type: Bidder Adapter -Maintainer: supply.partners@yoc.com +Maintainer: service@yoc.com ``` # Description @@ -47,14 +47,16 @@ var adUnits = [ } ] }, - // In-stream video adUnit + // YOC In-stream adUnit { code: 'instream-test-div', mediaTypes: { video: { context: 'instream', - playerSize: [400, 300] - } + playerSize: [400, 300], + mimes: ['video/mp4'], + protocols: [3, 6] + }, }, bids: [ { diff --git a/modules/voxBidAdapter.js b/modules/voxBidAdapter.js index 8db97800630..ba469c3c7ed 100644 --- a/modules/voxBidAdapter.js +++ b/modules/voxBidAdapter.js @@ -1,4 +1,4 @@ -import { _map, logWarn, deepAccess, isArray } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import {BANNER, VIDEO} from '../src/mediaTypes.js' import find from 'core-js-pure/features/array/find.js'; @@ -11,7 +11,7 @@ const VIDEO_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVi const TTL = 60; function buildBidRequests(validBidRequests) { - return _map(validBidRequests, function(validBidRequest) { + return utils._map(validBidRequests, function(validBidRequest) { const params = validBidRequest.params; const bidRequest = { bidId: validBidRequest.bidId, @@ -53,7 +53,7 @@ const createRenderer = (bid) => { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on renderer', err); + utils.logWarn('Prebid Error calling setRender on renderer', err); } return renderer; @@ -111,8 +111,8 @@ function hasVideoMandatoryParams(mediaTypes) { const isHasVideoContext = !!mediaTypes.video && (mediaTypes.video.context === 'instream' || mediaTypes.video.context === 'outstream'); const isPlayerSize = - !!deepAccess(mediaTypes, 'video.playerSize') && - isArray(deepAccess(mediaTypes, 'video.playerSize')); + !!utils.deepAccess(mediaTypes, 'video.playerSize') && + utils.isArray(utils.deepAccess(mediaTypes, 'video.playerSize')); return isHasVideoContext && isPlayerSize; } @@ -231,8 +231,8 @@ export const spec = { let bidRequests = JSON.parse(bidRequest.data).bidRequests; const serverBody = serverResponse.body; - if (serverBody && serverBody.bids && isArray(serverBody.bids)) { - return _map(serverBody.bids, function(bid) { + if (serverBody && serverBody.bids && utils.isArray(serverBody.bids)) { + return utils._map(serverBody.bids, function(bid) { let rawBid = find(bidRequests, function (item) { return item.bidId === bid.bidId; }); diff --git a/modules/vrtcalBidAdapter.js b/modules/vrtcalBidAdapter.js index d08ef52106e..d23a05e23ca 100644 --- a/modules/vrtcalBidAdapter.js +++ b/modules/vrtcalBidAdapter.js @@ -1,7 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; import {ajax} from '../src/ajax.js'; -import {isFn, isPlainObject} from '../src/utils.js'; export const spec = { code: 'vrtcal', @@ -11,17 +10,8 @@ export const spec = { }, buildRequests: function (bidRequests) { const requests = bidRequests.map(function (bid) { - let floor = 0; - - if (isFn(bid.getFloor)) { - const floorInfo = bid.getFloor({ currency: 'USD', mediaType: 'banner', size: bid.sizes.map(([w, h]) => ({w, h})) }); - - if (isPlainObject(floorInfo) && floorInfo.currency === 'USD' && !isNaN(parseFloat(floorInfo.floor))) { - floor = Math.max(floor, parseFloat(floorInfo.floor)); - } - } - const params = { + prebidJS: 1, prebidAdUnitCode: bid.adUnitCode, id: bid.bidId, @@ -29,7 +19,7 @@ export const spec = { id: '1', banner: { }, - bidfloor: floor + bidfloor: 0.75 }], site: { id: 'VRTCAL_FILLED', diff --git a/modules/vuukleBidAdapter.js b/modules/vuukleBidAdapter.js index ddf96b3e940..7a83bf4e331 100644 --- a/modules/vuukleBidAdapter.js +++ b/modules/vuukleBidAdapter.js @@ -1,4 +1,4 @@ -import { parseSizesInput } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; const BIDDER_CODE = 'vuukle'; @@ -14,7 +14,7 @@ export const spec = { buildRequests: function(bidRequests) { const requests = bidRequests.map(function (bid) { - const parseSized = parseSizesInput(bid.sizes); + const parseSized = utils.parseSizesInput(bid.sizes); const arrSize = parseSized[0].split('x'); const params = { url: encodeURIComponent(window.location.href), diff --git a/modules/waardexBidAdapter.js b/modules/waardexBidAdapter.js index ee17a71dd35..bc60e151e39 100644 --- a/modules/waardexBidAdapter.js +++ b/modules/waardexBidAdapter.js @@ -1,7 +1,7 @@ -import { logError, isArray, deepAccess, getBidIdParameter } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import * as utils from '../src/utils.js'; import find from 'core-js-pure/features/array/find.js'; const ENDPOINT = `https://hb.justbidit.xyz:8843/prebid`; @@ -9,38 +9,38 @@ const BIDDER_CODE = 'waardex'; const isBidRequestValid = bid => { if (!bid.bidId) { - logError(BIDDER_CODE + ': bid.bidId should be non-empty'); + utils.logError(BIDDER_CODE + ': bid.bidId should be non-empty'); return false; } if (!bid.params) { - logError(BIDDER_CODE + ': bid.params should be non-empty'); + utils.logError(BIDDER_CODE + ': bid.params should be non-empty'); return false; } if (!+bid.params.zoneId) { - logError(BIDDER_CODE + ': bid.params.zoneId should be non-empty Number'); + utils.logError(BIDDER_CODE + ': bid.params.zoneId should be non-empty Number'); return false; } if (bid.mediaTypes && bid.mediaTypes.video) { if (!bid.mediaTypes.video.playerSize) { - logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty'); + utils.logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty'); return false; } - if (!isArray(bid.mediaTypes.video.playerSize)) { - logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be an Array'); + if (!utils.isArray(bid.mediaTypes.video.playerSize)) { + utils.logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be an Array'); return false; } if (!bid.mediaTypes.video.playerSize[0]) { - logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty'); + utils.logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty'); return false; } - if (!isArray(bid.mediaTypes.video.playerSize[0])) { - logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty Array'); + if (!utils.isArray(bid.mediaTypes.video.playerSize[0])) { + utils.logError(BIDDER_CODE + ': bid.mediaTypes.video.playerSize should be non-empty Array'); return false; } } @@ -139,22 +139,22 @@ const transformSizes = requestSizes => { const createVideoObject = (videoMediaTypes, videoParams) => { return { - w: deepAccess(videoMediaTypes, 'playerSize')[0][0], - h: deepAccess(videoMediaTypes, 'playerSize')[0][1], - mimes: getBidIdParameter('mimes', videoParams) || ['application/javascript', 'video/mp4', 'video/webm'], - minduration: getBidIdParameter('minduration', videoParams) || 0, - maxduration: getBidIdParameter('maxduration', videoParams) || 500, - protocols: getBidIdParameter('protocols', videoParams) || [2, 3, 5, 6], - startdelay: getBidIdParameter('startdelay', videoParams) || 0, - placement: getBidIdParameter('placement', videoParams) || videoMediaTypes.context === 'outstream' ? 3 : 1, - skip: getBidIdParameter('skip', videoParams) || 1, - skipafter: getBidIdParameter('skipafter', videoParams) || 0, - minbitrate: getBidIdParameter('minbitrate', videoParams) || 0, - maxbitrate: getBidIdParameter('maxbitrate', videoParams) || 3500, - delivery: getBidIdParameter('delivery', videoParams) || [2], - playbackmethod: getBidIdParameter('playbackmethod', videoParams) || [1, 2, 3, 4], - api: getBidIdParameter('api', videoParams) || [2], - linearity: getBidIdParameter('linearity', videoParams) || 1 + w: utils.deepAccess(videoMediaTypes, 'playerSize')[0][0], + h: utils.deepAccess(videoMediaTypes, 'playerSize')[0][1], + mimes: utils.getBidIdParameter('mimes', videoParams) || ['application/javascript', 'video/mp4', 'video/webm'], + minduration: utils.getBidIdParameter('minduration', videoParams) || 0, + maxduration: utils.getBidIdParameter('maxduration', videoParams) || 500, + protocols: utils.getBidIdParameter('protocols', videoParams) || [2, 3, 5, 6], + startdelay: utils.getBidIdParameter('startdelay', videoParams) || 0, + placement: utils.getBidIdParameter('placement', videoParams) || videoMediaTypes.context === 'outstream' ? 3 : 1, + skip: utils.getBidIdParameter('skip', videoParams) || 1, + skipafter: utils.getBidIdParameter('skipafter', videoParams) || 0, + minbitrate: utils.getBidIdParameter('minbitrate', videoParams) || 0, + maxbitrate: utils.getBidIdParameter('maxbitrate', videoParams) || 3500, + delivery: utils.getBidIdParameter('delivery', videoParams) || [2], + playbackmethod: utils.getBidIdParameter('playbackmethod', videoParams) || [1, 2, 3, 4], + api: utils.getBidIdParameter('api', videoParams) || [2], + linearity: utils.getBidIdParameter('linearity', videoParams) || 1 }; }; diff --git a/modules/weboramaBidAdapter.md b/modules/weboramaBidAdapter.md new file mode 100644 index 00000000000..5bdca0bfcd1 --- /dev/null +++ b/modules/weboramaBidAdapter.md @@ -0,0 +1,27 @@ +# Overview + +``` +Module Name: Weborama SSP Bidder Adapter +Module Type: Bidder Adapter +Maintainer: devweborama@gmail.com +``` + +# Description + +Module that connects to Weborama SSP demand sources + +# Test Parameters +``` + var adUnits = [{ + code: 'placementCode', + sizes: [[300, 250]], + bids: [{ + bidder: 'weborama', + params: { + placementId: 0, + traffic: 'banner' + } + }] + } + ]; +``` diff --git a/modules/weboramaRtdProvider.js b/modules/weboramaRtdProvider.js deleted file mode 100644 index 70f258e1698..00000000000 --- a/modules/weboramaRtdProvider.js +++ /dev/null @@ -1,389 +0,0 @@ -/** - * This module adds Weborama provider to the real time data module - * The {@link module:modules/realTimeData} module is required - * The module will fetch contextual data (page-centric) from Weborama server - * and may access user-centric data from local storage - * @module modules/weboramaRtdProvider - * @requires module:modules/realTimeData - */ - -/** - * @typedef {Object} ModuleParams - * @property {WeboCtxConf} weboCtxConf - * @property {WeboUserDataConf} weboUserDataConf - */ - -/** - * @typedef {Object} WeboCtxConf - * @property {string} token required token to be used on bigsea contextual API requests - * @property {?string} targetURL specify the target url instead use the referer - * @property {?Boolean} setPrebidTargeting if true will set the GAM targeting (default true) - * @property {?Boolean} sendToBidders if true, will send the contextual profile to all bidders (default true) - * @property {?object} defaultProfile to be used if the profile is not found - */ - -/** - * @typedef {Object} WeboUserDataConf - * @property {?string} localStorageProfileKey can be used to customize the local storage key (default is 'webo_wam2gam_entry') - * @property {?Boolean} setPrebidTargeting if true will set the GAM targeting (default true) - * @property {?Boolean} sendToBidders if true, will send the contextual profile to all bidders (default true) - * @property {?object} defaultProfile to be used if the profile is not found - */ - -import { - getGlobal -} from '../src/prebidGlobal.js'; -import { - deepSetValue, - deepAccess, - isEmpty, - mergeDeep, - logError, - tryAppendQueryString, - logMessage -} from '../src/utils.js'; -import { - submodule -} from '../src/hook.js'; -import { - ajax -} from '../src/ajax.js'; -import { - getStorageManager -} from '../src/storageManager.js'; - -const adapterManager = require('../src/adapterManager.js').default; - -/** @type {string} */ -const MODULE_NAME = 'realTimeData'; -/** @type {string} */ -const SUBMODULE_NAME = 'weborama'; -/** @type {string} */ -export const DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY = 'webo_wam2gam_entry'; -/** @type {string} */ -const LOCAL_STORAGE_USER_TARGETING_SECTION = 'targeting'; -/** @type {number} */ -const GVLID = 284; -/** @type {object} */ -export const storage = getStorageManager(GVLID, SUBMODULE_NAME); - -/** @type {null|Object} */ -let _weboContextualProfile = null; - -/** @type {Boolean} */ -let _weboCtxInitialized = false; - -/** @type {null|Object} */ -let _weboUserDataUserProfile = null; - -/** @type {Boolean} */ -let _weboUserDataInitialized = false; - -/** Initialize module - * @param {object} moduleConfig - * @return {Boolean} true if module was initialized with success - */ -function init(moduleConfig) { - moduleConfig = moduleConfig || {}; - const moduleParams = moduleConfig.params || {}; - const weboCtxConf = moduleParams.weboCtxConf || {}; - const weboUserDataConf = moduleParams.weboUserDataConf; - - _weboCtxInitialized = initWeboCtx(weboCtxConf); - _weboUserDataInitialized = initWeboUserData(weboUserDataConf); - - return _weboCtxInitialized || _weboUserDataInitialized; -} - -/** Initialize contextual sub module - * @param {WeboCtxConf} weboCtxConf - * @return {Boolean} true if sub module was initialized with success - */ -function initWeboCtx(weboCtxConf) { - _weboCtxInitialized = false; - _weboContextualProfile = null; - - if (!weboCtxConf.token) { - logError('missing param "token" for weborama contextual sub module initialization'); - return false; - } - - return true; -} - -/** Initialize weboUserData sub module - * @param {WeboUserDataConf} weboUserDataConf - * @return {Boolean} true if sub module was initialized with success - */ -function initWeboUserData(weboUserDataConf) { - _weboUserDataInitialized = false; - _weboUserDataUserProfile = null; - - return !!weboUserDataConf; -} - -/** function that provides ad server targeting data to RTD-core - * @param {Array} adUnitsCodes - * @param {Object} moduleConfig - * @returns {Object} target data - */ -function getTargetingData(adUnitsCodes, moduleConfig) { - moduleConfig = moduleConfig || {}; - const moduleParams = moduleConfig.params || {}; - const weboCtxConf = moduleParams.weboCtxConf || {}; - const weboUserDataConf = moduleParams.weboUserDataConf || {}; - const weboCtxConfTargeting = weboCtxConf.setPrebidTargeting !== false; - const weboUserDataConfTargeting = weboUserDataConf.setPrebidTargeting !== false; - - try { - const profile = getCompleteProfile(moduleParams, weboCtxConfTargeting, weboUserDataConfTargeting); - - if (isEmpty(profile)) { - return {}; - } - - const td = adUnitsCodes.reduce((data, adUnitCode) => { - if (adUnitCode) { - data[adUnitCode] = profile; - } - return data; - }, {}); - - return td; - } catch (e) { - logError('unable to format weborama rtd targeting data', e); - return {}; - } -} - -/** function that provides complete profile formatted to be used - * @param {ModuleParams} moduleParams - * @param {Boolean} weboCtxConfTargeting - * @param {Boolean} weboUserDataConfTargeting - * @returns {Object} complete profile - */ -function getCompleteProfile(moduleParams, weboCtxConfTargeting, weboUserDataConfTargeting) { - const profile = {}; - - if (weboCtxConfTargeting) { - const contextualProfile = getContextualProfile(moduleParams.weboCtxConf || {}); - mergeDeep(profile, contextualProfile); - } - - if (weboUserDataConfTargeting) { - const weboUserDataProfile = getWeboUserDataProfile(moduleParams.weboUserDataConf || {}); - mergeDeep(profile, weboUserDataProfile); - } - - return profile; -} - -/** return contextual profile - * @param {WeboCtxConf} weboCtxConf - * @returns {Object} contextual profile - */ -function getContextualProfile(weboCtxConf) { - const defaultContextualProfile = weboCtxConf.defaultProfile || {}; - return _weboContextualProfile || defaultContextualProfile; -} - -/** return weboUserData profile - * @param {WeboUserDataConf} weboUserDataConf - * @returns {Object} weboUserData profile - */ -function getWeboUserDataProfile(weboUserDataConf) { - const weboUserDataDefaultUserProfile = weboUserDataConf.defaultProfile || {}; - - if (storage.localStorageIsEnabled() && !_weboUserDataUserProfile) { - const localStorageProfileKey = weboUserDataConf.localStorageProfileKey || DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY; - - const entry = storage.getDataFromLocalStorage(localStorageProfileKey); - if (entry) { - const data = JSON.parse(entry); - if (data && Object.keys(data).length > 0) { - _weboUserDataUserProfile = data[LOCAL_STORAGE_USER_TARGETING_SECTION]; - } - } - } - - return _weboUserDataUserProfile || weboUserDataDefaultUserProfile; -} - -/** function that will allow RTD sub-modules to modify the AdUnit object for each auction - * @param {Object} reqBidsConfigObj - * @param {doneCallback} onDone - * @param {Object} moduleConfig - * @returns {void} - */ -export function getBidRequestData(reqBidsConfigObj, onDone, moduleConfig) { - moduleConfig = moduleConfig || {}; - const moduleParams = moduleConfig.params || {}; - const weboCtxConf = moduleParams.weboCtxConf || {}; - - const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits; - - if (!_weboCtxInitialized) { - handleBidRequestData(adUnits, moduleParams); - - onDone(); - - return; - } - - fetchContextualProfile(weboCtxConf, (data) => { - logMessage('fetchContextualProfile on getBidRequestData is done'); - - setWeboContextualProfile(data); - }, () => { - handleBidRequestData(adUnits, moduleParams); - - onDone(); - }); -} - -/** function that handles bid request data - * @param {Object[]} adUnits - * @param {ModuleParams} moduleParams - * @returns {void} - */ - -function handleBidRequestData(adUnits, moduleParams) { - const weboCtxConf = moduleParams.weboCtxConf || {}; - const weboUserDataConf = moduleParams.weboUserDataConf || {}; - const weboCtxConfTargeting = weboCtxConf.sendToBidders !== false; - const weboUserDataConfTargeting = weboUserDataConf.sendToBidders !== false; - const profile = getCompleteProfile(moduleParams, weboCtxConfTargeting, weboUserDataConfTargeting); - - if (isEmpty(profile)) { - return; - } - - adUnits.forEach(adUnit => { - if (adUnit.hasOwnProperty('bids')) { - adUnit.bids.forEach(bid => handleBid(adUnit, profile, bid)); - } - }); -} - -/** @type {string} */ -const SMARTADSERVER = 'smartadserver'; - -/** @type {Object} */ -const bidderAliasRegistry = adapterManager.aliasRegistry || {}; - -/** handle individual bid - * @param {Object} adUnit - * @param {Object} profile - * @param {Object} bid - * @returns {void} - */ -function handleBid(adUnit, profile, bid) { - const bidder = bidderAliasRegistry[bid.bidder] || bid.bidder; - - logMessage('handle bidder', bidder, bid); - - switch (bidder) { - case SMARTADSERVER: - handleSmartadserverBid(adUnit, profile, bid); - - break; - } -} - -/** handle smartadserver bid - * @param {Object} adUnit - * @param {Object} profile - * @param {Object} bid - * @returns {void} - */ -function handleSmartadserverBid(adUnit, profile, bid) { - const target = []; - - if (deepAccess(bid, 'params.target')) { - target.push(bid.params.target.split(';')); - } - - Object.keys(profile).forEach(key => { - profile[key].forEach(value => { - const keyword = `${key}=${value}`; - if (target.indexOf(keyword) === -1) { - target.push(keyword); - } - }); - }); - - deepSetValue(bid, 'params.target', target.join(';')); -} - -/** set bigsea contextual profile on module state - * @param {null|Object} data - * @returns {void} - */ -export function setWeboContextualProfile(data) { - if (data && Object.keys(data).length > 0) { - _weboContextualProfile = data; - } -} - -/** onSuccess callback type - * @callback successCallback - * @param {null|Object} data - * @returns {void} - */ - -/** onDone callback type - * @callback doneCallback - * @returns {void} - */ - -/** Fetch Bigsea Contextual Profile - * @param {WeboCtxConf} weboCtxConf - * @param {successCallback} onSuccess callback - * @param {doneCallback} onDone callback - * @returns {void} - */ -function fetchContextualProfile(weboCtxConf, onSuccess, onDone) { - const targetURL = weboCtxConf.targetURL || document.URL; - const token = weboCtxConf.token; - - let queryString = ''; - queryString = tryAppendQueryString(queryString, 'token', token); - queryString = tryAppendQueryString(queryString, 'url', targetURL); - - const url = 'https://ctx.weborama.com/api/profile?' + queryString; - - ajax(url, { - success: function(response, req) { - if (req.status === 200) { - try { - const data = JSON.parse(response); - onSuccess(data); - onDone(); - } catch (e) { - onDone(); - logError('unable to parse weborama data', e); - throw e; - } - } else if (req.status === 204) { - onDone(); - } - }, - error: function() { - onDone(); - logError('unable to get weborama data'); - } - }, - null, { - method: 'GET', - withCredentials: false, - }); -} - -export const weboramaSubmodule = { - name: SUBMODULE_NAME, - init: init, - getTargetingData: getTargetingData, - getBidRequestData: getBidRequestData, -}; - -submodule(MODULE_NAME, weboramaSubmodule); diff --git a/modules/weboramaRtdProvider.md b/modules/weboramaRtdProvider.md deleted file mode 100644 index 06e5b4fb43b..00000000000 --- a/modules/weboramaRtdProvider.md +++ /dev/null @@ -1,87 +0,0 @@ -# Weborama Real-Time Data Submodule - -``` -Module Name: Weborama Rtd Provider -Module Type: Rtd Provider -Maintainer: prebid-support@weborama.com -``` - -# Description - -Weborama provides a Semantic AI Contextual API that classifies in Real-time a web page seen by a web user within generic and custom topics. It enables publishers to better monetize their inventory and unlock it to programmatic. - -Contact prebid-support@weborama.com for information. - -### Publisher Usage - -Compile the Weborama RTD module into your Prebid build: - -`gulp build --modules=rtdModule,weboramaRtdProvider` - -Add the Weborama RTD provider to your Prebid config. - -```javascript -pbjs.setConfig( - ... - realTimeData: { - auctionDelay: 1000, - dataProviders: [ - { - name: "weborama", - waitForIt: true, - params: { - weboCtxConf: { // contextual configuration - token: "<>", // mandatory - targetURL: "...", // default is document.URL - setPrebidTargeting: true, // default - sendToBidders: true, // default - defaultProfile: { // optional, default is none - webo_ctx: ['foo'], - webo_ds: ['bar'] - } - }, - weboUserDataConf: { // user-centric configuration - setPrebidTargeting: true, // default - sendToBidders: true, // default - defaultProfile: { // optional, default is none - webo_cs: ['baz'], - webo_audiences: ['bam'] - }, - localStorageProfileKey: 'webo_wam2gam_entry' // default - } - } - } - ] - } - ... -); -``` - -### Parameter Descriptions for the Weborama Configuration Section - -| Name |Type | Description | Notes | -| :------------ | :------------ | :------------ |:------------ | -| name | String | Real time data module name | Mandatory. Always 'Weborama' | -| waitForIt | Boolean | Mandatory. Required to ensure that the auction is delayed until prefetch is complete | Optional. Defaults to false but recommended to true | -| params | Object | | Optional | -| params.weboCtxConf | Object | Weborama Contextual Configuration | Optional | -| params.weboCtxConf.token | String | Security Token provided by Weborama, unique per client | Mandatory | -| params.weboCtxConf.targetURL | String | Url to be profiled in the contextual api | Optional. Defaults to `document.URL` | -| params.weboCtxConf.setPrebidTargeting|Boolean|If true, will use the contextual profile to set the prebid (GPT/GAM or AST) targeting of all adunits managed by prebid.js| Optional. Default is *true*.| -| params.weboCtxConf.sendToBidders|Boolean|If true, will send the contextual profile to all bidders (only smartadserver is supported now)| Optional. Default is *true*.| -| params.weboCtxConf.defaultProfile | Object | default value of the profile to be used when there are no response from contextual api (such as timeout)| Optional. Default is `{}` | -| params.weboUserDataConf | Object | WeboUserData Configuration | Optional | -| params.weboUserDataConf.setPrebidTargeting|Boolean|If true, will use the contextual profile to set the prebid (GPT/GAM or AST) targeting of all adunits managed by prebid.js| Optional. Default is *true*.| -| params.weboUserDataConf.sendToBidders|Boolean|If true, will send the contextual profile to all bidders (only smartadserver is supported now)| Optional. Default is *true*.| -| params.weboUserDataConf.defaultProfile | Object | default value of the profile to be used when there are no response from contextual api (such as timeout)| Optional. Default is `{}` | -| params.weboUserDataConf.localStorageProfileKey| String | can be used to customize the local storage key | Optional | - -### Testing - -To view an example of available segments returned by Weborama's backends: - -`gulp serve --modules=rtdModule,weboramaRtdProvider,smartadserverBidAdapter` - -and then point your browser at: - -`http://localhost:9999/integrationExamples/gpt/weboramaRtdProvider_example.html` diff --git a/modules/welectBidAdapter.js b/modules/welectBidAdapter.js deleted file mode 100644 index d88a3f4c3e2..00000000000 --- a/modules/welectBidAdapter.js +++ /dev/null @@ -1,106 +0,0 @@ -import { deepAccess } from '../src/utils.js'; -import { registerBidder } from '../src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'welect'; -const DEFAULT_DOMAIN = 'www.welect.de'; - -export const spec = { - code: BIDDER_CODE, - aliases: ['wlt'], - gvlid: 282, - supportedMediaTypes: ['video'], - - // short code - /** - * Determines whether or not the given bid request is valid. - * - * @param {BidRequest} bid The bid params to validate. - * @return boolean True if this is a valid bid, and false otherwise. - */ - isBidRequestValid: function (bid) { - return ( - deepAccess(bid, 'mediaTypes.video.context') === 'instream' && - !!bid.params.placementId - ); - }, - /** - * Make a server request from the list of BidRequests. - * - * @param {validBidRequests[]} - an array of bids - * @return ServerRequest Info describing the request to the server. - */ - buildRequests: function (validBidRequests) { - return validBidRequests.map((bidRequest) => { - let rawSizes = - deepAccess(bidRequest, 'mediaTypes.video.playerSize') || - bidRequest.sizes; - let size = rawSizes[0]; - - let domain = bidRequest.params.domain || DEFAULT_DOMAIN; - - let url = `https://${domain}/api/v2/preflight/${bidRequest.params.placementId}`; - - let gdprConsent = null; - - if (bidRequest && bidRequest.gdprConsent) { - gdprConsent = { - gdpr_consent: { - gdprApplies: bidRequest.gdprConsent.gdprApplies, - tcString: bidRequest.gdprConsent.gdprConsent, - }, - }; - } - - const data = { - width: size[0], - height: size[1], - bid_id: bidRequest.bidId, - ...gdprConsent, - }; - - return { - method: 'POST', - url: url, - data: data, - options: { - contentType: 'application/json', - withCredentials: false, - crossOrigin: true, - }, - }; - }); - }, - /** - * Unpack the response from the server into a list of bids. - * - * @param {ServerResponse} serverResponse A successful response from the server. - * @return {Bid[]} An array of bids which were nested inside the server. - */ - interpretResponse: function (serverResponse, bidRequest) { - const responseBody = serverResponse.body; - - if (typeof responseBody !== 'object' || responseBody.available !== true) { - return []; - } - - const bidResponses = []; - const bidResponse = { - requestId: responseBody.bidResponse.requestId, - cpm: responseBody.bidResponse.cpm, - width: responseBody.bidResponse.width, - height: responseBody.bidResponse.height, - creativeId: responseBody.bidResponse.creativeId, - currency: responseBody.bidResponse.currency, - netRevenue: responseBody.bidResponse.netRevenue, - ttl: responseBody.bidResponse.ttl, - ad: responseBody.bidResponse.ad, - vastUrl: responseBody.bidResponse.vastUrl, - meta: { - advertiserDomains: responseBody.bidResponse.meta.advertiserDomains - } - }; - bidResponses.push(bidResponse); - return bidResponses; - }, -}; -registerBidder(spec); diff --git a/modules/winrBidAdapter.js b/modules/winrBidAdapter.js index 9213c113460..b73758e9717 100644 --- a/modules/winrBidAdapter.js +++ b/modules/winrBidAdapter.js @@ -1,4 +1,4 @@ -import { convertCamelToUnderscore, isArray, isNumber, isPlainObject, deepAccess, logError, convertTypes, getParameterByName, getBidRequest, isEmpty, transformBidderParamKeywords, isFn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { BANNER } from '../src/mediaTypes.js'; @@ -139,16 +139,16 @@ export const spec = { Object.keys(userObjBid.params.user) .filter((param) => includes(USER_PARAMS, param)) .forEach((param) => { - let uparam = convertCamelToUnderscore(param); + let uparam = utils.convertCamelToUnderscore(param); if ( param === 'segments' && - isArray(userObjBid.params.user[param]) + utils.isArray(userObjBid.params.user[param]) ) { let segs = []; userObjBid.params.user[param].forEach((val) => { - if (isNumber(val)) { + if (utils.isNumber(val)) { segs.push({ id: val }); - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { segs.push(val); } }); @@ -228,12 +228,12 @@ export const spec = { if (bidRequests[0].userId) { let eids = []; - addUserId(eids, deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); - addUserId(eids, deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); - addUserId(eids, deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.flocId.id`), 'chrome.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.criteoId`), 'criteo.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.netId`), 'netid.de', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.idl_env`), 'liveramp.com', null); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.tdid`), 'adserver.org', 'TDID'); + addUserId(eids, utils.deepAccess(bidRequests[0], `userId.uid2.id`), 'uidapi.com', 'UID2'); if (eids.length) { payload.eids = eids; @@ -262,7 +262,7 @@ export const spec = { if (serverResponse && serverResponse.error) { errorMessage += `: ${serverResponse.error}`; } - logError(errorMessage); + utils.logError(errorMessage); return bids; } @@ -297,12 +297,12 @@ export const spec = { }, transformBidParams: function (params, isOpenRtb) { - params = convertTypes( + params = utils.convertTypes( { member: 'string', invCode: 'string', placementId: 'number', - keywords: transformBidderParamKeywords, + keywords: utils.transformBidderParamKeywords, publisherId: 'number', }, params @@ -322,7 +322,7 @@ export const spec = { } Object.keys(params).forEach((paramKey) => { - let convertedKey = convertCamelToUnderscore(paramKey); + let convertedKey = utils.convertCamelToUnderscore(paramKey); if (convertedKey !== paramKey) { params[convertedKey] = params[paramKey]; delete params[paramKey]; @@ -335,7 +335,7 @@ export const spec = { }; function isPopulatedArray(arr) { - return !!(isArray(arr) && arr.length > 0); + return !!(utils.isArray(arr) && arr.length > 0); } function deleteValues(keyPairObj) { @@ -352,7 +352,7 @@ function hasPurpose1Consent(bidderRequest) { bidderRequest.gdprConsent.apiVersion === 2 ) { result = !!( - deepAccess( + utils.deepAccess( bidderRequest.gdprConsent, 'vendorData.purpose.consents.1' ) === true @@ -375,7 +375,7 @@ function formatRequest(payload, bidderRequest) { } if ( - getParameterByName('apn_test').toUpperCase() === 'TRUE' || + utils.getParameterByName('apn_test').toUpperCase() === 'TRUE' || config.getConfig('apn_test') === true ) { options.customHeaders = { @@ -403,7 +403,7 @@ function formatRequest(payload, bidderRequest) { * @return Bid */ function newBid(serverBid, rtbBid, bidderRequest) { - const bidRequest = getBidRequest(serverBid.uuid, [bidderRequest]); + const bidRequest = utils.getBidRequest(serverBid.uuid, [bidderRequest]); const bid = { adType: rtbBid.ad_type, requestId: serverBid.uuid, @@ -463,7 +463,7 @@ function newBid(serverBid, rtbBid, bidderRequest) { }); } } catch (error) { - logError('Error assigning ad', error); + utils.logError('Error assigning ad', error); } return bid; } @@ -502,8 +502,8 @@ function bidToTag(bid) { if (bid.params.externalImpId) { tag.external_imp_id = bid.params.externalImpId; } - if (!isEmpty(bid.params.keywords)) { - let keywords = transformBidderParamKeywords(bid.params.keywords); + if (!utils.isEmpty(bid.params.keywords)) { + let keywords = utils.transformBidderParamKeywords(bid.params.keywords); if (keywords.length > 0) { keywords.forEach(deleteValues); @@ -511,7 +511,7 @@ function bidToTag(bid) { tag.keywords = keywords; } - let gpid = deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); + let gpid = utils.deepAccess(bid, 'ortb2Imp.ext.data.pbadslot'); if (gpid) { tag.gpid = gpid; } @@ -531,9 +531,9 @@ function transformSizes(requestSizes) { let sizeObj = {}; if ( - isArray(requestSizes) && + utils.isArray(requestSizes) && requestSizes.length === 2 && - !isArray(requestSizes[0]) + !utils.isArray(requestSizes[0]) ) { sizeObj.width = parseInt(requestSizes[0], 10); sizeObj.height = parseInt(requestSizes[1], 10); @@ -596,7 +596,7 @@ function addUserId(eids, id, source, rti) { } function getBidFloor(bid) { - if (!isFn(bid.getFloor)) { + if (!utils.isFn(bid.getFloor)) { return (bid.params.reserve) ? bid.params.reserve : null; } @@ -605,7 +605,7 @@ function getBidFloor(bid) { mediaType: '*', size: '*' }); - if (isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { + if (utils.isPlainObject(floor) && !isNaN(floor.floor) && floor.currency === 'USD') { return floor.floor; } return null; diff --git a/modules/wipesBidAdapter.js b/modules/wipesBidAdapter.js index 3d040fee8d3..c08429ecc63 100644 --- a/modules/wipesBidAdapter.js +++ b/modules/wipesBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; @@ -13,7 +13,7 @@ function isBidRequestValid(bid) { case !!(bid.params.asid): break; default: - logWarn(`isBidRequestValid Error. ${bid.params}, please check your implementation.`); + utils.logWarn(`isBidRequestValid Error. ${bid.params}, please check your implementation.`); return false; } return true; diff --git a/modules/yahoosspBidAdapter.js b/modules/yahoosspBidAdapter.js deleted file mode 100644 index 73a991ec79a..00000000000 --- a/modules/yahoosspBidAdapter.js +++ /dev/null @@ -1,641 +0,0 @@ -import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { BANNER, VIDEO } from '../src/mediaTypes.js'; -import { deepAccess, isFn, isStr, isNumber, isArray, isEmpty, isPlainObject, generateUUID, logInfo, logWarn } from '../src/utils.js'; -import { config } from '../src/config.js'; -import { Renderer } from '../src/Renderer.js'; - -const INTEGRATION_METHOD = 'prebid.js'; -const BIDDER_CODE = 'yahoossp'; -const ADAPTER_VERSION = '1.0.2'; -const PREBID_VERSION = '$prebid.version$'; -const DEFAULT_BID_TTL = 300; -const TEST_MODE_DCN = '8a969516017a7a396ec539d97f540011'; -const TEST_MODE_PUBID_DCN = '1234567'; -const TEST_MODE_BANNER_POS = '8a969978017a7aaabab4ab0bc01a0009'; -const TEST_MODE_VIDEO_POS = '8a96958a017a7a57ac375d50c0c700cc'; -const DEFAULT_RENDERER_TIMEOUT = 700; -const DEFAULT_CURRENCY = 'USD'; -const SSP_ENDPOINT_DCN_POS = 'https://c2shb.pubgw.yahoo.com/bidRequest'; -const SSP_ENDPOINT_PUBID = 'https://c2shb.pubgw.yahoo.com/admax/bid/partners/PBJS'; -const SUPPORTED_USER_ID_SOURCES = [ - 'admixer.net', - 'adserver.org', - 'adtelligent.com', - 'akamai.com', - 'amxrtb.com', - 'audigent.com', - 'britepool.com', - 'criteo.com', - 'crwdcntrl.net', - 'deepintent.com', - 'hcn.health', - 'id5-sync.com', - 'idx.lat', - 'intentiq.com', - 'intimatemerger.com', - 'liveintent.com', - 'liveramp.com', - 'mediawallahscript.com', - 'merkleinc.com', - 'netid.de', - 'neustar.biz', - 'nextroll.com', - 'novatiq.com', - 'parrable.com', - 'pubcid.org', - 'quantcast.com', - 'quantcast.com', - 'tapad.com', - 'uidapi.com', - 'verizonmedia.com', - 'yahoo.com', - 'zeotap.com' -]; - -/* Utility functions */ -function hasPurpose1Consent(bidderRequest) { - if (bidderRequest && bidderRequest.gdprConsent) { - if (bidderRequest.gdprConsent.gdprApplies && bidderRequest.gdprConsent.apiVersion === 2) { - return !!false; - } - } - return true; -} - -function getSize(size) { - return { - w: parseInt(size[0]), - h: parseInt(size[1]) - } -} - -function transformSizes(sizes) { - if (isArray(sizes) && sizes.length === 2 && !isArray(sizes[0])) { - return [ getSize(sizes) ]; - } - return sizes.map(getSize); -} - -function extractUserSyncUrls(syncOptions, pixels) { - let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi; - let tagNameRegExp = /\w*(?=\s)/; - let srcRegExp = /src=("|')(.*?)\1/; - let userSyncObjects = []; - - if (pixels) { - let matchedItems = pixels.match(itemsRegExp); - if (matchedItems) { - matchedItems.forEach(item => { - let tagName = item.match(tagNameRegExp)[0]; - let url = item.match(srcRegExp)[2]; - - if (tagName && url) { - let tagType = tagName.toLowerCase() === 'img' ? 'image' : 'iframe'; - if ((!syncOptions.iframeEnabled && tagType === 'iframe') || - (!syncOptions.pixelEnabled && tagType === 'image')) { - return; - } - userSyncObjects.push({ - type: tagType, - url: url - }); - } - }); - } - } - - return userSyncObjects; -} - -function getSupportedEids(bid) { - if (isArray(deepAccess(bid, 'userIdAsEids'))) { - return bid.userIdAsEids.filter(eid => { - return SUPPORTED_USER_ID_SOURCES.indexOf(eid.source) !== -1; - }); - } - return []; -} - -function isSecure(bid) { - return deepAccess(bid, 'params.bidOverride.imp.secure') || (document.location.protocol === 'https:') ? 1 : 0; -}; - -function getPubIdMode(bid) { - let pubIdMode; - if (deepAccess(bid, 'params.pubId')) { - pubIdMode = true; - } else if (deepAccess(bid, 'params.dcn') && deepAccess(bid, 'params.pos')) { - pubIdMode = false; - }; - return pubIdMode; -}; - -function getAdapterMode() { - let adapterMode = config.getConfig('yahoossp.mode'); - adapterMode = adapterMode ? adapterMode.toLowerCase() : undefined; - if (typeof adapterMode === 'undefined' || adapterMode === BANNER) { - return BANNER; - } else if (adapterMode === VIDEO) { - return VIDEO; - } else if (adapterMode === 'all') { - return '*'; - } -}; - -function getResponseFormat(bid) { - const adm = bid.adm; - if (adm.indexOf('o2playerSettings') !== -1 || adm.indexOf('YAHOO.VideoPlatform.VideoPlayer') !== -1 || adm.indexOf('AdPlacement') !== -1) { - return BANNER; - } else if (adm.indexOf('VAST') !== -1) { - return VIDEO; - } -}; - -function getFloorModuleData(bid) { - const adapterMode = getAdapterMode(); - const getFloorRequestObject = { - currency: deepAccess(bid, 'params.bidOverride.cur') || DEFAULT_CURRENCY, - mediaType: adapterMode, - size: '*' - }; - return (isFn(bid.getFloor)) ? bid.getFloor(getFloorRequestObject) : false; -}; - -function filterBidRequestByMode(validBidRequests) { - const mediaTypesMode = getAdapterMode(); - let result = []; - if (mediaTypesMode === BANNER) { - result = validBidRequests.filter(bid => { - return Object.keys(bid.mediaTypes).some(item => item === BANNER); - }); - } else if (mediaTypesMode === VIDEO) { - result = validBidRequests.filter(bid => { - return Object.keys(bid.mediaTypes).some(item => item === VIDEO); - }); - } else if (mediaTypesMode === '*') { - result = validBidRequests.filter(bid => { - return Object.keys(bid.mediaTypes).some(item => item === BANNER || item === VIDEO); - }); - }; - return result; -}; - -function validateAppendObject(validationType, allowedKeys, inputObject, appendToObject) { - const outputObject = { - ...appendToObject - }; - - for (const objectKey in inputObject) { - switch (validationType) { - case 'string': - if (allowedKeys.indexOf(objectKey) !== -1 && isStr(inputObject[objectKey])) { - outputObject[objectKey] = inputObject[objectKey]; - }; - break; - case 'number': - if (allowedKeys.indexOf(objectKey) !== -1 && isNumber(inputObject[objectKey])) { - outputObject[objectKey] = inputObject[objectKey]; - }; - break; - - case 'array': - if (allowedKeys.indexOf(objectKey) !== -1 && isArray(inputObject[objectKey])) { - outputObject[objectKey] = inputObject[objectKey]; - }; - break; - case 'object': - if (allowedKeys.indexOf(objectKey) !== -1 && isPlainObject(inputObject[objectKey])) { - outputObject[objectKey] = inputObject[objectKey]; - }; - break; - case 'objectAllKeys': - if (isPlainObject(inputObject)) { - outputObject[objectKey] = inputObject[objectKey]; - }; - break; - }; - }; - return outputObject; -}; - -function getTtl(bidderRequest) { - const globalTTL = config.getConfig('yahoossp.ttl'); - return globalTTL ? validateTTL(globalTTL) : validateTTL(deepAccess(bidderRequest, 'params.ttl')); -}; - -function validateTTL(ttl) { - return (isNumber(ttl) && ttl > 0 && ttl < 3600) ? ttl : DEFAULT_BID_TTL -}; - -function isNotEmptyStr(value) { - return (isStr(value) && value.length > 0); -}; - -function generateOpenRtbObject(bidderRequest, bid) { - if (bidderRequest) { - let outBoundBidRequest = { - id: generateUUID(), - cur: [getFloorModuleData(bidderRequest).currency || deepAccess(bid, 'params.bidOverride.cur') || DEFAULT_CURRENCY], - imp: [], - site: { - page: deepAccess(bidderRequest, 'refererInfo.referer'), - }, - device: { - dnt: 0, - ua: navigator.userAgent, - ip: deepAccess(bid, 'params.bidOverride.device.ip') || deepAccess(bid, 'params.ext.ip') || undefined - }, - regs: { - ext: { - 'us_privacy': bidderRequest.uspConsent ? bidderRequest.uspConsent : '', - gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0 - } - }, - source: { - ext: { - hb: 1, - adapterver: ADAPTER_VERSION, - prebidver: PREBID_VERSION, - integration: { - name: INTEGRATION_METHOD, - ver: PREBID_VERSION - } - }, - fd: 1 - }, - user: { - ext: { - consent: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies - ? bidderRequest.gdprConsent.consentString : '', - eids: getSupportedEids(bid) - } - } - }; - - if (getPubIdMode(bid) === true) { - outBoundBidRequest.site.publisher = { - id: bid.params.pubId - } - if (deepAccess(bid, 'params.bidOverride.site.id') || deepAccess(bid, 'params.siteId')) { - outBoundBidRequest.site.id = deepAccess(bid, 'params.bidOverride.site.id') || bid.params.siteId; - } - } else { - outBoundBidRequest.site.id = bid.params.dcn; - }; - - if (config.getConfig('ortb2')) { - outBoundBidRequest = appendFirstPartyData(outBoundBidRequest, bid); - }; - - if (deepAccess(bid, 'schain')) { - outBoundBidRequest.source.ext.schain = bid.schain; - outBoundBidRequest.source.ext.schain.nodes[0].rid = outBoundBidRequest.id; - }; - - return outBoundBidRequest; - }; -}; - -function appendImpObject(bid, openRtbObject) { - const mediaTypeMode = getAdapterMode(); - - if (openRtbObject && bid) { - const impObject = { - id: bid.bidId, - secure: isSecure(bid), - bidfloor: getFloorModuleData(bid).floor || deepAccess(bid, 'params.bidOverride.imp.bidfloor') - }; - - if (bid.mediaTypes.banner && (typeof mediaTypeMode === 'undefined' || mediaTypeMode === BANNER || mediaTypeMode === '*')) { - impObject.banner = { - mimes: bid.mediaTypes.banner.mimes || ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: transformSizes(bid.sizes) - }; - if (bid.mediaTypes.banner.pos) { - impObject.banner.pos = bid.mediaTypes.banner.pos; - }; - }; - - if (bid.mediaTypes.video && (mediaTypeMode === VIDEO || mediaTypeMode === '*')) { - const playerSize = transformSizes(bid.mediaTypes.video.playerSize); - impObject.video = { - mimes: deepAccess(bid, 'params.bidOverride.imp.video.mimes') || bid.mediaTypes.video.mimes || ['video/mp4', 'application/javascript'], - w: deepAccess(bid, 'params.bidOverride.imp.video.w') || playerSize[0].w, - h: deepAccess(bid, 'params.bidOverride.imp.video.h') || playerSize[0].h, - maxbitrate: deepAccess(bid, 'params.bidOverride.imp.video.maxbitrate') || bid.mediaTypes.video.maxbitrate || undefined, - maxduration: deepAccess(bid, 'params.bidOverride.imp.video.maxduration') || bid.mediaTypes.video.maxduration || undefined, - minduration: deepAccess(bid, 'params.bidOverride.imp.video.minduration') || bid.mediaTypes.video.minduration || undefined, - api: deepAccess(bid, 'params.bidOverride.imp.video.api') || bid.mediaTypes.video.api || [2], - delivery: deepAccess(bid, 'params.bidOverride.imp.video.delivery') || bid.mediaTypes.video.delivery || undefined, - pos: deepAccess(bid, 'params.bidOverride.imp.video.pos') || bid.mediaTypes.video.pos || undefined, - playbackmethod: deepAccess(bid, 'params.bidOverride.imp.video.playbackmethod') || bid.mediaTypes.video.playbackmethod || undefined, - placement: deepAccess(bid, 'params.bidOverride.imp.video.placement') || bid.mediaTypes.video.placement || undefined, - linearity: deepAccess(bid, 'params.bidOverride.imp.video.linearity') || bid.mediaTypes.video.linearity || 1, - protocols: deepAccess(bid, 'params.bidOverride.imp.video.protocols') || bid.mediaTypes.video.protocols || [2, 5], - startdelay: deepAccess(bid, 'params.bidOverride.imp.video.startdelay') || bid.mediaTypes.video.startdelay || 0, - rewarded: deepAccess(bid, 'params.bidOverride.imp.video.rewarded') || undefined, - } - } - - impObject.ext = { - dfp_ad_unit_code: bid.adUnitCode - }; - - if (deepAccess(bid, 'params.kvp') && isPlainObject(bid.params.kvp)) { - impObject.ext.kvs = {}; - for (const key in bid.params.kvp) { - if (isStr(bid.params.kvp[key]) || isNumber(bid.params.kvp[key])) { - impObject.ext.kvs[key] = bid.params.kvp[key]; - } else if (isArray(bid.params.kvp[key])) { - const array = bid.params.kvp[key]; - if (array.every(value => isStr(value)) || array.every(value => isNumber(value))) { - impObject.ext.kvs[key] = bid.params.kvp[key]; - } - } - } - }; - - if (deepAccess(bid, 'ortb2Imp.ext.data') && isPlainObject(bid.ortb2Imp.ext.data)) { - impObject.ext.data = bid.ortb2Imp.ext.data; - }; - - if (deepAccess(bid, 'ortb2Imp.instl') && isNumber(bid.ortb2Imp.instl) && (bid.ortb2Imp.instl === 1)) { - impObject.instl = bid.ortb2Imp.instl; - }; - - if (getPubIdMode(bid) === false) { - impObject.tagid = bid.params.pos; - impObject.ext.pos = bid.params.pos; - } else if (deepAccess(bid, 'params.placementId')) { - impObject.tagid = bid.params.placementId - }; - - openRtbObject.imp.push(impObject); - }; -}; - -function appendFirstPartyData(outBoundBidRequest, bid) { - const ortb2Object = config.getConfig('ortb2'); - const siteObject = deepAccess(ortb2Object, 'site') || undefined; - const siteContentObject = deepAccess(siteObject, 'content') || undefined; - const siteContentDataArray = deepAccess(siteObject, 'content.data') || undefined; - const appContentObject = deepAccess(ortb2Object, 'app.content') || undefined; - const appContentDataArray = deepAccess(ortb2Object, 'app.content.data') || undefined; - const userObject = deepAccess(ortb2Object, 'user') || undefined; - - if (siteObject && isPlainObject(siteObject)) { - const allowedSiteStringKeys = ['name', 'domain', 'page', 'ref', 'keywords', 'search']; - const allowedSiteArrayKeys = ['cat', 'sectioncat', 'pagecat']; - const allowedSiteObjectKeys = ['ext']; - outBoundBidRequest.site = validateAppendObject('string', allowedSiteStringKeys, siteObject, outBoundBidRequest.site); - outBoundBidRequest.site = validateAppendObject('array', allowedSiteArrayKeys, siteObject, outBoundBidRequest.site); - outBoundBidRequest.site = validateAppendObject('object', allowedSiteObjectKeys, siteObject, outBoundBidRequest.site); - }; - - if (siteContentObject && isPlainObject(siteContentObject)) { - const allowedContentStringKeys = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language']; - const allowedContentNumberkeys = ['episode', 'prodq', 'context', 'livestream', 'len']; - const allowedContentArrayKeys = ['cat']; - const allowedContentObjectKeys = ['ext']; - outBoundBidRequest.site.content = validateAppendObject('string', allowedContentStringKeys, siteContentObject, outBoundBidRequest.site.content); - outBoundBidRequest.site.content = validateAppendObject('number', allowedContentNumberkeys, siteContentObject, outBoundBidRequest.site.content); - outBoundBidRequest.site.content = validateAppendObject('array', allowedContentArrayKeys, siteContentObject, outBoundBidRequest.site.content); - outBoundBidRequest.site.content = validateAppendObject('object', allowedContentObjectKeys, siteContentObject, outBoundBidRequest.site.content); - - if (siteContentDataArray && isArray(siteContentDataArray)) { - siteContentDataArray.every(dataObject => { - let newDataObject = {}; - const allowedContentDataStringKeys = ['id', 'name']; - const allowedContentDataArrayKeys = ['segment']; - const allowedContentDataObjectKeys = ['ext']; - newDataObject = validateAppendObject('string', allowedContentDataStringKeys, dataObject, newDataObject); - newDataObject = validateAppendObject('array', allowedContentDataArrayKeys, dataObject, newDataObject); - newDataObject = validateAppendObject('object', allowedContentDataObjectKeys, dataObject, newDataObject); - outBoundBidRequest.site.content.data = []; - outBoundBidRequest.site.content.data.push(newDataObject); - }) - }; - }; - - if (appContentObject && isPlainObject(appContentObject)) { - if (appContentDataArray && isArray(appContentDataArray)) { - appContentDataArray.every(dataObject => { - let newDataObject = {}; - const allowedContentDataStringKeys = ['id', 'name']; - const allowedContentDataArrayKeys = ['segment']; - const allowedContentDataObjectKeys = ['ext']; - newDataObject = validateAppendObject('string', allowedContentDataStringKeys, dataObject, newDataObject); - newDataObject = validateAppendObject('array', allowedContentDataArrayKeys, dataObject, newDataObject); - newDataObject = validateAppendObject('object', allowedContentDataObjectKeys, dataObject, newDataObject); - outBoundBidRequest.app = { - content: { - data: [] - } - }; - outBoundBidRequest.app.content.data.push(newDataObject); - }) - }; - }; - - if (userObject && isPlainObject(userObject)) { - const allowedUserStrings = ['id', 'buyeruid', 'gender', 'keywords', 'customdata']; - const allowedUserNumbers = ['yob']; - const allowedUserArrays = ['data']; - const allowedUserObjects = ['ext']; - outBoundBidRequest.user = validateAppendObject('string', allowedUserStrings, userObject, outBoundBidRequest.user); - outBoundBidRequest.user = validateAppendObject('number', allowedUserNumbers, userObject, outBoundBidRequest.user); - outBoundBidRequest.user = validateAppendObject('array', allowedUserArrays, userObject, outBoundBidRequest.user); - outBoundBidRequest.user.ext = validateAppendObject('object', allowedUserObjects, userObject, outBoundBidRequest.user.ext); - }; - - return outBoundBidRequest; -}; - -function generateServerRequest({payload, requestOptions, bidderRequest}) { - const pubIdMode = getPubIdMode(bidderRequest); - let sspEndpoint = config.getConfig('yahoossp.endpoint') || SSP_ENDPOINT_DCN_POS; - - if (pubIdMode === true) { - sspEndpoint = config.getConfig('yahoossp.endpoint') || SSP_ENDPOINT_PUBID; - }; - - if (deepAccess(bidderRequest, 'params.testing.e2etest') === true) { - logInfo('yahoossp adapter e2etest mode is active'); - requestOptions.withCredentials = false; - - if (pubIdMode === true) { - payload.site.id = TEST_MODE_PUBID_DCN; - } else { - const mediaTypeMode = getAdapterMode(); - payload.site.id = TEST_MODE_DCN; - payload.imp.forEach(impObject => { - impObject.ext.e2eTestMode = true; - if (mediaTypeMode === BANNER) { - impObject.tagid = TEST_MODE_BANNER_POS; // banner passback - } else if (mediaTypeMode === VIDEO) { - impObject.tagid = TEST_MODE_VIDEO_POS; // video passback - } else { - logWarn('yahoossp adapter e2etest mode does not support yahoossp.mode="all". \n Please specify either "banner" or "video"'); - logWarn('yahoossp adapter e2etest mode: Please make sure your adUnit matches the yahoossp.mode video or banner'); - } - }); - } - }; - logWarn('yahoossp adapter endpoint override enabled. Pointing requests to: ', sspEndpoint); - - return { - url: sspEndpoint, - method: 'POST', - data: payload, - options: requestOptions, - bidderRequest: bidderRequest - }; -}; - -function createRenderer(bidderRequest, bidResponse) { - const renderer = Renderer.install({ - url: 'https://cdn.vidible.tv/prod/hb-outstream-renderer/renderer.js', - loaded: false, - adUnitCode: bidderRequest.adUnitCode - }) - - try { - renderer.setRender(function(bidResponse) { - setTimeout(function() { - // eslint-disable-next-line no-undef - o2PlayerRender(bidResponse); - }, deepAccess(bidderRequest, 'params.testing.renderer.setTimeout') || DEFAULT_RENDERER_TIMEOUT); - }); - } catch (error) { - logWarn('yahoossp renderer error: setRender() failed', error); - } - return renderer; -} -/* Utility functions */ - -export const spec = { - code: BIDDER_CODE, - aliases: [], - supportedMediaTypes: [BANNER, VIDEO], - - isBidRequestValid: function(bid) { - const params = bid.params; - if (deepAccess(params, 'testing.e2etest') === true) { - return true; - } else if ( - isPlainObject(params) && - (isNotEmptyStr(params.pubId) || (isNotEmptyStr(params.dcn) && isNotEmptyStr(params.pos))) - ) { - return true; - } else { - logWarn('yahoossp bidder params missing or incorrect, please pass object with either: dcn & pos OR pubId'); - return false; - } - }, - - buildRequests: function(validBidRequests, bidderRequest) { - if (isEmpty(validBidRequests) || isEmpty(bidderRequest)) { - logWarn('yahoossp Adapter: buildRequests called with either empty "validBidRequests" or "bidderRequest"'); - return undefined; - }; - - const requestOptions = { - contentType: 'application/json', - customHeaders: { - 'x-openrtb-version': '2.5' - } - }; - - requestOptions.withCredentials = hasPurpose1Consent(bidderRequest); - - const filteredBidRequests = filterBidRequestByMode(validBidRequests); - - if (config.getConfig('yahoossp.singleRequestMode') === true) { - const payload = generateOpenRtbObject(bidderRequest, filteredBidRequests[0]); - filteredBidRequests.forEach(bid => { - appendImpObject(bid, payload); - }); - - return generateServerRequest({payload, requestOptions, bidderRequest}); - } - - return filteredBidRequests.map(bid => { - const payloadClone = generateOpenRtbObject(bidderRequest, bid); - appendImpObject(bid, payloadClone); - return generateServerRequest({payload: payloadClone, requestOptions, bidderRequest: bid}); - }); - }, - - interpretResponse: function(serverResponse, { data, bidderRequest }) { - const response = []; - if (!serverResponse.body || !Array.isArray(serverResponse.body.seatbid)) { - return response; - } - - let seatbids = serverResponse.body.seatbid; - seatbids.forEach(seatbid => { - let bid; - - try { - bid = seatbid.bid[0]; - } catch (e) { - return response; - } - - let cpm = (bid.ext && bid.ext.encp) ? bid.ext.encp : bid.price; - - let bidResponse = { - adId: deepAccess(bid, 'adId') ? bid.adId : bid.impid || bid.crid, - adUnitCode: bidderRequest.adUnitCode, - requestId: bid.impid, - bidderCode: spec.code, - cpm: cpm, - width: bid.w, - height: bid.h, - creativeId: bid.crid || 0, - currency: bid.cur || DEFAULT_CURRENCY, - dealId: bid.dealid ? bid.dealid : null, - netRevenue: true, - ttl: getTtl(bidderRequest), - meta: { - advertiserDomains: bid.adomain, - } - }; - - const responseAdmFormat = getResponseFormat(bid); - if (responseAdmFormat === BANNER) { - bidResponse.mediaType = BANNER; - bidResponse.ad = bid.adm; - bidResponse.meta.mediaType = BANNER; - } else if (responseAdmFormat === VIDEO) { - bidResponse.mediaType = VIDEO; - bidResponse.meta.mediaType = VIDEO; - bidResponse.vastXml = bid.adm; - - if (bid.nurl) { - bidResponse.vastUrl = bid.nurl; - }; - } - - if (deepAccess(bidderRequest, 'mediaTypes.video.context') === 'outstream' && !bidderRequest.renderer) { - bidResponse.renderer = createRenderer(bidderRequest, bidResponse) || undefined; - } - - response.push(bidResponse); - }); - - return response; - }, - - getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { - const bidResponse = !isEmpty(serverResponses) && serverResponses[0].body; - - if (bidResponse && bidResponse.ext && bidResponse.ext.pixels) { - return extractUserSyncUrls(syncOptions, bidResponse.ext.pixels); - } - - return []; - } -}; - -registerBidder(spec); diff --git a/modules/yahoosspBidAdapter.md b/modules/yahoosspBidAdapter.md deleted file mode 100644 index 7fb7a307192..00000000000 --- a/modules/yahoosspBidAdapter.md +++ /dev/null @@ -1,795 +0,0 @@ -# Overview -**Module Name:** yahoossp Bid Adapter -**Module Type:** Bidder Adapter -**Maintainer:** hb-fe-tech@yahooinc.com - -# Description -The Yahoo SSP Bid Adapter is an OpenRTB interface that consolidates all previous "Oath.inc" adapters such as: "aol", "oneMobile", "oneDisplay" & "oneVideo" supply-side platforms. - -# Supported Features: -* Media Types: Banner & Video -* Outstream renderer -* Multi-format adUnits -* Schain module -* Price floors module -* Advertiser domains -* End-2-End self-served testing mode -* Outstream renderer/Player -* User ID Modules - ConnectId and others -* First Party Data (ortb2 & ortb2Imp) -* Custom TTL (time to live) - - -# Adapter Request mode -Since the yahoossp adapter now supports both Banner and Video adUnits a controller was needed to allow you to define when the adapter should generate a bid-requests to our Yahoo SSP. - -**Important!** By default the adapter mode is set to "banner" only. -This means that you do not need to explicitly declare the yahoossp.mode in the Global config to initiate banner adUnit requests. - -## Request modes: -* **undefined** - (Default) Will generate bid-requests for "Banner" formats only. -* **banner** - Will generate bid-requests for "Banner" formats only (Explicit declaration). -* **video** - Will generate bid-requests for "Video" formats only (Explicit declaration). -* **all** - Will generate bid-requests for both "Banner" & "Video" formats - -**Important!** When setting yahoossp.mode = 'all' Make sure your Yahoo SSP Placement (pos id) supports both Banner & Video placements. -If it does not, the Yahoo SSP will respond only in the format it is set too. - -```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'banner' // 'all', 'video', 'banner' (default) - } -}); -``` -# Integration Options -The `yahoossp` bid adapter supports 2 types of integration: -1. **dcn & pos** DEFAULT (Site/App & Position targeting) - For Display partners/publishers. -2. **pubId** (Publisher ID) - For legacy "oneVideo" AND New partners/publishers. -**Important:** pubId integration (option 2) is only possible when your Seller account is setup for "Inventory Mapping". - -**Please Note:** Most examples in this file are using dcn & pos. - -## Who is currently eligible for "pubId" integration -At this time, only the following partners/publishers are eligble for pubId integration: -1. New partners/publishers that do not have any existing accounts on Yahoo SSP (aka: aol, oneMobile, oneDisplay). -2. Video SSP (oneVideo) partners/publishers that - A. Do not have any display/banner inventory. - B. Do not have any existing accounts on Yahoo SSP (aka: aol, oneMobile, oneDisplay). - -# Mandatory Bidder Parameters -## dcn & pos (DEFAULT) -The minimal requirements for the 'yahoossp' bid adapter to generate an outbound bid-request to our Yahoo SSP are: -1. At least 1 adUnit including mediaTypes: banner or video -2. **bidder.params** object must include: - A. **dcn:** Yahoo SSP Site/App inventory parameter. - B. **pos:** Yahoo SSP position inventory parameter. - -### Example: dcn & pos Mandatory Parameters (Single banner adUnit) -```javascript -const adUnits = [{ - code: 'your-placement', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [ - { - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from SSP - pos: '8a969978017a7aaabab4ab0bc01a0009' // Placement ID provided from SSP - } - } - ] -}]; -``` - -## pubId -The minimal requirements for the 'yahoossp' bid adapter to generate an outbound bid-request to our Yahoo SSP are: -1. At least 1 adUnit including mediaTypes: banner or video -2. **bidder.params** object must include: - A. **pubId:** Yahoo SSP Publisher ID (AKA oneVideo pubId/Exchange name) - -### Example: pubId Mandatory Parameters (Single banner adUnit) -```javascript -const adUnits = [{ - code: 'your-placement', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [ - { - bidder: 'yahoossp', - params: { - pubId: 'DemoPublisher', // Publisher External ID provided from Yahoo SSP. - } - } - ] -}]; -``` -# Advanced adUnit Examples: -## Banner -```javascript -const adUnits = [{ - code: 'banner-adUnit', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from Yahoo SSP - pos: '8a969978017a7aaabab4ab0bc01a0009', // Placement ID provided from Yahoo SSP - } - } - }] -}]; -``` -## Video Instream -**Important!** Make sure that the Yahoo SSP Placement type (in-stream) matches the adUnit video inventory type. -**Note:** Make sure to set the adapter mode to allow video requests by setting it to mode: 'video' OR mode: 'all'. -```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'video' - } -}); - -const adUnits = [{ - code: 'video-adUnit', - mediaTypes: { - video: { - context: 'instream', - playerSize: [ - [300, 250] - ], - mimes: ['video/mp4','application/javascript'], - api: [2] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from Yahoo SSP - pos: '8a96958a017a7a57ac375d50c0c700cc', // Placement ID provided from Yahoo SSP - } - }] -}]; -``` -## Video Outstream -**Important!** Make sure that the Yahoo SSP Placement type (in-feed/ in-article) matches the adUnit video inventory type. -**Note:** Make sure to set the adapter mode to allow video requests by setting it to mode: 'video' OR mode: 'all' -```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'video' - } -}); - -const adUnits = [{ - code: 'video-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - mimes: ['video/mp4','application/javascript'], - api: [2] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from Yahoo SSP - pos: '8a96958a017a7a57ac375d50c0c700cc', // Placement ID provided from Yahoo SSP - } - }] -}]; -``` -## Multi-Format -**Important!** If you intend to use the yahoossp bidder for both Banner and Video formats please make sure: -1. Set the adapter as mode: 'all' - to call the Yahoo SSP for both banner & video formats. -2. Make sure the Yahoo SSP placement (pos id) supports both banner & video format requests. - -```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'all' - } -}); - -const adUnits = [{ - code: 'video-adUnit', - mediaTypes: { - banner: { - sizes: [[300, 250]] - }, - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - mimes: ['video/mp4','application/javascript'], - api: [2] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from Yahoo SSP - pos: '8a96958a017a7a57ac375d50c0c700cc', // Placement ID provided from Yahoo SSP - } - }] -}]; -``` - -# Optional: Schain module support -The yahoossp adapter supports the Prebid.org Schain module and will pass it through to our Yahoo SSP -For further details please see, https://docs.prebid.org/dev-docs/modules/schain.html - -## Global Schain Example: -```javascript - pbjs.setConfig({ - "schain": { - "validation": "off", - "config": { - "ver": "1.0", - "complete": 1, - "nodes": [{ - "asi": "some-platform.com", - "sid": "111111", - "hp": 1 - }] - } - } - }); -``` -## Bidder Specific Schain Example: -```javascript - pbjs.setBidderConfig({ - "bidders": ['yahoossp'], // can list more bidders here if they share the same config - "config": { - "schain": { - "validation": "strict", - "config": { - "ver": "1.0", - "complete": 1, - "nodes": [{ - "asi": "other-platform.com", - "sid": "222222", - "hp": 0 - }] - } - } - } - }); -``` - -# Optional: Price floors module & bidfloor -The yahoossp adapter supports the Prebid.org Price Floors module and will use it to define the outbound bidfloor and currency. -By default the adapter will always check the existance of Module price floor. -If a module price floor does not exist you can set a custom bid floor for your impression using "params.bidOverride.imp.bidfloor". - -**Note:** All override params apply to all requests generated using this configuration regardless of format type. - -```javascript -const adUnits = [{ - code: 'override-pricefloor', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', // Site/App ID provided from Yahoo SSP - pos: '8a969978017a7aaabab4ab0bc01a0009', // Placement ID provided from Yahoo SSP - bidOverride :{ - imp: { - bidfloor: 5.00 // bidOverride priceFloor - } - } - } - } - }] -}]; -``` - -For further details please see, https://docs.prebid.org/dev-docs/modules/floors.html - -# Optional: Self-served E2E testing mode -If you want to see how the yahoossp adapter works and loads you are invited to try it out using our testing mode. -This is useful for integration testing and response parsing when checking banner vs video capabilities. - -## How to use E2E test mode: -1. Set the yahoossp global config mode to either 'banner' or 'video' - depending on the adUnit you want to test. -2. Add params.testing.e2etest: true to your adUnit bidder config - See examples below. - -**Note:** When using E2E Test Mode you do not need to pass mandatory bidder params dcn or pos. - -**Important!** E2E Testing Mode only works when the Bidder Request Mode is set explicitly to either 'banner' or 'video'. - -## Activating E2E Test for "Banner" - ```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'banner' // select 'banner' or 'video' to define what response to load - } -}); - -const adUnits = [{ - code: 'your-placement', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [ - { - bidder: 'yahoossp', - params: { - testing: { - e2etest: true // Activate E2E Test mode - } - } - } - ] -}]; - -``` -## Activating E2E Test for "Video" -**Note:** We recommend using Video Outstream as it would load the video response using our Outstream Renderer feature - ```javascript -pbjs.setConfig({ - yahoossp: { - mode: 'video' - } -}); - -const adUnits = [{ - code: 'video-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - mimes: ['video/mp4','application/javascript'], - api: [2] - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - testing: { - e2etest: true // Activate E2E Test mode - } - } - }] -}]; -``` - -# Optional: First Party Data -The yahoossp adapter now supports first party data passed via: -1. Global ortb2 object using pbjs.setConfig() -2. adUnit ortb2Imp object declared within an adUnit. -For further details please see, https://docs.prebid.org/features/firstPartyData.html -## Global First Party Data "ortb2" -### Passing First Party "site" data: -```javascript -pbjs.setConfig({ - ortb2: { - site: { - name: 'yahooAdTech', - domain: 'yahooadtech.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.yahooadtech.com/here.html', - ref: 'https://ref.yahooadtech.com/there.html', - keywords:'yahoo, ad, tech', - search: 'SSP', - content: { - id: '1234', - title: 'Title', - series: 'Series', - season: 'Season', - episode: 1, - cat: ['IAB1', 'IAB1-1', 'IAB1-2', 'IAB2', 'IAB2-1'], - genre: 'Fantase', - contentrating: 'C-Rating', - language: 'EN', - prodq: 1, - context: 1, - len: 200, - data: [{ - name: "www.dataprovider1.com", - ext: { segtax: 4 }, - segment: [ - { id: "687" }, - { id: "123" } - ] - }], - ext: { - network: 'ext-network', - channel: 'ext-channel', - data: { - pageType: "article", - category: "repair" - } - } - } - } - } - }); -``` -### Passing First Party "user" data: -```javascript -pbjs.setConfig({ - ortb2: { - user: { - yob: 1985, - gender: 'm', - keywords: 'a,b', - data: [{ - name: "www.dataprovider1.com", - ext: { segtax: 4 }, - segment: [ - { id: "687" }, - { id: "123" } - ] - }], - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - }); -``` -### Passing First Party "app.content.data" data: -```javascript -pbjs.setConfig({ - ortb2: { - app: { - content: { - data: [{ - name: "www.dataprovider1.com", - ext: { segtax: 4 }, - segment: [ - { id: "687" }, - { id: "123" } - ] - }], - } - } - } - }); -``` - - -## AdUnit First Party Data "ortb2Imp" -Most DSPs are adopting the Global Placement ID (GPID). -Please pass your placement specific GPID value to Yahoo SSP using `adUnit.ortb2Imp.ext.data.pbadslot`. -```javascript -const adUnits = [{ - code: 'placement', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - }, - }, - ortb2Imp: { - ext: { - data: { - pbadslot: "homepage-top-rect", - adUnitSpecificAttribute: "123" - } - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - pubdId: 'DemoPublisher' - } - }] - } - ] -``` - -# Optional: Bidder bidOverride Parameters -The yahoossp adapter allows passing override data to the outbound bid-request in that overrides First Party Data. -**Important!** We highly recommend using prebid modules to pass data instead of bidder speicifc overrides. -The use of these parameters are a last resort to force a specific feature or use case in your implementation. - -Currently the bidOverride object only accepts the following: -* imp - * video - * mimes - * w - * h - * maxbitrate - * maxduration - * minduration - * api - * delivery - * pos - * playbackmethod - * placement - * linearity - * protocols - * rewarded -* site - * page -* device - * ip - - -```javascript -const adUnits = [{ - code: 'bidOverride-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', - pos: '8a96958a017a7a57ac375d50c0c700cc', - bidOverride: { - imp: { - video: { - mimes: ['video/mp4', 'javascript/application'], - w: 300, - h: 200, - maxbitrate: 4000, - maxduration: 30, - minduration: 10, - api: [1,2], - delivery: 1, - pos: 1, - playbackmethod: 0, - placement: 1, - linearity: 1, - protocols: [2,5], - startdelay: 0, - rewarded: 0 - } - }, - site: { - page: 'https://yahoossp-bid-adapter.com', - }, - device: { - ip: "1.2.3.4" - } - } - } - }] -}] -``` - -# Optional: Custom Key-Value Pairs -Custom key-value paris can be used for both inventory targeting and reporting. -You must set up key-value pairs in the Yahoo SSP before sending them via the adapter otherwise the Ad Server will not be listening and picking them up. - -Important! Key-value pairs can only contain values of types: String, Number, Array of strings OR Array of numbers - -```javascript -const adUnits = [{ - code: 'key-value-pairs', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', - pos: '8a96958a017a7a57ac375d50c0c700cc', - kvp: { - key1: 'value', // String - key2: 123456, // Number - key3: ['string1','string2', 'string3'], // Array of strings - key4: [1, 23, 456, 7890] // Array of Numbers - } - } - }] -}] -``` - -# Optional: Custom Cache Time To Live (ttl): -The yahoossp adapter supports passing of "Time To Live" (ttl) that indicates to prebid chache for how long to keep the chaced winning bid alive. Value is Number in seconds and you can enter any number between 1 - 3600 (seconds). -The setting can be defined globally using setConfig or within the adUnit.params. -Global level setConfig overrides adUnit.params. -If no value is being passed default is 300 seconds. -## Global TTL -```javascript -pbjs.setConfig({ - yahoossp: { - ttl: 300 - } -}); - -const adUnits = [{ - code: 'global-ttl', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', - pos: '8a96958a017a7a57ac375d50c0c700cc', - } - }] -}] -``` - -## Ad Unit Params TTL -```javascript -const adUnits = [{ - code: 'adUnit-ttl', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', - pos: '8a96958a017a7a57ac375d50c0c700cc', - ttl: 300, - } - }] -}] -``` -# Optional: Video Features -## Rewarded video flag -To indicate to Yahoo SSP that this adUnit is a rewarded video you can pass the following in the params.bidOverride.imp.video.rewarded: 1 - -```javascript -const adUnits = [{ - code: 'rewarded-video-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - dcn: '8a969516017a7a396ec539d97f540011', - pos: '8a96958a017a7a57ac375d50c0c700cc', - bidOverride: { - imp: { - video: { - rewarded: 1 - } - } - } - } - }] -}] -``` - -## Site/App Targeting for "pubId" Inventory Mapping -To target your adUnit explicitly to a specific Site/App Object in Yahoo SSP, you can pass one of the following: -1. params.siteId = External Site ID || Video SSP RTBIS Id (in String format). -2. params.bidOverride.site.id = External Site ID || Video SSP RTBIS Id (in String format). -**Important:** Site override is a only supported when using "pubId" mode. -**Important:** If you are switching from the oneVideo adapter, please make sure to pass inventoryid as a String instead of Integer. - -```javascript -const adUnits = [{ - code: 'pubId-site-targeting-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - pubId: 'DemoPublisher', - siteId: '1234567'; - } - }] -}] -``` - -## Placement Targeting for "pubId" Inventory Mapping -To target your adUnit explicitly to a specific Placement within a Site/App Object in Yahoo SSP, you can pass the following params.placementId = External Placement ID || Placement Alias - -**Important!** Placement override is a only supported when using "pubId" mode. -**Important!** It is highly recommended that you pass both `siteId` AND `placementId` together to avoid inventory miss matching. - -### Site & Placement override -**Important!** If the placement ID does not reside under the defined Site/App object, the request will not resolve and no response will be sent back from the ad-server. -```javascript -const adUnits = [{ - code: 'pubId-site-targeting-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - pubId: 'DemoPublisher', - siteId: '1234567', - placementId: 'header-250x300' - } - }] -}] -``` -### Placement only override -**Important!** Using this method is not advised if you have multiple Site/Apps that are broken out of a Run Of Network (RON) Site/App. If the placement ID does not reside under a matching Site/App object, the request will not resolve and no response will be sent back from the ad-server. -```javascript -const adUnits = [{ - code: 'pubId-site-targeting-adUnit', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [300, 250] - ], - } - }, - bids: [{ - bidder: 'yahoossp', - params: { - pubId: 'DemoPublisher', - placementId: 'header-250x300' - } - }] -}] -``` - -# Optional: Legacy override Parameters -This adapter does not support passing legacy overrides via 'bidder.params.ext' since most of the data should be passed using prebid modules (First Party Data, Schain, Price Floors etc.). -If you do not know how to pass a custom parameter that you previously used, please contact us using the information provided above. - -Thanks you, -Yahoo SSP - diff --git a/modules/yieldlabBidAdapter.js b/modules/yieldlabBidAdapter.js index c2f2b79a3b7..c05ecbc15fc 100644 --- a/modules/yieldlabBidAdapter.js +++ b/modules/yieldlabBidAdapter.js @@ -1,9 +1,8 @@ -import { _each, isPlainObject, isArray, deepAccess } from '../src/utils.js'; +import * as utils from '../src/utils.js' import { registerBidder } from '../src/adapters/bidderFactory.js' import find from 'core-js-pure/features/array/find.js' -import { VIDEO, BANNER, NATIVE } from '../src/mediaTypes.js' +import { VIDEO, BANNER } from '../src/mediaTypes.js' import { Renderer } from '../src/Renderer.js' -import { config } from '../src/config.js'; const ENDPOINT = 'https://ad.yieldlab.net' const BIDDER_CODE = 'yieldlab' @@ -15,7 +14,7 @@ const GVLID = 70 export const spec = { code: BIDDER_CODE, gvlid: GVLID, - supportedMediaTypes: [VIDEO, BANNER, NATIVE], + supportedMediaTypes: [VIDEO, BANNER], isBidRequestValid: function (bid) { if (bid && bid.params && bid.params.adslotId && bid.params.supplyId) { @@ -37,7 +36,7 @@ export const spec = { json: true } - _each(validBidRequests, function (bid) { + utils._each(validBidRequests, function (bid) { adslotIds.push(bid.params.adslotId) if (bid.params.targeting) { query.t = createTargetingString(bid.params.targeting) @@ -45,19 +44,14 @@ export const spec = { if (bid.userIdAsEids && Array.isArray(bid.userIdAsEids)) { query.ids = createUserIdString(bid.userIdAsEids) } - if (bid.params.customParams && isPlainObject(bid.params.customParams)) { + if (bid.params.customParams && utils.isPlainObject(bid.params.customParams)) { for (let prop in bid.params.customParams) { query[prop] = bid.params.customParams[prop] } } - if (bid.schain && isPlainObject(bid.schain) && Array.isArray(bid.schain.nodes)) { + if (bid.schain && utils.isPlainObject(bid.schain) && Array.isArray(bid.schain.nodes)) { query.schain = createSchainString(bid.schain) } - - const iabContent = getContentObject(bid) - if (iabContent) { - query.iab_content = createIabContentString(iabContent) - } }) if (bidderRequest) { @@ -104,14 +98,13 @@ export const spec = { }) if (matchedBid) { - const adUnitSize = bidRequest.sizes.length === 2 && !isArray(bidRequest.sizes[0]) ? bidRequest.sizes : bidRequest.sizes[0] + const adUnitSize = bidRequest.sizes.length === 2 && !utils.isArray(bidRequest.sizes[0]) ? bidRequest.sizes : bidRequest.sizes[0] const adSize = bidRequest.params.adSize !== undefined ? parseSize(bidRequest.params.adSize) : (matchedBid.adsize !== undefined) ? parseSize(matchedBid.adsize) : adUnitSize const extId = bidRequest.params.extId !== undefined ? '&id=' + bidRequest.params.extId : '' const adType = matchedBid.adtype !== undefined ? matchedBid.adtype : '' const gdprApplies = reqParams.gdpr ? '&gdpr=' + reqParams.gdpr : '' const gdprConsent = reqParams.consent ? '&consent=' + reqParams.consent : '' const pvId = matchedBid.pvid !== undefined ? '&pvid=' + matchedBid.pvid : '' - const iabContent = reqParams.iab_content ? '&iab_content=' + reqParams.iab_content : '' const bidResponse = { requestId: bidRequest.bidId, @@ -124,7 +117,7 @@ export const spec = { netRevenue: false, ttl: BID_RESPONSE_TTL_SEC, referrer: '', - ad: ``, + ad: ``, meta: { advertiserDomains: (matchedBid.advertiser) ? matchedBid.advertiser : 'n/a' } @@ -137,7 +130,7 @@ export const spec = { bidResponse.height = playersize[1] } bidResponse.mediaType = VIDEO - bidResponse.vastUrl = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}${iabContent}` + bidResponse.vastUrl = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}` if (isOutstream(bidRequest)) { const renderer = Renderer.install({ id: bidRequest.bidId, @@ -149,27 +142,6 @@ export const spec = { } } - if (isNative(bidRequest, adType)) { - const url = `${ENDPOINT}/d/${matchedBid.id}/${bidRequest.params.supplyId}/?ts=${timestamp}${extId}${gdprApplies}${gdprConsent}${pvId}` - bidResponse.adUrl = url - bidResponse.mediaType = NATIVE - const nativeImageAssetObj = find(matchedBid.native.assets, e => e.id === 2) - const nativeImageAsset = nativeImageAssetObj ? nativeImageAssetObj.img : {url: '', w: 0, h: 0}; - const nativeTitleAsset = find(matchedBid.native.assets, e => e.id === 1) - const nativeBodyAsset = find(matchedBid.native.assets, e => e.id === 3) - bidResponse.native = { - title: nativeTitleAsset ? nativeTitleAsset.title.text : '', - body: nativeBodyAsset ? nativeBodyAsset.data.value : '', - image: { - url: nativeImageAsset.url, - width: nativeImageAsset.w, - height: nativeImageAsset.h, - }, - clickUrl: matchedBid.native.link.url, - impressionTrackers: matchedBid.native.imptrackers, - }; - } - bidResponses.push(bidResponse) } }) @@ -183,18 +155,8 @@ export const spec = { * @param {String} adtype * @returns {Boolean} */ -function isVideo(format, adtype) { - return deepAccess(format, 'mediaTypes.video') && adtype.toLowerCase() === 'video' -} - -/** - * Is this a native format? - * @param {Object} format - * @param {String} adtype - * @returns {Boolean} - */ -function isNative(format, adtype) { - return deepAccess(format, 'mediaTypes.native') && adtype.toLowerCase() === 'native' +function isVideo (format, adtype) { + return utils.deepAccess(format, 'mediaTypes.video') && adtype.toLowerCase() === 'video' } /** @@ -202,8 +164,8 @@ function isNative(format, adtype) { * @param {Object} format * @returns {Boolean} */ -function isOutstream(format) { - let context = deepAccess(format, 'mediaTypes.video.context') +function isOutstream (format) { + let context = utils.deepAccess(format, 'mediaTypes.video.context') return (context === 'outstream') } @@ -212,9 +174,9 @@ function isOutstream(format) { * @param {Object} format * @returns {Array} */ -function getPlayerSize(format) { - let playerSize = deepAccess(format, 'mediaTypes.video.playerSize') - return (playerSize && isArray(playerSize[0])) ? playerSize[0] : playerSize +function getPlayerSize (format) { + let playerSize = utils.deepAccess(format, 'mediaTypes.video.playerSize') + return (playerSize && utils.isArray(playerSize[0])) ? playerSize[0] : playerSize } /** @@ -222,7 +184,7 @@ function getPlayerSize(format) { * @param {String} size * @returns {Array} */ -function parseSize(size) { +function parseSize (size) { return size.split('x').map(Number) } @@ -231,7 +193,7 @@ function parseSize(size) { * @param {Array} eids * @returns {String} */ -function createUserIdString(eids) { +function createUserIdString (eids) { let str = [] for (let i = 0; i < eids.length; i++) { str.push(eids[i].source + ':' + eids[i].uids[0].id) @@ -244,12 +206,12 @@ function createUserIdString(eids) { * @param {Object} obj * @returns {String} */ -function createQueryString(obj) { +function createQueryString (obj) { let str = [] for (var p in obj) { if (obj.hasOwnProperty(p)) { let val = obj[p] - if (p !== 'schain' && p !== 'iab_content') { + if (p !== 'schain') { str.push(encodeURIComponent(p) + '=' + encodeURIComponent(val)) } else { str.push(p + '=' + val) @@ -264,7 +226,7 @@ function createQueryString(obj) { * @param {Object} obj * @returns {String} */ -function createTargetingString(obj) { +function createTargetingString (obj) { let str = [] for (var p in obj) { if (obj.hasOwnProperty(p)) { @@ -281,7 +243,7 @@ function createTargetingString(obj) { * @param {Object} schain * @returns {String} */ -function createSchainString(schain) { +function createSchainString (schain) { const ver = schain.ver || '' const complete = (schain.complete === 1 || schain.complete === 0) ? schain.complete : '' const keys = ['asi', 'sid', 'hp', 'rid', 'name', 'domain', 'ext'] @@ -291,44 +253,6 @@ function createSchainString(schain) { return `${ver},${complete}${nodesString}` } -/** - * Get content object from bid request - * First get content from bidder params; - * If not provided in bidder params, get from first party data under 'ortb2.site.content' or 'ortb2.app.content' - * @param {Object} bid - * @returns {Object} - */ -function getContentObject(bid) { - if (bid.params.iabContent && isPlainObject(bid.params.iabContent)) { - return bid.params.iabContent - } - - const globalContent = config.getConfig('ortb2.site') ? config.getConfig('ortb2.site.content') - : config.getConfig('ortb2.app.content') - if (globalContent && isPlainObject(globalContent)) { - return globalContent - } - return undefined -} - -/** - * Creates a string for iab_content object - * @param {Object} iabContent - * @returns {String} - */ -function createIabContentString(iabContent) { - const arrKeys = ['keywords', 'cat'] - let str = [] - for (let key in iabContent) { - if (iabContent.hasOwnProperty(key)) { - const value = (arrKeys.indexOf(key) !== -1 && Array.isArray(iabContent[key])) - ? iabContent[key].map(node => encodeURIComponent(node)).join('|') : encodeURIComponent(iabContent[key]) - str.push(''.concat(key, ':', value)) - } - } - return encodeURIComponent(str.join(',')) -} - /** * Encodes URI Component with exlamation mark included. Needed for schain object. * @param {String} str diff --git a/modules/yieldlabBidAdapter.md b/modules/yieldlabBidAdapter.md index 1f52e26f5c7..a7a3f2715dc 100644 --- a/modules/yieldlabBidAdapter.md +++ b/modules/yieldlabBidAdapter.md @@ -11,96 +11,38 @@ Maintainer: solutions@yieldlab.de Module that connects to Yieldlab's demand sources # Test Parameters - -```javascript -const adUnits = [ - { - code: 'banner', - sizes: [ [ 728, 90 ] ], - bids: [{ - bidder: 'yieldlab', - params: { - adslotId: '5220336', - supplyId: '1381604', - targeting: { - key1: 'value1', - key2: 'value2' - }, - extId: 'abc', - iabContent: { - id: 'some_id', - episode: '1', - title: 'some title', - series: 'some series', - season: 's1', - artist: 'John Doe', - genre: 'some genre', - isrc: 'CC-XXX-YY-NNNNN', - url: 'http://foo_url.de', - cat: [ 'IAB1-1', 'IAB1-2', 'IAB2-10' ], - context: '7', - keywords: ['k1', 'k2'], - live: '0' - } - } - }] - }, - { - code: 'video', - sizes: [ [ 640, 480 ] ], - mediaTypes: { - video: { - context: 'instream' // or 'outstream' - } - }, - bids: [{ - bidder: 'yieldlab', - params: { - adslotId: '5220339', - supplyId: '1381604' - } - }] - }, - { - code: 'native', - mediaTypes: { - native: { - // native config - } - }, - bids: [{ - bidder: 'yieldlab', - params: { - adslotId: '5220339', - supplyId: '1381604' - } - }] - } -]; ``` - -# Multi-Format Setup - -A general overview of how to set up multi-format ads can be found in the offical Prebid.js docs. See: [show multi-format ads](https://docs.prebid.org/dev-docs/show-multi-format-ads.html) - -When setting up multi-format ads with Yieldlab make sure to always add at least one eligible Adslot per given media type in the ad unit configuration. - -```javascript -const adUnit = { - code: 'multi-format-adslot', - mediaTypes: { - banner: { - sizes: [ [ 728, 90 ] ] - }, - native: { - // native config - } - }, - bids: [ - // banner Adslot - { bidder: 'yieldlab', params: { adslotId: '1234', supplyId: '42' } }, - // native Adslot - { bidder: 'yieldlab', params: { adslotId: '2345', supplyId: '42' } } - ] -}; + var adUnits = [ + { + code: "banner", + sizes: [[728, 90]], + bids: [{ + bidder: "yieldlab", + params: { + adslotId: "5220336", + supplyId: "1381604", + targeting: { + key1: "value1", + key2: "value2" + }, + extId: "abc" + } + }] + }, { + code: "video", + sizes: [[640, 480]], + mediaTypes: { + video: { + context: "instream" // or "outstream" + } + }, + bids: [{ + bidder: "yieldlab", + params: { + adslotId: "5220339", + supplyId: "1381604" + } + }] + } + ]; ``` diff --git a/modules/yieldliftBidAdapter.js b/modules/yieldliftBidAdapter.js index 61b99d95605..9398e2c7816 100644 --- a/modules/yieldliftBidAdapter.js +++ b/modules/yieldliftBidAdapter.js @@ -1,5 +1,5 @@ -import { deepSetValue, logInfo, deepAccess } from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; import {BANNER} from '../src/mediaTypes.js'; const ENDPOINT_URL = 'https://x.yieldlift.com/auction'; @@ -58,18 +58,18 @@ export const spec = { // adding schain object if (validBidRequests[0].schain) { - deepSetValue(openrtbRequest, 'source.ext.schain', validBidRequests[0].schain); + utils.deepSetValue(openrtbRequest, 'source.ext.schain', validBidRequests[0].schain); } // Attaching GDPR Consent Params if (bidderRequest.gdprConsent) { - deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(openrtbRequest, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(openrtbRequest, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest.uspConsent) { - deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(openrtbRequest, 'regs.ext.us_privacy', bidderRequest.uspConsent); } const payloadString = JSON.stringify(openrtbRequest); @@ -102,12 +102,12 @@ export const spec = { }) }) } else { - logInfo('yieldlift.interpretResponse :: no valid responses to interpret'); + utils.logInfo('yieldlift.interpretResponse :: no valid responses to interpret'); } return bidResponses; }, getUserSyncs: function (syncOptions, serverResponses) { - logInfo('yieldlift.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses); + utils.logInfo('yieldlift.getUserSyncs', 'syncOptions', syncOptions, 'serverResponses', serverResponses); let syncs = []; if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { @@ -115,7 +115,7 @@ export const spec = { } serverResponses.forEach(resp => { - const userSync = deepAccess(resp, 'body.ext.usersync'); + const userSync = utils.deepAccess(resp, 'body.ext.usersync'); if (userSync) { let syncDetails = []; Object.keys(userSync).forEach(key => { @@ -139,7 +139,7 @@ export const spec = { } } }); - logInfo('yieldlift.getUserSyncs result=%o', syncs); + utils.logInfo('yieldlift.getUserSyncs result=%o', syncs); return syncs; }, diff --git a/modules/yieldmoBidAdapter.js b/modules/yieldmoBidAdapter.js index 6642d1e9b83..654e7236210 100644 --- a/modules/yieldmoBidAdapter.js +++ b/modules/yieldmoBidAdapter.js @@ -1,10 +1,9 @@ -import { isNumber, isStr, isInteger, isBoolean, isArray, isEmpty, isArrayOfNums, getWindowTop, parseQueryStringParameters, parseUrl, deepSetValue, deepAccess, logError } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; import includes from 'core-js-pure/features/array/includes'; import find from 'core-js-pure/features/array/find.js'; -import { createEidsArray } from './userId/eids.js'; const BIDDER_CODE = 'yieldmo'; const CURRENCY = 'USD'; @@ -16,7 +15,7 @@ const OUTSTREAM_VIDEO_PLAYER_URL = 'https://prebid-outstream.yieldmo.com/bundle. const OPENRTB_VIDEO_BIDPARAMS = ['mimes', 'startdelay', 'placement', 'startdelay', 'skipafter', 'protocols', 'api', 'playbackmethod', 'maxduration', 'minduration', 'pos', 'skip', 'skippable']; const OPENRTB_VIDEO_SITEPARAMS = ['name', 'domain', 'cat', 'keywords']; -const LOCAL_WINDOW = getWindowTop(); +const LOCAL_WINDOW = utils.getWindowTop(); const DEFAULT_PLAYBACK_METHOD = 2; const DEFAULT_START_DELAY = 0; const VAST_TIMEOUT = 15000; @@ -47,32 +46,29 @@ export const spec = { buildRequests: function (bidRequests, bidderRequest) { const bannerBidRequests = bidRequests.filter(request => hasBannerMediaType(request)); const videoBidRequests = bidRequests.filter(request => hasVideoMediaType(request)); + let serverRequests = []; - const eids = getEids(bidRequests[0]) || []; if (bannerBidRequests.length > 0) { let serverRequest = { pbav: '$prebid.version$', p: [], page_url: bidderRequest.refererInfo.referer, bust: new Date().getTime().toString(), + pr: (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || '', + scrd: LOCAL_WINDOW.devicePixelRatio || 0, dnt: getDNT(), description: getPageDescription(), + title: LOCAL_WINDOW.document.title || '', + w: LOCAL_WINDOW.innerWidth, + h: LOCAL_WINDOW.innerHeight, userConsent: JSON.stringify({ // case of undefined, stringify will remove param - gdprApplies: deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || '', - cmp: deepAccess(bidderRequest, 'gdprConsent.consentString') || '' + gdprApplies: utils.deepAccess(bidderRequest, 'gdprConsent.gdprApplies') || '', + cmp: utils.deepAccess(bidderRequest, 'gdprConsent.consentString') || '' }), - us_privacy: deepAccess(bidderRequest, 'uspConsent') || '' + us_privacy: utils.deepAccess(bidderRequest, 'uspConsent') || '' }; - if (canAccessTopWindow()) { - serverRequest.pr = (LOCAL_WINDOW.document && LOCAL_WINDOW.document.referrer) || ''; - serverRequest.scrd = LOCAL_WINDOW.devicePixelRatio || 0; - serverRequest.title = LOCAL_WINDOW.document.title || ''; - serverRequest.w = LOCAL_WINDOW.innerWidth; - serverRequest.h = LOCAL_WINDOW.innerHeight; - } - const mtp = window.navigator.maxTouchPoints; if (mtp) { serverRequest.mtp = mtp; @@ -97,17 +93,14 @@ export const spec = { if (request.schain) { serverRequest.schain = JSON.stringify(request.schain); } - if (deepAccess(request, 'params.lr_env')) { + if (utils.deepAccess(request, 'params.lr_env')) { serverRequest.ats_envelope = request.params.lr_env; } }); serverRequest.p = '[' + serverRequest.p.toString() + ']'; - if (eids.length) { - serverRequest.eids = JSON.stringify(eids); - }; // check if url exceeded max length - const url = `${BANNER_SERVER_ENDPOINT}?${parseQueryStringParameters(serverRequest)}`; + const url = `${BANNER_SERVER_ENDPOINT}?${utils.parseQueryStringParameters(serverRequest)}`; let extraCharacters = url.length - MAX_BANNER_REQUEST_URL_LENGTH; if (extraCharacters > 0) { for (let i = 0; i < BANNER_REQUEST_PROPERTIES_TO_REDUCE.length; i++) { @@ -128,9 +121,6 @@ export const spec = { if (videoBidRequests.length > 0) { const serverRequest = openRtbRequest(videoBidRequests, bidderRequest); - if (eids.length) { - serverRequest.user = { eids }; - }; serverRequests.push({ method: 'POST', url: VIDEO_SERVER_ENDPOINT, @@ -177,14 +167,14 @@ registerBidder(spec); * @param {BidRequest} bidRequest bid request */ function hasBannerMediaType(bidRequest) { - return !!deepAccess(bidRequest, 'mediaTypes.banner'); + return !!utils.deepAccess(bidRequest, 'mediaTypes.banner'); } /** * @param {BidRequest} bidRequest bid request */ function hasVideoMediaType(bidRequest) { - return !!deepAccess(bidRequest, 'mediaTypes.video'); + return !!utils.deepAccess(bidRequest, 'mediaTypes.video'); } /** @@ -192,7 +182,6 @@ function hasVideoMediaType(bidRequest) { * @param request bid request */ function addPlacement(request) { - const gpid = deepAccess(request, 'ortb2Imp.ext.data.pbadslot'); const placementInfo = { placement_id: request.adUnitCode, callback_id: request.bidId, @@ -207,9 +196,6 @@ function addPlacement(request) { placementInfo.bidFloor = bidfloor; } } - if (gpid) { - placementInfo.gpid = gpid; - } return JSON.stringify(placementInfo); } @@ -241,7 +227,7 @@ function createNewBannerBid(response) { * @param bidRequest server request */ function createNewVideoBid(response, bidRequest) { - const imp = find((deepAccess(bidRequest, 'data.imp') || []), imp => imp.id === response.impid); + const imp = find((utils.deepAccess(bidRequest, 'data.imp') || []), imp => imp.id === response.impid); let result = { requestId: imp.id, @@ -320,7 +306,7 @@ function getPageDescription() { * @returns an id if there is one, or undefined */ function getId(request, idType) { - return (typeof deepAccess(request, 'userId') === 'object') ? request.userId[idType] : undefined; + return (typeof utils.deepAccess(request, 'userId') === 'object') ? request.userId[idType] : undefined; } /** @@ -329,13 +315,12 @@ function getId(request, idType) { * @return Object OpenRTB request object */ function openRtbRequest(bidRequests, bidderRequest) { - const schain = bidRequests[0].schain; let openRtbRequest = { id: bidRequests[0].bidderRequestId, at: 1, imp: bidRequests.map(bidRequest => openRtbImpression(bidRequest)), site: openRtbSite(bidRequests[0], bidderRequest), - device: openRtbDevice(bidRequests[0]), + device: openRtbDevice(), badv: bidRequests[0].params.badv || [], bcat: bidRequests[0].params.bcat || [], ext: { @@ -344,10 +329,6 @@ function openRtbRequest(bidRequests, bidderRequest) { ats_envelope: bidRequests[0].params.lr_env, }; - if (schain) { - openRtbRequest.schain = schain; - } - populateOpenRtbGdpr(openRtbRequest, bidderRequest); return openRtbRequest; @@ -358,7 +339,6 @@ function openRtbRequest(bidRequests, bidderRequest) { * @return Object OpenRTB's 'imp' (impression) object */ function openRtbImpression(bidRequest) { - const gpid = deepAccess(bidRequest, 'ortb2Imp.ext.data.pbadslot'); const size = extractPlayerSize(bidRequest); const imp = { id: bidRequest.bidId, @@ -374,12 +354,12 @@ function openRtbImpression(bidRequest) { } }; - const mediaTypesParams = deepAccess(bidRequest, 'mediaTypes.video'); + const mediaTypesParams = utils.deepAccess(bidRequest, 'mediaTypes.video'); Object.keys(mediaTypesParams) .filter(param => includes(OPENRTB_VIDEO_BIDPARAMS, param)) .forEach(param => imp.video[param] = mediaTypesParams[param]); - const videoParams = deepAccess(bidRequest, 'params.video'); + const videoParams = utils.deepAccess(bidRequest, 'params.video'); Object.keys(videoParams) .filter(param => includes(OPENRTB_VIDEO_BIDPARAMS, param)) .forEach(param => imp.video[param] = videoParams[param]); @@ -392,9 +372,6 @@ function openRtbImpression(bidRequest) { imp.video.startdelay = DEFAULT_START_DELAY; imp.video.playbackmethod = [ DEFAULT_PLAYBACK_METHOD ]; } - if (gpid) { - imp.ext.gpid = gpid; - } return imp; } @@ -413,10 +390,10 @@ function getBidFloor(bidRequest, mediaType) { * @return [number, number] || null Player's width and height, or undefined otherwise. */ function extractPlayerSize(bidRequest) { - const sizeArr = deepAccess(bidRequest, 'mediaTypes.video.playerSize'); - if (isArrayOfNums(sizeArr, 2)) { + const sizeArr = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize'); + if (utils.isArrayOfNums(sizeArr, 2)) { return sizeArr; - } else if (isArray(sizeArr) && isArrayOfNums(sizeArr[0], 2)) { + } else if (utils.isArray(sizeArr) && utils.isArrayOfNums(sizeArr[0], 2)) { return sizeArr[0]; } return null; @@ -430,8 +407,8 @@ function extractPlayerSize(bidRequest) { function openRtbSite(bidRequest, bidderRequest) { let result = {}; - const loc = parseUrl(deepAccess(bidderRequest, 'refererInfo.referer')); - if (!isEmpty(loc)) { + const loc = utils.parseUrl(utils.deepAccess(bidderRequest, 'refererInfo.referer')); + if (!utils.isEmpty(loc)) { result.page = `${loc.protocol}://${loc.hostname}${loc.pathname}`; } @@ -444,7 +421,7 @@ function openRtbSite(bidRequest, bidderRequest) { result.keywords = keywords.content; } - const siteParams = deepAccess(bidRequest, 'params.site'); + const siteParams = utils.deepAccess(bidRequest, 'params.site'); if (siteParams) { Object.keys(siteParams) .filter(param => includes(OPENRTB_VIDEO_SITEPARAMS, param)) @@ -456,12 +433,11 @@ function openRtbSite(bidRequest, bidderRequest) { /** * @return Object OpenRTB's 'device' object */ -function openRtbDevice(bidRequest) { - const deviceObj = { +function openRtbDevice() { + return { ua: navigator.userAgent, language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), }; - return deviceObj; } /** @@ -472,12 +448,12 @@ function openRtbDevice(bidRequest) { function populateOpenRtbGdpr(openRtbRequest, bidderRequest) { const gdpr = bidderRequest.gdprConsent; if (gdpr && 'gdprApplies' in gdpr) { - deepSetValue(openRtbRequest, 'regs.ext.gdpr', gdpr.gdprApplies ? 1 : 0); - deepSetValue(openRtbRequest, 'user.ext.consent', gdpr.consentString); + utils.deepSetValue(openRtbRequest, 'regs.ext.gdpr', gdpr.gdprApplies ? 1 : 0); + utils.deepSetValue(openRtbRequest, 'user.ext.consent', gdpr.consentString); } - const uspConsent = deepAccess(bidderRequest, 'uspConsent'); + const uspConsent = utils.deepAccess(bidderRequest, 'uspConsent'); if (uspConsent) { - deepSetValue(openRtbRequest, 'regs.ext.us_privacy', uspConsent); + utils.deepSetValue(openRtbRequest, 'regs.ext.us_privacy', uspConsent); } } @@ -510,8 +486,8 @@ function validateVideoParams(bid) { if (fieldPath.indexOf('video') === 0) { const valueFieldPath = 'params.' + fieldPath; const mediaFieldPath = 'mediaTypes.' + fieldPath; - const valueParams = deepAccess(bid, valueFieldPath); - const mediaTypesParams = deepAccess(bid, mediaFieldPath); + const valueParams = utils.deepAccess(bid, valueFieldPath); + const mediaTypesParams = utils.deepAccess(bid, mediaFieldPath); const hasValidValueParams = validateCb(valueParams); const hasValidMediaTypesParams = validateCb(mediaTypesParams); @@ -523,7 +499,7 @@ function validateVideoParams(bid) { } return valueParams || mediaTypesParams; } else { - const value = deepAccess(bid, fieldPath); + const value = utils.deepAccess(bid, fieldPath); if (!validateCb(value)) { errorCb(fieldPath, value, errorCbParam); } @@ -532,16 +508,16 @@ function validateVideoParams(bid) { } try { - validate('video.context', val => !isEmpty(val), paramRequired); + validate('video.context', val => !utils.isEmpty(val), paramRequired); - validate('params.placementId', val => !isEmpty(val), paramRequired); + validate('params.placementId', val => !utils.isEmpty(val), paramRequired); - validate('video.playerSize', val => isArrayOfNums(val, 2) || - (isArray(val) && val.every(v => isArrayOfNums(v, 2))), + validate('video.playerSize', val => utils.isArrayOfNums(val, 2) || + (utils.isArray(val) && val.every(v => utils.isArrayOfNums(v, 2))), paramInvalid, 'array of 2 integers, ex: [640,480] or [[640,480]]'); validate('video.mimes', val => isDefined(val), paramRequired); - validate('video.mimes', val => isArray(val) && val.every(v => isStr(v)), paramInvalid, + validate('video.mimes', val => utils.isArray(val) && val.every(v => utils.isStr(v)), paramInvalid, 'array of strings, ex: ["video/mp4"]'); const placement = validate('video.placement', val => isDefined(val), paramRequired); @@ -549,33 +525,33 @@ function validateVideoParams(bid) { if (placement === 1) { validate('video.startdelay', val => isDefined(val), (field, v) => paramRequired(field, v, 'placement == 1')); - validate('video.startdelay', val => isNumber(val), paramInvalid, 'number, ex: 5'); + validate('video.startdelay', val => utils.isNumber(val), paramInvalid, 'number, ex: 5'); } validate('video.protocols', val => isDefined(val), paramRequired); - validate('video.protocols', val => isArrayOfNums(val) && val.every(v => (v >= 1 && v <= 6)), + validate('video.protocols', val => utils.isArrayOfNums(val) && val.every(v => (v >= 1 && v <= 6)), paramInvalid, 'array of numbers, ex: [2,3]'); validate('video.api', val => isDefined(val), paramRequired); - validate('video.api', val => isArrayOfNums(val) && val.every(v => (v >= 1 && v <= 6)), + validate('video.api', val => utils.isArrayOfNums(val) && val.every(v => (v >= 1 && v <= 6)), paramInvalid, 'array of numbers, ex: [2,3]'); - validate('video.playbackmethod', val => !isDefined(val) || isArrayOfNums(val), paramInvalid, + validate('video.playbackmethod', val => !isDefined(val) || utils.isArrayOfNums(val), paramInvalid, 'array of integers, ex: [2,6]'); validate('video.maxduration', val => isDefined(val), paramRequired); - validate('video.maxduration', val => isInteger(val), paramInvalid); - validate('video.minduration', val => !isDefined(val) || isNumber(val), paramInvalid); - validate('video.skippable', val => !isDefined(val) || isBoolean(val), paramInvalid); - validate('video.skipafter', val => !isDefined(val) || isNumber(val), paramInvalid); - validate('video.pos', val => !isDefined(val) || isNumber(val), paramInvalid); - validate('params.badv', val => !isDefined(val) || isArray(val), paramInvalid, + validate('video.maxduration', val => utils.isInteger(val), paramInvalid); + validate('video.minduration', val => !isDefined(val) || utils.isNumber(val), paramInvalid); + validate('video.skippable', val => !isDefined(val) || utils.isBoolean(val), paramInvalid); + validate('video.skipafter', val => !isDefined(val) || utils.isNumber(val), paramInvalid); + validate('video.pos', val => !isDefined(val) || utils.isNumber(val), paramInvalid); + validate('params.badv', val => !isDefined(val) || utils.isArray(val), paramInvalid, 'array of strings, ex: ["ford.com","pepsi.com"]'); - validate('params.bcat', val => !isDefined(val) || isArray(val), paramInvalid, + validate('params.bcat', val => !isDefined(val) || utils.isArray(val), paramInvalid, 'array of strings, ex: ["IAB1-5","IAB1-6"]'); return true; } catch (e) { - logError(e.message); + utils.logError(e.message); return false; } } @@ -601,29 +577,3 @@ function shortcutProperty(extraCharacters, target, propertyName) { return charactersLeft; } - -/** - * Creates and returnes eids arr using createEidsArray from './userId/eids.js' module; - * @param {Object} openRtbRequest OpenRTB's request as a cource of userId. - * @return array of eids objects - */ -function getEids(bidRequest) { - if (deepAccess(bidRequest, 'userId')) { - return createEidsArray(bidRequest.userId) || []; - } -}; - -/** - * Check if top window can be accessed - * - * @return {boolean} true if can access top window otherwise false - */ -function canAccessTopWindow() { - try { - if (getWindowTop().location.href) { - return true; - } - } catch (error) { - return false; - } -} diff --git a/modules/yieldmoSyntheticInventoryModule.js b/modules/yieldmoSyntheticInventoryModule.js deleted file mode 100644 index bca778a7b43..00000000000 --- a/modules/yieldmoSyntheticInventoryModule.js +++ /dev/null @@ -1,46 +0,0 @@ -import { config } from '../src/config.js'; -import { isGptPubadsDefined } from '../src/utils.js'; - -export const MODULE_NAME = 'Yieldmo Synthetic Inventory Module'; - -export function init(config) { - validateConfig(config); - - if (!isGptPubadsDefined()) { - window.googletag = window.googletag || {}; - window.googletag.cmd = window.googletag.cmd || []; - } - - const googletag = window.googletag; - const containerName = 'ym_sim_container_' + config.placementId; - - googletag.cmd.push(() => { - if (window.document.body) { - googletagCmd(config, containerName, googletag); - } else { - window.document.addEventListener('DOMContentLoaded', () => googletagCmd(config, containerName, googletag)); - } - }); -} - -export function validateConfig(config) { - if (!('placementId' in config)) { - throw new Error(`${MODULE_NAME}: placementId required`); - } - if (!('adUnitPath' in config)) { - throw new Error(`${MODULE_NAME}: adUnitPath required`); - } -} - -function googletagCmd(config, containerName, googletag) { - const gamContainer = window.document.createElement('div'); - gamContainer.id = containerName; - window.document.body.appendChild(gamContainer); - googletag.defineSlot(config.adUnitPath, [1, 1], containerName) - .addService(googletag.pubads()) - .setTargeting('ym_sim_p_id', config.placementId); - googletag.enableServices(); - googletag.display(containerName); -} - -config.getConfig('yieldmo_synthetic_inventory', config => init(config.yieldmo_synthetic_inventory)); diff --git a/modules/yieldmoSyntheticInventoryModule.md b/modules/yieldmoSyntheticInventoryModule.md deleted file mode 100644 index dd6f0acf884..00000000000 --- a/modules/yieldmoSyntheticInventoryModule.md +++ /dev/null @@ -1,68 +0,0 @@ -# Yieldmo Synthetic Inventory Module - -## Overview - -This module enables publishers to set up Yieldmo Synthetic Outstream ads on their pages. - -If publishers will enable this module and provide placementId and Google Ad Manager ad unit path, this module will create a placement on the page and inject Yieldmo SDK into this placement. Publisher will then need to get a placement id from their Yieldmo account manager (accounts email) and setup corresponding ad units on the GAM ad server. - -## Integration - -Build the Yieldmo Synthetic Inventory Module into the Prebid.js package with: - -``` -gulp build --modules=yieldmoSyntheticInventoryModule,... -``` - -## Module Configuration - -```js -pbjs.que.push(function() { - pbjs.setConfig({ - yieldmo_synthetic_inventory: { - placementId: '1234567890', - adUnitPath: '/1234567/ad_unit_name_used_in_gam' - } - }); -}); -``` - -### Configuration Parameters - -|Name |Scope |Description | Example| Type -| :------------ | :------------ | :------------ | :------------ | :------------ | -|placementId | required | Yieldmo placement ID | '1234567890' | string -|adUnitPath | required | Google Ad Manager ad unit path | '/6355419/ad_unit_name_used_in_gam' | string - -### How to get ad unit path - -Ad unit path follows the format /network-code/[parent-ad-unit-code/.../]ad-unit-code, where: - -- network-code is a unique identifier for the Ad Manager network the ad unit belongs to -- parent-ad-unit-code are the codes of all parent ad units (only applies to non-top level ad units) -- ad-unit-code is the code for the ad unit to be displayed - -Note that all ad unit codes included in the ad unit path must adhere to the [formatting rules](https://support.google.com/admanager/answer/1628457#ad-unit-codes) specified by Ad Manager. - -Another and probably the easiest way to get an ad unit path is to get it from the google ad manager ad unit document header generated tag: - -```js -googletag.defineSlot('/1234567/ad_unit_name_used_in_gam', [1, 1], 'ad-container-id').addService(googletag.pubads()); -``` - -### How to get Yieldmo placement id - -Please reach out to your Yieldmo account's person or email to support@yieldmo.com - -### Google Ad Manager setup - -Yieldmo Synthetic Inventory Module is designed to be used along with Google Ad Manager. GAM should be set as usual, but there are a few requirements: - -- Ad unit size should be 1x1 -- Creative should NOT be served into a SafeFrame and also should have 1x1 size -- Synthetic Inventory Universal Tag should be used as 3rd party creative code -### Synthetic Inventory Universal Tag - -```js -
-``` \ No newline at end of file diff --git a/modules/yieldoneAnalyticsAdapter.js b/modules/yieldoneAnalyticsAdapter.js index cb13503365e..542c0917708 100644 --- a/modules/yieldoneAnalyticsAdapter.js +++ b/modules/yieldoneAnalyticsAdapter.js @@ -1,10 +1,10 @@ -import { isArray, deepClone } from '../src/utils.js'; import {ajax} from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import CONSTANTS from '../src/constants.json'; import adapterManager from '../src/adapterManager.js'; import { targeting } from '../src/targeting.js'; import { auctionManager } from '../src/auctionManager.js'; +import * as utils from '../src/utils.js'; const ANALYTICS_CODE = 'yieldone'; const analyticsType = 'endpoint'; @@ -42,7 +42,7 @@ function makeAdUnitNameMap() { } function addAdUnitNameForArray(ar, map) { - if (isArray(ar)) { + if (utils.isArray(ar)) { ar.forEach((it) => { addAdUnitName(it, map) }); } } @@ -51,14 +51,14 @@ function addAdUnitName(params, map) { if (params.adUnitCode && map[params.adUnitCode]) { params.adUnitName = map[params.adUnitCode]; } - if (isArray(params.adUnits)) { + if (utils.isArray(params.adUnits)) { params.adUnits.forEach((adUnit) => { if (adUnit.code && map[adUnit.code]) { adUnit.name = map[adUnit.code]; } }); } - if (isArray(params.adUnitCodes)) { + if (utils.isArray(params.adUnitCodes)) { params.adUnitNames = params.adUnitCodes.map((code) => map[code]); } ['bids', 'bidderRequests', 'bidsReceived', 'noBids'].forEach((it) => { @@ -71,13 +71,13 @@ const yieldoneAnalytics = Object.assign(adapter({analyticsType}), { track({eventType, args = {}}) { if (eventType === CONSTANTS.EVENTS.BID_REQUESTED) { const reqBidderId = `${args.bidderCode}_${args.auctionId}`; - requestedBidders[reqBidderId] = deepClone(args); + requestedBidders[reqBidderId] = utils.deepClone(args); requestedBidders[reqBidderId].bids = []; args.bids.forEach((bid) => { requestedBids[`${bid.bidId}_${bid.auctionId}`] = bid; }); } - if (eventType === CONSTANTS.EVENTS.BID_TIMEOUT && isArray(args)) { + if (eventType === CONSTANTS.EVENTS.BID_TIMEOUT && utils.isArray(args)) { const eventsStorage = yieldoneAnalytics.eventsStorage; const reqBidders = {}; args.forEach((bid) => { diff --git a/modules/yieldoneBidAdapter.js b/modules/yieldoneBidAdapter.js index fe5a63cab51..73c3d2e8808 100644 --- a/modules/yieldoneBidAdapter.js +++ b/modules/yieldoneBidAdapter.js @@ -1,4 +1,4 @@ -import {deepAccess, isEmpty, isStr, logWarn, parseSizesInput} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {config} from '../src/config.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import { Renderer } from '../src/Renderer.js'; @@ -11,8 +11,6 @@ const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/d const CMER_PLAYER_URL = 'https://an.cmertv.com/hb/renderer/cmertv-video-yone-prebid.min.js'; const VIEWABLE_PERCENTAGE_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/prebid-adformat-config.js'; -const DEFAULT_VIDEO_SIZE = {w: 640, h: 360}; - export const spec = { code: BIDDER_CODE, aliases: ['y1'], @@ -42,23 +40,21 @@ export const spec = { t: 'i' }; - const mediaType = getMediaType(bidRequest); - switch (mediaType) { - case BANNER: - payload.sz = getBannerSizes(bidRequest); - break; - case VIDEO: - const videoSize = getVideoSize(bidRequest); - payload.w = videoSize.w; - payload.h = videoSize.h; - break; - default: - break; + const videoMediaType = utils.deepAccess(bidRequest, 'mediaTypes.video'); + if ((utils.isEmpty(bidRequest.mediaType) && utils.isEmpty(bidRequest.mediaTypes)) || + (bidRequest.mediaType === BANNER || (bidRequest.mediaTypes && bidRequest.mediaTypes[BANNER]))) { + const sizes = utils.deepAccess(bidRequest, 'mediaTypes.banner.sizes') || bidRequest.sizes; + payload.sz = utils.parseSizesInput(sizes).join(','); + } else if (bidRequest.mediaType === VIDEO || videoMediaType) { + const sizes = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') || bidRequest.sizes; + const size = utils.parseSizesInput(sizes)[0]; + payload.w = size.split('x')[0]; + payload.h = size.split('x')[1]; } // LiveRampID - const idlEnv = deepAccess(bidRequest, 'userId.idl_env'); - if (isStr(idlEnv) && !isEmpty(idlEnv)) { + const idlEnv = utils.deepAccess(bidRequest, 'userId.idl_env'); + if (utils.isStr(idlEnv) && !utils.isEmpty(idlEnv)) { payload.lr_env = idlEnv; } @@ -171,106 +167,6 @@ export const spec = { }, } -/** - * NOTE: server side does not yet support multiple formats. - * @param {Object} bidRequest - - * @param {boolean} [enabledOldFormat = true] - default: `true`. - * @return {string|null} - `"banner"` or `"video"` or `null`. - */ -function getMediaType(bidRequest, enabledOldFormat = true) { - let hasBannerType = Boolean(deepAccess(bidRequest, 'mediaTypes.banner')); - let hasVideoType = Boolean(deepAccess(bidRequest, 'mediaTypes.video')); - - if (enabledOldFormat) { - hasBannerType = hasBannerType || bidRequest.mediaType === BANNER || - (isEmpty(bidRequest.mediaTypes) && isEmpty(bidRequest.mediaType)); - hasVideoType = hasVideoType || bidRequest.mediaType === VIDEO; - } - - if (hasBannerType && hasVideoType) { - const playerParams = deepAccess(bidRequest, 'params.playerParams') - if (playerParams) { - return VIDEO; - } else { - return BANNER; - } - } else if (hasBannerType) { - return BANNER; - } else if (hasVideoType) { - return VIDEO; - } - - return null; -} - -/** - * NOTE: - * If `mediaTypes.banner` exists, then `mediaTypes.banner.sizes` must also exist. - * The reason for this is that Prebid.js will perform the verification and - * if `mediaTypes.banner.sizes` is inappropriate, it will delete the entire `mediaTypes.banner`. - * @param {Object} bidRequest - - * @param {Object} bidRequest.banner - - * @param {Array} bidRequest.banner.sizes - - * @param {boolean} [enabledOldFormat = true] - default: `true`. - * @return {string} - strings like `"300x250"` or `"300x250,728x90"`. - */ -function getBannerSizes(bidRequest, enabledOldFormat = true) { - let sizes = deepAccess(bidRequest, 'mediaTypes.banner.sizes'); - - if (enabledOldFormat) { - sizes = sizes || bidRequest.sizes; - } - - return parseSizesInput(sizes).join(','); -} - -/** - * @param {Object} bidRequest - - * @param {boolean} [enabledOldFormat = true] - default: `true`. - * @param {boolean} [enabledFlux = true] - default: `true`. - * @return {{w: number, h: number}} - - */ -function getVideoSize(bidRequest, enabledOldFormat = true, enabledFlux = true) { - /** - * @param {Array | Array>} sizes - - * @return {{w: number, h: number} | null} - - */ - const _getPlayerSize = (sizes) => { - let result = null; - - const size = parseSizesInput(sizes)[0]; - if (isEmpty(size)) { - return result; - } - - const splited = size.split('x'); - const sizeObj = {w: parseInt(splited[0], 10), h: parseInt(splited[1], 10)}; - const _isValidPlayerSize = !(isEmpty(sizeObj)) && (isFinite(sizeObj.w) && isFinite(sizeObj.h)); - if (!_isValidPlayerSize) { - return result; - } - - result = sizeObj; - return result; - } - - let playerSize = _getPlayerSize(deepAccess(bidRequest, 'mediaTypes.video.playerSize')); - - if (enabledOldFormat) { - playerSize = playerSize || _getPlayerSize(bidRequest.sizes); - } - - if (enabledFlux) { - // NOTE: `video.playerSize` in Flux is always [1,1]. - if (playerSize && (playerSize.w === 1 && playerSize.h === 1)) { - // NOTE: `params.playerSize` is a specific object to support `FLUX`. - playerSize = _getPlayerSize(deepAccess(bidRequest, 'params.playerSize')); - } - } - - return playerSize || DEFAULT_VIDEO_SIZE; -} - function newRenderer(response) { const renderer = Renderer.install({ id: response.uid, @@ -281,7 +177,7 @@ function newRenderer(response) { try { renderer.setRender(outstreamRender); } catch (err) { - logWarn('Prebid Error calling setRender on newRenderer', err); + utils.logWarn('Prebid Error calling setRender on newRenderer', err); } return renderer; @@ -303,7 +199,7 @@ function newCmerRenderer(response) { try { renderer.setRender(cmerRender); } catch (err) { - logWarn('Prebid Error calling setRender on newRenderer', err); + utils.logWarn('Prebid Error calling setRender on newRenderer', err); } return renderer; diff --git a/modules/yuktamediaAnalyticsAdapter.js b/modules/yuktamediaAnalyticsAdapter.js index 080af9f3973..2ef2d251ace 100644 --- a/modules/yuktamediaAnalyticsAdapter.js +++ b/modules/yuktamediaAnalyticsAdapter.js @@ -1,8 +1,8 @@ -import { getWindowLocation, generateUUID, parseUrl, buildUrl, logInfo, parseSizesInput, logError } from '../src/utils.js'; import { ajax } from '../src/ajax.js'; import adapter from '../src/AnalyticsAdapter.js'; import adapterManager from '../src/adapterManager.js'; import CONSTANTS from '../src/constants.json'; +import * as utils from '../src/utils.js'; import { getStorageManager } from '../src/storageManager.js'; import { getRefererInfo } from '../src/refererDetection.js'; import strIncludes from 'core-js-pure/features/string/includes.js'; @@ -17,7 +17,7 @@ const events = { }; const localStoragePrefix = 'yuktamediaAnalytics_'; const utmTags = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content']; -const location = getWindowLocation(); +const location = utils.getWindowLocation(); const referer = getRefererInfo().referer; const _pageInfo = { userAgent: window.navigator.userAgent, @@ -25,13 +25,13 @@ const _pageInfo = { language: window.navigator.language, screenWidth: window.screen.width, screenHeight: window.screen.height, - pageViewId: generateUUID(), + pageViewId: utils.generateUUID(), host: location.host, path: location.pathname, search: location.search, hash: location.hash, referer: referer, - refererDomain: parseUrl(referer).host, + refererDomain: utils.parseUrl(referer).host, yuktamediaAnalyticsVersion: yuktamediaAnalyticsVersion, prebidVersion: $$PREBID_GLOBAL$$.version }; @@ -53,7 +53,7 @@ function isNavigatorSendBeaconSupported() { function updateSessionId() { if (isSessionIdTimeoutExpired()) { - let newSessionId = generateUUID(); + let newSessionId = utils.generateUUID(); storage.setDataInLocalStorage(localStoragePrefix.concat('session_id'), newSessionId); } initOptions.sessionId = getSessionId(); @@ -80,7 +80,7 @@ function isUtmTimeoutExpired() { function send(data, status) { data.initOptions = Object.assign(_pageInfo, initOptions); - const yuktamediaAnalyticsRequestUrl = buildUrl({ + const yuktamediaAnalyticsRequestUrl = utils.buildUrl({ protocol: 'https', hostname: 'analytics-prebid.yuktamedia.com', pathname: '/api/bids' @@ -97,13 +97,13 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin if (typeof args !== 'undefined') { switch (eventType) { case CONSTANTS.EVENTS.AUCTION_INIT: - logInfo(localStoragePrefix + 'AUCTION_INIT:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'AUCTION_INIT:', JSON.stringify(args)); if (typeof args.auctionId !== 'undefined' && args.auctionId.length) { events.auctions[args.auctionId] = { bids: {} }; } break; case CONSTANTS.EVENTS.BID_REQUESTED: - logInfo(localStoragePrefix + 'BID_REQUESTED:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'BID_REQUESTED:', JSON.stringify(args)); if (typeof args.auctionId !== 'undefined' && args.auctionId.length) { if (typeof events.auctions[args.auctionId] === 'undefined') { events.auctions[args.auctionId] = { bids: {} }; @@ -113,7 +113,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin events.auctions[args.auctionId]['bids'][bidRequest.bidId] = { bidder: bidRequest.bidder, adUnit: bidRequest.adUnitCode, - sizes: parseSizesInput(bidRequest.sizes).toString(), + sizes: utils.parseSizesInput(bidRequest.sizes).toString(), isBid: false, won: false, timeout: false, @@ -132,7 +132,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin } break; case CONSTANTS.EVENTS.BID_RESPONSE: - logInfo(localStoragePrefix + 'BID_RESPONSE:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'BID_RESPONSE:', JSON.stringify(args)); if (typeof args.auctionId !== 'undefined' && args.auctionId.length) { if (typeof events.auctions[args.auctionId] === 'undefined') { events.auctions[args.auctionId] = { bids: {} }; @@ -162,7 +162,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin } break; case CONSTANTS.EVENTS.NO_BID: - logInfo(localStoragePrefix + 'NO_BID:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'NO_BID:', JSON.stringify(args)); if (typeof args.auctionId !== 'undefined' && args.auctionId.length) { if (typeof events.auctions[args.auctionId] === 'undefined') { events.auctions[args.auctionId] = { bids: {} }; @@ -173,7 +173,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin } break; case CONSTANTS.EVENTS.BID_WON: - logInfo(localStoragePrefix + 'BID_WON:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'BID_WON:', JSON.stringify(args)); if (typeof initOptions.enableSession !== 'undefined' && initOptions.enableSession) { updateSessionId(); } @@ -189,7 +189,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin } break; case CONSTANTS.EVENTS.BID_TIMEOUT: - logInfo(localStoragePrefix + 'BID_TIMEOUT:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'BID_TIMEOUT:', JSON.stringify(args)); if (args.length) { args.forEach(timeout => { if (typeof timeout !== 'undefined' && typeof timeout.auctionId !== 'undefined' && timeout.auctionId.length) { @@ -205,7 +205,7 @@ var yuktamediaAnalyticsAdapter = Object.assign(adapter({ analyticsType: 'endpoin } break; case CONSTANTS.EVENTS.AUCTION_END: - logInfo(localStoragePrefix + 'AUCTION_END:', JSON.stringify(args)); + utils.logInfo(localStoragePrefix + 'AUCTION_END:', JSON.stringify(args)); if (typeof initOptions.enableSession !== 'undefined' && initOptions.enableSession) { updateSessionId(); } @@ -249,7 +249,7 @@ yuktamediaAnalyticsAdapter.originEnableAnalytics = yuktamediaAnalyticsAdapter.en yuktamediaAnalyticsAdapter.enableAnalytics = function (config) { if (config && config.options) { if (typeof config.options.pubId === 'undefined' || typeof config.options.pubKey === 'undefined') { - logError('Need pubId and pubKey to log auction results. Please contact a YuktaMedia representative if you do not know your pubId and pubKey.'); + utils.logError('Need pubId and pubKey to log auction results. Please contact a YuktaMedia representative if you do not know your pubId and pubKey.'); return; } } diff --git a/modules/zeotapIdPlusIdSystem.js b/modules/zeotapIdPlusIdSystem.js index 5cb3a836cd8..8f26cc827d6 100644 --- a/modules/zeotapIdPlusIdSystem.js +++ b/modules/zeotapIdPlusIdSystem.js @@ -4,7 +4,7 @@ * @module modules/zeotapIdPlusIdSystem * @requires module:modules/userId */ -import { isStr, isPlainObject } from '../src/utils.js'; +import * as utils from '../src/utils.js' import {submodule} from '../src/hook.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -45,7 +45,7 @@ export const zeotapIdPlusSubmodule = { * @return { Object | string | undefined } */ decode(value) { - const id = value ? isStr(value) ? value : isPlainObject(value) ? value.id : undefined : undefined; + const id = value ? utils.isStr(value) ? value : utils.isPlainObject(value) ? value.id : undefined : undefined; return id ? { 'IDP': JSON.parse(atob(id)) } : undefined; diff --git a/modules/zetaBidAdapter.js b/modules/zetaBidAdapter.js index 27650888677..c6ce7e857ba 100644 --- a/modules/zetaBidAdapter.js +++ b/modules/zetaBidAdapter.js @@ -1,4 +1,4 @@ -import { logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; const BIDDER_CODE = 'zeta_global'; @@ -24,30 +24,30 @@ export const spec = { if (!(bid && bid.bidId && bid.params)) { - logWarn('Invalid bid request - missing required bid data'); + utils.logWarn('Invalid bid request - missing required bid data'); return false; } if (!(bid.params.user && bid.params.user.buyeruid)) { - logWarn('Invalid bid request - missing required user data'); + utils.logWarn('Invalid bid request - missing required user data'); return false; } if (!(bid.params.device && bid.params.device.ip)) { - logWarn('Invalid bid request - missing required device data'); + utils.logWarn('Invalid bid request - missing required device data'); return false; } if (!(bid.params.device.geo && bid.params.device.geo.country)) { - logWarn('Invalid bid request - missing required geo data'); + utils.logWarn('Invalid bid request - missing required geo data'); return false; } if (!bid.params.definerId) { - logWarn('Invalid bid request - missing required definer data'); + utils.logWarn('Invalid bid request - missing required definer data'); return false; } diff --git a/modules/zetaSspBidAdapter.md b/modules/zetaSspBidAdapter.md index 00d8663586c..d2950bce6b9 100644 --- a/modules/zetaSspBidAdapter.md +++ b/modules/zetaSspBidAdapter.md @@ -10,7 +10,7 @@ Maintainer: miakovlev@zetaglobal.com Module that connects to Zeta's SSP -# Banner Ad Unit: For Publishers +# Test Parameters ``` var adUnits = [ { @@ -40,35 +40,3 @@ Module that connects to Zeta's SSP } ]; ``` - -# Video Ad Unit: For Publishers -``` - var adUnits = [ - { - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream' - } - }, - bids: [ - { - bidder: 'zeta_global_ssp', - bidId: 12345, - params: { - placement: 12345, - user: { - uid: 12345, - buyeruid: 12345 - }, - tags: { - someTag: 123, - sid: 'publisherId' - }, - test: 1 - } - } - ] - } - ]; -``` diff --git a/modules/zeta_global_sspAnalyticsAdapter.js b/modules/zeta_global_sspAnalyticsAdapter.js deleted file mode 100644 index 906e6e19cc2..00000000000 --- a/modules/zeta_global_sspAnalyticsAdapter.js +++ /dev/null @@ -1,97 +0,0 @@ -import { logInfo, logError } from '../src/utils.js'; -import { ajax } from '../src/ajax.js'; -import adapterManager from '../src/adapterManager.js'; -import CONSTANTS from '../src/constants.json'; - -import adapter from '../src/AnalyticsAdapter.js'; - -const ZETA_GVL_ID = 833; -const ADAPTER_CODE = 'zeta_global_ssp'; -const BASE_URL = 'https://ssp.disqus.com/prebid/event'; -const LOG_PREFIX = 'ZetaGlobalSsp-Analytics: '; - -/// /////////// VARIABLES //////////////////////////////////// - -let publisherId; // int - -/// /////////// HELPER FUNCTIONS ///////////////////////////// - -function sendEvent(eventType, event) { - ajax( - BASE_URL + '/' + eventType, - null, - JSON.stringify(event) - ); -} - -/// /////////// ADAPTER EVENT HANDLER FUNCTIONS ////////////// - -function adRenderSucceededHandler(args) { - let eventType = CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED - logInfo(LOG_PREFIX + 'handle ' + eventType + ' event'); - - sendEvent(eventType, args); -} - -function auctionEndHandler(args) { - let eventType = CONSTANTS.EVENTS.AUCTION_END; - logInfo(LOG_PREFIX + 'handle ' + eventType + ' event'); - - sendEvent(eventType, args); -} - -/// /////////// ADAPTER DEFINITION /////////////////////////// - -let baseAdapter = adapter({ analyticsType: 'endpoint' }); -let zetaAdapter = Object.assign({}, baseAdapter, { - - enableAnalytics(config = {}) { - let error = false; - - if (typeof config.options === 'object') { - if (config.options.sid) { - publisherId = Number(config.options.sid); - } - } else { - logError(LOG_PREFIX + 'Config not found'); - error = true; - } - - if (!publisherId) { - logError(LOG_PREFIX + 'Missing sid (publisher id)'); - error = true; - } - - if (error) { - logError(LOG_PREFIX + 'Analytics is disabled due to error(s)'); - } else { - baseAdapter.enableAnalytics.call(this, config); - } - }, - - disableAnalytics() { - publisherId = undefined; - baseAdapter.disableAnalytics.apply(this, arguments); - }, - - track({ eventType, args }) { - switch (eventType) { - case CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED: - adRenderSucceededHandler(args); - break; - case CONSTANTS.EVENTS.AUCTION_END: - auctionEndHandler(args); - break; - } - } -}); - -/// /////////// ADAPTER REGISTRATION ///////////////////////// - -adapterManager.registerAnalyticsAdapter({ - adapter: zetaAdapter, - code: ADAPTER_CODE, - gvlid: ZETA_GVL_ID -}); - -export default zetaAdapter; diff --git a/modules/zeta_global_sspAnalyticsAdapter.md b/modules/zeta_global_sspAnalyticsAdapter.md deleted file mode 100644 index d586d0069b1..00000000000 --- a/modules/zeta_global_sspAnalyticsAdapter.md +++ /dev/null @@ -1,24 +0,0 @@ -# Zeta Global SSP Analytics Adapter - -## Overview - -Module Name: Zeta Global SSP Analytics Adapter\ -Module Type: Analytics Adapter\ -Maintainer: abermanov@zetaglobal.com - -## Description - -Analytics Adapter which sends auctionEnd and adRenderSucceeded events to Zeta Global SSP analytics endpoints - -## How to configure -``` -pbjs.enableAnalytics({ - provider: 'zeta_global_ssp', - options: { - sid: 111, - tags: { - ... - } - } -}); -``` diff --git a/modules/zeta_global_sspBidAdapter.js b/modules/zeta_global_sspBidAdapter.js index 77542252aeb..4d5966e03e9 100644 --- a/modules/zeta_global_sspBidAdapter.js +++ b/modules/zeta_global_sspBidAdapter.js @@ -1,6 +1,6 @@ -import {deepAccess, deepSetValue, isArray, isBoolean, isNumber, isStr, logWarn} from '../src/utils.js'; +import * as utils from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; -import {BANNER, VIDEO} from '../src/mediaTypes.js'; +import {BANNER} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; const BIDDER_CODE = 'zeta_global_ssp'; @@ -11,36 +11,9 @@ const DEFAULT_CUR = 'USD'; const TTL = 200; const NET_REV = true; -const VIDEO_REGEX = new RegExp(/VAST\s+version/); - -const DATA_TYPES = { - 'NUMBER': 'number', - 'STRING': 'string', - 'BOOLEAN': 'boolean', - 'ARRAY': 'array', - 'OBJECT': 'object' -}; -const VIDEO_CUSTOM_PARAMS = { - 'mimes': DATA_TYPES.ARRAY, - 'minduration': DATA_TYPES.NUMBER, - 'maxduration': DATA_TYPES.NUMBER, - 'startdelay': DATA_TYPES.NUMBER, - 'playbackmethod': DATA_TYPES.ARRAY, - 'api': DATA_TYPES.ARRAY, - 'protocols': DATA_TYPES.ARRAY, - 'w': DATA_TYPES.NUMBER, - 'h': DATA_TYPES.NUMBER, - 'battr': DATA_TYPES.ARRAY, - 'linearity': DATA_TYPES.NUMBER, - 'placement': DATA_TYPES.NUMBER, - 'minbitrate': DATA_TYPES.NUMBER, - 'maxbitrate': DATA_TYPES.NUMBER, - 'skip': DATA_TYPES.NUMBER -} - export const spec = { code: BIDDER_CODE, - supportedMediaTypes: [BANNER, VIDEO], + supportedMediaTypes: [BANNER], /** * Determines whether or not the given bid request is valid. @@ -53,7 +26,7 @@ export const spec = { if (!(bid && bid.bidId && bid.params)) { - logWarn('Invalid bid request - missing required bid data'); + utils.logWarn('Invalid bid request - missing required bid data'); return false; } return true; @@ -72,23 +45,9 @@ export const spec = { const params = request.params; const impData = { id: request.bidId, - secure: secure + secure: secure, + banner: buildBanner(request) }; - if (request.mediaTypes) { - for (const mediaType in request.mediaTypes) { - switch (mediaType) { - case BANNER: - impData.banner = buildBanner(request); - break; - case VIDEO: - impData.video = buildVideo(request); - break; - } - } - } - if (!impData.banner && !impData.video) { - impData.banner = buildBanner(request); - } const fpd = config.getLegacyFpd(config.getConfig('ortb2')) || {}; let payload = { id: bidderRequest.auctionId, @@ -117,13 +76,13 @@ export const spec = { // Attaching GDPR Consent Params if (bidderRequest && bidderRequest.gdprConsent) { - deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); - deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); + utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); + utils.deepSetValue(payload, 'regs.ext.gdpr', (bidderRequest.gdprConsent.gdprApplies ? 1 : 0)); } // CCPA if (bidderRequest && bidderRequest.uspConsent) { - deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } provideEids(request, payload); @@ -163,7 +122,6 @@ export const spec = { advertiserDomains: zetaBid.adomain }; } - provideMediaType(zetaBid, bid); bidResponses.push(bid); }) }) @@ -220,52 +178,9 @@ function buildBanner(request) { }; } -function buildVideo(request) { - let video = {}; - const videoParams = deepAccess(request, 'mediaTypes.video', {}); - for (const key in VIDEO_CUSTOM_PARAMS) { - if (videoParams.hasOwnProperty(key)) { - video[key] = checkParamDataType(key, videoParams[key], VIDEO_CUSTOM_PARAMS[key]); - } - } - if (videoParams.playerSize) { - if (isArray(videoParams.playerSize[0])) { - video.w = parseInt(videoParams.playerSize[0][0], 10); - video.h = parseInt(videoParams.playerSize[0][1], 10); - } else if (isNumber(videoParams.playerSize[0])) { - video.w = parseInt(videoParams.playerSize[0], 10); - video.h = parseInt(videoParams.playerSize[1], 10); - } - } - return video; -} - -function checkParamDataType(key, value, datatype) { - let functionToExecute; - switch (datatype) { - case DATA_TYPES.BOOLEAN: - functionToExecute = isBoolean; - break; - case DATA_TYPES.NUMBER: - functionToExecute = isNumber; - break; - case DATA_TYPES.STRING: - functionToExecute = isStr; - break; - case DATA_TYPES.ARRAY: - functionToExecute = isArray; - break; - } - if (functionToExecute(value)) { - return value; - } - logWarn('Ignoring param key: ' + key + ', expects ' + datatype + ', found ' + typeof value); - return undefined; -} - function provideEids(request, payload) { if (Array.isArray(request.userIdAsEids) && request.userIdAsEids.length > 0) { - deepSetValue(payload, 'user.ext.eids', request.userIdAsEids); + utils.deepSetValue(payload, 'user.ext.eids', request.userIdAsEids); } } @@ -287,22 +202,4 @@ function isConnectedTV() { return /(smart[-]?tv|hbbtv|appletv|googletv|hdmi|netcast\.tv|viera|nettv|roku|\bdtv\b|sonydtv|inettvbrowser|\btv\b)/i.test(navigator.userAgent); } -function provideMediaType(zetaBid, bid) { - if (zetaBid.ext && zetaBid.ext.bidtype) { - if (zetaBid.ext.bidtype === VIDEO) { - bid.mediaType = VIDEO; - bid.vastXml = bid.ad; - } else { - bid.mediaType = BANNER; - } - } else { - if (VIDEO_REGEX.test(bid.ad)) { - bid.mediaType = VIDEO; - bid.vastXml = bid.ad; - } else { - bid.mediaType = BANNER; - } - } -} - registerBidder(spec); diff --git a/package.json b/package.json index 557d8dac1cc..72c529eab4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "6.7.0-pre", + "version": "5.11.0-pre", "description": "Header Bidding Management Library", "main": "src/prebid.js", "scripts": { @@ -11,11 +11,6 @@ "type": "git", "url": "https://github.com/prebid/Prebid.js.git" }, - "browserslist": [ - "> 0.25%", - "not IE 11", - "not op_mini all" - ], "keywords": [ "advertising", "auction", diff --git a/plugins/pbjsGlobals.js b/plugins/pbjsGlobals.js index 73912d8126e..bf3c9033ee6 100644 --- a/plugins/pbjsGlobals.js +++ b/plugins/pbjsGlobals.js @@ -1,13 +1,11 @@ let t = require('@babel/core').types; let prebid = require('../package.json'); -const path = require('path'); module.exports = function(api, options) { - const pbGlobal = options.globalVarName || prebid.globalVarName; let replace = { '$prebid.version$': prebid.version, - '$$PREBID_GLOBAL$$': pbGlobal, + '$$PREBID_GLOBAL$$': options.globalVarName || prebid.globalVarName, '$$REPO_AND_VERSION$$': `${prebid.repository.url.split('/')[3]}_prebid_${prebid.version}` }; @@ -15,33 +13,8 @@ module.exports = function(api, options) { '$$REPO_AND_VERSION$$' ]; - const PREBID_ROOT = path.resolve(__dirname, '..'); - - function getModuleName(filename) { - const modPath = path.parse(path.relative(PREBID_ROOT, filename)); - if (modPath.ext.toLowerCase() !== '.js') { - return null; - } - if (modPath.dir === 'modules') { - // modules/moduleName.js -> moduleName - return modPath.name; - } - if (modPath.name.toLowerCase() === 'index' && path.dirname(modPath.dir) === 'modules') { - // modules/moduleName/index.js -> moduleName - return path.basename(modPath.dir); - } - return null; - } - return { visitor: { - Program(path, state) { - const modName = getModuleName(state.filename); - if (modName != null) { - // append "registration" of module file to $$PREBID_GLOBAL$$.installedModules - path.node.body.push(...api.parse(`window.${pbGlobal}.installedModules.push('${modName}');`).program.body); - } - }, StringLiteral(path) { Object.keys(replace).forEach(name => { if (path.node.value.includes(name)) { diff --git a/src/AnalyticsAdapter.js b/src/AnalyticsAdapter.js index 2c27307ead3..97513b80cc7 100644 --- a/src/AnalyticsAdapter.js +++ b/src/AnalyticsAdapter.js @@ -1,8 +1,8 @@ import CONSTANTS from './constants.json'; import { ajax } from './ajax.js'; -import { logMessage, _each } from './utils.js'; const events = require('./events.js'); +const utils = require('./utils.js'); const { EVENTS: { @@ -123,22 +123,22 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } } }; - _each(_handlers, (handler, event) => { + utils._each(_handlers, (handler, event) => { events.on(event, handler); }); } else { - logMessage(`Analytics adapter for "${global}" disabled by sampling`); + utils.logMessage(`Analytics adapter for "${global}" disabled by sampling`); } // finally set this function to return log message, prevents multiple adapter listeners this._oldEnable = this.enableAnalytics; this.enableAnalytics = function _enable() { - return logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`); + return utils.logMessage(`Analytics adapter for "${global}" already enabled, unnecessary call to \`enableAnalytics\`.`); }; } function _disable() { - _each(_handlers, (handler, event) => { + utils._each(_handlers, (handler, event) => { events.off(event, handler); }); this.enableAnalytics = this._oldEnable ? this._oldEnable : _enable; @@ -158,6 +158,6 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } _enableCheck = false; } - logMessage(`event count sent to ${global}: ${_eventCount}`); + utils.logMessage(`event count sent to ${global}: ${_eventCount}`); } } diff --git a/src/Renderer.js b/src/Renderer.js index 1d7506418bb..c997658b30b 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -1,7 +1,5 @@ import { loadExternalScript } from './adloader.js'; -import { - logError, logWarn, logMessage, deepAccess -} from './utils.js'; +import * as utils from './utils.js'; import find from 'core-js-pure/features/array/find.js'; const moduleCode = 'outstream'; @@ -27,7 +25,7 @@ export function Renderer(options) { this.cmd = []; this.push = func => { if (typeof func !== 'function') { - logError('Commands given to Renderer.push must be wrapped in a function'); + utils.logError('Commands given to Renderer.push must be wrapped in a function'); return; } this.loaded ? func.call() : this.cmd.push(func); @@ -46,7 +44,7 @@ export function Renderer(options) { if (this._render) { this._render.apply(this, renderArgs) } else { - logWarn(`No render function was provided, please use .setRender on the renderer`); + utils.logWarn(`No render function was provided, please use .setRender on the renderer`); } } @@ -55,7 +53,7 @@ export function Renderer(options) { this.cmd.unshift(runRender) // should render run first ? loadExternalScript(url, moduleCode, this.callback); } else { - logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`); + utils.logWarn(`External Js not loaded by Renderer since renderer url and callback is already defined on adUnit ${adUnitCode}`); runRender() } }.bind(this) // bind the function to this object to avoid 'this' errors @@ -82,7 +80,7 @@ Renderer.prototype.handleVideoEvent = function({ id, eventName }) { this.handlers[eventName](); } - logMessage(`Prebid Renderer event for id ${id} type ${eventName}`); + utils.logMessage(`Prebid Renderer event for id ${id} type ${eventName}`); }; /* @@ -94,7 +92,7 @@ Renderer.prototype.process = function() { try { this.cmd.shift().call(); } catch (error) { - logError('Error processing Renderer command: ', error); + utils.logError('Error processing Renderer command: ', error); } } }; @@ -128,11 +126,11 @@ function isRendererPreferredFromAdUnit(adUnitCode) { } // renderer defined at adUnit level - const adUnitRenderer = deepAccess(adUnit, 'renderer'); + const adUnitRenderer = utils.deepAccess(adUnit, 'renderer'); const hasValidAdUnitRenderer = !!(adUnitRenderer && adUnitRenderer.url && adUnitRenderer.render); // renderer defined at adUnit.mediaTypes level - const mediaTypeRenderer = deepAccess(adUnit, 'mediaTypes.video.renderer'); + const mediaTypeRenderer = utils.deepAccess(adUnit, 'mediaTypes.video.renderer'); const hasValidMediaTypeRenderer = !!(mediaTypeRenderer && mediaTypeRenderer.url && mediaTypeRenderer.render) return !!( diff --git a/src/adapterManager.js b/src/adapterManager.js index 9a041543cf8..5f8f2e5721c 100644 --- a/src/adapterManager.js +++ b/src/adapterManager.js @@ -1,10 +1,6 @@ /** @module adaptermanger */ -import { - _each, getUserConfiguredParams, groupBy, logInfo, deepAccess, isValidMediaTypes, - getUniqueIdentifierStr, deepClone, logWarn, logError, logMessage, isArray, generateUUID, - flatten, getBidderCodes, getDefinedParams, shuffle, timestamp, getBidderRequest, bind -} from './utils.js'; +import { flatten, getBidderCodes, getDefinedParams, shuffle, timestamp, getBidderRequest, bind } from './utils.js'; import { getLabels, resolveStatus } from './sizeMapping.js'; import { processNativeAdUnitParams, nativeAdapters } from './native.js'; import { newBidder } from './adapters/bidderFactory.js'; @@ -16,6 +12,7 @@ import find from 'core-js-pure/features/array/find.js'; import { adunitCounter } from './adUnits.js'; import { getRefererInfo } from './refererDetection.js'; +var utils = require('./utils.js'); var CONSTANTS = require('./constants.json'); var events = require('./events.js'); let s2sTestingModule; // store s2sTesting module if it's loaded @@ -28,7 +25,7 @@ let _aliasRegistry = adapterManager.aliasRegistry = {}; let _s2sConfigs = []; config.getConfig('s2sConfig', config => { if (config && config.s2sConfig) { - _s2sConfigs = isArray(config.s2sConfig) ? config.s2sConfig : [config.s2sConfig]; + _s2sConfigs = Array.isArray(config.s2sConfig) ? config.s2sConfig : [config.s2sConfig]; } }); @@ -54,16 +51,16 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) ); if (!active) { - logInfo(`Size mapping disabled adUnit "${adUnit.code}"`); + utils.logInfo(`Size mapping disabled adUnit "${adUnit.code}"`); } else if (filterResults) { - logInfo(`Size mapping filtered adUnit "${adUnit.code}" banner sizes from `, filterResults.before, 'to ', filterResults.after); + utils.logInfo(`Size mapping filtered adUnit "${adUnit.code}" banner sizes from `, filterResults.before, 'to ', filterResults.after); } if (active) { result.push(adUnit.bids.filter(bid => bid.bidder === bidderCode) .reduce((bids, bid) => { const nativeParams = - adUnit.nativeParams || deepAccess(adUnit, 'mediaTypes.native'); + adUnit.nativeParams || utils.deepAccess(adUnit, 'mediaTypes.native'); if (nativeParams) { bid = Object.assign({}, bid, { nativeParams: processNativeAdUnitParams(nativeParams), @@ -84,17 +81,17 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) } = resolveStatus(getLabels(bid, labels), filteredMediaTypes); if (!active) { - logInfo(`Size mapping deactivated adUnit "${adUnit.code}" bidder "${bid.bidder}"`); + utils.logInfo(`Size mapping deactivated adUnit "${adUnit.code}" bidder "${bid.bidder}"`); } else if (filterResults) { - logInfo(`Size mapping filtered adUnit "${adUnit.code}" bidder "${bid.bidder}" banner sizes from `, filterResults.before, 'to ', filterResults.after); + utils.logInfo(`Size mapping filtered adUnit "${adUnit.code}" bidder "${bid.bidder}" banner sizes from `, filterResults.before, 'to ', filterResults.after); } - if (isValidMediaTypes(mediaTypes)) { + if (utils.isValidMediaTypes(mediaTypes)) { bid = Object.assign({}, bid, { mediaTypes }); } else { - logError( + utils.logError( `mediaTypes is not correctly configured for adunit ${adUnit.code}` ); } @@ -103,8 +100,8 @@ function getBids({bidderCode, auctionId, bidderRequestId, adUnits, labels, src}) bids.push(Object.assign({}, bid, { adUnitCode: adUnit.code, transactionId: adUnit.transactionId, - sizes: deepAccess(mediaTypes, 'banner.sizes') || deepAccess(mediaTypes, 'video.playerSize') || [], - bidId: bid.bid_id || getUniqueIdentifierStr(), + sizes: utils.deepAccess(mediaTypes, 'banner.sizes') || utils.deepAccess(mediaTypes, 'video.playerSize') || [], + bidId: bid.bid_id || utils.getUniqueIdentifierStr(), bidderRequestId, auctionId, src, @@ -125,7 +122,7 @@ const hookedGetBids = hook('sync', getBids, 'getBids'); function getAdUnitCopyForPrebidServer(adUnits, s2sConfig) { let adaptersServerSide = s2sConfig.bidders; - let adUnitsCopy = deepClone(adUnits); + let adUnitsCopy = utils.deepClone(adUnits); adUnitsCopy.forEach((adUnit) => { // filter out client side bids @@ -133,7 +130,7 @@ function getAdUnitCopyForPrebidServer(adUnits, s2sConfig) { return includes(adaptersServerSide, bid.bidder) && (!doingS2STesting(s2sConfig) || bid.finalSource !== s2sTestingModule.CLIENT); }).map((bid) => { - bid.bid_id = getUniqueIdentifierStr(); + bid.bid_id = utils.getUniqueIdentifierStr(); return bid; }); }); @@ -146,7 +143,7 @@ function getAdUnitCopyForPrebidServer(adUnits, s2sConfig) { } function getAdUnitCopyForClientAdapters(adUnits) { - let adUnitsClientCopy = deepClone(adUnits); + let adUnitsClientCopy = utils.deepClone(adUnits); // filter out s2s bids adUnitsClientCopy.forEach((adUnit) => { adUnit.bids = adUnit.bids.filter((bid) => { @@ -257,22 +254,20 @@ adapterManager.makeBidRequests = hook('sync', function (adUnits, auctionStart, a _s2sConfigs.forEach(s2sConfig => { if (s2sConfig && s2sConfig.enabled) { if ((isTestingServerOnly(s2sConfig) && adUnitsContainServerRequests(adUnits, s2sConfig))) { - logWarn('testServerOnly: True. All client requests will be suppressed.'); + utils.logWarn('testServerOnly: True. All client requests will be suppressed.'); clientBidderCodes.length = 0; } let adUnitsS2SCopy = getAdUnitCopyForPrebidServer(adUnits, s2sConfig); - - // uniquePbsTid is so we know which server to send which bids to during the callBids function - let uniquePbsTid = generateUUID(); + let tid = utils.generateUUID(); adaptersServerSide.forEach(bidderCode => { - const bidderRequestId = getUniqueIdentifierStr(); + const bidderRequestId = utils.getUniqueIdentifierStr(); const bidderRequest = { bidderCode, auctionId, bidderRequestId, - uniquePbsTid, - bids: hookedGetBids({bidderCode, auctionId, bidderRequestId, 'adUnits': deepClone(adUnitsS2SCopy), labels, src: CONSTANTS.S2S.SRC}), + tid, + bids: hookedGetBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsS2SCopy), labels, src: CONSTANTS.S2S.SRC}), auctionStart: auctionStart, timeout: s2sConfig.timeout, src: CONSTANTS.S2S.SRC, @@ -303,19 +298,19 @@ adapterManager.makeBidRequests = hook('sync', function (adUnits, auctionStart, a // client adapters let adUnitsClientCopy = getAdUnitCopyForClientAdapters(adUnits); clientBidderCodes.forEach(bidderCode => { - const bidderRequestId = getUniqueIdentifierStr(); + const bidderRequestId = utils.getUniqueIdentifierStr(); const bidderRequest = { bidderCode, auctionId, bidderRequestId, - bids: hookedGetBids({bidderCode, auctionId, bidderRequestId, 'adUnits': deepClone(adUnitsClientCopy), labels, src: 'client'}), + bids: hookedGetBids({bidderCode, auctionId, bidderRequestId, 'adUnits': utils.deepClone(adUnitsClientCopy), labels, src: 'client'}), auctionStart: auctionStart, timeout: cbTimeout, refererInfo }; const adapter = _bidderRegistry[bidderCode]; if (!adapter) { - logError(`Trying to make a request for bidder that does not exist: ${bidderCode}`); + utils.logError(`Trying to make a request for bidder that does not exist: ${bidderCode}`); } if (adapter && bidderRequest.bids && bidderRequest.bids.length !== 0) { @@ -339,7 +334,7 @@ adapterManager.makeBidRequests = hook('sync', function (adUnits, auctionStart, a adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, requestCallbacks, requestBidsTimeout, onTimelyResponse) => { if (!bidRequests.length) { - logWarn('callBids executed with no bidRequests. Were they filtered by labels or sizing?'); + utils.logWarn('callBids executed with no bidRequests. Were they filtered by labels or sizing?'); return; } @@ -352,7 +347,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request serverBidRequests.forEach(serverBidRequest => { var index = -1; for (var i = 0; i < uniqueServerBidRequests.length; ++i) { - if (serverBidRequest.uniquePbsTid === uniqueServerBidRequests[i].uniquePbsTid) { + if (serverBidRequest.tid === uniqueServerBidRequests[i].tid) { index = i; break; } @@ -362,10 +357,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request } }); - let counter = 0; - - // $.source.tid MUST be a unique UUID and also THE SAME between all PBS Requests for a given Auction - const sourceTid = generateUUID(); + let counter = 0 _s2sConfigs.forEach((s2sConfig) => { if (s2sConfig && uniqueServerBidRequests[counter] && includes(s2sConfig.bidders, uniqueServerBidRequests[counter].bidderCode)) { // s2s should get the same client side timeout as other client side requests. @@ -375,13 +367,13 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request } : undefined); let adaptersServerSide = s2sConfig.bidders; const s2sAdapter = _bidderRegistry[s2sConfig.adapter]; - let uniquePbsTid = uniqueServerBidRequests[counter].uniquePbsTid; + let tid = uniqueServerBidRequests[counter].tid; let adUnitsS2SCopy = uniqueServerBidRequests[counter].adUnitsS2SCopy; - let uniqueServerRequests = serverBidRequests.filter(serverBidRequest => serverBidRequest.uniquePbsTid === uniquePbsTid); + let uniqueServerRequests = serverBidRequests.filter(serverBidRequest => serverBidRequest.tid === tid) if (s2sAdapter) { - let s2sBidRequest = {tid: sourceTid, 'ad_units': adUnitsS2SCopy, s2sConfig}; + let s2sBidRequest = {tid, 'ad_units': adUnitsS2SCopy, s2sConfig}; if (s2sBidRequest.ad_units.length) { let doneCbs = uniqueServerRequests.map(bidRequest => { bidRequest.start = timestamp(); @@ -392,12 +384,11 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request let allBidders = s2sBidRequest.ad_units.reduce((adapters, adUnit) => { return adapters.concat((adUnit.bids || []).reduce((adapters, bid) => adapters.concat(bid.bidder), [])); }, []); - logMessage(`CALLING S2S HEADER BIDDERS ==== ${adaptersServerSide.filter(adapter => includes(allBidders, adapter)).join(',')}`); + utils.logMessage(`CALLING S2S HEADER BIDDERS ==== ${adaptersServerSide.filter(adapter => includes(allBidders, adapter)).join(',')}`); // fire BID_REQUESTED event for each s2s bidRequest uniqueServerRequests.forEach(bidRequest => { - // add the new sourceTid - events.emit(CONSTANTS.EVENTS.BID_REQUESTED, {...bidRequest, tid: sourceTid}); + events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest); }); // make bid requests @@ -415,7 +406,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request ); } } else { - logError('missing ' + s2sConfig.adapter); + utils.logError('missing ' + s2sConfig.adapter); } counter++ } @@ -427,7 +418,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request // TODO : Do we check for bid in pool from here and skip calling adapter again ? const adapter = _bidderRegistry[bidRequest.bidderCode]; config.runWithBidder(bidRequest.bidderCode, () => { - logMessage(`CALLING BIDDER`); + utils.logMessage(`CALLING BIDDER`); events.emit(CONSTANTS.EVENTS.BID_REQUESTED, bidRequest); }); let ajax = ajaxBuilder(requestBidsTimeout, requestCallbacks ? { @@ -450,7 +441,7 @@ adapterManager.callBids = (adUnits, bidRequests, addBidResponse, doneCb, request ) ); } catch (e) { - logError(`${bidRequest.bidderCode} Bid Adapter emitted an uncaught error when parsing their bidRequest`, {e, bidRequest}); + utils.logError(`${bidRequest.bidderCode} Bid Adapter emitted an uncaught error when parsing their bidRequest`, {e, bidRequest}); adapterDone(); } }); @@ -485,10 +476,10 @@ adapterManager.registerBidAdapter = function (bidAdapter, bidderCode, {supported nativeAdapters.push(bidderCode); } } else { - logError('Bidder adaptor error for bidder code: ' + bidderCode + 'bidder must implement a callBids() function'); + utils.logError('Bidder adaptor error for bidder code: ' + bidderCode + 'bidder must implement a callBids() function'); } } else { - logError('bidAdapter or bidderCode not specified'); + utils.logError('bidAdapter or bidderCode not specified'); } }; @@ -511,7 +502,7 @@ adapterManager.aliasBidAdapter = function (bidderCode, alias, options) { } }); nonS2SAlias.forEach(bidderCode => { - logError('bidderCode "' + bidderCode + '" is not an existing bidder.', 'adapterManager.aliasBidAdapter'); + utils.logError('bidderCode "' + bidderCode + '" is not an existing bidder.', 'adapterManager.aliasBidAdapter'); }) } else { try { @@ -533,11 +524,11 @@ adapterManager.aliasBidAdapter = function (bidderCode, alias, options) { supportedMediaTypes }); } catch (e) { - logError(bidderCode + ' bidder does not currently support aliasing.', 'adapterManager.aliasBidAdapter'); + utils.logError(bidderCode + ' bidder does not currently support aliasing.', 'adapterManager.aliasBidAdapter'); } } } else { - logMessage('alias name "' + alias + '" has been already specified.'); + utils.logMessage('alias name "' + alias + '" has been already specified.'); } }; @@ -547,25 +538,25 @@ adapterManager.registerAnalyticsAdapter = function ({adapter, code, gvlid}) { adapter.code = code; _analyticsRegistry[code] = { adapter, gvlid }; } else { - logError(`Prebid Error: Analytics adaptor error for analytics "${code}" + utils.logError(`Prebid Error: Analytics adaptor error for analytics "${code}" analytics adapter must implement an enableAnalytics() function`); } } else { - logError('Prebid Error: analyticsAdapter or analyticsCode not specified'); + utils.logError('Prebid Error: analyticsAdapter or analyticsCode not specified'); } }; adapterManager.enableAnalytics = function (config) { - if (!isArray(config)) { + if (!utils.isArray(config)) { config = [config]; } - _each(config, adapterConfig => { + utils._each(config, adapterConfig => { var adapter = _analyticsRegistry[adapterConfig.provider].adapter; if (adapter) { adapter.enableAnalytics(adapterConfig); } else { - logError(`Prebid Error: no analytics adapter found in registry for + utils.logError(`Prebid Error: no analytics adapter found in registry for ${adapterConfig.provider}.`); } }); @@ -590,22 +581,22 @@ function tryCallBidderMethod(bidder, method, param) { const adapter = _bidderRegistry[bidder]; const spec = adapter.getSpec(); if (spec && spec[method] && typeof spec[method] === 'function') { - logInfo(`Invoking ${bidder}.${method}`); + utils.logInfo(`Invoking ${bidder}.${method}`); config.runWithBidder(bidder, bind.call(spec[method], spec, param)); } } catch (e) { - logWarn(`Error calling ${method} of ${bidder}`); + utils.logWarn(`Error calling ${method} of ${bidder}`); } } adapterManager.callTimedOutBidders = function(adUnits, timedOutBidders, cbTimeout) { timedOutBidders = timedOutBidders.map((timedOutBidder) => { // Adding user configured params & timeout to timeout event data - timedOutBidder.params = getUserConfiguredParams(adUnits, timedOutBidder.adUnitCode, timedOutBidder.bidder); + timedOutBidder.params = utils.getUserConfiguredParams(adUnits, timedOutBidder.adUnitCode, timedOutBidder.bidder); timedOutBidder.timeout = cbTimeout; return timedOutBidder; }); - timedOutBidders = groupBy(timedOutBidders, 'bidder'); + timedOutBidders = utils.groupBy(timedOutBidders, 'bidder'); Object.keys(timedOutBidders).forEach((bidder) => { tryCallBidderMethod(bidder, 'onTimeout', timedOutBidders[bidder]); @@ -614,7 +605,7 @@ adapterManager.callTimedOutBidders = function(adUnits, timedOutBidders, cbTimeou adapterManager.callBidWonBidder = function(bidder, bid, adUnits) { // Adding user configured params to bidWon event data - bid.params = getUserConfiguredParams(adUnits, bid.adUnitCode, bid.bidder); + bid.params = utils.getUserConfiguredParams(adUnits, bid.adUnitCode, bid.bidder); adunitCounter.incrementBidderWinsCounter(bid.adUnitCode, bid.bidder); tryCallBidderMethod(bidder, 'onBidWon', bid); }; @@ -627,9 +618,4 @@ adapterManager.callBidViewableBidder = function(bidder, bid) { tryCallBidderMethod(bidder, 'onBidViewable', bid); }; -adapterManager.callBidderError = function(bidder, error, bidderRequest) { - const param = { error, bidderRequest }; - tryCallBidderMethod(bidder, 'onBidderError', param); -}; - export default adapterManager; diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index fc736926dd7..c71c4ee355b 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -230,7 +230,6 @@ export function newBidder(spec) { // Server requests have returned and been processed. Since `ajax` accepts a single callback, // we need to rig up a function which only executes after all the requests have been responded. const onResponse = delayExecution(configEnabledCallback(afterAllResponses), requests.length) - requests.forEach(_ => events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP, bidderRequest)); requests.forEach(processRequest); function formatGetParameters(data) { @@ -278,8 +277,8 @@ export function newBidder(spec) { } // If the server responds successfully, use the adapter code to unpack the Bids from it. - // If the adapter code fails, no bids should be added. After all the bids have been added, - // make sure to call the `onResponse` function so that we're one step closer to calling done(). + // If the adapter code fails, no bids should be added. After all the bids have been added, make + // sure to call the `onResponse` function so that we're one step closer to calling done(). function onSuccess(response, responseObj) { onTimelyResponse(spec.code); @@ -335,11 +334,10 @@ export function newBidder(spec) { // If the server responds with an error, there's not much we can do. Log it, and make sure to // call onResponse() so that we're one step closer to calling done(). - function onFailure(errorMessage, error) { + function onFailure(err) { onTimelyResponse(spec.code); - adapterManager.callBidderError(spec.code, error, bidderRequest) - events.emit(CONSTANTS.EVENTS.BIDDER_ERROR, { error, bidderRequest }); - logError(`Server call for ${spec.code} failed: ${errorMessage} ${error.status}. Continuing without bids.`); + + logError(`Server call for ${spec.code} failed: ${err}. Continuing without bids.`); onResponse(); } } diff --git a/src/adloader.js b/src/adloader.js index 9039fa14c4c..5460cc79410 100644 --- a/src/adloader.js +++ b/src/adloader.js @@ -1,5 +1,5 @@ import includes from 'core-js-pure/features/array/includes.js'; -import { logError, logWarn, insertElement } from './utils.js'; +import * as utils from './utils.js'; const _requestCache = {}; // The below list contains modules or vendors whom Prebid allows to load external JS. @@ -20,11 +20,11 @@ const _approvedLoadExternalJSList = [ */ export function loadExternalScript(url, moduleCode, callback) { if (!moduleCode || !url) { - logError('cannot load external script without url and moduleCode'); + utils.logError('cannot load external script without url and moduleCode'); return; } if (!includes(_approvedLoadExternalJSList, moduleCode)) { - logError(`${moduleCode} not whitelisted for loading external JavaScript`); + utils.logError(`${moduleCode} not whitelisted for loading external JavaScript`); return; } // only load each asset once @@ -49,7 +49,7 @@ export function loadExternalScript(url, moduleCode, callback) { _requestCache[url].callbacks.push(callback); } - logWarn(`module ${moduleCode} is loading external JavaScript`); + utils.logWarn(`module ${moduleCode} is loading external JavaScript`); return requestResource(url, function () { _requestCache[url].loaded = true; try { @@ -57,7 +57,7 @@ export function loadExternalScript(url, moduleCode, callback) { _requestCache[url].callbacks[i](); } } catch (e) { - logError('Error executing callback', 'adloader.js:loadExternalScript', e); + utils.logError('Error executing callback', 'adloader.js:loadExternalScript', e); } }); @@ -84,7 +84,7 @@ export function loadExternalScript(url, moduleCode, callback) { jptScript.src = tagSrc; // add the new script tag to the page - insertElement(jptScript); + utils.insertElement(jptScript); return jptScript; } diff --git a/src/ajax.js b/src/ajax.js index 5e926f3210d..a6317e7963d 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -1,5 +1,6 @@ import { config } from './config.js'; -import { logMessage, logError, parseUrl, buildUrl, _each } from './utils.js'; + +var utils = require('./utils.js'); const XHR_DONE = 4; @@ -24,10 +25,10 @@ export function ajaxBuilder(timeout = 3000, {request, done} = {}) { let callbacks = typeof callback === 'object' && callback !== null ? callback : { success: function() { - logMessage('xhr success'); + utils.logMessage('xhr success'); }, error: function(e) { - logError('xhr error', null, e); + utils.logError('xhr error', null, e); } }; @@ -54,14 +55,14 @@ export function ajaxBuilder(timeout = 3000, {request, done} = {}) { // Disabled timeout temporarily to avoid xhr failed requests. https://github.com/prebid/Prebid.js/issues/2648 if (!config.getConfig('disableAjaxTimeout')) { x.ontimeout = function () { - logError(' xhr timeout after ', x.timeout, 'ms'); + utils.logError(' xhr timeout after ', x.timeout, 'ms'); }; } if (method === 'GET' && data) { - let urlInfo = parseUrl(url, options); + let urlInfo = utils.parseUrl(url, options); Object.assign(urlInfo.search, data); - url = buildUrl(urlInfo); + url = utils.buildUrl(urlInfo); } x.open(method, url, true); @@ -74,7 +75,7 @@ export function ajaxBuilder(timeout = 3000, {request, done} = {}) { if (options.withCredentials) { x.withCredentials = true; } - _each(options.customHeaders, (value, header) => { + utils._each(options.customHeaders, (value, header) => { x.setRequestHeader(header, value); }); if (options.preflight) { @@ -92,7 +93,7 @@ export function ajaxBuilder(timeout = 3000, {request, done} = {}) { x.send(); } } catch (error) { - logError('xhr construction', error); + utils.logError('xhr construction', error); typeof callback === 'object' && callback !== null && callback.error(error); } } diff --git a/src/auction.js b/src/auction.js index 175f08439d1..a6f0342e582 100644 --- a/src/auction.js +++ b/src/auction.js @@ -57,10 +57,7 @@ * @property {function(): void} callBids - sends requests to all adapters for bids */ -import { - flatten, timestamp, adUnitsFilter, deepAccess, getBidRequest, getValue, parseUrl, generateUUID, - logMessage, bind, logError, logInfo, logWarn, isEmpty, _each, isFn, isEmptyStr, isAllowZeroCpmBidsEnabled -} from './utils.js'; +import {flatten, timestamp, adUnitsFilter, deepAccess, getBidRequest, getValue, parseUrl} from './utils.js'; import { getPriceBucketString } from './cpmBucketManager.js'; import { getNativeTargeting } from './native.js'; import { getCacheUrl, store } from './videoCache.js'; @@ -74,7 +71,7 @@ import { OUTSTREAM } from './video.js'; import { VIDEO } from './mediaTypes.js'; const { syncUsers } = userSync; - +const utils = require('./utils.js'); const adapterManager = require('./adapterManager.js').default; const events = require('./events.js'); const CONSTANTS = require('./constants.json'); @@ -115,7 +112,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a let _noBids = []; let _auctionStart; let _auctionEnd; - let _auctionId = auctionId || generateUUID(); + let _auctionId = auctionId || utils.generateUUID(); let _auctionStatus; let _callback = callback; let _timer; @@ -160,7 +157,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a if (_auctionEnd === undefined) { let timedOutBidders = []; if (timedOut) { - logMessage(`Auction ${_auctionId} timedOut`); + utils.logMessage(`Auction ${_auctionId} timedOut`); timedOutBidders = getTimedOutBids(_bidderRequests, _timelyBidders); if (timedOutBidders.length) { events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, timedOutBidders); @@ -176,13 +173,13 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a if (_callback != null) { const adUnitCodes = _adUnitCodes; const bids = _bidsReceived - .filter(bind.call(adUnitsFilter, this, adUnitCodes)) + .filter(utils.bind.call(adUnitsFilter, this, adUnitCodes)) .reduce(groupByPlacement, {}); _callback.apply($$PREBID_GLOBAL$$, [bids, timedOut, _auctionId]); _callback = null; } } catch (e) { - logError('Error executing bidsBackHandler', null, e); + utils.logError('Error executing bidsBackHandler', null, e); } finally { // Calling timed out bidders if (timedOutBidders.length) { @@ -202,7 +199,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a function auctionDone() { config.resetBidder(); // when all bidders have called done callback atleast once it means auction is complete - logInfo(`Bids Received for Auction with id: ${_auctionId}`, _bidsReceived); + utils.logInfo(`Bids Received for Auction with id: ${_auctionId}`, _bidsReceived); _auctionStatus = AUCTION_COMPLETED; executeCallback(false, true); } @@ -216,10 +213,10 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a _auctionStart = Date.now(); let bidRequests = adapterManager.makeBidRequests(_adUnits, _auctionStart, _auctionId, _timeout, _labels); - logInfo(`Bids Requested for Auction with id: ${_auctionId}`, bidRequests); + utils.logInfo(`Bids Requested for Auction with id: ${_auctionId}`, bidRequests); if (bidRequests.length < 1) { - logWarn('No valid bid requests returned for auction'); + utils.logWarn('No valid bid requests returned for auction'); auctionDone(); } else { addBidderRequests.call({ @@ -282,7 +279,7 @@ export function newAuction({adUnits, adUnitCodes, callback, cbTimeout, labels, a }; if (!runIfOriginHasCapacity(call)) { - logWarn('queueing auction due to limited endpoint capacity'); + utils.logWarn('queueing auction due to limited endpoint capacity'); queuedCalls.push(call); } @@ -407,7 +404,7 @@ export function auctionCallbacks(auctionDone, auctionInstance) { bidderRequestsDone.add(bidderRequest); - if (auctionOptionsConfig && !isEmpty(auctionOptionsConfig)) { + if (auctionOptionsConfig && !utils.isEmpty(auctionOptionsConfig)) { const secondaryBidders = auctionOptionsConfig.secondaryBidders; if (secondaryBidders && !bidderRequests.every(bidder => includes(secondaryBidders, bidder.bidderCode))) { bidderRequests = bidderRequests.filter(request => !includes(secondaryBidders, request.bidderCode)); @@ -466,7 +463,7 @@ function tryAddVideoBid(auctionInstance, bidResponse, bidRequests, afterBidAdded addBid = false; callPrebidCache(auctionInstance, bidResponse, afterBidAdded, bidderRequest); } else if (!bidResponse.vastUrl) { - logError('videoCacheKey specified but not required vastUrl for video bid'); + utils.logError('videoCacheKey specified but not required vastUrl for video bid'); addBid = false; } } @@ -479,12 +476,12 @@ function tryAddVideoBid(auctionInstance, bidResponse, bidRequests, afterBidAdded export const callPrebidCache = hook('async', function(auctionInstance, bidResponse, afterBidAdded, bidderRequest) { store([bidResponse], function (error, cacheIds) { if (error) { - logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`); + utils.logWarn(`Failed to save to the video cache: ${error}. Video bid must be discarded.`); doCallbacksIfTimedout(auctionInstance, bidResponse); } else { if (cacheIds[0].uuid === '') { - logWarn(`Supplied video cache key was already in use by Prebid Cache; caching attempt was rejected. Video bid must be discarded.`); + utils.logWarn(`Supplied video cache key was already in use by Prebid Cache; caching attempt was rejected. Video bid must be discarded.`); doCallbacksIfTimedout(auctionInstance, bidResponse); } else { @@ -567,9 +564,8 @@ function getPreparedBidForAuction({adUnitCode, bid, bidderRequest, auctionId}) { function setupBidTargeting(bidObject, bidderRequest) { let keyValues; - const cpmCheck = (isAllowZeroCpmBidsEnabled(bidObject.bidderCode)) ? bidObject.cpm >= 0 : bidObject.cpm > 0; - if (bidObject.bidderCode && (cpmCheck || bidObject.dealId)) { - let bidReq = find(bidderRequest.bids, bid => bid.adUnitCode === bidObject.adUnitCode && bid.bidId === bidObject.requestId); + if (bidObject.bidderCode && (bidObject.cpm > 0 || bidObject.dealId)) { + let bidReq = find(bidderRequest.bids, bid => bid.adUnitCode === bidObject.adUnitCode); keyValues = getKeyValueTargetingPairs(bidObject.bidderCode, bidObject, bidReq); } @@ -614,8 +610,7 @@ export const getPriceGranularity = (mediaType, bidReq) => { * @returns {function} */ export const getPriceByGranularity = (granularity) => { - return (bid, bidReq) => { - granularity = granularity || getPriceGranularity(bid.mediaType, bidReq); + return (bid) => { if (granularity === CONSTANTS.GRANULARITY_OPTIONS.AUTO) { return bid.pbAg; } else if (granularity === CONSTANTS.GRANULARITY_OPTIONS.DENSE) { @@ -648,14 +643,14 @@ export const getAdvertiserDomain = () => { * @param {BidRequest} bidReq * @returns {*} */ -export function getStandardBidderSettings(mediaType, bidderCode) { +export function getStandardBidderSettings(mediaType, bidderCode, bidReq) { // factory for key value objs function createKeyVal(key, value) { return { key, val: (typeof value === 'function') - ? function (bidResponse, bidReq) { - return value(bidResponse, bidReq); + ? function (bidResponse) { + return value(bidResponse); } : function (bidResponse) { return getValue(bidResponse, value); @@ -663,6 +658,7 @@ export function getStandardBidderSettings(mediaType, bidderCode) { }; } const TARGETING_KEYS = CONSTANTS.TARGETING_KEYS; + const granularity = getPriceGranularity(mediaType, bidReq); let bidderSettings = $$PREBID_GLOBAL$$.bidderSettings; if (!bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD]) { @@ -672,7 +668,7 @@ export function getStandardBidderSettings(mediaType, bidderCode) { bidderSettings[CONSTANTS.JSON_MAPPING.BD_SETTING_STANDARD][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING] = [ createKeyVal(TARGETING_KEYS.BIDDER, 'bidderCode'), createKeyVal(TARGETING_KEYS.AD_ID, 'adId'), - createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity()), + createKeyVal(TARGETING_KEYS.PRICE_BUCKET, getPriceByGranularity(granularity)), createKeyVal(TARGETING_KEYS.SIZE, 'size'), createKeyVal(TARGETING_KEYS.DEAL, 'dealId'), createKeyVal(TARGETING_KEYS.SOURCE, 'source'), @@ -692,12 +688,12 @@ export function getStandardBidderSettings(mediaType, bidderCode) { }); // Adding hb_cache_host - if (config.getConfig('cache.url') && (!bidderCode || deepAccess(bidderSettings, `${bidderCode}.sendStandardTargeting`) !== false)) { + if (config.getConfig('cache.url') && (!bidderCode || utils.deepAccess(bidderSettings, `${bidderCode}.sendStandardTargeting`) !== false)) { const urlInfo = parseUrl(config.getConfig('cache.url')); if (typeof find(adserverTargeting, targetingKeyVal => targetingKeyVal.key === TARGETING_KEYS.CACHE_HOST) === 'undefined') { adserverTargeting.push(createKeyVal(TARGETING_KEYS.CACHE_HOST, function(bidResponse) { - return deepAccess(bidResponse, `adserverTargeting.${TARGETING_KEYS.CACHE_HOST}`) + return utils.deepAccess(bidResponse, `adserverTargeting.${TARGETING_KEYS.CACHE_HOST}`) ? bidResponse.adserverTargeting[TARGETING_KEYS.CACHE_HOST] : urlInfo.hostname; })); } @@ -717,12 +713,12 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) { // 1) set the keys from "standard" setting or from prebid defaults if (bidderSettings) { // initialize default if not set - const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode); - setKeys(keyValues, standardSettings, custBidObj, bidReq); + const standardSettings = getStandardBidderSettings(custBidObj.mediaType, bidderCode, bidReq); + setKeys(keyValues, standardSettings, custBidObj); // 2) set keys from specific bidder setting override if they exist if (bidderCode && bidderSettings[bidderCode] && bidderSettings[bidderCode][CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]) { - setKeys(keyValues, bidderSettings[bidderCode], custBidObj, bidReq); + setKeys(keyValues, bidderSettings[bidderCode], custBidObj); custBidObj.sendStandardTargeting = bidderSettings[bidderCode].sendStandardTargeting; } } @@ -735,23 +731,23 @@ export function getKeyValueTargetingPairs(bidderCode, custBidObj, bidReq) { return keyValues; } -function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { +function setKeys(keyValues, bidderSettings, custBidObj) { var targeting = bidderSettings[CONSTANTS.JSON_MAPPING.ADSERVER_TARGETING]; custBidObj.size = custBidObj.getSize(); - _each(targeting, function (kvPair) { + utils._each(targeting, function (kvPair) { var key = kvPair.key; var value = kvPair.val; if (keyValues[key]) { - logWarn('The key: ' + key + ' is being overwritten'); + utils.logWarn('The key: ' + key + ' is getting ovewritten'); } - if (isFn(value)) { + if (utils.isFn(value)) { try { - value = value(custBidObj, bidReq); + value = value(custBidObj); } catch (e) { - logError('bidmanager', 'ERROR', e); + utils.logError('bidmanager', 'ERROR', e); } } @@ -759,12 +755,12 @@ function setKeys(keyValues, bidderSettings, custBidObj, bidReq) { ((typeof bidderSettings.suppressEmptyKeys !== 'undefined' && bidderSettings.suppressEmptyKeys === true) || key === CONSTANTS.TARGETING_KEYS.DEAL) && // hb_deal is suppressed automatically if not set ( - isEmptyStr(value) || + utils.isEmptyStr(value) || value === null || value === undefined ) ) { - logInfo("suppressing empty key '" + key + "' from adserver targeting"); + utils.logInfo("suppressing empty key '" + key + "' from adserver targeting"); } else { keyValues[key] = value; } @@ -787,7 +783,7 @@ export function adjustBids(bid) { try { bidPriceAdjusted = bidCpmAdjustment(bid.cpm, Object.assign({}, bid)); } catch (e) { - logError('Error during bid adjustment', 'bidmanager.js', e); + utils.logError('Error during bid adjustment', 'bidmanager.js', e); } } } diff --git a/src/bidfactory.js b/src/bidfactory.js index e15112f1735..8701184c799 100644 --- a/src/bidfactory.js +++ b/src/bidfactory.js @@ -1,4 +1,4 @@ -import { getUniqueIdentifierStr } from './utils.js'; +var utils = require('./utils.js'); /** Required paramaters @@ -22,7 +22,7 @@ function Bid(statusCode, bidRequest) { this.width = 0; this.height = 0; this.statusMessage = _getStatus(); - this.adId = getUniqueIdentifierStr(); + this.adId = utils.getUniqueIdentifierStr(); this.requestId = bidRequest && bidRequest.bidId; this.mediaType = 'banner'; this.source = _bidSrc; diff --git a/src/config.js b/src/config.js index ddf3b79a6af..00cf1efd854 100644 --- a/src/config.js +++ b/src/config.js @@ -1,6 +1,6 @@ /* * Module for getting and setting Prebid configuration. -*/ + */ /** * @typedef {Object} MediaTypePriceGranularity @@ -16,15 +16,13 @@ import { isValidPriceConfig } from './cpmBucketManager.js'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; import Set from 'core-js-pure/features/set'; -import { - mergeDeep, deepClone, getParameterByName, isPlainObject, logMessage, logWarn, logError, - isArray, isStr, isBoolean, deepAccess, bind -} from './utils.js'; +import { mergeDeep } from './utils.js'; const from = require('core-js-pure/features/array/from.js'); +const utils = require('./utils.js'); const CONSTANTS = require('./constants.json'); -const DEFAULT_DEBUG = getParameterByName(CONSTANTS.DEBUG_MODE).toUpperCase() === 'TRUE'; +const DEFAULT_DEBUG = utils.getParameterByName(CONSTANTS.DEBUG_MODE).toUpperCase() === 'TRUE'; const DEFAULT_BIDDER_TIMEOUT = 3000; const DEFAULT_PUBLISHER_DOMAIN = window.location.origin; const DEFAULT_ENABLE_SEND_ALL_BIDS = true; @@ -105,10 +103,10 @@ export function newConfig() { if (validatePriceGranularity(val)) { if (typeof val === 'string') { this._priceGranularity = (hasGranularity(val)) ? val : GRANULARITY_OPTIONS.MEDIUM; - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { this._customPriceBucket = val; this._priceGranularity = GRANULARITY_OPTIONS.CUSTOM; - logMessage('Using custom price granularity'); + utils.logMessage('Using custom price granularity'); } } }, @@ -135,12 +133,12 @@ export function newConfig() { if (validatePriceGranularity(val[item])) { if (typeof val === 'string') { aggregate[item] = (hasGranularity(val[item])) ? val[item] : this._priceGranularity; - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { aggregate[item] = val[item]; - logMessage(`Using custom price granularity for ${item}`); + utils.logMessage(`Using custom price granularity for ${item}`); } } else { - logWarn(`Invalid price granularity for media type: ${item}`); + utils.logWarn(`Invalid price granularity for media type: ${item}`); } return aggregate; }, {}); @@ -182,7 +180,7 @@ export function newConfig() { if (VALID_ORDERS[val]) { this._bidderSequence = val; } else { - logWarn(`Invalid order: ${val}. Bidder Sequence was not set.`); + utils.logWarn(`Invalid order: ${val}. Bidder Sequence was not set.`); } }, @@ -244,16 +242,16 @@ export function newConfig() { function validatePriceGranularity(val) { if (!val) { - logError('Prebid Error: no value passed to `setPriceGranularity()`'); + utils.logError('Prebid Error: no value passed to `setPriceGranularity()`'); return false; } if (typeof val === 'string') { if (!hasGranularity(val)) { - logWarn('Prebid Warning: setPriceGranularity was called with invalid setting, using `medium` as default.'); + utils.logWarn('Prebid Warning: setPriceGranularity was called with invalid setting, using `medium` as default.'); } - } else if (isPlainObject(val)) { + } else if (utils.isPlainObject(val)) { if (!isValidPriceConfig(val)) { - logError('Invalid custom price value passed to `setPriceGranularity()`'); + utils.logError('Invalid custom price value passed to `setPriceGranularity()`'); return false; } } @@ -261,27 +259,27 @@ export function newConfig() { } function validateauctionOptions(val) { - if (!isPlainObject(val)) { - logWarn('Auction Options must be an object') + if (!utils.isPlainObject(val)) { + utils.logWarn('Auction Options must be an object') return false } for (let k of Object.keys(val)) { if (k !== 'secondaryBidders' && k !== 'suppressStaleRender') { - logWarn(`Auction Options given an incorrect param: ${k}`) + utils.logWarn(`Auction Options given an incorrect param: ${k}`) return false } if (k === 'secondaryBidders') { - if (!isArray(val[k])) { - logWarn(`Auction Options ${k} must be of type Array`); + if (!utils.isArray(val[k])) { + utils.logWarn(`Auction Options ${k} must be of type Array`); return false - } else if (!val[k].every(isStr)) { - logWarn(`Auction Options ${k} must be only string`); + } else if (!val[k].every(utils.isStr)) { + utils.logWarn(`Auction Options ${k} must be only string`); return false } } else if (k === 'suppressStaleRender') { - if (!isBoolean(val[k])) { - logWarn(`Auction Options ${k} must be of type boolean`); + if (!utils.isBoolean(val[k])) { + utils.logWarn(`Auction Options ${k} must be of type boolean`); return false; } } @@ -295,7 +293,7 @@ export function newConfig() { * @private */ function _getConfig() { - if (currBidder && bidderConfig && isPlainObject(bidderConfig[currBidder])) { + if (currBidder && bidderConfig && utils.isPlainObject(bidderConfig[currBidder])) { let currBidderConfig = bidderConfig[currBidder]; const configTopicSet = new Set(Object.keys(config).concat(Object.keys(currBidderConfig))); @@ -305,7 +303,7 @@ export function newConfig() { } else if (typeof config[topic] === 'undefined') { memo[topic] = currBidderConfig[topic]; } else { - if (isPlainObject(currBidderConfig[topic])) { + if (utils.isPlainObject(currBidderConfig[topic])) { memo[topic] = mergeDeep({}, config[topic], currBidderConfig[topic]); } else { memo[topic] = currBidderConfig[topic]; @@ -317,26 +315,6 @@ export function newConfig() { return Object.assign({}, config); } - /* - * Returns the configuration object if called without parameters, - * or single configuration property if given a string matching a configuration - * property name. Allows deep access e.g. getConfig('currency.adServerCurrency') - * - * If called with callback parameter, or a string and a callback parameter, - * subscribes to configuration updates. See `subscribe` function for usage. - * - * The object returned is a deepClone of the `config` property. - */ - function readConfig(...args) { - if (args.length <= 1 && typeof args[0] !== 'function') { - const option = args[0]; - const configClone = deepClone(_getConfig()); - return option ? deepAccess(configClone, option) : configClone; - } - - return subscribe(...args); - } - /* * Returns configuration object if called without parameters, * or single configuration property if given a string matching a configuration @@ -348,7 +326,7 @@ export function newConfig() { function getConfig(...args) { if (args.length <= 1 && typeof args[0] !== 'function') { const option = args[0]; - return option ? deepAccess(_getConfig(), option) : _getConfig(); + return option ? utils.deepAccess(_getConfig(), option) : _getConfig(); } return subscribe(...args); @@ -373,9 +351,9 @@ export function newConfig() { let prop = (type === 'site') ? 'context' : type; duplicate[prop] = (prop === 'context' || prop === 'user') ? Object.keys(obj[type]).filter(key => key !== 'data').reduce((result, key) => { if (key === 'ext') { - mergeDeep(result, obj[type][key]); + utils.mergeDeep(result, obj[type][key]); } else { - mergeDeep(result, {[key]: obj[type][key]}); + utils.mergeDeep(result, {[key]: obj[type][key]}); } return result; @@ -393,14 +371,14 @@ export function newConfig() { let duplicate = {}; - if (deepAccess(obj, 'ext.data')) { + if (utils.deepAccess(obj, 'ext.data')) { Object.keys(obj.ext.data).forEach((key) => { if (key === 'pbadslot') { - mergeDeep(duplicate, {context: {pbAdSlot: obj.ext.data[key]}}); + utils.mergeDeep(duplicate, {context: {pbAdSlot: obj.ext.data[key]}}); } else if (key === 'adserver') { - mergeDeep(duplicate, {context: {adServer: obj.ext.data[key]}}); + utils.mergeDeep(duplicate, {context: {adServer: obj.ext.data[key]}}); } else { - mergeDeep(duplicate, {context: {data: {[key]: obj.ext.data[key]}}}); + utils.mergeDeep(duplicate, {context: {data: {[key]: obj.ext.data[key]}}}); } }); } @@ -418,9 +396,9 @@ export function newConfig() { let prop = (type === 'context') ? 'site' : type; duplicate[prop] = (prop === 'site' || prop === 'user') ? Object.keys(opt[type]).reduce((result, key) => { if (key === 'data') { - mergeDeep(result, {ext: {data: opt[type][key]}}); + utils.mergeDeep(result, {ext: {data: opt[type][key]}}); } else { - mergeDeep(result, {[key]: opt[type][key]}); + utils.mergeDeep(result, {[key]: opt[type][key]}); } return result; @@ -440,14 +418,14 @@ export function newConfig() { Object.keys(opt).filter(prop => prop === 'context').forEach((type) => { Object.keys(opt[type]).forEach((key) => { if (key === 'data') { - mergeDeep(duplicate, {ext: {data: opt[type][key]}}); + utils.mergeDeep(duplicate, {ext: {data: opt[type][key]}}); } else { if (typeof opt[type][key] === 'object' && !Array.isArray(opt[type][key])) { Object.keys(opt[type][key]).forEach(data => { - mergeDeep(duplicate, {ext: {data: {[key.toLowerCase()]: {[data.toLowerCase()]: opt[type][key][data]}}}}); + utils.mergeDeep(duplicate, {ext: {data: {[key.toLowerCase()]: {[data.toLowerCase()]: opt[type][key][data]}}}}); }); } else { - mergeDeep(duplicate, {ext: {data: {[key.toLowerCase()]: opt[type][key]}}}); + utils.mergeDeep(duplicate, {ext: {data: {[key.toLowerCase()]: opt[type][key]}}}); } } }); @@ -464,7 +442,7 @@ export function newConfig() { arr.forEach((adunit) => { if (adunit.fpd) { - (adunit['ortb2Imp']) ? mergeDeep(adunit['ortb2Imp'], convertImpFpd(adunit.fpd)) : adunit['ortb2Imp'] = convertImpFpd(adunit.fpd); + (adunit['ortb2Imp']) ? utils.mergeDeep(adunit['ortb2Imp'], convertImpFpd(adunit.fpd)) : adunit['ortb2Imp'] = convertImpFpd(adunit.fpd); convert.push((({ fpd, ...duplicate }) => duplicate)(adunit)); } else { convert.push(adunit); @@ -479,8 +457,8 @@ export function newConfig() { * listeners that were added by the `subscribe` function */ function setConfig(options) { - if (!isPlainObject(options)) { - logError('setConfig options must be an object'); + if (!utils.isPlainObject(options)) { + utils.logError('setConfig options must be an object'); return; } @@ -491,7 +469,7 @@ export function newConfig() { let prop = (topic === 'fpd') ? 'ortb2' : topic; let option = (topic === 'fpd') ? convertFpd(options[topic]) : options[topic]; - if (isPlainObject(defaults[prop]) && isPlainObject(option)) { + if (utils.isPlainObject(defaults[prop]) && utils.isPlainObject(option)) { option = Object.assign({}, defaults[prop], option); } @@ -506,8 +484,8 @@ export function newConfig() { * @param {object} options */ function setDefaults(options) { - if (!isPlainObject(defaults)) { - logError('defaults must be an object'); + if (!utils.isPlainObject(defaults)) { + utils.logError('defaults must be an object'); return; } @@ -548,7 +526,7 @@ export function newConfig() { } if (typeof callback !== 'function') { - logError('listener must be a function'); + utils.logError('listener must be a function'); return; } @@ -580,7 +558,7 @@ export function newConfig() { .forEach(listener => listener.callback(options)); } - function setBidderConfig(config, mergeFlag = false) { + function setBidderConfig(config) { try { check(config); config.bidders.forEach(bidder => { @@ -591,51 +569,29 @@ export function newConfig() { let prop = (topic === 'fpd') ? 'ortb2' : topic; let option = (topic === 'fpd') ? convertFpd(config.config[topic]) : config.config[topic]; - if (isPlainObject(option)) { - const func = mergeFlag ? mergeDeep : Object.assign; - bidderConfig[bidder][prop] = func({}, bidderConfig[bidder][prop] || {}, option); + if (utils.isPlainObject(option)) { + bidderConfig[bidder][prop] = Object.assign({}, bidderConfig[bidder][prop] || {}, option); } else { bidderConfig[bidder][prop] = option; } }); }); } catch (e) { - logError(e); + utils.logError(e); } - function check(obj) { - if (!isPlainObject(obj)) { + if (!utils.isPlainObject(obj)) { throw 'setBidderConfig bidder options must be an object'; } if (!(Array.isArray(obj.bidders) && obj.bidders.length)) { throw 'setBidderConfig bidder options must contain a bidders list with at least 1 bidder'; } - if (!isPlainObject(obj.config)) { + if (!utils.isPlainObject(obj.config)) { throw 'setBidderConfig bidder options must contain a config object'; } } } - function mergeConfig(obj) { - if (!isPlainObject(obj)) { - logError('mergeConfig input must be an object'); - return; - } - - const mergedConfig = Object.keys(obj).reduce((accum, key) => { - const prevConf = _getConfig(key)[key] || {}; - accum[key] = mergeDeep(prevConf, obj[key]); - return accum; - }, {}); - - setConfig({ ...mergedConfig }); - return mergedConfig; - } - - function mergeBidderConfig(obj) { - return setBidderConfig(obj, true); - } - /** * Internal functions for core to execute some synchronous code while having an active bidder set. */ @@ -651,9 +607,9 @@ export function newConfig() { return function(cb) { return function(...args) { if (typeof cb === 'function') { - return runWithBidder(bidder, bind.call(cb, this, ...args)) + return runWithBidder(bidder, utils.bind.call(cb, this, ...args)) } else { - logWarn('config.callbackWithBidder callback is not a function'); + utils.logWarn('config.callbackWithBidder callback is not a function'); } } } @@ -673,16 +629,13 @@ export function newConfig() { getCurrentBidder, resetBidder, getConfig, - readConfig, setConfig, - mergeConfig, setDefaults, resetConfig, runWithBidder, callbackWithBidder, setBidderConfig, getBidderConfig, - mergeBidderConfig, convertAdUnitFpd, getLegacyFpd, getLegacyImpFpd diff --git a/src/constants.json b/src/constants.json index 055ccd8aacb..77d87e056d9 100644 --- a/src/constants.json +++ b/src/constants.json @@ -32,10 +32,8 @@ "NO_BID": "noBid", "BID_WON": "bidWon", "BIDDER_DONE": "bidderDone", - "BIDDER_ERROR": "bidderError", "SET_TARGETING": "setTargeting", "BEFORE_REQUEST_BIDS": "beforeRequestBids", - "BEFORE_BIDDER_HTTP": "beforeBidderHttp", "REQUEST_BIDS": "requestBids", "ADD_AD_UNITS": "addAdUnits", "AD_RENDER_FAILED": "adRenderFailed", diff --git a/src/cpmBucketManager.js b/src/cpmBucketManager.js index b90dc8df717..a6b76cc38e2 100644 --- a/src/cpmBucketManager.js +++ b/src/cpmBucketManager.js @@ -1,5 +1,5 @@ import find from 'core-js-pure/features/array/find.js'; -import { isEmpty } from './utils.js'; +const utils = require('./utils.js'); const _defaultPrecision = 2; const _lgPriceConfig = { @@ -102,7 +102,7 @@ function getCpmStringValue(cpm, config, granularityMultiplier) { } function isValidPriceConfig(config) { - if (isEmpty(config) || !config.buckets || !Array.isArray(config.buckets)) { + if (utils.isEmpty(config) || !config.buckets || !Array.isArray(config.buckets)) { return false; } let isValid = true; diff --git a/src/hook.js b/src/hook.js index 2c8e4c7a6e7..9050bf2f7dc 100644 --- a/src/hook.js +++ b/src/hook.js @@ -13,18 +13,14 @@ export function setupBeforeHookFnOnce(baseFn, hookFn, priority = 15) { baseFn.before(hookFn, priority); } } -const submoduleInstallMap = {}; -export function module(name, install, {postInstallAllowed = false} = {}) { +export function module(name, install) { hook('async', function (submodules) { submodules.forEach(args => install(...args)); - if (postInstallAllowed) submoduleInstallMap[name] = install; }, name)([]); // will be queued until hook.ready() called in pbjs.processQueue(); } export function submodule(name, ...args) { - const install = submoduleInstallMap[name]; - if (install) return install(...args); getHook(name).before((next, modules) => { modules.push(args); next(modules); diff --git a/src/prebid.js b/src/prebid.js index e59ee6cded6..3264a5fc60b 100644 --- a/src/prebid.js +++ b/src/prebid.js @@ -1,12 +1,7 @@ /** @module pbjs */ import { getGlobal } from './prebidGlobal.js'; -import { - adUnitsFilter, flatten, getHighestCpm, isArrayOfNums, isGptPubadsDefined, uniques, logInfo, - contains, logError, isArray, deepClone, deepAccess, isNumber, logWarn, logMessage, isFn, - transformAdServerTargetingObj, bind, replaceAuctionPrice, replaceClickThrough, insertElement, - inIframe, callBurl, createInvisibleIframe, generateUUID, unsupportedBidderMessage, isEmpty -} from './utils.js'; +import { adUnitsFilter, flatten, getHighestCpm, isArrayOfNums, isGptPubadsDefined, uniques } from './utils.js'; import { listenMessagesFromCreative } from './secureCreatives.js'; import { userSync } from './userSync.js'; import { config } from './config.js'; @@ -22,6 +17,7 @@ import { storageCallbacks } from './storageManager.js'; const $$PREBID_GLOBAL$$ = getGlobal(); const CONSTANTS = require('./constants.json'); +const utils = require('./utils.js'); const adapterManager = require('./adapterManager.js').default; const events = require('./events.js'); const { triggerUserSyncs } = userSync; @@ -45,9 +41,10 @@ $$PREBID_GLOBAL$$.libLoaded = true; // version auto generated from build $$PREBID_GLOBAL$$.version = 'v$prebid.version$'; -logInfo('Prebid.js v$prebid.version$ loaded'); +utils.logInfo('Prebid.js v$prebid.version$ loaded'); -$$PREBID_GLOBAL$$.installedModules = $$PREBID_GLOBAL$$.installedModules || []; +// modules list generated from build +$$PREBID_GLOBAL$$.installedModules = ['v$prebid.modulesList$']; // create adUnit array $$PREBID_GLOBAL$$.adUnits = $$PREBID_GLOBAL$$.adUnits || []; @@ -60,8 +57,8 @@ function checkDefinedPlacement(id) { .reduce(flatten) .filter(uniques); - if (!contains(adUnitCodes, id)) { - logError('The "' + id + '" placement is not defined.'); + if (!utils.contains(adUnitCodes, id)) { + utils.logError('The "' + id + '" placement is not defined.'); return; } @@ -77,7 +74,7 @@ function setRenderSize(doc, width, height) { function validateSizes(sizes, targLength) { let cleanSizes = []; - if (isArray(sizes) && ((targLength) ? sizes.length === targLength : sizes.length > 0)) { + if (utils.isArray(sizes) && ((targLength) ? sizes.length === targLength : sizes.length > 0)) { // check if an array of arrays or array of numbers if (sizes.every(sz => isArrayOfNums(sz, 2))) { cleanSizes = sizes; @@ -89,7 +86,7 @@ function validateSizes(sizes, targLength) { } function validateBannerMediaType(adUnit) { - const validatedAdUnit = deepClone(adUnit); + const validatedAdUnit = utils.deepClone(adUnit); const banner = validatedAdUnit.mediaTypes.banner; const bannerSizes = validateSizes(banner.sizes); if (bannerSizes.length > 0) { @@ -97,14 +94,14 @@ function validateBannerMediaType(adUnit) { // Deprecation Warning: This property will be deprecated in next release in favor of adUnit.mediaTypes.banner.sizes validatedAdUnit.sizes = bannerSizes; } else { - logError('Detected a mediaTypes.banner object without a proper sizes field. Please ensure the sizes are listed like: [[300, 250], ...]. Removing invalid mediaTypes.banner object from request.'); + utils.logError('Detected a mediaTypes.banner object without a proper sizes field. Please ensure the sizes are listed like: [[300, 250], ...]. Removing invalid mediaTypes.banner object from request.'); delete validatedAdUnit.mediaTypes.banner } return validatedAdUnit; } function validateVideoMediaType(adUnit) { - const validatedAdUnit = deepClone(adUnit); + const validatedAdUnit = utils.deepClone(adUnit); const video = validatedAdUnit.mediaTypes.video; if (video.playerSize) { let tarPlayerSizeLen = (typeof video.playerSize[0] === 'number') ? 2 : 1; @@ -112,13 +109,13 @@ function validateVideoMediaType(adUnit) { const videoSizes = validateSizes(video.playerSize, tarPlayerSizeLen); if (videoSizes.length > 0) { if (tarPlayerSizeLen === 2) { - logInfo('Transforming video.playerSize from [640,480] to [[640,480]] so it\'s in the proper format.'); + utils.logInfo('Transforming video.playerSize from [640,480] to [[640,480]] so it\'s in the proper format.'); } video.playerSize = videoSizes; // Deprecation Warning: This property will be deprecated in next release in favor of adUnit.mediaTypes.video.playerSize validatedAdUnit.sizes = videoSizes; } else { - logError('Detected incorrect configuration of mediaTypes.video.playerSize. Please specify only one set of dimensions in a format like: [[640, 480]]. Removing invalid mediaTypes.video.playerSize property from request.'); + utils.logError('Detected incorrect configuration of mediaTypes.video.playerSize. Please specify only one set of dimensions in a format like: [[640, 480]]. Removing invalid mediaTypes.video.playerSize property from request.'); delete validatedAdUnit.mediaTypes.video.playerSize; } } @@ -126,30 +123,30 @@ function validateVideoMediaType(adUnit) { } function validateNativeMediaType(adUnit) { - const validatedAdUnit = deepClone(adUnit); + const validatedAdUnit = utils.deepClone(adUnit); const native = validatedAdUnit.mediaTypes.native; if (native.image && native.image.sizes && !Array.isArray(native.image.sizes)) { - logError('Please use an array of sizes for native.image.sizes field. Removing invalid mediaTypes.native.image.sizes property from request.'); + utils.logError('Please use an array of sizes for native.image.sizes field. Removing invalid mediaTypes.native.image.sizes property from request.'); delete validatedAdUnit.mediaTypes.native.image.sizes; } if (native.image && native.image.aspect_ratios && !Array.isArray(native.image.aspect_ratios)) { - logError('Please use an array of sizes for native.image.aspect_ratios field. Removing invalid mediaTypes.native.image.aspect_ratios property from request.'); + utils.logError('Please use an array of sizes for native.image.aspect_ratios field. Removing invalid mediaTypes.native.image.aspect_ratios property from request.'); delete validatedAdUnit.mediaTypes.native.image.aspect_ratios; } if (native.icon && native.icon.sizes && !Array.isArray(native.icon.sizes)) { - logError('Please use an array of sizes for native.icon.sizes field. Removing invalid mediaTypes.native.icon.sizes property from request.'); + utils.logError('Please use an array of sizes for native.icon.sizes field. Removing invalid mediaTypes.native.icon.sizes property from request.'); delete validatedAdUnit.mediaTypes.native.icon.sizes; } return validatedAdUnit; } function validateAdUnitPos(adUnit, mediaType) { - let pos = deepAccess(adUnit, `mediaTypes.${mediaType}.pos`); + let pos = utils.deepAccess(adUnit, `mediaTypes.${mediaType}.pos`); - if (!pos || !isNumber(pos) || !isFinite(pos)) { + if (!pos || !utils.isNumber(pos) || !isFinite(pos)) { let warning = `Value of property 'pos' on ad unit ${adUnit.code} should be of type: Number`; - logWarn(warning); + utils.logWarn(warning); events.emit(CONSTANTS.EVENTS.AUCTION_DEBUG, {type: 'WARNING', arguments: warning}); delete adUnit.mediaTypes[mediaType].pos; } @@ -172,13 +169,13 @@ export const checkAdUnitSetup = hook('sync', function (adUnits) { const bids = adUnit.bids; let validatedBanner, validatedVideo, validatedNative; - if (!bids || !isArray(bids)) { - logError(`Detected adUnit.code '${adUnit.code}' did not have 'adUnit.bids' defined or 'adUnit.bids' is not an array. Removing adUnit from auction.`); + if (!bids || !utils.isArray(bids)) { + utils.logError(`Detected adUnit.code '${adUnit.code}' did not have 'adUnit.bids' defined or 'adUnit.bids' is not an array. Removing adUnit from auction.`); return; } if (!mediaTypes || Object.keys(mediaTypes).length === 0) { - logError(`Detected adUnit.code '${adUnit.code}' did not have a 'mediaTypes' object defined. This is a required field for the auction, so this adUnit has been removed.`); + utils.logError(`Detected adUnit.code '${adUnit.code}' did not have a 'mediaTypes' object defined. This is a required field for the auction, so this adUnit has been removed.`); return; } @@ -217,14 +214,14 @@ export const checkAdUnitSetup = hook('sync', function (adUnits) { * @return {Array} returnObj return bids array */ $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr = function (adunitCode) { - logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCodeStr', arguments); // call to retrieve bids array if (adunitCode) { var res = $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCode(adunitCode); - return transformAdServerTargetingObj(res); + return utils.transformAdServerTargetingObj(res); } else { - logMessage('Need to call getAdserverTargetingForAdUnitCodeStr with adunitCode'); + utils.logMessage('Need to call getAdserverTargetingForAdUnitCodeStr with adunitCode'); } }; @@ -242,7 +239,7 @@ $$PREBID_GLOBAL$$.getHighestUnusedBidResponseForAdUnitCode = function (adunitCod return bid.length ? bid.reduce(getHighestCpm) : {} } else { - logMessage('Need to call getHighestUnusedBidResponseForAdUnitCode with adunitCode'); + utils.logMessage('Need to call getHighestUnusedBidResponseForAdUnitCode with adunitCode'); } }; @@ -263,13 +260,13 @@ $$PREBID_GLOBAL$$.getAdserverTargetingForAdUnitCode = function (adUnitCode) { */ $$PREBID_GLOBAL$$.getAdserverTargeting = function (adUnitCode) { - logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargeting', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getAdserverTargeting', arguments); return targeting.getAllTargeting(adUnitCode); }; function getBids(type) { const responses = auctionManager[type]() - .filter(bind.call(adUnitsFilter, this, auctionManager.getAdUnitCodes())); + .filter(utils.bind.call(adUnitsFilter, this, auctionManager.getAdUnitCodes())); // find the last auction id to get responses for most recent auction only const currentAuctionId = auctionManager.getLastAuctionId(); @@ -294,7 +291,7 @@ function getBids(type) { */ $$PREBID_GLOBAL$$.getNoBids = function () { - logInfo('Invoking $$PREBID_GLOBAL$$.getNoBids', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getNoBids', arguments); return getBids('getNoBids'); }; @@ -317,7 +314,7 @@ $$PREBID_GLOBAL$$.getNoBidsForAdUnitCode = function (adUnitCode) { */ $$PREBID_GLOBAL$$.getBidResponses = function () { - logInfo('Invoking $$PREBID_GLOBAL$$.getBidResponses', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getBidResponses', arguments); return getBids('getBidsReceived'); }; @@ -340,9 +337,9 @@ $$PREBID_GLOBAL$$.getBidResponsesForAdUnitCode = function (adUnitCode) { * @alias module:pbjs.setTargetingForGPTAsync */ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit, customSlotMatching) { - logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForGPTAsync', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForGPTAsync', arguments); if (!isGptPubadsDefined()) { - logError('window.googletag is not defined on the page'); + utils.logError('window.googletag is not defined on the page'); return; } @@ -373,9 +370,9 @@ $$PREBID_GLOBAL$$.setTargetingForGPTAsync = function (adUnit, customSlotMatching * @alias module:pbjs.setTargetingForAst */ $$PREBID_GLOBAL$$.setTargetingForAst = function (adUnitCodes) { - logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForAn', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.setTargetingForAn', arguments); if (!targeting.isApntagDefined()) { - logError('window.apntag is not defined on the page'); + utils.logError('window.apntag is not defined on the page'); return; } @@ -390,7 +387,7 @@ function emitAdRenderFail({ reason, message, bid, id }) { if (bid) data.bid = bid; if (id) data.adId = id; - logError(message); + utils.logError(message); events.emit(AD_RENDER_FAILED, data); } @@ -402,29 +399,16 @@ function emitAdRenderSucceeded({ doc, bid, id }) { events.emit(AD_RENDER_SUCCEEDED, data); } -/** - * This function will check for presence of given node in given parent. If not present - will inject it. - * @param {Node} node node, whose existance is in question - * @param {Document} doc document element do look in - * @param {string} tagName tag name to look in - */ -function reinjectNodeIfRemoved(node, doc, tagName) { - const injectionNode = doc.querySelector(tagName); - if (!node.parentNode || node.parentNode !== injectionNode) { - insertElement(node, doc, tagName); - } -} - /** * This function will render the ad (based on params) in the given iframe document passed through. * Note that doc SHOULD NOT be the parent document page as we can't doc.write() asynchronously - * @param {Document} doc document + * @param {HTMLDocument} doc document * @param {string} id bid id to locate the ad * @alias module:pbjs.renderAd */ $$PREBID_GLOBAL$$.renderAd = hook('async', function (doc, id, options) { - logInfo('Invoking $$PREBID_GLOBAL$$.renderAd', arguments); - logMessage('Calling renderAd with adId :' + id); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.renderAd', arguments); + utils.logMessage('Calling renderAd with adId :' + id); if (doc && id) { try { @@ -434,23 +418,23 @@ $$PREBID_GLOBAL$$.renderAd = hook('async', function (doc, id, options) { if (bid) { let shouldRender = true; if (bid && bid.status === CONSTANTS.BID_STATUS.RENDERED) { - logWarn(`Ad id ${bid.adId} has been rendered before`); + utils.logWarn(`Ad id ${bid.adId} has been rendered before`); events.emit(STALE_RENDER, bid); - if (deepAccess(config.getConfig('auctionOptions'), 'suppressStaleRender')) { + if (utils.deepAccess(config.getConfig('auctionOptions'), 'suppressStaleRender')) { shouldRender = false; } } if (shouldRender) { // replace macros according to openRTB with price paid = bid.cpm - bid.ad = replaceAuctionPrice(bid.ad, bid.cpm); - bid.adUrl = replaceAuctionPrice(bid.adUrl, bid.cpm); + bid.ad = utils.replaceAuctionPrice(bid.ad, bid.cpm); + bid.adUrl = utils.replaceAuctionPrice(bid.adUrl, bid.cpm); // replacing clickthrough if submitted if (options && options.clickThrough) { const {clickThrough} = options; - bid.ad = replaceClickThrough(bid.ad, clickThrough); - bid.adUrl = replaceClickThrough(bid.adUrl, clickThrough); + bid.ad = utils.replaceClickThrough(bid.ad, clickThrough); + bid.adUrl = utils.replaceClickThrough(bid.adUrl, clickThrough); } // save winning bids @@ -462,13 +446,12 @@ $$PREBID_GLOBAL$$.renderAd = hook('async', function (doc, id, options) { const {height, width, ad, mediaType, adUrl, renderer} = bid; const creativeComment = document.createComment(`Creative ${bid.creativeId} served by ${bid.bidder} Prebid.js Header Bidding`); - insertElement(creativeComment, doc, 'html'); if (isRendererRequired(renderer)) { executeRenderer(renderer, bid); - reinjectNodeIfRemoved(creativeComment, doc, 'html'); + utils.insertElement(creativeComment, doc, 'html'); emitAdRenderSucceeded({ doc, bid, id }); - } else if ((doc === document && !inIframe()) || mediaType === 'video') { + } else if ((doc === document && !utils.inIframe()) || mediaType === 'video') { const message = `Error trying to write ad. Ad render call ad id ${id} was prevented from writing to the main document.`; emitAdRenderFail({reason: PREVENT_WRITING_ON_MAIN_DOCUMENT, message, bid, id}); } else if (ad) { @@ -485,21 +468,21 @@ $$PREBID_GLOBAL$$.renderAd = hook('async', function (doc, id, options) { doc.write(ad); doc.close(); setRenderSize(doc, width, height); - reinjectNodeIfRemoved(creativeComment, doc, 'html'); - callBurl(bid); + utils.insertElement(creativeComment, doc, 'html'); + utils.callBurl(bid); emitAdRenderSucceeded({ doc, bid, id }); } else if (adUrl) { - const iframe = createInvisibleIframe(); + const iframe = utils.createInvisibleIframe(); iframe.height = height; iframe.width = width; iframe.style.display = 'inline'; iframe.style.overflow = 'hidden'; iframe.src = adUrl; - insertElement(iframe, doc, 'body'); + utils.insertElement(iframe, doc, 'body'); setRenderSize(doc, width, height); - reinjectNodeIfRemoved(creativeComment, doc, 'html'); - callBurl(bid); + utils.insertElement(creativeComment, doc, 'html'); + utils.callBurl(bid); emitAdRenderSucceeded({ doc, bid, id }); } else { const message = `Error trying to write ad. No ad for bid response id: ${id}`; @@ -526,7 +509,7 @@ $$PREBID_GLOBAL$$.renderAd = hook('async', function (doc, id, options) { * @alias module:pbjs.removeAdUnit */ $$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) { - logInfo('Invoking $$PREBID_GLOBAL$$.removeAdUnit', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.removeAdUnit', arguments); if (!adUnitCode) { $$PREBID_GLOBAL$$.adUnits = []; @@ -535,7 +518,7 @@ $$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) { let adUnitCodes; - if (isArray(adUnitCode)) { + if (utils.isArray(adUnitCode)) { adUnitCodes = adUnitCode; } else { adUnitCodes = [adUnitCode]; @@ -563,9 +546,9 @@ $$PREBID_GLOBAL$$.removeAdUnit = function (adUnitCode) { $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeout, adUnits, adUnitCodes, labels, auctionId } = {}) { events.emit(REQUEST_BIDS); const cbTimeout = timeout || config.getConfig('bidderTimeout'); - adUnits = (adUnits && config.convertAdUnitFpd(isArray(adUnits) ? adUnits : [adUnits])) || $$PREBID_GLOBAL$$.adUnits; + adUnits = (adUnits && config.convertAdUnitFpd(utils.isArray(adUnits) ? adUnits : [adUnits])) || $$PREBID_GLOBAL$$.adUnits; - logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.requestBids', arguments); let _s2sConfigs = []; const s2sBidders = []; @@ -605,7 +588,7 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo const bidders = (s2sBidders) ? allBidders.filter(bidder => !includes(s2sBidders, bidder)) : allBidders; - adUnit.transactionId = generateUUID(); + adUnit.transactionId = utils.generateUUID(); bidders.forEach(bidder => { const adapter = bidderRegistry[bidder]; @@ -617,7 +600,7 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo const bidderEligible = adUnitMediaTypes.some(type => includes(bidderMediaTypes, type)); if (!bidderEligible) { // drop the bidder from the ad unit if it's not compatible - logWarn(unsupportedBidderMessage(adUnit, bidder)); + utils.logWarn(utils.unsupportedBidderMessage(adUnit, bidder)); adUnit.bids = adUnit.bids.filter(bid => bid.bidder !== bidder); } else { adunitCounter.incrementBidderRequestsCounter(adUnit.code, bidder); @@ -627,13 +610,13 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo }); if (!adUnits || adUnits.length === 0) { - logMessage('No adUnits configured. No bids requested.'); + utils.logMessage('No adUnits configured. No bids requested.'); if (typeof bidsBackHandler === 'function') { // executeCallback, this will only be called in case of first request try { bidsBackHandler(); } catch (e) { - logError('Error executing bidsBackHandler', null, e); + utils.logError('Error executing bidsBackHandler', null, e); } } return; @@ -643,7 +626,7 @@ $$PREBID_GLOBAL$$.requestBids = hook('async', function ({ bidsBackHandler, timeo let adUnitsLen = adUnits.length; if (adUnitsLen > 15) { - logInfo(`Current auction ${auction.getAuctionId()} contains ${adUnitsLen} adUnits.`, adUnits); + utils.logInfo(`Current auction ${auction.getAuctionId()} contains ${adUnitsLen} adUnits.`, adUnits); } adUnitCodes.forEach(code => targeting.setLatestAuctionForAdUnit(code, auction.getAuctionId())); @@ -673,8 +656,8 @@ $$PREBID_GLOBAL$$.requestBids.before(executeCallbacks, 49); * @alias module:pbjs.addAdUnits */ $$PREBID_GLOBAL$$.addAdUnits = function (adUnitArr) { - logInfo('Invoking $$PREBID_GLOBAL$$.addAdUnits', arguments); - $$PREBID_GLOBAL$$.adUnits.push.apply($$PREBID_GLOBAL$$.adUnits, config.convertAdUnitFpd(isArray(adUnitArr) ? adUnitArr : [adUnitArr])); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.addAdUnits', arguments); + $$PREBID_GLOBAL$$.adUnits.push.apply($$PREBID_GLOBAL$$.adUnits, config.convertAdUnitFpd(utils.isArray(adUnitArr) ? adUnitArr : [adUnitArr])); // emit event events.emit(ADD_AD_UNITS); }; @@ -696,14 +679,14 @@ $$PREBID_GLOBAL$$.addAdUnits = function (adUnitArr) { * Currently `bidWon` is the only event that accepts an `id` parameter. */ $$PREBID_GLOBAL$$.onEvent = function (event, handler, id) { - logInfo('Invoking $$PREBID_GLOBAL$$.onEvent', arguments); - if (!isFn(handler)) { - logError('The event handler provided is not a function and was not set on event "' + event + '".'); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.onEvent', arguments); + if (!utils.isFn(handler)) { + utils.logError('The event handler provided is not a function and was not set on event "' + event + '".'); return; } if (id && !eventValidators[event].call(null, id)) { - logError('The id provided is not valid for event "' + event + '" and no handler was set.'); + utils.logError('The id provided is not valid for event "' + event + '" and no handler was set.'); return; } @@ -717,7 +700,7 @@ $$PREBID_GLOBAL$$.onEvent = function (event, handler, id) { * @alias module:pbjs.offEvent */ $$PREBID_GLOBAL$$.offEvent = function (event, handler, id) { - logInfo('Invoking $$PREBID_GLOBAL$$.offEvent', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.offEvent', arguments); if (id && !eventValidators[event].call(null, id)) { return; } @@ -731,7 +714,7 @@ $$PREBID_GLOBAL$$.offEvent = function (event, handler, id) { * @alias module:pbjs.getEvents */ $$PREBID_GLOBAL$$.getEvents = function () { - logInfo('Invoking $$PREBID_GLOBAL$$.getEvents'); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.getEvents'); return events.getEvents(); }; @@ -742,11 +725,11 @@ $$PREBID_GLOBAL$$.getEvents = function () { * @alias module:pbjs.registerBidAdapter */ $$PREBID_GLOBAL$$.registerBidAdapter = function (bidderAdaptor, bidderCode) { - logInfo('Invoking $$PREBID_GLOBAL$$.registerBidAdapter', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.registerBidAdapter', arguments); try { adapterManager.registerBidAdapter(bidderAdaptor(), bidderCode); } catch (e) { - logError('Error registering bidder adapter : ' + e.message); + utils.logError('Error registering bidder adapter : ' + e.message); } }; @@ -756,11 +739,11 @@ $$PREBID_GLOBAL$$.registerBidAdapter = function (bidderAdaptor, bidderCode) { * @alias module:pbjs.registerAnalyticsAdapter */ $$PREBID_GLOBAL$$.registerAnalyticsAdapter = function (options) { - logInfo('Invoking $$PREBID_GLOBAL$$.registerAnalyticsAdapter', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.registerAnalyticsAdapter', arguments); try { adapterManager.registerAnalyticsAdapter(options); } catch (e) { - logError('Error registering analytics adapter : ' + e.message); + utils.logError('Error registering analytics adapter : ' + e.message); } }; @@ -771,7 +754,7 @@ $$PREBID_GLOBAL$$.registerAnalyticsAdapter = function (options) { * @return {Object} bidResponse [description] */ $$PREBID_GLOBAL$$.createBid = function (statusCode) { - logInfo('Invoking $$PREBID_GLOBAL$$.createBid', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.createBid', arguments); return createBid(statusCode); }; @@ -794,11 +777,11 @@ $$PREBID_GLOBAL$$.createBid = function (statusCode) { const enableAnalyticsCallbacks = []; const enableAnalyticsCb = hook('async', function (config) { - if (config && !isEmpty(config)) { - logInfo('Invoking $$PREBID_GLOBAL$$.enableAnalytics for: ', config); + if (config && !utils.isEmpty(config)) { + utils.logInfo('Invoking $$PREBID_GLOBAL$$.enableAnalytics for: ', config); adapterManager.enableAnalytics(config); } else { - logError('$$PREBID_GLOBAL$$.enableAnalytics should be called with option {}'); + utils.logError('$$PREBID_GLOBAL$$.enableAnalytics should be called with option {}'); } }, 'enableAnalyticsCb'); @@ -810,11 +793,11 @@ $$PREBID_GLOBAL$$.enableAnalytics = function (config) { * @alias module:pbjs.aliasBidder */ $$PREBID_GLOBAL$$.aliasBidder = function (bidderCode, alias, options) { - logInfo('Invoking $$PREBID_GLOBAL$$.aliasBidder', arguments); + utils.logInfo('Invoking $$PREBID_GLOBAL$$.aliasBidder', arguments); if (bidderCode && alias) { adapterManager.aliasBidAdapter(bidderCode, alias, options); } else { - logError('bidderCode and alias must be passed as arguments', '$$PREBID_GLOBAL$$.aliasBidder'); + utils.logError('bidderCode and alias must be passed as arguments', '$$PREBID_GLOBAL$$.aliasBidder'); } }; @@ -900,7 +883,7 @@ $$PREBID_GLOBAL$$.markWinningBidAsUsed = function (markBidRequest) { } else if (markBidRequest.adId) { bids = auctionManager.getBidsReceived().filter(bid => bid.adId === markBidRequest.adId); } else { - logWarn('Improper use of markWinningBidAsUsed. It needs an adUnitCode or an adId to function.'); + utils.logWarn('Improper use of markWinningBidAsUsed. It needs an adUnitCode or an adId to function.'); } if (bids.length > 0) { @@ -914,9 +897,6 @@ $$PREBID_GLOBAL$$.markWinningBidAsUsed = function (markBidRequest) { * @alias module:pbjs.getConfig */ $$PREBID_GLOBAL$$.getConfig = config.getConfig; -$$PREBID_GLOBAL$$.readConfig = config.readConfig; -$$PREBID_GLOBAL$$.mergeConfig = config.mergeConfig; -$$PREBID_GLOBAL$$.mergeBidderConfig = config.mergeBidderConfig; /** * Set Prebid config options. @@ -994,10 +974,10 @@ $$PREBID_GLOBAL$$.cmd.push = function (command) { try { command.call(); } catch (e) { - logError('Error processing command :', e.message, e.stack); + utils.logError('Error processing command :', e.message, e.stack); } } else { - logError('Commands written into $$PREBID_GLOBAL$$.cmd.push must be wrapped in a function'); + utils.logError('Commands written into $$PREBID_GLOBAL$$.cmd.push must be wrapped in a function'); } }; @@ -1010,7 +990,7 @@ function processQueue(queue) { cmd.call(); cmd.called = true; } catch (e) { - logError('Error processing command :', 'prebid.js', e); + utils.logError('Error processing command :', 'prebid.js', e); } } }); diff --git a/src/secureCreatives.js b/src/secureCreatives.js index 01a84ae254a..60e60688c64 100644 --- a/src/secureCreatives.js +++ b/src/secureCreatives.js @@ -60,6 +60,7 @@ export function receiveMessage(ev) { if (data.action === 'assetRequest') { const message = getAssetMessage(data, adObject); ev.source.postMessage(JSON.stringify(message), ev.origin); + return; } else if (data.action === 'allAssetRequest') { const message = getAllAssetsMessage(data, adObject); ev.source.postMessage(JSON.stringify(message), ev.origin); @@ -67,13 +68,13 @@ export function receiveMessage(ev) { adObject.height = data.height; adObject.width = data.width; resizeRemoteCreative(adObject); - } else { - const trackerType = fireNativeTrackers(data, adObject); - if (trackerType === 'click') { return; } - - auctionManager.addWinningBid(adObject); - events.emit(BID_WON, adObject); } + + const trackerType = fireNativeTrackers(data, adObject); + if (trackerType === 'click') { return; } + + auctionManager.addWinningBid(adObject); + events.emit(BID_WON, adObject); } } } @@ -127,12 +128,11 @@ function resizeRemoteCreative({ adId, adUnitCode, width, height }) { } function getDfpElementId(adId) { - const slot = find(window.googletag.pubads().getSlots(), slot => { + return find(window.googletag.pubads().getSlots(), slot => { return find(slot.getTargetingKeys(), key => { return includes(slot.getTargeting(key), adId); }); - }); - return slot ? slot.getSlotElementId() : null; + }).getSlotElementId(); } function getAstElementId(adUnitCode) { diff --git a/src/storageManager.js b/src/storageManager.js index 888cdf24325..66a0cf68cbf 100644 --- a/src/storageManager.js +++ b/src/storageManager.js @@ -1,5 +1,5 @@ import {hook} from './hook.js'; -import { hasDeviceAccess, checkCookieSupport, logError } from './utils.js'; +import * as utils from './utils.js'; import includes from 'core-js-pure/features/array/includes.js'; const moduleTypeWhiteList = ['core', 'prebid-module']; @@ -40,7 +40,7 @@ export function newStorageManager({gvlid, moduleName, moduleType} = {}) { } else { let result = { hasEnforcementHook: false, - valid: hasDeviceAccess() + valid: utils.hasDeviceAccess() } value = cb(result); } @@ -135,7 +135,7 @@ export function newStorageManager({gvlid, moduleName, moduleType} = {}) { const cookiesAreEnabled = function (done) { let cb = function (result) { if (result && result.valid) { - if (checkCookieSupport()) { + if (utils.checkCookieSupport()) { return true; } window.document.cookie = 'prebid.cookieTest'; @@ -222,7 +222,7 @@ export function newStorageManager({gvlid, moduleName, moduleType} = {}) { try { return !!window.localStorage; } catch (e) { - logError('Local storage api disabled'); + utils.logError('Local storage api disabled'); } } return false; @@ -247,7 +247,7 @@ export function newStorageManager({gvlid, moduleName, moduleType} = {}) { let cb = function (result) { if (result && result.valid) { const all = []; - if (hasDeviceAccess()) { + if (utils.hasDeviceAccess()) { const cookies = document.cookie.split(';'); while (cookies.length) { const cookie = cookies.pop(); diff --git a/src/targeting.js b/src/targeting.js index 423e946896e..4bbed7bb758 100644 --- a/src/targeting.js +++ b/src/targeting.js @@ -1,7 +1,4 @@ -import { - uniques, isGptPubadsDefined, getHighestCpm, getOldestHighestCpmBid, groupBy, isAdUnitCodeMatchingSlot, timestamp, - deepAccess, deepClone, logError, logWarn, logInfo, isFn, isArray, logMessage, isStr, isAllowZeroCpmBidsEnabled -} from './utils.js'; +import { uniques, isGptPubadsDefined, getHighestCpm, getOldestHighestCpmBid, groupBy, isAdUnitCodeMatchingSlot, timestamp, deepAccess, deepClone, logError, logWarn, logInfo } from './utils.js'; import { config } from './config.js'; import { NATIVE_TARGETING_KEYS } from './native.js'; import { auctionManager } from './auctionManager.js'; @@ -11,6 +8,7 @@ import { hook } from './hook.js'; import includes from 'core-js-pure/features/array/includes.js'; import find from 'core-js-pure/features/array/find.js'; +const utils = require('./utils.js'); var CONSTANTS = require('./constants.json'); var pbTargetingKeys = []; @@ -18,10 +16,6 @@ var pbTargetingKeys = []; const MAX_DFP_KEYLENGTH = 20; const TTL_BUFFER = 1000; -const CFG_ALLOW_TARGETING_KEYS = `targetingControls.allowTargetingKeys`; -const CFG_ADD_TARGETING_KEYS = `targetingControls.addTargetingKeys`; -const TARGETING_KEY_CONFIGURATION_ERROR_MSG = `Only one of "${CFG_ALLOW_TARGETING_KEYS}" or "${CFG_ADD_TARGETING_KEYS}" can be set`; - export const TARGETING_KEYS = Object.keys(CONSTANTS.TARGETING_KEYS).map( key => CONSTANTS.TARGETING_KEYS[key] ); @@ -127,19 +121,17 @@ export function newTargeting(auctionManager) { if (isGptPubadsDefined()) { const adUnitCodes = getAdUnitCodes(adUnitCode); const adUnits = auctionManager.getAdUnits().filter(adUnit => includes(adUnitCodes, adUnit.code)); - let unsetKeys = pbTargetingKeys.reduce((reducer, key) => { - reducer[key] = null; - return reducer; - }, {}); window.googletag.pubads().getSlots().forEach(slot => { - let customSlotMatchingFunc = isFn(customSlotMatching) && customSlotMatching(slot); - // reset only registered adunits - adUnits.forEach(unit => { - if (unit.code === slot.getAdUnitPath() || - unit.code === slot.getSlotElementId() || - (isFn(customSlotMatchingFunc) && customSlotMatchingFunc(unit.code))) { - slot.updateTargetingFromMap(unsetKeys); - } + let customSlotMatchingFunc = utils.isFn(customSlotMatching) && customSlotMatching(slot); + pbTargetingKeys.forEach(function(key) { + // reset only registered adunits + adUnits.forEach(function(unit) { + if (unit.code === slot.getAdUnitPath() || + unit.code === slot.getSlotElementId() || + (utils.isFn(customSlotMatchingFunc) && customSlotMatchingFunc(unit.code))) { + slot.setTargeting(key, null); + } + }); }); }); } @@ -168,7 +160,7 @@ export function newTargeting(auctionManager) { */ function bidShouldBeAddedToTargeting(bid, adUnitCodes) { return bid.adserverTargeting && adUnitCodes && - ((isArray(adUnitCodes) && includes(adUnitCodes, bid.adUnitCode)) || + ((utils.isArray(adUnitCodes) && includes(adUnitCodes, bid.adUnitCode)) || (typeof adUnitCodes === 'string' && bid.adUnitCode === adUnitCodes)); }; @@ -265,17 +257,7 @@ export function newTargeting(auctionManager) { }); const defaultKeys = Object.keys(Object.assign({}, CONSTANTS.DEFAULT_TARGETING_KEYS, CONSTANTS.NATIVE_KEYS)); - let allowedKeys = config.getConfig(CFG_ALLOW_TARGETING_KEYS); - const addedKeys = config.getConfig(CFG_ADD_TARGETING_KEYS); - - if (addedKeys != null && allowedKeys != null) { - throw new Error(TARGETING_KEY_CONFIGURATION_ERROR_MSG); - } else if (addedKeys != null) { - allowedKeys = defaultKeys.concat(addedKeys); - } else { - allowedKeys = allowedKeys || defaultKeys; - } - + const allowedKeys = config.getConfig('targetingControls.allowTargetingKeys') || defaultKeys; if (Array.isArray(allowedKeys) && allowedKeys.length > 0) { targeting = getAllowedTargetingKeyValues(targeting, allowedKeys); } @@ -298,13 +280,6 @@ export function newTargeting(auctionManager) { return targeting; }; - // warn about conflicting configuration - config.getConfig('targetingControls', function (config) { - if (deepAccess(config, CFG_ALLOW_TARGETING_KEYS) != null && deepAccess(config, CFG_ADD_TARGETING_KEYS) != null) { - logError(TARGETING_KEY_CONFIGURATION_ERROR_MSG); - } - }); - // create an encoded string variant based on the keypairs of the provided object // - note this will encode the characters between the keys (ie = and &) function convertKeysToQueryForm(keyMap) { @@ -362,7 +337,7 @@ export function newTargeting(auctionManager) { * "div-gpt-ad-1460505748561-0": [{"hb_bidder": ["appnexusAst"]}] * }, * { - * "div-gpt-ad-1460505748561-0": [{"hb_bidder_appnexusAs": ["appnexusAst", "other"]}] + * "div-gpt-ad-1460505748561-0": [{"hb_bidder_appnexusAs": ["appnexusAst"]}] * } * ] * ``` @@ -371,7 +346,7 @@ export function newTargeting(auctionManager) { * { * "div-gpt-ad-1460505748561-0": { * "hb_bidder": "appnexusAst", - * "hb_bidder_appnexusAs": "appnexusAst,other" + * "hb_bidder_appnexusAs": "appnexusAst" * } * } * ``` @@ -385,7 +360,7 @@ export function newTargeting(auctionManager) { [Object.keys(targeting)[0]]: targeting[Object.keys(targeting)[0]] .map(target => { return { - [Object.keys(target)[0]]: target[Object.keys(target)[0]].join(',') + [Object.keys(target)[0]]: target[Object.keys(target)[0]].join(', ') }; }).reduce((p, c) => Object.assign(c, p), {}) }; @@ -404,18 +379,21 @@ export function newTargeting(auctionManager) { targeting.setTargetingForGPT = function(targetingConfig, customSlotMatching) { window.googletag.pubads().getSlots().forEach(slot => { Object.keys(targetingConfig).filter(customSlotMatching ? customSlotMatching(slot) : isAdUnitCodeMatchingSlot(slot)) - .forEach(targetId => { + .forEach(targetId => Object.keys(targetingConfig[targetId]).forEach(key => { - let value = targetingConfig[targetId][key]; - if (typeof value === 'string' && value.indexOf(',') !== -1) { - // due to the check the array will be formed only if string has ',' else plain string will be assigned as value - value = value.split(','); + let valueArr = targetingConfig[targetId][key]; + if (typeof valueArr === 'string') { + valueArr = valueArr.split(','); } - targetingConfig[targetId][key] = value; - }); - logMessage(`Attempting to set targeting-map for slot: ${slot.getSlotElementId()} with targeting-map:`, targetingConfig[targetId]); - slot.updateTargetingFromMap(targetingConfig[targetId]) - }) + valueArr = (valueArr.length > 1) ? [valueArr] : valueArr; + valueArr.map((value) => { + utils.logMessage(`Attempting to set key value for slot: ${slot.getSlotElementId()} key: ${key} value: ${value}`); + return value; + }).forEach(value => { + slot.setTargeting(key, value); + }); + }) + ) }) }; @@ -427,7 +405,7 @@ export function newTargeting(auctionManager) { function getAdUnitCodes(adUnitCode) { if (typeof adUnitCode === 'string') { return [adUnitCode]; - } else if (isArray(adUnitCode)) { + } else if (utils.isArray(adUnitCode)) { return adUnitCode; } return auctionManager.getAdUnitCodes() || []; @@ -459,7 +437,7 @@ export function newTargeting(auctionManager) { const adUnitCodes = getAdUnitCodes(adUnitCode); return bidsReceived .filter(bid => includes(adUnitCodes, bid.adUnitCode)) - .filter(bid => (isAllowZeroCpmBidsEnabled(bid.bidderCode)) ? bid.cpm >= 0 : bid.cpm > 0) + .filter(bid => bid.cpm > 0) .map(bid => bid.adUnitCode) .filter(uniques) .map(adUnitCode => bidsReceived @@ -477,14 +455,14 @@ export function newTargeting(auctionManager) { try { targeting.resetPresetTargetingAST(adUnitCodes); } catch (e) { - logError('unable to reset targeting for AST' + e) + utils.logError('unable to reset targeting for AST' + e) } Object.keys(astTargeting).forEach(targetId => Object.keys(astTargeting[targetId]).forEach(key => { - logMessage(`Attempting to set targeting for targetId: ${targetId} key: ${key} value: ${astTargeting[targetId][key]}`); + utils.logMessage(`Attempting to set targeting for targetId: ${targetId} key: ${key} value: ${astTargeting[targetId][key]}`); // setKeywords supports string and array as value - if (isStr(astTargeting[targetId][key]) || isArray(astTargeting[targetId][key])) { + if (utils.isStr(astTargeting[targetId][key]) || utils.isArray(astTargeting[targetId][key])) { let keywordsObj = {}; let regex = /pt[0-9]/; if (key.search(regex) < 0) { @@ -549,7 +527,7 @@ export function newTargeting(auctionManager) { function mergeAdServerTargeting(acc, bid, index, arr) { function concatTargetingValue(key) { return function(currentBidElement) { - if (!isArray(currentBidElement.adserverTargeting[key])) { + if (!utils.isArray(currentBidElement.adserverTargeting[key])) { currentBidElement.adserverTargeting[key] = [currentBidElement.adserverTargeting[key]]; } currentBidElement.adserverTargeting[key] = currentBidElement.adserverTargeting[key].concat(bid.adserverTargeting[key]).filter(uniques); @@ -656,8 +634,8 @@ export function newTargeting(auctionManager) { return Object.keys(aut) .map(function(key) { - if (isStr(aut[key])) aut[key] = aut[key].split(',').map(s => s.trim()); - if (!isArray(aut[key])) aut[key] = [ aut[key] ]; + if (utils.isStr(aut[key])) aut[key] = aut[key].split(','); + if (!utils.isArray(aut[key])) aut[key] = [ aut[key] ]; return { [key]: aut[key] }; }); } @@ -670,7 +648,7 @@ export function newTargeting(auctionManager) { } targeting.isApntagDefined = function() { - if (window.apntag && isFn(window.apntag.setKeywords)) { + if (window.apntag && utils.isFn(window.apntag.setKeywords)) { return true; } }; diff --git a/src/userSync.js b/src/userSync.js index 60e605f29fb..f653880fa29 100644 --- a/src/userSync.js +++ b/src/userSync.js @@ -1,7 +1,4 @@ -import { - deepClone, isPlainObject, logError, shuffle, logMessage, triggerPixel, insertUserSyncIframe, isArray, - logWarn, isStr, isSafariBrowser -} from './utils.js'; +import * as utils from './utils.js'; import { config } from './config.js'; import includes from 'core-js-pure/features/array/includes.js'; import { getCoreStorageManager } from './storageManager.js'; @@ -21,7 +18,7 @@ export const USERSYNC_DEFAULT_CONFIG = { // Set userSync default values config.setDefaults({ - 'userSync': deepClone(USERSYNC_DEFAULT_CONFIG) + 'userSync': utils.deepClone(USERSYNC_DEFAULT_CONFIG) }); const storage = getCoreStorageManager('usersync'); @@ -57,7 +54,7 @@ export function newUserSync(userSyncDependencies) { // if userSync.filterSettings does not contain image/all configs, merge in default image config to ensure image pixels are fired if (conf.userSync) { let fs = conf.userSync.filterSettings; - if (isPlainObject(fs)) { + if (utils.isPlainObject(fs)) { if (!fs.image && !fs.all) { conf.userSync.filterSettings.image = { bidders: '*', @@ -94,12 +91,12 @@ export function newUserSync(userSyncDependencies) { } try { - // Iframe syncs - loadIframes(); // Image pixels fireImagePixels(); + // Iframe syncs + loadIframes(); } catch (e) { - return logError('Error firing user syncs', e); + return utils.logError('Error firing user syncs', e); } // Reset the user sync queue queue = getDefaultQueue(); @@ -109,7 +106,7 @@ export function newUserSync(userSyncDependencies) { // Randomize the order of the pixels before firing // This is to avoid giving any bidder who has registered multiple syncs // any preferential treatment and balancing them out - shuffle(queue).forEach((sync) => { + utils.shuffle(queue).forEach((sync) => { fn(sync); hasFiredBidder.add(sync[0]); }); @@ -126,9 +123,9 @@ export function newUserSync(userSyncDependencies) { } forEachFire(queue.image, (sync) => { let [bidderName, trackingPixelUrl] = sync; - logMessage(`Invoking image pixel user sync for bidder: ${bidderName}`); + utils.logMessage(`Invoking image pixel user sync for bidder: ${bidderName}`); // Create image object and add the src url - triggerPixel(trackingPixelUrl); + utils.triggerPixel(trackingPixelUrl); }); } @@ -141,21 +138,11 @@ export function newUserSync(userSyncDependencies) { if (!(permittedPixels.iframe)) { return; } - forEachFire(queue.iframe, (sync) => { let [bidderName, iframeUrl] = sync; - logMessage(`Invoking iframe user sync for bidder: ${bidderName}`); + utils.logMessage(`Invoking iframe user sync for bidder: ${bidderName}`); // Insert iframe into DOM - insertUserSyncIframe(iframeUrl); - // for a bidder, if iframe sync is present then remove image pixel - removeImagePixelsForBidder(queue, bidderName); - }); - } - - function removeImagePixelsForBidder(queue, iframeSyncBidderName) { - queue.image = queue.image.filter(imageSync => { - let imageSyncBidderName = imageSync[0]; - return imageSyncBidderName !== iframeSyncBidderName + utils.insertUserSyncIframe(iframeUrl); }); } @@ -190,21 +177,21 @@ export function newUserSync(userSyncDependencies) { */ publicApi.registerSync = (type, bidder, url) => { if (hasFiredBidder.has(bidder)) { - return logMessage(`already fired syncs for "${bidder}", ignoring registerSync call`); + return utils.logMessage(`already fired syncs for "${bidder}", ignoring registerSync call`); } - if (!usConfig.syncEnabled || !isArray(queue[type])) { - return logWarn(`User sync type "${type}" not supported`); + if (!usConfig.syncEnabled || !utils.isArray(queue[type])) { + return utils.logWarn(`User sync type "${type}" not supported`); } if (!bidder) { - return logWarn(`Bidder is required for registering sync`); + return utils.logWarn(`Bidder is required for registering sync`); } if (usConfig.syncsPerBidder !== 0 && Number(numAdapterBids[bidder]) >= usConfig.syncsPerBidder) { - return logWarn(`Number of user syncs exceeded for "${bidder}"`); + return utils.logWarn(`Number of user syncs exceeded for "${bidder}"`); } const canBidderRegisterSync = publicApi.canBidderRegisterSync(type, bidder); if (!canBidderRegisterSync) { - return logWarn(`Bidder "${bidder}" not permitted to register their "${type}" userSync pixels.`); + return utils.logWarn(`Bidder "${bidder}" not permitted to register their "${type}" userSync pixels.`); } // the bidder's pixel has passed all checks and is allowed to register @@ -251,7 +238,7 @@ export function newUserSync(userSyncDependencies) { */ function isFilterConfigValid(filterConfig, type) { if (filterConfig.all && filterConfig[type]) { - logWarn(`Detected presence of the "filterSettings.all" and "filterSettings.${type}" in userSync config. You cannot mix "all" with "iframe/image" configs; they are mutually exclusive.`); + utils.logWarn(`Detected presence of the "filterSettings.all" and "filterSettings.${type}" in userSync config. You cannot mix "all" with "iframe/image" configs; they are mutually exclusive.`); return false; } @@ -268,12 +255,12 @@ export function newUserSync(userSyncDependencies) { let biddersField = activeConfig.bidders; if (filterField && filterField !== 'include' && filterField !== 'exclude') { - logWarn(`UserSync "filterSettings.${activeConfigName}.filter" setting '${filterField}' is not a valid option; use either 'include' or 'exclude'.`); + utils.logWarn(`UserSync "filterSettings.${activeConfigName}.filter" setting '${filterField}' is not a valid option; use either 'include' or 'exclude'.`); return false; } - if (biddersField !== '*' && !(Array.isArray(biddersField) && biddersField.length > 0 && biddersField.every(bidderInList => isStr(bidderInList) && bidderInList !== '*'))) { - logWarn(`Detected an invalid setup in userSync "filterSettings.${activeConfigName}.bidders"; use either '*' (to represent all bidders) or an array of bidders.`); + if (biddersField !== '*' && !(Array.isArray(biddersField) && biddersField.length > 0 && biddersField.every(bidderInList => utils.isStr(bidderInList) && bidderInList !== '*'))) { + utils.logWarn(`Detected an invalid setup in userSync "filterSettings.${activeConfigName}.bidders"; use either '*' (to represent all bidders) or an array of bidders.`); return false; } @@ -315,7 +302,7 @@ export function newUserSync(userSyncDependencies) { return publicApi; } -const browserSupportsCookies = !isSafariBrowser() && storage.cookiesAreEnabled(); +const browserSupportsCookies = !utils.isSafariBrowser() && storage.cookiesAreEnabled(); export const userSync = newUserSync({ config: config.getConfig('userSync'), diff --git a/src/utils.js b/src/utils.js index cbe1b1665aa..03c76529ddf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,6 +1,5 @@ /* eslint-disable no-console */ import { config } from './config.js'; -import { getGlobal } from './prebidGlobal.js'; import clone from 'just-clone'; import find from 'core-js-pure/features/array/find.js'; import includes from 'core-js-pure/features/array/includes.js'; @@ -482,43 +481,16 @@ export function insertElement(elm, doc, target, asLastChildChild) { } catch (e) {} } -/** - * Returns a promise that completes when the given element triggers a 'load' or 'error' DOM event, or when - * `timeout` milliseconds have elapsed. - * - * @param {HTMLElement} element - * @param {Number} [timeout] - * @returns {Promise} - */ -export function waitForElementToLoad(element, timeout) { - let timer = null; - return new Promise((resolve) => { - const onLoad = function() { - element.removeEventListener('load', onLoad); - element.removeEventListener('error', onLoad); - if (timer != null) { - window.clearTimeout(timer); - } - resolve(); - }; - element.addEventListener('load', onLoad); - element.addEventListener('error', onLoad); - if (timeout != null) { - timer = window.setTimeout(onLoad, timeout); - } - }); -} - /** * Inserts an image pixel with the specified `url` for cookie sync * @param {string} url URL string of the image pixel to load * @param {function} [done] an optional exit callback, used when this usersync pixel is added during an async process - * @param {Number} [timeout] an optional timeout in milliseconds for the image to load before calling `done` */ -export function triggerPixel(url, done, timeout) { +export function triggerPixel(url, done) { const img = new Image(); if (done && internal.isFn(done)) { - waitForElementToLoad(img, timeout).then(done); + img.addEventListener('load', done); + img.addEventListener('error', done); } img.src = url; } @@ -566,18 +538,18 @@ export function insertHtmlIntoIframe(htmlCode) { * @param {string} url URL to be requested * @param {string} encodeUri boolean if URL should be encoded before inserted. Defaults to true * @param {function} [done] an optional exit callback, used when this usersync pixel is added during an async process - * @param {Number} [timeout] an optional timeout in milliseconds for the iframe to load before calling `done` */ -export function insertUserSyncIframe(url, done, timeout) { +export function insertUserSyncIframe(url, done) { let iframeHtml = internal.createTrackPixelIframeHtml(url, false, 'allow-scripts allow-same-origin'); let div = document.createElement('div'); div.innerHTML = iframeHtml; let iframe = div.firstChild; if (done && internal.isFn(done)) { - waitForElementToLoad(iframe, timeout).then(done); + iframe.addEventListener('load', done); + iframe.addEventListener('error', done); } internal.insertElement(iframe, document, 'html', true); -} +}; /** * Creates a snippet of HTML that retrieves the specified `url` @@ -1272,18 +1244,7 @@ export function mergeDeep(target, ...sources) { if (!target[key]) { Object.assign(target, { [key]: source[key] }); } else if (isArray(target[key])) { - source[key].forEach(obj => { - let addItFlag = 1; - for (let i = 0; i < target[key].length; i++) { - if (deepEqual(target[key][i], obj)) { - addItFlag = 0; - break; - } - } - if (addItFlag) { - target[key].push(obj); - } - }); + target[key] = target[key].concat(source[key]); } } else { Object.assign(target, { [key]: source[key] }); @@ -1333,9 +1294,3 @@ export function cyrb53Hash(str, seed = 0) { h2 = imul(h2 ^ (h2 >>> 16), 2246822507) ^ imul(h1 ^ (h1 >>> 13), 3266489909); return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(); } - -export function isAllowZeroCpmBidsEnabled(bidderCode) { - const bidderSettings = getGlobal().bidderSettings; - return ((bidderSettings[bidderCode] && bidderSettings[bidderCode].allowZeroCpmBids === true) || - (bidderSettings.standard && bidderSettings.standard.allowZeroCpmBids === true)); -} diff --git a/src/videoCache.js b/src/videoCache.js index 57618024c32..9e378d90574 100644 --- a/src/videoCache.js +++ b/src/videoCache.js @@ -11,7 +11,7 @@ import { ajax } from './ajax.js'; import { config } from './config.js'; -import { isPlainObject } from './utils.js'; +import * as utils from './utils.js'; /** * @typedef {object} CacheableUrlBid @@ -73,7 +73,7 @@ function toStorageRequest(bid) { payload.bidid = bid.requestId; payload.aid = bid.auctionId; // function has a thisArg set to bidderRequest for accessing the auctionStart - if (isPlainObject(this) && this.hasOwnProperty('auctionStart')) { + if (utils.isPlainObject(this) && this.hasOwnProperty('auctionStart')) { payload.timestamp = this.auctionStart; } } diff --git a/test/.eslintrc.js b/test/.eslintrc.js index abb34438653..0ea3276dbaf 100644 --- a/test/.eslintrc.js +++ b/test/.eslintrc.js @@ -8,8 +8,7 @@ module.exports = { '$$PREBID_GLOBAL$$': false }, parserOptions: { - sourceType: 'module', - ecmaVersion: 2018 + sourceType: 'module' }, rules: { 'comma-dangle': 'off', diff --git a/test/helpers/prebidGlobal.js b/test/helpers/prebidGlobal.js index 94776a5242b..597076ab0db 100644 --- a/test/helpers/prebidGlobal.js +++ b/test/helpers/prebidGlobal.js @@ -1,4 +1,3 @@ window.$$PREBID_GLOBAL$$ = (window.$$PREBID_GLOBAL$$ || {}); -window.$$PREBID_GLOBAL$$.installedModules = (window.$$PREBID_GLOBAL$$.installedModules || []); window.$$PREBID_GLOBAL$$.cmd = window.$$PREBID_GLOBAL$$.cmd || []; window.$$PREBID_GLOBAL$$.que = window.$$PREBID_GLOBAL$$.que || []; diff --git a/test/spec/config_spec.js b/test/spec/config_spec.js index 04501ccb5b5..9492db6e849 100644 --- a/test/spec/config_spec.js +++ b/test/spec/config_spec.js @@ -6,11 +6,8 @@ const utils = require('src/utils'); let getConfig; let setConfig; -let readConfig; -let mergeConfig; let getBidderConfig; let setBidderConfig; -let mergeBidderConfig; let setDefaults; describe('config API', function () { @@ -20,11 +17,8 @@ describe('config API', function () { const config = newConfig(); getConfig = config.getConfig; setConfig = config.setConfig; - readConfig = config.readConfig; - mergeConfig = config.mergeConfig; getBidderConfig = config.getBidderConfig; setBidderConfig = config.setBidderConfig; - mergeBidderConfig = config.mergeBidderConfig; setDefaults = config.setDefaults; logErrorSpy = sinon.spy(utils, 'logError'); logWarnSpy = sinon.spy(utils, 'logWarn'); @@ -43,67 +37,6 @@ describe('config API', function () { expect(getConfig()).to.be.a('object'); }); - it('readConfig returns deepCopy of the internal config object', function () { - setConfig({ foo: {biz: 'bar'} }); - const config1 = readConfig('foo'); - config1.biz = 'buz'; - const config2 = readConfig('foo'); - expect(readConfig()).to.be.a('object'); - expect(config1.biz).to.not.equal(config2.biz); - }); - - it('readConfig retrieves arbitrary configuration properties', function () { - setConfig({ baz: 'qux' }); - expect(readConfig('baz')).to.equal('qux'); - }); - - it('readConfig has subscribe functionality for adding listeners to config updates', function () { - const listener = sinon.spy(); - - readConfig(listener); - - setConfig({ foo: 'bar' }); - - sinon.assert.calledOnce(listener); - sinon.assert.calledWith(listener, { foo: 'bar' }); - }); - - it('readConfig subscribers can unsubscribe', function () { - const listener = sinon.spy(); - - const unsubscribe = getConfig(listener); - - unsubscribe(); - - readConfig({ logging: true }); - - sinon.assert.notCalled(listener); - }); - - it('readConfig subscribers can subscribe to topics', function () { - const listener = sinon.spy(); - - readConfig('logging', listener); - - setConfig({ logging: true, foo: 'bar' }); - - sinon.assert.calledOnce(listener); - sinon.assert.calledWithExactly(listener, { logging: true }); - }); - - it('readConfig topic subscribers are only called when that topic is changed', function () { - const listener = sinon.spy(); - const wildcard = sinon.spy(); - - readConfig('subject', listener); - readConfig(wildcard); - - setConfig({ foo: 'bar' }); - - sinon.assert.notCalled(listener); - sinon.assert.calledOnce(wildcard); - }); - it('sets and gets arbitrary configuration properties', function () { setConfig({ baz: 'qux' }); expect(getConfig('baz')).to.equal('qux'); @@ -349,279 +282,4 @@ describe('config API', function () { const warning = 'Auction Options given an incorrect param: testing'; assert.ok(logWarnSpy.calledWith(warning), 'expected warning was logged'); }); - - it('should merge input with existing global config', function () { - const obj = { - ortb2: { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - } - } - }; - setConfig({ ortb2: { - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - }); - mergeConfig(obj); - const expected = { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - }, - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - expect(getConfig('ortb2')).to.deep.equal(expected); - }); - - it('input should take precedence over existing config if keys are the same', function() { - const input = { - ortb2: { - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - } - setConfig({ ortb2: { - user: { - ext: { - data: { - registered: false - } - } - } - }}); - mergeConfig(input); - const expected = { - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - expect(getConfig('ortb2')).to.deep.equal(expected); - }); - - it('should log error for a non-object value passed in', function () { - mergeConfig('invalid object'); - expect(logErrorSpy.calledOnce).to.equal(true); - const error = 'mergeConfig input must be an object'; - assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); - }); - - it('should merge input with existing bidder config', function () { - const input = { - bidders: ['rubicon', 'appnexus'], - config: { - ortb2: { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - }, - user: { - ext: { - ssp: 'magnite', - data: { - registered: false, - interests: ['sports'] - } - } - } - } - } - }; - setBidderConfig({ - bidders: ['rubicon'], - config: { - ortb2: { - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - } - }); - mergeBidderConfig(input); - const expected = { - rubicon: { - ortb2: { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - }, - user: { - ext: { - ssp: 'magnite', - data: { - registered: false, - interests: ['cars', 'sports'] - } - } - } - } - }, - appnexus: { - ortb2: { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - }, - user: { - ext: { - ssp: 'magnite', - data: { - registered: false, - interests: ['sports'] - } - } - } - } - } - } - expect(getBidderConfig()).to.deep.equal(expected); - }); - - it('should log error for a non-object value passed in', function () { - mergeBidderConfig('invalid object'); - expect(logErrorSpy.calledOnce).to.equal(true); - const error = 'setBidderConfig bidder options must be an object'; - assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); - }); - - it('should log error for empty bidders array', function () { - mergeBidderConfig({ - bidders: [], - config: { - ortb2: { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'] - } - } - } - }); - expect(logErrorSpy.calledOnce).to.equal(true); - const error = 'setBidderConfig bidder options must contain a bidders list with at least 1 bidder'; - assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); - }); - - it('should log error for nonexistent config object', function () { - mergeBidderConfig({ - bidders: ['appnexus'] - }); - expect(logErrorSpy.calledOnce).to.equal(true); - const error = 'setBidderConfig bidder options must contain a config object'; - assert.ok(logErrorSpy.calledWith(error), 'expected error was logged'); - }); - - it('should merge without array duplication', function() { - const userObj1 = { - name: 'www.dataprovider1.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1776' - }] - }; - - const userObj2 = { - name: 'www.dataprovider2.com', - ext: { taxonomyname: 'iab_audience_taxonomy' }, - segment: [{ - id: '1914' - }] - }; - - const siteObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - } - - setConfig({ - ortb2: { - user: { - data: [userObj1, userObj2] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }); - - const rtd = { - ortb2: { - user: { - data: [userObj1] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }; - mergeConfig(rtd); - - let ortb2Config = getConfig('ortb2'); - - expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]); - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(1); - }); }); diff --git a/test/spec/integration/faker/googletag.js b/test/spec/integration/faker/googletag.js index a8676b500a5..9d91bf315d9 100644 --- a/test/spec/integration/faker/googletag.js +++ b/test/spec/integration/faker/googletag.js @@ -51,15 +51,9 @@ export function enable() { window.googletag = { _slots: [], _callbackMap: {}, - _ppid: undefined, - cmd: [], pubads: function () { var self = this; return { - setPublisherProvidedId: function (ppid) { - self._ppid = ppid; - }, - getSlots: function () { return self._slots; }, @@ -97,9 +91,4 @@ export function disable() { window.googletag = undefined; } -export function reset() { - disable(); - enable(); -} - enable(); diff --git a/test/spec/modules/33acrossBidAdapter_spec.js b/test/spec/modules/33acrossBidAdapter_spec.js index 141edc1e61c..b5443cdd5c2 100644 --- a/test/spec/modules/33acrossBidAdapter_spec.js +++ b/test/spec/modules/33acrossBidAdapter_spec.js @@ -16,21 +16,20 @@ function validateBuiltServerRequest(builtReq, expectedReq) { describe('33acrossBidAdapter:', function () { const BIDDER_CODE = '33across'; const SITE_ID = 'sample33xGUID123456789'; + const PRODUCT_ID = 'siab'; const END_POINT = 'https://ssc.33across.com/api/v1/hb'; let element, win; let bidRequests; let sandbox; - function TtxRequestBuilder(siteId = SITE_ID) { + function TtxRequestBuilder() { const ttxRequest = { - imp: [{ - id: 'b1' - }], + imp: [{}], site: { - id: siteId + id: SITE_ID }, - id: 'r1', + id: 'b1', regs: { ext: { gdpr: 0 @@ -47,83 +46,66 @@ describe('33acrossBidAdapter:', function () { } }; - this.addImp = (id = 'b2') => { - ttxRequest.imp.push({ id }); - - return this; - } - this.withBanner = () => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp, { - banner: { - format: [ - { - w: 300, - h: 250 - }, - { - w: 728, - h: 90 - } - ], - ext: { - ttx: { - viewability: { - amount: 100 - } + Object.assign(ttxRequest.imp[0], { + banner: { + format: [ + { + w: 300, + h: 250 + }, + { + w: 728, + h: 90 + } + ], + ext: { + ttx: { + viewability: { + amount: 100 } } } - }); + } }); + return this; }; this.withBannerSizes = this.withSizes = sizes => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp.banner, { format: sizes }); - }); - + Object.assign(ttxRequest.imp[0].banner, { format: sizes }); return this; }; this.withVideo = (params = {}) => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp, { - video: { - w: 300, - h: 250, - placement: 2, - ...params - } - }); + Object.assign(ttxRequest.imp[0], { + video: { + w: 300, + h: 250, + placement: 2, + ...params + } }); return this; }; this.withViewability = (viewability, format = 'banner') => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp[format], { - ext: { - ttx: { viewability } - } - }); + Object.assign(ttxRequest.imp[0][format], { + ext: { + ttx: { viewability } + } }); - return this; }; - this.withProduct = (prod = 'siab') => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp, { - ext: { - ttx: { - prod - } + this.withProduct = (prod = PRODUCT_ID) => { + Object.assign(ttxRequest.imp[0], { + ext: { + ttx: { + prod } - }); + } }); return this; @@ -267,7 +249,7 @@ describe('33acrossBidAdapter:', function () { bidderRequestId: 'b1a', params: { siteId: SITE_ID, - productId: 'siab' + productId: PRODUCT_ID }, adUnitCode: 'div-id', auctionId: 'r1', @@ -276,61 +258,35 @@ describe('33acrossBidAdapter:', function () { } ]; - this.addBid = (bidParams = {}) => { - bidRequests.push({ - bidId: 'b2', - bidder: '33across', - bidderRequestId: 'b1b', - params: { - siteId: SITE_ID, - productId: 'siab' - }, - adUnitCode: 'div-id', - auctionId: 'r1', - mediaTypes: {}, - transactionId: 't2', - ...bidParams - }); - - return this; - }; - this.withBanner = () => { - bidRequests.forEach((bid) => { - bid.mediaTypes.banner = { - sizes: [ - [300, 250], - [728, 90] - ] - }; - }); + bidRequests[0].mediaTypes.banner = { + sizes: [ + [300, 250], + [728, 90] + ] + }; return this; }; this.withProduct = (prod) => { - bidRequests.forEach((bid) => { - bid.params.productId = prod; - }); + bidRequests[0].params.productId = prod; + return this; }; this.withVideo = (params) => { - bidRequests.forEach((bid) => { - bid.mediaTypes.video = { - playerSize: [[300, 250]], - context: 'outstream', - ...params - }; - }); + bidRequests[0].mediaTypes.video = { + playerSize: [[300, 250]], + context: 'outstream', + ...params + }; return this; } this.withUserIds = (eids) => { - bidRequests.forEach((bid) => { - bid.userIdAsEids = eids; - }); + bidRequests[0].userIdAsEids = eids; return this; }; @@ -359,7 +315,6 @@ describe('33acrossBidAdapter:', function () { } }; win = { - parent: null, document: { visibilityState: 'visible' }, @@ -376,7 +331,7 @@ describe('33acrossBidAdapter:', function () { sandbox = sinon.sandbox.create(); sandbox.stub(Date, 'now').returns(1); - sandbox.stub(document, 'getElementById').returns(element); + sandbox.stub(document, 'getElementById').withArgs('div-id').returns(element); sandbox.stub(utils, 'getWindowTop').returns(win); sandbox.stub(utils, 'getWindowSelf').returns(win); }); @@ -1421,146 +1376,10 @@ describe('33acrossBidAdapter:', function () { }); }); }); - - context('when SRA mode is enabled', function() { - it('builds a single request with multiple imps corresponding to each group {siteId, productId}', function() { - sandbox.stub(config, 'getConfig').callsFake(() => { - return { - enableSRAMode: true - } - }); - - const bidRequests = new BidRequestsBuilder() - .addBid() - .addBid({ - bidId: 'b3', - adUnitCode: 'div-id', - params: { - siteId: 'sample33xGUID123456780', - productId: 'siab' - } - }) - .addBid({ - bidId: 'b4', - adUnitCode: 'div-id', - params: { - siteId: 'sample33xGUID123456780', - productId: 'inview' - } - }) - .withBanner() - .withVideo({context: 'outstream'}) - .build(); - - const req1 = new TtxRequestBuilder() - .addImp() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - const req2 = new TtxRequestBuilder('sample33xGUID123456780') - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req2.imp[0].id = 'b3'; - - const req3 = new TtxRequestBuilder('sample33xGUID123456780') - .withProduct('inview') - .withBanner() - .withVideo() - .build(); - - req3.imp[0].id = 'b4'; - - const serverReq1 = new ServerRequestBuilder() - .withData(req1) - .build(); - - const serverReq2 = new ServerRequestBuilder() - .withData(req2) - .withUrl('https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780') - .build(); - - const serverReq3 = new ServerRequestBuilder() - .withData(req3) - .withUrl('https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780') - .build(); - - const builtServerRequests = spec.buildRequests(bidRequests, {}); - - expect(builtServerRequests).to.deep.equal([serverReq1, serverReq2, serverReq3]); - }); - }); - - context('when SRA mode is not enabled', function() { - it('builds multiple requests, one corresponding to each Ad Unit', function() { - const bidRequests = new BidRequestsBuilder() - .addBid() - .addBid({ - bidId: 'b3', - adUnitCode: 'div-id', - params: { - siteId: 'sample33xGUID123456780', - productId: 'siab' - } - }) - .withBanner() - .withVideo({context: 'outstream'}) - .build(); - - const req1 = new TtxRequestBuilder() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - const req2 = new TtxRequestBuilder() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req2.imp[0].id = 'b2'; - - const req3 = new TtxRequestBuilder('sample33xGUID123456780') - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req3.imp[0].id = 'b3'; - - const serverReq1 = new ServerRequestBuilder() - .withData(req1) - .build(); - - const serverReq2 = new ServerRequestBuilder() - .withData(req2) - .build(); - - const serverReq3 = new ServerRequestBuilder() - .withData(req3) - .withUrl('https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780') - .build(); - - const builtServerRequests = spec.buildRequests(bidRequests, {}); - - expect(builtServerRequests) - .to.deep.equal([ - serverReq1, - serverReq2, - serverReq3 - ]); - }); - }); }); describe('interpretResponse', function() { let ttxRequest, serverRequest; - const videoBid = ''; beforeEach(function() { ttxRequest = new TtxRequestBuilder() @@ -1571,7 +1390,6 @@ describe('33acrossBidAdapter:', function () { page: 'https://test-url.com' }) .build(); - serverRequest = new ServerRequestBuilder() .withUrl('https://staging-ssc.33across.com/api/v1/hb') .withData(ttxRequest) @@ -1587,12 +1405,11 @@ describe('33acrossBidAdapter:', function () { const serverResponse = { cur: 'USD', ext: {}, - id: 'r1', + id: 'b1', seatbid: [ { bid: [{ id: '1', - impid: 'b1', adm: '

I am an ad

', crid: 1, h: 250, @@ -1624,15 +1441,15 @@ describe('33acrossBidAdapter:', function () { }); it('interprets and returns the single video bid response', function() { + const videoBid = ''; const serverResponse = { cur: 'USD', ext: {}, - id: 'r1', + id: 'b1', seatbid: [ { bid: [{ id: '1', - impid: 'b1', adm: videoBid, ext: { ttx: { @@ -1680,7 +1497,6 @@ describe('33acrossBidAdapter:', function () { { bid: [{ id: '1', - impid: 'b1', adm: '

I am an ad

', crid: 1, h: 250, @@ -1717,7 +1533,7 @@ describe('33acrossBidAdapter:', function () { const serverResponse = { cur: 'USD', ext: {}, - id: 'r1', + id: 'b1', seatbid: [] }; @@ -1726,16 +1542,15 @@ describe('33acrossBidAdapter:', function () { }); context('when more than one bids are returned', function() { - it('interprets and returns all bids', function() { + it('interprets and returns the the first bid of the first seatbid', function() { const serverResponse = { cur: 'USD', ext: {}, - id: 'r1', + id: 'b1', seatbid: [ { bid: [{ id: '1', - impid: 'b1', adm: '

I am an ad

', crid: 1, h: 250, @@ -1744,7 +1559,6 @@ describe('33acrossBidAdapter:', function () { }, { id: '2', - impid: 'b2', adm: '

I am an ad

', crid: 2, h: 250, @@ -1756,14 +1570,7 @@ describe('33acrossBidAdapter:', function () { { bid: [{ id: '3', - impid: 'b3', - adm: videoBid, - ext: { - ttx: { - mediaType: 'video', - vastType: 'xml' - } - }, + adm: '

I am an ad

', crid: 3, h: 250, w: 300, @@ -1772,50 +1579,21 @@ describe('33acrossBidAdapter:', function () { } ] }; - const bidResponse = [ - { - requestId: 'b1', - bidderCode: BIDDER_CODE, - cpm: 0.0940, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 1, - mediaType: 'banner', - currency: 'USD', - netRevenue: true - }, - { - requestId: 'b2', - bidderCode: BIDDER_CODE, - cpm: 0.0938, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 2, - mediaType: 'banner', - currency: 'USD', - netRevenue: true - }, - { - requestId: 'b3', - bidderCode: BIDDER_CODE, - cpm: 0.0938, - width: 300, - height: 250, - ad: videoBid, - vastXml: '', - ttl: 60, - creativeId: 3, - mediaType: 'video', - currency: 'USD', - netRevenue: true - } - ]; + const bidResponse = { + requestId: 'b1', + bidderCode: BIDDER_CODE, + cpm: 0.0940, + width: 300, + height: 250, + ad: '

I am an ad

', + ttl: 60, + creativeId: 1, + mediaType: 'banner', + currency: 'USD', + netRevenue: true + }; - expect(spec.interpretResponse({ body: serverResponse }, serverRequest)).to.deep.equal(bidResponse); + expect(spec.interpretResponse({ body: serverResponse }, serverRequest)).to.deep.equal([bidResponse]); }); }); }); diff --git a/test/spec/modules/adbookpspBidAdapter_spec.js b/test/spec/modules/adbookpspBidAdapter_spec.js index 3a49f25edb6..a6b8a794eeb 100755 --- a/test/spec/modules/adbookpspBidAdapter_spec.js +++ b/test/spec/modules/adbookpspBidAdapter_spec.js @@ -504,11 +504,9 @@ describe('adbookpsp bid adapter', () => { ad: '
ad
', adId: '5', adserverTargeting: { - hb_ad_ord_adbookpsp: '0_0', // the value to the left of the underscore represents the index of the ad id and the number to the right represents the order index hb_adid_c_adbookpsp: '5', hb_deal_adbookpsp: 'werwetwerw', hb_liid_adbookpsp: '2342345', - hb_ordid_adbookpsp: '567843', }, referrer: 'http://prebid-test-page.io:8080/banner.html', lineItemId: '2342345', @@ -518,11 +516,9 @@ describe('adbookpsp bid adapter', () => { adId: '10', adUnitCode: 'div-gpt-ad-837465923534-0', adserverTargeting: { - hb_ad_ord_adbookpsp: '0_0', hb_adid_c_adbookpsp: '10', hb_deal_adbookpsp: 'dsfxcxcvxc', hb_liid_adbookpsp: '2121221', - hb_ordid_adbookpsp: '5678234', }, bidId: 'bid4321', bidderRequestId: '999ccceeee11', @@ -560,18 +556,14 @@ describe('adbookpsp bid adapter', () => { expect(bids).to.have.length(2); expect(bids[0].adserverTargeting).to.deep.equal({ - hb_ad_ord_adbookpsp: '0_0', - hb_adid_c_adbookpsp: '5', hb_deal_adbookpsp: 'werwetwerw', hb_liid_adbookpsp: '2342345', - hb_ordid_adbookpsp: '567843', + hb_adid_c_adbookpsp: '5', }); expect(bids[1].adserverTargeting).to.deep.equal({ - hb_ad_ord_adbookpsp: '0_0', - hb_adid_c_adbookpsp: '10', hb_deal_adbookpsp: 'dsfxcxcvxc', hb_liid_adbookpsp: '2121221', - hb_ordid_adbookpsp: '5678234', + hb_adid_c_adbookpsp: '10', }); }); @@ -588,11 +580,9 @@ describe('adbookpsp bid adapter', () => { expect(bids).to.have.length(2); for (const bid of bids) { expect(bid.adserverTargeting).to.deep.equal({ - hb_ad_ord_adbookpsp: '0_0,1_0', - hb_adid_c_adbookpsp: '5,10', hb_deal_adbookpsp: 'werwetwerw,dsfxcxcvxc', hb_liid_adbookpsp: '2342345,2121221', - hb_ordid_adbookpsp: '567843,5678234', + hb_adid_c_adbookpsp: '5,10', }); } }); @@ -680,11 +670,9 @@ describe('adbookpsp bid adapter', () => { ); expect(bids[0].adserverTargeting).to.deep.equal({ - hb_ad_ord_adbookpsp: '0_0', hb_adid_c_adbookpsp: '10', hb_deal_adbookpsp: 'dsfxcxcvxc', hb_liid_adbookpsp: '2121221', - hb_ordid_adbookpsp: '5678234', }); }); @@ -1291,7 +1279,6 @@ const exchangeResponse = { nurl: 'http://win.example.url', ext: { liid: '2342345', - ordid: '567843', }, cat: ['IAB2-1', 'IAB2-2', 'IAB2-3'], adomain: ['advertiser.com'], @@ -1314,7 +1301,6 @@ const exchangeResponse = { nurl: 'http://win.example.url', ext: { liid: '2121221', - ordid: '5678234', }, cat: ['IAB2-3'], adomain: ['advertiser.com', 'campaign.advertiser.com'], diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js index ed096e7189d..ef11490529a 100644 --- a/test/spec/modules/adfBidAdapter_spec.js +++ b/test/spec/modules/adfBidAdapter_spec.js @@ -29,34 +29,11 @@ describe('Adf adapter', function () { it('should return true when required params found', function () { assert(spec.isBidRequestValid(bid)); - - bid.params = { - inv: 1234, - mname: 'some-placement' - }; - assert(spec.isBidRequestValid(bid)); - - bid.params = { - mid: 4332, - inv: 1234, - mname: 'some-placement' - }; - assert(spec.isBidRequestValid(bid)); }); it('should return false when required params are missing', function () { bid.params = { adxDomain: 'adx.adform.net' }; assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - mname: 'some-placement' - }; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - inv: 1234 - }; - assert.isFalse(spec.isBidRequestValid(bid)); }); }); @@ -354,83 +331,8 @@ describe('Adf adapter', function () { } }); - describe('dynamic placement tag', function () { - it('should add imp parameters correctly', function () { - const validBidRequests = [ - { bidId: 'bidId', params: { inv: 1000, mname: 'placement' }, mediaTypes: {video: {}} }, - { bidId: 'bidId', params: { mid: 1234, inv: 1002, mname: 'placement2' }, mediaTypes: {video: {}} }, - { bidId: 'bidId', params: { mid: 1234 }, mediaTypes: {video: {}} } - ]; - const [ imp1, imp2, imp3 ] = getRequestImps(validBidRequests); - - assert.equal(imp1.ext.bidder.inv, 1000); - assert.equal(imp1.ext.bidder.mname, 'placement'); - assert.equal('tagid' in imp1, false); - - assert.equal(imp2.ext.bidder.inv, 1002); - assert.equal(imp2.ext.bidder.mname, 'placement2'); - assert.equal(imp2.tagid, 1234); - - assert.ok(imp3.ext.bidder); - assert.equal('inv' in imp3.ext.bidder, false); - assert.equal('mname' in imp3.ext.bidder, false); - assert.equal(imp3.tagid, 1234); - }); - }); - - describe('price floors', function () { - it('should not add if floors module not configured', function () { - const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, undefined); - }); - - it('should not add if floor price not defined', function () { - const validBidRequests = [ getBidWithFloor() ]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'USD'); - }); - - it('should request floor price in adserver currency', function () { - config.setConfig({ currency: { adServerCurrency: 'DKK' } }); - const validBidRequests = [ getBidWithFloor() ]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'DKK'); - }); - - it('should add correct floor values', function () { - const expectedFloors = [ 1, 1.3, 0.5 ]; - const validBidRequests = expectedFloors.map(getBidWithFloor); - let imps = getRequestImps(validBidRequests); - - expectedFloors.forEach((floor, index) => { - assert.equal(imps[index].bidfloor, floor); - assert.equal(imps[index].bidfloorcur, 'USD'); - }); - }); - - function getBidWithFloor(floor) { - return { - params: { mid: 1 }, - mediaTypes: { video: {} }, - getFloor: ({ currency }) => { - return { - currency: currency, - floor - }; - } - }; - } - }); - describe('multiple media types', function () { - it('should use all configured media types for bidding', function () { + it('should use single media type for bidding', function () { let validBidRequests = [{ bidId: 'bidId', params: { mid: 1000 }, @@ -457,23 +359,20 @@ describe('Adf adapter', function () { banner: { sizes: [[100, 100], [200, 300]] }, - native: {}, - video: {} + native: {} } }]; - let [ first, second, third ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; - - assert.ok(first.banner); - assert.ok(first.video); - assert.equal(first.native, undefined); - - assert.ok(second.video); - assert.equal(second.banner, undefined); - assert.equal(second.native, undefined); - - assert.ok(third.native); - assert.ok(third.video); - assert.ok(third.banner); + let [ banner, video, native ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; + + assert.ok(banner.banner); + assert.equal(banner.video, undefined); + assert.equal(banner.native, undefined); + assert.ok(video.video); + assert.equal(video.banner, undefined); + assert.equal(video.native, undefined); + assert.ok(native.native); + assert.equal(native.video, undefined); + assert.equal(native.banner, undefined); }); }); @@ -672,10 +571,6 @@ describe('Adf adapter', function () { }); }); }); - - function getRequestImps(validBidRequests) { - return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp; - } }); describe('interpretResponse', function () { @@ -804,12 +699,7 @@ describe('Adf adapter', function () { imptrackers: ['imptrackers url1', 'imptrackers url2'] }, dealid: 'deal-id', - adomain: [ 'demo.com' ], - ext: { - prebid: { - type: 'native' - } - } + adomain: [ 'demo.com' ] } ] }], @@ -822,6 +712,7 @@ describe('Adf adapter', function () { { bidId: 'bidId1', params: { mid: 1000 }, + mediaType: 'native', nativeParams: { title: { required: true, len: 140 }, image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, @@ -953,7 +844,7 @@ describe('Adf adapter', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'banner' } } }] + bid: [{ impid: '1', adm: '' }] }] } }; @@ -962,7 +853,8 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { mid: 1000 } + params: { mid: 1000 }, + mediaType: 'banner' } ] }; @@ -970,8 +862,6 @@ describe('Adf adapter', function () { bids = spec.interpretResponse(serverResponse, bidRequest); assert.equal(bids.length, 1); assert.equal(bids[0].ad, ''); - assert.equal(bids[0].mediaType, 'banner'); - assert.equal(bids[0].meta.mediaType, 'banner'); }); }); @@ -980,7 +870,7 @@ describe('Adf adapter', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }] + bid: [{ impid: '1', adm: '' }] }] } }; @@ -989,7 +879,8 @@ describe('Adf adapter', function () { bids: [ { bidId: 'bidId1', - params: { mid: 1000 } + params: { mid: 1000 }, + mediaType: 'video' } ] }; @@ -997,15 +888,13 @@ describe('Adf adapter', function () { bids = spec.interpretResponse(serverResponse, bidRequest); assert.equal(bids.length, 1); assert.equal(bids[0].vastXml, ''); - assert.equal(bids[0].mediaType, 'video'); - assert.equal(bids[0].meta.mediaType, 'video'); }); it('should add renderer for outstream bids', function () { let serverResponse = { body: { seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }, { impid: '2', adm: '', ext: { prebid: { type: 'video' } } }] + bid: [{ impid: '1', adm: '' }, { impid: '2', adm: '' }] }] } }; @@ -1015,6 +904,7 @@ describe('Adf adapter', function () { { bidId: 'bidId1', params: { mid: 1000 }, + mediaType: 'video', mediaTypes: { video: { context: 'outstream' @@ -1024,6 +914,7 @@ describe('Adf adapter', function () { { bidId: 'bidId2', params: { mid: 1000 }, + mediaType: 'video', mediaTypes: { video: { constext: 'instream' diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index 3ff5e1fb302..7eacba2f7d4 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -92,9 +92,9 @@ describe('AdgenerationAdapter', function () { } }; const data = { - banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.2.0&imark=1&tp=https%3A%2F%2Fexample.com`, - bannerUSD: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=USD&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.2.0&imark=1&tp=https%3A%2F%2Fexample.com`, - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=' + prebid.version + '&sdkname=prebidjs&adapterver=1.2.0&tp=https%3A%2F%2Fexample.com' + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.1.0&imark=1&tp=https%3A%2F%2Fexample.com`, + bannerUSD: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=USD&pbver=${prebid.version}&sdkname=prebidjs&adapterver=1.1.0&imark=1&tp=https%3A%2F%2Fexample.com`, + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=' + prebid.version + '&sdkname=prebidjs&adapterver=1.1.0&tp=https%3A%2F%2Fexample.com' }; it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests, bidderRequest)[0]; @@ -192,21 +192,6 @@ describe('AdgenerationAdapter', function () { transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' }, }, - upperBillboard: { - bidRequest: { - bidder: 'adg', - params: { - id: '143038', // banner - marginTop: '50', - }, - adUnitCode: 'adunit-code', - sizes: [[320, 180]], - bidId: '2f6ac468a9c15e', - bidderRequestId: '14a9f773e30243', - auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', - transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' - }, - }, }; const serverResponse = { @@ -231,12 +216,12 @@ describe('AdgenerationAdapter', function () { dealid: 'fd5sa5fa7f', ttl: 1000, results: [ - {ad: '<\!DOCTYPE html>
'}, + {ad: '
'}, ], adomain: ['advertiserdomain.com'] }, native: { - ad: '<\!DOCTYPE html>↵ ↵ ↵ ↵ ↵
↵ ', + ad: '↵ ↵ ↵ ↵ ↵
↵ ', beacon: '', cpm: 36.0008, displaytype: '1', @@ -326,78 +311,6 @@ describe('AdgenerationAdapter', function () { creativeid: '1k2kv35vsa5r', dealid: 'fd5sa5fa7f', ttl: 1000 - }, - upperBillboard: { - 'ad': '<\!DOCTYPE html>\n \n \n \n \n \n \n \n
\n \n
\n \n', - 'beacon': '', - 'beaconurl': 'https://tg.socdm.com/bc/v3?b=Y2hzbT0yOTQsNGZiM2NkNWVpZD0xNDMwMzgmcG9zPVNTUExPQyZhZD0xMjMzMzIzLzI2MTA2MS4yNjU3OTkuMTIzMzMyMy8yMTY2NDY2LzE1NDQxMC8xNDMwMzg6U1NQTE9DOiovaWR4PTA7ZHNwaWQ9MTtkaTI9MjEzNC0xMzI4NjRfbmV3Zm9ybWF0X3Rlc3Q7ZnR5cGU9Mztwcj15TXB3O3ByYj15UTtwcm89eVE7cHJvYz1KUFk7Y3JkMnk9MTExLjkyO2NyeTJkPTAuMDA4OTM0OTUzNTM4MjQxNjAxMztwcnY9aWp6QVZtWW9wbmJUV1B0cWhtZEN1ZWRXNDd0MjU1MEtmYjFWYmI3SzsmZXg9MTYzMzMyNzU4MyZjdD0xNjMzMzI3NTgzODAzJnNyPWh0dHA-&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA&ctsv=m-ad240&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&seqctx=gat3by5hZy5mdHlwZaEz&t=.gif', - 'cpm': 80, - 'creative_params': {}, - 'creativeid': 'ScaleOut_2146187', - 'dealid': '2134-132864_newformat_test', - 'displaytype': '1', - 'h': 180, - 'ids': { - 'anid': '', - 'diid': '', - 'idfa': '', - 'soc': 'Xm8Q8cCo5r8AAHCCMg0AAAAA' - }, - 'location_params': { - 'option': { - 'ad_type': 'upper_billboard' - } - }, - 'locationid': '143038', - 'results': [ - { - 'ad': '<\!DOCTYPE html>\n \n \n \n \n \n \n \n
\n \n
\n \n', - 'beacon': '', - 'beaconurl': 'https://tg.socdm.com/bc/v3?b=Y2hzbT0yOTQsNGZiM2NkNWVpZD0xNDMwMzgmcG9zPVNTUExPQyZhZD0xMjMzMzIzLzI2MTA2MS4yNjU3OTkuMTIzMzMyMy8yMTY2NDY2LzE1NDQxMC8xNDMwMzg6U1NQTE9DOiovaWR4PTA7ZHNwaWQ9MTtkaTI9MjEzNC0xMzI4NjRfbmV3Zm9ybWF0X3Rlc3Q7ZnR5cGU9Mztwcj15TXB3O3ByYj15UTtwcm89eVE7cHJvYz1KUFk7Y3JkMnk9MTExLjkyO2NyeTJkPTAuMDA4OTM0OTUzNTM4MjQxNjAxMztwcnY9aWp6QVZtWW9wbmJUV1B0cWhtZEN1ZWRXNDd0MjU1MEtmYjFWYmI3SzsmZXg9MTYzMzMyNzU4MyZjdD0xNjMzMzI3NTgzODAzJnNyPWh0dHA-&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA&ctsv=m-ad240&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&seqctx=gat3by5hZy5mdHlwZaEz&t=.gif', - 'cpm': 80, - 'creative_params': {}, - 'creativeid': 'ScaleOut_2146187', - 'dealid': '2134-132864_newformat_test', - 'h': 180, - 'landing_url': 'https://supership.jp/', - 'rparams': {}, - 'scheduleid': '1233323', - 'trackers': { - 'imp': [ - 'https://tg.socdm.com/bc/v3?b=Y2hzbT0yOTQsNGZiM2NkNWVpZD0xNDMwMzgmcG9zPVNTUExPQyZhZD0xMjMzMzIzLzI2MTA2MS4yNjU3OTkuMTIzMzMyMy8yMTY2NDY2LzE1NDQxMC8xNDMwMzg6U1NQTE9DOiovaWR4PTA7ZHNwaWQ9MTtkaTI9MjEzNC0xMzI4NjRfbmV3Zm9ybWF0X3Rlc3Q7ZnR5cGU9Mztwcj15TXB3O3ByYj15UTtwcm89eVE7cHJvYz1KUFk7Y3JkMnk9MTExLjkyO2NyeTJkPTAuMDA4OTM0OTUzNTM4MjQxNjAxMztwcnY9aWp6QVZtWW9wbmJUV1B0cWhtZEN1ZWRXNDd0MjU1MEtmYjFWYmI3SzsmZXg9MTYzMzMyNzU4MyZjdD0xNjMzMzI3NTgzODAzJnNyPWh0dHA-&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA&ctsv=m-ad240&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&seqctx=gat3by5hZy5mdHlwZaEz&t=.gif' - ], - 'viewable_imp': [ - 'https://tg.socdm.com/aux/inview?creative_id=2166466&ctsv=m-ad240&extra_field=idx%3D0%3Bdspid%3D1%3Bdi2%3D2134-132864_newformat_test%3Bftype%3D3%3Bprb%3D0%3Bpro%3D0%3Bproc%3DJPY%3Bcrd2y%3D111.92%3Bcry2d%3D0.0089349535382416013%3Bsspm%3D0%3Bsom%3D0.2%3Borgm%3D0%3Btechm%3D0%3Bssp_margin%3D0%3Bso_margin%3D0.2%3Borg_margin%3D0%3Btech_margin%3D0%3Bbs%3Dclassic%3B&family_id=1233323&id=143038&loglocation_id=154410&lookupname=143038%3ASSPLOC%3A*&pos=SSPLOC&schedule_id=261061.265799.1233323&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA' - ], - 'viewable_measured': [ - 'https://tg.socdm.com/aux/measured?creative_id=2166466&ctsv=m-ad240&extra_field=idx%3D0%3Bdspid%3D1%3Bdi2%3D2134-132864_newformat_test%3Bftype%3D3%3Bprb%3D0%3Bpro%3D0%3Bproc%3DJPY%3Bcrd2y%3D111.92%3Bcry2d%3D0.0089349535382416013%3Bsspm%3D0%3Bsom%3D0.2%3Borgm%3D0%3Btechm%3D0%3Bssp_margin%3D0%3Bso_margin%3D0.2%3Borg_margin%3D0%3Btech_margin%3D0%3Bbs%3Dclassic%3B&family_id=1233323&id=143038&loglocation_id=154410&lookupname=143038%3ASSPLOC%3A*&pos=SSPLOC&schedule_id=261061.265799.1233323&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA' - ] - }, - 'ttl': 1000, - 'vastxml': '\n \n \n SOADS\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n 00:00:15\n \n \n \n \n \n \n \n \n \n \n \n \n https://i.socdm.com/a/2/2095/2091787/20210810043037-de3e74aec30f36.mp4\n https://i.socdm.com/a/2/2095/2091788/20210810043037-6dd368dc91d507.mp4\n https://i.socdm.com/a/2/2095/2091789/20210810043037-c8eb814ddd85c4.webm\n https://i.socdm.com/a/2/2095/2091790/20210810043037-0a7f74c40268ab.webm\n \n \n \n \n \n \n', - 'vcpm': 0, - 'w': 320, - 'weight': 1 - } - ], - 'rotation': '0', - 'scheduleid': '1233323', - 'sdktype': '0', - 'trackers': { - 'imp': [ - 'https://tg.socdm.com/bc/v3?b=Y2hzbT0yOTQsNGZiM2NkNWVpZD0xNDMwMzgmcG9zPVNTUExPQyZhZD0xMjMzMzIzLzI2MTA2MS4yNjU3OTkuMTIzMzMyMy8yMTY2NDY2LzE1NDQxMC8xNDMwMzg6U1NQTE9DOiovaWR4PTA7ZHNwaWQ9MTtkaTI9MjEzNC0xMzI4NjRfbmV3Zm9ybWF0X3Rlc3Q7ZnR5cGU9Mztwcj15TXB3O3ByYj15UTtwcm89eVE7cHJvYz1KUFk7Y3JkMnk9MTExLjkyO2NyeTJkPTAuMDA4OTM0OTUzNTM4MjQxNjAxMztwcnY9aWp6QVZtWW9wbmJUV1B0cWhtZEN1ZWRXNDd0MjU1MEtmYjFWYmI3SzsmZXg9MTYzMzMyNzU4MyZjdD0xNjMzMzI3NTgzODAzJnNyPWh0dHA-&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA&ctsv=m-ad240&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&seqctx=gat3by5hZy5mdHlwZaEz&t=.gif' - ], - 'viewable_imp': [ - 'https://tg.socdm.com/aux/inview?creative_id=2166466&ctsv=m-ad240&extra_field=idx%3D0%3Bdspid%3D1%3Bdi2%3D2134-132864_newformat_test%3Bftype%3D3%3Bprb%3D0%3Bpro%3D0%3Bproc%3DJPY%3Bcrd2y%3D111.92%3Bcry2d%3D0.0089349535382416013%3Bsspm%3D0%3Bsom%3D0.2%3Borgm%3D0%3Btechm%3D0%3Bssp_margin%3D0%3Bso_margin%3D0.2%3Borg_margin%3D0%3Btech_margin%3D0%3Bbs%3Dclassic%3B&family_id=1233323&id=143038&loglocation_id=154410&lookupname=143038%3ASSPLOC%3A*&pos=SSPLOC&schedule_id=261061.265799.1233323&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA' - ], - 'viewable_measured': [ - 'https://tg.socdm.com/aux/measured?creative_id=2166466&ctsv=m-ad240&extra_field=idx%3D0%3Bdspid%3D1%3Bdi2%3D2134-132864_newformat_test%3Bftype%3D3%3Bprb%3D0%3Bpro%3D0%3Bproc%3DJPY%3Bcrd2y%3D111.92%3Bcry2d%3D0.0089349535382416013%3Bsspm%3D0%3Bsom%3D0.2%3Borgm%3D0%3Btechm%3D0%3Bssp_margin%3D0%3Bso_margin%3D0.2%3Borg_margin%3D0%3Btech_margin%3D0%3Bbs%3Dclassic%3B&family_id=1233323&id=143038&loglocation_id=154410&lookupname=143038%3ASSPLOC%3A*&pos=SSPLOC&schedule_id=261061.265799.1233323&seqid=be38bdb4-74a7-14a7-3439-b7f1ea8b4f33&seqtime=1633327583803&xuid=Xm8Q8cCo5r8AAHCCMg0AAAAA' - ] - }, - 'ttl': 1000, - 'vastxml': '\n \n \n SOADS\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n 00:00:15\n \n \n \n \n \n \n \n \n \n \n \n \n https://i.socdm.com/a/2/2095/2091787/20210810043037-de3e74aec30f36.mp4\n https://i.socdm.com/a/2/2095/2091788/20210810043037-6dd368dc91d507.mp4\n https://i.socdm.com/a/2/2095/2091789/20210810043037-c8eb814ddd85c4.webm\n https://i.socdm.com/a/2/2095/2091790/20210810043037-0a7f74c40268ab.webm\n \n \n \n \n \n \n', - 'vcpm': 0, - 'w': 320, } }, emptyAdomain: { @@ -418,12 +331,12 @@ describe('AdgenerationAdapter', function () { dealid: 'fd5sa5fa7f', ttl: 1000, results: [ - {ad: '<\!DOCTYPE html>
'}, + {ad: '
'}, ], adomain: [] }, native: { - ad: '<\!DOCTYPE html>↵ ↵ ↵ ↵ ↵
↵ ', + ad: '↵ ↵ ↵ ↵ ↵
↵ ', beacon: '', cpm: 36.0008, displaytype: '1', @@ -533,11 +446,11 @@ describe('AdgenerationAdapter', function () { dealid: 'fd5sa5fa7f', ttl: 1000, results: [ - {ad: '<\!DOCTYPE html>
'}, + {ad: '
'}, ], }, native: { - ad: '<\!DOCTYPE html>↵ ↵ ↵ ↵ ↵
↵ ', + ad: '↵ ↵ ↵ ↵ ↵
↵ ', beacon: '', cpm: 36.0008, displaytype: '1', @@ -678,20 +591,7 @@ describe('AdgenerationAdapter', function () { impressionTrackers: ['https://adg-dummy-dsp.s3-ap-northeast-1.amazonaws.com/1x1.gif'] }, mediaType: NATIVE - }, - upperBillboard: { - requestId: '2f6ac468a9c15e', - cpm: 80, - width: 320, - height: 180, - creativeId: 'ScaleOut_2146187', - dealId: '2134-132864_newformat_test', - currency: 'JPY', - netRevenue: true, - ttl: 1000, - ad: ``, - adomain: ['advertiserdomain.com'] - }, + } }, emptyAdomain: { banner: { @@ -796,17 +696,46 @@ describe('AdgenerationAdapter', function () { expect(result.length).to.equal(0); }); - it('handles ADGBrowserM responses', function () { - const result = spec.interpretResponse({body: serverResponse.normal.upperBillboard}, bidRequests.upperBillboard)[0]; - expect(result.requestId).to.equal(bidResponses.normal.upperBillboard.requestId); - expect(result.width).to.equal(bidResponses.normal.upperBillboard.width); - expect(result.height).to.equal(bidResponses.normal.upperBillboard.height); - expect(result.creativeId).to.equal(bidResponses.normal.upperBillboard.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.upperBillboard.dealId); - expect(result.currency).to.equal(bidResponses.normal.upperBillboard.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.upperBillboard.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.upperBillboard.ttl); - expect(result.ad).to.equal(bidResponses.normal.upperBillboard.ad); + it('handles banner responses', function () { + const result = spec.interpretResponse({body: serverResponse.normal.banner}, bidRequests.banner)[0]; + expect(result.requestId).to.equal(bidResponses.normal.banner.requestId); + expect(result.width).to.equal(bidResponses.normal.banner.width); + expect(result.height).to.equal(bidResponses.normal.banner.height); + expect(result.creativeId).to.equal(bidResponses.normal.banner.creativeId); + expect(result.dealId).to.equal(bidResponses.normal.banner.dealId); + expect(result.currency).to.equal(bidResponses.normal.banner.currency); + expect(result.netRevenue).to.equal(bidResponses.normal.banner.netRevenue); + expect(result.ttl).to.equal(bidResponses.normal.banner.ttl); + expect(result.ad).to.equal(bidResponses.normal.banner.ad); + expect(result.meta.advertiserDomains).deep.equal(bidResponses.normal.banner.adomain); + }); + + it('handles native responses', function () { + const result = spec.interpretResponse({body: serverResponse.normal.native}, bidRequests.native)[0]; + expect(result.requestId).to.equal(bidResponses.normal.native.requestId); + expect(result.width).to.equal(bidResponses.normal.native.width); + expect(result.height).to.equal(bidResponses.normal.native.height); + expect(result.creativeId).to.equal(bidResponses.normal.native.creativeId); + expect(result.dealId).to.equal(bidResponses.normal.native.dealId); + expect(result.currency).to.equal(bidResponses.normal.native.currency); + expect(result.netRevenue).to.equal(bidResponses.normal.native.netRevenue); + expect(result.ttl).to.equal(bidResponses.normal.native.ttl); + expect(result.native.title).to.equal(bidResponses.normal.native.native.title); + expect(result.native.image.url).to.equal(bidResponses.normal.native.native.image.url); + expect(result.native.image.height).to.equal(bidResponses.normal.native.native.image.height); + expect(result.native.image.width).to.equal(bidResponses.normal.native.native.image.width); + expect(result.native.icon.url).to.equal(bidResponses.normal.native.native.icon.url); + expect(result.native.icon.width).to.equal(bidResponses.normal.native.native.icon.width); + expect(result.native.icon.height).to.equal(bidResponses.normal.native.native.icon.height); + expect(result.native.sponsoredBy).to.equal(bidResponses.normal.native.native.sponsoredBy); + expect(result.native.body).to.equal(bidResponses.normal.native.native.body); + expect(result.native.cta).to.equal(bidResponses.normal.native.native.cta); + expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.normal.native.native.privacyLink); + expect(result.native.clickUrl).to.equal(bidResponses.normal.native.native.clickUrl); + expect(result.native.impressionTrackers[0]).to.equal(bidResponses.normal.native.native.impressionTrackers[0]); + expect(result.native.clickTrackers[0]).to.equal(bidResponses.normal.native.native.clickTrackers[0]); + expect(result.mediaType).to.equal(bidResponses.normal.native.mediaType); + expect(result.meta.advertiserDomains).deep.equal(bidResponses.normal.native.adomain); }); it('handles banner responses for empty adomain', function () { diff --git a/test/spec/modules/adhashBidAdapter_spec.js b/test/spec/modules/adhashBidAdapter_spec.js deleted file mode 100644 index 6c214b84928..00000000000 --- a/test/spec/modules/adhashBidAdapter_spec.js +++ /dev/null @@ -1,155 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adhashBidAdapter.js'; - -describe('adhashBidAdapter', function () { - describe('isBidRequestValid', function () { - const validBid = { - bidder: 'adhash', - params: { - publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb', - platformURL: 'https://adhash.org/p/struma/' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '12345678901234', - bidderRequestId: '98765432109876', - auctionId: '01234567891234', - }; - - it('should return true when all mandatory parameters are there', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return false when there are no params', function () { - const bid = { ...validBid }; - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when unsupported media type is requested', function () { - const bid = { ...validBid }; - bid.mediaTypes = { native: { sizes: [[300, 250]] } }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not a string', function () { - const bid = { ...validBid }; - bid.params.publisherId = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not valid', function () { - const bid = { ...validBid }; - bid.params.publisherId = 'short string'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not a string', function () { - const bid = { ...validBid }; - bid.params.platformURL = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not valid', function () { - const bid = { ...validBid }; - bid.params.platformURL = 'https://'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequest = { - params: { - publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb' - }, - sizes: [[300, 250]], - adUnitCode: 'adUnitCode' - }; - it('should build the request correctly', function () { - const result = spec.buildRequests( - [ bidRequest ], - { gdprConsent: true, refererInfo: { referer: 'http://example.com/' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=1.0&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'); - expect(result[0].bidRequest).to.equal(bidRequest); - expect(result[0].data).to.have.property('timezone'); - expect(result[0].data).to.have.property('location'); - expect(result[0].data).to.have.property('publisherId'); - expect(result[0].data).to.have.property('size'); - expect(result[0].data).to.have.property('navigator'); - expect(result[0].data).to.have.property('creatives'); - expect(result[0].data).to.have.property('blockedCreatives'); - expect(result[0].data).to.have.property('currentTimestamp'); - expect(result[0].data).to.have.property('recentAds'); - }); - it('should build the request correctly without referer', function () { - const result = spec.buildRequests([ bidRequest ], { gdprConsent: true }); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=1.0&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'); - expect(result[0].bidRequest).to.equal(bidRequest); - expect(result[0].data).to.have.property('timezone'); - expect(result[0].data).to.have.property('location'); - expect(result[0].data).to.have.property('publisherId'); - expect(result[0].data).to.have.property('size'); - expect(result[0].data).to.have.property('navigator'); - expect(result[0].data).to.have.property('creatives'); - expect(result[0].data).to.have.property('blockedCreatives'); - expect(result[0].data).to.have.property('currentTimestamp'); - expect(result[0].data).to.have.property('recentAds'); - }); - }); - - describe('interpretResponse', function () { - const request = { - data: { some: 'data' }, - bidRequest: { - bidId: '12345678901234', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - params: { - platformURL: 'https://adhash.org/p/struma/' - } - } - }; - - it('should interpret the response correctly', function () { - const serverResponse = { - body: { - creatives: [{ costEUR: 1.234 }], - advertiserDomains: 'adhash.org' - } - }; - const result = spec.interpretResponse(serverResponse, request); - expect(result.length).to.equal(1); - expect(result[0].requestId).to.equal('12345678901234'); - expect(result[0].cpm).to.equal(1.234); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].creativeId).to.equal('adunit-code'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].ttl).to.equal(60); - expect(result[0].meta.advertiserDomains).to.eql(['adhash.org']); - }); - - it('should return empty array when there are no creatives returned', function () { - expect(spec.interpretResponse({body: {creatives: []}}, request).length).to.equal(0); - }); - - it('should return empty array when there is no creatives key in the response', function () { - expect(spec.interpretResponse({body: {}}, request).length).to.equal(0); - }); - - it('should return empty array when something is not right', function () { - expect(spec.interpretResponse(null, request).length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/adheseBidAdapter_spec.js b/test/spec/modules/adheseBidAdapter_spec.js index 3fe0a62b2a0..78ca25d6be2 100644 --- a/test/spec/modules/adheseBidAdapter_spec.js +++ b/test/spec/modules/adheseBidAdapter_spec.js @@ -1,6 +1,5 @@ import {expect} from 'chai'; import {spec} from 'modules/adheseBidAdapter.js'; -import {config} from 'src/config.js'; const BID_ID = 456; const TTL = 360; @@ -132,21 +131,12 @@ describe('AdheseAdapter', function () { expect(JSON.parse(req.data)).to.not.have.key('eids'); }); - it('should request vast content as url by default', function () { + it('should request vast content as url', function () { let req = spec.buildRequests([ minimalBid() ], bidderRequest); expect(JSON.parse(req.data).vastContentAsUrl).to.equal(true); }); - it('should request vast content as markup when configured', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ vastContentAsUrl: false }); - - let req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).vastContentAsUrl).to.equal(false); - config.getConfig.restore(); - }); - it('should include bids', function () { let bid = minimalBid(); let req = spec.buildRequests([ bid ], bidderRequest); @@ -165,22 +155,6 @@ describe('AdheseAdapter', function () { expect(req.url).to.equal('https://ads-demo.adhese.com/json'); }); - - it('should include params specified in the config', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ globalTargets: { 'tl': [ 'all' ] } }); - let req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'tl': [ 'all' ] }); - config.getConfig.restore(); - }); - - it('should give priority to bid params over config params', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ globalTargets: { 'xt': ['CONFIG_CONSENT_STRING'] } }); - let req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'xt': [ 'CONSENT_STRING' ] }); - config.getConfig.restore(); - }); }); describe('interpretResponse', () => { diff --git a/test/spec/modules/adlooxAnalyticsAdapter_spec.js b/test/spec/modules/adlooxAnalyticsAdapter_spec.js index b87fd20adc2..0264922f45e 100644 --- a/test/spec/modules/adlooxAnalyticsAdapter_spec.js +++ b/test/spec/modules/adlooxAnalyticsAdapter_spec.js @@ -3,7 +3,7 @@ import analyticsAdapter, { command as analyticsCommand, COMMAND } from 'modules/ import { AUCTION_COMPLETED } from 'src/auction.js'; import { expect } from 'chai'; import events from 'src/events.js'; -import CONSTANTS from 'src/constants.json'; +import { EVENTS } from 'src/constants.json'; import * as utils from 'src/utils.js'; import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; @@ -35,7 +35,7 @@ describe('Adloox Analytics Adapter', function () { tagid: 0, params: { dummy1: '%%client%%', - dummy2: '%%pbadslot%%', + dummy2: '%%pbAdSlot%%', dummy3: function(bid) { throw new Error(esplode) } } }; @@ -143,10 +143,10 @@ describe('Adloox Analytics Adapter', function () { return arg.tagName === 'LINK' && arg.getAttribute('rel') === 'preload' && arg.getAttribute('as') === 'script' && href_uri.href === uri.href; }; - events.emit(CONSTANTS.EVENTS.AUCTION_END, auctionDetails); + events.emit(EVENTS.AUCTION_END, auctionDetails); expect(insertElementStub.calledWith(sinon.match(isLinkPreloadAsScript))).to.true; - events.emit(CONSTANTS.EVENTS.AUCTION_END, auctionDetails); + events.emit(EVENTS.AUCTION_END, auctionDetails); expect(insertElementStub.callCount).to.equal(1); done(); @@ -167,7 +167,7 @@ describe('Adloox Analytics Adapter', function () { const querySelectorStub = sandbox.stub(document, 'querySelector'); querySelectorStub.withArgs(`#${bid.adUnitCode}`).returns(slot); - events.emit(CONSTANTS.EVENTS.BID_WON, bid); + events.emit(EVENTS.BID_WON, bid); const [urlInserted, moduleCode] = loadExternalScriptStub.getCall(0).args; @@ -196,7 +196,7 @@ describe('Adloox Analytics Adapter', function () { const querySelectorStub = sandbox.stub(document, 'querySelector'); querySelectorStub.withArgs(`#${bid.adUnitCode}`).returns(slot); - events.emit(CONSTANTS.EVENTS.BID_WON, bidIgnore); + events.emit(EVENTS.BID_WON, bidIgnore); expect(parent.querySelector('script')).is.null; @@ -238,7 +238,7 @@ describe('Adloox Analytics Adapter', function () { it('should inject tracking event', function (done) { const data = { - eventType: CONSTANTS.EVENTS.BID_WON, + eventType: EVENTS.BID_WON, args: bid }; diff --git a/test/spec/modules/adlooxRtdProvider_spec.js b/test/spec/modules/adlooxRtdProvider_spec.js deleted file mode 100644 index c0438c45451..00000000000 --- a/test/spec/modules/adlooxRtdProvider_spec.js +++ /dev/null @@ -1,313 +0,0 @@ -import adapterManager from 'src/adapterManager.js'; -import analyticsAdapter from 'modules/adlooxAnalyticsAdapter.js'; -import { config as _config } from 'src/config.js'; -import { expect } from 'chai'; -import events from 'src/events.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; -import { subModuleObj as rtdProvider } from 'modules/adlooxRtdProvider.js'; -import * as utils from 'src/utils.js'; - -const analyticsAdapterName = 'adloox'; - -describe('Adloox RTD Provider', function () { - let sandbox; - - const adUnit = { - code: 'ad-slot-1', - ortb2Imp: { - ext: { - data: { - pbadslot: '/123456/home/ad-slot-1' - } - } - }, - mediaTypes: { - banner: { - sizes: [ [300, 250] ] - } - }, - bids: [ - { - bidder: 'dummy' - } - ] - }; - - const analyticsOptions = { - js: 'https://j.adlooxtracking.com/ads/js/tfav_adl_%%clientid%%.js', - client: 'adlooxtest', - clientid: 127, - platformid: 0, - tagid: 0 - }; - - const config = {}; - - adapterManager.registerAnalyticsAdapter({ - code: analyticsAdapterName, - adapter: analyticsAdapter - }); - - before(function () { - sandbox = sinon.sandbox.create(); - sandbox.stub(events, 'getEvents').returns([]); - }); - - after(function () { - sandbox.restore(); - sandbox = undefined; - }); - - describe('invalid config', function () { - it('should require config', function (done) { - const ret = rtdProvider.init(); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-object config.params', function (done) { - const ret = rtdProvider.init({ params: null }); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-string config.params.api_origin', function (done) { - const ret = rtdProvider.init({ params: { api_origin: null } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject less than one config.params.imps', function (done) { - const ret = rtdProvider.init({ params: { imps: 0 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject negative config.params.freqcap_ip', function (done) { - const ret = rtdProvider.init({ params: { freqcap_ip: -1 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject negative integer config.params.freqcap_ipua', function (done) { - const ret = rtdProvider.init({ params: { freqcap_ipua: -1 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-array of integers with value greater than zero config.params.thresholds', function (done) { - const ret = rtdProvider.init({ params: { thresholds: [ 70, null ] } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-boolean config.params.slotinpath', function (done) { - const ret = rtdProvider.init({ params: { slotinpath: null } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject invalid config.params.params (legacy/deprecated)', function (done) { - const ret = rtdProvider.init({ params: { params: { clientid: 0, tagid: 0 } } }); - - expect(ret).is.false; - - done(); - }); - }); - - describe('process segments', function () { - before(function () { - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptions - }); - expect(analyticsAdapter.context).is.not.null; - }); - - after(function () { - analyticsAdapter.disableAnalytics(); - expect(analyticsAdapter.context).is.null; - }); - - let server = null; - let __config = null, CONFIG = null; - let getConfigStub, setConfigStub; - beforeEach(function () { - server = sinon.createFakeServer(); - __config = {}; - CONFIG = utils.deepClone(config); - getConfigStub = sinon.stub(_config, 'getConfig').callsFake(function (path) { - return utils.deepAccess(__config, path); - }); - setConfigStub = sinon.stub(_config, 'setConfig').callsFake(function (obj) { - utils.mergeDeep(__config, obj); - }); - }); - afterEach(function () { - setConfigStub.restore(); - getConfigStub.restore(); - getConfigStub = setConfigStub = undefined; - CONFIG = null; - __config = null; - server.restore(); - server = null; - }); - - it('should fetch segments', function (done) { - const adUnitWithSegments = utils.deepClone(adUnit); - const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({ - adUnits: [ adUnitWithSegments ] - }); - - const ret = rtdProvider.init(CONFIG); - expect(ret).is.true; - - const callback = function () { - expect(__config.ortb2.site.ext.data.adloox_rtd.ok).is.true; - expect(__config.ortb2.site.ext.data.adloox_rtd.nope).is.undefined; - expect(__config.ortb2.user.ext.data.adloox_rtd.unused).is.false; - expect(__config.ortb2.user.ext.data.adloox_rtd.nope).is.undefined; - expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.dis.length).is.equal(3); - expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.nope).is.undefined; - - getGlobalStub.restore(); - - done(); - }; - rtdProvider.getBidRequestData({}, callback, CONFIG, null); - - const request = server.requests[0]; - const response = { unused: false, _: [ { d: 77 } ] }; - request.respond(200, { 'content-type': 'application/json' }, JSON.stringify(response)); - }); - - it('should set ad server targeting', function (done) { - utils.deepSetValue(__config, 'ortb2.site.ext.data.adloox_rtd.ok', true); - - const adUnitWithSegments = utils.deepClone(adUnit); - utils.deepSetValue(adUnitWithSegments, 'ortb2Imp.ext.data.adloox_rtd.dis', [ 50, 60 ]); - const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({ - adUnits: [ adUnitWithSegments ] - }); - - const targetingData = rtdProvider.getTargetingData([ adUnitWithSegments.code ], CONFIG); - expect(Object.keys(targetingData).length).is.equal(1); - expect(Object.keys(targetingData[adUnit.code]).length).is.equal(2); - expect(targetingData[adUnit.code].adl_ok).is.equal(1); - expect(targetingData[adUnit.code].adl_dis.length).is.equal(2); - - getGlobalStub.restore(); - - done(); - }); - }); - - describe('measure atf', function () { - const adUnitCopy = utils.deepClone(adUnit); - - const ratio = 0.38; - const [ [width, height] ] = utils.getAdUnitSizes(adUnitCopy); - - before(function () { - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptions - }); - expect(analyticsAdapter.context).is.not.null; - }); - - after(function () { - analyticsAdapter.disableAnalytics(); - expect(analyticsAdapter.context).is.null; - }); - - it(`should return ${ratio} for same-origin`, function (done) { - const el = document.createElement('div'); - el.setAttribute('id', adUnitCopy.code); - - const offset = height * ratio; - const elStub = sinon.stub(el, 'getBoundingClientRect').returns({ - top: 0 - (height - offset), - bottom: height - offset, - left: 0, - right: width - }); - - const querySelectorStub = sinon.stub(document, 'querySelector'); - querySelectorStub.withArgs(`#${adUnitCopy.code}`).returns(el); - - rtdProvider.atf(adUnitCopy, function(x) { - expect(x).is.equal(ratio); - - querySelectorStub.restore(); - elStub.restore(); - - done(); - }); - }); - - ('IntersectionObserver' in window ? it : it.skip)(`should return ${ratio} for cross-origin`, function (done) { - const frameElementStub = sinon.stub(window, 'frameElement').value(null); - - const el = document.createElement('div'); - el.setAttribute('id', adUnitCopy.code); - - const elStub = sinon.stub(el, 'getBoundingClientRect').returns({ - top: 0, - bottom: height, - left: 0, - right: width - }); - - const querySelectorStub = sinon.stub(document, 'querySelector'); - querySelectorStub.withArgs(`#${adUnitCopy.code}`).returns(el); - - let intersectionObserverStubFn = null; - const intersectionObserverStub = sinon.stub(window, 'IntersectionObserver').callsFake((fn) => { - intersectionObserverStubFn = fn; - return { - observe: (element) => { - expect(element).is.equal(el); - - intersectionObserverStubFn([{ - target: element, - intersectionRect: { width, height }, - intersectionRatio: ratio - }]); - }, - unobserve: (element) => { - expect(element).is.equal(el); - } - } - }); - - rtdProvider.atf(adUnitCopy, function(x) { - expect(x).is.equal(ratio); - - intersectionObserverStub.restore(); - querySelectorStub.restore(); - elStub.restore(); - frameElementStub.restore(); - - done(); - }); - }); - }); -}); diff --git a/test/spec/modules/admanBidAdapter_spec.js b/test/spec/modules/admanBidAdapter_spec.js deleted file mode 100644 index 33e6a8a89b9..00000000000 --- a/test/spec/modules/admanBidAdapter_spec.js +++ /dev/null @@ -1,187 +0,0 @@ -import {expect} from 'chai'; -import {spec} from '../../../modules/admanBidAdapter.js'; - -describe('AdmanAdapter', function () { - let bid = { - bidId: '2dd581a2b6281d', - bidder: 'adman', - bidderRequestId: '145e1d6a7837c9', - params: { - placementId: 0 - }, - placementCode: 'placementid_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '0', - hp: 1, - rid: 'bidrequestid', - // name: 'alladsallthetime', - domain: 'example.com' - } - ] - } - }; - let bidderRequest = { - bidderCode: 'adman', - auctionId: 'fffffff-ffff-ffff-ffff-ffffffffffff', - bidderRequestId: 'ffffffffffffff', - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000, - uspConsent: '1YN-', - refererInfo: { - referer: 'http://www.example.com', - reachedTop: true, - }, - bids: [bid] - } - - describe('isBidRequestValid', function () { - it('Should return true when placementId can be cast to a number', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false when placementId is not a number', function () { - bid.params.placementId = 'aaa'; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests([bid], bidderRequest); - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://pub.admanmedia.com/?c=o&m=multi'); - }); - it('Should contain ccpa', function() { - expect(serverRequest.data.ccpa).to.be.an('string') - }) - - it('Returns valid data if array of bids is valid', function () { - let data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'ccpa'); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - let placements = data['placements']; - for (let i = 0; i < placements.length; i++) { - let placement = placements[i]; - expect(placement).to.have.all.keys('placementId', 'eids', 'bidId', 'traffic', 'sizes', 'schain', 'bidFloor'); - expect(placement.schain).to.be.an('object') - expect(placement.placementId).to.be.a('number'); - expect(placement.bidId).to.be.a('string'); - expect(placement.traffic).to.be.a('string'); - expect(placement.sizes).to.be.an('array'); - expect(placement.bidFloor).to.be.an('number'); - } - }); - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([]); - let data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - - describe('buildRequests with user ids', function () { - bid.userId = {} - bid.userId.uid2 = { id: 'uid2id123' }; - let serverRequest = spec.buildRequests([bid], bidderRequest); - it('Returns valid data if array of bids is valid', function () { - let data = serverRequest.data; - let placements = data['placements']; - expect(data).to.be.an('object'); - for (let i = 0; i < placements.length; i++) { - let placement = placements[i]; - expect(placement).to.have.property('eids') - expect(placement.eids).to.be.an('array') - expect(placement.eids.length).to.be.equal(1) - for (let index in placement.eids) { - let v = placement.eids[index]; - expect(v).to.have.all.keys('source', 'uids') - expect(v.source).to.be.oneOf(['uidapi.com']) - expect(v.uids).to.be.an('array'); - expect(v.uids.length).to.be.equal(1) - expect(v.uids[0]).to.have.property('id') - } - } - }); - }); - - describe('interpretResponse', function () { - let resObject = { - body: [ { - requestId: '123', - mediaType: 'banner', - cpm: 0.3, - width: 320, - height: 50, - ad: '

Hello ad

', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - } ] - }; - let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', function () { - expect(serverResponses).to.be.an('array').that.is.not.empty; - for (let i = 0; i < serverResponses.length; i++) { - let dataItem = serverResponses[i]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'mediaType', 'meta'); - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.ad).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.mediaType).to.be.a('string'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - } - it('Returns an empty array if invalid response is passed', function () { - serverResponses = spec.interpretResponse('invalid_response'); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - }); - - describe('getUserSyncs', function () { - let userSync = spec.getUserSyncs({}); - it('Returns valid URL and type', function () { - expect(userSync).to.be.an('array').with.lengthOf(1); - expect(userSync[0].type).to.exist; - expect(userSync[0].url).to.exist; - expect(userSync[0].type).to.be.equal('image'); - expect(userSync[0].url).to.be.equal('https://pub.admanmedia.com/image?pbjs=1&coppa=0'); - }); - }); -}); diff --git a/test/spec/modules/admixerBidAdapter_spec.js b/test/spec/modules/admixerBidAdapter_spec.js index 6dfde0d0652..27dc895e3a4 100644 --- a/test/spec/modules/admixerBidAdapter_spec.js +++ b/test/spec/modules/admixerBidAdapter_spec.js @@ -67,7 +67,7 @@ describe('AdmixerAdapter', function () { it('should add referrer and imp to be equal bidRequest', function () { const request = spec.buildRequests(validRequest, bidderRequest); - const payload = request.data; + const payload = JSON.parse(request.data.substr(5)); expect(payload.referrer).to.not.be.undefined; expect(payload.imps[0]).to.deep.equal(validRequest[0]); }); @@ -75,7 +75,7 @@ describe('AdmixerAdapter', function () { it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(validRequest, bidderRequest); expect(request.url).to.equal(ENDPOINT_URL); - expect(request.method).to.equal('POST'); + expect(request.method).to.equal('GET'); }); it('sends bid request to CUSTOM_ENDPOINT via GET', function () { @@ -85,7 +85,7 @@ describe('AdmixerAdapter', function () { }); const request = config.runWithBidder(BIDDER_CODE, () => spec.buildRequests(validRequest, bidderRequest)); expect(request.url).to.equal(ENDPOINT_URL_CUSTOM); - expect(request.method).to.equal('POST'); + expect(request.method).to.equal('GET'); }); }); diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js index 3b6ad8d0912..e2682b8d0d5 100644 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ b/test/spec/modules/adnuntiusBidAdapter_spec.js @@ -19,7 +19,6 @@ describe('adnuntiusBidAdapter', function () { }); const tzo = new Date().getTimezoneOffset(); const ENDPOINT_URL = `${URL}${tzo}&format=json&userId=${usi}`; - const ENDPOINT_URL_NOCOOKIE = `${URL}${tzo}&format=json&userId=${usi}&noCookies=true`; const ENDPOINT_URL_SEGMENTS = `${URL}${tzo}&format=json&segments=segment1,segment2,segment3&userId=${usi}`; const ENDPOINT_URL_CONSENT = `${URL}${tzo}&format=json&consentString=consentString&userId=${usi}`; const adapter = newBidder(spec); @@ -200,108 +199,6 @@ describe('adnuntiusBidAdapter', function () { expect(request[0]).to.have.property('url') expect(request[0].url).to.equal(ENDPOINT_URL); }); - - it('should pass segments if available in config', function () { - config.setBidderConfig({ - bidders: ['adnuntius', 'other'], - config: { - ortb2: { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }] - }, - { - name: 'other', - segment: ['segment3'] - }], - } - } - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests)); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS); - }); - - it('should skip segments in config if not either id or array of strings', function () { - config.setBidderConfig({ - bidders: ['adnuntius', 'other'], - config: { - ortb2: { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }, { id: 'segment3' }] - }, - { - name: 'other', - segment: [{ - notright: 'segment4' - }] - }], - } - } - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests)); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS); - }); - - it('should user user ID if present in ortb2.user.id field', function () { - config.setBidderConfig({ - bidders: ['adnuntius', 'other'], - config: { - ortb2: { - user: { - id: usi - } - } - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests)); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL); - }); - }); - - describe('user privacy', function () { - it('should send GDPR Consent data if gdprApplies', function () { - let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL_CONSENT); - }); - - it('should not send GDPR Consent data if gdprApplies equals undefined', function () { - let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL); - }); - }); - - describe('use cookie', function () { - it('should send noCookie in url if set to false.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - useCookie: false - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests)); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL_NOCOOKIE); - }); }); describe('interpretResponse', function () { diff --git a/test/spec/modules/adomikAnalyticsAdapter_spec.js b/test/spec/modules/adomikAnalyticsAdapter_spec.js index 93822d04c88..1414b2402b9 100644 --- a/test/spec/modules/adomikAnalyticsAdapter_spec.js +++ b/test/spec/modules/adomikAnalyticsAdapter_spec.js @@ -1,6 +1,5 @@ import adomikAnalytics from 'modules/adomikAnalyticsAdapter.js'; -import { expect } from 'chai'; - +import {expect} from 'chai'; let events = require('src/events'); let adapterManager = require('src/adapterManager').default; let constants = require('src/constants.json'); @@ -9,7 +8,6 @@ describe('Adomik Prebid Analytic', function () { let sendEventStub; let sendWonEventStub; let clock; - before(function () { clock = sinon.useFakeTimers(); }); @@ -45,8 +43,6 @@ describe('Adomik Prebid Analytic', function () { const initOptions = { id: '123456', url: 'testurl', - testId: '12345', - testValue: '1000' }; const bid = { @@ -73,9 +69,6 @@ describe('Adomik Prebid Analytic', function () { expect(adomikAnalytics.currentContext).to.deep.equal({ uid: '123456', url: 'testurl', - sampling: undefined, - testId: '12345', - testValue: '1000', id: '', timeouted: false }); @@ -86,9 +79,6 @@ describe('Adomik Prebid Analytic', function () { expect(adomikAnalytics.currentContext).to.deep.equal({ uid: '123456', url: 'testurl', - sampling: undefined, - testId: '12345', - testValue: '1000', id: 'test-test-test', timeouted: false }); @@ -101,7 +91,7 @@ describe('Adomik Prebid Analytic', function () { type: 'request', event: { bidder: 'BIDDERTEST', - placementCode: '0000', + placementCode: 'placementtest', } }); diff --git a/test/spec/modules/adpartnerBidAdapter_spec.js b/test/spec/modules/adpartnerBidAdapter_spec.js deleted file mode 100644 index 94b56f7735b..00000000000 --- a/test/spec/modules/adpartnerBidAdapter_spec.js +++ /dev/null @@ -1,336 +0,0 @@ -import {expect} from 'chai'; -import {spec, ENDPOINT_PROTOCOL, ENDPOINT_DOMAIN, ENDPOINT_PATH} from 'modules/adpartnerBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'adpartner'; - -describe('AdpartnerAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - let validRequest = { - 'params': { - 'unitId': 123 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return true when required params is srting', function () { - let validRequest = { - 'params': { - 'unitId': '456' - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - let validRequest = { - 'params': { - 'unknownId': 123 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when required params is 0', function () { - let validRequest = { - 'params': { - 'unitId': 0 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain'; - - let validRequest = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'unitId': 123 - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e' - }, - { - 'bidder': BIDDER_CODE, - 'params': { - 'unitId': '456' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '22aidtbx5eabd9' - }, - { - 'bidder': BIDDER_CODE, - 'params': { - 'partnerId': 777 - }, - 'adUnitCode': 'partner-code-3', - 'sizes': [[300, 250]], - 'bidId': '5d4531d5a6c013' - } - ]; - - let bidderRequest = { - refererInfo: { - referer: 'https://test.domain' - } - }; - - it('bidRequest HTTP method', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.method).to.equal('POST'); - }); - - it('bidRequest url', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.url).to.equal(validEndpoint); - }); - - it('bidRequest data', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload[0].unitId).to.equal(123); - expect(payload[0].sizes).to.deep.equal([[300, 250], [300, 600]]); - expect(payload[0].bidId).to.equal('30b31c1838de1e'); - expect(payload[1].unitId).to.equal(456); - expect(payload[1].sizes).to.deep.equal([[728, 90]]); - expect(payload[1].bidId).to.equal('22aidtbx5eabd9'); - expect(payload[2].partnerId).to.equal(777); - expect(payload[2].sizes).to.deep.equal([[300, 250]]); - expect(payload[2].bidId).to.equal('5d4531d5a6c013'); - }); - }); - - describe('joinSizesToString', function () { - it('success convert sizes list to string', function () { - const sizesStr = spec.joinSizesToString([[300, 250], [300, 600]]); - expect(sizesStr).to.equal('300x250|300x600'); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - 'method': 'POST', - 'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777code=adunit-code-1,adunit-code-2,partner-code-3&bid=30b31c1838de1e,22aidtbx5eabd9,5d4531d5a6c013&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain', - 'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},' + - '{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"},' + - '{"unitId": 0,"partnerId": 777,"adUnitCode":"div-gpt-ad-1460505748561-2","sizes": [[300, 250]],"bidId": "5d4531d5a6c013","referer": "https://test.domain/index.html"}]' - }; - - const bidResponse = { - body: { - 'div-gpt-ad-1460505748561-0': - { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'adomain': [ - 'test.domain' - ], - 'syncs': [ - {'type': 'image', 'url': 'https://test.domain/tracker_1.gif'}, - {'type': 'image', 'url': 'https://test.domain/tracker_2.gif'}, - {'type': 'image', 'url': 'https://test.domain/tracker_3.gif'} - ], - 'winNotification': [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true - } - }, - headers: {} - }; - - it('result is correct', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].requestId).to.equal('2bdcb0b203c17d'); - expect(result[0].cpm).to.equal(0.01); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].creativeId).to.equal('8:123456'); - expect(result[0].currency).to.equal('USD'); - expect(result[0].ttl).to.equal(60); - expect(result[0].meta.advertiserDomains).to.deep.equal(['test.domain']); - expect(result[0].winNotification[0]).to.deep.equal({'method': 'POST', 'path': '/hb/bid_won?test=1', 'data': {'ad': [{'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'}], 'unit_id': 1234, 'site_id': 123}}); - }); - }); - - describe('adResponse', function () { - const bid = { - 'unitId': 13144370, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '2bdcb0b203c17d', - 'referer': 'https://test.domain/index.html' - }; - const ad = { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'syncs': [], - 'winNotification': [], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true, - 'adomain': [ - 'test.domain' - ], - }; - - it('fill ad for response', function () { - const result = spec.adResponse(bid, ad); - expect(result.requestId).to.equal('2bdcb0b203c17d'); - expect(result.cpm).to.equal(0.01); - expect(result.width).to.equal(300); - expect(result.height).to.equal(250); - expect(result.creativeId).to.equal('8:123456'); - expect(result.currency).to.equal('USD'); - expect(result.ttl).to.equal(60); - expect(result.meta.advertiserDomains).to.deep.equal(['test.domain']); - }); - }); - - describe('onBidWon', function () { - const bid = { - winNotification: [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 0.01, 'nurl': 'http://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ] - }; - - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'postRequest') - }) - - afterEach(() => { - ajaxStub.restore() - }) - - it('calls adpartner\'s callback endpoint', () => { - const result = spec.onBidWon(bid); - expect(result).to.equal(true); - expect(ajaxStub.calledOnce).to.equal(true); - expect(ajaxStub.firstCall.args[0]).to.equal(ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + '/hb/bid_won?test=1'); - expect(ajaxStub.firstCall.args[1]).to.deep.equal(JSON.stringify(bid.winNotification[0].data)); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse = [{ - body: { - 'div-gpt-ad-1460505748561-0': - { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'adomain': [ - 'test.domain' - ], - 'syncs': [ - {'type': 'image', 'link': 'https://test.domain/tracker_1.gif'}, - {'type': 'image', 'link': 'https://test.domain/tracker_2.gif'}, - {'type': 'image', 'link': 'https://test.domain/tracker_3.gif'} - ], - 'winNotification': [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true - } - }, - headers: {} - }]; - - it('should return nothing when sync is disabled', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': false - }; - - let syncs = spec.getUserSyncs(syncOptions); - expect(syncs).to.deep.equal([]); - }); - - it('should register image sync when only image is enabled where gdprConsent is undefined', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true - }; - - const gdprConsent = undefined; - let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); - expect(syncs.length).to.equal(3); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif'); - }); - - it('should register image sync when only image is enabled where gdprConsent is defined', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true - }; - const gdprConsent = { - consentString: 'someString', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - - let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); - expect(syncs.length).to.equal(3); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif?gdpr=1&gdpr_consent=someString'); - }); - }); -}); diff --git a/test/spec/modules/adplusBidAdapter_spec.js b/test/spec/modules/adplusBidAdapter_spec.js deleted file mode 100644 index 840d86c80f1..00000000000 --- a/test/spec/modules/adplusBidAdapter_spec.js +++ /dev/null @@ -1,213 +0,0 @@ -import {expect} from 'chai'; -import {spec, BIDDER_CODE, ADPLUS_ENDPOINT, } from 'modules/adplusBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -describe('AplusBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - let validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '30', - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - let validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '30', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when required param types are wrong', function () { - let validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when size is not exists', function () { - let validRequest = { - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when size is wrong', function () { - let validRequest = { - mediaTypes: { - banner: { - sizes: [[300]] - } - }, - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let validRequest = [ - { - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '-1', - adUnitId: '-3', - }, - bidId: '2bdcb0b203c17d' - }, - ]; - - let bidderRequest = { - refererInfo: { - referer: 'https://test.domain' - } - }; - - it('bidRequest HTTP method', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request[0].method).to.equal('GET'); - }); - - it('bidRequest url', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request[0].url).to.equal(ADPLUS_ENDPOINT); - }); - - it('tests bidRequest data is clean and has the right values', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - - expect(request[0].data.bidId).to.equal('2bdcb0b203c17d'); - expect(request[0].data.inventoryId).to.equal('-1'); - expect(request[0].data.adUnitId).to.equal('-3'); - expect(request[0].data.adUnitWidth).to.equal(300); - expect(request[0].data.adUnitHeight).to.equal(250); - expect(request[0].data.sdkVersion).to.equal('1'); - expect(typeof request[0].data.session).to.equal('string'); - expect(request[0].data.session).length(36); - expect(request[0].data.interstitial).to.equal(0); - expect(request[0].data).to.not.have.deep.property('extraData'); - expect(request[0].data).to.not.have.deep.property('yearOfBirth'); - expect(request[0].data).to.not.have.deep.property('gender'); - expect(request[0].data).to.not.have.deep.property('categories'); - expect(request[0].data).to.not.have.deep.property('latitude'); - expect(request[0].data).to.not.have.deep.property('longitude'); - }); - }); - - describe('interpretResponse', function () { - const requestData = { - language: window.navigator.language, - screenWidth: 1440, - screenHeight: 900, - sdkVersion: '1', - inventoryId: '-1', - adUnitId: '-3', - adUnitWidth: 300, - adUnitHeight: 250, - domain: 'tassandigi.com', - pageUrl: 'https%3A%2F%2Ftassandigi.com%2Fserafettin%2Fads.html', - interstitial: 0, - session: '1c02db03-5289-932a-93af-7b4022611fec', - token: '1c02db03-5289-937a-93df-7b4022611fec', - secure: 1, - bidId: '2bdcb0b203c17d', - }; - const bidRequest = { - 'method': 'GET', - 'url': ADPLUS_ENDPOINT, - 'data': requestData, - }; - - const bidResponse = { - body: [ - { - 'ad': '
ad
', - 'advertiserDomains': [ - 'advertiser.com' - ], - 'categoryIDs': [ - 'IAB-111' - ], - 'cpm': 3.57, - 'creativeID': '1', - 'currency': 'TRY', - 'dealID': '1', - 'height': 300, - 'mediaType': 'banner', - 'netRevenue': true, - 'requestID': '2bdcb0b203c17d', - 'ttl': 300, - 'width': 250 - } - ], - headers: {} - }; - - const emptyBidResponse = { - body: null, - }; - - it('returns an empty array when the result body is not valid', function () { - const result = spec.interpretResponse(emptyBidResponse, bidRequest); - expect(result).to.deep.equal([]); - }); - - it('result is correct', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].requestId).to.equal('2bdcb0b203c17d'); - expect(result[0].cpm).to.equal(3.57); - expect(result[0].width).to.equal(250); - expect(result[0].height).to.equal(300); - expect(result[0].creativeId).to.equal('1'); - expect(result[0].currency).to.equal('TRY'); - expect(result[0].dealId).to.equal('1'); - expect(result[0].mediaType).to.equal('banner'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].ttl).to.equal(300); - expect(result[0].meta.advertiserDomains).to.deep.equal(['advertiser.com']); - expect(result[0].meta.secondaryCatIds).to.deep.equal(['IAB-111']); - }); - }); -}); diff --git a/test/spec/modules/adqueryBidAdapter_spec.js b/test/spec/modules/adqueryBidAdapter_spec.js deleted file mode 100644 index 4285377e8a7..00000000000 --- a/test/spec/modules/adqueryBidAdapter_spec.js +++ /dev/null @@ -1,185 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/adqueryBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' -import * as utils from '../../../src/utils'; - -describe('adqueryBidAdapter', function () { - const adapter = newBidder(spec) - let bidRequest = { - bidder: 'adquery', - params: { - placementId: '6d93f2a0e5f0fe2cc3a6e9e3ade964b43b07f897', - type: 'banner300x250' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - } - } - - let expectedResponse = { - 'body': { - 'data': - { - 'requestId': 1, - 'emission_id': 1, - 'eventTracker': 'https://example.com', - 'externalEmissionCodes': 'https://example.com', - 'impressionTracker': 'https://example.com', - 'viewabilityTracker': 'https://example.com', - 'clickTracker': 'https://example.com', - 'link': 'https://example.com', - 'logo': 'https://example.com', - 'medias': [ - { - 'src': 'banner/2021-04-09/938', - 'ext': 'zip', - 'type': 3, - } - ], - 'domain': 'https://example.com', - 'urlAdq': 'https://example.com', - 'creationId': 1, - 'currency': 'PLN', - 'adDomains': ['https://example.com'], - 'tag': ' ', - 'adqLib': 'https://example.com/js/example.js', - 'mediaType': {'width': 300, 'height': 250, 'name': 'banner', 'type': 'banner300x250'}, - 'cpm': 2.5, - 'meta': { - 'advertiserDomains': ['example.com'], - 'mediaType': 'banner', - } - } - } - } - describe('codes', function () { - it('should return a bidder code of adquery', function () { - expect(spec.code).to.equal('adquery') - }) - }) - - describe('isBidRequestValid', function () { - let inValidBid = Object.assign({}, bidRequest) - delete inValidBid.params - it('should return true if all params present', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true) - }) - - it('should return false if any parameter missing', function () { - expect(spec.isBidRequestValid(inValidBid)).to.be.false - }) - }) - - describe('buildRequests', function () { - let req = spec.buildRequests([ bidRequest ], { refererInfo: { } })[0] - let rdata - - it('should return request object', function () { - expect(req).to.not.be.null - }) - - it('should build request data', function () { - expect(req.data).to.not.be.null - }) - - it('should include one request', function () { - rdata = req.data; - expect(rdata.data).to.not.be.null - }) - - it('should include placementCode', function () { - expect(rdata.placementCode).not.be.null - }) - - it('should include qid', function () { - expect(rdata.qid).not.be.null - }) - - it('should include type', function () { - expect(rdata.type !== null).not.be.null - }) - - it('should include all publisher params', function () { - expect(rdata.type !== null && rdata.placementCode !== null).to.be.true - }) - - it('should include bidder', function () { - expect(rdata.bidder !== null).to.be.true - }) - }) - - describe('interpretResponse', function () { - it('should get the correct bid response', function () { - let result = spec.interpretResponse(expectedResponse) - expect(result).to.be.an('array') - }) - - it('validate response params', function() { - const newResponse = spec.interpretResponse(expectedResponse, bidRequest); - expect(newResponse[0].requestId).to.be.equal(1) - }); - it('handles empty bid response', function () { - let response = { - body: {} - }; - let result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }) - }) - - describe('getUserSyncs', function () { - it('should return iframe sync', function () { - let sync = spec.getUserSyncs() - expect(sync.length).to.equal(1) - expect(sync[0].type === 'iframe') - expect(typeof sync[0].url === 'string') - }) - - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - }); - }) - - describe('test onBidWon function', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - it('should return nothing', function () { - var response = spec.onBidWon({}); - expect(response).to.be.an('undefined') - expect(utils.triggerPixel.called).to.equal(true); - }); - }) - - describe('onTimeout', function () { - const timeoutData = [{ - timeout: null - }]; - - it('should exists and be a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - it('should include timeoutData', function () { - expect(spec.onTimeout(timeoutData)).to.be.undefined; - }) - }); - - it(`onSetTargeting is present and type function`, function () { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function') - }); -}) diff --git a/test/spec/modules/adqueryIdSystem_spec.js b/test/spec/modules/adqueryIdSystem_spec.js deleted file mode 100644 index ab98b253b33..00000000000 --- a/test/spec/modules/adqueryIdSystem_spec.js +++ /dev/null @@ -1,74 +0,0 @@ -import { adqueryIdSubmodule, storage } from 'modules/adqueryIdSystem.js'; -import { server } from 'test/mocks/xhr.js'; -import {amxIdSubmodule} from '../../../modules/amxIdSystem'; -import * as utils from '../../../src/utils'; - -const config = { - storage: { - type: 'html5', - }, -}; - -describe('AdqueryIdSystem', function () { - describe('qid submodule', () => { - it('should expose a "name" property containing qid', () => { - expect(adqueryIdSubmodule.name).to.equal('qid'); - }); - - it('should expose a "gvlid" property containing the GVL ID 902', () => { - expect(adqueryIdSubmodule.gvlid).to.equal(902); - }); - }); - - describe('getId', function() { - let getDataFromLocalStorageStub; - - beforeEach(function() { - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - it('gets a adqueryId', function() { - const config = { - params: {} - }; - const callbackSpy = sinon.spy(); - const callback = adqueryIdSubmodule.getId(config).callback; - callback(callbackSpy); - const request = server.requests[0]; - expect(request.url).to.eq(`https://bidder.adquery.io/prebid/qid`); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'qid' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); - }); - - it('gets a cached adqueryId', function() { - const config = { - params: {} - }; - getDataFromLocalStorageStub.withArgs('qid').returns('qid'); - - const callbackSpy = sinon.spy(); - const callback = adqueryIdSubmodule.getId(config).callback; - callback(callbackSpy); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); - }); - - it('allows configurable id url', function() { - const config = { - params: { - url: 'https://bidder.adquery.io' - } - }; - const callbackSpy = sinon.spy(); - const callback = adqueryIdSubmodule.getId(config).callback; - callback(callbackSpy); - const request = server.requests[0]; - expect(request.url).to.eq('https://bidder.adquery.io'); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'testqid' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'testqid'}); - }); - }); -}); diff --git a/test/spec/modules/adtelligentBidAdapter_spec.js b/test/spec/modules/adtelligentBidAdapter_spec.js index a004d888268..4cfb367efb3 100644 --- a/test/spec/modules/adtelligentBidAdapter_spec.js +++ b/test/spec/modules/adtelligentBidAdapter_spec.js @@ -17,7 +17,6 @@ const aliasEP = { mediafuse: 'https://ghb.hbmp.mediafuse.com/v2/auction/', navelix: 'https://ghb.hb.navelix.com/v2/auction/', bidsxchange: 'https://ghb.hbd.bidsxchange.com/v2/auction/', - streamkey: 'https://ghb.hb.streamkey.net/v2/auction/', }; const DEFAULT_ADATPER_REQ = { bidderCode: 'adtelligent' }; diff --git a/test/spec/modules/advangelistsBidAdapter_spec.js b/test/spec/modules/advangelistsBidAdapter_spec.js deleted file mode 100755 index e1cd6977c5d..00000000000 --- a/test/spec/modules/advangelistsBidAdapter_spec.js +++ /dev/null @@ -1,139 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/advangelistsBidAdapter'; -import { BANNER, VIDEO } from 'src/mediaTypes'; - -describe('advangelistsBidAdapter', function () { - let bidRequests; - let bidRequestsVid; - - beforeEach(function () { - bidRequests = [{'bidder': 'advangelists', 'params': {'pubid': '0cf8d6d643e13d86a5b6374148a4afac', 'placement': 1234}, 'crumbs': {'pubcid': '979fde13-c71e-4ac2-98b7-28c90f99b449'}, 'mediaTypes': {'banner': {'sizes': [[300, 250]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': 'f72931e6-2b0e-4e37-a2bc-1ea912141f81', 'sizes': [[300, 250]], 'bidId': '2aa73f571eaf29', 'bidderRequestId': '1bac84515a7af3', 'auctionId': '5dbc60fa-1aa1-41ce-9092-e6bbd4d478f7', 'src': 'client', 'bidRequestsCount': 1, 'pageurl': 'http://google.com'}]; - - bidRequestsVid = [{'bidder': 'advangelists', 'params': {'pubid': '8537f00948fc37cc03c5f0f88e198a76', 'placement': 1234}, 'crumbs': {'pubcid': '979fde13-c71e-4ac2-98b7-28c90f99b449'}, 'mediaTypes': {'video': {'playerSize': [[320, 480]], 'context': 'instream', 'skip': 1, 'mimes': ['video/mp4', 'application/javascript'], 'playbackmethod': [2, 6], 'maxduration': 30}}, 'adUnitCode': 'video1', 'transactionId': '8b060952-93f7-4863-af44-bb8796b97c42', 'sizes': [], 'bidId': '25c6ab92aa0e81', 'bidderRequestId': '1d420b73a013fc', 'auctionId': '9a69741c-34fb-474c-83e1-cfa003aaee17', 'src': 'client', 'bidRequestsCount': 1, 'pageurl': 'http://google.com'}]; - }); - - describe('spec.isBidRequestValid', function () { - it('should return true when the required params are passed for banner', function () { - const bidRequest = bidRequests[0]; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when the required params are passed for video', function () { - const bidRequests = bidRequestsVid[0]; - expect(spec.isBidRequestValid(bidRequests)).to.equal(true); - }); - - it('should return false when no pub id params are passed', function () { - const bidRequest = bidRequests[0]; - bidRequest.params.pubid = ''; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when no placement params are passed', function () { - const bidRequest = bidRequests[0]; - bidRequest.params.placement = ''; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when a bid request is not passed', function () { - expect(spec.isBidRequestValid()).to.equal(false); - expect(spec.isBidRequestValid({})).to.equal(false); - }); - }); - - describe('spec.buildRequests', function () { - it('should create a POST request for each bid', function () { - const bidRequest = bidRequests[0]; - const requests = spec.buildRequests([ bidRequest ]); - expect(requests[0].method).to.equal('POST'); - }); - - it('should create a POST request for each bid in video request', function () { - const bidRequest = bidRequestsVid[0]; - const requests = spec.buildRequests([ bidRequest ]); - expect(requests[0].method).to.equal('POST'); - }); - - it('should have domain in request', function () { - const bidRequest = bidRequests[0]; - const requests = spec.buildRequests([ bidRequest ]); - expect(requests[0].data.site.domain).length !== 0; - }); - }); - - describe('spec.interpretResponse', function () { - describe('for banner bids', function () { - it('should return no bids if the response is not valid', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); - - if (typeof bidResponse !== 'undefined') { - expect(bidResponse.length).to.equal(0); - } else { - expect(true).to.equal(true); - } - }); - - it('should return no bids if the response is empty', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const bidResponse = spec.interpretResponse({ body: [] }, { bidRequest }); - if (typeof bidResponse !== 'undefined') { - expect(bidResponse.length).to.equal(0); - } else { expect(true).to.equal(true); } - }); - - it('should return valid video bid responses', function () { - let _mediaTypes = VIDEO; - const advangelistsbidreqVid = {'bidRequest': {'mediaTypes': {'video': {'w': 320, 'h': 480}}}}; - const serverResponseVid = {'cur': 'USD', 'id': '25c6ab92aa0e81', 'seatbid': [{'seat': '3', 'bid': [{'crid': '1855', 'h': 480, 'protocol': 2, 'nurl': 'http://nep.advangelists.com/xp/evt?pp=1MO1wiaMhhq7wLRzZZwwwPkJxxKpYEnM5k5MH4qSGm1HR8rp3Nl7vDocvzZzSAvE4pnREL9mQ1kf5PDjk6E8em6DOk7vVrYUH1TYQyqCucd58PFpJNN7h30RXKHHFg3XaLuQ3PKfMuI1qZATBJ6WHcu875y0hqRdiewn0J4JsCYF53M27uwmcV0HnQxARQZZ72mPqrW95U6wgkZljziwKrICM3aBV07TU6YK5R5AyzJRuD6mtrQ2xtHlQ3jXVYKE5bvWFiUQd90t0jOGhPtYBNoOfP7uQ4ZZj4pyucxbr96orHe9PSOn9UpCSWArdx7s8lOfDpwOvbMuyGxynbStDWm38sDgd4bMHnIt762m5VMDNJfiUyX0vWzp05OsufJDVEaWhAM62i40lQZo7mWP4ipoOWLkmlaAzFIMsTcNaHAHiKKqGEOZLkCEhFNM0SLcvgN2HFRULOOIZvusq7TydOKxuXgCS91dLUDxDDDFUK83BFKlMkTxnCzkLbIR1bd9GKcr1TRryOrulyvRWAKAIhEsUzsc5QWFUhmI2dZ1eqnBQJ0c89TaPcnoaP2WipF68UgyiOstf2CBy0M34858tC5PmuQwQYwXscg6zyqDwR0i9MzGH4FkTyU5yeOlPcsA0ht6UcoCdFpHpumDrLUwAaxwGk1Nj8S6YlYYT5wNuTifDGbg22QKXzZBkUARiyVvgPn9nRtXnrd7WmiMYq596rya9RQj7LC0auQW8bHVQLEe49shsZDnAwZTWr4QuYKqgRGZcXteG7RVJe0ryBZezOq11ha9C0Lv0siNVBahOXE35Wzoq4c4BDaGpqvhaKN7pjeWLGlQR04ufWekwxiMWAvjmfgAfexBJ7HfbYNZpq__', 'adid': '61_1855', 'adomain': ['chevrolet.com'], 'price': 2, 'w': 320, 'iurl': 'https://daf37cpxaja7f.cloudfront.net/c61/creative_url_14922301369663_1.png', 'cat': ['IAB2'], 'id': '7f570b40-aca1-4806-8ea8-818ea679c82b_0', 'attr': [], 'impid': '0', 'cid': '61'}]}], 'bidid': '7f570b40-aca1-4806-8ea8-818ea679c82b'}; - const bidResponseVid = spec.interpretResponse({ body: serverResponseVid }, advangelistsbidreqVid); - delete bidResponseVid['vastUrl']; - delete bidResponseVid['ad']; - expect(bidResponseVid).to.deep.equal({ - requestId: bidRequestsVid[0].bidId, - bidderCode: 'advangelists', - creativeId: serverResponseVid.seatbid[0].bid[0].crid, - cpm: serverResponseVid.seatbid[0].bid[0].price, - width: serverResponseVid.seatbid[0].bid[0].w, - height: serverResponseVid.seatbid[0].bid[0].h, - mediaType: 'video', - meta: { 'advertiserDomains': serverResponseVid.seatbid[0].bid[0].adomain }, - currency: 'USD', - netRevenue: true, - ttl: 60 - }); - }); - - it('should return valid banner bid responses', function () { - const advangelistsbidreq = {bids: {}}; - bidRequests.forEach(bid => { - let _mediaTypes = (bid.mediaTypes && bid.mediaTypes.video ? VIDEO : BANNER); - advangelistsbidreq.bids[bid.bidId] = {mediaTypes: _mediaTypes, - w: _mediaTypes == BANNER ? bid.mediaTypes[_mediaTypes].sizes[0][0] : bid.mediaTypes[_mediaTypes].playerSize[0], - h: _mediaTypes == BANNER ? bid.mediaTypes[_mediaTypes].sizes[0][1] : bid.mediaTypes[_mediaTypes].playerSize[1] - - }; - }); - const serverResponse = {'id': '2aa73f571eaf29', 'seatbid': [{'bid': [{'id': '2c5e8a1a84522d', 'impid': '2c5e8a1a84522d', 'price': 0.81, 'adid': 'abcde-12345', 'nurl': '', 'adm': '
', 'iurl': '', 'cid': 'campaign1', 'crid': 'abcde-12345', 'adomain': ['chevrolet.com'], 'w': 300, 'h': 250}], 'seat': '19513bcfca8006'}], 'bidid': '19513bcfca8006', 'cur': 'USD', 'w': 300, 'h': 250}; - - const bidResponse = spec.interpretResponse({ body: serverResponse }, advangelistsbidreq); - expect(bidResponse).to.deep.equal({ - requestId: bidRequests[0].bidId, - ad: serverResponse.seatbid[0].bid[0].adm, - bidderCode: 'advangelists', - creativeId: serverResponse.seatbid[0].bid[0].crid, - cpm: serverResponse.seatbid[0].bid[0].price, - width: serverResponse.seatbid[0].bid[0].w, - height: serverResponse.seatbid[0].bid[0].h, - mediaType: 'banner', - meta: { 'advertiserDomains': serverResponse.seatbid[0].bid[0].adomain }, - currency: 'USD', - netRevenue: true, - ttl: 60 - }); - }); - }); - }); -}); diff --git a/test/spec/modules/adxcgBidAdapter_spec.js b/test/spec/modules/adxcgBidAdapter_spec.js index 7721295572c..551d50b60e7 100644 --- a/test/spec/modules/adxcgBidAdapter_spec.js +++ b/test/spec/modules/adxcgBidAdapter_spec.js @@ -1,902 +1,653 @@ -// jshint esversion: 6, es3: false, node: true -import {assert} from 'chai'; +import {expect} from 'chai'; import {spec} from 'modules/adxcgBidAdapter.js'; -import {config} from 'src/config.js'; -import {createEidsArray} from 'modules/userId/eids.js'; -const utils = require('src/utils'); - -describe('Adxcg adapter', function () { - let bids = []; - - describe('isBidRequestValid', function () { - let bid = { - 'bidder': 'adxcg', - 'params': { - 'adzoneid': '19910113' +import {deepClone, parseUrl} from 'src/utils.js'; +import * as utils from '../../../src/utils.js'; + +describe('AdxcgAdapter', function () { + let bidBanner = { + bidder: 'adxcg', + params: { + adzoneid: '1' + }, + adUnitCode: 'adunit-code', + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [640, 360], + [1, 1] + ] } - }; - - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); + }, + bidId: '84ab500420319d', + bidderRequestId: '7101db09af0db2', + auctionId: '1d1a030790a475' + }; + + let bidVideo = { + bidder: 'adxcg', + params: { + adzoneid: '20', + video: { + api: [2], + maxduration: 30 + } + }, + mediaTypes: { + video: { + context: 'instream', + playerSize: [[640, 480]], + protocols: [1, 2], + mimes: ['video/mp4'], + } + }, + adUnitCode: 'adunit-code', + bidId: '84ab500420319d', + bidderRequestId: '7101db09af0db2', + auctionId: '1d1a030790a475' + }; + + let bidNative = { + bidder: 'adxcg', + params: { + adzoneid: '2379' + }, + mediaTypes: { + native: { + image: { + sendId: false, + required: true, + sizes: [80, 80] + }, + title: { + required: true, + len: 75 + }, + body: { + required: true, + len: 200 + }, + sponsoredBy: { + required: false, + len: 20 + } + } + }, + adUnitCode: 'adunit-code', + bidId: '84ab500420319d', + bidderRequestId: '7101db09af0db2', + auctionId: '1d1a030790a475' + }; - bid.params = { - adzoneid: 4332, - }; - assert(spec.isBidRequestValid(bid)); + describe('isBidRequestValid', function () { + it('should return true when required params found bidNative', function () { + expect(spec.isBidRequestValid(bidNative)).to.equal(true); }); - it('should return false when required params are missing', function () { - bid.params = {}; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - mname: 'some-placement' - }; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - inv: 1234 - }; - assert.isFalse(spec.isBidRequestValid(bid)); + it('should return true when required params found bidVideo', function () { + expect(spec.isBidRequestValid(bidVideo)).to.equal(true); }); - }); - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); + it('should return true when required params found bidBanner', function () { + expect(spec.isBidRequestValid(bidBanner)).to.equal(true); }); - it('should send request with correct structure', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: { - adzoneid: '19910113' - } - }]; - let request = spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}); - assert.equal(request.method, 'POST'); - assert.equal(request.url, 'https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'); - assert.deepEqual(request.options, {contentType: 'application/json'}); - assert.ok(request.data); + it('should return false when required params not found', function () { + expect(spec.isBidRequestValid({})).to.be.false; }); - describe('user privacy', function () { - it('should send GDPR Consent data to exchange if gdprApplies', function () { - let validBidRequests = [{bidId: 'bidId', params: {test: 1}}]; - let bidderRequest = { - gdprConsent: {gdprApplies: true, consentString: 'consentDataString'}, - refererInfo: {referer: 'page'} - }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.user.ext.consent, bidderRequest.gdprConsent.consentString); - assert.equal(request.regs.ext.gdpr, bidderRequest.gdprConsent.gdprApplies); - assert.equal(typeof request.regs.ext.gdpr, 'number'); - }); - - it('should send gdpr as number', function () { - let validBidRequests = [{bidId: 'bidId', params: {test: 1}}]; - let bidderRequest = { - gdprConsent: {gdprApplies: true, consentString: 'consentDataString'}, - refererInfo: {referer: 'page'} - }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(typeof request.regs.ext.gdpr, 'number'); - assert.equal(request.regs.ext.gdpr, 1); - }); - - it('should send CCPA Consent data to exchange', function () { - let validBidRequests = [{bidId: 'bidId', params: {test: 1}}]; - let bidderRequest = {uspConsent: '1YA-', refererInfo: {referer: 'page'}}; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.regs.ext.us_privacy, '1YA-'); - - bidderRequest = { - uspConsent: '1YA-', - gdprConsent: {gdprApplies: true, consentString: 'consentDataString'}, - refererInfo: {referer: 'page'} - }; - request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.regs.ext.us_privacy, '1YA-'); - assert.equal(request.user.ext.consent, 'consentDataString'); - assert.equal(request.regs.ext.gdpr, 1); - }); - - it('should not send GDPR Consent data to adxcg if gdprApplies is undefined', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {siteId: 'siteId'} - }]; - let bidderRequest = { - gdprConsent: {gdprApplies: false, consentString: 'consentDataString'}, - refererInfo: {referer: 'page'} - }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.user.ext.consent, 'consentDataString'); - assert.equal(request.regs.ext.gdpr, 0); - - bidderRequest = {gdprConsent: {consentString: 'consentDataString'}, refererInfo: {referer: 'page'}}; - request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.user, undefined); - assert.equal(request.regs, undefined); - }); - it('should send default GDPR Consent data to exchange', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {siteId: 'siteId'} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.equal(request.user, undefined); - assert.equal(request.regs, undefined); - }); + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bidBanner); + delete bid.params; + bid.params = {}; + expect(spec.isBidRequestValid(bid)).to.equal(false); }); - it('should add test and is_debug to request, if test is set in parameters', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {test: 1} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.ok(request.is_debug); - assert.equal(request.test, 1); + it('should return true when required video params not found', function () { + const simpleVideo = JSON.parse(JSON.stringify(bidVideo)); + simpleVideo.params.adzoneid = 123; + expect(spec.isBidRequestValid(simpleVideo)).to.be.false; }); + }); - it('should have default request structure', function () { - let keys = 'site,geo,device,source,ext,imp'.split(','); - let validBidRequests = [{ - bidId: 'bidId', - params: {siteId: 'siteId'} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - let data = Object.keys(request); - - assert.deepEqual(keys, data); + describe('request function http', function () { + it('creates a valid adxcg request url bidBanner', function () { + let request = spec.buildRequests([bidBanner]); + expect(request).to.exist; + expect(request.method).to.equal('GET'); + let parsedRequestUrl = parseUrl(request.url); + expect(parsedRequestUrl.hostname).to.equal('hbps.adxcg.net'); + expect(parsedRequestUrl.pathname).to.equal('/get/adi'); + + let query = parsedRequestUrl.search; + expect(query.renderformat).to.equal('javascript'); + expect(query.ver).to.equal('r20210330PB40'); + expect(query.source).to.equal('pbjs10'); + expect(query.pbjs).to.equal('$prebid.version$'); + expect(query.adzoneid).to.equal('1'); + expect(query.format).to.equal('300x250|640x360|1x1'); + expect(query.jsonp).to.be.undefined; + expect(query.prebidBidIds).to.equal('84ab500420319d'); + expect(query.bidfloors).to.equal('0'); + + expect(query).to.have.property('secure'); + expect(query).to.have.property('uw'); + expect(query).to.have.property('uh'); + expect(query).to.have.property('dpr'); + expect(query).to.have.property('bt'); + expect(query).to.have.property('cookies'); + expect(query).to.have.property('tz'); + expect(query).to.have.property('dt'); + expect(query).to.have.property('iob'); + expect(query).to.have.property('rndid'); + expect(query).to.have.property('ref'); + expect(query).to.have.property('url'); }); - it('should set request keys correct values', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {siteId: 'siteId'}, - transactionId: 'transactionId' - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.equal(request.source.tid, validBidRequests[0].transactionId); - assert.equal(request.source.fd, 1); + it('creates a valid adxcg request url bidVideo', function () { + let request = spec.buildRequests([bidVideo]); + expect(request).to.exist; + expect(request.method).to.equal('GET'); + let parsedRequestUrl = parseUrl(request.url); + expect(parsedRequestUrl.hostname).to.equal('hbps.adxcg.net'); + expect(parsedRequestUrl.pathname).to.equal('/get/adi'); + + let query = parsedRequestUrl.search; + // general part + expect(query.renderformat).to.equal('javascript'); + expect(query.ver).to.equal('r20210330PB40'); + expect(query.source).to.equal('pbjs10'); + expect(query.pbjs).to.equal('$prebid.version$'); + expect(query.adzoneid).to.equal('20'); + expect(query.format).to.equal('640x480'); + expect(query.jsonp).to.be.undefined; + expect(query.prebidBidIds).to.equal('84ab500420319d'); + expect(query.bidfloors).to.equal('0'); + + expect(query).to.have.property('secure'); + expect(query).to.have.property('uw'); + expect(query).to.have.property('uh'); + expect(query).to.have.property('dpr'); + expect(query).to.have.property('bt'); + expect(query).to.have.property('cookies'); + expect(query).to.have.property('tz'); + expect(query).to.have.property('dt'); + expect(query).to.have.property('iob'); + expect(query).to.have.property('rndid'); + expect(query).to.have.property('ref'); + expect(query).to.have.property('url'); + + // video specific part + expect(query['video.maxduration.0']).to.equal('30'); + expect(query['video.mimes.0']).to.equal('video/mp4'); + expect(query['video.context.0']).to.equal('instream'); }); - it('should send info about device', function () { - config.setConfig({ - device: {w: 100, h: 100} - }); - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: '1000'} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.equal(request.device.ua, navigator.userAgent); - assert.equal(request.device.w, 100); - assert.equal(request.device.h, 100); + it('creates a valid adxcg request url bidNative', function () { + let request = spec.buildRequests([bidNative]); + expect(request).to.exist; + expect(request.method).to.equal('GET'); + let parsedRequestUrl = parseUrl(request.url); + expect(parsedRequestUrl.hostname).to.equal('hbps.adxcg.net'); + expect(parsedRequestUrl.pathname).to.equal('/get/adi'); + + let query = parsedRequestUrl.search; + expect(query.renderformat).to.equal('javascript'); + expect(query.ver).to.equal('r20210330PB40'); + expect(query.source).to.equal('pbjs10'); + expect(query.pbjs).to.equal('$prebid.version$'); + expect(query.adzoneid).to.equal('2379'); + expect(query.format).to.equal('0x0'); + expect(query.jsonp).to.be.undefined; + expect(query.prebidBidIds).to.equal('84ab500420319d'); + expect(query.bidfloors).to.equal('0'); + + expect(query).to.have.property('secure'); + expect(query).to.have.property('uw'); + expect(query).to.have.property('uh'); + expect(query).to.have.property('dpr'); + expect(query).to.have.property('bt'); + expect(query).to.have.property('cookies'); + expect(query).to.have.property('tz'); + expect(query).to.have.property('dt'); + expect(query).to.have.property('iob'); + expect(query).to.have.property('rndid'); + expect(query).to.have.property('ref'); + expect(query).to.have.property('url'); }); + }); - it('should send app info', function () { - config.setConfig({ - app: {id: 'appid'}, - ortb2: {app: {name: 'appname'}} + describe('gdpr compliance', function () { + it('should send GDPR Consent data if gdprApplies', function () { + let request = spec.buildRequests([bidBanner], { + gdprConsent: { + gdprApplies: true, + consentString: 'consentDataString' + } }); - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: '1000'} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.equal(request.app.id, 'appid'); - assert.equal(request.app.name, 'appname'); - assert.equal(request.site, undefined); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; + + expect(query.gdpr).to.equal('1'); + expect(query.gdpr_consent).to.equal('consentDataString'); }); - it('should send info about the site', function () { - config.setConfig({ - site: { - id: '123123', - publisher: { - domain: 'publisher.domain.com' - } - }, - ortb2: { - site: { - publisher: { - id: 4441, - name: 'publisher\'s name' - } - } + it('should not send GDPR Consent data if gdprApplies is false or undefined', function () { + let request = spec.buildRequests([bidBanner], { + gdprConsent: { + gdprApplies: false, + consentString: 'consentDataString' } }); - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: '1000'} - }]; - let refererInfo = {referer: 'page'}; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo}).data); - - assert.deepEqual(request.site, { - domain: 'localhost', - id: '123123', - page: refererInfo.referer, - publisher: { - domain: 'publisher.domain.com', - id: 4441, - name: 'publisher\'s name' - } - }); - }); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; - it('should pass extended ids', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {}, - userIdAsEids: createEidsArray({ - tdid: 'TTD_ID_FROM_USER_ID_MODULE', - pubcid: 'pubCommonId_FROM_USER_ID_MODULE' - }) - }]; - - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - assert.deepEqual(request.user.ext.eids, [ - {source: 'adserver.org', uids: [{id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: {rtiPartner: 'TDID'}}]}, - {source: 'pubcid.org', uids: [{id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1}]} - ]); + expect(query.gdpr).to.be.undefined; + expect(query.gdpr_consent).to.be.undefined; }); + }); - it('should send currency if defined', function () { - config.setConfig({currency: {adServerCurrency: 'EUR'}}); - let validBidRequests = [{params: {}}]; - let refererInfo = {referer: 'page'}; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo}).data); + describe('userid pubcid should be passed to querystring', function () { + let bidderRequests = {}; + let bid = deepClone([bidBanner]); + bid[0].userId = {pubcid: 'pubcidabcd'}; - assert.deepEqual(request.cur, ['EUR']); + it('should send pubcid if available', function () { + let request = spec.buildRequests(bid, bidderRequests); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; + expect(query.pubcid).to.equal('pubcidabcd'); }); + }); - it('should pass supply chain object', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {}, - schain: { - validation: 'strict', - config: { - ver: '1.0' - } - } - }]; + describe('userid tdid should be passed to querystring', function () { + let bid = deepClone([bidBanner]); + let bidderRequests = {}; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - assert.deepEqual(request.source.ext.schain, { - validation: 'strict', - config: { - ver: '1.0' - } - }); + bid[0].userId = {tdid: 'tdidabcd'}; + + it('should send pubcid if available', function () { + let request = spec.buildRequests(bid, bidderRequests); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; + expect(query.tdid).to.equal('tdidabcd'); }); + }); - describe('bids', function () { - it('should add more than one bid to the request', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {siteId: 'siteId'} - }, { - bidId: 'bidId2', - params: {siteId: 'siteId'} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data); - - assert.equal(request.imp.length, 2); - }); - it('should add incrementing values of id', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: '1000'}, - mediaTypes: {video: {}} - }, { - bidId: 'bidId2', - params: {adzoneid: '1000'}, - mediaTypes: {video: {}} - }, { - bidId: 'bidId3', - params: {adzoneid: '1000'}, - mediaTypes: {video: {}} - }]; - let imps = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp; - - for (let i = 0; i < 3; i++) { - assert.equal(imps[i].id, i + 1); - } - }); + describe('userid id5id should be passed to querystring', function () { + let bid = deepClone([bidBanner]); + let bidderRequests = {}; - it('should add adzoneid', function () { - let validBidRequests = [{bidId: 'bidId', params: {adzoneid: 1000}, mediaTypes: {video: {}}}, - {bidId: 'bidId2', params: {adzoneid: 1001}, mediaTypes: {video: {}}}, - {bidId: 'bidId3', params: {adzoneid: 1002}, mediaTypes: {video: {}}}]; - let imps = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp; - for (let i = 0; i < 3; i++) { - assert.equal(imps[i].tagid, validBidRequests[i].params.adzoneid); - } - }); + bid[0].userId = {id5id: {uid: 'id5idsample'}}; - describe('price floors', function () { - it('should not add if floors module not configured', function () { - const validBidRequests = [{bidId: 'bidId', params: {adzoneid: 1000}, mediaTypes: {video: {}}}]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, undefined); - }); - - it('should not add if floor price not defined', function () { - const validBidRequests = [getBidWithFloor()]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'USD'); - }); - - it('should request floor price in adserver currency', function () { - config.setConfig({currency: {adServerCurrency: 'DKK'}}); - const validBidRequests = [getBidWithFloor()]; - let imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'DKK'); - }); - - it('should add correct floor values', function () { - const expectedFloors = [1, 1.3, 0.5]; - const validBidRequests = expectedFloors.map(getBidWithFloor); - let imps = getRequestImps(validBidRequests); - - expectedFloors.forEach((floor, index) => { - assert.equal(imps[index].bidfloor, floor); - assert.equal(imps[index].bidfloorcur, 'USD'); - }); - }); - - function getBidWithFloor(floor) { - return { - params: {adzoneid: 1}, - mediaTypes: {video: {}}, - getFloor: ({currency}) => { - return { - currency: currency, - floor - }; - } - }; - } - }); + it('should send pubcid if available', function () { + let request = spec.buildRequests(bid, bidderRequests); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; + expect(query.id5id).to.equal('id5idsample'); + }); + }); - describe('multiple media types', function () { - it('should use all configured media types for bidding', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - }, - video: {} - } - }, { - bidId: 'bidId1', - params: {adzoneid: 1000}, - mediaTypes: { - video: {}, - native: {} - } - }, { - bidId: 'bidId2', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140} - }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - }, - native: {}, - video: {} - } - }]; - let [first, second, third] = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp; + describe('userid idl_env should be passed to querystring', function () { + let bid = deepClone([bidBanner]); + let bidderRequests = {}; - assert.ok(first.banner); - assert.ok(first.video); - assert.equal(first.native, undefined); + bid[0].userId = {idl_env: 'idl_envsample'}; - assert.ok(second.video); - assert.equal(second.banner, undefined); - assert.equal(second.native, undefined); + it('should send pubcid if available', function () { + let request = spec.buildRequests(bid, bidderRequests); + let parsedRequestUrl = parseUrl(request.url); + let query = parsedRequestUrl.search; + expect(query.idl_env).to.equal('idl_envsample'); + }); + }); - assert.ok(third.native); - assert.ok(third.video); - assert.ok(third.banner); - }); - }); + describe('response handler', function () { + let BIDDER_REQUEST = { + bidder: 'adxcg', + params: { + adzoneid: '1' + }, + adUnitCode: 'adunit-code', + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [640, 360], + [1, 1] + ] + } + }, + bidId: '84ab500420319d', + bidderRequestId: '7101db09af0db2', + auctionId: '1d1a030790a475' + }; - describe('banner', function () { - it('should convert sizes to openrtb format', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] + let BANNER_RESPONSE = { + body: { + id: 'auctionid', + bidid: '84ab500420319d', + seatbid: [{ + bid: [ + { + impid: '84ab500420319d', + price: 0.45, + crid: '42', + adm: '', + w: 300, + h: 250, + adomain: ['adomain.com'], + cat: ['IAB1-4', 'IAB8-16', 'IAB25-5'], + ext: { + crType: 'banner', + advertiser_id: '777', + advertiser_name: 'advertiser', + agency_name: 'agency' } } - }]; - let {banner} = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0]; - assert.deepEqual(banner, { - format: [{w: 100, h: 100}, {w: 200, h: 300}] - }); - }); - }); + ] + }], + cur: 'USD' + }, + headers: {someheader: 'fakedata'} + }; - describe('video', function () { - it('should pass video mediatype config', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] + let BANNER_RESPONSE_WITHDEALID = { + body: { + id: 'auctionid', + bidid: '84ab500420319d', + seatbid: [{ + bid: [ + { + impid: '84ab500420319d', + price: 0.45, + crid: '42', + dealid: '7722', + adm: '', + w: 300, + h: 250, + adomain: ['adomain.com'], + ext: { + crType: 'banner' } } - }]; - let {video} = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0]; - assert.deepEqual(video, { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] - }); - }); - }); + ] + }], + cur: 'USD' + } + }; - describe('native', function () { - describe('assets', function () { - it('should set correct asset id', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif']}, - body: {len: 140} - } - }]; - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - - assert.equal(assets[0].id, 0); - assert.equal(assets[1].id, 3); - assert.equal(assets[2].id, 4); - }); - it('should add required key if it is necessary', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif']}, - body: {len: 140}, - sponsoredBy: {required: true, len: 140} - } - }]; - - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - - assert.equal(assets[0].required, 1); - assert.ok(!assets[1].required); - assert.ok(!assets[2].required); - assert.equal(assets[3].required, 1); - }); - - it('should map img and data assets', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: true, sizes: [150, 50]}, - icon: {required: false, sizes: [50, 50]}, - body: {required: false, len: 140}, - sponsoredBy: {required: true}, - cta: {required: false}, - clickUrl: {required: false} - } - }]; - - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - assert.ok(assets[0].title); - assert.equal(assets[0].title.len, 140); - assert.deepEqual(assets[1].img, {type: 3, w: 150, h: 50}); - assert.deepEqual(assets[2].img, {type: 1, w: 50, h: 50}); - assert.deepEqual(assets[3].data, {type: 2, len: 140}); - assert.deepEqual(assets[4].data, {type: 1}); - assert.deepEqual(assets[5].data, {type: 12}); - assert.ok(!assets[6]); - }); - - describe('icon/image sizing', function () { - it('should flatten sizes and utilise first pair', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - image: { - sizes: [[200, 300], [100, 200]] - }, - } - }]; - - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - assert.ok(assets[0].img); - assert.equal(assets[0].img.w, 200); - assert.equal(assets[0].img.h, 300); - }); - }); - - it('should utilise aspect_ratios', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - image: { - aspect_ratios: [{ - min_width: 100, - ratio_height: 3, - ratio_width: 1 - }] - }, - icon: { - aspect_ratios: [{ - min_width: 10, - ratio_height: 5, - ratio_width: 2 - }] - } - } - }]; - - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - assert.ok(assets[0].img); - assert.equal(assets[0].img.wmin, 100); - assert.equal(assets[0].img.hmin, 300); - - assert.ok(assets[1].img); - assert.equal(assets[1].img.wmin, 10); - assert.equal(assets[1].img.hmin, 25); - }); - - it('should not throw error if aspect_ratios config is not defined', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - image: { - aspect_ratios: [] - }, - icon: { - aspect_ratios: [] - } - } - }]; - - assert.doesNotThrow(() => spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}})); - }); - }); - - it('should expect any dimensions if min_width not passed', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {adzoneid: 1000}, - nativeParams: { - image: { - aspect_ratios: [{ - ratio_height: 3, - ratio_width: 1 - }] + let VIDEO_RESPONSE = { + body: { + id: 'auctionid', + bidid: '84ab500420319d', + seatbid: [{ + bid: [ + { + impid: '84ab500420319d', + price: 0.45, + crid: '42', + nurl: 'vastContentUrl', + adomain: ['adomain.com'], + w: 640, + h: 360, + ext: { + crType: 'video' } } - }]; - - let nativeRequest = JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp[0].native.request; - let assets = JSON.parse(nativeRequest).assets; - assert.ok(assets[0].img); - assert.equal(assets[0].img.wmin, 0); - assert.equal(assets[0].img.hmin, 0); - assert.ok(!assets[1]); - }); - }); - }); + ] + }], + cur: 'USD' + }, + headers: {someheader: 'fakedata'} + }; - function getRequestImps(validBidRequests) { - return JSON.parse(spec.buildRequests(validBidRequests, {refererInfo: {referer: 'page'}}).data).imp; + let NATIVE_RESPONSEob = { + assets: [ + { + id: 1, + required: 0, + title: { + text: 'titleContent' + } + }, + { + id: 2, + required: 0, + img: { + url: 'imageContent', + w: 600, + h: 600 + } + }, + { + id: 3, + required: 0, + data: { + label: 'DESC', + value: 'descriptionContent' + } + }, + { + id: 0, + required: 0, + data: { + label: 'SPONSORED', + value: 'sponsoredByContent' + } + }, + { + id: 5, + required: 0, + icon: { + url: 'iconContent', + w: 400, + h: 400 + } + } + ], + link: { + url: 'linkContent' + }, + imptrackers: ['impressionTracker1', 'impressionTracker2'] } - }); - - describe('interpretResponse', function () { - it('should return if no body in response', function () { - let serverResponse = {}; - let bidRequest = {}; - assert.ok(!spec.interpretResponse(serverResponse, bidRequest)); - }); - it('should return more than one bids', function () { - let serverResponse = { - body: { - seatbid: [{ - bid: [{ - impid: '1', - native: {ver: '1.1', link: {url: 'link'}, assets: [{id: 1, title: {text: 'Asset title text'}}]} - }] - }, { - bid: [{ - impid: '2', - native: {ver: '1.1', link: {url: 'link'}, assets: [{id: 1, data: {value: 'Asset title text'}}]} - }] - }] - } - }; - let bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif']}, - body: {len: 140} - } - }, - { - bidId: 'bidId2', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif']}, - body: {len: 140} + let NATIVE_RESPONSE = { + body: { + id: 'auctionid', + bidid: '84ab500420319d', + seatbid: [{ + bid: [ + { + impid: '84ab500420319d', + price: 0.45, + crid: '42', + w: 0, + h: 0, + adm: JSON.stringify(NATIVE_RESPONSEob), + adomain: ['adomain.com'], + ext: { + crType: 'native' + } } - } - ] - }; + ] + }], + cur: 'USD' + }, + headers: {someheader: 'fakedata'} + }; - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(spec.interpretResponse(serverResponse, bidRequest).length, 2); + it('handles regular responses', function () { + expect(BANNER_RESPONSE).to.exist; + expect(BANNER_RESPONSE.body).to.exist; + expect(BANNER_RESPONSE.body.id).to.exist; + expect(BANNER_RESPONSE.body.seatbid[0]).to.exist; + let result = spec.interpretResponse(BANNER_RESPONSE, BIDDER_REQUEST); + + expect(result).to.have.lengthOf(1); + + expect(result[0]).to.exist; + expect(result[0].width).to.equal(300); + expect(result[0].height).to.equal(250); + expect(result[0].creativeId).to.equal(42); + expect(result[0].cpm).to.be.within(0.45, 0.46); + expect(result[0].ad).to.equal(''); + expect(result[0].currency).to.equal('USD'); + expect(result[0].netRevenue).to.equal(true); + expect(result[0].ttl).to.equal(300); + expect(result[0].dealId).to.not.exist; + expect(result[0].meta.advertiserDomains[0]).to.equal('adomain.com'); + expect(result[0].meta.advertiserId).to.be.eql('777'); + expect(result[0].meta.advertiserName).to.be.eql('advertiser'); + expect(result[0].meta.agencyName).to.be.eql('agency'); + expect(result[0].meta.advertiserDomains).to.be.eql(['adomain.com']); + expect(result[0].meta.secondaryCatIds).to.be.eql(['IAB1-4', 'IAB8-16', 'IAB25-5']); }); - it('should set correct values to bid', function () { - let nativeExample1 = { - assets: [], - link: {url: 'link'}, - imptrackers: ['imptrackers url1', 'imptrackers url2'] - } + it('handles regular responses with dealid', function () { + let result = spec.interpretResponse(BANNER_RESPONSE_WITHDEALID); - let serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{ - bid: [ - { - impid: '1', - price: 93.1231, - crid: '12312312', - adm: JSON.stringify(nativeExample1), - dealid: 'deal-id', - adomain: ['demo.com'], - ext: { - crType: 'native', - advertiser_id: 'adv1', - advertiser_name: 'advname', - agency_name: 'agname', - mediaType: 'native' - } - } - ] - }], - cur: 'EUR' - } - }; - let bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: {adzoneid: 1000}, - nativeParams: { - title: {required: true, len: 140}, - image: {required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif']}, - body: {len: 140} - } - } - ] - }; + expect(result).to.have.lengthOf(1); - const bids = spec.interpretResponse(serverResponse, bidRequest); - const bid = serverResponse.body.seatbid[0].bid[0]; - assert.deepEqual(bids[0].requestId, bidRequest.bids[0].bidId); - assert.deepEqual(bids[0].cpm, bid.price); - assert.deepEqual(bids[0].creativeId, bid.crid); - assert.deepEqual(bids[0].ttl, 300); - assert.deepEqual(bids[0].netRevenue, false); - assert.deepEqual(bids[0].currency, serverResponse.body.cur); - assert.deepEqual(bids[0].mediaType, 'native'); - assert.deepEqual(bids[0].meta.mediaType, 'native'); - assert.deepEqual(bids[0].meta.advertiserDomains, ['demo.com']); - - assert.deepEqual(bids[0].meta.advertiserName, 'advname'); - assert.deepEqual(bids[0].meta.agencyName, 'agname'); - - assert.deepEqual(bids[0].dealId, 'deal-id'); + expect(result[0].width).to.equal(300); + expect(result[0].height).to.equal(250); + expect(result[0].creativeId).to.equal(42); + // expect(result[0].cpm).to.equal(0.45); + expect(result[0].cpm).to.be.within(0.45, 0.46); + expect(result[0].ad).to.equal(''); + expect(result[0].currency).to.equal('USD'); + expect(result[0].netRevenue).to.equal(true); + expect(result[0].ttl).to.equal(300); }); - it('should return empty when there is no bids in response', function () { - const serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{bid: []}], - cur: 'EUR' - } - }; - let bidRequest = { - data: {}, - bids: [{bidId: 'bidId1'}] - }; - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.ok(!result); + it('handles video responses', function () { + let result = spec.interpretResponse(VIDEO_RESPONSE); + expect(result).to.have.lengthOf(1); + + expect(result[0].width).to.equal(640); + expect(result[0].height).to.equal(360); + expect(result[0].mediaType).to.equal('video'); + expect(result[0].creativeId).to.equal(42); + expect(result[0].cpm).to.equal(0.45); + expect(result[0].vastUrl).to.equal('vastContentUrl'); + expect(result[0].currency).to.equal('USD'); + expect(result[0].netRevenue).to.equal(true); + expect(result[0].ttl).to.equal(300); }); - describe('banner', function () { - it('should set ad content on response', function () { - let serverResponse = { - body: { - seatbid: [{ - bid: [{impid: '1', adm: '', ext: {crType: 'banner'}}] - }] - } - }; - let bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: {adzoneid: 1000} - } - ] - }; + it('handles native responses', function () { + let result = spec.interpretResponse(NATIVE_RESPONSE); - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(bids.length, 1); - assert.equal(bids[0].ad, ''); - assert.equal(bids[0].mediaType, 'banner'); - assert.equal(bids[0].meta.mediaType, 'banner'); - }); + expect(result[0].width).to.equal(0); + expect(result[0].height).to.equal(0); + + expect(result[0].creativeId).to.equal(42); + expect(result[0].cpm).to.equal(0.45); + expect(result[0].currency).to.equal('USD'); + expect(result[0].netRevenue).to.equal(true); + expect(result[0].ttl).to.equal(300); + + expect(result[0].mediaType).to.equal('native'); + + expect(result[0].native.clickUrl).to.equal('linkContent'); + expect(result[0].native.impressionTrackers).to.deep.equal([ + 'impressionTracker1', + 'impressionTracker2' + ]); + expect(result[0].native.title).to.equal('titleContent'); + + expect(result[0].native.image.url).to.equal('imageContent'); + expect(result[0].native.image.height).to.equal(600); + expect(result[0].native.image.width).to.equal(600); + + expect(result[0].native.icon.url).to.equal('iconContent'); + expect(result[0].native.icon.height).to.equal(400); + expect(result[0].native.icon.width).to.equal(400); + + expect(result[0].native.body).to.equal('descriptionContent'); + expect(result[0].native.sponsoredBy).to.equal('sponsoredByContent'); }); - describe('video', function () { - it('should set vastXml on response', function () { - let serverResponse = { - body: { - seatbid: [{ - bid: [{impid: '1', adm: '', ext: {crType: 'video'}}] - }] - } - }; - let bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: {adzoneid: 1000} - } - ] - }; + it('handles nobid responses', function () { + let response = []; + let bidderRequest = BIDDER_REQUEST; - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(bids.length, 1); - assert.equal(bids[0].vastXml, ''); - assert.equal(bids[0].mediaType, 'video'); - assert.equal(bids[0].meta.mediaType, 'video'); - }); + let result = spec.interpretResponse(response, bidderRequest); + expect(result.length).to.equal(0); }); }); describe('getUserSyncs', function () { - const usersyncUrl = 'https://usersync-url.com'; - beforeEach(() => { - config.setConfig( - { - adxcg: { - usersyncUrl: usersyncUrl, - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should return user sync if pixel enabled with adxcg config', function () { - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.deep.equal([{type: 'image', url: usersyncUrl}]) - }) - - it('should not return user sync if pixel disabled', function () { - const ret = spec.getUserSyncs({pixelEnabled: false}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if url is not set', function () { - config.resetConfig() - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should pass GDPR consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=0&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=` - }]); - }); - - it('should pass US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?us_privacy=1NYN` - }]); - }); + let syncoptionsIframe = { + iframeEnabled: 'true' + }; - it('should pass GDPR and US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN` - }]); + it('should return iframe sync option', function () { + expect(spec.getUserSyncs(syncoptionsIframe)[0].type).to.equal('iframe'); + expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.equal( + 'https://cdn.adxcg.net/pb-sync.html' + ); }); }); - describe('onBidWon', function() { - beforeEach(function() { + describe('on bidWon', function () { + beforeEach(function () { sinon.stub(utils, 'triggerPixel'); }); - afterEach(function() { + afterEach(function () { utils.triggerPixel.restore(); }); - - it('Should trigger pixel if bid nurl', function() { + it('should replace burl for banner', function () { + const burl = 'burl=${' + 'AUCTION_PRICE}'; const bid = { - nurl: 'http://example.com/win/${AUCTION_PRICE}', - cpm: 2.1, - originalCpm: 1.1, - } + 'bidderCode': 'adxcg', + 'width': 0, + 'height': 0, + 'statusMessage': 'Bid available', + 'adId': '3d0b6ff1dda89', + 'requestId': '2a423489e058a1', + 'mediaType': 'banner', + 'source': 'client', + 'ad': burl, + 'cpm': 0.66, + 'creativeId': '353538_591471', + 'currency': 'USD', + 'dealId': '', + 'netRevenue': true, + 'ttl': 300, + // 'nurl': nurl, + 'burl': burl, + 'isBurl': true, + 'auctionId': 'a92bffce-14d2-4f8f-a78a-7b9b5e4d28fa', + 'responseTimestamp': 1556867386065, + 'requestTimestamp': 1556867385916, + 'bidder': 'adxcg', + 'adUnitCode': 'div-gpt-ad-1555415275793-0', + 'timeToRespond': 149, + 'pbLg': '0.50', + 'pbMg': '0.60', + 'pbHg': '0.66', + 'pbAg': '0.65', + 'pbDg': '0.66', + 'pbCg': '', + 'size': '0x0', + 'adserverTargeting': { + 'hb_bidder': 'mgid', + 'hb_adid': '3d0b6ff1dda89', + 'hb_pb': '0.66', + 'hb_size': '0x0', + 'hb_source': 'client', + 'hb_format': 'banner', + 'hb_banner_title': 'TITLE', + 'hb_banner_image': 'hb_banner_image:3d0b6ff1dda89', + 'hb_banner_icon': 'IconURL', + 'hb_banner_linkurl': 'hb_banner_linkurl:3d0b6ff1dda89' + }, + 'status': 'targetingSet', + 'params': [{'adzoneid': '20'}] + }; spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) + expect(bid.burl).to.deep.equal(burl); + }); + }); }); diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js index 4a13fbf1232..befc95e5f24 100644 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ b/test/spec/modules/adyoulikeBidAdapter_spec.js @@ -95,40 +95,6 @@ describe('Adyoulike Adapter', function () { } ]; - const bidRequestWithMultipleMediatype = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': { - 'banner': { - 'sizes': ['640x480'] - }, - 'video': { - 'playerSize': [640, 480], - 'context': 'outstream' - }, - 'native': { - 'image': { - 'required': true, - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'cta': { - 'required': false - }, - } - }, - 'transactionId': 'bid_id_0_transaction_id' - } - ]; - const bidRequestWithNativeImageType = [ { 'bidId': 'bid_id_0', @@ -624,32 +590,6 @@ describe('Adyoulike Adapter', function () { expect(payload.gdprConsent.consentRequired).to.be.null; }); - it('should add userid eids information to the request', function () { - let bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'userId': { - pubcid: '01EAJWWNEPN3CYMM5N8M5VXY22', - unsuported: '666' - } - }; - - bidderRequest.bids = bidRequestWithSinglePlacement; - - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.userId).to.exist; - expect(payload.userId).to.deep.equal([{ - 'source': 'pubcid.org', - 'uids': [{ - 'atype': 1, - 'id': '01EAJWWNEPN3CYMM5N8M5VXY22' - }] - }]); - }); - it('sends bid request to endpoint with single placement', function () { const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); const payload = JSON.parse(request.data); @@ -681,21 +621,6 @@ describe('Adyoulike Adapter', function () { expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); }); - it('sends bid request to endpoint with single placement multiple mediatype', function () { - canonicalQuery.restore(); - const request = spec.buildRequests(bidRequestWithMultipleMediatype, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - - expect(request.url).to.not.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(payload.Version).to.equal('1.0'); - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - }); - it('sends bid request to endpoint with multiple placements', function () { const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest); const payload = JSON.parse(request.data); diff --git a/test/spec/modules/afpBidAdapter_spec.js b/test/spec/modules/afpBidAdapter_spec.js deleted file mode 100644 index 8e77a1f3e15..00000000000 --- a/test/spec/modules/afpBidAdapter_spec.js +++ /dev/null @@ -1,306 +0,0 @@ -import includes from 'core-js-pure/features/array/includes.js' -import cloneDeep from 'lodash/cloneDeep' -import unset from 'lodash/unset' -import { expect } from 'chai' -import { BANNER, VIDEO } from '../../../src/mediaTypes.js' -import { - spec, - IN_IMAGE_BANNER_TYPE, - IN_IMAGE_MAX_BANNER_TYPE, - IN_CONTENT_BANNER_TYPE, - IN_CONTENT_VIDEO_TYPE, - OUT_CONTENT_VIDEO_TYPE, - IN_CONTENT_STORY_TYPE, - ACTION_SCROLLER_TYPE, - ACTION_SCROLLER_LIGHT_TYPE, - JUST_BANNER_TYPE, - BIDDER_CODE, - SSP_ENDPOINT, - REQUEST_METHOD, - TEST_PAGE_URL, - IS_DEV, mediaTypeByPlaceType -} from 'modules/afpBidAdapter.js' - -const placeId = '613221112871613d1517d181' -const bidId = '2a67c5577ff6a5' -const transactionId = '7e8515a2-2ed9-4733-b976-6c2596a03287' -const imageUrl = 'https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png' -const placeContainer = '#container' -const imageWidth = 600 -const imageHeight = 400 -const pageUrl = IS_DEV ? TEST_PAGE_URL : 'referer' -const sizes = [[imageWidth, imageHeight]] -const bidderRequest = { - refererInfo: { referer: pageUrl }, -} -const mediaTypeBanner = { [BANNER]: {sizes: [[imageWidth, imageHeight]]} } -const mediaTypeVideo = { [VIDEO]: {playerSize: [[imageWidth, imageHeight]]} } -const commonParams = { - placeId, - placeContainer, -} -const commonParamsForInImage = Object.assign({}, commonParams, { - imageUrl, - imageWidth, - imageHeight, -}) -const configByPlaceType = { - get [IN_IMAGE_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParamsForInImage, { - placeType: IN_IMAGE_BANNER_TYPE - }), - }) - }, - get [IN_IMAGE_MAX_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParamsForInImage, { - placeType: IN_IMAGE_MAX_BANNER_TYPE - }), - }) - }, - get [IN_CONTENT_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_BANNER_TYPE - }), - }) - }, - get [IN_CONTENT_VIDEO_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeVideo, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_VIDEO_TYPE - }), - }) - }, - get [OUT_CONTENT_VIDEO_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeVideo, - params: Object.assign({}, commonParams, { - placeType: OUT_CONTENT_VIDEO_TYPE - }), - }) - }, - get [IN_CONTENT_STORY_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_STORY_TYPE - }), - }) - }, - get [ACTION_SCROLLER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: ACTION_SCROLLER_TYPE - }), - }) - }, - get [ACTION_SCROLLER_LIGHT_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: ACTION_SCROLLER_LIGHT_TYPE - }), - }) - }, - get [JUST_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: JUST_BANNER_TYPE - }), - }) - }, -} -const getTransformedConfig = ({mediaTypes, params}) => { - return { - params: params, - sizes, - bidId, - bidder: BIDDER_CODE, - mediaTypes: mediaTypes, - transactionId, - } -} -const validBidRequests = Object.keys(configByPlaceType).map(key => getTransformedConfig(configByPlaceType[key])) - -describe('AFP Adapter', function() { - describe('isBidRequestValid method', function() { - describe('returns true', function() { - describe('when config has all mandatory params', () => { - Object.keys(configByPlaceType).forEach(placeType => { - it(`and ${placeType} config has the correct value`, function() { - const isBidRequestValid = spec.isBidRequestValid(configByPlaceType[placeType]) - expect(isBidRequestValid).to.equal(true) - }) - }) - }) - }) - describe('returns false', function() { - const checkMissingParams = (placesTypes, missingParams) => - placesTypes.forEach(placeType => - missingParams.forEach(missingParam => { - const config = configByPlaceType[placeType] - it(`${placeType} does not have the ${missingParam}.`, function() { - unset(config, missingParam) - const isBidRequestValid = spec.isBidRequestValid(config) - expect(isBidRequestValid).to.equal(false) - }) - }) - ) - - describe('when params are not correct', function() { - checkMissingParams(Object.keys(configByPlaceType), ['params.placeId', 'params.placeType']) - checkMissingParams([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], - ['params.imageUrl', 'params.imageWidth', 'params.imageHeight']) - - it('does not have a the correct placeType.', function() { - const config = configByPlaceType[IN_IMAGE_BANNER_TYPE] - config.params.placeType = 'something' - const isBidRequestValid = spec.isBidRequestValid(config) - expect(isBidRequestValid).to.equal(false) - }) - }) - describe('when video mediaType object is not correct.', function() { - checkMissingParams([IN_CONTENT_VIDEO_TYPE, OUT_CONTENT_VIDEO_TYPE], - [`mediaTypes.${VIDEO}.playerSize`, `mediaTypes.${VIDEO}`]) - checkMissingParams([ - IN_IMAGE_BANNER_TYPE, - IN_IMAGE_MAX_BANNER_TYPE, - IN_CONTENT_BANNER_TYPE, - IN_CONTENT_STORY_TYPE, - ACTION_SCROLLER_TYPE, - ACTION_SCROLLER_LIGHT_TYPE, - JUST_BANNER_TYPE - ], [`mediaTypes.${BANNER}.sizes`, `mediaTypes.${BANNER}`]) - }) - }) - }) - - describe('buildRequests method', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - - it('Url should be correct', function() { - expect(request.url).to.equal(SSP_ENDPOINT) - }) - - it('Method should be correct', function() { - expect(request.method).to.equal(REQUEST_METHOD) - }) - - describe('Common data request should be correct', function() { - it('pageUrl should be correct', function() { - expect(request.data.pageUrl).to.equal(pageUrl) - }) - it('bidRequests should be array', function() { - expect(Array.isArray(request.data.bidRequests)).to.equal(true) - }) - - request.data.bidRequests.forEach((bid, index) => { - describe(`bid with ${validBidRequests[index].params.placeType} should be correct`, function() { - it('bidId should be correct', function() { - expect(bid.bidId).to.equal(bidId) - }) - it('placeId should be correct', function() { - expect(bid.placeId).to.equal(placeId) - }) - it('transactionId should be correct', function() { - expect(bid.transactionId).to.equal(transactionId) - }) - it('sizes should be correct', function() { - expect(bid.sizes).to.equal(sizes) - }) - - if (includes([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], validBidRequests[index].params.placeType)) { - it('imageUrl should be correct', function() { - expect(bid.imageUrl).to.equal(imageUrl) - }) - it('imageWidth should be correct', function() { - expect(bid.imageWidth).to.equal(Math.floor(imageWidth)) - }) - it('imageHeight should be correct', function() { - expect(bid.imageHeight).to.equal(Math.floor(imageHeight)) - }) - } - }) - }) - }) - }) - - describe('interpretResponse method', function() { - it('should return a void array, when the server response are not correct.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { - body: {} - } - const bids = spec.interpretResponse(serverResponse, request) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - it('should return a void array, when the server response have not got bids.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { body: { bids: [] } } - const bids = spec.interpretResponse(serverResponse, request) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - describe('when the server response return a bids', function() { - Object.keys(configByPlaceType).forEach(placeType => { - it(`should return a bid with ${placeType} placeType`, function() { - const cpm = 10 - const currency = 'RUB' - const creativeId = '123' - const netRevenue = true - const width = sizes[0][0] - const height = sizes[0][1] - const adSettings = { - content: 'html' - } - const placeSettings = { - placeType, - } - const request = spec.buildRequests([validBidRequests[0]], bidderRequest) - const serverResponse = { - body: { - bids: [ - { - bidId, - cpm, - currency, - creativeId, - netRevenue, - width, - height, - adSettings, - placeSettings, - } - ] - } - } - const bids = spec.interpretResponse(serverResponse, request) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal(bidId) - expect(bids[0].meta.mediaType).to.equal(mediaTypeByPlaceType[placeSettings.placeType]) - expect(bids[0].cpm).to.equal(cpm) - expect(bids[0].width).to.equal(width) - expect(bids[0].height).to.equal(height) - expect(bids[0].currency).to.equal(currency) - expect(bids[0].netRevenue).to.equal(netRevenue) - - if (mediaTypeByPlaceType[placeSettings.placeType] === BANNER) { - expect(typeof bids[0].ad).to.equal('string') - } else if (mediaTypeByPlaceType[placeSettings.placeType] === VIDEO) { - expect(typeof bids[0].vastXml).to.equal('string') - expect(typeof bids[0].renderer).to.equal('object') - } - }) - }) - }) - }) -}) diff --git a/test/spec/modules/ajaBidAdapter_spec.js b/test/spec/modules/ajaBidAdapter_spec.js index 9bb77520212..ccc2ab7de99 100644 --- a/test/spec/modules/ajaBidAdapter_spec.js +++ b/test/spec/modules/ajaBidAdapter_spec.js @@ -34,21 +34,21 @@ describe('AjaAdapter', function () { }); describe('buildRequests', function () { - const bidRequests = [ + let bidRequests = [ { - bidder: 'aja', - params: { - asi: '123456' + 'bidder': 'aja', + 'params': { + 'asi': '123456' }, - adUnitCode: 'adunit', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', + 'adUnitCode': 'adunit', + 'sizes': [[300, 250]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', } ]; - const bidderRequest = { + let bidderRequest = { refererInfo: { referer: 'https://hoge.com' } @@ -62,44 +62,6 @@ describe('AjaAdapter', function () { }); }); - describe('buildRequests with UserModule', function () { - const bidRequests = [ - { - bidder: 'aja', - params: { - asi: '123456' - }, - adUnitCode: 'adunit', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - } - ] - } - ]; - - const bidderRequest = { - refererInfo: { - referer: 'https://hoge.com' - } - }; - - it('sends bid request to ENDPOINT via GET', function () { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].data).to.equal('asi=123456&skt=5&prebid_id=30b31c1838de1e&prebid_ver=$prebid.version$&page_url=https%3A%2F%2Fhoge.com&eids=%7B%22eids%22%3A%5B%7B%22source%22%3A%22pubcid.org%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22some-random-id-value%22%2C%22atype%22%3A1%7D%5D%7D%5D%7D&'); - }); - }); - describe('interpretResponse', function () { it('should get correct banner bid response', function () { let response = { diff --git a/test/spec/modules/akamaiDapRtdProvider_spec.js b/test/spec/modules/akamaiDapRtdProvider_spec.js deleted file mode 100644 index b350c2bb529..00000000000 --- a/test/spec/modules/akamaiDapRtdProvider_spec.js +++ /dev/null @@ -1,246 +0,0 @@ -import {config} from 'src/config.js'; -import {SEGMENTS_STORAGE_KEY, TOKEN_STORAGE_KEY, dapUtils, addRealTimeData, getRealTimeData, akamaiDapRtdSubmodule, storage} from 'modules/akamaiDapRtdProvider.js'; -import {server} from 'test/mocks/xhr.js'; -import logMessage from 'src/utils.js' -const responseHeader = {'Content-Type': 'application/json'}; - -describe('akamaiDapRtdProvider', function() { - let getDataFromLocalStorageStub; - let getDapTokenStub; - - const testReqBidsConfigObj = { - adUnits: [ - { - bids: ['bid1', 'bid2'] - } - ] - }; - - const onDone = function() { return true }; - - const onSuccess = function() { return ('request', 200, 'success') }; - - const cmoduleConfig = { - 'name': 'dap', - 'waitForIt': true, - 'params': { - 'apiHostname': 'prebid.dap.akadns.net', - 'apiVersion': 'x1', - 'domain': 'prebid.org', - 'identityType': 'dap-signature:1.0.0', - 'segtax': 503, - 'tokenTtl': 5 - } - } - - const sampleConfig = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 'x1', - 'domain': 'prebid.org', - 'segtax': 503 - } - const sampleIdentity = { - type: 'dap-signature:1.0.0' - }; - - beforeEach(function() { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage') - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('akamaiDapRtdSubmodule', function() { - it('successfully instantiates', function () { - expect(akamaiDapRtdSubmodule.init()).to.equal(true); - }); - }); - - describe('Get Real-Time Data', function() { - it('gets rtd from local storage cache', function() { - const rtdConfig = { - params: { - segmentCache: true - } - }; - - const bidConfig = {}; - - const rtdUserObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const cachedRtd = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - } - }; - - getDataFromLocalStorageStub.withArgs(SEGMENTS_STORAGE_KEY).returns(JSON.stringify(cachedRtd)); - - expect(config.getConfig().ortb2).to.be.undefined; - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(config.getConfig().ortb2.user.data).to.deep.include.members([rtdUserObj1]); - }); - - it('should initalise and return with config', function () { - expect(getRealTimeData(testReqBidsConfigObj, onDone, cmoduleConfig)).to.equal(undefined) - }); - }); - - describe('dapTokenize', function () { - it('dapTokenize error callback', function () { - let configAsync = JSON.parse(JSON.stringify(sampleConfig)); - let submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, - function(token, status, xhr) { - }, - function(xhr, status, error) { - } - ); - let request = server.requests[0]; - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapTokenize success callback', function () { - let configAsync = JSON.parse(JSON.stringify(sampleConfig)); - let submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, - function(token, status, xhr) { - }, - function(xhr, status, error) { - } - ); - let request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapTokenize and dapMembership incorrect params', function () { - it('Onerror and config are null', function () { - expect(dapUtils.dapTokenize(null, 'identity', null, null)).to.be.equal(undefined); - expect(dapUtils.dapMembership(null, 'identity', null, null)).to.be.equal(undefined); - const config = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 1, - 'domain': '', - 'segtax': 503 - }; - let identity = { - type: 'dap-signature:1.0.0' - }; - expect(dapUtils.dapTokenize(config, identity, null, null)).to.be.equal(undefined); - expect(dapUtils.dapMembership(config, 'token', null, null)).to.be.equal(undefined); - }); - - it('dapGetToken success', function () { - let dapTokenizeStub = sinon.stub(dapUtils, 'dapTokenize').returns(onSuccess); - expect(dapUtils.dapGetToken(sampleConfig, 'token', - function(token, status, xhr) { - }, - function(xhr, status, error) { - } - )).to.be.equal(null); - dapTokenizeStub.restore(); - }); - }); - - describe('dapMembership', function () { - it('dapMembership success callback', function () { - let configAsync = JSON.parse(JSON.stringify(sampleConfig)); - let submoduleCallback = dapUtils.dapMembership(configAsync, 'token', - function(token, status, xhr) { - }, - function(xhr, status, error) { - } - ); - let request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapMembership error callback', function () { - let configAsync = JSON.parse(JSON.stringify(sampleConfig)); - let submoduleCallback = dapUtils.dapMembership(configAsync, 'token', - function(token, status, xhr) { - }, - function(xhr, status, error) { - } - ); - let request = server.requests[0]; - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapMembership', function () { - it('should invoke the getDapToken and getDapMembership', function () { - let config = { - api_hostname: cmoduleConfig.params.apiHostname, - api_version: cmoduleConfig.params.apiVersion, - domain: cmoduleConfig.params.domain, - segtax: cmoduleConfig.params.segtax - }; - let identity = { - type: cmoduleConfig.params.identityType - }; - - let membership = { - said: 'item.said1', - cohorts: 'item.cohorts', - attributes: null - }; - - let getDapTokenStub = sinon.stub(dapUtils, 'dapGetToken').returns('token3'); - let getDapMembershipStub = sinon.stub(dapUtils, 'dapGetMembership').returns(membership); - let dapTokenizeStub = sinon.stub(dapUtils, 'dapTokenize').returns('response', 200, 'request'); - getRealTimeData(testReqBidsConfigObj, onDone, cmoduleConfig); - expect(getDapTokenStub.calledOnce).to.be.equal(true); - expect(getDapMembershipStub.calledOnce).to.be.equal(true); - getDapTokenStub.restore(); - getDapMembershipStub.restore(); - dapTokenizeStub.restore(); - }); - }); - - describe('dapMembershipToRtbSegment', function () { - it('dapMembershipToRtbSegment', function () { - let membership1 = { - said: 'item.said1', - cohorts: 'item.cohorts', - attributes: null - }; - const config = { - apiHostname: 'prebid.dap.akadns.net', - apiVersion: 'x1', - domain: 'prebid.org', - tokenTtl: 5, - segtax: 503 - }; - let identity = { - type: 'dap-signature:1.0.0' - }; - - expect(dapUtils.dapGetMembership(config, 'token')).to.equal(null) - const membership = {cohorts: ['1', '5', '7']} - expect(dapUtils.dapMembershipToRtbSegment(membership, config)).to.not.equal(undefined); - }); - }); -}); diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index e7724a4dc83..9396c1e1928 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -1004,16 +1004,12 @@ describe('AppNexusAdapter', function () { describe('interpretResponse', function () { let bfStub; - let bidderSettingsStorage; - before(function() { bfStub = sinon.stub(bidderFactory, 'getIabSubCategory'); - bidderSettingsStorage = $$PREBID_GLOBAL$$.bidderSettings; }); after(function() { bfStub.restore(); - $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsStorage; }); let response = { @@ -1051,8 +1047,7 @@ describe('AppNexusAdapter', function () { 'trackers': [ { 'impression_urls': [ - 'https://lax1-ib.adnxs.com/impression', - 'https://www.test.com/tracker' + 'https://lax1-ib.adnxs.com/impression' ], 'video_events': {} } @@ -1081,15 +1076,6 @@ describe('AppNexusAdapter', function () { 'adUnitCode': 'code', 'appnexus': { 'buyerMemberId': 958 - }, - 'meta': { - 'dchain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [{ - 'bsid': '958' - }] - } } } ]; @@ -1098,46 +1084,11 @@ describe('AppNexusAdapter', function () { bidId: '3db3773286ee59', adUnitCode: 'code' }] - }; + } let result = spec.interpretResponse({ body: response }, {bidderRequest}); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); }); - it('should reject 0 cpm bids', function () { - let zeroCpmResponse = deepClone(response); - zeroCpmResponse.tags[0].ads[0].cpm = 0; - - let bidderRequest = { - bidderCode: 'appnexus' - }; - - let result = spec.interpretResponse({ body: zeroCpmResponse }, { bidderRequest }); - expect(result.length).to.equal(0); - }); - - it('should allow 0 cpm bids if allowZeroCpmBids setConfig is true', function () { - $$PREBID_GLOBAL$$.bidderSettings = { - appnexus: { - allowZeroCpmBids: true - } - }; - - let zeroCpmResponse = deepClone(response); - zeroCpmResponse.tags[0].ads[0].cpm = 0; - - let bidderRequest = { - bidderCode: 'appnexus', - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - }; - - let result = spec.interpretResponse({ body: zeroCpmResponse }, { bidderRequest }); - expect(result.length).to.equal(1); - expect(result[0].cpm).to.equal(0); - }); - it('handles nobid responses', function () { let response = { 'version': '0.0.1', @@ -1383,20 +1334,6 @@ describe('AppNexusAdapter', function () { expect(Object.keys(result[0].meta)).to.include.members(['advertiserId']); }); - it('should add brand id', function() { - let responseBrandId = deepClone(response); - responseBrandId.tags[0].ads[0].brand_id = 123; - - let bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - let result = spec.interpretResponse({ body: responseBrandId }, {bidderRequest}); - expect(Object.keys(result[0].meta)).to.include.members(['brandId']); - }); - it('should add advertiserDomains', function() { let responseAdvertiserId = deepClone(response); responseAdvertiserId.tags[0].ads[0].adomain = ['123']; diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js index cae90a19223..e2dd4747199 100644 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ b/test/spec/modules/atsAnalyticsAdapter_spec.js @@ -5,22 +5,16 @@ import {server} from '../../mocks/xhr.js'; import {parseBrowser} from '../../../modules/atsAnalyticsAdapter.js'; import {getStorageManager} from '../../../src/storageManager.js'; import {analyticsUrl} from '../../../modules/atsAnalyticsAdapter.js'; -let utils = require('src/utils'); let events = require('src/events'); let constants = require('src/constants.json'); export const storage = getStorageManager(); -let sandbox; -let clock; -let now = new Date(); describe('ats analytics adapter', function () { beforeEach(function () { sinon.stub(events, 'getEvents').returns([]); storage.setCookie('_lr_env_src_ats', 'true', 'Thu, 01 Jan 1970 00:00:01 GMT'); - sandbox = sinon.sandbox.create(); - clock = sandbox.useFakeTimers(now.getTime()); }); afterEach(function () { @@ -28,21 +22,18 @@ describe('ats analytics adapter', function () { atsAnalyticsAdapter.getUserAgent.restore(); atsAnalyticsAdapter.disableAnalytics(); Math.random.restore(); - sandbox.restore(); - clock.restore(); }); describe('track', function () { it('builds and sends request and response data', function () { sinon.stub(Math, 'random').returns(0.99); + sinon.stub(atsAnalyticsAdapter, 'shouldFireRequest').returns(true); sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - + let now = new Date(); now.setTime(now.getTime() + 3600000); storage.setCookie('_lr_env_src_ats', 'true', now.toUTCString()); storage.setCookie('_lr_sampling_rate', '10', now.toUTCString()); - this.timeout(2100); - let initOptions = { pid: '10433394' }; @@ -68,7 +59,7 @@ describe('ats analytics adapter', function () { 'refererInfo': { 'referer': 'https://example.com/dev' }, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7' + 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7', }; // prepare general auction - response let bidResponse = { @@ -96,7 +87,7 @@ describe('ats analytics adapter', function () { let expectedAfterBid = { 'Data': [{ 'has_envelope': true, - 'adapter_version': 3, + 'adapter_version': 1, 'bidder': 'appnexus', 'bid_id': '30c77d079cdf17', 'auction_id': 'a5b849e5-87d7-4205-8300-d063084fcfb7', @@ -109,30 +100,10 @@ describe('ats analytics adapter', function () { 'response_time_stamp': '2020-02-03T14:23:11.978Z', 'currency': 'USD', 'cpm': 0.5, - 'net_revenue': true, - 'bid_won': true + 'net_revenue': true }] }; - let wonRequest = { - 'adId': '2eddfdc0c791dc', - 'mediaType': 'banner', - 'requestId': '30c77d079cdf17', - 'cpm': 0.5, - 'creativeId': 29681110, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7', - 'statusMessage': 'Bid available', - 'responseTimestamp': 1633525319061, - 'requestTimestamp': 1633525319258, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'size': '300x250', - 'status': 'rendered' - }; - // lets simulate that some bidders timeout let bidTimeoutArgsV1 = [ { @@ -174,14 +145,6 @@ describe('ats analytics adapter', function () { // Step 5: Send auction end event events.emit(constants.EVENTS.AUCTION_END, {}); - // Step 6: Send bid won event - events.emit(constants.EVENTS.BID_WON, wonRequest); - - sandbox.stub($$PREBID_GLOBAL$$, 'getAllWinningBids').callsFake((key) => { - return [wonRequest] - }); - - clock.tick(2000); let requests = server.requests.filter(req => { return req.url.indexOf(analyticsUrl) > -1; @@ -190,12 +153,13 @@ describe('ats analytics adapter', function () { expect(requests.length).to.equal(1); let realAfterBid = JSON.parse(requests[0].requestBody); - - // Step 7: assert real data after bid and expected data + // Step 6: assert real data after bid and expected data expect(realAfterBid['Data']).to.deep.equal(expectedAfterBid['Data']); // check that the publisher ID is configured via options expect(atsAnalyticsAdapter.context.pid).to.equal(initOptions.pid); + + atsAnalyticsAdapter.shouldFireRequest.restore(); }) it('check browser is safari', function () { sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); @@ -221,12 +185,6 @@ describe('ats analytics adapter', function () { let browser = parseBrowser(); expect(browser).to.equal('Firefox'); }) - it('check browser is unknown', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns(undefined); - sinon.stub(Math, 'random').returns(0.99); - let browser = parseBrowser(); - expect(browser).to.equal('Unknown'); - }) it('should not fire analytics request if sampling rate is 0', function () { sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); sinon.stub(Math, 'random').returns(0.99); @@ -237,7 +195,7 @@ describe('ats analytics adapter', function () { sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); sinon.stub(Math, 'random').returns(0.99); // publisher can try to pass anything they want but we will set sampling rate to 100, which means we will have 1% of requests - let result = atsAnalyticsAdapter.shouldFireRequest(8); + let result = atsAnalyticsAdapter.shouldFireRequest(10); expect(result).to.equal(true); }) it('should not fire analytics request if math random is something other then 0.99', function () { @@ -247,31 +205,5 @@ describe('ats analytics adapter', function () { let result = atsAnalyticsAdapter.shouldFireRequest(10); expect(result).to.equal(false); }) - - it('should set cookie value to 10 for _lr_sampling_rate', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.setSamplingCookie(10); - let samplingRate = storage.getCookie('_lr_sampling_rate'); - expect(samplingRate).to.equal('10'); - }) - - it('should set cookie value to 0 for _lr_sampling_rate', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.setSamplingCookie(0); - let samplingRate = storage.getCookie('_lr_sampling_rate'); - expect(samplingRate).to.equal('0'); - }) - - it('enable analytics', function () { - sandbox.stub(utils, 'logError'); - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.enableAnalytics({ - options: {} - }); - expect(utils.logError.called).to.equal(true); - }) }) }) diff --git a/test/spec/modules/beachfrontBidAdapter_spec.js b/test/spec/modules/beachfrontBidAdapter_spec.js index d9b8cac10b4..e29994eba44 100644 --- a/test/spec/modules/beachfrontBidAdapter_spec.js +++ b/test/spec/modules/beachfrontBidAdapter_spec.js @@ -1,7 +1,6 @@ import { expect } from 'chai'; import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, OUTSTREAM_SRC, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter.js'; -import { config } from 'src/config.js'; -import { parseUrl, deepAccess } from 'src/utils.js'; +import { parseUrl } from 'src/utils.js'; describe('BeachfrontAdapter', function () { let bidRequests; @@ -557,69 +556,6 @@ describe('BeachfrontAdapter', function () { }); }); - describe('with first-party data', function () { - let sandbox - - beforeEach(function () { - sandbox = sinon.sandbox.create(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('must add first-party data to the video bid request', function () { - sandbox.stub(config, 'getConfig').callsFake(key => { - const cfg = { - ortb2: { - site: { - keywords: 'test keyword' - }, - user: { - data: 'some user data' - } - } - }; - return deepAccess(cfg, key); - }); - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com/page.html' - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.user.data).to.equal('some user data'); - expect(data.site.keywords).to.equal('test keyword'); - expect(data.site.page).to.equal('http://example.com/page.html'); - expect(data.site.domain).to.equal('example.com'); - }); - - it('must add first-party data to the banner bid request', function () { - sandbox.stub(config, 'getConfig').callsFake(key => { - const cfg = { - ortb2: { - site: { - keywords: 'test keyword' - }, - user: { - data: 'some user data' - } - } - }; - return deepAccess(cfg, key); - }); - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const requests = spec.buildRequests([ bidRequest ]); - const data = requests[0].data; - expect(data.ortb2.user.data).to.equal('some user data'); - expect(data.ortb2.site.keywords).to.equal('test keyword'); - }); - }); - describe('for multi-format bids', function () { it('should create a POST request for each bid format', function () { const width = 300; diff --git a/test/spec/modules/beopBidAdapter_spec.js b/test/spec/modules/beopBidAdapter_spec.js index 832ad2707d3..58296243a4a 100644 --- a/test/spec/modules/beopBidAdapter_spec.js +++ b/test/spec/modules/beopBidAdapter_spec.js @@ -1,7 +1,6 @@ import { expect } from 'chai'; import { spec } from 'modules/beopBidAdapter.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; const utils = require('src/utils'); const ENDPOINT = 'https://hb.beop.io/bid'; @@ -17,12 +16,6 @@ let validBid = { 'sizes': [[1, 1]] } }, - 'getFloor': () => { - return { - currency: 'USD', - floor: 10, - } - }, 'bidId': '30b31c1838de1e', 'bidderRequestId': '22edbae2733bf6', 'auctionId': '1d1a030790a475', @@ -31,10 +24,6 @@ let validBid = { }; describe('BeOp Bid Adapter tests', () => { - afterEach(function () { - config.setConfig({}); - }); - const adapter = newBidder(spec); describe('inherited functions', () => { @@ -92,7 +81,6 @@ describe('BeOp Bid Adapter tests', () => { bidRequests.push(validBid); it('should build the request', function () { - config.setConfig({'currency': {'adServerCurrency': 'USD'}}); const request = spec.buildRequests(bidRequests, {}); const payload = JSON.parse(request.data); const url = request.url; @@ -101,7 +89,6 @@ describe('BeOp Bid Adapter tests', () => { expect(payload.pid).to.equal('5a8af500c9e77c00017e4cad'); expect(payload.slts[0].name).to.exist; expect(payload.slts[0].name).to.equal('bellow-article'); - expect(payload.slts[0].flr).to.equal(10); }); it('should call the endpoint with GDPR consent and pageURL info if found', function () { @@ -124,7 +111,7 @@ describe('BeOp Bid Adapter tests', () => { expect(payload.tc_string).to.exist; expect(payload.tc_string).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='); expect(payload.url).to.exist; - expect(payload.url).to.equal('http://localhost:9876/context.html'); + expect(payload.url).to.equal('http://test.te'); }); }); diff --git a/test/spec/modules/betweenBidAdapter_spec.js b/test/spec/modules/betweenBidAdapter_spec.js index 65c200748e4..44d0752d4b2 100644 --- a/test/spec/modules/betweenBidAdapter_spec.js +++ b/test/spec/modules/betweenBidAdapter_spec.js @@ -23,32 +23,6 @@ describe('betweenBidAdapterTests', function () { let req_data = JSON.parse(request.data)[0].data; expect(req_data.bidid).to.equal('bid1234'); }); - - it('validate_video_params', function () { - let bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: {w: 240, h: 400, s: 1112}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [970, 250], - maxd: 123, - mind: 234, - codeType: 'unknown code type' - } - }, - }]; - let request = spec.buildRequests(bidRequestData); - let req_data = JSON.parse(request.data)[0].data; - - expect(req_data.mediaType).to.equal(2); - expect(req_data.maxd).to.equal(123); - expect(req_data.mind).to.equal(234); - expect(req_data.pos).to.equal('atf'); - expect(req_data.codeType).to.equal('inpage'); - }); - it('validate itu param', function() { let bidRequestData = [{ bidId: 'bid1234', @@ -103,54 +77,6 @@ describe('betweenBidAdapterTests', function () { expect(req_data.subid).to.equal(1138); }); - - it('validate eids parameter', function() { - const USER_ID_DATA = [ - { - source: 'admixer.net', - uids: [ - { id: '5706411dc1c54268ac2ed668b27f92a3', atype: 3 } - ] - } - ]; - - let bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - }, - sizes: [[240, 400]], - userIdAsEids: USER_ID_DATA, - }]; - - let request = spec.buildRequests(bidRequestData); - let req_data = JSON.parse(request.data)[0].data; - - expect(req_data.eids).to.have.deep.members(USER_ID_DATA); - }); - - it('validate eids parameter, if userIdAsEids = undefined', function() { - let bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - }, - sizes: [[240, 400]], - userIdAsEids: undefined - }]; - - let request = spec.buildRequests(bidRequestData); - let req_data = JSON.parse(request.data)[0].data; - - expect(req_data.eids).to.have.deep.members([]); - }); - it('validate click3rd param', function() { let bidRequestData = [{ bidId: 'bid1234', @@ -256,21 +182,6 @@ describe('betweenBidAdapterTests', function () { expect(bid.requestId).to.equal('bid1234'); expect(bid.ad).to.equal('Ad html'); }); - - it('validate_response_video_params', function () { - let serverResponse = { - body: [{ - mediaType: 2, - vastXml: 'vastXml', - }] - }; - let bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - let bid = bids[0]; - expect(bid.mediaType).to.equal(2); - expect(bid.vastXml).to.equal('vastXml'); - }); - it('validate response params without currency', function () { let serverResponse = { body: [{ @@ -311,6 +222,53 @@ describe('betweenBidAdapterTests', function () { expect(req_data.sizes).to.deep.equal(['970x250', '240x400', '728x90']) }); + it('check sharedId with id and third', function() { + const bidRequestData = [{ + bidId: 'bid123', + bidder: 'between', + mediaTypes: { + banner: { + sizes: [[728, 90]] + } + }, + params: { + s: 1112, + }, + userId: { + sharedid: { + id: '01EXQE7JKNDRDDVATB0S2GX1NT', + third: '01EXQE7JKNDRDDVATB0S2GX1NT' + } + } + }]; + const shid = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid; + const shid3 = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid3; + expect(shid).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT') && expect(shid3).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT'); + }); + + it('check sharedId with only id', function() { + const bidRequestData = [{ + bidId: 'bid123', + bidder: 'between', + mediaTypes: { + banner: { + sizes: [[728, 90]] + } + }, + params: { + s: 1112, + }, + userId: { + sharedid: { + id: '01EXQE7JKNDRDDVATB0S2GX1NT', + } + } + }]; + const shid = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid; + const shid3 = JSON.parse(spec.buildRequests(bidRequestData).data)[0].data.shid3; + expect(shid).to.equal('01EXQE7JKNDRDDVATB0S2GX1NT') && expect(shid3).to.equal(''); + }); + it('check adomain', function() { const serverResponse = { body: [{ diff --git a/test/spec/modules/bidViewabilityIO_spec.js b/test/spec/modules/bidViewabilityIO_spec.js index 5b4944082bc..b59dbc867c1 100644 --- a/test/spec/modules/bidViewabilityIO_spec.js +++ b/test/spec/modules/bidViewabilityIO_spec.js @@ -3,7 +3,7 @@ import * as events from 'src/events.js'; import * as utils from 'src/utils.js'; import * as sinon from 'sinon'; import { expect } from 'chai'; -import CONSTANTS from 'src/constants.json'; +import { EVENTS } from 'src/constants.json'; describe('#bidViewabilityIO', function() { const makeElement = (id) => { @@ -97,7 +97,7 @@ describe('#bidViewabilityIO', function() { expect(mockObserver.unobserve.calledOnce).to.be.true; expect(emitSpy.calledOnce).to.be.true; // expect(emitSpy.firstCall.args).to.be.false; - expect(emitSpy.firstCall.args[0]).to.eq(CONSTANTS.EVENTS.BID_VIEWABLE); + expect(emitSpy.firstCall.args[0]).to.eq(EVENTS.BID_VIEWABLE); }); }) diff --git a/test/spec/modules/bidViewability_spec.js b/test/spec/modules/bidViewability_spec.js index a822d86f852..211dec090a5 100644 --- a/test/spec/modules/bidViewability_spec.js +++ b/test/spec/modules/bidViewability_spec.js @@ -5,7 +5,7 @@ import * as utils from 'src/utils.js'; import * as sinon from 'sinon'; import {expect, spy} from 'chai'; import * as prebidGlobal from 'src/prebidGlobal.js'; -import CONSTANTS from 'src/constants.json'; +import { EVENTS } from 'src/constants.json'; import adapterManager, { gdprDataHandler, uspDataHandler } from 'src/adapterManager.js'; import parse from 'url-parse'; @@ -279,9 +279,9 @@ describe('#bidViewability', function() { let call = callBidViewableBidderSpy.getCall(0); expect(call.args[0]).to.equal(PBJS_WINNING_BID.bidder); expect(call.args[1]).to.deep.equal(PBJS_WINNING_BID); - // CONSTANTS.EVENTS.BID_VIEWABLE is triggered + // EVENTS.BID_VIEWABLE is triggered call = eventsEmitSpy.getCall(0); - expect(call.args[0]).to.equal(CONSTANTS.EVENTS.BID_VIEWABLE); + expect(call.args[0]).to.equal(EVENTS.BID_VIEWABLE); expect(call.args[1]).to.deep.equal(PBJS_WINNING_BID); }); @@ -290,7 +290,7 @@ describe('#bidViewability', function() { expect(triggerPixelSpy.callCount).to.equal(0); // adapterManager.callBidViewableBidder is NOT called expect(callBidViewableBidderSpy.callCount).to.equal(0); - // CONSTANTS.EVENTS.BID_VIEWABLE is NOT triggered + // EVENTS.BID_VIEWABLE is NOT triggered expect(eventsEmitSpy.callCount).to.equal(0); }); }); diff --git a/test/spec/modules/bliinkBidAdapter_spec.js b/test/spec/modules/bliinkBidAdapter_spec.js deleted file mode 100644 index 729605f7db8..00000000000 --- a/test/spec/modules/bliinkBidAdapter_spec.js +++ /dev/null @@ -1,612 +0,0 @@ -import { expect } from 'chai' -import { spec, buildBid, BLIINK_ENDPOINT_ENGINE, parseXML, getMetaList } from 'modules/bliinkBidAdapter.js' - -/** - * @description Mockup bidRequest - * @return {{ - * bidderWinsCount: number, - * adUnitCode: string, - * bidder: string, - * src: string, - * bidRequestsCount: number, - * params: {tagId: string, placement: string}, - * bidId: string, - * transactionId: string, - * auctionId: string, - * bidderRequestId: string, - * bidderRequestsCount: number, - * mediaTypes: {banner: {sizes: number[][]}}, - * sizes: number[][], - * crumbs: {pubcid: string}, - * ortb2Imp: {ext: {data: {pbadslot: string}}}}} - */ -const getConfigBid = (placement) => { - return { - adUnitCode: '/19968336/test', - auctionId: '6752b51c-dcd4-4001-85dc-885ab5c504cf', - bidId: '2def0c5b2a7f6e', - bidRequestsCount: 1, - bidder: 'bliink', - bidderRequestId: '1592eb20088b18', - bidderRequestsCount: 1, - bidderWinsCount: 0, - crumbs: { - pubcid: '55ffadc5-051f-428d-8ecc-dc585e0bde0d' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - ortb2Imp: { - ext: { - data: { - pbadslot: '/19968336/test' - } - } - }, - params: { - placement: placement, - tagId: '14f30eca-85d2-11e8-9eed-0242ac120007' - }, - sizes: [ - [300, 250] - ], - src: 'client', - transactionId: 'cc6678c4-9746-4082-b9e2-d8065d078ebf' - } -} - -/** - * @description Mockup response from engine.bliink.io/xxxx - * @return { - * { - * viewability_percent_in_view: number, - * viewability_duration: number, - * ad_id: number, - * id: number, - * category: number, - * type: number, - * content: { - * creative: { - * adm: string - * } - * } - * } - * } -* } - */ -const getConfigCreative = () => { - return { - ad_id: 5648, - price: 1, - currency: 'EUR', - media_type: 'banner', - category: 1, - id: 2825, - creativeId: 2825, - type: 1, - viewability_duration: 1, - viewability_percent_in_view: 30, - content: { - creative: { - adm: '', - } - } - } -} - -const getConfigCreativeVideo = () => { - return { - ad_id: 5648, - price: 1, - currency: 'EUR', - media_type: 'video', - category: 1, - creativeId: 2825, - content: '' - } -} - -/** - * @description Mockup BuildRequest function - * @return {{bidderRequestId: string, bidderCode: string, bids: {bidderWinsCount: number, adUnitCode: string, bidder: string, src: string, bidRequestsCount: number, params: {tagId: string, placement: string}, bidId: string, transactionId: string, auctionId: string, bidderRequestId: string, bidderRequestsCount: number, mediaTypes: {banner: {sizes: number[][]}}, sizes: number[][], crumbs: {pubcid: string}, ortb2Imp: {ext: {data: {pbadslot: string}}}}[], refererInfo: {referer: string, canonicalUrl: null, isAmp: boolean, reachedTop: boolean, numIframes: number}}} - */ -const getConfigBuildRequest = (placement) => { - let buildRequest = { - bidderRequestId: '164ddfd207e94d', - bidderCode: 'bliink', - bids: [getConfigBid(placement)], - refererInfo: { - canonicalUrl: null, - isAmp: false, - numIframes: 0, - reachedTop: true, - referer: 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html?pbjs_debug=true', - }, - } - - if (!placement) { - return buildRequest - } - - return Object.assign(buildRequest, { - params: { - bids: [getConfigBid(placement)], - placement: placement - }, - }) -} - -/** - * @description Mockup response from API - * @param noAd - * @return {{mode: string, message: string}|{headers: {}, body: {mode: string, creative: {viewability_percent_in_view: number, viewability_duration: number, ad_id: number, adm: string, id: number, category: number, type: number}, token: string}}} - */ -const getConfigInterpretResponse = (noAd = false) => { - if (noAd) { - return { - message: 'invalid tag', - mode: 'no-ad' - } - } - - return { - body: { - creative: getConfigCreative(), - mode: 'ad', - token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjgxNzA4MzEsImlhdCI6MTYyNzU2NjAzMSwiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6IjM1YmU1NDNjLTNkZTQtNGQ1Yy04N2NjLWIzYzEyOGZiYzU0MCIsIm5ldHdvcmtJZCI6MjEsInNpdGVJZCI6NTksInRhZ0lkIjo1OSwiY29va2llSWQiOiJjNGU4MWVhOS1jMjhmLTQwZDItODY1ZC1hNjQzZjE1OTcyZjUiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwiaXAiOiI3OC4xMjIuNzUuNzIiLCJ0aW1lIjoxNjI3NTY2MDMxLCJsb2NhdGlvbiI6eyJsYXRpdHVkZSI6NDguOTczOSwibG9uZ2l0dWRlIjozLjMxMTMsInJlZ2lvbiI6IkhERiIsImNvdW50cnkiOiJGUiIsImNpdHkiOiJTYXVsY2hlcnkiLCJ6aXBDb2RlIjoiMDIzMTAiLCJkZXBhcnRtZW50IjoiMDIifSwiY2l0eSI6IlNhdWxjaGVyeSIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTEuMC40NDcyLjEyNCBTYWZhcmkvNTM3LjM2In0sImdkcHIiOnsiaGFzQ29uc2VudCI6dHJ1ZX0sIndpbiI6ZmFsc2UsImFkSWQiOjU2NDgsImFkdmVydGlzZXJJZCI6MSwiY2FtcGFpZ25JZCI6MSwiY3JlYXRpdmVJZCI6MjgyNSwiZXJyb3IiOmZhbHNlfX0.-UefQH4G0k-RJGemBYffs-KL7EEwma2Wuwgk2xnpij8' - }, - headers: {}, - } -} - -/** - * @description Mockup response from API for RTB creative - * @param noAd - * @return {{body: string} | {mode: string, message: string}} - */ -const getConfigInterpretResponseRTB = (noAd = false) => { - if (noAd) { - return { - message: 'invalid tag', - mode: 'no-ad' - } - } - - return { - body: ` - - - - BLIINK - https://vast.bliink.io/p/508379d0-9f65-4198-8ba5-f61f2b51224f.xml - https://e.api.bliink.io/e?name=vast-error&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzQwMzA1MjcsImlhdCI6MTYzMzQyNTcyNywiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6ImE2NjJjZGJmLTkzNDYtNDI0MS1iMTU0LTJhOTc2OTg0NjNmOSIsIm5ldHdvcmtJZCI6MjUsInNpdGVJZCI6MTQzLCJ0YWdJZCI6MTI3MSwiY29va2llSWQiOiIwNWFhN2UwMi05MzgzLTQ1NGYtOTJmZC1jOTE2YWNlMmUyZjYiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwicmVmZXJyZXIiOiJodHRwOi8vbG9jYWxob3N0OjgxODEvaW50ZWdyYXRpb25FeGFtcGxlcy9ncHQvYmxpaW5rLWluc3RyZWFtLmh0bWwiLCJwYWdlVXJsIjoiaHR0cDovL2xvY2FsaG9zdDo4MTgxL2ludGVncmF0aW9uRXhhbXBsZXMvZ3B0L2JsaWluay1pbnN0cmVhbS5odG1sIiwiaXAiOiIzMS4zOS4xNDEuMTQwIiwidGltZSI6MTYzMzQyNTcyNywibG9jYXRpb24iOnsibGF0aXR1ZGUiOjQ4Ljk0MjIsImxvbmdpdHVkZSI6Mi41MDM5LCJyZWdpb24iOiJJREYiLCJjb3VudHJ5IjoiRlIiLCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsInppcENvZGUiOiI5MzYwMCIsImRlcGFydG1lbnQiOiI5MyJ9LCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTMuMC40NTc3LjYzIFNhZmFyaS81MzcuMzYiLCJjb250ZW50Q2xhc3NpZmljYXRpb24iOnsiYnJhbmRzYWZlIjpmYWxzZX19LCJnZHByIjp7Imhhc0NvbnNlbnQiOnRydWV9LCJ3aW4iOmZhbHNlLCJhZElkIjo1NzkzLCJhZHZlcnRpc2VySWQiOjEsImNhbXBhaWduSWQiOjEsImNyZWF0aXZlSWQiOjExOTQsImVycm9yIjpmYWxzZX19.nJSJPKovg0_jSHtLdrMPDqesAIlFKCuXPXYxpsyWBDw - https://e.api.bliink.io/e?name=impression&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzQwMzA1MjcsImlhdCI6MTYzMzQyNTcyNywiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6ImE2NjJjZGJmLTkzNDYtNDI0MS1iMTU0LTJhOTc2OTg0NjNmOSIsIm5ldHdvcmtJZCI6MjUsInNpdGVJZCI6MTQzLCJ0YWdJZCI6MTI3MSwiY29va2llSWQiOiIwNWFhN2UwMi05MzgzLTQ1NGYtOTJmZC1jOTE2YWNlMmUyZjYiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwicmVmZXJyZXIiOiJodHRwOi8vbG9jYWxob3N0OjgxODEvaW50ZWdyYXRpb25FeGFtcGxlcy9ncHQvYmxpaW5rLWluc3RyZWFtLmh0bWwiLCJwYWdlVXJsIjoiaHR0cDovL2xvY2FsaG9zdDo4MTgxL2ludGVncmF0aW9uRXhhbXBsZXMvZ3B0L2JsaWluay1pbnN0cmVhbS5odG1sIiwiaXAiOiIzMS4zOS4xNDEuMTQwIiwidGltZSI6MTYzMzQyNTcyNywibG9jYXRpb24iOnsibGF0aXR1ZGUiOjQ4Ljk0MjIsImxvbmdpdHVkZSI6Mi41MDM5LCJyZWdpb24iOiJJREYiLCJjb3VudHJ5IjoiRlIiLCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsInppcENvZGUiOiI5MzYwMCIsImRlcGFydG1lbnQiOiI5MyJ9LCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTMuMC40NTc3LjYzIFNhZmFyaS81MzcuMzYiLCJjb250ZW50Q2xhc3NpZmljYXRpb24iOnsiYnJhbmRzYWZlIjpmYWxzZX19LCJnZHByIjp7Imhhc0NvbnNlbnQiOnRydWV9LCJ3aW4iOmZhbHNlLCJhZElkIjo1NzkzLCJhZHZlcnRpc2VySWQiOjEsImNhbXBhaWduSWQiOjEsImNyZWF0aXZlSWQiOjExOTQsImVycm9yIjpmYWxzZX19.nJSJPKovg0_jSHtLdrMPDqesAIlFKCuXPXYxpsyWBDw - 1EUR - - - - ` - } -} - -/** - * - * - * - * @description Below start tests for utils fonctions - * - * - * - */ - -const testsGetMetaList = [ - { - title: 'Should return empty array if there are no parameters', - args: { - fn: getMetaList() - }, - want: [] - }, - { - title: 'Should return list of metas with name associated', - args: { - fn: getMetaList('test'), - }, - want: [ - { - key: 'name', - value: 'test', - }, - { - key: 'name*', - value: 'test', - }, - { - key: 'itemprop*', - value: 'test', - }, - { - key: 'property', - value: `'og:${'test'}'`, - }, - { - key: 'property', - value: `'twitter:${'test'}'`, - }, - { - key: 'property', - value: `'article:${'test'}'`, - }, - ] - } -] - -describe('BLIINK Adapter getMetaList', function() { - for (const test of testsGetMetaList) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn: (string|Document)}, want: string, title: string}, {args: {fn: (string|Document)}, want: string, title: string}]} - */ -const testsParseXML = [ - { - title: 'Should return null, if content length equal to 0', - args: { - fn: parseXML('') - }, - want: null, - }, - { - title: 'Should return null, if content isnt string', - args: { - fn: parseXML({}) - }, - want: null, - }, -] - -describe('BLIINK Adapter parseXML', function() { - for (const test of testsParseXML) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) - -/** - * - * - * - * @description End tests for utils fonctions - * - * - * - */ - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn}, want: boolean, title: string}, {args: {fn}, want: boolean, title: string}, {args: {fn}, want: boolean, title: string}]} - */ -const testsIsBidRequestValid = [ - { - title: 'isBidRequestValid format not valid', - args: { - fn: spec.isBidRequestValid({}) - }, - want: false, - }, - { - title: 'isBidRequestValid does not receive any bid', - args: { - fn: spec.isBidRequestValid() - }, - want: false, - }, - { - title: 'isBidRequestValid Receive a valid bid', - args: { - fn: spec.isBidRequestValid(getConfigBid('banner')) - }, - want: true, - } -] - -describe('BLIINK Adapter isBidRequestValid', function() { - for (const test of testsIsBidRequestValid) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) - -const testsInterpretResponse = [ - { - title: 'Should construct bid for video instream', - args: { - fn: spec.interpretResponse(getConfigInterpretResponseRTB(false), getConfigBuildRequest('video')) - }, - want: { - cpm: 0, - currency: 'EUR', - height: 250, - width: 300, - creativeId: 0, - mediaType: 'video', - netRevenue: false, - requestId: '2def0c5b2a7f6e', - ttl: 3600, - vastXml: getConfigInterpretResponseRTB().body, - } - }, - { - title: 'ServerResponse with message: invalid tag, return empty array', - args: { - fn: spec.interpretResponse(getConfigInterpretResponse(true), getConfigBuildRequest('banner')) - }, - want: [] - }, -] - -describe('BLIINK Adapter interpretResponse', function() { - for (const test of testsInterpretResponse) { - it(test.title, () => { - const res = test.args.fn - - if (res) { - expect(res).to.eql(test.want) - } - }) - } -}) - -/** - * @description Array of tests used in describe function below - * @type {[ - * {args: - * {fn: { - * cpm: number, - * netRevenue: boolean, - * ad, requestId, - * meta: {mediaType}, - * width: number, - * currency: string, - * ttl: number, - * creativeId: number, - * height: number - * } - * }, want, title: string}]} - */ -const testsBuildBid = [ - { - title: 'Should return null if no bid passed in parameters', - args: { - fn: buildBid() - }, - want: null - }, - { - title: 'Input data must respect the output model', - args: { - fn: buildBid({ id: 1, test: '123' }, { id: 2, test: '345' }, false, false) - }, - want: null - }, - { - title: 'input data respect the output model for video', - args: { - fn: buildBid(getConfigBid('video'), getConfigCreativeVideo()) - }, - want: { - requestId: getConfigBid('video').bidId, - cpm: 1, - currency: 'EUR', - mediaType: 'video', - width: 300, - height: 250, - creativeId: getConfigCreativeVideo().creativeId, - netRevenue: false, - vastXml: getConfigCreativeVideo().content, - ttl: 3600, - } - }, - { - title: 'input data respect the output model for banner', - args: { - fn: buildBid(getConfigBid('banner'), getConfigCreative()) - }, - want: { - requestId: getConfigBid('banner').bidId, - cpm: 1, - currency: 'EUR', - mediaType: 'banner', - width: 300, - height: 250, - creativeId: getConfigCreative().id, - ad: getConfigCreative().content.creative.adm, - ttl: 3600, - netRevenue: false, - } - } -] - -describe('BLIINK Adapter buildBid', function() { - for (const test of testsBuildBid) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn}, want, title: string}]} - */ -const testsBuildRequests = [ - { - title: 'Should not build request, no bidder request exist', - args: { - fn: spec.buildRequests() - }, - want: null - }, - { - title: 'Should build request if bidderRequest exist', - args: { - fn: spec.buildRequests([], getConfigBuildRequest('banner')) - }, - want: { - method: 'GET', - url: `${BLIINK_ENDPOINT_ENGINE}/${getConfigBuildRequest('banner').bids[0].params.tagId}`, - params: { - bidderRequestId: getConfigBuildRequest('banner').bidderRequestId, - bidderCode: getConfigBuildRequest('banner').bidderCode, - bids: getConfigBuildRequest('banner').bids, - refererInfo: getConfigBuildRequest('banner').refererInfo - }, - data: { - gdpr: false, - gdpr_consent: '', - height: 250, - width: 300, - keywords: '', - pageDescription: '', - pageTitle: '', - pageUrl: 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html?pbjs_debug=true', - } - } - }, - { - title: 'Should build request width GDPR configuration', - args: { - fn: spec.buildRequests([], Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX' - }, - })) - }, - want: { - method: 'GET', - url: `${BLIINK_ENDPOINT_ENGINE}/${getConfigBuildRequest('banner').bids[0].params.tagId}`, - params: { - bidderRequestId: getConfigBuildRequest('banner').bidderRequestId, - bidderCode: getConfigBuildRequest('banner').bidderCode, - bids: getConfigBuildRequest('banner').bids, - refererInfo: getConfigBuildRequest('banner').refererInfo - }, - data: { - gdpr: true, - gdpr_consent: 'XXXX', - pageDescription: '', - pageTitle: '', - keywords: '', - pageUrl: 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html?pbjs_debug=true', - height: 250, - width: 300, - } - } - } -] - -describe('BLIINK Adapter buildRequests', function() { - for (const test of testsBuildRequests) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) - -const getSyncOptions = (pixelEnabled = true, iframeEnabled = 'false') => { - return { - pixelEnabled, - iframeEnabled - } -} - -const getServerResponses = () => { - return [ - { - body: '', - } - ] -} - -const getGdprConsent = () => { - return { - gdprApplies: 1, - consentString: 'XXX' - } -} - -const testsGetUserSyncs = [ - { - title: 'Should not have gdprConsent exist', - args: { - fn: spec.getUserSyncs(getSyncOptions(), getServerResponses(), getGdprConsent()) - }, - want: [ - { - type: 'script', - url: 'https://prg.smartadserver.com/ac?out=js&nwid=3392&siteid=305791&pgname=rg&fmtid=81127&tgt=[sas_target]&visit=m&tmstp=[timestamp]&clcturl=[countgo]' - }, - { - type: 'image', - url: 'https://sync.smartadserver.com/getuid?nwid=3392&consentString=XXX&url=https%3A%2F%2Fcookiesync.api.bliink.io%2Fcookiesync%3Fpartner%3Dsmart%26uid%3D%5Bsas_uid%5D' - }, - { - type: 'image', - url: 'https://ad.360yield.com/server_match?partner_id=1531&consentString=XXX&r=https%3A%2F%2Fcookiesync.api.bliink.io%2Fcookiesync%3Fpartner%3Dazerion%26uid%3D%7BPUB_USER_ID%7D', - }, - { - type: 'image', - url: 'https://ads.stickyadstv.com/auto-user-sync?consentString=XXX', - }, - { - type: 'image', - url: 'https://cookiesync.api.bliink.io/getuid?url=https%3A%2F%2Fvisitor.omnitagjs.com%2Fvisitor%2Fsync%3Fuid%3D1625272249969090bb9d544bd6d8d645%26name%3DBLIINK%26visitor%3D%24UID%26external%3Dtrue&consentString=XXX', - }, - { - type: 'image', - url: 'https://cookiesync.api.bliink.io/getuid?url=https://pixel.advertising.com/ups/58444/sync?&gdpr=1&gdpr_consent=XXX&redir=true&uid=$UID', - }, - { - type: 'image', - url: 'https://ups.analytics.yahoo.com/ups/58499/occ?gdpr=1&gdpr_consent=XXX', - }, - { - type: 'image', - url: 'https://secure.adnxs.com/getuid?https%3A%2F%2Fcookiesync.api.bliink.io%2Fcookiesync%3Fpartner%3Dazerion%26uid%3D%24UID', - }, - ] - }, - { - title: 'Should not have gdpr consent', - args: { - fn: spec.getUserSyncs(getSyncOptions(), getServerResponses()) - }, - want: [] - } -] - -describe('BLIINK Adapter getUserSyncs', function() { - for (const test of testsGetUserSyncs) { - it(test.title, () => { - const res = test.args.fn - expect(res).to.eql(test.want) - }) - } -}) diff --git a/test/spec/modules/browsiRtdProvider_spec.js b/test/spec/modules/browsiRtdProvider_spec.js index 32e1c7fe795..ee37d16905b 100644 --- a/test/spec/modules/browsiRtdProvider_spec.js +++ b/test/spec/modules/browsiRtdProvider_spec.js @@ -1,6 +1,5 @@ import * as browsiRTD from '../../../modules/browsiRtdProvider.js'; import {makeSlot} from '../integration/faker/googletag.js'; -import * as utils from '../../../src/utils' describe('browsi Real time data sub module', function () { const conf = { @@ -30,11 +29,11 @@ describe('browsi Real time data sub module', function () { }); it('should match placement with ad unit', function () { - const slot = makeSlot({code: '/123/abc', divId: 'browsiAd_1'}); + const slot = makeSlot({code: '/57778053/Browsi_Demo_300x250', divId: 'browsiAd_1'}); - const test1 = browsiRTD.isIdMatchingAdUnit(slot, ['/123/abc']); // true - const test2 = browsiRTD.isIdMatchingAdUnit(slot, ['/123/abc', '/456/def']); // true - const test3 = browsiRTD.isIdMatchingAdUnit(slot, ['/123/def']); // false + const test1 = browsiRTD.isIdMatchingAdUnit(slot, ['/57778053/Browsi_Demo_300x250']); // true + const test2 = browsiRTD.isIdMatchingAdUnit(slot, ['/57778053/Browsi_Demo_300x250', '/57778053/Browsi']); // true + const test3 = browsiRTD.isIdMatchingAdUnit(slot, ['/57778053/Browsi_Demo_Low']); // false const test4 = browsiRTD.isIdMatchingAdUnit(slot, []); // true expect(test1).to.equal(true); @@ -44,12 +43,12 @@ describe('browsi Real time data sub module', function () { }); it('should return correct macro values', function () { - const slot = makeSlot({code: '/123/abc', divId: 'browsiAd_1'}); + const slot = makeSlot({code: '/57778053/Browsi_Demo_300x250', divId: 'browsiAd_1'}); slot.setTargeting('test', ['test', 'value']); // slot getTargeting doesn't act like GPT so we can't expect real value const macroResult = browsiRTD.getMacroId({p: '/'}, slot); - expect(macroResult).to.equal('/123/abc/NA'); + expect(macroResult).to.equal('/57778053/Browsi_Demo_300x250/NA'); const macroResultB = browsiRTD.getMacroId({}, slot); expect(macroResultB).to.equal('browsiAd_1'); @@ -73,7 +72,7 @@ describe('browsi Real time data sub module', function () { it('should return prediction from server', function () { makeSlot({code: 'hasPrediction', divId: 'hasPrediction'}); const data = { - p: {'hasPrediction': {ps: {0: 0.234}}}, + p: {'hasPrediction': {p: 0.234}}, kn: 'bv', pmd: undefined }; @@ -81,58 +80,4 @@ describe('browsi Real time data sub module', function () { expect(browsiRTD.browsiSubmodule.getTargetingData(['hasPrediction'])).to.eql({hasPrediction: {bv: '0.20'}}); }) }) - - describe('should return matching prediction', function () { - const predictions = { - 0: 0.123, - 1: 0.254, - 3: 0, - 4: 0.8 - } - const singlePrediction = { - 0: 0.123 - } - it('should return raw value if valid', function () { - expect(browsiRTD.getCurrentData(predictions, 0)).to.equal(0.123); - expect(browsiRTD.getCurrentData(predictions, 1)).to.equal(0.254); - }) - it('should return 0 for prediction = 0', function () { - expect(browsiRTD.getCurrentData(predictions, 3)).to.equal(0); - }) - it('should return -1 for invalid params', function () { - expect(browsiRTD.getCurrentData(null, 3)).to.equal(-1); - expect(browsiRTD.getCurrentData(predictions, null)).to.equal(-1); - }) - it('should return prediction according to object keys length ', function () { - expect(browsiRTD.getCurrentData(singlePrediction, 0)).to.equal(0.123); - expect(browsiRTD.getCurrentData(singlePrediction, 1)).to.equal(-1); - expect(browsiRTD.getCurrentData(singlePrediction, 2)).to.equal(-1); - expect(browsiRTD.getCurrentData(predictions, 4)).to.equal(0.8); - expect(browsiRTD.getCurrentData(predictions, 5)).to.equal(0.8); - expect(browsiRTD.getCurrentData(predictions, 8)).to.equal(0.8); - }) - }) - describe('should set bid request data', function () { - const data = { - p: { - 'adUnit1': {ps: {0: 0.234}}, - 'adUnit2': {ps: {0: 0.134}}}, - kn: 'bv', - pmd: undefined - }; - browsiRTD.setData(data); - const fakeAdUnits = [ - { - code: 'adUnit1' - }, - { - code: 'adUnit2' - } - ] - browsiRTD.browsiSubmodule.getBidRequestData({adUnits: fakeAdUnits}, () => {}, {}, null); - it('should set ad unit params with prediction values', function () { - expect(utils.deepAccess(fakeAdUnits[0], 'ortb2Imp.ext.data.browsi')).to.eql({bv: '0.20'}); - expect(utils.deepAccess(fakeAdUnits[1], 'ortb2Imp.ext.data.browsi')).to.eql({bv: '0.10'}); - }) - }) }); diff --git a/test/spec/modules/byDataAnalyticsAdapter_spec.js b/test/spec/modules/byDataAnalyticsAdapter_spec.js deleted file mode 100644 index 90b4e1d53a6..00000000000 --- a/test/spec/modules/byDataAnalyticsAdapter_spec.js +++ /dev/null @@ -1,139 +0,0 @@ -import ascAdapter from 'modules/byDataAnalyticsAdapter'; -import { expect } from 'chai'; -let adapterManager = require('src/adapterManager').default; -let events = require('src/events'); -let constants = require('src/constants.json'); -let auctionId = 'b70ef967-5c5b-4602-831e-f2cf16e59af2'; -const initOptions = { - clientId: 'asc00000', - logFrequency: 1, -}; -let userData = { - userId: '5da77-ec87-277b-8e7a5', - client_id: 'asc00000', - plateform_name: 'Macintosh', - os_version: 10.157, - browser_name: 'Chrome', - browser_version: 92.04515107, - screen_size: { - width: 1440, - height: 900 - }, - device_type: 'Desktop', - time_zone: 'Asia/Calcutta' -}; -let bidTimeoutArgs = [{ - auctionId, - bidId: '12e90cb5ddc5dea', - bidder: 'appnexus', - adUnitCode: 'div-gpt-ad-mrec1' -}]; -let noBidArgs = { - adUnitCode: 'div-gpt-ad-mrec1', - auctionId, - bidId: '14480e9832f2d2b', - bidder: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - src: 'client', - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' -} -let auctionEndArgs = { - adUnitCodes: ['div-gpt-ad-mrec1'], - adUnits: [{ - code: 'div-gpt-ad-mrec1', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - bids: [{bidder: 'appnexus', params: {placementId: '19305195'}}], - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' - }], - auctionEnd: 1627973487504, - auctionId, - auctionStatus: 'completed', - timestamp: 1627973484504, - bidsReceived: [], - bidderRequests: [{ - auctionId, - auctionStart: 1627973484504, - bidderCode: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - bids: [ - { - adUnitCode: 'div-gpt-ad-mrec1', - auctionId, - bidId: '14480e9832f2d2b', - bidder: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - src: 'client', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' - } - ] - }] -} -let expectedDataArgs = { - visitor_data: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1ZGE3Ny1lYzg3LTI3N2ItOGU3YTUiLCJjbGllbnRfaWQiOiJhc2MwMDAwMCIsInBsYXRlZm9ybV9uYW1lIjoiTWFjaW50b3NoIiwib3NfdmVyc2lvbiI6MTAuMTU3LCJicm93c2VyX25hbWUiOiJDaHJvbWUiLCJicm93c2VyX3ZlcnNpb24iOjkyLjA0NTE1MTA3LCJzY3JlZW5fc2l6ZSI6eyJ3aWR0aCI6MTQ0MCwiaGVpZ2h0Ijo5MDB9LCJkZXZpY2VfdHlwZSI6IkRlc2t0b3AiLCJ0aW1lX3pvbmUiOiJBc2lhL0NhbGN1dHRhIn0.jNKjsb3Q-ZjkVMcbss_dQFOmu_GdkGqd7t9MbRmqlG4YEMorcJHhUVmUuPi-9pKvC9_t4XlgjED90UieCvdxCQ', - auction_id: auctionId, - auction_start: 1627973484504, - auctionData: [ { - 'adUnit': 'div-gpt-ad-mrec1', - 'size': '300x250', - 'media_type': 'display', - 'bids_bidder': 'appnexus', - 'bids_bid_id': '14480e9832f2d2b' - }, { - 'adUnit': 'div-gpt-ad-mrec1', - 'size': '250x250', - 'media_type': 'display', - 'bids_bidder': 'appnexus', - 'bids_bid_id': '14480e9832f2d2b' - }] -} - -describe('byData Analytics Adapter ', () => { - beforeEach(() => { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(() => { - events.getEvents.restore(); - }); - - describe('enableAnalytics ', function () { - beforeEach(() => { - sinon.spy(ascAdapter, 'track'); - }); - afterEach(() => { - ascAdapter.disableAnalytics(); - ascAdapter.track.restore(); - }); - it('should init with correct options', function () { - ascAdapter.enableAnalytics(initOptions) - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'bydata', - options: initOptions - }); - expect(ascAdapter.initOptions).to.have.property('clientId', 'asc00000'); - expect(ascAdapter.initOptions).to.have.property('logFrequency', 1); - }); - }); - - describe('track-events', function () { - ascAdapter.enableAnalytics(initOptions) - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'bydata', - options: initOptions - }); - it('sends and formatted auction data ', function () { - events.emit(constants.EVENTS.BID_TIMEOUT, bidTimeoutArgs); - events.emit(constants.EVENTS.NO_BID, noBidArgs); - var userToken = ascAdapter.getVisitorData(userData); - var newAuData = ascAdapter.dataProcess(auctionEndArgs); - newAuData['visitor_data'] = userToken; - expect(newAuData).to.deep.equal(expectedDataArgs); - }); - }); -}); diff --git a/test/spec/modules/cleanioRtdProvider_spec.js b/test/spec/modules/cleanioRtdProvider_spec.js deleted file mode 100644 index 47c4b1b4961..00000000000 --- a/test/spec/modules/cleanioRtdProvider_spec.js +++ /dev/null @@ -1,188 +0,0 @@ -import * as utils from '../../../src/utils.js'; -import * as hook from '../../../src/hook.js' - -import { __TEST__ } from '../../../modules/cleanioRtdProvider.js'; - -const { - readConfig, - ConfigError, - pageInitStepPreloadScript, - pageInitStepProtectPage, - bidWrapStepAugmentHtml, - bidWrapStepProtectByWrapping, - beforeInit, -} = __TEST__; - -sinon.assert.expose(chai.assert, { prefix: 'sinon' }); - -const fakeScriptURL = 'https://example.com/script.js'; - -function makeFakeBidResponse() { - return { - ad: 'hello ad', - bidderCode: 'BIDDER', - creativeId: 'CREATIVE', - cpm: 1.23, - }; -} - -describe('clean.io RTD module', function () { - describe('readConfig()', function() { - it('should throw ConfigError on invalid configurations', function() { - expect(() => readConfig({})).to.throw(ConfigError); - expect(() => readConfig({ params: {} })).to.throw(ConfigError); - expect(() => readConfig({ params: { protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc', protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: '123' } })).to.throw(ConfigError); - }); - - it('should accept valid configurations', function() { - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids-nowait' } })).to.not.throw(); - }); - }); - - describe('Module initialization step', function() { - let insertElementStub; - beforeEach(function() { - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function() { - utils.insertElement.restore(); - }); - - it('pageInitStepPreloadScript() should insert link/preload element', function() { - pageInitStepPreloadScript(fakeScriptURL); - - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.rel === 'preload')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.as === 'script')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.href === fakeScriptURL)); - }); - - it('pageInitStepProtectPage() should insert script element', function() { - pageInitStepProtectPage(fakeScriptURL); - - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'SCRIPT')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.type === 'text/javascript')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.src === fakeScriptURL)); - }); - }); - - function ensurePrependToBidResponse(fakeBidResponse) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(''); - } - - function ensureWrapBidResponse(fakeBidResponse, scriptUrl) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(`src="${scriptUrl}"`); - expect(fakeBidResponse.ad).to.contain('agent.put(ad)'); - } - - describe('Bid processing step', function() { - it('bidWrapStepAugmentHtml() should prepend bid-specific information in a comment', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepAugmentHtml(fakeBidResponse); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('bidWrapStepProtectByWrapping() should wrap payload into a script tag', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepProtectByWrapping(fakeScriptURL, 0, fakeBidResponse); - ensureWrapBidResponse(fakeBidResponse, fakeScriptURL); - }); - }); - - describe('Sumbodule execution', function() { - let submoduleStub; - let insertElementStub; - beforeEach(function () { - submoduleStub = sinon.stub(hook, 'submodule'); - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function () { - utils.insertElement.restore(); - submoduleStub.restore(); - }); - - function getModule() { - beforeInit(); - - expect(submoduleStub.calledOnceWith('realTimeData')).to.equal(true); - - const registeredSubmoduleDefinition = submoduleStub.getCall(0).args[1]; - expect(registeredSubmoduleDefinition).to.be.an('object'); - expect(registeredSubmoduleDefinition).to.have.own.property('name', 'clean.io'); - expect(registeredSubmoduleDefinition).to.have.own.property('init').that.is.a('function'); - expect(registeredSubmoduleDefinition).to.have.own.property('onBidResponseEvent').that.is.a('function'); - - return registeredSubmoduleDefinition; - } - - it('should register clean.io RTD submodule provider', function () { - getModule(); - }); - - it('should refuse initialization with incorrect parameters', function () { - const { init } = getModule(); - expect(init({ params: { cdnUrl: 'abc', protectionMode: 'full' } }, {})).to.equal(false); // too short distribution name - sinon.assert.notCalled(insertElementStub); - }); - - it('should iniitalize in full (page) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'SCRIPT')); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('should iniitalize in bids (frame) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensureWrapBidResponse(fakeBidResponse, 'https://abc1234567890.cloudfront.net/script.js'); - }); - - it('should respect preload status in bids-nowait protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids-nowait' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - const preloadLink = insertElementStub.getCall(0).args[0]; - expect(preloadLink).to.have.property('onload').which.is.a('function'); - expect(preloadLink).to.have.property('onerror').which.is.a('function'); - - const fakeBidResponse1 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse1, {}, {}); - ensurePrependToBidResponse(fakeBidResponse1); - - // Simulate successful preloading - preloadLink.onload(); - - const fakeBidResponse2 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse2, {}, {}); - ensureWrapBidResponse(fakeBidResponse2, 'https://abc1234567890.cloudfront.net/script.js'); - - // Simulate error - preloadLink.onerror(); - - // Now we should fallback to just prepending - const fakeBidResponse3 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse3, {}, {}); - ensurePrependToBidResponse(fakeBidResponse3); - }); - }); -}); diff --git a/test/spec/modules/codefuelBidAdapter_spec.js b/test/spec/modules/codefuelBidAdapter_spec.js deleted file mode 100644 index a2549012d84..00000000000 --- a/test/spec/modules/codefuelBidAdapter_spec.js +++ /dev/null @@ -1,316 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/codefuelBidAdapter.js'; -import {config} from 'src/config.js'; -import {server} from 'test/mocks/xhr'; - -const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4515.159 Safari/537.36'; -const DEFAULT_USER_AGENT = window.navigator.userAgent; -const setUADefault = () => { window.navigator.__defineGetter__('userAgent', function () { return DEFAULT_USER_AGENT }) }; -const setUAMock = () => { window.navigator.__defineGetter__('userAgent', function () { return USER_AGENT }) }; - -describe('Codefuel Adapter', function () { - describe('Bid request and response', function () { - const commonBidRequest = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id' - }, - }, - bidId: '2d6815a92ba1ba', - auctionId: '12043683-3254-4f74-8934-f941b085579e', - } - const nativeBidRequestParams = { - nativeParams: { - image: { - required: true, - sizes: [ - 120, - 100 - ], - sendId: true - }, - title: { - required: true, - sendId: true - }, - sponsoredBy: { - required: false - } - }, - } - - const displayBidRequestParams = { - sizes: [ - [ - 300, - 250 - ] - ] - } - - describe('isBidRequestValid', function () { - before(() => { - config.setConfig({ - codefuel: { - bidderUrl: 'https://bidder-url.com', - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should fail when bid is invalid', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should not succeed when bid contains native params', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should not succeed when bid contains only sizes', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...displayBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if publisher id is not set', function () { - const bid = { - bidder: 'codefuel', - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - - it('should fail if bidder url is not set', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - config.resetConfig() - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - before(() => { - setUAMock() - config.setConfig({ - codefuel: { - bidderUrl: 'https://bidder-url.com', - } - } - ) - }) - after(() => { - config.resetConfig() - setUADefault() - }) - - const commonBidderRequest = { - timeout: 500, - auctionId: '12043683-3254-4f74-8934-f941b085579e', - refererInfo: { - referer: 'https://example.com/', - } - } - - it('should build display request', function () { - const bidRequest = { - ...commonBidRequest, - ...displayBidRequestParams, - } - const expectedData = { - cur: [ - 'USD' - ], - device: { - devicetype: 2, - ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4515.159 Safari/537.36' - }, - id: '12043683-3254-4f74-8934-f941b085579e', - imp: [ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ] - }, - id: '1' - } - ], - site: { - domain: 'example.com', - page: 'https://example.com/', - publisher: { - id: 'publisher-id' - } - }, - source: { - fd: 1 - }, - tmax: 500 - } - const res = spec.buildRequests([bidRequest], commonBidderRequest) - expect(res.url).to.equal('https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid') - expect(res.data).to.deep.equal(expectedData) - }) - - it('should pass bidder timeout', function () { - const bidRequest = { - ...commonBidRequest, - } - const bidderRequest = { - ...commonBidderRequest, - timeout: 500 - } - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = res.data - expect(resData.tmax).to.equal(500) - }); - }) - - describe('interpretResponse', function () { - it('should return empty array if no valid bids', function () { - const res = spec.interpretResponse({}, []) - expect(res).to.be.an('array').that.is.empty - }); - - it('should interpret display response', function () { - const serverResponse = { - body: { - id: '6b2eedc8-8ff5-46ef-adcf-e701b508943e', - seatbid: [ - { - bid: [ - { - id: 'd90fe7fa-28d7-11eb-8ce4-462a842a7cf9', - impid: '1', - price: 1.1, - nurl: 'http://example.com/win/${AUCTION_PRICE}', - adm: '
ad
', - adomain: [ - 'example.com' - ], - cid: '3865084', - crid: '29998660', - cat: [ - 'IAB10-2' - ], - w: 300, - h: 250 - } - ], - seat: 'acc-6536' - } - ], - bidid: 'd90fe7fa-28d7-11eb-8ce4-13d94bfa26f9', - cur: 'USD' - } - } - const request = { - bids: [ - { - ...commonBidRequest, - ...displayBidRequestParams - } - ] - } - const expectedRes = [ - { - requestId: request.bids[0].bidId, - cpm: 1.1, - creativeId: '29998660', - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - ad: '
ad
', - width: 300, - height: 250, - meta: {'advertiserDomains': []} - } - ] - - const res = spec.interpretResponse(serverResponse, request) - expect(res).to.deep.equal(expectedRes) - }); - }) - }) - - describe('getUserSyncs', function () { - const usersyncUrl = 'https://usersync-url.com'; - beforeEach(() => { - config.setConfig({ - codefuel: { - usersyncUrl: usersyncUrl, - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should not return user sync if pixel enabled with codefuel config', function () { - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if pixel disabled', function () { - const ret = spec.getUserSyncs({pixelEnabled: false}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if url is not set', function () { - config.resetConfig() - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not pass GDPR consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.to.be.an('array').that.is.empty - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.be.an('array').that.is.empty - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.be.an('array').that.is.empty - }); - - it('should not pass US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.be.an('array').that.is.empty - }); - - it('should pass GDPR and US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.be.an('array').that.is.empty - }); - }) -}) diff --git a/test/spec/modules/colossussspBidAdapter_spec.js b/test/spec/modules/colossussspBidAdapter_spec.js index 91f900d6279..4d80b52496e 100644 --- a/test/spec/modules/colossussspBidAdapter_spec.js +++ b/test/spec/modules/colossussspBidAdapter_spec.js @@ -1,5 +1,5 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/colossussspBidAdapter.js'; +import {expect} from 'chai'; +import {spec} from '../../../modules/colossussspBidAdapter.js'; describe('ColossussspAdapter', function () { let bid = { @@ -7,8 +7,7 @@ describe('ColossussspAdapter', function () { bidder: 'colossusssp', bidderRequestId: '145e1d6a7837c9', params: { - placement_id: 0, - group_id: 0 + placement_id: 0 }, placementCode: 'placementid_0', auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', @@ -17,13 +16,6 @@ describe('ColossussspAdapter', function () { sizes: [[300, 250]] } }, - ortb2Imp: { - ext: { - data: { - pbadslot: '/19968336/prebid_cache_video_adunit' - } - } - }, transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', schain: { ver: '1.0', @@ -80,7 +72,7 @@ describe('ColossussspAdapter', function () { it('Returns valid URL', function () { expect(serverRequest.url).to.equal('https://colossusssp.com/?c=o&m=multi'); }); - it('Should contain ccpa', function () { + it('Should contain ccpa', function() { expect(serverRequest.data.ccpa).to.be.an('string') }) @@ -97,15 +89,13 @@ describe('ColossussspAdapter', function () { let placements = data['placements']; for (let i = 0; i < placements.length; i++) { let placement = placements[i]; - expect(placement).to.have.all.keys('placementId', 'groupId', 'eids', 'bidId', 'traffic', 'sizes', 'schain', 'floor', 'gpid'); + expect(placement).to.have.all.keys('placementId', 'eids', 'bidId', 'traffic', 'sizes', 'schain', 'floor'); expect(placement.schain).to.be.an('object') expect(placement.placementId).to.be.a('number'); - expect(placement.groupId).to.be.a('number'); expect(placement.bidId).to.be.a('string'); expect(placement.traffic).to.be.a('string'); expect(placement.sizes).to.be.an('array'); expect(placement.floor).to.be.an('object'); - expect(placement.gpid).to.be.an('string'); } }); it('Returns empty data if no valid requests are passed', function () { @@ -121,7 +111,6 @@ describe('ColossussspAdapter', function () { bid.userId.idl_env = 'idl_env123'; bid.userId.tdid = 'tdid123'; bid.userId.id5id = { uid: 'id5id123' }; - bid.userId.uid2 = { id: 'uid2id123' }; let serverRequest = spec.buildRequests([bid], bidderRequest); it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; @@ -131,11 +120,11 @@ describe('ColossussspAdapter', function () { let placement = placements[i]; expect(placement).to.have.property('eids') expect(placement.eids).to.be.an('array') - expect(placement.eids.length).to.be.equal(5) + expect(placement.eids.length).to.be.equal(4) for (let index in placement.eids) { let v = placement.eids[index]; expect(v).to.have.all.keys('source', 'uids') - expect(v.source).to.be.oneOf(['britepool.com', 'identityLink', 'adserver.org', 'id5-sync.com', 'uidapi.com']) + expect(v.source).to.be.oneOf(['britepool.com', 'identityLink', 'adserver.org', 'id5-sync.com']) expect(v.uids).to.be.an('array'); expect(v.uids.length).to.be.equal(1) expect(v.uids[0]).to.have.property('id') @@ -146,7 +135,7 @@ describe('ColossussspAdapter', function () { describe('interpretResponse', function () { let resObject = { - body: [{ + body: [ { requestId: '123', mediaType: 'banner', cpm: 0.3, @@ -161,7 +150,7 @@ describe('ColossussspAdapter', function () { advertiserDomains: ['google.com'], advertiserId: 1234 } - }] + } ] }; let serverResponses = spec.interpretResponse(resObject); it('Returns an array of valid server responses if response object is valid', function () { @@ -189,15 +178,6 @@ describe('ColossussspAdapter', function () { }); }); - describe('onBidWon', function () { - it('should make an ajax call', function () { - const bid = { - nurl: 'http://example.com/win', - }; - expect(spec.onBidWon(bid)).to.equals(undefined); - }); - }) - describe('getUserSyncs', function () { let userSync = spec.getUserSyncs(); it('Returns valid URL and type', function () { diff --git a/test/spec/modules/compassBidAdapter_spec.js b/test/spec/modules/compassBidAdapter_spec.js deleted file mode 100644 index 28021c4f7c0..00000000000 --- a/test/spec/modules/compassBidAdapter_spec.js +++ /dev/null @@ -1,398 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/compassBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'compass' - -describe('CompassBidAdapter', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner', - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo', - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative', - } - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - refererInfo: { - referer: 'https://test.com' - } - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://sa-lb.deliverimp.com/pbjs'); - }); - - it('Returns general data valid', function () { - let data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('string'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - let data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('string'); - expect(data.gdpr).to.equal(bidderRequest.gdprConsent); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - let data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([], bidderRequest); - let data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - let bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - let dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - let videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - let dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - let nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - let dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - let serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - let serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - let serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - let serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sa-cs.deliverimp.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sa-cs.deliverimp.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/connectIdSystem_spec.js b/test/spec/modules/connectIdSystem_spec.js deleted file mode 100644 index 41135a74515..00000000000 --- a/test/spec/modules/connectIdSystem_spec.js +++ /dev/null @@ -1,189 +0,0 @@ -import {expect} from 'chai'; -import {parseQS} from 'src/utils.js'; -import {connectIdSubmodule} from 'modules/connectIdSystem.js'; - -describe('Yahoo ConnectID Submodule', () => { - const HASHED_EMAIL = '6bda6f2fa268bf0438b5423a9861a2cedaa5dec163c03f743cfe05c08a8397b2'; - const PIXEL_ID = '1234'; - const PROD_ENDPOINT = `https://ups.analytics.yahoo.com/ups/${PIXEL_ID}/fed`; - const OVERRIDE_ENDPOINT = 'https://foo/bar'; - - it('should have the correct module name declared', () => { - expect(connectIdSubmodule.name).to.equal('connectId'); - }); - - it('should have the correct TCFv2 Vendor ID declared', () => { - expect(connectIdSubmodule.gvlid).to.equal(25); - }); - - describe('getId()', () => { - let ajaxStub; - let getAjaxFnStub; - let consentData; - beforeEach(() => { - ajaxStub = sinon.stub(); - getAjaxFnStub = sinon.stub(connectIdSubmodule, 'getAjaxFn'); - getAjaxFnStub.returns(ajaxStub); - - consentData = { - gdpr: { - gdprApplies: 1, - consentString: 'GDPR_CONSENT_STRING' - }, - uspConsent: 'USP_CONSENT_STRING' - }; - }); - - afterEach(() => { - getAjaxFnStub.restore(); - }); - - function invokeGetIdAPI(configParams, consentData) { - let result = connectIdSubmodule.getId({ - params: configParams - }, consentData); - if (typeof result === 'object') { - result.callback(sinon.stub()); - } - return result; - } - - it('returns undefined if he and pixelId params are not passed', () => { - expect(invokeGetIdAPI({}, consentData)).to.be.undefined; - expect(ajaxStub.callCount).to.equal(0); - }); - - it('returns undefined if the pixelId param is not passed', () => { - expect(invokeGetIdAPI({ - he: HASHED_EMAIL - }, consentData)).to.be.undefined; - expect(ajaxStub.callCount).to.equal(0); - }); - - it('returns undefined if the he param is not passed', () => { - expect(invokeGetIdAPI({ - pixelId: PIXEL_ID - }, consentData)).to.be.undefined; - expect(ajaxStub.callCount).to.equal(0); - }); - - it('returns an object with the callback function if the correct params are passed', () => { - let result = invokeGetIdAPI({ - he: HASHED_EMAIL, - pixelId: PIXEL_ID - }, consentData); - expect(result).to.be.an('object').that.has.all.keys('callback'); - expect(result.callback).to.be.a('function'); - }); - - it('Makes an ajax GET request to the production API endpoint with query params', () => { - invokeGetIdAPI({ - he: HASHED_EMAIL, - pixelId: PIXEL_ID - }, consentData); - - const expectedParams = { - he: HASHED_EMAIL, - pixelId: PIXEL_ID, - '1p': '0', - gdpr: '1', - gdpr_consent: consentData.gdpr.consentString, - us_privacy: consentData.uspConsent - }; - const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]); - - expect(ajaxStub.firstCall.args[0].indexOf(`${PROD_ENDPOINT}?`)).to.equal(0); - expect(requestQueryParams).to.deep.equal(expectedParams); - expect(ajaxStub.firstCall.args[3]).to.deep.equal({method: 'GET', withCredentials: true}); - }); - - it('Makes an ajax GET request to the specified override API endpoint with query params', () => { - invokeGetIdAPI({ - he: HASHED_EMAIL, - endpoint: OVERRIDE_ENDPOINT - }, consentData); - - const expectedParams = { - he: HASHED_EMAIL, - '1p': '0', - gdpr: '1', - gdpr_consent: consentData.gdpr.consentString, - us_privacy: consentData.uspConsent - }; - const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]); - - expect(ajaxStub.firstCall.args[0].indexOf(`${OVERRIDE_ENDPOINT}?`)).to.equal(0); - expect(requestQueryParams).to.deep.equal(expectedParams); - expect(ajaxStub.firstCall.args[3]).to.deep.equal({method: 'GET', withCredentials: true}); - }); - - it('sets the callbacks param of the ajax function call correctly', () => { - invokeGetIdAPI({ - he: HASHED_EMAIL, - pixelId: PIXEL_ID, - }, consentData); - - expect(ajaxStub.firstCall.args[1]).to.be.an('object').that.has.all.keys(['success', 'error']); - }); - - it('sets GDPR consent data flag correctly when call is under GDPR jurisdiction.', () => { - invokeGetIdAPI({ - he: HASHED_EMAIL, - pixelId: PIXEL_ID, - }, consentData); - - const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]); - expect(requestQueryParams.gdpr).to.equal('1'); - expect(requestQueryParams.gdpr_consent).to.equal(consentData.gdpr.consentString); - }); - - it('sets GDPR consent data flag correctly when call is NOT under GDPR jurisdiction.', () => { - consentData.gdpr.gdprApplies = false; - - invokeGetIdAPI({ - he: HASHED_EMAIL, - pixelId: PIXEL_ID, - }, consentData); - - const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]); - expect(requestQueryParams.gdpr).to.equal('0'); - expect(requestQueryParams.gdpr_consent).to.equal(''); - }); - - [1, '1', true].forEach(firstPartyParamValue => { - it(`sets 1p payload property to '1' for a config value of ${firstPartyParamValue}`, () => { - invokeGetIdAPI({ - '1p': firstPartyParamValue, - he: HASHED_EMAIL, - pixelId: PIXEL_ID, - }, consentData); - - const requestQueryParams = parseQS(ajaxStub.firstCall.args[0].split('?')[1]); - expect(requestQueryParams['1p']).to.equal('1'); - }); - }); - }); - - describe('decode()', () => { - const VALID_API_RESPONSES = [{ - key: 'connectid', - expected: '4567', - payload: { - connectid: '4567' - } - }]; - VALID_API_RESPONSES.forEach(responseData => { - it('should return a newly constructed object with the connect ID for a payload with ${responseData.key} key(s)', () => { - expect(connectIdSubmodule.decode(responseData.payload)).to.deep.equal( - {connectId: responseData.expected} - ); - }); - }); - - [{}, '', {foo: 'bar'}].forEach((response) => { - it(`should return undefined for an invalid response "${JSON.stringify(response)}"`, () => { - expect(connectIdSubmodule.decode(response)).to.be.undefined; - }); - }); - }); -}); diff --git a/test/spec/modules/consentManagement_spec.js b/test/spec/modules/consentManagement_spec.js index d7ae3c58a85..5e9b0f07f46 100644 --- a/test/spec/modules/consentManagement_spec.js +++ b/test/spec/modules/consentManagement_spec.js @@ -715,26 +715,6 @@ describe('consentManagement', function () { expect(consent).to.be.null; }); - it('allows the auction when CMP is unresponsive', (done) => { - setConsentConfig({ - cmpApi: 'iab', - timeout: 10, - defaultGdprScope: true - }); - - requestBidsHook(() => { - didHookReturn = true; - }, {}); - - setTimeout(() => { - expect(didHookReturn).to.be.true; - const consent = gdprDataHandler.getConsentData(); - expect(consent.gdprApplies).to.be.true; - expect(consent.consentString).to.be.undefined; - done(); - }, 20); - }); - it('It still considers it a valid cmp response if gdprApplies is not a boolean', function () { // gdprApplies is undefined, should just still store consent response but use whatever defaultGdprScope was let testConsentData = { diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index aa995b3c9a0..7ec6972e1a5 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -772,44 +772,6 @@ describe('The Criteo bidding adapter', function () { expect(ortbRequest.slots[0].video.placement).to.equal(2); }); - it('should properly build a video request when mediaTypes.video.skip=0', function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - transactionId: 'transaction-123', - sizes: [[728, 90]], - mediaTypes: { - video: { - playerSize: [ [300, 250] ], - mimes: ['video/mp4', 'video/MPV', 'video/H264', 'video/webm', 'video/ogg'], - minduration: 1, - maxduration: 30, - playbackmethod: [2, 3, 4, 5, 6], - api: [1, 2, 3, 4, 5, 6], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 0 - } - }, - params: { - networkId: 123 - } - } - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.match(/^https:\/\/bidder\.criteo\.com\/cdb\?profileId=207&av=\d+&wv=[^&]+&cb=\d/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.slots[0].video.playersizes).to.deep.equal(['300x250']); - expect(ortbRequest.slots[0].video.mimes).to.deep.equal(['video/mp4', 'video/MPV', 'video/H264', 'video/webm', 'video/ogg']); - expect(ortbRequest.slots[0].video.minduration).to.equal(1); - expect(ortbRequest.slots[0].video.maxduration).to.equal(30); - expect(ortbRequest.slots[0].video.playbackmethod).to.deep.equal([2, 3, 4, 5, 6]); - expect(ortbRequest.slots[0].video.api).to.deep.equal([1, 2, 3, 4, 5, 6]); - expect(ortbRequest.slots[0].video.protocols).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]); - expect(ortbRequest.slots[0].video.skip).to.equal(0); - }); - it('should properly build a request with ceh', function () { const bidRequests = [ { diff --git a/test/spec/modules/criteoIdSystem_spec.js b/test/spec/modules/criteoIdSystem_spec.js index d50eadebb55..65e5aaf741d 100644 --- a/test/spec/modules/criteoIdSystem_spec.js +++ b/test/spec/modules/criteoIdSystem_spec.js @@ -1,9 +1,15 @@ import { criteoIdSubmodule, storage } from 'modules/criteoIdSystem.js'; import * as utils from 'src/utils.js'; -import {server} from '../../mocks/xhr'; +import * as ajaxLib from 'src/ajax.js'; const pastDateString = new Date(0).toString() +function mockResponse(responseText, fakeResponse = (url, callback) => callback(responseText)) { + return function() { + return fakeResponse; + } +} + describe('CriteoId module', function () { const cookiesMaxAge = 13 * 30 * 24 * 60 * 60 * 1000; @@ -16,6 +22,7 @@ describe('CriteoId module', function () { let removeFromLocalStorageStub; let timeStampStub; let parseUrlStub; + let ajaxBuilderStub; let triggerPixelStub; beforeEach(function (done) { @@ -25,6 +32,7 @@ describe('CriteoId module', function () { setLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage'); removeFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage'); timeStampStub = sinon.stub(utils, 'timestamp').returns(nowTimestamp); + ajaxBuilderStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockResponse('{}')); parseUrlStub = sinon.stub(utils, 'parseUrl').returns({protocol: 'https', hostname: 'testdev.com'}) triggerPixelStub = sinon.stub(utils, 'triggerPixel'); done(); @@ -37,6 +45,7 @@ describe('CriteoId module', function () { setLocalStorageStub.restore(); removeFromLocalStorageStub.restore(); timeStampStub.restore(); + ajaxBuilderStub.restore(); triggerPixelStub.restore(); parseUrlStub.restore(); }); @@ -52,9 +61,8 @@ describe('CriteoId module', function () { getCookieStub.withArgs('cto_bidid').returns(testCase.cookie); getLocalStorageStub.withArgs('cto_bidid').returns(testCase.localStorage); - const result = criteoIdSubmodule.getId(); - expect(result.id).to.be.deep.equal(testCase.expected ? { criteoId: testCase.expected } : undefined); - expect(result.callback).to.be.a('function'); + const id = criteoIdSubmodule.getId(); + expect(id).to.be.deep.equal({id: testCase.expected ? { criteoId: testCase.expected } : undefined}); })) it('decode() should return the bidId when it exists in local storages', function () { @@ -66,21 +74,16 @@ describe('CriteoId module', function () { getCookieStub.withArgs('cto_bundle').returns('bundle'); window.criteo_pubtag = {} - let callBackSpy = sinon.spy(); - let result = criteoIdSubmodule.getId(); - result.callback(callBackSpy); + const emptyObj = '{}'; + let ajaxStub = sinon.stub().callsFake((url, callback) => callback(emptyObj)); + ajaxBuilderStub.callsFake(mockResponse(undefined, ajaxStub)) + criteoIdSubmodule.getId(); const expectedUrl = `https://gum.criteo.com/sid/json?origin=prebid&topUrl=https%3A%2F%2Ftestdev.com%2F&domain=testdev.com&bundle=bundle&cw=1&pbt=1&lsw=1`; - let request = server.requests[0]; - expect(request.url).to.be.eq(expectedUrl); + expect(ajaxStub.calledWith(expectedUrl)).to.be.true; - request.respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - expect(callBackSpy.calledOnce).to.be.true; + window.criteo_pubtag = undefined; }); const responses = [ @@ -98,37 +101,31 @@ describe('CriteoId module', function () { responses.forEach(response => describe('test user sync response behavior', function () { const expirationTs = new Date(nowTimestamp + cookiesMaxAge).toString(); - it('should save bidId if it exists', function () { - const result = criteoIdSubmodule.getId(); - result.callback((id) => { - expect(id).to.be.deep.equal(response.bidId ? { criteoId: response.bidId } : undefined); - }); - - let request = server.requests[0]; - request.respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify(response) - ); + beforeEach(function (done) { + const fakeResponse = (url, callback) => { + callback(JSON.stringify(response)); + setTimeout(done, 0); + } + ajaxBuilderStub.callsFake(mockResponse(undefined, fakeResponse)); + criteoIdSubmodule.getId(); + }) + it('should save bidId if it exists', function () { if (response.acwsUrl) { expect(triggerPixelStub.called).to.be.true; expect(setCookieStub.calledWith('cto_bundle')).to.be.false; expect(setLocalStorageStub.calledWith('cto_bundle')).to.be.false; } else if (response.bundle) { - expect(setCookieStub.calledWith('cto_bundle', response.bundle, expirationTs, null, '.com')).to.be.true; - expect(setCookieStub.calledWith('cto_bundle', response.bundle, expirationTs, null, '.testdev.com')).to.be.true; + expect(setCookieStub.calledWith('cto_bundle', response.bundle, expirationTs)).to.be.true; expect(setLocalStorageStub.calledWith('cto_bundle', response.bundle)).to.be.true; expect(triggerPixelStub.called).to.be.false; } if (response.bidId) { - expect(setCookieStub.calledWith('cto_bidid', response.bidId, expirationTs, null, '.com')).to.be.true; - expect(setCookieStub.calledWith('cto_bidid', response.bidId, expirationTs, null, '.testdev.com')).to.be.true; + expect(setCookieStub.calledWith('cto_bidid', response.bidId, expirationTs)).to.be.true; expect(setLocalStorageStub.calledWith('cto_bidid', response.bidId)).to.be.true; } else { - expect(setCookieStub.calledWith('cto_bidid', '', pastDateString, null, '.com')).to.be.true; - expect(setCookieStub.calledWith('cto_bidid', '', pastDateString, null, '.testdev.com')).to.be.true; + expect(setCookieStub.calledWith('cto_bidid', '', pastDateString)).to.be.true; expect(removeFromLocalStorageStub.calledWith('cto_bidid')).to.be.true; } }); @@ -143,23 +140,16 @@ describe('CriteoId module', function () { ]; gdprConsentTestCases.forEach(testCase => it('should call user sync url with the gdprConsent', function () { - let callBackSpy = sinon.spy(); - let result = criteoIdSubmodule.getId(undefined, testCase.consentData); - result.callback(callBackSpy); + const emptyObj = '{}'; + let ajaxStub = sinon.stub().callsFake((url, callback) => callback(emptyObj)); + ajaxBuilderStub.callsFake(mockResponse(undefined, ajaxStub)) + + criteoIdSubmodule.getId(undefined, testCase.consentData); - let request = server.requests[0]; if (testCase.expected) { - expect(request.url).to.have.string(`gdprString=${testCase.expected}`); + expect(ajaxStub.calledWithMatch(`gdprString=${testCase.expected}`)).to.be.true; } else { - expect(request.url).to.not.have.string('gdprString'); + expect(ajaxStub.calledWithMatch('gdprString')).not.to.be.true; } - - request.respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - - expect(callBackSpy.calledOnce).to.be.true; })); }); diff --git a/test/spec/modules/cwireBidAdapter_spec.js b/test/spec/modules/cwireBidAdapter_spec.js deleted file mode 100644 index 3f922fc1471..00000000000 --- a/test/spec/modules/cwireBidAdapter_spec.js +++ /dev/null @@ -1,248 +0,0 @@ -import { expect } from 'chai'; -import * as utils from '../../../src/utils.js'; -import { - spec, - CW_PAGE_VIEW_ID, - ENDPOINT_URL, - RENDERER_URL, -} from '../../../modules/cwireBidAdapter.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; - -// ------------------------------------ -// Bid Request Builder -// ------------------------------------ - -const BID_DEFAULTS = { - request: { - bidder: 'cwire', - auctionId: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', - transactionId: 'txaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', - bidId: 'bid123445', - bidderRequestId: 'brid12345', - code: 'original-div', - }, - params: { - placementId: 123456, - pageId: 777, - adUnitElementId: 'target-div' - }, - sizes: [[300, 250], [1, 1]], -}; - -const BidderRequestBuilder = function BidderRequestBuilder(options) { - const defaults = { - bidderCode: 'cwire', - auctionId: BID_DEFAULTS.request.auctionId, - bidderRequestId: BID_DEFAULTS.request.bidderRequestId, - transactionId: BID_DEFAULTS.request.transactionId, - timeout: 3000, - }; - - const request = { - ...defaults, - ...options - }; - - this.build = () => request; -}; - -const BidRequestBuilder = function BidRequestBuilder(options, deleteKeys) { - const defaults = JSON.parse(JSON.stringify(BID_DEFAULTS)); - - const request = { - ...defaults.request, - ...options - }; - - if (request && utils.isArray(deleteKeys)) { - deleteKeys.forEach((k) => { - delete request[k]; - }) - } - - this.withParams = (options, deleteKeys) => { - request.params = { - ...defaults.params, - ...options - }; - if (request && utils.isArray(deleteKeys)) { - deleteKeys.forEach((k) => { - delete request.params[k]; - }) - } - return this; - }; - - this.build = () => request; -}; - -describe('C-WIRE bid adapter', () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - // START TESTING - describe('C-WIRE - isBidRequestValid', function () { - it('should return true when required params found', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - expect(spec.isBidRequestValid(bid01)).to.equal(true); - }); - - it('should fail if there is no placementId', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - delete bid01.params.placementId - expect(spec.isBidRequestValid(bid01)).to.equal(false); - }); - - it('should fail if invalid placementId type', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - delete bid01.params.placementId; - bid01.placementId = '322'; - expect(spec.isBidRequestValid(bid01)).to.equal(false); - }); - - it('should fail if there is no pageId', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - delete bid01.params.pageId - expect(spec.isBidRequestValid(bid01)).to.equal(false); - }); - - it('should fail if invalid pageId type', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - delete bid01.params.pageId; - bid01.params.pageId = '3320'; - expect(spec.isBidRequestValid(bid01)).to.equal(false); - }); - - it('should use params.adUnitElementId if provided', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - - expect(spec.isBidRequestValid(bid01)).to.equal(true); - expect(bid01.params.adUnitElementId).to.exist; - expect(bid01.params.adUnitElementId).to.equal('target-div'); - }); - - it('should use default adUnitCode if no adUnitElementId provided', function () { - const bid01 = new BidRequestBuilder().withParams({}, ['adUnitElementId']).build(); - expect(spec.isBidRequestValid(bid01)).to.equal(true); - expect(bid01.params.adUnitElementId).to.exist; - expect(bid01.params.adUnitElementId).to.equal('original-div'); - }); - }); - - describe('C-WIRE - buildRequests()', function () { - it('creates a valid request', function () { - // for whatever reason stub for getWindowLocation does not work - // so this was the closest way to test for get params - const params = sandbox.stub(utils, 'getParameterByName'); - params.withArgs('cwgroups').returns('group_1'); - params.withArgs('cwcreative').returns('54321'); - - const bid01 = new BidRequestBuilder({ - mediaTypes: { - banner: { - sizes: [[1, 1]], - } - } - }).withParams().build(); - - const bidderRequest01 = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest01); - - expect(requests.data.slots.length).to.equal(1); - expect(requests.data.cwid).to.be.null; - expect(requests.data.slots[0].sizes[0]).to.equal('1x1'); - expect(requests.data.cwcreative).to.equal('54321'); - expect(requests.data.refgroups[0]).to.equal('group_1'); - }); - }); - - describe('C-WIRE - interpretResponse()', function () { - const serverResponse = { - body: { - bids: [{ - html: '

AD CONTENT

', - currency: 'CHF', - cpm: 43.37, - dimensions: [1, 1], - netRevenue: true, - creativeId: '1337', - requestId: BID_DEFAULTS.request.bidId, - ttl: 3500, - }], - } - }; - - const expectedResponse = [{ - ad: JSON.parse(JSON.stringify(serverResponse.body.bids[0].html)), - bidderCode: BID_DEFAULTS.request.bidder, - cpm: JSON.parse(JSON.stringify(serverResponse.body.bids[0].cpm)), - creativeId: JSON.parse(JSON.stringify(serverResponse.body.bids[0].creativeId)), - currency: JSON.parse(JSON.stringify(serverResponse.body.bids[0].currency)), - height: JSON.parse(JSON.stringify(serverResponse.body.bids[0].dimensions[0])), - width: JSON.parse(JSON.stringify(serverResponse.body.bids[0].dimensions[1])), - netRevenue: JSON.parse(JSON.stringify(serverResponse.body.bids[0].netRevenue)), - requestId: JSON.parse(JSON.stringify(serverResponse.body.bids[0].requestId)), - ttl: JSON.parse(JSON.stringify(serverResponse.body.bids[0].ttl)), - meta: { - advertiserDomains: [], - }, - mediaType: 'banner', - }] - - it('correctly parses response', function () { - const bid01 = new BidRequestBuilder({ - mediaTypes: { - banner: { - sizes: [[1, 1]], - } - } - }).withParams().build(); - - const bidderRequest01 = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest01); - - const response = spec.interpretResponse(serverResponse, requests); - expect(response).to.deep.equal(expectedResponse); - }); - - it('attaches renderer', function () { - const bid01 = new BidRequestBuilder({ - mediaTypes: { - video: { - playerSize: [[640, 480]], - context: 'outstream', - } - } - }).withParams().build(); - const bidderRequest01 = new BidderRequestBuilder().build(); - - const _serverResponse = utils.deepClone(serverResponse); - _serverResponse.body.bids[0].vastXml = ''; - - const _expectedResponse = utils.deepClone(expectedResponse); - _expectedResponse[0].mediaType = 'video'; - _expectedResponse[0].videoScript = JSON.parse(JSON.stringify(_serverResponse.body.bids[0].html)); - _expectedResponse[0].vastXml = JSON.parse(JSON.stringify(_serverResponse.body.bids[0].vastXml)); - delete _expectedResponse[0].ad; - - const requests = spec.buildRequests([bid01], bidderRequest01); - expect(requests.data.slots[0].sizes).to.deep.equal(['640x480']); - - const response = spec.interpretResponse(_serverResponse, requests); - expect(response[0].renderer).to.exist; - expect(response[0].renderer.url).to.equals(RENDERER_URL); - expect(response[0].renderer.loaded).to.equals(false); - - delete response[0].renderer; - expect(response).to.deep.equal(_expectedResponse); - }); - }); -}); diff --git a/test/spec/modules/dailyhuntBidAdapter_spec.js b/test/spec/modules/dailyhuntBidAdapter_spec.js deleted file mode 100644 index f347d6cec5b..00000000000 --- a/test/spec/modules/dailyhuntBidAdapter_spec.js +++ /dev/null @@ -1,404 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/dailyhuntBidAdapter.js'; - -const PROD_PREBID_ENDPOINT_URL = 'https://pbs.dailyhunt.in/openrtb2/auction?partner=dailyhunt'; -const PROD_PREBID_TEST_ENDPOINT_URL = 'https://qa-pbs-van.dailyhunt.in/openrtb2/auction?partner=dailyhunt'; - -const _encodeURIComponent = function (a) { - if (!a) { return } - let b = window.encodeURIComponent(a); - b = b.replace(/'/g, '%27'); - return b; -} - -describe('DailyhuntAdapter', function () { - describe('isBidRequestValid', function () { - let bid = { - 'bidder': 'dailyhunt', - 'params': { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - describe('buildRequests', function() { - let bidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt', - bidfloor: 0.1, - device: { - ip: '47.9.247.217' - }, - site: { - cat: ['1', '2', '3'] - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - let nativeBidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt', - }, - nativeParams: { - title: { - required: true, - len: 80 - }, - image: { - required: true, - sizes: [150, 50] - }, - }, - mediaTypes: { - native: { - title: { - required: true - }, - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - let videoBidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt' - }, - nativeParams: { - video: { - context: 'instream' - } - }, - mediaTypes: { - video: { - context: 'instream' - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - let bidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...bidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - let nativeBidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...nativeBidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - let videoBidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...videoBidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - - it('sends display bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('sends native bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(nativeBidRequests, nativeBidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('sends video bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(videoBidRequests, videoBidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - }); - describe('interpretResponse', function () { - let bidResponses = { - id: 'da32def7-6779-403c-ada7-0b201dbc9744', - seatbid: [ - { - bid: [ - { - id: 'id1', - impid: 'banner-impid', - price: 1.4, - adm: 'adm', - adid: '66658', - crid: 'asd5ddbf014cac993.66466212', - dealid: 'asd5ddbf014cac993.66466212', - w: 300, - h: 250, - nurl: 'winUrl', - ext: { - prebid: { - type: 'banner' - } - } - }, - { - id: '5caccc1f-94a6-4230-a1f9-6186ee65da99', - impid: 'video-impid', - price: 1.4, - nurl: 'winUrl', - adm: 'adm', - adid: '980', - crid: '2394', - w: 300, - h: 250, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - cacheKey: 'cache_key', - vastUrl: 'vastUrl' - } - } - }, - { - id: '74973faf-cce7-4eff-abd0-b59b8e91ca87', - impid: 'native-impid', - price: 50, - nurl: 'winUrl', - adm: '{"native":{"link":{"url":"url","clicktrackers":[]},"assets":[{"id":1,"required":1,"img":{},"video":{},"data":{},"title":{"text":"TITLE"},"link":{}},{"id":1,"required":1,"img":{},"video":{},"data":{"type":2,"value":"Lorem Ipsum Lorem Ipsum Lorem Ipsum."},"title":{},"link":{}},{"id":1,"required":1,"img":{},"video":{},"data":{"type":12,"value":"Install Here"},"title":{},"link":{}},{"id":1,"required":1,"img":{"type":3,"url":"urk","w":990,"h":505},"video":{},"data":{},"title":{},"link":{}}],"imptrackers":[]}}', - adid: '968', - crid: '2370', - w: 300, - h: 250, - ext: { - prebid: { - type: 'native' - }, - bidder: null - } - }, - { - id: '5caccc1f-94a6-4230-a1f9-6186ee65da99', - impid: 'video-outstream-impid', - price: 1.4, - nurl: 'winUrl', - adm: 'adm', - adid: '980', - crid: '2394', - w: 300, - h: 250, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - cacheKey: 'cache_key', - vastUrl: 'vastUrl' - } - } - }, - ], - seat: 'dailyhunt' - } - ], - ext: { - responsetimemillis: { - dailyhunt: 119 - } - } - }; - - it('should get correct bid response', function () { - let expectedResponse = [ - { - requestId: '1', - cpm: 1.4, - creativeId: 'asd5ddbf014cac993.66466212', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - ad: 'adm', - mediaType: 'banner', - winUrl: 'winUrl', - adomain: 'dailyhunt' - }, - { - requestId: '2', - cpm: 1.4, - creativeId: '2394', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'video', - winUrl: 'winUrl', - adomain: 'dailyhunt', - videoCacheKey: 'cache_key', - vastUrl: 'vastUrl', - }, - { - requestId: '3', - cpm: 1.4, - creativeId: '2370', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'native', - winUrl: 'winUrl', - adomain: 'dailyhunt', - native: { - clickUrl: 'https%3A%2F%2Fmontu1996.github.io%2F', - clickTrackers: [], - impressionTrackers: [], - javascriptTrackers: [], - title: 'TITLE', - body: 'Lorem Ipsum Lorem Ipsum Lorem Ipsum.', - cta: 'Install Here', - image: { - url: 'url', - height: 505, - width: 990 - } - } - }, - { - requestId: '4', - cpm: 1.4, - creativeId: '2394', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'video', - winUrl: 'winUrl', - adomain: 'dailyhunt', - vastXml: 'adm', - }, - ]; - let bidderRequest = { - bids: [ - { - bidId: 'banner-impid', - adUnitCode: 'code1', - requestId: '1' - }, - { - bidId: 'video-impid', - adUnitCode: 'code2', - requestId: '2', - mediaTypes: { - video: { - context: 'instream' - } - } - }, - { - bidId: 'native-impid', - adUnitCode: 'code3', - requestId: '3' - }, - { - bidId: 'video-outstream-impid', - adUnitCode: 'code4', - requestId: '4', - mediaTypes: { - video: { - context: 'outstream' - } - } - }, - ] - } - let result = spec.interpretResponse({ body: bidResponses }, bidderRequest); - result.forEach((r, i) => { - expect(Object.keys(r)).to.have.members(Object.keys(expectedResponse[i])); - }); - }); - }) - describe('onBidWon', function () { - it('should hit win url when bid won', function () { - let bid = { - requestId: '1', - cpm: 1.4, - creativeId: 'asd5ddbf014cac993.66466212', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - ad: 'adm', - mediaType: 'banner', - winUrl: 'winUrl' - }; - expect(spec.onBidWon(bid)).to.equal(undefined); - }); - }) -}) diff --git a/test/spec/modules/datablocksBidAdapter_spec.js b/test/spec/modules/datablocksBidAdapter_spec.js index ff7b0aad48c..0ec12905430 100644 --- a/test/spec/modules/datablocksBidAdapter_spec.js +++ b/test/spec/modules/datablocksBidAdapter_spec.js @@ -96,8 +96,8 @@ const bidderRequest = { refererInfo: { numIframes: 0, reachedTop: true, - referer: 'https://7560.v5demo.datablocks.net/test', - stack: ['https://7560.v5demo.datablocks.net/test'] + referer: 'https://v5demo.datablocks.net/test', + stack: ['https://v5demo.datablocks.net/test'] }, start: Date.now(), timeout: 10000 @@ -452,7 +452,7 @@ describe('DatablocksAdapter', function() { it('Returns valid URL', function() { expect(request.url).to.exist; - expect(request.url).to.equal('https://v5demo.datablocks.net/openrtb/?sid=7560'); + expect(request.url).to.equal('https://7560.v5demo.datablocks.net/openrtb/?sid=7560'); }); it('Creates an array of request objects', function() { diff --git a/test/spec/modules/dchain_spec.js b/test/spec/modules/dchain_spec.js deleted file mode 100644 index 45061c539c1..00000000000 --- a/test/spec/modules/dchain_spec.js +++ /dev/null @@ -1,329 +0,0 @@ -import { checkDchainSyntax, addBidResponseHook } from '../../../modules/dchain.js'; -import { config } from '../../../src/config.js'; -import { expect } from 'chai'; - -describe('dchain module', function () { - const STRICT = 'strict'; - const RELAX = 'relaxed'; - const OFF = 'off'; - - describe('checkDchainSyntax', function () { - let bid; - - beforeEach(function () { - bid = { - meta: { - dchain: { - 'ver': '1.0', - 'complete': 0, - 'ext': {}, - 'nodes': [{ - 'asi': 'domain.com', - 'bsid': '12345', - }, { - 'name': 'bidder', - 'domain': 'bidder.com', - 'ext': {} - }] - } - } - }; - }); - - it('Returns false if complete param is not 0 or 1', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.complete = 0; // integer - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.complete = 1; // integer - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.complete = '1'; // string - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.complete = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.complete = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.complete; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.complete = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.complete = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if ver param is not a String', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.ver = 1; // integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ver = '1'; // string - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.ver = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ver = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.ver; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ver = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ver = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if ext param is not an Object', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.ext = 1; // integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ext = '1'; // string - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ext = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ext = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.true; - delete dchainConfig.ext; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.ext = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.ext = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes param is not an Array', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes = 1; // integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes = '1'; // string - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if unknown field is used in main dchain', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.test = '1'; // String - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].asi is not a String', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].asi = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].asi = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].asi = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes[0].asi; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].asi = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].asi = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].bsid is not a String', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].bsid = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].bsid = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].bsid = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes[0].bsid; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].bsid = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].bsid = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].rid is not a String', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].rid = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].rid = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].rid = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes[0].rid; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].rid = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].rid = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].name is not a String', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].name = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].name = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].name = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes[0].name; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].name = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].name = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].domain is not a String', function () { - let dchainConfig = bid.meta.dchain; - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].domain = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].domain = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].domain = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.false; - delete dchainConfig.nodes[0].domain; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].domain = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].domain = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if nodes[].ext is not an Object', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.nodes[0].ext = '1'; // String - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].ext = 1; // Integer - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].ext = 1.1; // float - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].ext = {}; // object - expect(checkDchainSyntax(bid, STRICT)).to.true; - delete dchainConfig.nodes[0].ext; // undefined - expect(checkDchainSyntax(bid, STRICT)).to.true; - dchainConfig.nodes[0].ext = true; // boolean - expect(checkDchainSyntax(bid, STRICT)).to.false; - dchainConfig.nodes[0].ext = []; // array - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Returns false if unknown field is used in nodes[]', function () { - let dchainConfig = bid.meta.dchain; - dchainConfig.nodes[0].test = '1'; // String - expect(checkDchainSyntax(bid, STRICT)).to.false; - }); - - it('Relaxed mode: returns true even for invalid config', function () { - bid.meta.dchain = { - ver: 1.1, - complete: '0', - nodes: [{ - name: 'asdf', - domain: ['domain.com'] - }] - }; - - expect(checkDchainSyntax(bid, RELAX)).to.true; - }); - }); - - describe('addBidResponseHook', function () { - let bid; - let adUnitCode = 'adUnit1'; - - beforeEach(function () { - bid = { - bidderCode: 'bidderA', - meta: { - dchain: { - 'ver': '1.0', - 'complete': 0, - 'ext': {}, - 'nodes': [{ - 'asi': 'domain.com', - 'bsid': '12345', - }, { - 'name': 'bidder', - 'domain': 'bidder.com', - 'ext': {} - }] - }, - networkName: 'myNetworkName', - networkId: 8475 - } - }; - }); - - afterEach(function () { - config.resetConfig(); - }); - - it('good strict config should append a node object to existing bid.meta.dchain object', function () { - function testCallback(adUnitCode, bid) { - expect(bid.meta.dchain).to.exist; - expect(bid.meta.dchain.nodes[1]).to.exist.and.to.deep.equal({ - 'name': 'bidder', - 'domain': 'bidder.com', - 'ext': {} - }); - expect(bid.meta.dchain.nodes[2]).to.exist.and.to.deep.equal({ asi: 'bidderA' }); - } - - config.setConfig({ dchain: { validation: STRICT } }); - addBidResponseHook(testCallback, adUnitCode, bid); - }); - - it('bad strict config should delete the bid.meta.dchain object', function () { - function testCallback(adUnitCode, bid) { - expect(bid.meta.dchain).to.not.exist; - } - - config.setConfig({ dchain: { validation: STRICT } }); - bid.meta.dchain.complete = 3; - addBidResponseHook(testCallback, adUnitCode, bid); - }); - - it('relaxed config should allow bid.meta.dchain to proceed, even with bad values', function () { - function testCallback(adUnitCode, bid) { - expect(bid.meta.dchain).to.exist; - expect(bid.meta.dchain.complete).to.exist.and.to.equal(3); - expect(bid.meta.dchain.nodes[2]).to.exist.and.to.deep.equal({ asi: 'bidderA' }); - } - - config.setConfig({ dchain: { validation: RELAX } }); - bid.meta.dchain.complete = 3; - addBidResponseHook(testCallback, adUnitCode, bid); - }); - - it('off config should allow the bid.meta.dchain to proceed', function () { - // check for missing nodes - function testCallback(adUnitCode, bid) { - expect(bid.meta.dchain).to.exist; - expect(bid.meta.dchain.complete).to.exist.and.to.equal(0); - expect(bid.meta.dchain.nodes).to.exist.and.to.deep.equal({ test: 123 }); - } - - config.setConfig({ dchain: { validation: OFF } }); - bid.meta.dchain.nodes = { test: 123 }; - addBidResponseHook(testCallback, adUnitCode, bid); - }); - - it('no bidder dchain', function () { - function testCallback(adUnitCode, bid) { - expect(bid.meta.dchain).to.exist; - expect(bid.meta.dchain.ver).to.exist.and.to.equal('1.0'); - expect(bid.meta.dchain.complete).to.exist.and.to.equal(0); - expect(bid.meta.dchain.nodes).to.exist.and.to.deep.equal([{ name: 'myNetworkName', bsid: '8475' }, { name: 'bidderA' }]); - } - - delete bid.meta.dchain; - config.setConfig({ dchain: { validation: RELAX } }); - addBidResponseHook(testCallback, adUnitCode, bid); - }); - }); -}); diff --git a/test/spec/modules/deepintentBidAdapter_spec.js b/test/spec/modules/deepintentBidAdapter_spec.js index d2a351b4089..fcf7056fb3f 100644 --- a/test/spec/modules/deepintentBidAdapter_spec.js +++ b/test/spec/modules/deepintentBidAdapter_spec.js @@ -3,8 +3,8 @@ import {spec} from 'modules/deepintentBidAdapter.js'; import * as utils from '../../../src/utils.js'; describe('Deepintent adapter', function () { - let request, videoBidRequests; - let bannerResponse, videoBidResponse, invalidResponse; + let request; + let bannerResponse; beforeEach(function () { request = [ @@ -32,38 +32,6 @@ describe('Deepintent adapter', function () { } } ]; - videoBidRequests = - [ - { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - bidder: 'deepintent', - bidId: '22bddb28db77d', - params: { - tagId: '100013', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - testwrongparam: 3, - testwrongparam1: 'wrong', - minduration: 5, - maxduration: 30, - startdelay: 5, - playbackmethod: [1, 3], - api: [1, 2], - protocols: [2, 3], - battr: [13, 14], - minbitrate: 10, - maxbitrate: 10 - } - } - } - ]; bannerResponse = { 'body': { 'id': '303e1fae-9677-41e2-9a92-15a23445363f', @@ -85,47 +53,7 @@ describe('Deepintent adapter', function () { }], 'bidid': '0b08b09f-aaa1-4c14-b1c8-7debb1a7c1cd' } - }; - invalidResponse = { - 'body': { - 'id': '303e1fae-9677-41e2-9a92-15a23445363f', - 'seatbid': [{ - 'bid': [{ - 'id': '11447bb1-a266-470d-b0d7-8810f5b1b75f', - 'impid': 'a7e92b9b-d9db-4de8-9c3f-f90737335445', - 'price': 0.6, - 'adid': '10001', - 'adm': 'invalid response', - 'adomain': ['deepintent.com'], - 'cid': '103389', - 'crid': '13665', - 'w': 300, - 'h': 250, - 'dealId': 'dee_12312stdszzsx' - }], - 'seat': '10000' - }], - 'bidid': '0b08b09f-aaa1-4c14-b1c8-7debb1a7c1cd' - } - }; - videoBidResponse = { - 'body': { - 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - 'seatbid': [{ - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '22bddb28db77d', - 'price': 1.3, - 'adm': 'Acudeo CompatibleVAST 2.0 Instream Test 1VAST 2.0 Instream Test 1https://dsptracker.com/{PSPM}00:00:04https://www.deepintent.com', - 'h': 250, - 'w': 300, - 'ext': { - 'deal_channel': 6 - } - }] - }] - } - }; + } }); describe('validations', function () { @@ -160,45 +88,6 @@ describe('Deepintent adapter', function () { isValid = spec.isBidRequestValid(bid); expect(isValid).to.equals(false); }); - it('should check for context if video is present', function() { - let bid = { - bidder: 'deepintent', - params: { - tagId: '12345', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - } - }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - }, - isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - it('should error out if context is not present and is Video', function() { - let bid = { - bidder: 'deepintent', - params: { - tagId: '12345', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - } - }, - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - }, - isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }) }); describe('request check', function () { it('unmutaable bid request check', function () { @@ -290,28 +179,6 @@ describe('Deepintent adapter', function () { expect(data2.regs).to.equal(undefined); expect(data2.user.ext).to.equal(undefined); }); - it('bid request check: Video params check ', function() { - let bRequest = spec.buildRequests(videoBidRequests); - let data = JSON.parse(bRequest.data); - expect(data.imp[0].video).to.be.a('object'); - expect(data.imp[0].video.minduration).to.be.a('number'); - expect(data.imp[0].video.maxduration).to.be.a('number'); - expect(data.imp[0].video.startdelay).to.be.a('number'); - expect(data.imp[0].video.playbackmethod).to.be.an('array'); - expect(data.imp[0].video.api).to.be.an('array'); - expect(data.imp[0].video.protocols).to.be.an('array'); - expect(data.imp[0].video.battr).to.be.an('array'); - expect(data.imp[0].video.minbitrate).to.be.a('number'); - expect(data.imp[0].video.maxbitrate).to.be.a('number'); - expect(data.imp[0].video.w).to.be.a('number'); - }); - it('bid request param check : invalid video params', function() { - let bRequest = spec.buildRequests(videoBidRequests); - let data = JSON.parse(bRequest.data); - expect(data.imp[0].video).to.be.a('object'); - expect(data.imp[0].video.testwrongparam).to.equal(undefined); - expect(data.imp[0].video.testwrongparam1).to.equal(undefined); - }); }); describe('user sync check', function () { it('user sync url check', function () { @@ -335,27 +202,10 @@ describe('Deepintent adapter', function () { expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); expect(bResponse[0].currency).to.equal('USD'); expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('banner'); expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['deepintent.com']); expect(bResponse[0].ttl).to.equal(300); expect(bResponse[0].creativeId).to.equal(bannerResponse.body.seatbid[0].bid[0].crid); expect(bResponse[0].dealId).to.equal(bannerResponse.body.seatbid[0].bid[0].dealId); }); - it('bid response check: valid video bid response', function() { - let request = spec.buildRequests(videoBidRequests); - let response = spec.interpretResponse(videoBidResponse, request); - expect(response[0].mediaType).to.equal('video'); - expect(response[0].vastXml).to.not.equal(undefined); - }); - it('invalid bid response check ', function() { - let bRequest = spec.buildRequests(request); - let response = spec.interpretResponse(invalidResponse, bRequest); - expect(response[0].mediaType).to.equal(undefined); - }); - it('invalid bid response check ', function() { - let bRequest = spec.buildRequests(videoBidRequests); - let response = spec.interpretResponse(invalidResponse, bRequest); - expect(response[0].mediaType).to.equal(undefined); - }); }) }); diff --git a/test/spec/modules/deltaprojectsBidAdapter_spec.js b/test/spec/modules/deltaprojectsBidAdapter_spec.js deleted file mode 100644 index 382415eab62..00000000000 --- a/test/spec/modules/deltaprojectsBidAdapter_spec.js +++ /dev/null @@ -1,399 +0,0 @@ -import { expect } from 'chai'; -import { - BIDDER_CODE, - BIDDER_ENDPOINT_URL, - spec, USERSYNC_URL, - getBidFloor -} from 'modules/deltaprojectsBidAdapter.js'; - -const BID_REQ_REFER = 'http://example.com/page?param=val'; - -describe('deltaprojectsBidAdapter', function() { - describe('isBidRequestValid', function () { - function makeBid() { - return { - bidder: BIDDER_CODE, - params: { - publisherId: '12345' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - } - - it('should return true when bidder set correctly', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when bid request is null', function () { - expect(spec.isBidRequestValid(undefined)).to.equal(false); - }); - - it('should return false when bidder not set correctly', function () { - let bid = makeBid(); - delete bid.bidder; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisher id is not set', function () { - let bid = makeBid(); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const BIDREQ = { - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com', - }, - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - } - const bidRequests = [BIDREQ]; - const bannerRequest = spec.buildRequests(bidRequests, {refererInfo: { referer: BID_REQ_REFER }})[0]; - const bannerRequestBody = bannerRequest.data; - - it('send bid request with test tag if it is set in the param', function () { - const TEST_TAG = 1; - const bidRequest = Object.assign({}, BIDREQ, { - params: { ...BIDREQ.params, test: TEST_TAG }, - }); - const bidderRequest = { refererInfo: { referer: BID_REQ_REFER } }; - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - expect(request.data.test).to.equal(TEST_TAG); - }); - - it('send bid request with correct timeout', function () { - const TMAX = 10; - const bidderRequest = { refererInfo: { referer: BID_REQ_REFER }, timeout: TMAX }; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.tmax).to.equal(TMAX); - }); - - it('send bid request to the correct endpoint URL', function () { - expect(bannerRequest.url).to.equal(BIDDER_ENDPOINT_URL); - }); - - it('sends bid request to our endpoint via POST', function () { - expect(bannerRequest.method).to.equal('POST'); - }); - - it('sends screen dimensions', function () { - expect(bannerRequestBody.device.w).to.equal(screen.width); - expect(bannerRequestBody.device.h).to.equal(screen.height); - }); - - it('includes the ad size in the bid request', function () { - expect(bannerRequestBody.imp[0].banner.format[0].w).to.equal(BIDREQ.sizes[0][0]); - expect(bannerRequestBody.imp[0].banner.format[0].h).to.equal(BIDREQ.sizes[0][1]); - }); - - it('sets domain and href correctly', function () { - expect(bannerRequestBody.site.domain).to.equal(BIDREQ.params.siteId); - expect(bannerRequestBody.site.page).to.equal(BID_REQ_REFER); - }); - - const gdprBidRequests = [{ - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com' - }, - sizes: [ - [300, 250] - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475' - }]; - const consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - - const GDPR_REQ_REFERER = 'http://localhost:9876/' - function getGdprRequestBody(gdprApplies, consentString) { - const gdprRequest = spec.buildRequests(gdprBidRequests, { - gdprConsent: { - gdprApplies: gdprApplies, - consentString: consentString, - }, - refererInfo: { - referer: GDPR_REQ_REFERER, - }, - })[0]; - return gdprRequest.data; - } - - it('should handle gdpr applies being present and true', function() { - const gdprRequestBody = getGdprRequestBody(true, consentString); - expect(gdprRequestBody.regs.ext.gdpr).to.equal(1); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr applies being present and false', function() { - const gdprRequestBody = getGdprRequestBody(false, consentString); - expect(gdprRequestBody.regs.ext.gdpr).to.equal(0); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr applies being undefined', function() { - const gdprRequestBody = getGdprRequestBody(undefined, consentString); - expect(gdprRequestBody.regs).to.deep.equal({ext: {}}); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr consent being undefined', function() { - const gdprRequest = spec.buildRequests(gdprBidRequests, {refererInfo: { referer: GDPR_REQ_REFERER }})[0]; - const gdprRequestBody = gdprRequest.data; - expect(gdprRequestBody.regs).to.deep.equal({ ext: {} }); - expect(gdprRequestBody.user).to.deep.equal({ ext: {} }); - }) - }); - - describe('interpretResponse', function () { - const bidRequests = [ - { - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com', - currency: 'USD', - }, - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }, - ]; - const request = spec.buildRequests(bidRequests, {refererInfo: { referer: BID_REQ_REFER }})[0]; - function makeResponse() { - return { - body: { - id: '5e5c23a5ba71e78', - seatbid: [ - { - bid: [ - { - id: '6vmb3isptf', - crid: 'deltaprojectscreative', - impid: '322add653672f68', - price: 1.22, - adm: '', - attr: [5], - h: 90, - nurl: 'http://nurl', - w: 728, - } - ], - seat: 'MOCK' - } - ], - bidid: '5e5c23a5ba71e78', - cur: 'USD' - } - }; - } - const expectedBid = { - requestId: '322add653672f68', - cpm: 1.22, - width: 728, - height: 90, - creativeId: 'deltaprojectscreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60, - ad: '
' - }; - - it('should get incorrect bid response if response body is missing', function () { - let response = makeResponse(); - delete response.body; - let result = spec.interpretResponse(response, request); - expect(result.length).to.equal(0); - }); - - it('should get incorrect bid response if id or seat id of response body is missing', function () { - let response1 = makeResponse(); - delete response1.body.id; - let result1 = spec.interpretResponse(response1, request); - expect(result1.length).to.equal(0); - - let response2 = makeResponse(); - delete response2.body.seatbid; - let result2 = spec.interpretResponse(response2, request); - expect(result2.length).to.equal(0); - }); - - it('should get the correct bid response', function () { - let result = spec.interpretResponse(makeResponse(), request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - - it('should handle a missing crid', function () { - let noCridResponse = makeResponse(); - delete noCridResponse.body.seatbid[0].bid[0].crid; - const fallbackCrid = noCridResponse.body.seatbid[0].bid[0].id; - let noCridResult = Object.assign({}, expectedBid, {'creativeId': fallbackCrid}); - let result = spec.interpretResponse(noCridResponse, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(noCridResult); - }); - - it('should handle a missing nurl', function () { - let noNurlResponse = makeResponse(); - delete noNurlResponse.body.seatbid[0].bid[0].nurl; - let noNurlResult = Object.assign({}, expectedBid); - noNurlResult.ad = ''; - let result = spec.interpretResponse(noNurlResponse, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(noNurlResult); - }); - - it('handles empty bid response', function () { - let response = { - body: { - id: '5e5c23a5ba71e78', - seatbid: [] - } - }; - let result = spec.interpretResponse(response, request); - expect(result.length).to.equal(0); - }); - - it('should keep custom properties', () => { - const customProperties = {test: 'a test message', param: {testParam: 1}}; - const expectedResult = Object.assign({}, expectedBid, {[spec.code]: customProperties}); - const response = makeResponse(); - response.body.seatbid[0].bid[0].ext = customProperties; - const result = spec.interpretResponse(response, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedResult); - }); - }); - - describe('onBidWon', function () { - const OPEN_RTB_RESP = { - body: { - id: 'abc', - seatbid: [ - { - bid: [ - { - 'id': 'abc*123*456', - 'impid': 'xxxxxxx', - 'price': 46.657196, - 'adm': '', - 'adid': '56380110', - 'cid': '44724710', - 'crid': '443801010', - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'targeting': { - 'hb_bidder': 'luponmedia', - 'hb_pb': '0.40', - 'hb_size': '300x250' - }, - 'type': 'banner' - } - } - } - ], - 'seat': 'luponmedia' - } - ], - 'cur': 'USD', - 'ext': { - 'responsetimemillis': { - 'luponmedia': 233 - }, - 'tmaxrequest': 1500, - 'usersyncs': { - 'status': 'ok', - 'bidder_status': [] - } - } - }; - - let expectedResponse = [ - { - 'requestId': '2a122246ef72ea', - 'cpm': '0.43', - 'width': 300, - 'height': 250, - 'creativeId': '443801010', - 'currency': 'USD', - 'dealId': '23425', - 'netRevenue': false, - 'ttl': 300, - 'referrer': '', - 'ad': ' ' - } - ]; - - let bidderRequest = { - 'data': '{"site":{"page":"https://novi.ba/clanak/176067/fast-car-beginner-s-guide-to-tuning-turbo-engines"}}' - }; - - let result = spec.interpretResponse({ body: response }, bidderRequest); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', function () { - let noBidResponse = []; - - let noBidBidderRequest = { - 'data': '{"site":{"page":""}}' - } - let noBidResult = spec.interpretResponse({ body: noBidResponse }, noBidBidderRequest); - expect(noBidResult.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse1 = { - 'body': { - 'ext': { - 'responsetimemillis': { - 'luponmedia': 233 - }, - 'tmaxrequest': 1500, - 'usersyncs': { - 'status': 'ok', - 'bidder_status': [ - { - 'bidder': 'luponmedia', - 'no_cookie': true, - 'usersync': { - 'url': 'https://adxpremium.services/api/usersync', - 'type': 'redirect' - } - }, - { - 'bidder': 'luponmedia', - 'no_cookie': true, - 'usersync': { - 'url': 'https://adxpremium.services/api/iframeusersync', - 'type': 'iframe' - } - } - ] - } - } - } - }; - - const bidResponse2 = { - 'body': { - 'ext': { - 'responsetimemillis': { - 'luponmedia': 233 - }, - 'tmaxrequest': 1500, - 'usersyncs': { - 'status': 'no_cookie', - 'bidder_status': [] - } - } - } - }; - - it('should use a sync url from first response (pixel and iframe)', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [bidResponse1, bidResponse2]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://adxpremium.services/api/usersync' - }, - { - type: 'iframe', - url: 'https://adxpremium.services/api/iframeusersync' - } - ]); - }); - - it('handle empty response (e.g. timeout)', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('returns empty syncs when not pixel enabled and not iframe enabled', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: false }, [bidResponse1]); - expect(syncs).to.deep.equal([]); - }); - - it('returns pixel syncs when pixel enabled and not iframe enabled', function() { - resetUserSync(); - - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, [bidResponse1]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://adxpremium.services/api/usersync' - } - ]); - }); - - it('returns iframe syncs when not pixel enabled and iframe enabled', function() { - resetUserSync(); - - const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: true }, [bidResponse1]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://adxpremium.services/api/iframeusersync' - } - ]); - }); - }); - - describe('hasValidSupplyChainParams', function () { - it('returns true if schain is valid', function () { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'novi.ba', - 'sid': '199424', - 'hp': 1 - } - ] - }; - - const checkSchain = hasValidSupplyChainParams(schain); - expect(checkSchain).to.equal(true); - }); - - it('returns false if schain is invalid', function () { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'invalid': 'novi.ba' - } - ] - }; - - const checkSchain = hasValidSupplyChainParams(schain); - expect(checkSchain).to.equal(false); - }); - }); - - describe('onBidWon', function () { - const bidWonEvent = { - 'bidderCode': 'luponmedia', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '105bbf8c54453ff', - 'requestId': '934b8752185955', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.364, - 'creativeId': '443801010', - 'currency': 'USD', - 'netRevenue': false, - 'ttl': 300, - 'referrer': '', - 'ad': '', - 'auctionId': '926a8ea3-3dd4-4bf2-95ab-c85c2ce7e99b', - 'responseTimestamp': 1598527728026, - 'requestTimestamp': 1598527727629, - 'bidder': 'luponmedia', - 'adUnitCode': 'div-gpt-ad-1533155193780-5', - 'timeToRespond': 397, - 'size': '300x250', - 'status': 'rendered' - }; - - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'sendWinningsToServer') - }) - - afterEach(() => { - ajaxStub.restore() - }) - - it('calls luponmedia\'s callback endpoint', () => { - const result = spec.onBidWon(bidWonEvent); - expect(result).to.equal(undefined); - expect(ajaxStub.calledOnce).to.equal(true); - expect(ajaxStub.firstCall.args[0]).to.deep.equal(JSON.stringify(bidWonEvent)); - }); - }); -}); diff --git a/test/spec/modules/mediakeysBidAdapter_spec.js b/test/spec/modules/mediakeysBidAdapter_spec.js index 602524e6eb3..040c0abd566 100644 --- a/test/spec/modules/mediakeysBidAdapter_spec.js +++ b/test/spec/modules/mediakeysBidAdapter_spec.js @@ -1,11 +1,9 @@ import { expect } from 'chai'; -import find from 'core-js-pure/features/array/find.js'; import { spec } from 'modules/mediakeysBidAdapter.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; import * as utils from 'src/utils.js'; import { config } from 'src/config.js'; import { BANNER, NATIVE, VIDEO } from '../../../src/mediaTypes.js'; -import { OUTSTREAM } from '../../../src/video.js'; describe('mediakeysBidAdapter', function () { const adapter = newBidder(spec); @@ -41,100 +39,39 @@ describe('mediakeysBidAdapter', function () { } }; - const bidNative = { - bidder: 'mediakeys', - params: {}, - mediaTypes: { - native: { - body: { - required: true - }, - title: { - required: true, - len: 800 - }, - sponsoredBy: { - required: true - }, - body2: { - required: true - }, - image: { - required: true, - sizes: [[300, 250], [300, 600], [100, 150]], - }, - icon: { - required: true, - sizes: [50, 50], - }, - }, - }, - nativeParams: { - body: { - required: true - }, - title: { - required: true, - len: 800 - }, - sponsoredBy: { - required: true - }, - body2: { - required: true - }, - image: { - required: true, - sizes: [[300, 250], [300, 600], [100, 150]], - }, - icon: { - required: true, - sizes: [50, 50], - }, - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', - bidId: '299320f4de980d', - bidderRequestId: '1c1b642f803242', - auctionId: '84212956-c377-40e8-b000-9885a06dc692', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2Imp: { - ext: { data: { something: 'test' } } - } - }; - - const bidVideo = { - bidder: 'mediakeys', - params: {}, - mediaTypes: { - video: { - context: OUTSTREAM, - playerSize: [480, 320] - } - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', - bidId: '299320f4de980d', - bidderRequestId: '1c1b642f803242', - auctionId: '84212956-c377-40e8-b000-9885a06dc692', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2Imp: { - ext: { data: { something: 'test' } } - } - }; - const bidderRequest = { bidderCode: 'mediakeys', auctionId: '84212956-c377-40e8-b000-9885a06dc692', bidderRequestId: '1c1b642f803242', bids: [ - bid + { + bidder: 'mediakeys', + params: {}, + mediaTypes: { + banner: { + sizes: [ + [300, 250], + [300, 600], + ], + }, + }, + adUnitCode: 'div-gpt-ad-1460505748561-0', + transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', + sizes: [ + [300, 250], + [300, 600], + ], + bidId: '299320f4de980d', + bidderRequestId: '1c1b642f803242', + auctionId: '84212956-c377-40e8-b000-9885a06dc692', + src: 'client', + bidRequestsCount: 1, + bidderRequestsCount: 1, + bidderWinsCount: 0, + ortb2Imp: { + ext: { data: { something: 'test' } } + } + }, ], auctionStart: 1620973766319, timeout: 1000, @@ -179,25 +116,23 @@ describe('mediakeysBidAdapter', function () { it('should create imp for supported mediaType only', function() { const bidRequests = [utils.deepClone(bid)]; const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; bidRequests[0].mediaTypes.video = { playerSize: [300, 250], - context: OUTSTREAM + context: 'outstream' } - bidRequests[0].mediaTypes.native = bidNative.mediaTypes.native; - bidRequests[0].nativeParams = bidNative.mediaTypes.native; - - bidderRequestCopy.bids = bidRequests[0]; + bidRequests[0].mediaTypes.native = { + type: 'image' + } const request = spec.buildRequests(bidRequests, bidderRequestCopy); const data = request.data; expect(data.imp.length).to.equal(1); expect(data.imp[0].banner).to.exist; - expect(data.imp[0].video).to.exist; - expect(data.imp[0].native).to.exist; + expect(data.imp[0].video).to.not.exist; + expect(data.imp[0].native).to.not.exist; }); it('should get expected properties with default values (no params set)', function () { @@ -226,205 +161,6 @@ describe('mediakeysBidAdapter', function () { expect(data.imp[0].ext.data.something).to.equal('test'); }); - describe('native imp', function() { - it('should get a native object in request', function() { - const bidRequests = [utils.deepClone(bidNative)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].native).to.exist; - expect(data.imp[0].native.request.ver).to.equal('1.2'); - expect(data.imp[0].native.request.context).to.equal(1); - expect(data.imp[0].native.request.plcmttype).to.equal(1); - expect(data.imp[0].native.request.assets.length).to.equal(6); - // find the asset body - const bodyAsset = find(data.imp[0].native.request.assets, asset => asset.id === 6); - expect(bodyAsset.data.type).to.equal(2); - }); - - it('should get a native object in request with properties filled with params values', function() { - const bidRequests = [utils.deepClone(bidNative)]; - bidRequests[0].params = { - native: { - context: 3, - plcmttype: 3, - } - } - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].native).to.exist; - expect(data.imp[0].native.request.ver).to.equal('1.2'); - expect(data.imp[0].native.request.context).to.equal(3); - expect(data.imp[0].native.request.plcmttype).to.equal(3); - expect(data.imp[0].native.request.assets.length).to.equal(6); - }); - - it('should get a native object in request when native type ,image" has been set', function() { - const bidRequests = [utils.deepClone(bidNative)]; - bidRequests[0].mediaTypes.native = { type: 'image' }; - bidRequests[0].nativeParams = { - image: { required: true }, - title: { required: true }, - sponsoredBy: { required: true }, - clickUrl: { required: true }, // [1] Will be ignored as it is used in response validation only - body: { required: false }, - icon: { required: false }, - }; - - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].native).to.exist; - expect(data.imp[0].native.request.ver).to.equal('1.2'); - expect(data.imp[0].native.request.context).to.equal(1); - expect(data.imp[0].native.request.plcmttype).to.equal(1); - expect(data.imp[0].native.request.assets.length).to.equal(5); // [1] clickUrl ignored - }); - - it('should log errors and ignore misformated assets', function() { - const bidRequests = [utils.deepClone(bidNative)]; - delete bidRequests[0].nativeParams.title.len; - bidRequests[0].nativeParams.unregistred = {required: true}; - - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - utilsMock.expects('logWarn').twice(); - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].native).to.exist; - expect(data.imp[0].native.request.assets.length).to.equal(5); - }); - }); - - describe('video imp', function() { - it('should get a video object in request', function() { - const bidRequests = [utils.deepClone(bidVideo)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].banner).to.not.exist; - expect(data.imp[0].video).to.exist; - expect(data.imp[0].video.w).to.equal(480); - expect(data.imp[0].video.h).to.equal(320); - }); - - it('should ignore and warn misformated ORTB video properties', function() { - const bidRequests = [utils.deepClone(bidVideo)]; - bidRequests[0].mediaTypes.video.unknown = 'foo'; - bidRequests[0].mediaTypes.video.placement = 10; - bidRequests[0].mediaTypes.video.skipmin = 5; - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].banner).to.not.exist; - expect(data.imp[0].video).to.exist; - expect(data.imp[0].video.w).to.equal(480); - expect(data.imp[0].video.h).to.equal(320); - expect(data.imp[0].video.skipmin).to.equal(5); - expect(data.imp[0].video.placement).to.not.exist; - expect(data.imp[0].video.unknown).to.not.exist; - }); - - it('should merge adUnit mediaTypes level and bidder level params properties ', function() { - const bidRequests = [utils.deepClone(bidVideo)]; - bidRequests[0].mediaTypes.video.placement = 1; - bidRequests[0].mediaTypes.video.mimes = ['video/mpeg4']; - bidRequests[0].mediaTypes.video.protocols = [1]; - bidRequests[0].mediaTypes.video.minduration = 10; - bidRequests[0].mediaTypes.video.maxduration = 45; - bidRequests[0].mediaTypes.video.skipmin = 5; - bidRequests[0].mediaTypes.video.sequence = 3; - bidRequests[0].mediaTypes.video.linearity = 1; - bidRequests[0].mediaTypes.video.battr = [12]; - bidRequests[0].mediaTypes.video.maxextended = 10; - bidRequests[0].mediaTypes.video.minbitrate = 720; - bidRequests[0].mediaTypes.video.maxbitrate = 720; - bidRequests[0].mediaTypes.video.boxingallowed = 1; - bidRequests[0].mediaTypes.video.playbackmethod = [1]; - bidRequests[0].mediaTypes.video.playbackend = 2; - bidRequests[0].mediaTypes.video.delivery = 2; - bidRequests[0].mediaTypes.video.pos = 0; - bidRequests[0].mediaTypes.video.companionad = [{ w: 360, h: 80 }] - bidRequests[0].mediaTypes.video.api = [1]; - bidRequests[0].mediaTypes.video.companiontype = [1]; - - // bidder level - bidRequests[0].params.video = { - pos: 2, // override - skip: 1, - skipafter: 10, - startdelay: 3 - }; - - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - utilsMock.expects('logWarn').never(); - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = request.data; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].banner).to.not.exist; - expect(data.imp[0].video).to.exist; - - expect(Object.keys(data.imp[0].video).length).to.equal(23); // 21 ortb params (2 skipped) + computed width/height. - expect(data.imp[0].video.w).to.equal(480); - expect(data.imp[0].video.h).to.equal(320); - expect(data.imp[0].video.mimes[0]).to.equal('video/mpeg4'); - expect(data.imp[0].video.pos).to.equal(2); - expect(data.imp[0].video.skip).to.equal(1); - expect(data.imp[0].video.skipafter).to.equal(10); - expect(data.imp[0].video.startdelay).to.equal(3); - expect(data.imp[0].video.companionad).to.not.exist; - expect(data.imp[0].video.companiontype).to.not.exist; - }); - - it('should log warn message when OpenRTB validation fails ', function() { - const bidRequests = [utils.deepClone(bidVideo)]; - bidRequests[0].mediaTypes.video.placement = 'string'; - bidRequests[0].mediaTypes.video.api = 1; - const bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - utilsMock.expects('logWarn').twice(); - - spec.buildRequests(bidRequests, bidderRequestCopy); - }); - }); - it('should get expected properties with values from params', function () { const bidRequests = [utils.deepClone(bid)]; bidRequests[0].params = { @@ -529,25 +265,13 @@ describe('mediakeysBidAdapter', function () { expect(data.imp[0].bidfloor).to.not.exist; }); - it('should get the highest floorPrice found when bid have several mediaTypes', function() { + it('should get and set floor by mediatype', function() { const bidWithPriceFloors = utils.deepClone(bid); bidWithPriceFloors.mediaTypes.video = { playerSize: [600, 480] }; - bidWithPriceFloors.mediaTypes.native = { - body: { - required: true - } - }; - - bidWithPriceFloors.nativeParams = { - body: { - required: true - } - }; - bidWithPriceFloors.getFloor = getFloorTest; const bidRequests = [bidWithPriceFloors]; @@ -555,9 +279,10 @@ describe('mediakeysBidAdapter', function () { const data = request.data; expect(data.imp[0].banner).to.exist; - expect(data.imp[0].video).to.exist; - expect(data.imp[0].native).to.exist; - expect(data.imp[0].bidfloor).to.equal(5); + expect(data.imp[0].bidfloor).to.equal(1); + + // expect(data.imp[1].video).to.exist; + // expect(data.imp[1].bidfloor).to.equal(5); }); it('should set properties at payload level from FPD', function() { @@ -695,8 +420,8 @@ describe('mediakeysBidAdapter', function () { const bidRequests = [utils.deepClone(bid)]; const request = spec.buildRequests(bidRequests, bidderRequest); sinon.stub(utils, 'isArray').throws(); - utilsMock.expects('logError').once(); spec.interpretResponse(rawServerResponse, request); + utilsMock.expects('logError').once(); utils.isArray.restore(); }); @@ -758,108 +483,28 @@ describe('mediakeysBidAdapter', function () { }); }); - it('interprets video bid response', function () { - const vastUrl = 'https://url.local?req=content'; - const bidRequests = [utils.deepClone(bidVideo)]; + it('Build video response', function () { + const bidRequests = [utils.deepClone(bid)]; const request = spec.buildRequests(bidRequests, bidderRequest); - const rawServerResponseVideo = utils.deepClone(rawServerResponse); rawServerResponseVideo.body.seatbid[0].bid[0].ext.prebid.type = 'V'; - rawServerResponseVideo.body.seatbid[0].bid[0].ext.vast_url = vastUrl; - const response = spec.interpretResponse(rawServerResponseVideo, request); expect(response.length).to.equal(1); expect(response[0].mediaType).to.equal('video'); expect(response[0].meta.mediaType).to.equal('video'); - expect(response[0].vastXml).to.not.exist; - expect(response[0].vastUrl).to.equal(vastUrl + '&no_cache'); - expect(response[0].videoCacheKey).to.equal('no_cache'); }); - describe('Native response', function () { - let bidRequests; - let bidderRequestCopy; - let request; - let rawServerResponseNative; - let nativeObject; - - beforeEach(function() { - bidRequests = [utils.deepClone(bidNative)]; - bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - request = spec.buildRequests(bidRequests, bidderRequestCopy); - - nativeObject = { - ver: '1.2', - privacy: 'https://privacy.me', - assets: [ - { id: 5, data: { type: 1, value: 'Sponsor Brand' } }, - { id: 6, data: { type: 2, value: 'Brand Body' } }, - { id: 14, data: { type: 10, value: 'Brand Body 2' } }, - { id: 1, title: { text: 'Brand Title' } }, - { id: 2, img: { type: 3, url: 'https://url.com/img.jpg', w: 300, h: 250 } }, - { id: 3, img: { type: 1, url: 'https://url.com/ico.png', w: 50, h: 50 } }, - ], - link: { - url: 'https://brand.me', - clicktrackers: [ - 'https://click.me' - ] - }, - eventtrackers: [ - { event: 1, method: 1, url: 'https://click.me' }, - { event: 1, method: 2, url: 'https://click-script.me' } - ] - }; - - rawServerResponseNative = utils.deepClone(rawServerResponse); - rawServerResponseNative.body.seatbid[0].bid[0].ext.prebid.type = 'N'; - rawServerResponseNative.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObject) - }); - - it('should ignore invalid native response', function() { - const nativeObjectCopy = utils.deepClone(nativeObject); - nativeObjectCopy.assets = []; - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - rawServerResponseNativeCopy.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObjectCopy) - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response.length).to.equal(1); - expect(response[0].native).to.not.exist; - }); - - it('should build a classic Prebid.js native object for response', function() { - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response.length).to.equal(1); - expect(response[0].mediaType).to.equal('native'); - expect(response[0].meta.mediaType).to.equal('native'); - expect(response[0].native).to.exist; - expect(response[0].native.body).to.exist; - expect(response[0].native.privacyLink).to.exist; - expect(response[0].native.body2).to.exist; - expect(response[0].native.sponsoredBy).to.exist; - expect(response[0].native.image).to.exist; - expect(response[0].native.icon).to.exist; - expect(response[0].native.title).to.exist; - expect(response[0].native.clickUrl).to.exist; - expect(response[0].native.clickTrackers).to.exist; - expect(response[0].native.clickTrackers.length).to.equal(1); - expect(response[0].native.javascriptTrackers).to.equal(''); - expect(response[0].native.impressionTrackers).to.exist; - expect(response[0].native.impressionTrackers.length).to.equal(1); - }); + it('Build native response', function () { + const bidRequests = [utils.deepClone(bid)]; + const request = spec.buildRequests(bidRequests, bidderRequest); + const rawServerResponseVideo = utils.deepClone(rawServerResponse); + rawServerResponseVideo.body.seatbid[0].bid[0].ext.prebid.type = 'N'; + const response = spec.interpretResponse(rawServerResponseVideo, request); - it('should ignore eventtrackers with a unsupported type', function() { - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - const nativeObjectCopy = utils.deepClone(nativeObject); - nativeObjectCopy.eventtrackers[0].event = 2; - rawServerResponseNativeCopy.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObjectCopy); - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response[0].native.impressionTrackers).to.exist; - expect(response[0].native.impressionTrackers.length).to.equal(0); - }) + expect(response.length).to.equal(1); + expect(response[0].mediaType).to.equal('native'); + expect(response[0].meta.mediaType).to.equal('native'); }); }); diff --git a/test/spec/modules/medianetAnalyticsAdapter_spec.js b/test/spec/modules/medianetAnalyticsAdapter_spec.js index a0a62710a56..41a6338225e 100644 --- a/test/spec/modules/medianetAnalyticsAdapter_spec.js +++ b/test/spec/modules/medianetAnalyticsAdapter_spec.js @@ -11,12 +11,10 @@ const { const MOCK = { Ad_Units: [{'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'banner': {'sizes': [[300, 250]]}}, 'bids': [], 'ext': {'prop1': 'value1'}}], MULTI_FORMAT_TWIN_AD_UNITS: [{'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'banner': {'sizes': [[300, 250]]}, 'native': {'image': {'required': true, 'sizes': [150, 50]}}}, 'bids': [], 'ext': {'prop1': 'value1'}}, {'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'video': {'playerSize': [640, 480], 'context': 'instream'}}, 'bids': [], 'ext': {'prop1': 'value1'}}], - TWIN_AD_UNITS: [{'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'banner': {'sizes': [[300, 100]]}}, 'ask': '300x100', 'bids': [{'bidder': 'bidder1', 'params': {'siteId': '451465'}}]}, {'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'banner': {'sizes': [[300, 250], [300, 100]]}}, 'bids': [{'bidder': 'medianet', 'params': {'cid': 'TEST_CID', 'crid': '451466393'}}]}, {'code': 'div-gpt-ad-1460505748561-0', 'mediaTypes': {'banner': {'sizes': [[300, 250]]}}, 'bids': [{'bidder': 'bidder1', 'params': {'siteId': '451466'}}]}], AUCTION_INIT: {'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'timestamp': 1584563605739, 'timeout': 6000}, AUCTION_INIT_WITH_FLOOR: {'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'timestamp': 1584563605739, 'timeout': 6000, 'bidderRequests': [{'bids': [{ 'floorData': {'enforcements': {'enforceJS': true}} }]}]}, BID_REQUESTED: {'bidderCode': 'medianet', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'bids': [{'bidder': 'medianet', 'params': {'cid': 'TEST_CID', 'crid': '451466393'}, 'mediaTypes': {'banner': {'sizes': [[300, 250]], 'ext': ['asdads']}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'sizes': [[300, 250]], 'bidId': '28248b0e6aece2', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'src': 'client'}], 'auctionStart': 1584563605739, 'timeout': 6000, 'uspConsent': '1YY', 'start': 1584563605743}, MULTI_FORMAT_BID_REQUESTED: {'bidderCode': 'medianet', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'bids': [{'bidder': 'medianet', 'params': {'cid': 'TEST_CID', 'crid': '451466393'}, 'mediaTypes': {'banner': {'sizes': [[300, 250]]}, 'video': {'playerSize': [640, 480], 'context': 'instream'}, 'native': {'image': {'required': true, 'sizes': [150, 50]}, 'title': {'required': true, 'len': 80}}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'sizes': [[300, 250]], 'bidId': '28248b0e6aece2', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'src': 'client'}], 'auctionStart': 1584563605739, 'timeout': 6000, 'uspConsent': '1YY', 'start': 1584563605743}, - TWIN_AD_UNITS_BID_REQUESTED: [{'bidderCode': 'bidder1', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'bidderRequestId': '16f0746ff657b5', 'bids': [{'bidder': 'bidder1', 'params': {'siteId': '451465'}, 'mediaTypes': {'banner': {'sizes': [[300, 100]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '9615b5d1-7a4f-4c65-9464-4178b91da9e3', 'sizes': [[300, 100]], 'bidId': '2984d18e18bdfe', 'bidderRequestId': '16f0746ff657b5', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'src': 'client', 'bidRequestsCount': 3, 'bidderRequestsCount': 2, 'bidderWinsCount': 0}, {'bidder': 'bidder1', 'params': {'siteId': '451466'}, 'mediaTypes': {'banner': {'sizes': [[300, 250]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '8bd7c9f2-0fe6-4ac5-8f2a-7f4a88af1b71', 'sizes': [[300, 250]], 'bidId': '3dced609066035', 'bidderRequestId': '16f0746ff657b5', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'src': 'client', 'bidRequestsCount': 3, 'bidderRequestsCount': 2, 'bidderWinsCount': 0}], 'auctionStart': 1584563605739, 'timeout': 3000, 'start': 1584563605743}, {'bidderCode': 'medianet', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'bidderRequestId': '4b45d1de1fa8fe', 'bids': [{'bidder': 'medianet', 'params': {'cid': 'TEST_CID', 'crid': '451466393'}, 'mediaTypes': {'banner': {'sizes': [[300, 250], [300, 100]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '215c038e-3b6a-465b-8937-d32e2ad8de45', 'sizes': [[300, 250], [300, 100]], 'bidId': '58d34adcb09c99', 'bidderRequestId': '4b45d1de1fa8fe', 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'src': 'client', 'bidRequestsCount': 3, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}], 'auctionStart': 1584563605739, 'timeout': 3000, 'start': 1584563605743}], BID_RESPONSE: {'bidderCode': 'medianet', 'width': 300, 'height': 250, 'adId': '3e6e4bce5c8fb3', 'requestId': '28248b0e6aece2', 'mediaType': 'banner', 'source': 'client', 'ext': {'pvid': 123, 'crid': '321'}, 'no_bid': false, 'cpm': 2.299, 'ad': 'AD_CODE', 'ttl': 180, 'creativeId': 'Test1', 'netRevenue': true, 'currency': 'USD', 'dfp_id': 'div-gpt-ad-1460505748561-0', 'originalCpm': 1.1495, 'originalCurrency': 'USD', 'floorData': {'floorValue': 1.10, 'floorRule': 'banner'}, 'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'responseTimestamp': 1584563606009, 'requestTimestamp': 1584563605743, 'bidder': 'medianet', 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'timeToRespond': 266, 'pbLg': '2.00', 'pbMg': '2.20', 'pbHg': '2.29', 'pbAg': '2.25', 'pbDg': '2.29', 'pbCg': '2.00', 'size': '300x250', 'adserverTargeting': {'hb_bidder': 'medianet', 'hb_adid': '3e6e4bce5c8fb3', 'hb_pb': '2.00', 'hb_size': '300x250', 'hb_source': 'client', 'hb_format': 'banner', 'prebid_test': 1}, 'status': 'rendered', 'params': [{'cid': 'test123', 'crid': '451466393'}]}, AUCTION_END: {'auctionId': '8e0d5245-deb3-406c-96ca-9b609e077ff7', 'auctionEnd': 1584563605739}, SET_TARGETING: {'div-gpt-ad-1460505748561-0': {'prebid_test': '1', 'hb_format': 'banner', 'hb_source': 'client', 'hb_size': '300x250', 'hb_pb': '2.00', 'hb_adid': '3e6e4bce5c8fb3', 'hb_bidder': 'medianet', 'hb_format_medianet': 'banner', 'hb_source_medianet': 'client', 'hb_size_medianet': '300x250', 'hb_pb_medianet': '2.00', 'hb_adid_medianet': '3e6e4bce5c8fb3', 'hb_bidder_medianet': 'medianet'}}, @@ -27,7 +25,7 @@ const MOCK = { } function performAuctionWithFloorConfig() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT_WITH_FLOOR, {adUnits: MOCK.Ad_Units})); + events.emit(AUCTION_INIT, {...MOCK.AUCTION_INIT_WITH_FLOOR, adUnits: MOCK.Ad_Units}); events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); events.emit(BID_RESPONSE, MOCK.BID_RESPONSE); events.emit(AUCTION_END, MOCK.AUCTION_END); @@ -36,7 +34,7 @@ function performAuctionWithFloorConfig() { } function performStandardAuctionWithWinner() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.Ad_Units})); + events.emit(AUCTION_INIT, {...MOCK.AUCTION_INIT, adUnits: MOCK.Ad_Units}); events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); events.emit(BID_RESPONSE, MOCK.BID_RESPONSE); events.emit(AUCTION_END, MOCK.AUCTION_END); @@ -45,23 +43,15 @@ function performStandardAuctionWithWinner() { } function performMultiFormatAuctionWithNoBid() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.MULTI_FORMAT_TWIN_AD_UNITS})); + events.emit(AUCTION_INIT, {...MOCK.AUCTION_INIT, adUnits: MOCK.MULTI_FORMAT_TWIN_AD_UNITS}); events.emit(BID_REQUESTED, MOCK.MULTI_FORMAT_BID_REQUESTED); events.emit(NO_BID, MOCK.NO_BID); events.emit(AUCTION_END, MOCK.AUCTION_END); events.emit(SET_TARGETING, MOCK.NO_BID_SET_TARGETING); } -function performTwinAdUnitAuctionWithNoBid() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.TWIN_AD_UNITS})); - MOCK.TWIN_AD_UNITS_BID_REQUESTED.forEach(bidRequested => events.emit(BID_REQUESTED, bidRequested)); - MOCK.TWIN_AD_UNITS_BID_REQUESTED.forEach(bidRequested => bidRequested.bids.forEach(noBid => events.emit(NO_BID, noBid))); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.NO_BID_SET_TARGETING); -} - function performStandardAuctionWithNoBid() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.Ad_Units})); + events.emit(AUCTION_INIT, {...MOCK.AUCTION_INIT, adUnits: MOCK.Ad_Units}); events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); events.emit(NO_BID, MOCK.NO_BID); events.emit(AUCTION_END, MOCK.AUCTION_END); @@ -69,20 +59,17 @@ function performStandardAuctionWithNoBid() { } function performStandardAuctionWithTimeout() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.Ad_Units})); + events.emit(AUCTION_INIT, {...MOCK.AUCTION_INIT, adUnits: MOCK.Ad_Units}); events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); events.emit(AUCTION_END, MOCK.AUCTION_END); events.emit(SET_TARGETING, MOCK.NO_BID_SET_TARGETING); } -function getQueryData(url, decode = false) { +function getQueryData(url) { const queryArgs = url.split('?')[1].split('&'); return queryArgs.reduce((data, arg) => { - let [key, val] = arg.split('='); - if (decode) { - val = decodeURIComponent(val); - } + const [key, val] = arg.split('='); if (data[key] !== undefined) { if (!Array.isArray(data[key])) { data[key] = [data[key]]; @@ -162,25 +149,6 @@ describe('Media.net Analytics Adapter', function() { expect(noBidLog.vplcmtt).to.equal('instream'); }); - it('twin ad units should have correct sizes', function() { - performTwinAdUnitAuctionWithNoBid(); - const noBidLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log, true))[0]; - const banner = 'banner'; - expect(noBidLog.pvnm).to.have.ordered.members(['-2', 'bidder1', 'bidder1', 'medianet']); - expect(noBidLog.mtype).to.have.ordered.members([banner, banner, banner, banner]); - expect(noBidLog.status).to.have.ordered.members(['1', '2', '2', '2']); - expect(noBidLog.size).to.have.ordered.members(['', '', '', '']); - expect(noBidLog.szs).to.have.ordered.members(['300x100|300x250', '300x100', '300x250', '300x250|300x100']); - }); - - it('AP log should fire only once', function() { - performStandardAuctionWithNoBid(); - events.emit(SET_TARGETING, MOCK.NO_BID_SET_TARGETING); - const logs = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log, true)); - expect(logs.length).to.equal(1); - expect(logs[0].lgtp).to.equal('APPR'); - }); - it('should have winner log in standard auction', function() { medianetAnalytics.clearlogsQueue(); performStandardAuctionWithWinner(); diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js index 8589c3b404f..adb9663ba7c 100644 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ b/test/spec/modules/medianetBidAdapter_spec.js @@ -1,4 +1,4 @@ -import {expect, assert} from 'chai'; +import {expect} from 'chai'; import {spec} from 'modules/medianetBidAdapter.js'; import { makeSlot } from '../integration/faker/googletag.js'; import { config } from 'src/config.js'; @@ -99,56 +99,6 @@ let VALID_BID_REQUEST = [{ 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', 'bidRequestsCount': 1 }], - VALID_BID_REQUEST_WITH_ORTB2 = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'ortb2Imp': { 'ext': { 'data': { 'pbadslot': '/12345/my-gpt-tag-0' } } }, - 'bidRequestsCount': 1 - }, { - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'ortb2Imp': { 'ext': { 'data': { 'pbadslot': '/12345/my-gpt-tag-0' } } }, - 'bidRequestsCount': 1 - }], VALID_BID_REQUEST_WITH_USERID = [{ 'bidder': 'medianet', 'params': { @@ -1297,17 +1247,6 @@ describe('Media.net bid adapter', function () { expect(JSON.parse(bidreq.data)).to.deep.equal(VALID_PAYLOAD_WITH_CRID); }); - it('should have valid ortb2Imp param present in bid request', function() { - let bidreq = spec.buildRequests(VALID_BID_REQUEST_WITH_ORTB2, VALID_AUCTIONDATA); - let actual = JSON.parse(bidreq.data).imp[0].ortb2Imp; - const expected = VALID_BID_REQUEST_WITH_ORTB2[0].ortb2Imp - assert.equal(JSON.stringify(actual), JSON.stringify(expected)) - - bidreq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - actual = JSON.parse(bidreq.data).imp[0].ortb2Imp; - assert.equal(actual, undefined) - }); - it('should have userid in bid request', function () { let bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_USERID, VALID_AUCTIONDATA); expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_WITH_USERID); diff --git a/test/spec/modules/mediasquareBidAdapter_spec.js b/test/spec/modules/mediasquareBidAdapter_spec.js index 862b74f4f97..f3f09a8ddf8 100644 --- a/test/spec/modules/mediasquareBidAdapter_spec.js +++ b/test/spec/modules/mediasquareBidAdapter_spec.js @@ -167,7 +167,7 @@ describe('MediaSquare bid adapter tests', function () { }); it('Verifies user sync without cookie in bid response', function () { var syncs = spec.getUserSyncs({}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); + expect(syncs).to.have.property('type').and.to.equal('iframe'); }); it('Verifies user sync with cookies in bid response', function () { BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; @@ -178,13 +178,13 @@ describe('MediaSquare bid adapter tests', function () { }); it('Verifies user sync with no bid response', function() { var syncs = spec.getUserSyncs({}, null, DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); + expect(syncs).to.have.property('type').and.to.equal('iframe'); }); it('Verifies user sync with no bid body response', function() { var syncs = spec.getUserSyncs({}, [], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); + expect(syncs).to.have.property('type').and.to.equal('iframe'); var syncs = spec.getUserSyncs({}, [{}], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); + expect(syncs).to.have.property('type').and.to.equal('iframe'); }); it('Verifies native in bid response', function () { const request = spec.buildRequests(NATIVE_PARAMS, DEFAULT_OPTIONS); diff --git a/test/spec/modules/merkleIdSystem_spec.js b/test/spec/modules/merkleIdSystem_spec.js deleted file mode 100644 index 63a2791ba3c..00000000000 --- a/test/spec/modules/merkleIdSystem_spec.js +++ /dev/null @@ -1,230 +0,0 @@ -import * as ajaxLib from 'src/ajax.js'; -import * as utils from 'src/utils.js'; -import {merkleIdSubmodule} from 'modules/merkleIdSystem.js'; - -import sinon from 'sinon'; - -let expect = require('chai').expect; - -const CONFIG_PARAMS = { - endpoint: 'https://test/id', - vendor: 'idsv2', - sv_cid: '5344_04531', - sv_pubid: '11314', - sv_domain: 'www.testDomain.com', - sv_session: 'testsession' -}; - -const STORAGE_PARAMS = { - type: 'cookie', - name: 'merkle', - expires: 10, - refreshInSeconds: 10 -}; - -const MOCK_RESPONSE = { - c: { - name: '_svsid', - value: '123876327647627364236478' - } -}; - -function mockResponse( - responseText, - response = (url, successCallback) => successCallback(responseText)) { - return function() { - return response; - } -} - -describe('Merkle System', function () { - describe('Merkle System getId()', function () { - const callbackSpy = sinon.spy(); - let sandbox; - let ajaxStub; - - beforeEach(function () { - sandbox = sinon.sandbox.create(); - sinon.stub(utils, 'logInfo'); - sinon.stub(utils, 'logWarn'); - sinon.stub(utils, 'logError'); - callbackSpy.resetHistory(); - ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockResponse(JSON.stringify(MOCK_RESPONSE))); - }); - - afterEach(function () { - utils.logInfo.restore(); - utils.logWarn.restore(); - utils.logError.restore(); - ajaxStub.restore(); - }); - - it('getId() should fail on missing vendor', function () { - let config = { - params: { - ...CONFIG_PARAMS, - vendor: undefined - }, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined); - expect(submoduleCallback).to.be.undefined; - expect(utils.logError.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule requires a valid vendor to be defined'); - }); - - it('getId() should fail on missing vendor', function () { - let config = { - params: { - ...CONFIG_PARAMS, - vendor: undefined - }, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined); - expect(submoduleCallback).to.be.undefined; - expect(utils.logError.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule requires a valid vendor to be defined'); - }); - - it('getId() should fail on missing sv_cid', function () { - let config = { - params: { - ...CONFIG_PARAMS, - sv_cid: undefined - }, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined); - expect(submoduleCallback).to.be.undefined; - expect(utils.logError.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule requires a valid sv_cid string to be defined'); - }); - - it('getId() should fail on missing sv_pubid', function () { - let config = { - params: { - ...CONFIG_PARAMS, - sv_pubid: undefined - }, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined); - expect(submoduleCallback).to.be.undefined; - expect(utils.logError.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule requires a valid sv_pubid string to be defined'); - }); - - it('getId() should warn on missing endpoint', function () { - let config = { - params: { - ...CONFIG_PARAMS, - endpoint: undefined - }, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined).callback; - submoduleCallback(callbackSpy); - expect(callbackSpy.calledOnce).to.be.true; - expect(utils.logWarn.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule endpoint string is not defined'); - }); - - it('getId() should handle callback with valid configuration', function () { - let config = { - params: CONFIG_PARAMS, - storage: STORAGE_PARAMS - }; - - let submoduleCallback = merkleIdSubmodule.getId(config, undefined).callback; - submoduleCallback(callbackSpy); - expect(callbackSpy.calledOnce).to.be.true; - }); - }); - - describe('Merkle System extendId()', function () { - const callbackSpy = sinon.spy(); - let sandbox; - let ajaxStub; - - beforeEach(function () { - sandbox = sinon.sandbox.create(); - sinon.stub(utils, 'logInfo'); - sinon.stub(utils, 'logWarn'); - sinon.stub(utils, 'logError'); - callbackSpy.resetHistory(); - ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(mockResponse(JSON.stringify(MOCK_RESPONSE))); - }); - - afterEach(function () { - utils.logInfo.restore(); - utils.logWarn.restore(); - utils.logError.restore(); - ajaxStub.restore(); - }); - - it('extendId() get storedid', function () { - let config = { - params: { - ...CONFIG_PARAMS, - }, - storage: STORAGE_PARAMS - }; - - let id = merkleIdSubmodule.extendId(config, undefined, 'Merkle_Stored_ID'); - expect(id.id).to.exist.and.to.equal('Merkle_Stored_ID'); - }); - - it('extendId() get storedId on configured storageParam.refreshInSeconds', function () { - let config = { - params: { - ...CONFIG_PARAMS, - refreshInSeconds: 1000 - }, - storage: STORAGE_PARAMS - }; - - let yesterday = new Date(Date.now() - 86400000).toUTCString(); - let storedId = {value: 'Merkle_Stored_ID', date: yesterday}; - - let id = merkleIdSubmodule.extendId(config, undefined, - storedId); - - expect(id.id).to.exist.and.to.equal(storedId); - }); - it('extendId() should warn on missing endpoint', function () { - let config = { - params: { - ...CONFIG_PARAMS, - endpoint: undefined - }, - storage: STORAGE_PARAMS - }; - - let yesterday = new Date(Date.now() - 86400000).toUTCString(); - let storedId = {value: 'Merkle_Stored_ID', date: yesterday}; - - let submoduleCallback = merkleIdSubmodule.extendId(config, undefined, - storedId).callback; - submoduleCallback(callbackSpy); - expect(callbackSpy.calledOnce).to.be.true; - expect(utils.logWarn.args[0][0]).to.exist.and.to.equal('User ID - merkleId submodule endpoint string is not defined'); - }); - - it('extendId() callback on configured storageParam.refreshInSeconds', function () { - let config = { - params: { - ...CONFIG_PARAMS, - refreshInSeconds: 1 - } - }; - - let yesterday = new Date(Date.now() - 86400000).toUTCString(); - let storedId = {value: 'Merkle_Stored_ID', date: yesterday}; - - let submoduleCallback = merkleIdSubmodule.extendId(config, undefined, storedId).callback; - submoduleCallback(callbackSpy); - expect(callbackSpy.calledOnce).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/mgidBidAdapter_spec.js b/test/spec/modules/mgidBidAdapter_spec.js deleted file mode 100644 index 34ad29b3e92..00000000000 --- a/test/spec/modules/mgidBidAdapter_spec.js +++ /dev/null @@ -1,826 +0,0 @@ -import {assert, expect} from 'chai'; -import { spec, storage } from 'modules/mgidBidAdapter.js'; -import { version } from 'package.json'; -import * as utils from '../../../src/utils.js'; - -describe('Mgid bid adapter', function () { - let sandbox; - let logErrorSpy; - let logWarnSpy; - beforeEach(function () { - sandbox = sinon.sandbox.create(); - logErrorSpy = sinon.spy(utils, 'logError'); - logWarnSpy = sinon.spy(utils, 'logWarn'); - }); - - afterEach(function () { - sandbox.restore(); - utils.logError.restore(); - utils.logWarn.restore(); - }); - const ua = navigator.userAgent; - const screenHeight = screen.height; - const screenWidth = screen.width; - const dnt = (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0; - const language = navigator.language ? 'language' : 'userLanguage'; - let lang = navigator[language].split('-')[0]; - if (lang.length != 2 && lang.length != 3) { - lang = ''; - } - const secure = window.location.protocol === 'https:' ? 1 : 0; - const mgid_ver = spec.VERSION; - const utcOffset = (new Date()).getTimezoneOffset().toString(); - - describe('isBidRequestValid', function () { - let bid = { - 'adUnitCode': 'div', - 'bidder': 'mgid', - 'params': { - 'property': '10433394', - 'zone': 'zone' - }, - }; - - it('should not accept bid without required params', function () { - let isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }); - - it('should return false when params are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '', placementId: ''}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.adUnitCode = ''; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when adUnitCode not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.adUnitCode = ''; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when valid params are passed as nums', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.adUnitCode = 'div'; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when valid params are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.mediaTypes = { - native: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: '0', placementId: '00'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner.sizes are not passed', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - sizes: [] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner.sizes are not valid', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - sizes: [300, 250] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when valid params are passed as strings', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.adUnitCode = 'div'; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when valid mediaTypes.native is not object', function () { - let bid = Object.assign({}, bid); - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: [] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native is empty object', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native is invalid object', function () { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: { - image: { - sizes: [80, 80] - }, - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native has unsupported required asset', function () { - let bid = Object.assign({}, bid); - bid.params = {accountId: '2', placementId: '1'}; - bid.mediaTypes = { - native: { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }, - }; - bid.nativeParams = { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - unsupported: {required: true}, - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when mediaTypes.native all assets needed', function () { - let bid = Object.assign({}, bid); - bid.adUnitCode = 'div'; - bid.params = {accountId: '2', placementId: '1'}; - bid.mediaTypes = { - native: { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }, - }; - bid.nativeParams = { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('override defaults', function () { - let bid = { - bidder: 'mgid', - params: { - accountId: '1', - placementId: '2', - }, - }; - it('should return object', function () { - let bid = Object.assign({}, bid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request).to.exist.and.to.be.a('object'); - }); - - it('should return overwrite default bidurl', function () { - let bid = Object.assign({}, bid); - bid.params = { - bidUrl: 'https://newbidurl.com/', - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.url).to.include('https://newbidurl.com/1'); - }); - it('should return overwrite default bidFloor', function () { - let bid = Object.assign({}, bid); - bid.params = { - bidFloor: 1.1, - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.data).to.be.a('string'); - const data = JSON.parse(request.data); - expect(data).to.be.a('object'); - expect(data.imp).to.be.a('array'); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor).to.deep.equal(1.1); - }); - it('should return overwrite default currency', function () { - let bid = Object.assign({}, bid); - bid.params = { - cur: 'GBP', - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.data).to.be.a('string'); - const data = JSON.parse(request.data); - expect(data).to.be.a('object'); - expect(data.cur).to.deep.equal(['GBP']); - }); - }); - - describe('buildRequests', function () { - let abid = { - adUnitCode: 'div', - bidder: 'mgid', - params: { - accountId: '1', - placementId: '2', - }, - }; - - it('should return undefined if no validBidRequests passed', function () { - expect(spec.buildRequests([])).to.be.undefined; - }); - it('should return request url with muid', function () { - let getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getDataFromLocalStorageStub.withArgs('mgMuidn').returns('xxx'); - - let bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1?muid=xxx'); - - getDataFromLocalStorageStub.restore(); - }); - it('should proper handle gdpr', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'gdpr', gdprApplies: true}}); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.user).deep.equal({ext: {consent: 'gdpr'}}); - expect(data.regs).deep.equal({ext: {gdpr: 1}}); - }); - it('should return proper banner imp', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - let bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(ua); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].banner).to.deep.equal({w: 300, h: 250}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': '{"site":{"domain":"' + domain + '","page":"' + page + '"},"cur":["USD"],"geo":{"utcoffset":' + utcOffset + '},"device":{"ua":"' + ua + '","js":1,"dnt":' + dnt + ',"h":' + screenHeight + ',"w":' + screenWidth + ',"language":"' + lang + '"},"ext":{"mgid_ver":"' + mgid_ver + '","prebid_ver":"' + version + '"},"imp":[{"tagid":"2/div","secure":' + secure + ',"banner":{"w":300,"h":250}}]}', - }); - }); - it('should not return native imp if minimum asset list not requested', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.undefined; - }); - it('should return proper native imp', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - sponsored: { }, - }; - - let bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(ua); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 80, 'type': 3, 'w': 80}, 'required': 0}, {'data': {'type': 1}, 'id': 11, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': '{"site":{"domain":"' + domain + '","page":"' + page + '"},"cur":["USD"],"geo":{"utcoffset":' + utcOffset + '},"device":{"ua":"' + ua + '","js":1,"dnt":' + dnt + ',"h":' + screenHeight + ',"w":' + screenWidth + ',"language":"' + lang + '"},"ext":{"mgid_ver":"' + mgid_ver + '","prebid_ver":"' + version + '"},"imp":[{"tagid":"2/div","secure":' + secure + ',"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":0,"img":{"type":3,"w":80,"h":80}},{"id":11,"required":0,"data":{"type":1}}]}}}]}', - }); - }); - it('should return proper native imp with image altered', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {wmin: 50, hmin: 50, required: true}, - icon: {}, - sponsored: { }, - }; - - let bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(ua); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 328, hmin: 50, 'type': 3, 'w': 492, wmin: 50}, 'required': 1}, {'id': 3, 'img': {'h': 50, 'type': 1, 'w': 50}, 'required': 0}, {'data': {'type': 1}, 'id': 11, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': '{"site":{"domain":"' + domain + '","page":"' + page + '"},"cur":["USD"],"geo":{"utcoffset":' + utcOffset + '},"device":{"ua":"' + ua + '","js":1,"dnt":' + dnt + ',"h":' + screenHeight + ',"w":' + screenWidth + ',"language":"' + lang + '"},"ext":{"mgid_ver":"' + mgid_ver + '","prebid_ver":"' + version + '"},"imp":[{"tagid":"2/div","secure":' + secure + ',"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":1,"img":{"type":3,"w":492,"h":328,"wmin":50,"hmin":50}},{"id":3,"required":0,"img":{"type":1,"w":50,"h":50}},{"id":11,"required":0,"data":{"type":1}}]}}}]}', - }); - }); - it('should return proper native imp with sponsoredBy', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - sponsoredBy: { }, - }; - - let bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(ua); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 80, 'type': 3, 'w': 80}, 'required': 0}, {'data': {'type': 1}, 'id': 4, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': '{"site":{"domain":"' + domain + '","page":"' + page + '"},"cur":["USD"],"geo":{"utcoffset":' + utcOffset + '},"device":{"ua":"' + ua + '","js":1,"dnt":' + dnt + ',"h":' + screenHeight + ',"w":' + screenWidth + ',"language":"' + lang + '"},"ext":{"mgid_ver":"' + mgid_ver + '","prebid_ver":"' + version + '"},"imp":[{"tagid":"2/div","secure":' + secure + ',"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":0,"img":{"type":3,"w":80,"h":80}},{"id":4,"required":0,"data":{"type":1}}]}}}]}', - }); - }); - it('should return proper banner request', function () { - let bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 600], [300, 250]], - pos: 1, - }, - }; - let bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(ua); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].banner).to.deep.equal({w: 300, h: 600, format: [{w: 300, h: 600}, {w: 300, h: 250}], pos: 1}); - expect(data.imp[0].secure).to.deep.equal(secure); - - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': '{"site":{"domain":"' + domain + '","page":"' + page + '"},"cur":["USD"],"geo":{"utcoffset":' + utcOffset + '},"device":{"ua":"' + ua + '","js":1,"dnt":' + dnt + ',"h":' + screenHeight + ',"w":' + screenWidth + ',"language":"' + lang + '"},"ext":{"mgid_ver":"' + mgid_ver + '","prebid_ver":"' + version + '"},"imp":[{"tagid":"2/div","secure":' + secure + ',"banner":{"w":300,"h":600,"format":[{"w":300,"h":600},{"w":300,"h":250}],"pos":1}}]}', - }); - }); - }); - - describe('interpretResponse', function () { - it('should not push proper native bid response if adm is missing', function () { - let resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - let bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([]) - }); - it('should not push proper native bid response if assets is empty', function () { - let resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - let bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([]) - }); - it('should push proper native bid response, assets1', function () { - let resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}},{"id":4,"required":0,"data":{"type":4,"value":"sponsored"}},{"id":5,"required":0,"data":{"type":6,"value":"price1"}},{"id":6,"required":0,"data":{"type":7,"value":"price2"}}],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}], ext: {'muidn': 'userid'}} - }; - let bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([{ - 'ad': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}},{"id":4,"required":0,"data":{"type":4,"value":"sponsored"}},{"id":5,"required":0,"data":{"type":6,"value":"price1"}},{"id":6,"required":0,"data":{"type":7,"value":"price2"}}],"imptrackers":["imptrackers1"]}}', - 'burl': 'https burl', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'GBP', - 'dealId': '', - 'height': 0, - 'isBurl': true, - 'mediaType': 'native', - 'meta': {'advertiserDomains': ['test.com']}, - 'native': { - 'clickTrackers': [], - 'clickUrl': 'link_url', - 'data': 'price1', - 'icon': { - 'height': 50, - 'url': 'icon_src', - 'width': 50 - }, - 'image': { - 'height': 80, - 'url': 'image_src', - 'width': 80 - }, - 'impressionTrackers': [ - 'imptrackers1' - ], - 'jstracker': [], - 'sponsoredBy': 'sponsored', - 'title': 'title1' - }, - 'netRevenue': true, - 'nurl': 'https nurl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 0 - }]) - }); - it('should push proper native bid response, assets2', function () { - let resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}}],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - let bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([ - { - 'ad': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}}],"imptrackers":["imptrackers1"]}}', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'GBP', - 'dealId': '', - 'height': 0, - 'isBurl': true, - 'mediaType': 'native', - 'meta': {'advertiserDomains': ['test.com']}, - 'netRevenue': true, - 'nurl': 'https nurl', - 'burl': 'https burl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 0, - 'native': { - clickTrackers: [], - title: 'title1', - image: { - url: 'image_src', - width: 80, - height: 80, - }, - icon: { - url: 'icon_src', - width: 50, - height: 50, - }, - impressionTrackers: ['imptrackers1'], - jstracker: [], - clickUrl: 'link_url', - } - } - ]); - }); - - it('should not push bid response', function () { - let bids = spec.interpretResponse(); - expect(bids).to.be.undefined; - }); - it('should push proper banner bid response', function () { - let resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': '', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': 'html: adm', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - let bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([ - { - 'ad': 'html: adm', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'USD', - 'dealId': '', - 'height': 600, - 'isBurl': true, - 'mediaType': 'banner', - 'meta': {'advertiserDomains': ['test.com']}, - 'netRevenue': true, - 'nurl': 'https nurl', - 'burl': 'https burl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 300, - } - ]); - }); - }); - - describe('getUserSyncs', function () { - it('should do nothing on getUserSyncs', function () { - spec.getUserSyncs() - }); - }); - - describe('on bidWon', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('should replace nurl and burl for native', function () { - const burl = 'burl&s=${' + 'AUCTION_PRICE}'; - const nurl = 'nurl&s=${' + 'AUCTION_PRICE}'; - const bid = {'bidderCode': 'mgid', 'width': 0, 'height': 0, 'statusMessage': 'Bid available', 'adId': '3d0b6ff1dda89', 'requestId': '2a423489e058a1', 'mediaType': 'native', 'source': 'client', 'ad': '{"native":{"ver":"1.1","link":{"url":"LinkURL"},"assets":[{"id":1,"required":0,"title":{"text":"TITLE"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"ImageURL"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"IconURL"}},{"id":11,"required":0,"data":{"type":1,"value":"sponsored"}}],"imptrackers":["ImpTrackerURL"]}}', 'cpm': 0.66, 'creativeId': '353538_591471', 'currency': 'USD', 'dealId': '', 'netRevenue': true, 'ttl': 300, 'nurl': nurl, 'burl': burl, 'isBurl': true, 'native': {'title': 'TITLE', 'image': {'url': 'ImageURL', 'height': 80, 'width': 80}, 'icon': {'url': 'IconURL', 'height': 50, 'width': 50}, 'sponsored': 'sponsored', 'clickUrl': 'LinkURL', 'clickTrackers': [], 'impressionTrackers': ['ImpTrackerURL'], 'jstracker': []}, 'auctionId': 'a92bffce-14d2-4f8f-a78a-7b9b5e4d28fa', 'responseTimestamp': 1556867386065, 'requestTimestamp': 1556867385916, 'bidder': 'mgid', 'adUnitCode': 'div-gpt-ad-1555415275793-0', 'timeToRespond': 149, 'pbLg': '0.50', 'pbMg': '0.60', 'pbHg': '0.66', 'pbAg': '0.65', 'pbDg': '0.66', 'pbCg': '', 'size': '0x0', 'adserverTargeting': {'hb_bidder': 'mgid', 'hb_adid': '3d0b6ff1dda89', 'hb_pb': '0.66', 'hb_size': '0x0', 'hb_source': 'client', 'hb_format': 'native', 'hb_native_title': 'TITLE', 'hb_native_image': 'hb_native_image:3d0b6ff1dda89', 'hb_native_icon': 'IconURL', 'hb_native_linkurl': 'hb_native_linkurl:3d0b6ff1dda89'}, 'status': 'targetingSet', 'params': [{'accountId': '184', 'placementId': '353538'}]}; - spec.onBidWon(bid); - expect(bid.nurl).to.deep.equal('nurl&s=0.66'); - expect(bid.burl).to.deep.equal('burl&s=0.66'); - }); - it('should replace nurl and burl for banner', function () { - const burl = 'burl&s=${' + 'AUCTION_PRICE}'; - const nurl = 'nurl&s=${' + 'AUCTION_PRICE}'; - const bid = {'bidderCode': 'mgid', 'width': 0, 'height': 0, 'statusMessage': 'Bid available', 'adId': '3d0b6ff1dda89', 'requestId': '2a423489e058a1', 'mediaType': 'banner', 'source': 'client', 'ad': burl, 'cpm': 0.66, 'creativeId': '353538_591471', 'currency': 'USD', 'dealId': '', 'netRevenue': true, 'ttl': 300, 'nurl': nurl, 'burl': burl, 'isBurl': true, 'auctionId': 'a92bffce-14d2-4f8f-a78a-7b9b5e4d28fa', 'responseTimestamp': 1556867386065, 'requestTimestamp': 1556867385916, 'bidder': 'mgid', 'adUnitCode': 'div-gpt-ad-1555415275793-0', 'timeToRespond': 149, 'pbLg': '0.50', 'pbMg': '0.60', 'pbHg': '0.66', 'pbAg': '0.65', 'pbDg': '0.66', 'pbCg': '', 'size': '0x0', 'adserverTargeting': {'hb_bidder': 'mgid', 'hb_adid': '3d0b6ff1dda89', 'hb_pb': '0.66', 'hb_size': '0x0', 'hb_source': 'client', 'hb_format': 'banner', 'hb_banner_title': 'TITLE', 'hb_banner_image': 'hb_banner_image:3d0b6ff1dda89', 'hb_banner_icon': 'IconURL', 'hb_banner_linkurl': 'hb_banner_linkurl:3d0b6ff1dda89'}, 'status': 'targetingSet', 'params': [{'accountId': '184', 'placementId': '353538'}]}; - spec.onBidWon(bid); - expect(bid.nurl).to.deep.equal('nurl&s=0.66'); - expect(bid.burl).to.deep.equal(burl); - expect(bid.ad).to.deep.equal('burl&s=0.66'); - }); - }); - - describe('price floor module', function() { - let bidRequest; - let bidRequests0 = { - adUnitCode: 'div', - bidder: 'mgid', - params: { - accountId: '1', - placementId: '2', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - sizes: [[300, 250]], - } - beforeEach(function() { - bidRequest = [utils.deepClone(bidRequests0)]; - }); - - it('obtain floor from getFloor', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - it('obtain floor from params', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 1.23 - }; - }; - bidRequest[0].params.bidfloor = 0.1; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 0.1); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('undefined currency -> USD', function() { - bidRequest[0].params.currency = 'EUR' - bidRequest[0].getFloor = () => { - return { - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.have.property('bidfloorcur', 'USD'); - }); - it('altered currency', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'EUR', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.have.property('bidfloorcur', 'EUR'); - }); - it('altered currency, same as in request', function() { - bidRequest[0].params.cur = 'EUR' - bidRequest[0].getFloor = () => { - return { - currency: 'EUR', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('bad floor value', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 'test' - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('empty floor object', function() { - bidRequest[0].getFloor = () => { - return {}; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('undefined floor result', function() { - bidRequest[0].getFloor = () => {}; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - }); -}); diff --git a/test/spec/modules/missenaBidAdapter_spec.js b/test/spec/modules/missenaBidAdapter_spec.js deleted file mode 100644 index 86b967cca5b..00000000000 --- a/test/spec/modules/missenaBidAdapter_spec.js +++ /dev/null @@ -1,134 +0,0 @@ -import { expect } from 'chai'; -import { spec, _getPlatform } from 'modules/missenaBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('Missena Adapter', function () { - const adapter = newBidder(spec); - - const bidId = 'abc'; - - const bid = { - bidder: 'missena', - bidId: bidId, - sizes: [[1, 1]], - params: { - apiKey: 'PA-34745704', - }, - }; - - describe('codes', function () { - it('should return a bidder code of missena', function () { - expect(spec.code).to.equal('missena'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true if the apiKey param is present', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if the apiKey is missing', function () { - expect( - spec.isBidRequestValid(Object.assign(bid, { params: {} })) - ).to.equal(false); - }); - - it('should return false if the apiKey is an empty string', function () { - expect( - spec.isBidRequestValid(Object.assign(bid, { params: { apiKey: '' } })) - ).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const consentString = 'AAAAAAAAA=='; - - const bidderRequest = { - gdprConsent: { - consentString: consentString, - gdprApplies: true, - }, - refererInfo: { - referer: 'https://referer', - canonicalUrl: 'https://canonical', - }, - }; - - const requests = spec.buildRequests([bid, bid], bidderRequest); - const request = requests[0]; - const payload = JSON.parse(request.data); - - it('should return as many server requests as bidder requests', function () { - expect(requests.length).to.equal(2); - }); - - it('should have a post method', function () { - expect(request.method).to.equal('POST'); - }); - - it('should send the bidder id', function () { - expect(payload.request_id).to.equal(bidId); - }); - - it('should send referer information to the request', function () { - expect(payload.referer).to.equal('https://referer'); - expect(payload.referer_canonical).to.equal('https://canonical'); - }); - - it('should send gdpr consent information to the request', function () { - expect(payload.consent_string).to.equal(consentString); - expect(payload.consent_required).to.equal(true); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - requestId: bidId, - cpm: 0.5, - currency: 'USD', - ad: '', - meta: { - advertiserDomains: ['missena.com'] - }, - }; - - const serverTimeoutResponse = { - requestId: bidId, - timeout: true, - ad: '', - }; - - const serverEmptyAdResponse = { - requestId: bidId, - cpm: 0.5, - currency: 'USD', - ad: '', - }; - - it('should return a proper bid response', function () { - const result = spec.interpretResponse({ body: serverResponse }, bid); - - expect(result.length).to.equal(1); - - expect(Object.keys(result[0])).to.have.members( - Object.keys(serverResponse) - ); - }); - - it('should return an empty response when the server answers with a timeout', function () { - const result = spec.interpretResponse( - { body: serverTimeoutResponse }, - bid - ); - expect(result).to.deep.equal([]); - }); - - it('should return an empty response when the server answers with an empty ad', function () { - const result = spec.interpretResponse( - { body: serverEmptyAdResponse }, - bid - ); - expect(result).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/multibid_spec.js b/test/spec/modules/multibid_spec.js index 86365eb520f..e849392ee4b 100644 --- a/test/spec/modules/multibid_spec.js +++ b/test/spec/modules/multibid_spec.js @@ -82,7 +82,7 @@ describe('multibid adapter', function () { 'sizes': [[300, 250]] } }, - 'adUnitCode': 'test.div', + 'adUnitCode': 'test-div', 'transactionId': 'c153f3da-84f0-4be8-95cb-0647c458bc60', 'sizes': [[300, 250]], 'bidId': '2408ef83b84c9d', @@ -106,7 +106,7 @@ describe('multibid adapter', function () { 'sizes': [[300, 250]] } }, - 'adUnitCode': 'test.div', + 'adUnitCode': 'test-div', 'transactionId': 'c153f3da-84f0-4be8-95cb-0647c458bc60', 'sizes': [[300, 250]], 'bidId': '2408ef83b84c9d', @@ -197,14 +197,14 @@ describe('multibid adapter', function () { }); it('adds original bids and does not modify', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArray[0]}, {...bidArray[1]}]; addBidResponseHook(callbackFn, adUnitCode, {...bids[0]}); expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[0]); @@ -214,13 +214,13 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[1]); }); it('modifies and adds both bids based on multibid configuration', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArray[0]}, {...bidArray[1]}]; config.setConfig({multibid: [{bidder: 'bidderA', maxBids: 2, targetBiddercodePrefix: 'bidA'}]}); @@ -232,7 +232,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[0]); @@ -250,13 +250,13 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[1]); }); it('only modifies bids defined in the multibid configuration', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArray[0]}, {...bidArray[1]}]; bids.push({ @@ -276,7 +276,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[0]); @@ -292,7 +292,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[1]); @@ -302,13 +302,13 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[2]); }); it('only modifies and returns bids under limit for a specifc bidder in the multibid configuration', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArray[0]}, {...bidArray[1]}]; bids.push({ @@ -328,7 +328,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[0]); @@ -344,7 +344,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[1]); @@ -356,7 +356,7 @@ describe('multibid adapter', function () { }); it('if no prefix in multibid configuration, modifies and returns bids under limit without preifx property', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArray[0]}, {...bidArray[1]}]; bids.push({ @@ -375,7 +375,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[0]); @@ -389,7 +389,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid).to.deep.equal(bids[1]); @@ -401,7 +401,7 @@ describe('multibid adapter', function () { }); it('does not include extra bids if cpm is less than floor value', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArrayAlt[1]}, {...bidArrayAlt[0]}, {...bidArrayAlt[2]}, {...bidArrayAlt[3]}]; bids.map(bid => { @@ -418,7 +418,7 @@ describe('multibid adapter', function () { floorRuleValue: 65, floorValue: 65, matchedFields: { - gptSlot: 'test.div', + gptSlot: 'test-div', mediaType: 'banner' } } @@ -435,7 +435,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid.bidder).to.equal('bidderA'); expect(result.bid.targetingBidder).to.equal(undefined); @@ -452,7 +452,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid.bidder).to.equal('bidderB'); expect(result.bid.targetingBidder).to.equal(undefined); @@ -463,14 +463,14 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid.bidder).to.equal('bidderC'); expect(result.bid.targetingBidder).to.equal(undefined); }); it('does include extra bids if cpm is not less than floor value', function () { - let adUnitCode = 'test.div'; + let adUnitCode = 'test-div'; let bids = [{...bidArrayAlt[1]}, {...bidArrayAlt[0]}]; bids.map(bid => { @@ -487,7 +487,7 @@ describe('multibid adapter', function () { floorRuleValue: 25, floorValue: 25, matchedFields: { - gptSlot: 'test.div', + gptSlot: 'test-div', mediaType: 'banner' } } @@ -504,7 +504,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid.bidder).to.equal('bidderA'); expect(result.bid.targetingBidder).to.equal(undefined); @@ -518,7 +518,7 @@ describe('multibid adapter', function () { expect(result).to.not.equal(null); expect(result.adUnitCode).to.not.equal(null); - expect(result.adUnitCode).to.equal('test.div'); + expect(result.adUnitCode).to.equal('test-div'); expect(result.bid).to.not.equal(null); expect(result.bid.bidder).to.equal('bidderA'); expect(result.bid.targetingBidder).to.equal('bidA2'); @@ -578,7 +578,7 @@ describe('multibid adapter', function () { it('it sorts and creates dynamic alias on bidsReceived if multibid configuration found with prefix', function () { let modifiedBids = [{...bidArray[1]}, {...bidArray[0]}].map(bid => { - addBidResponseHook(bidResponseCallback, 'test.div', {...bid}); + addBidResponseHook(bidResponseCallback, 'test-div', {...bid}); return bidResult; }); @@ -603,7 +603,7 @@ describe('multibid adapter', function () { it('it sorts by cpm treating dynamic alias as unique bid when no bid limit defined', function () { let modifiedBids = [{...bidArrayAlt[0]}, {...bidArrayAlt[2]}, {...bidArrayAlt[3]}, {...bidArrayAlt[1]}].map(bid => { - addBidResponseHook(bidResponseCallback, 'test.div', {...bid}); + addBidResponseHook(bidResponseCallback, 'test-div', {...bid}); return bidResult; }); @@ -636,7 +636,7 @@ describe('multibid adapter', function () { it('it should filter out dynamic bid when bid limit is less than unique bid pool', function () { let modifiedBids = [{...bidArrayAlt[0]}, {...bidArrayAlt[2]}, {...bidArrayAlt[3]}, {...bidArrayAlt[1]}].map(bid => { - addBidResponseHook(bidResponseCallback, 'test.div', {...bid}); + addBidResponseHook(bidResponseCallback, 'test-div', {...bid}); return bidResult; }); @@ -662,7 +662,7 @@ describe('multibid adapter', function () { config.setConfig({ multibid: [{bidder: 'bidderA', maxBids: 2, targetBiddercodePrefix: 'bidA'}] }); let modifiedBids = [{...bidArrayAlt[0]}, {...bidArrayAlt[2]}, {...bidArrayAlt[3]}, {...bidArrayAlt[1]}].map(bid => { - addBidResponseHook(bidResponseCallback, 'test.div', {...bid}); + addBidResponseHook(bidResponseCallback, 'test-div', {...bid}); return bidResult; }); diff --git a/test/spec/modules/mytargetBidAdapter_spec.js b/test/spec/modules/mytargetBidAdapter_spec.js deleted file mode 100644 index 62d139bb926..00000000000 --- a/test/spec/modules/mytargetBidAdapter_spec.js +++ /dev/null @@ -1,199 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/mytargetBidAdapter'; - -describe('MyTarget Adapter', function() { - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - let validBid = { - bidder: 'mytarget', - params: { - placementId: '1' - } - }; - - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return false for when required params are not passed', function () { - let invalidBid = { - bidder: 'mytarget', - params: {} - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequests = [ - { - bidId: 'bid1', - bidder: 'mytarget', - params: { - placementId: '1' - } - }, - { - bidId: 'bid2', - bidder: 'mytarget', - params: { - placementId: '2', - position: 1, - response: 1, - bidfloor: 10000 - } - } - ]; - let bidderRequest = { - refererInfo: { - referer: 'https://example.com?param=value' - } - }; - - let bidRequest = spec.buildRequests(bidRequests, bidderRequest); - - it('should build single POST request for multiple bids', function() { - expect(bidRequest.method).to.equal('POST'); - expect(bidRequest.url).to.equal('//ad.mail.ru/hbid_prebid/'); - expect(bidRequest.data).to.be.an('object'); - expect(bidRequest.data.places).to.be.an('array'); - expect(bidRequest.data.places).to.have.lengthOf(2); - }); - - it('should pass bid parameters', function() { - let place1 = bidRequest.data.places[0]; - let place2 = bidRequest.data.places[1]; - - expect(place1.placementId).to.equal('1'); - expect(place2.placementId).to.equal('2'); - expect(place1.id).to.equal('bid1'); - expect(place2.id).to.equal('bid2'); - }); - - it('should pass default position and response type', function() { - let place = bidRequest.data.places[0]; - - expect(place.position).to.equal(0); - expect(place.response).to.equal(0); - }); - - it('should pass provided position and response type', function() { - let place = bidRequest.data.places[1]; - - expect(place.position).to.equal(1); - expect(place.response).to.equal(1); - }); - - it('should not pass default bidfloor', function() { - let place = bidRequest.data.places[0]; - - expect(place.bidfloor).not.to.exist; - }); - - it('should not pass provided bidfloor', function() { - let place = bidRequest.data.places[1]; - - expect(place.bidfloor).to.exist; - expect(place.bidfloor).to.equal(10000); - }); - - it('should pass site parameters', function() { - let site = bidRequest.data.site; - - expect(site).to.be.an('object'); - expect(site.sitename).to.equal('example.com'); - expect(site.page).to.equal('https://example.com?param=value'); - }); - - it('should pass settings', function() { - let settings = bidRequest.data.settings; - - expect(settings).to.be.an('object'); - expect(settings.currency).to.equal('RUB'); - expect(settings.windowSize).to.be.an('object'); - expect(settings.windowSize.width).to.equal(window.screen.width); - expect(settings.windowSize.height).to.equal(window.screen.height); - }); - }); - - describe('interpretResponse', function () { - let serverResponse = { - body: { - 'bidder_status': - [ - { - 'bidder': 'mail.ru', - 'response_time_ms': 100, - 'num_bids': 2 - } - ], - 'bids': - [ - { - 'displayUrl': 'https://ad.mail.ru/hbid_imp/12345', - 'size': - { - 'height': '400', - 'width': '240' - }, - 'id': '1', - 'currency': 'RUB', - 'price': 100, - 'ttl': 360, - 'creativeId': '123456' - }, - { - 'adm': '

Ad

', - 'size': - { - 'height': '250', - 'width': '300' - }, - 'id': '2', - 'price': 200 - } - ] - } - }; - - let bids = spec.interpretResponse(serverResponse); - - it('should return empty array for response with no bids', function() { - let emptyBids = spec.interpretResponse({ body: {} }); - - expect(emptyBids).to.have.lengthOf(0); - }); - - it('should parse all bids from response', function() { - expect(bids).to.have.lengthOf(2); - }); - - it('should parse bid with ad url', function() { - expect(bids[0].requestId).to.equal('1'); - expect(bids[0].cpm).to.equal(100); - expect(bids[0].width).to.equal('240'); - expect(bids[0].height).to.equal('400'); - expect(bids[0].ttl).to.equal(360); - expect(bids[0].currency).to.equal('RUB'); - expect(bids[0]).to.have.property('creativeId'); - expect(bids[0].creativeId).to.equal('123456'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].adUrl).to.equal('https://ad.mail.ru/hbid_imp/12345'); - expect(bids[0]).to.not.have.property('ad'); - }); - - it('should parse bid with ad markup', function() { - expect(bids[1].requestId).to.equal('2'); - expect(bids[1].cpm).to.equal(200); - expect(bids[1].width).to.equal('300'); - expect(bids[1].height).to.equal('250'); - expect(bids[1].ttl).to.equal(180); - expect(bids[1].currency).to.equal('RUB'); - expect(bids[1]).to.have.property('creativeId'); - expect(bids[1].creativeId).not.to.equal('123456'); - expect(bids[1].netRevenue).to.equal(true); - expect(bids[1].ad).to.equal('

Ad

'); - expect(bids[1]).to.not.have.property('adUrl'); - }); - }); -}); diff --git a/test/spec/modules/nativoBidAdapter_spec.js b/test/spec/modules/nativoBidAdapter_spec.js index 23f48f3661a..4202b7c6f91 100644 --- a/test/spec/modules/nativoBidAdapter_spec.js +++ b/test/spec/modules/nativoBidAdapter_spec.js @@ -8,46 +8,29 @@ import { spec } from 'modules/nativoBidAdapter.js' describe('nativoBidAdapterTests', function () { describe('isBidRequestValid', function () { let bid = { - bidder: 'nativo' - } - - it('should return true if no params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return true for valid placementId value', function () { - bid.params = { + bidder: 'nativo', + params: { placementId: '10433394', - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return true for valid placementId value', function () { - bid.params = { - placementId: 10433394, - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return false for invalid placementId value', function () { - bid.params = { - placementId: true, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) + }, + adUnitCode: 'adunit-code', + sizes: [ + [300, 250], + [300, 600], + ], + bidId: '27b02036ccfa6e', + bidderRequestId: '1372cd8bd8d6a8', + auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114', + } - it('should return true for valid placementId value', function () { - bid.params = { - url: 'www.test.com', - } + it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true) }) - it('should return false for invalid placementId value', function () { - bid.params = { - url: 4567890, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) + it('should return false when required params are not passed', function () { + let bid2 = Object.assign({}, bid) + delete bid2.params + bid2.params = {} + expect(spec.isBidRequestValid(bid2)).to.equal(false) }) }) @@ -146,12 +129,7 @@ describe('interpretResponse', function () { } // mock - spec.getAdUnitData = () => { - return { - bidId: 123456, - sizes: [300, 250], - } - } + spec.getRequestId = () => 123456 let result = spec.interpretResponse({ body: response }, { bidderRequest }) expect(Object.keys(result[0])).to.have.deep.members( @@ -254,45 +232,3 @@ describe('getUserSyncs', function () { ) }) }) - -describe('getAdUnitData', () => { - afterEach(() => { - if (window.bidRequestMap) delete window.bidRequestMap - }) - - it('Matches placementId value', () => { - const adUnitData = { - bidId: 123456, - sizes: [300, 250], - } - - window.bidRequestMap = { - 9876543: { - 12345: adUnitData, - }, - } - - const data = spec.getAdUnitData(9876543, { impid: 12345 }) - expect(Object.keys(data)).to.have.deep.members( - Object.keys(adUnitData) - ) - }) - - it('Falls back to ad unit code value', () => { - const adUnitData = { - bidId: 123456, - sizes: [300, 250], - } - - window.bidRequestMap = { - 9876543: { - '#test-code': adUnitData, - }, - } - - const data = spec.getAdUnitData(9876543, { impid: 12345, ext: { ad_unit_code: '#test-code' } }) - expect(Object.keys(data)).to.have.deep.members( - Object.keys(adUnitData) - ) - }) -}) diff --git a/test/spec/modules/naveggIdSystem_spec.js b/test/spec/modules/naveggIdSystem_spec.js deleted file mode 100644 index c0973a05372..00000000000 --- a/test/spec/modules/naveggIdSystem_spec.js +++ /dev/null @@ -1,21 +0,0 @@ -import { naveggIdSubmodule, storage } from 'modules/naveggIdSystem.js'; - -describe('naveggId', function () { - it('should NOT find navegg id', function () { - let id = naveggIdSubmodule.getId(); - - expect(id).to.be.undefined; - }); - - it('getId() should return "test-nid" id from cookie OLD_NAVEGG_ID', function() { - sinon.stub(storage, 'getCookie').withArgs('nid').returns('test-nid'); - let id = naveggIdSubmodule.getId(); - expect(id).to.be.deep.equal({id: 'test-nid'}) - }) - - it('getId() should return "test-nvggid" id from local storage NAVEGG_ID', function() { - sinon.stub(storage, 'getDataFromLocalStorage').withArgs('nvggid').returns('test-ninvggidd'); - let id = naveggIdSubmodule.getId(); - expect(id).to.be.deep.equal({id: 'test-ninvggidd'}) - }) -}); diff --git a/test/spec/modules/nextMillenniumBidAdapter_spec.js b/test/spec/modules/nextMillenniumBidAdapter_spec.js index 0dfee96d0ea..15256d6c382 100644 --- a/test/spec/modules/nextMillenniumBidAdapter_spec.js +++ b/test/spec/modules/nextMillenniumBidAdapter_spec.js @@ -4,57 +4,20 @@ import { spec } from 'modules/nextMillenniumBidAdapter.js'; describe('nextMillenniumBidAdapterTests', function() { const bidRequestData = [ { - adUnitCode: 'test-div', bidId: 'bid1234', auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', bidder: 'nextMillennium', params: { placement_id: '-1' }, - sizes: [[300, 250]], - uspConsent: '1---', - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - } + sizes: [[300, 250]] } ]; - it('Request params check with GDPR and USP Consent', function () { - const request = spec.buildRequests(bidRequestData, bidRequestData[0]); - expect(JSON.parse(request[0].data).user.ext.consent).to.equal('kjfdniwjnifwenrif3'); - expect(JSON.parse(request[0].data).regs.ext.us_privacy).to.equal('1---'); - expect(JSON.parse(request[0].data).regs.ext.gdpr).to.equal(1); - }); - - it('Request params check without GDPR Consent', function () { - delete bidRequestData[0].gdprConsent - const request = spec.buildRequests(bidRequestData, bidRequestData[0]); - expect(JSON.parse(request[0].data).regs.ext.gdpr).to.be.undefined; - expect(JSON.parse(request[0].data).regs.ext.us_privacy).to.equal('1---'); - }); - it('validate_generated_params', function() { const request = spec.buildRequests(bidRequestData); expect(request[0].bidId).to.equal('bid1234'); expect(JSON.parse(request[0].data).id).to.equal('b06c5141-fe8f-4cdf-9d7d-54415490a917'); }); - it('Check if refresh_count param is incremented', function() { - const request = spec.buildRequests(bidRequestData); - expect(JSON.parse(request[0].data).ext.nextMillennium.refresh_count).to.equal(3); - }); - - it('Test getUserSyncs function', function () { - const syncOptions = { - 'iframeEnabled': true - } - const userSync = spec.getUserSyncs(syncOptions); - expect(userSync).to.be.an('array').with.lengthOf(1); - expect(userSync[0].type).to.exist; - expect(userSync[0].url).to.exist; - expect(userSync[0].type).to.be.equal('iframe'); - expect(userSync[0].url).to.be.equal('https://statics.nextmillmedia.com/load-cookie.html?v=4'); - }); - it('validate_response_params', function() { const serverResponse = { body: { diff --git a/test/spec/modules/nextrollBidAdapter_spec.js b/test/spec/modules/nextrollBidAdapter_spec.js deleted file mode 100644 index 4699fbc6e08..00000000000 --- a/test/spec/modules/nextrollBidAdapter_spec.js +++ /dev/null @@ -1,290 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/nextrollBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { deepClone } from '../../../src/utils'; - -describe('nextrollBidAdapter', function() { - let utilsMock; - beforeEach(function () { - utilsMock = sinon.mock(utils); - }); - - afterEach(function() { - global.NextRoll = undefined; - utilsMock.restore(); - }); - - let validBid = { - bidder: 'nextroll', - adUnitCode: 'adunit-code', - bidId: 'bid_id', - sizes: [[300, 200]], - params: { - bidfloor: 1, - zoneId: 'zone1', - publisherId: 'publisher_id' - } - }; - let bidWithoutValidId = { id: '' }; - let bidWithoutId = { params: { zoneId: 'zone1' } }; - - describe('nativeBidRequest', () => { - it('validates native spec', () => { - let nativeAdUnit = [{ - bidder: 'nextroll', - adUnitCode: 'adunit-code', - bidId: 'bid_id', - mediaTypes: { - native: { - title: {required: true, len: 80}, - image: {required: true, sizes: [728, 90]}, - sponsoredBy: {required: false, len: 20}, - clickUrl: {required: true}, - body: {required: true, len: 25}, - icon: {required: true, sizes: [50, 50], aspect_ratios: [{ratio_height: 3, ratio_width: 4}]}, - someRandomAsset: {required: false, len: 100} // This should be ignored - } - }, - params: { - bidfloor: 1, - zoneId: 'zone1', - publisherId: 'publisher_id' - } - }]; - - let request = spec.buildRequests(nativeAdUnit) - let assets = request[0].data.imp.native.request.native.assets - - let excptedAssets = [ - {id: 1, required: 1, title: {len: 80}}, - {id: 2, required: 1, img: {w: 728, h: 90, wmin: 1, hmin: 1, type: 3}}, - {id: 3, required: 1, img: {w: 50, h: 50, wmin: 4, hmin: 3, type: 1}}, - {id: 5, required: 0, data: {len: 20, type: 1}}, - {id: 6, required: 1, data: {len: 25, type: 2}} - ] - expect(assets).to.be.deep.equal(excptedAssets) - }) - }) - - describe('isBidRequestValid', function() { - it('validates the bids correctly when the bid has an id', function() { - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('validates the bids correcly when the bid does not have an id', function() { - expect(spec.isBidRequestValid(bidWithoutValidId)).to.be.false; - expect(spec.isBidRequestValid(bidWithoutId)).to.be.false; - }); - }); - - describe('buildRequests', function() { - it('builds the same amount of requests as valid requests it takes', function() { - expect(spec.buildRequests([validBid, validBid], {})).to.be.lengthOf(2); - }); - - it('doest not build a request when there is no valid requests', function () { - expect(spec.buildRequests([], {})).to.be.lengthOf(0); - }); - - it('builds a request with POST method', function () { - expect(spec.buildRequests([validBid], {})[0].method).to.equal('POST'); - }); - - it('builds a request with cookies method', function () { - expect(spec.buildRequests([validBid], {})[0].options.withCredentials).to.be.true; - }); - - it('builds a request with id, url and imp object', function () { - const request = spec.buildRequests([validBid], {})[0]; - expect(request.data.id).to.be.an('string').that.is.not.empty; - expect(request.url).to.equal('https://d.adroll.com/bid/prebid/'); - expect(request.data.imp).to.exist.and.to.be.a('object'); - }); - - it('builds a request with site and device information', function () { - const request = spec.buildRequests([validBid], {})[0]; - - expect(request.data.site).to.exist.and.to.be.a('object'); - expect(request.data.device).to.exist.and.to.be.a('object'); - }); - - it('builds a request with a complete imp object', function () { - const request = spec.buildRequests([validBid], {})[0]; - - expect(request.data.imp.id).to.equal('bid_id'); - expect(request.data.imp.bidfloor).to.be.equal(1); - expect(request.data.imp.banner).to.exist.and.to.be.a('object'); - expect(request.data.imp.ext.zone.id).to.be.equal('zone1'); - }); - - it('builds a request with the correct floor object', function () { - // bidfloor is defined, getFloor isn't - let bid = deepClone(validBid); - let request = spec.buildRequests([bid], {})[0]; - expect(request.data.imp.bidfloor).to.be.equal(1); - - // bidfloor not defined, getFloor not defined - bid = deepClone(validBid); - bid.params.bidfloor = null; - request = spec.buildRequests([bid], {})[0]; - expect(request.data.imp.bidfloor).to.not.exist; - - // bidfloor defined, getFloor defined, use getFloor - let getFloorResponse = { currency: 'USD', floor: 3 }; - bid = deepClone(validBid); - bid.getFloor = () => getFloorResponse; - request = spec.buildRequests([bid], {})[0]; - - expect(request.data.imp.bidfloor).to.exist.and.to.equal(3); - }); - - it('includes the sizes into the request correctly', function () { - const bannerObject = spec.buildRequests([validBid], {})[0].data.imp.banner; - - expect(bannerObject.format).to.exist; - expect(bannerObject.format).to.be.lengthOf(1); - expect(bannerObject.format[0].w).to.be.equal(300); - expect(bannerObject.format[0].h).to.be.equal(200); - }); - - it('sets the CCPA consent string', function () { - const us_privacy = '1YYY'; - const request = spec.buildRequests([validBid], {'uspConsent': us_privacy})[0]; - - expect(request.data.regs.ext.us_privacy).to.be.equal(us_privacy); - }); - }); - - describe('interpretResponse', function () { - let responseBody = { - id: 'bidresponse_id', - dealId: 'deal_id', - seatbid: [ - { - bid: [ - { - price: 1.2, - w: 300, - h: 200, - crid: 'crid1', - adm: 'adm1' - } - ] - }, - { - bid: [ - { - price: 2.1, - w: 250, - h: 300, - crid: 'crid2', - adm: 'adm2' - } - ] - } - ] - }; - - it('returns an empty list when there is no response body', function () { - expect(spec.interpretResponse({}, {})).to.be.eql([]); - }); - - it('builds the same amount of responses as server responses it receives', function () { - expect(spec.interpretResponse({body: responseBody}, {})).to.be.lengthOf(2); - }); - - it('builds a response with the expected fields', function () { - const response = spec.interpretResponse({body: responseBody}, {})[0]; - - expect(response.requestId).to.be.equal('bidresponse_id'); - expect(response.cpm).to.be.equal(1.2); - expect(response.width).to.be.equal(300); - expect(response.height).to.be.equal(200); - expect(response.creativeId).to.be.equal('crid1'); - expect(response.dealId).to.be.equal('deal_id'); - expect(response.currency).to.be.equal('USD'); - expect(response.netRevenue).to.be.equal(true); - expect(response.ttl).to.be.equal(300); - expect(response.ad).to.be.equal('adm1'); - }); - }); - - describe('interpret native response', () => { - let clickUrl = 'https://clickurl.com/with/some/path' - let titleText = 'Some title' - let imgW = 300 - let imgH = 250 - let imgUrl = 'https://clickurl.com/img.png' - let brandText = 'Some Brand' - let impUrl = 'https://clickurl.com/imptracker' - - let responseBody = { - body: { - id: 'bidresponse_id', - seatbid: [{ - bid: [{ - price: 1.2, - crid: 'crid1', - adm: { - link: {url: clickUrl}, - assets: [ - {id: 1, title: {text: titleText}}, - {id: 2, img: {w: imgW, h: imgH, url: imgUrl}}, - {id: 5, data: {value: brandText}} - ], - imptrackers: [impUrl] - } - }] - }] - } - }; - - it('Should interpret response', () => { - let response = spec.interpretResponse(utils.deepClone(responseBody)) - let expectedResponse = { - clickUrl: clickUrl, - impressionTrackers: [impUrl], - privacyLink: 'https://info.evidon.com/pub_info/573', - privacyIcon: 'https://c.betrad.com/pub/icon1.png', - title: titleText, - image: {url: imgUrl, width: imgW, height: imgH}, - sponsoredBy: brandText, - clickTrackers: [], - jstracker: [] - } - - expect(response[0].native).to.be.deep.equal(expectedResponse) - }) - - it('Should interpret all assets', () => { - let allAssetsResponse = utils.deepClone(responseBody) - let iconUrl = imgUrl + '?icon=true', iconW = 10, iconH = 15 - let logoUrl = imgUrl + '?logo=true', logoW = 20, logoH = 25 - let bodyText = 'Some body text' - - allAssetsResponse.body.seatbid[0].bid[0].adm.assets.push(...[ - {id: 3, img: {w: iconW, h: iconH, url: iconUrl}}, - {id: 4, img: {w: logoW, h: logoH, url: logoUrl}}, - {id: 6, data: {value: bodyText}} - ]) - - let response = spec.interpretResponse(allAssetsResponse) - let expectedResponse = { - clickUrl: clickUrl, - impressionTrackers: [impUrl], - jstracker: [], - clickTrackers: [], - privacyLink: 'https://info.evidon.com/pub_info/573', - privacyIcon: 'https://c.betrad.com/pub/icon1.png', - title: titleText, - image: {url: imgUrl, width: imgW, height: imgH}, - icon: {url: iconUrl, width: iconW, height: iconH}, - logo: {url: logoUrl, width: logoW, height: logoH}, - body: bodyText, - sponsoredBy: brandText - } - - expect(response[0].native).to.be.deep.equal(expectedResponse) - }) - }) -}); diff --git a/test/spec/modules/nobidBidAdapter_spec.js b/test/spec/modules/nobidBidAdapter_spec.js index eccf0e84031..f775e439a80 100644 --- a/test/spec/modules/nobidBidAdapter_spec.js +++ b/test/spec/modules/nobidBidAdapter_spec.js @@ -2,7 +2,6 @@ import { expect } from 'chai'; import * as utils from 'src/utils.js'; import { spec } from 'modules/nobidBidAdapter.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; import * as bidderFactory from 'src/adapters/bidderFactory.js'; describe('Nobid Adapter', function () { @@ -51,70 +50,6 @@ describe('Nobid Adapter', function () { }); }); - describe('Request with ORTB2', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const BIDDER_CODE = 'duration'; - let bidRequests = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - let bidderRequest = { - refererInfo: {referer: REFERER}, bidderCode: BIDDER_CODE - } - - const siteName = 'example'; - const siteDomain = 'page.example.com'; - const sitePage = 'https://page.example.com/here.html'; - const siteRef = 'https://ref.example.com'; - const siteKeywords = 'power tools, drills'; - const siteSearch = 'drill'; - const siteCat = 'IAB2'; - const siteSectionCat = 'IAB2-2'; - const sitePageCat = 'IAB2-12'; - - it('ortb2 should exist', function () { - config.setConfig({ - ortb2: { - site: { - name: siteName, - domain: siteDomain, - cat: [ siteCat ], - sectioncat: [ siteSectionCat ], - pagecat: [ sitePageCat ], - page: sitePage, - ref: siteRef, - keywords: siteKeywords, - search: siteSearch - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - let payload = JSON.parse(request.data); - payload = JSON.parse(JSON.stringify(payload)); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.ortb2.site.name).to.equal(siteName); - expect(payload.ortb2.site.domain).to.equal(siteDomain); - expect(payload.ortb2.site.page).to.equal(sitePage); - expect(payload.ortb2.site.ref).to.equal(siteRef); - expect(payload.ortb2.site.keywords).to.equal(siteKeywords); - expect(payload.ortb2.site.search).to.equal(siteSearch); - expect(payload.ortb2.site.cat[0]).to.equal(siteCat); - expect(payload.ortb2.site.sectioncat[0]).to.equal(siteSectionCat); - expect(payload.ortb2.site.pagecat[0]).to.equal(sitePageCat); - }); - }); - describe('isDurationBidRequestValid', function () { const SITE_ID = 2; const REFERER = 'https://www.examplereferer.com'; @@ -320,6 +255,7 @@ describe('Nobid Adapter', function () { expect(payload.a).to.exist; expect(payload.t).to.exist; expect(payload.tz).to.exist; + expect(payload.r).to.exist.and.to.equal('100x100'); expect(payload.lang).to.exist; expect(payload.ref).to.exist; expect(payload.a[0].d).to.exist.and.to.equal('adunit-code'); diff --git a/test/spec/modules/oguryBidAdapter_spec.js b/test/spec/modules/oguryBidAdapter_spec.js index 225d0cd30ef..0a57690db27 100644 --- a/test/spec/modules/oguryBidAdapter_spec.js +++ b/test/spec/modules/oguryBidAdapter_spec.js @@ -1,9 +1,8 @@ import { expect } from 'chai'; import { spec } from 'modules/oguryBidAdapter'; -import * as utils from 'src/utils.js'; +import { deepClone } from 'src/utils.js'; -const BID_URL = 'https://mweb-hb.presage.io/api/header-bidding-request'; -const TIMEOUT_URL = 'https://ms-ads-monitoring-events.presage.io/bid_timeout' +const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request'; describe('OguryBidAdapter', function () { let bidRequests; @@ -68,14 +67,14 @@ describe('OguryBidAdapter', function () { describe('isBidRequestValid', function () { it('should validate correct bid', () => { - let validBid = utils.deepClone(bidRequests[0]); + let validBid = deepClone(bidRequests[0]); let isValid = spec.isBidRequestValid(validBid); expect(isValid).to.equal(true); }); it('should not validate incorrect bid', () => { - let invalidBid = utils.deepClone(bidRequests[0]); + let invalidBid = deepClone(bidRequests[0]); delete invalidBid.sizes; delete invalidBid.mediaTypes; @@ -84,7 +83,7 @@ describe('OguryBidAdapter', function () { }); it('should not validate bid if adunit is not present', () => { - let invalidBid = utils.deepClone(bidRequests[0]); + let invalidBid = deepClone(bidRequests[0]); delete invalidBid.params.adUnitId; let isValid = spec.isBidRequestValid(invalidBid); @@ -92,7 +91,7 @@ describe('OguryBidAdapter', function () { }); it('should not validate bid if assetKet is not present', () => { - let invalidBid = utils.deepClone(bidRequests[0]); + let invalidBid = deepClone(bidRequests[0]); delete invalidBid.params.assetKey; let isValid = spec.isBidRequestValid(invalidBid); @@ -100,7 +99,7 @@ describe('OguryBidAdapter', function () { }); it('should validate bid if getFloor is not present', () => { - let invalidBid = utils.deepClone(bidRequests[1]); + let invalidBid = deepClone(bidRequests[1]); delete invalidBid.getFloor; let isValid = spec.isBidRequestValid(invalidBid); @@ -119,110 +118,28 @@ describe('OguryBidAdapter', function () { }; }); - it('should return syncs array with two elements of type image', () => { + it('should return syncs array with an element of type image', () => { const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); + expect(userSyncs).to.have.lengthOf(1); expect(userSyncs[0].type).to.equal('image'); expect(userSyncs[0].url).to.contain('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.contain('https://ms-cookie-sync.presage.io/ttd/init-sync'); }); it('should set the source as query param', () => { const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); expect(userSyncs[0].url).to.contain('source=prebid'); - expect(userSyncs[1].url).to.contain('source=prebid'); }); it('should set the tcString as query param', () => { const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); expect(userSyncs[0].url).to.contain(`iab_string=${gdprConsent.consentString}`); - expect(userSyncs[1].url).to.contain(`iab_string=${gdprConsent.consentString}`); }); it('should return an empty array when pixel is disable', () => { syncOptions.pixelEnabled = false; expect(spec.getUserSyncs(syncOptions, [], gdprConsent)).to.have.lengthOf(0); }); - - it('should return syncs array with two elements of type image when consentString is undefined', () => { - gdprConsent = { - gdprApplies: true, - consentString: undefined - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); - - it('should return syncs array with two elements of type image when consentString is null', () => { - gdprConsent = { - gdprApplies: true, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); - - it('should return syncs array with two elements of type image when gdprConsent is undefined', () => { - gdprConsent = undefined; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); - - it('should return syncs array with two elements of type image when gdprConsent is null', () => { - gdprConsent = null; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); - - it('should return syncs array with two elements of type image when gdprConsent is null and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); - - it('should return syncs array with two elements of type image when gdprConsent is empty string and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: '' - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(2); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid') - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.equal('https://ms-cookie-sync.presage.io/ttd/init-sync?iab_string=&source=prebid') - }); }); describe('buildRequests', function () { @@ -240,8 +157,7 @@ describe('OguryBidAdapter', function () { w: 300, h: 250 }] - }, - ext: bidRequests[0].params + } }, { id: bidRequests[1].bidId, tagid: bidRequests[1].params.adUnitId, @@ -251,8 +167,7 @@ describe('OguryBidAdapter', function () { w: 600, h: 500 }] - }, - ext: bidRequests[1].params + } }], regs: { ext: { @@ -262,29 +177,24 @@ describe('OguryBidAdapter', function () { site: { id: bidRequests[0].params.assetKey, domain: window.location.hostname, - page: window.location.href }, user: { ext: { consent: bidderRequest.gdprConsent.consentString }, - }, - ext: { - prebidversion: '$prebid.version$', - adapterversion: '1.2.7' } }; it('sends bid request to ENDPOINT via POST', function () { - const validBidRequests = utils.deepClone(bidRequests) + const validBidRequests = deepClone(bidRequests) const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.url).to.equal(BID_URL); + expect(request.url).to.equal(BID_HOST); expect(request.method).to.equal('POST'); }); it('bid request object should be conform', function () { - const validBidRequests = utils.deepClone(bidRequests) + const validBidRequests = deepClone(bidRequests) const request = spec.buildRequests(validBidRequests, bidderRequest); expect(request.data).to.deep.equal(expectedRequestObject); @@ -322,7 +232,7 @@ describe('OguryBidAdapter', function () { ...expectedRequestObject }; - const validBidRequests = utils.deepClone(bidRequests); + const validBidRequests = deepClone(bidRequests); validBidRequests[1] = { ...validBidRequests[1], getFloor: undefined @@ -337,7 +247,7 @@ describe('OguryBidAdapter', function () { ...expectedRequestObject }; - let validBidRequests = utils.deepClone(bidRequests); + let validBidRequests = deepClone(bidRequests); validBidRequests[1] = { ...validBidRequests[1], getFloor: 'getFloor' @@ -348,9 +258,9 @@ describe('OguryBidAdapter', function () { }); it('should handle bidFloor when currency is not USD', () => { - const expectedRequestWithUnsupportedFloorCurrency = utils.deepClone(expectedRequestObject) + const expectedRequestWithUnsupportedFloorCurrency = deepClone(expectedRequestObject) expectedRequestWithUnsupportedFloorCurrency.imp[0].bidfloor = 0; - let validBidRequests = utils.deepClone(bidRequests); + let validBidRequests = deepClone(bidRequests); validBidRequests[0] = { ...validBidRequests[0], getFloor: ({ size, currency, mediaType }) => { @@ -429,9 +339,7 @@ describe('OguryBidAdapter', function () { meta: { advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[0].adomain }, - nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl, - adapterVersion: '1.2.7', - prebidVersion: '$prebid.version$' + nurl: openRtbBidResponse.body.seatbid[0].bid[0].nurl }, { requestId: openRtbBidResponse.body.seatbid[0].bid[1].impid, cpm: openRtbBidResponse.body.seatbid[0].bid[1].price, @@ -446,9 +354,7 @@ describe('OguryBidAdapter', function () { meta: { advertiserDomains: openRtbBidResponse.body.seatbid[0].bid[1].adomain }, - nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl, - adapterVersion: '1.2.7', - prebidVersion: '$prebid.version$' + nurl: openRtbBidResponse.body.seatbid[0].bid[1].nurl }] let request = spec.buildRequests(bidRequests, bidderRequest); @@ -481,11 +387,11 @@ describe('OguryBidAdapter', function () { }) afterEach(function() { - xhr.restore() + xhr.restore(); }) it('Should not create nurl request if bid is undefined', function() { - spec.onBidWon() + spec.onBidWon(); expect(requests.length).to.equal(0); }) @@ -500,75 +406,5 @@ describe('OguryBidAdapter', function () { expect(requests[0].url).to.equal(nurl); expect(requests[0].method).to.equal('GET') }) - - it('Should trigger getWindowContext method', function() { - const bidSample = { - id: 'advertId', - impid: 'bidId', - price: 100, - nurl: 'url', - adm: `test creative
cookies
`, - adomain: ['renault.fr'], - ext: { - adcontent: 'sample_creative', - advertid: '1a278c48-b79a-4bbf-b69f-3824803e7d87', - campaignid: '31724', - mediatype: 'image', - userid: 'ab4aabed-5230-49d9-9f1a-f06280d28366', - usersync: true, - advertiserid: '1', - isomidcompliant: false - }, - w: 180, - h: 101 - } - spec.onBidWon(bidSample) - expect(window.top.OG_PREBID_BID_OBJECT).to.deep.equal(bidSample) - }) }) - - describe('getWindowContext', function() { - it('Should return top window if exist', function() { - const res = spec.getWindowContext() - expect(res).to.equal(window.top) - expect(res).to.not.be.undefined; - }) - - it('Should return self window if getting top window throw an error', function() { - const stub = sinon.stub(utils, 'getWindowTop') - stub.throws() - const res = spec.getWindowContext() - expect(res).to.equal(window.self) - utils.getWindowTop.restore() - }) - }) - - describe('onTimeout', function () { - let xhr; - let requests; - - beforeEach(function() { - xhr = sinon.useFakeXMLHttpRequest(); - requests = []; - xhr.onCreate = (xhr) => { - requests.push(xhr); - }; - }) - - afterEach(function() { - xhr.restore() - }) - - it('should send on bid timeout notification', function() { - const bid = { - ad: 'cookies', - cpm: 3 - } - spec.onTimeout(bid); - expect(requests).to.not.be.undefined; - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal(TIMEOUT_URL); - expect(requests[0].method).to.equal('POST'); - }) - }); }); diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js index e873597ca15..9fb73f7774b 100644 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ b/test/spec/modules/onetagBidAdapter_spec.js @@ -191,8 +191,12 @@ describe('onetag', function () { 'pubId', 'transactionId', 'context', + 'mimes', 'playerSize', - 'mediaTypeInfo', + 'protocols', + 'maxDuration', + 'api', + 'playbackmethod', 'type' ); } else if (isValid(BANNER, bid)) { @@ -203,7 +207,6 @@ describe('onetag', function () { 'bidderRequestId', 'pubId', 'transactionId', - 'mediaTypeInfo', 'sizes', 'type' ); diff --git a/test/spec/modules/openxBidAdapter_spec.js b/test/spec/modules/openxBidAdapter_spec.js index 3bc53e30eb8..96e545d70fa 100644 --- a/test/spec/modules/openxBidAdapter_spec.js +++ b/test/spec/modules/openxBidAdapter_spec.js @@ -1085,7 +1085,7 @@ describe('OpenxAdapter', function () { intentIqId: '1111-intentiqid', lipb: {lipbid: '1111-lipb'}, lotamePanoramaId: '1111-lotameid', - merkleId: {id: '1111-merkleid'}, + merkleId: '1111-merkleid', netId: 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', parrableId: { eid: 'eidVersion.encryptionKeyReference.encryptedValue' }, pubcid: '1111-pubcid', @@ -1102,11 +1102,6 @@ describe('OpenxAdapter', function () { mwOpenLinkId: '1111-mwopenlinkid', dapId: '1111-dapId', amxId: '1111-amxid', - kpuid: '1111-kpuid', - publinkId: '1111-publinkid', - naveggId: '1111-naveggid', - imuid: '1111-imuid', - adtelligentId: '1111-adtelligentid' }; // generates the same set of tests for each id provider @@ -1144,9 +1139,6 @@ describe('OpenxAdapter', function () { let userIdValue; // handle cases where userId key refers to an object switch (userIdProviderKey) { - case 'merkleId': - userIdValue = EXAMPLE_DATA_BY_ATTR.merkleId.id; - break; case 'flocId': userIdValue = EXAMPLE_DATA_BY_ATTR.flocId.id; break; @@ -1553,7 +1545,7 @@ describe('OpenxAdapter', function () { describe('with segments', function () { const TESTS = [ { - name: 'should send proprietary segment data from ortb2.user.data', + name: 'should send proprietary segment data from first party config', config: { ortb2: { user: { @@ -1564,51 +1556,10 @@ describe('OpenxAdapter', function () { } } }, - expect: {sm: 'dmp1/4:foo|bar,dmp2:baz'}, + expect: 'dmp1/4:foo|bar,dmp2:baz', }, { - name: 'should send proprietary segment data from ortb2.site.content.data', - config: { - ortb2: { - site: { - content: { - data: [ - {name: 'dmp1', ext: {segtax: 4}, segment: [{id: 'foo'}, {id: 'bar'}]}, - {name: 'dmp2', segment: [{id: 'baz'}]}, - ] - } - } - } - }, - expect: {scsm: 'dmp1/4:foo|bar,dmp2:baz'}, - }, - { - name: 'should send proprietary segment data from both ortb2.site.content.data and ortb2.user.data', - config: { - ortb2: { - user: { - data: [ - {name: 'dmp1', ext: {segtax: 4}, segment: [{id: 'foo'}, {id: 'bar'}]}, - {name: 'dmp2', segment: [{id: 'baz'}]}, - ] - }, - site: { - content: { - data: [ - {name: 'dmp3', ext: {segtax: 5}, segment: [{id: 'foo2'}, {id: 'bar2'}]}, - {name: 'dmp4', segment: [{id: 'baz2'}]}, - ] - } - } - } - }, - expect: { - sm: 'dmp1/4:foo|bar,dmp2:baz', - scsm: 'dmp3/5:foo2|bar2,dmp4:baz2' - }, - }, - { - name: 'should combine same provider segment data from ortb2.user.data', + name: 'should combine same provider segment data from first party config', config: { ortb2: { user: { @@ -1619,23 +1570,7 @@ describe('OpenxAdapter', function () { } } }, - expect: {sm: 'dmp1/4:foo|bar,dmp1:baz'}, - }, - { - name: 'should combine same provider segment data from ortb2.site.content.data', - config: { - ortb2: { - site: { - content: { - data: [ - {name: 'dmp1', ext: {segtax: 4}, segment: [{id: 'foo'}, {id: 'bar'}]}, - {name: 'dmp1', ext: {}, segment: [{id: 'baz'}]}, - ] - } - } - } - }, - expect: {scsm: 'dmp1/4:foo|bar,dmp1:baz'}, + expect: 'dmp1/4:foo|bar,dmp1:baz', }, { name: 'should not send any segment data if first party config is incomplete', @@ -1660,14 +1595,6 @@ describe('OpenxAdapter', function () { {name: 'dmp1', segment: [{id: 'foo'}, {id: 'bar'}]}, {name: 'dmp2', segment: [{id: 'baz'}]}, ] - }, - site: { - content: { - data: [ - {name: 'dmp3', ext: {segtax: 5}, segment: [{id: 'foo2'}, {id: 'bar2'}]}, - {name: 'dmp4', segment: [{id: 'baz2'}]}, - ] - } } } }, @@ -1679,10 +1606,7 @@ describe('OpenxAdapter', function () { }, }, }, - expect: { - sm: 'dmp1:foo|bar,dmp2:baz,liveintent:l1|l2', - scsm: 'dmp3/5:foo2|bar2,dmp4:baz2' - }, + expect: 'dmp1:foo|bar,dmp2:baz,liveintent:l1|l2', }, { name: 'should send just liveintent segment from request if no first party config', @@ -1695,7 +1619,7 @@ describe('OpenxAdapter', function () { }, }, }, - expect: {sm: 'liveintent:l1|l2'}, + expect: 'liveintent:l1|l2', }, { name: 'should send nothing if lipb section does not contain segments', @@ -1712,11 +1636,13 @@ describe('OpenxAdapter', function () { utils._each(TESTS, (t) => { context('in ortb2.user.data', function () { let bidRequests; + let configStub; + beforeEach(function () { let fpdConfig = t.config - sinon + configStub = sinon .stub(config, 'getConfig') - .withArgs(sinon.match(/^ortb2\.user\.data$|^ortb2\.site\.content\.data$/)) + .withArgs('ortb2.user.data') .callsFake((key) => { return utils.deepAccess(fpdConfig, key); }); @@ -1732,13 +1658,10 @@ describe('OpenxAdapter', function () { const request = spec.buildRequests(bidRequests, mockBidderRequest) expect(request.length).to.equal(1); if (t.expect) { - for (const key in t.expect) { - expect(request[0].data[key]).to.exist; - expect(request[0].data[key]).to.equal(t.expect[key]); - } + expect(request[0].data.sm).to.exist; + expect(request[0].data.sm).to.equal(encodeURIComponent(t.expect)); } else { expect(request[0].data.sm).to.not.exist; - expect(request[0].data.scsm).to.not.exist; } }); }); diff --git a/test/spec/modules/operaadsBidAdapter_spec.js b/test/spec/modules/operaadsBidAdapter_spec.js index 849a3eada3f..92e51c5473d 100644 --- a/test/spec/modules/operaadsBidAdapter_spec.js +++ b/test/spec/modules/operaadsBidAdapter_spec.js @@ -266,7 +266,7 @@ describe('Opera Ads Bid Adapter', function () { } }); - it('test getBidFloor', function() { + it('currency in params should be used', function () { const bidRequests = [ { adUnitCode: 'test-div', @@ -276,13 +276,8 @@ describe('Opera Ads Bid Adapter', function () { params: { placementId: 's12345678', publisherId: 'pub12345678', - endpointId: 'ep12345678' - }, - getFloor: function() { - return { - currency: 'USD', - floor: 0.1 - } + endpointId: 'ep12345678', + currency: 'RMB' } } ]; @@ -297,9 +292,7 @@ describe('Opera Ads Bid Adapter', function () { requestData = JSON.parse(req.data); }).to.not.throw(); - expect(requestData.imp).to.be.an('array').that.have.lengthOf(1); - expect(requestData.imp[0].bidfloor).to.be.equal(0.1); - expect(requestData.imp[0].bidfloorcur).to.be.equal('USD'); + expect(requestData.cur).to.be.an('array').that.includes('RMB'); } }); @@ -369,7 +362,7 @@ describe('Opera Ads Bid Adapter', function () { requestData = JSON.parse(reqs[0].data); }).to.not.throw(); - expect(requestData.user.buyeruid).to.equal(bidRequests[0].userId.sharedid.id); + expect(requestData.user.id).to.equal(bidRequests[0].userId.sharedid.id); }); it('pubcid should be used when sharedid is empty', function () { @@ -406,7 +399,7 @@ describe('Opera Ads Bid Adapter', function () { requestData = JSON.parse(reqs[0].data); }).to.not.throw(); - expect(requestData.user.buyeruid).to.equal(bidRequests[0].userId.pubcid); + expect(requestData.user.id).to.equal(bidRequests[0].userId.pubcid); }); it('random uid will be generate when userId is empty', function () { @@ -433,7 +426,7 @@ describe('Opera Ads Bid Adapter', function () { requestData = JSON.parse(reqs[0].data); }).to.not.throw(); - expect(requestData.user.buyeruid).to.not.be.empty; + expect(requestData.user.id).to.not.be.empty; }) }); @@ -679,41 +672,9 @@ describe('Opera Ads Bid Adapter', function () { }); }); - describe('Test getUserSyncs with both iframe and pixel disabled', function () { - it('getUserSyncs should return an empty array', function () { - const syncOptions = {}; - expect(spec.getUserSyncs(syncOptions)).to.be.an('array').that.is.empty; - }); - }); - - describe('Test getUserSyncs with iframe enabled', function () { - it('getUserSyncs should return array', function () { - const syncOptions = { - iframeEnabled: true - } - const userSyncPixels = spec.getUserSyncs(syncOptions) - expect(userSyncPixels).to.have.lengthOf(1); - expect(userSyncPixels[0].url).to.equal('https://s.adx.opera.com/usersync/page') - }); - }); - - describe('Test getUserSyncs with pixel enabled', function () { - it('getUserSyncs should return array', function () { - const serverResponse = { - body: { - 'pixels': [ - 'https://b1.com/usersync', - 'https://b2.com/usersync' - ] - } - }; - const syncOptions = { - pixelEnabled: true - } - const userSyncPixels = spec.getUserSyncs(syncOptions, [serverResponse]) - expect(userSyncPixels).to.have.lengthOf(2); - expect(userSyncPixels[0].url).to.equal('https://b1.com/usersync') - expect(userSyncPixels[1].url).to.equal('https://b2.com/usersync') + describe('Test getUserSyncs', function () { + it('getUserSyncs should return empty array', function () { + expect(spec.getUserSyncs()).to.be.an('array').that.is.empty; }); }); diff --git a/test/spec/modules/optimeraRtdProvider_spec.js b/test/spec/modules/optimeraRtdProvider_spec.js index 7883412ab70..8b1866d044a 100644 --- a/test/spec/modules/optimeraRtdProvider_spec.js +++ b/test/spec/modules/optimeraRtdProvider_spec.js @@ -35,30 +35,17 @@ describe('Optimera RTD score file properly sets targeting values', () => { 'de': { 'div-0': ['A5', 'A6'], 'div-1': ['A7', 'A8'], - 'insights': { - 'ilv': ['div-0'], - 'miv': ['div-4'], - } }, 'mo': { 'div-0': ['A9', 'B0'], 'div-1': ['B1', 'B2'], - 'insights': { - 'ilv': ['div-1'], - 'miv': ['div-2'], - } } - }, - 'insights': { - 'ilv': ['div-5'], - 'miv': ['div-6'], } }; - it('Properly set the score file url and scores', () => { + it('Properly set the score file url', () => { optimeraRTD.setScores(JSON.stringify(scores)); expect(optimeraRTD.optimeraTargeting['div-0']).to.include.ordered.members(['A5', 'A6']); expect(optimeraRTD.optimeraTargeting['div-1']).to.include.ordered.members(['A7', 'A8']); - expect(window.optimeraInsights.data['ilv']).to.include.ordered.members(['div-0']); }); }); diff --git a/test/spec/modules/otmBidAdapter_spec.js b/test/spec/modules/otmBidAdapter_spec.js deleted file mode 100644 index 6eb5768c3af..00000000000 --- a/test/spec/modules/otmBidAdapter_spec.js +++ /dev/null @@ -1,67 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/otmBidAdapter'; - -describe('otmBidAdapter', function () { - it('validate_pub_params', function () { - expect(spec.isBidRequestValid({ - bidder: 'otm', - params: { - tid: '123', - bidfloor: 20 - } - })).to.equal(true); - }); - - it('validate_generated_params', function () { - let bidRequestData = [{ - bidId: 'bid1234', - bidder: 'otm', - params: { - tid: '123', - bidfloor: 20 - }, - sizes: [[240, 400]] - }]; - - let request = spec.buildRequests(bidRequestData); - let req_data = request[0].data; - - expect(req_data.bidid).to.equal('bid1234'); - }); - - it('validate_response_params', function () { - let bidRequestData = { - data: { - bidId: 'bid1234' - } - }; - - let serverResponse = { - body: [ - { - 'auctionid': '3c6f8e22-541b-485c-9214-e974d9fb1b6f', - 'cpm': 847.097, - 'ad': 'test html', - 'w': 240, - 'h': 400, - 'currency': 'RUB', - 'ttl': 300, - 'creativeid': '1_7869053', - 'bidid': '101f211def7c99', - 'transactionid': 'transaction_id_1' - } - ] - }; - - let bids = spec.interpretResponse(serverResponse, bidRequestData); - expect(bids).to.have.lengthOf(1); - let bid = bids[0]; - expect(bid.cpm).to.equal(847.097); - expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal(240); - expect(bid.height).to.equal(400); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('101f211def7c99'); - expect(bid.ad).to.equal('test html'); - }); -}); diff --git a/test/spec/modules/outbrainBidAdapter_spec.js b/test/spec/modules/outbrainBidAdapter_spec.js index 4bc163aefe6..a5f23240a7c 100644 --- a/test/spec/modules/outbrainBidAdapter_spec.js +++ b/test/spec/modules/outbrainBidAdapter_spec.js @@ -2,7 +2,6 @@ import {expect} from 'chai'; import {spec} from 'modules/outbrainBidAdapter.js'; import {config} from 'src/config.js'; import {server} from 'test/mocks/xhr'; -import { createEidsArray } from 'modules/userId/eids.js'; describe('Outbrain Adapter', function () { describe('Bid request and response', function () { @@ -345,23 +344,6 @@ describe('Outbrain Adapter', function () { config.resetConfig() }); - - it('should pass extended ids', function () { - let bidRequest = { - bidId: 'bidId', - params: {}, - userIdAsEids: createEidsArray({ - idl_env: 'id-value', - }), - ...commonBidRequest, - }; - - let res = spec.buildRequests([bidRequest], commonBidderRequest); - const resData = JSON.parse(res.data) - expect(resData.user.ext.eids).to.deep.equal([ - {source: 'liveramp.com', uids: [{id: 'id-value', atype: 3}]} - ]); - }); }) describe('interpretResponse', function () { diff --git a/test/spec/modules/ozoneBidAdapter_spec.js b/test/spec/modules/ozoneBidAdapter_spec.js index 658af310ea5..f9941b41189 100644 --- a/test/spec/modules/ozoneBidAdapter_spec.js +++ b/test/spec/modules/ozoneBidAdapter_spec.js @@ -69,6 +69,8 @@ var validBidRequestsMulti = [ transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' } ]; +// use 'pubcid', 'tdid', 'id5id', 'parrableId', 'idl_env', 'criteoId' +// see http://prebid.org/dev-docs/modules/userId.html var validBidRequestsWithUserIdData = [ { adUnitCode: 'div-gpt-ad-1460505748561-0', @@ -289,6 +291,7 @@ var validBidRequests1OutstreamVideo2020 = [ } ]; +// WHEN sent as bidderRequest to buildRequests you should send the child: .bidderRequest var validBidderRequest1OutstreamVideo2020 = { bidderRequest: { auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', @@ -391,6 +394,7 @@ var validBidderRequest1OutstreamVideo2020 = { timeout: 3000 } }; +// WHEN sent as bidderRequest to buildRequests you should send the child: .bidderRequest var validBidderRequest = { bidderRequest: { auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', @@ -415,6 +419,11 @@ var validBidderRequest = { } }; +// bidder request with GDPR - change the values for testing: +// gdprConsent.gdprApplies (true/false) +// gdprConsent.vendorData.purposeConsents (make empty, make null, remove it) +// gdprConsent.vendorData.vendorConsents (remove 524, remove all, make the element null, remove it) +// WHEN sent as bidderRequest to buildRequests you should send the child: .bidderRequest var bidderRequestWithFullGdpr = { bidderRequest: { auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', @@ -503,6 +512,7 @@ var gdpr1 = { 'gdprApplies': true }; +// simulating the Mirror var bidderRequestWithPartialGdpr = { bidderRequest: { auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', @@ -548,6 +558,7 @@ var bidderRequestWithPartialGdpr = { } }; +// make sure the impid matches the request bidId var validResponse = { 'body': { 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', @@ -1102,6 +1113,7 @@ var multiRequest1 = [ } ]; +// WHEN sent as bidderRequest to buildRequests you should send the child: .bidderRequest var multiBidderRequest1 = { bidderRequest: { 'bidderCode': 'ozone', @@ -1495,6 +1507,7 @@ var multiResponse1 = { describe('ozone Adapter', function () { describe('isBidRequestValid', function () { + // A test ad unit that will consistently return test creatives let validBidReq = { bidder: BIDDER_CODE, params: { @@ -1928,6 +1941,7 @@ describe('ozone Adapter', function () { const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest.bidderRequest); expect(request).to.be.a('array'); expect(request[0]).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); + // need to reset the singleRequest config flag: config.setConfig({'ozone': {'singleRequest': true}}); }); @@ -1951,6 +1965,7 @@ describe('ozone Adapter', function () { expect(payload.user.ext.consent).to.equal(consentString); }); + // mirror it('should add gdpr consent information to the request when vendorData is missing vendorConsents (Mirror)', function () { let consentString = 'BOcocyaOcocyaAfEYDENCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NphLgA=='; let bidderRequest = validBidderRequest.bidderRequest; @@ -2003,6 +2018,7 @@ describe('ozone Adapter', function () { }; let bidRequests = validBidRequests; + // values from http://prebid.org/dev-docs/modules/userId.html#pubcommon-id bidRequests[0]['userId'] = { 'digitrustid': {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}}, 'id5id': { uid: '1111', ext: { linkType: 2, abTestingControlGroup: false } }, @@ -2022,11 +2038,13 @@ describe('ozone Adapter', function () { it('should pick up the value of pubcid when built using the pubCommonId module (not userId)', function () { let bidRequests = validBidRequests; + // values from http://prebid.org/dev-docs/modules/userId.html#pubcommon-id bidRequests[0]['userId'] = { 'digitrustid': {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}}, 'id5id': { uid: '1111', ext: { linkType: 2, abTestingControlGroup: false } }, 'idl_env': '3333', 'parrableid': 'eidVersion.encryptionKeyReference.encryptedValue', + // 'pubcid': '5555', // remove pubcid from here to emulate the OLD module & cause the failover code to kick in 'tdid': '6666', 'sharedid': {'id': '01EAJWWNEPN3CYMM5N8M5VXY22', 'third': '01EAJWWNEPN3CYMM5N8M5VXY22'} }; @@ -2152,6 +2170,7 @@ describe('ozone Adapter', function () { }); it('should use oztestmode GET value if set', function() { var specMock = utils.deepClone(spec); + // mock the getGetParametersAsObject function to simulate GET parameters for oztestmode: specMock.getGetParametersAsObject = function() { return {'oztestmode': 'mytestvalue_123'}; }; @@ -2162,6 +2181,7 @@ describe('ozone Adapter', function () { }); it('should pass through GET params if present: ozf, ozpf, ozrp, ozip', function() { var specMock = utils.deepClone(spec); + // mock the getGetParametersAsObject function to simulate GET parameters : specMock.getGetParametersAsObject = function() { return {ozf: '1', ozpf: '0', ozrp: '2', ozip: '123'}; }; @@ -2174,6 +2194,7 @@ describe('ozone Adapter', function () { }); it('should pass through GET params if present: ozf, ozpf, ozrp, ozip with alternative values', function() { var specMock = utils.deepClone(spec); + // mock the getGetParametersAsObject function to simulate GET parameters : specMock.getGetParametersAsObject = function() { return {ozf: 'false', ozpf: 'true', ozrp: 'xyz', ozip: 'hello'}; }; @@ -2186,6 +2207,7 @@ describe('ozone Adapter', function () { }); it('should use oztestmode GET value if set, even if there is no customdata in config', function() { var specMock = utils.deepClone(spec); + // mock the getGetParametersAsObject function to simulate GET parameters for oztestmode: specMock.getGetParametersAsObject = function() { return {'oztestmode': 'mytestvalue_123'}; }; @@ -2195,6 +2217,7 @@ describe('ozone Adapter', function () { expect(data.imp[0].ext.ozone.customData[0].targeting.oztestmode).to.equal('mytestvalue_123'); }); it('should use GET values auction=dev & cookiesync=dev if set', function() { + // mock the getGetParametersAsObject function to simulate GET parameters for oztestmode: var specMock = utils.deepClone(spec); specMock.getGetParametersAsObject = function() { return {}; @@ -2205,6 +2228,8 @@ describe('ozone Adapter', function () { let cookieUrl = specMock.getCookieSyncUrl(); expect(cookieUrl).to.equal('https://elb.the-ozone-project.com/static/load-cookie.html'); + // now mock the response from getGetParametersAsObject & do the request again + specMock = utils.deepClone(spec); specMock.getGetParametersAsObject = function() { return {'auction': 'dev', 'cookiesync': 'dev'}; @@ -2216,6 +2241,7 @@ describe('ozone Adapter', function () { expect(cookieUrl).to.equal('https://test.ozpr.net/static/load-cookie.html'); }); it('should use a valid ozstoredrequest GET value if set to override the placementId values, and set oz_rw if we find it', function() { + // mock the getGetParametersAsObject function to simulate GET parameters for ozstoredrequest: var specMock = utils.deepClone(spec); specMock.getGetParametersAsObject = function() { return {'ozstoredrequest': '1122334455'}; // 10 digits are valid @@ -2226,6 +2252,7 @@ describe('ozone Adapter', function () { expect(data.imp[0].ext.prebid.storedrequest.id).to.equal('1122334455'); }); it('should NOT use an invalid ozstoredrequest GET value if set to override the placementId values, and set oz_rw to 0', function() { + // mock the getGetParametersAsObject function to simulate GET parameters for ozstoredrequest: var specMock = utils.deepClone(spec); specMock.getGetParametersAsObject = function() { return {'ozstoredrequest': 'BADVAL'}; // 10 digits are valid @@ -2397,26 +2424,6 @@ describe('ozone Adapter', function () { expect(utils.deepAccess(payload, 'imp.0.floor.banner.floor')).to.equal(0.8); config.resetConfig(); }); - - it('handles schain object in each bidrequest (will be the same in each br)', function () { - let br = JSON.parse(JSON.stringify(validBidRequests)); - let schainConfigObject = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'bidderA.com', - 'sid': '00001', - 'hp': 1 - } - ] - }; - br[0]['schain'] = schainConfigObject; - const request = spec.buildRequests(br, validBidderRequest.bidderRequest); - const data = JSON.parse(request.data); - expect(data.source.ext).to.haveOwnProperty('schain'); - expect(data.source.ext.schain).to.deep.equal(schainConfigObject); // .deep.equal() : Target object deeply (but not strictly) equals `{a: 1}` - }); }); describe('interpretResponse', function () { @@ -2617,6 +2624,7 @@ describe('ozone Adapter', function () { expect(result[1]['impid']).to.equal('3025f169863b7f8'); expect(result[1]['id']).to.equal('18552976939844999'); expect(result[1]['adserverTargeting']['oz_ozappnexus_adId']).to.equal('3025f169863b7f8-0-oz-2'); + // change the bid values so a different second bid for an impid by the same bidder gets dropped validres = JSON.parse(JSON.stringify(multiResponse1)); validres.body.seatbid[0].bid[1].price = 1.1; validres.body.seatbid[0].bid[1].cpm = 1.1; @@ -2639,6 +2647,7 @@ describe('ozone Adapter', function () { expect(result).to.be.empty; }); it('should append the various values if they exist', function() { + // get the cookie bag populated spec.buildRequests(validBidRequests, validBidderRequest.bidderRequest); const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1); expect(result).to.be.an('array'); @@ -2648,12 +2657,14 @@ describe('ozone Adapter', function () { expect(result[0].url).to.include('gdpr_consent=BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA'); }); it('should append ccpa (usp data)', function() { + // get the cookie bag populated spec.buildRequests(validBidRequests, validBidderRequest.bidderRequest); const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1, '1YYN'); expect(result).to.be.an('array'); expect(result[0].url).to.include('usp_consent=1YYN'); }); it('should use "" if no usp is sent to cookieSync', function() { + // get the cookie bag populated spec.buildRequests(validBidRequests, validBidderRequest.bidderRequest); const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1); expect(result).to.be.an('array'); @@ -2876,27 +2887,4 @@ describe('ozone Adapter', function () { expect(response[1].bid.length).to.equal(2); }); }); - /** - * spec.getWhitelabelConfigItem test - get a config value for a whitelabelled bidder, - * from a standard ozone.oz_xxxx_yyy string - */ - describe('getWhitelabelConfigItem', function() { - it('should fetch the whitelabelled equivalent config value correctly', function () { - var specMock = utils.deepClone(spec); - config.setConfig({'ozone': {'oz_omp_floor': 'ozone-floor-value'}}); - config.setConfig({'markbidder': {'mb_omp_floor': 'markbidder-floor-value'}}); - specMock.propertyBag.whitelabel = {bidder: 'ozone', keyPrefix: 'oz'}; - let testKey = 'ozone.oz_omp_floor'; - let ozone_value = specMock.getWhitelabelConfigItem(testKey); - expect(ozone_value).to.equal('ozone-floor-value'); - specMock.propertyBag.whitelabel = {bidder: 'markbidder', keyPrefix: 'mb'}; - let markbidder_config = specMock.getWhitelabelConfigItem(testKey); - expect(markbidder_config).to.equal('markbidder-floor-value'); - config.setConfig({'markbidder': {'singleRequest': 'markbidder-singlerequest-value'}}); - let testKey2 = 'ozone.singleRequest'; - let markbidder_config2 = specMock.getWhitelabelConfigItem(testKey2); - expect(markbidder_config2).to.equal('markbidder-singlerequest-value'); - config.resetConfig(); - }); - }); }); diff --git a/test/spec/modules/prebidServerBidAdapter_spec.js b/test/spec/modules/prebidServerBidAdapter_spec.js index 73a531b30bf..dab68960644 100644 --- a/test/spec/modules/prebidServerBidAdapter_spec.js +++ b/test/spec/modules/prebidServerBidAdapter_spec.js @@ -8,7 +8,6 @@ import events from 'src/events.js'; import CONSTANTS from 'src/constants.json'; import { server } from 'test/mocks/xhr.js'; import { createEidsArray } from 'modules/userId/eids.js'; -import {deepAccess, deepClone} from 'src/utils.js'; let CONFIG = { accountId: '1', @@ -508,17 +507,6 @@ describe('S2S Adapter', function () { resetSyncedStatus(); }); - it('should set id to auction ID and source.tid to tid', function () { - config.setConfig({ s2sConfig: CONFIG }); - - adapter.callBids(OUTSTREAM_VIDEO_REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.id).to.equal('173afb6d132ba3'); - expect(requestBid.source).to.be.an('object'); - expect(requestBid.source.tid).to.equal('437fbbf5-33f5-487a-8e16-a7112903cfe5'); - }); - it('should block request if config did not define p1Consent URL in endpoint object config', function() { let badConfig = utils.deepClone(CONFIG); badConfig.endpoint = { noP1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }; @@ -1093,18 +1081,6 @@ describe('S2S Adapter', function () { }); }); - it('should not include ext.aspectratios if adunit\'s aspect_ratios do not define radio_width and ratio_height', () => { - const req = deepClone(REQUEST); - req.ad_units[0].mediaTypes.native.icon.aspect_ratios[0] = {'min_width': 1, 'min_height': 2}; - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const nativeReq = JSON.parse(JSON.parse(server.requests[0].requestBody).imp[0].native.request); - const icons = nativeReq.assets.map((a) => a.img).filter((img) => img && img.type === 1); - expect(icons).to.have.length(1); - expect(icons[0].hmin).to.equal(2); - expect(icons[0].wmin).to.equal(1); - expect(deepAccess(icons[0], 'ext.aspectratios')).to.be.undefined; - }) - it('adds site if app is not present', function () { const _config = { s2sConfig: CONFIG, @@ -1729,7 +1705,7 @@ describe('S2S Adapter', function () { expect(parsedRequestBody.ext.prebid.channel).to.deep.equal({name: 'pbjs', version: 'v$prebid.version$'}); }); - it('extPrebid is now mergedDeep -> should include default channel as well', () => { + it('does not set pbjs version in request if channel does exist in s2sConfig', () => { const s2sBidRequest = utils.deepClone(REQUEST); const bidRequests = utils.deepClone(BID_REQUESTS); @@ -1738,13 +1714,7 @@ describe('S2S Adapter', function () { adapter.callBids(s2sBidRequest, bidRequests, addBidResponse, done, ajax); const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - // extPrebid is now deep merged with - expect(parsedRequestBody.ext.prebid.channel).to.deep.equal({ - name: 'pbjs', - test: 1, - version: 'v$prebid.version$' - }); + expect(parsedRequestBody.ext.prebid.channel).to.deep.equal({test: 1}); }); it('passes first party data in request', () => { @@ -1775,8 +1745,6 @@ describe('S2S Adapter', function () { interests: ['cars'] } }; - const bcat = ['IAB25', 'IAB7-39']; - const badv = ['blockedAdv-1.com', 'blockedAdv-2.com']; const allowedBidders = [ 'rubicon', 'appnexus' ]; const expected = allowedBidders.map(bidder => ({ @@ -1801,23 +1769,19 @@ describe('S2S Adapter', function () { interests: ['cars'] } } - }, - bcat: ['IAB25', 'IAB7-39'], - badv: ['blockedAdv-1.com', 'blockedAdv-2.com'] + } } } })); const commonContextExpected = utils.mergeDeep({'page': 'http://mytestpage.com', 'publisher': {'id': '1'}}, commonContext); - config.setConfig({ fpd: { context: commonContext, user: commonUser, badv, bcat } }); - config.setBidderConfig({ bidders: allowedBidders, config: { fpd: { context, user, bcat, badv } } }); + config.setConfig({ fpd: { context: commonContext, user: commonUser } }); + config.setBidderConfig({ bidders: allowedBidders, config: { fpd: { context, user } } }); adapter.callBids(s2sBidRequest, bidRequests, addBidResponse, done, ajax); const parsedRequestBody = JSON.parse(server.requests[0].requestBody); expect(parsedRequestBody.ext.prebid.bidderconfig).to.deep.equal(expected); expect(parsedRequestBody.site).to.deep.equal(commonContextExpected); expect(parsedRequestBody.user).to.deep.equal(commonUser); - expect(parsedRequestBody.badv).to.deep.equal(badv); - expect(parsedRequestBody.bcat).to.deep.equal(bcat); }); describe('pbAdSlot config', function () { @@ -2433,36 +2397,6 @@ describe('S2S Adapter', function () { utils.getBidRequest.restore(); }); - - describe('on sync requested with no cookie', () => { - let cfg, req, csRes; - - beforeEach(() => { - cfg = utils.deepClone(CONFIG); - req = utils.deepClone(REQUEST); - cfg.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - req.s2sConfig = cfg; - config.setConfig({ s2sConfig: cfg }); - csRes = utils.deepClone(RESPONSE_NO_COOKIE); - }); - - afterEach(() => { - resetSyncedStatus(); - }) - - Object.entries({ - iframe: () => utils.insertUserSyncIframe, - image: () => utils.triggerPixel, - }).forEach(([type, syncer]) => { - it(`passes timeout to ${type} syncs`, () => { - cfg.syncTimeout = 123; - csRes.bidder_status[0].usersync.type = type; - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(csRes)); - expect(syncer().args[0]).to.include.members([123]); - }); - }); - }); }); describe('bid won events', function () { diff --git a/test/spec/modules/priceFloors_spec.js b/test/spec/modules/priceFloors_spec.js index b3105dafc39..548d2789d3e 100644 --- a/test/spec/modules/priceFloors_spec.js +++ b/test/spec/modules/priceFloors_spec.js @@ -15,7 +15,6 @@ import { allowedFields } from 'modules/priceFloors.js'; import events from 'src/events.js'; -import * as mockGpt from '../integration/faker/googletag.js'; describe('the price floors module', function () { let logErrorSpy; @@ -399,84 +398,6 @@ describe('the price floors module', function () { matchingFloor: 5.0 }); }); - describe('with gpt enabled', function () { - let gptFloorData; - beforeEach(function () { - gptFloorData = { - currency: 'USD', - schema: { - fields: ['gptSlot'] - }, - values: { - '/12345/sports/soccer': 1.1, - '/12345/sports/basketball': 2.2, - '/12345/news/politics': 3.3, - '/12345/news/weather': 4.4, - '*': 5.5, - }, - default: 0.5 - }; - // reset it so no lingering stuff from other test specs - mockGpt.reset(); - mockGpt.makeSlot({ - code: '/12345/sports/soccer', - divId: 'test_div_1' - }); - mockGpt.makeSlot({ - code: '/12345/sports/basketball', - divId: 'test_div_2' - }); - }); - afterEach(function () { - // reset it so no lingering stuff from other test specs - mockGpt.reset(); - }); - it('picks the right rule when looking for gptSlot', function () { - expect(getFirstMatchingFloor(gptFloorData, basicBidRequest)).to.deep.equal({ - floorMin: 0, - floorRuleValue: 1.1, - matchingFloor: 1.1, - matchingData: '/12345/sports/soccer', - matchingRule: '/12345/sports/soccer' - }); - - let newBidRequest = { ...basicBidRequest, adUnitCode: 'test_div_2' } - expect(getFirstMatchingFloor(gptFloorData, newBidRequest)).to.deep.equal({ - floorMin: 0, - floorRuleValue: 2.2, - matchingFloor: 2.2, - matchingData: '/12345/sports/basketball', - matchingRule: '/12345/sports/basketball' - }); - }); - it('picks the gptSlot from the bidRequest and does not call the slotMatching', function () { - const newBidRequest1 = { ...basicBidRequest }; - utils.deepSetValue(newBidRequest1, 'ortb2Imp.ext.data.adserver', { - name: 'gam', - adslot: '/12345/news/politics' - }) - expect(getFirstMatchingFloor(gptFloorData, newBidRequest1)).to.deep.equal({ - floorMin: 0, - floorRuleValue: 3.3, - matchingFloor: 3.3, - matchingData: '/12345/news/politics', - matchingRule: '/12345/news/politics' - }); - - const newBidRequest2 = { ...basicBidRequest, adUnitCode: 'test_div_2' }; - utils.deepSetValue(newBidRequest2, 'ortb2Imp.ext.data.adserver', { - name: 'gam', - adslot: '/12345/news/weather' - }) - expect(getFirstMatchingFloor(gptFloorData, newBidRequest2)).to.deep.equal({ - floorMin: 0, - floorRuleValue: 4.4, - matchingFloor: 4.4, - matchingData: '/12345/news/weather', - matchingRule: '/12345/news/weather' - }); - }); - }); }); describe('pre-auction tests', function () { let exposedAdUnits; diff --git a/test/spec/modules/pubgeniusBidAdapter_spec.js b/test/spec/modules/pubgeniusBidAdapter_spec.js index 4599eb2a6fa..6568f7aa782 100644 --- a/test/spec/modules/pubgeniusBidAdapter_spec.js +++ b/test/spec/modules/pubgeniusBidAdapter_spec.js @@ -173,7 +173,7 @@ describe('pubGENIUS adapter', () => { expectedRequest = { method: 'POST', - url: 'https://auction.adpearl.io/prebid/auction', + url: 'https://ortb.adpearl.io/prebid/auction', data: { id: 'fake-auction-id', imp: [ @@ -493,7 +493,7 @@ describe('pubGENIUS adapter', () => { }; expectedSync = { type: 'iframe', - url: 'https://auction.adpearl.io/usersync/pixels.html?', + url: 'https://ortb.adpearl.io/usersync/pixels.html?', }; }); @@ -551,7 +551,7 @@ describe('pubGENIUS adapter', () => { onTimeout(timeoutData); expect(server.requests[0].method).to.equal('POST'); - expect(server.requests[0].url).to.equal('https://auction.adpearl.io/prebid/events?type=timeout'); + expect(server.requests[0].url).to.equal('https://ortb.adpearl.io/prebid/events?type=timeout'); expect(JSON.parse(server.requests[0].requestBody)).to.deep.equal(timeoutData); }); }); diff --git a/test/spec/modules/publinkIdSystem_spec.js b/test/spec/modules/publinkIdSystem_spec.js deleted file mode 100644 index cfb5f8ed135..00000000000 --- a/test/spec/modules/publinkIdSystem_spec.js +++ /dev/null @@ -1,169 +0,0 @@ -import {publinkIdSubmodule} from 'modules/publinkIdSystem.js'; -import {getStorageManager} from '../../../src/storageManager'; -import {server} from 'test/mocks/xhr.js'; -import sinon from 'sinon'; -import {uspDataHandler} from '../../../src/adapterManager'; -import {parseUrl} from '../../../src/utils'; - -export const storage = getStorageManager(24); -const TEST_COOKIE_VALUE = 'cookievalue'; -describe('PublinkIdSystem', () => { - describe('decode', () => { - it('decode', () => { - const result = publinkIdSubmodule.decode(TEST_COOKIE_VALUE); - expect(result).deep.equals({publinkId: TEST_COOKIE_VALUE}); - }); - }); - - describe('Fetch Local Cookies', () => { - const PUBLINK_COOKIE = '_publink'; - const PUBLINK_SRV_COOKIE = '_publink_srv'; - const EXP = Date.now() + 60 * 60 * 24 * 7 * 1000; - const COOKIE_VALUE = {publink: 'publinkCookieValue', exp: EXP}; - const LOCAL_VALUE = {publink: 'publinkLocalStorageValue', exp: EXP}; - const COOKIE_EXPIRATION = (new Date(Date.now() + 60 * 60 * 24 * 1000)).toUTCString(); - const DELETE_COOKIE = 'Thu, 01 Jan 1970 00:00:01 GMT'; - it('publink srv cookie', () => { - storage.setCookie(PUBLINK_SRV_COOKIE, JSON.stringify(COOKIE_VALUE), COOKIE_EXPIRATION); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(COOKIE_VALUE.publink); - storage.setCookie(PUBLINK_SRV_COOKIE, '', DELETE_COOKIE); - }); - it('publink srv local storage', () => { - storage.setDataInLocalStorage(PUBLINK_SRV_COOKIE, JSON.stringify(LOCAL_VALUE)); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(LOCAL_VALUE.publink); - storage.removeDataFromLocalStorage(PUBLINK_SRV_COOKIE); - }); - it('publink cookie', () => { - storage.setCookie(PUBLINK_COOKIE, JSON.stringify(COOKIE_VALUE), COOKIE_EXPIRATION); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(COOKIE_VALUE.publink); - storage.setCookie(PUBLINK_COOKIE, '', DELETE_COOKIE); - }); - it('publink local storage', () => { - storage.setDataInLocalStorage(PUBLINK_COOKIE, JSON.stringify(LOCAL_VALUE)); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(LOCAL_VALUE.publink); - storage.removeDataFromLocalStorage(PUBLINK_COOKIE); - }); - it('priority goes to publink_srv cookie', () => { - storage.setCookie(PUBLINK_SRV_COOKIE, JSON.stringify(COOKIE_VALUE), COOKIE_EXPIRATION); - storage.setDataInLocalStorage(PUBLINK_COOKIE, JSON.stringify(LOCAL_VALUE)); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(COOKIE_VALUE.publink); - storage.setCookie(PUBLINK_SRV_COOKIE, '', DELETE_COOKIE); - storage.removeDataFromLocalStorage(PUBLINK_COOKIE); - }); - it('publink non-json cookie', () => { - storage.setCookie(PUBLINK_COOKIE, COOKIE_VALUE.publink, COOKIE_EXPIRATION); - const result = publinkIdSubmodule.getId(); - expect(result.id).to.equal(COOKIE_VALUE.publink); - storage.setCookie(PUBLINK_COOKIE, '', DELETE_COOKIE); - }); - }); - - describe('getId', () => { - const serverResponse = {publink: 'ec0xHT3yfAOnykP64Qf0ORSi7LjNT1wju04ZSCsoPBekOJdBwK-0Zl_lXKDNnzhauC4iszBc-PvA1Be6IMlh1QocA'}; - it('no config', () => { - const result = publinkIdSubmodule.getId(); - expect(result).to.exist; - expect(result.callback).to.be.a('function'); - }); - - it('Use local copy', () => { - const result = publinkIdSubmodule.getId({}, undefined, TEST_COOKIE_VALUE); - expect(result).to.be.undefined; - }); - - describe('callout for id', () => { - let callbackSpy = sinon.spy(); - - beforeEach(() => { - callbackSpy.resetHistory(); - }); - - it('Fetch with consent data', () => { - const config = {storage: {type: 'cookie'}, params: {e: 'ca11c0ca7', site_id: '102030'}}; - const consentData = {gdprApplies: 1, consentString: 'myconsentstring'}; - let submoduleCallback = publinkIdSubmodule.getId(config, consentData).callback; - submoduleCallback(callbackSpy); - - const request = server.requests[0]; - const parsed = parseUrl(request.url); - - expect(parsed.hostname).to.equal('proc.ad.cpe.dotomi.com'); - expect(parsed.pathname).to.equal('/cvx/client/sync/publink'); - expect(parsed.search.mpn).to.equal('Prebid.js'); - expect(parsed.search.mpv).to.equal('$prebid.version$'); - expect(parsed.search.gdpr).to.equal('1'); - expect(parsed.search.gdpr_consent).to.equal('myconsentstring'); - expect(parsed.search.sid).to.equal('102030'); - expect(parsed.search.apikey).to.be.undefined; - - request.respond(200, {}, JSON.stringify(serverResponse)); - expect(callbackSpy.calledOnce).to.be.true; - expect(callbackSpy.lastCall.lastArg).to.equal(serverResponse.publink); - }); - - it('server doesnt respond', () => { - const config = {storage: {type: 'cookie'}, params: {e: 'ca11c0ca7'}}; - let submoduleCallback = publinkIdSubmodule.getId(config).callback; - submoduleCallback(callbackSpy); - - let request = server.requests[0]; - const parsed = parseUrl(request.url); - - expect(parsed.hostname).to.equal('proc.ad.cpe.dotomi.com'); - expect(parsed.pathname).to.equal('/cvx/client/sync/publink'); - expect(parsed.search.mpn).to.equal('Prebid.js'); - expect(parsed.search.mpv).to.equal('$prebid.version$'); - - request.respond(204, {}, JSON.stringify(serverResponse)); - expect(callbackSpy.called).to.be.false; - }); - - it('reject plain email address', () => { - const config = {storage: {type: 'cookie'}, params: {e: 'tester@test.com'}}; - const consentData = {gdprApplies: 1, consentString: 'myconsentstring'}; - let submoduleCallback = publinkIdSubmodule.getId(config, consentData).callback; - submoduleCallback(callbackSpy); - - expect(server.requests).to.have.lengthOf(0); - expect(callbackSpy.called).to.be.false; - }); - }); - - describe('usPrivacy', () => { - let callbackSpy = sinon.spy(); - const oldPrivacy = uspDataHandler.getConsentData(); - before(() => { - uspDataHandler.setConsentData('1YNN'); - }); - after(() => { - uspDataHandler.setConsentData(oldPrivacy); - callbackSpy.resetHistory(); - }); - - it('Fetch with usprivacy data', () => { - const config = {storage: {type: 'cookie'}, params: {e: 'ca11c0ca7', api_key: 'abcdefg'}}; - let submoduleCallback = publinkIdSubmodule.getId(config).callback; - submoduleCallback(callbackSpy); - - let request = server.requests[0]; - const parsed = parseUrl(request.url); - - expect(parsed.hostname).to.equal('proc.ad.cpe.dotomi.com'); - expect(parsed.pathname).to.equal('/cvx/client/sync/publink'); - expect(parsed.search.mpn).to.equal('Prebid.js'); - expect(parsed.search.mpv).to.equal('$prebid.version$'); - expect(parsed.search.us_privacy).to.equal('1YNN'); - expect(parsed.search.apikey).to.equal('abcdefg'); - - request.respond(200, {}, JSON.stringify(serverResponse)); - expect(callbackSpy.calledOnce).to.be.true; - expect(callbackSpy.lastCall.lastArg).to.equal(serverResponse.publink); - }); - }); - }); -}); diff --git a/test/spec/modules/pubmaticAnalyticsAdapter_spec.js b/test/spec/modules/pubmaticAnalyticsAdapter_spec.js index b6268548ccc..c6496ee7fe1 100755 --- a/test/spec/modules/pubmaticAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubmaticAnalyticsAdapter_spec.js @@ -95,9 +95,6 @@ const BID2 = Object.assign({}, BID, { 'hb_pb': '1.500', 'hb_size': '728x90', 'hb_source': 'server' - }, - meta: { - advertiserDomains: ['example.com'] } }); @@ -385,7 +382,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -655,7 +651,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -713,7 +708,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -760,7 +754,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -778,10 +771,9 @@ describe('pubmatic analytics adapter', function () { expect(data.kgpv).to.equal('*'); }); - it('Logger: regexPattern in bid.bidResponse and url in adomain', function() { + it('Logger: regexPattern in bid.bidResponse', function() { const BID2_COPY = utils.deepClone(BID2); BID2_COPY.regexPattern = '*'; - BID2_COPY.meta.advertiserDomains = ['https://www.example.com/abc/223'] events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); @@ -816,7 +808,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -868,7 +859,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -922,7 +912,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); @@ -1022,7 +1011,6 @@ describe('pubmatic analytics adapter', function () { expect(data.s[1].ps[0].di).to.equal('the-deal-id'); expect(data.s[1].ps[0].dc).to.equal('PMP'); expect(data.s[1].ps[0].mi).to.equal('matched-impression'); - expect(data.s[1].ps[0].adv).to.equal('example.com'); expect(data.s[1].ps[0].l1).to.equal(3214); expect(data.s[1].ps[0].l2).to.equal(0); expect(data.s[1].ps[0].ss).to.equal(1); diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js index 9696501437b..23c5f01e520 100644 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ b/test/spec/modules/pubmaticBidAdapter_spec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import {spec, checkVideoPlacement} from 'modules/pubmaticBidAdapter.js'; +import {spec} from 'modules/pubmaticBidAdapter.js'; import * as utils from 'src/utils.js'; import {config} from 'src/config.js'; import { createEidsArray } from 'modules/userId/eids.js'; @@ -1565,69 +1565,6 @@ describe('PubMatic adapter', function () { expect(data2.regs).to.equal(undefined);// USP/CCPAs }); - it('Request params check with JW player params', function() { - let bidRequests = [ - { - bidder: 'pubmatic', - params: { - publisherId: '301', - adSlot: '/15671365/DMDemo@300x250:0', - dctr: 'key1=val1|key2=val2,val3' - }, - placementCode: '/19968336/header-bid-tag-1', - sizes: [[300, 250], [300, 600]], - bidId: '23acc48ad47af5', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - rtd: { - jwplayer: { - targeting: { - content: { id: 'jw_d9J2zcaA' }, - segments: ['80011026', '80011035'] - } - } - } - }]; - let key_val_output = 'key1=val1|key2=val2,val3|jw-id=jw_d9J2zcaA|jw-80011026=1|jw-80011035=1' - let request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - let data = JSON.parse(request.data); - expect(data.imp[0].ext).to.exist.and.to.be.an('object'); - expect(data.imp[0].ext.key_val).to.exist.and.to.equal(key_val_output); - - // jw player data not available. Only dctr sent. - delete bidRequests[0].rtd; - request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - data = JSON.parse(request.data); - - expect(data.imp[0].ext).to.exist.and.to.be.an('object'); // dctr parameter - expect(data.imp[0].ext.key_val).to.exist.and.to.equal(bidRequests[0].params.dctr); - - // jw player data is available, but dctr is not present - bidRequests[0].rtd = { - jwplayer: { - targeting: { - content: { id: 'jw_d9J2zcaA' }, - segments: ['80011026', '80011035'] - } - } - }; - - delete bidRequests[0].params.dctr; - key_val_output = 'jw-id=jw_d9J2zcaA|jw-80011026=1|jw-80011035=1'; - request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - data = JSON.parse(request.data); - - expect(data.imp[0].ext).to.exist.and.to.be.an('object'); - expect(data.imp[0].ext.key_val).to.exist.and.to.equal(key_val_output); - }); - describe('FPD', function() { let newRequest; @@ -1846,25 +1783,14 @@ describe('PubMatic adapter', function () { let newRequest; let floorModuleTestData; let getFloor = function(req) { - // actual getFloor module does not work like this :) - // special treatment for banner since for other mediaTypes we pass * - if (req.mediaType === 'banner') { - return floorModuleTestData[req.mediaType][ req.size[0] + 'x' + req.size[1] ] || {}; - } - return floorModuleTestData[req.mediaType] || {}; + return floorModuleTestData[req.mediaType]; }; beforeEach(() => { floorModuleTestData = { 'banner': { - '300x250': { - 'currency': 'USD', - 'floor': 1.50 - }, - '300x600': { - 'currency': 'USD', - 'floor': 2.0 - } + 'currency': 'USD', + 'floor': 1.50 }, 'video': { 'currency': 'USD', @@ -1880,7 +1806,7 @@ describe('PubMatic adapter', function () { }); it('bidfloor should be undefined if calculation is <= 0', function() { - floorModuleTestData.banner['300x250'].floor = 0; // lowest of them all + floorModuleTestData.banner.floor = 0; // lowest of them all newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1891,8 +1817,7 @@ describe('PubMatic adapter', function () { }); it('ignore floormodule o/p if floor is not number', function() { - floorModuleTestData.banner['300x250'].floor = 'Not-a-Number'; - floorModuleTestData.banner['300x600'].floor = 'Not-a-Number'; + floorModuleTestData.banner.floor = 'INR'; newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1903,8 +1828,7 @@ describe('PubMatic adapter', function () { }); it('ignore floormodule o/p if currency is not matched', function() { - floorModuleTestData.banner['300x250'].currency = 'INR'; - floorModuleTestData.banner['300x600'].currency = 'INR'; + floorModuleTestData.banner.currency = 'INR'; newRequest[0].params.kadfloor = undefined; let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -1934,7 +1858,7 @@ describe('PubMatic adapter', function () { expect(data.bidfloor).to.equal(3); }); - it('kadfloor is passed as 1, use min of floorModule as it is highest', function() { + it('kadfloor is passed as 1, use min of fllorModule as it is highest', function() { newRequest[0].params.kadfloor = '1.0';// yes, we want it as a string let request = spec.buildRequests(newRequest, { auctionId: 'new-auction-id' @@ -3457,7 +3381,7 @@ describe('PubMatic adapter', function () { 'h': 0, 'dealId': 'ASEA-MS-KLY-TTD-DESKTOP-ID-VID-6S-030420', 'ext': { - 'bidtype': 1 + 'BidType': 1 } }], 'ext': { @@ -3644,221 +3568,5 @@ describe('PubMatic adapter', function () { }]); }); }); - - describe('JW player segment data for S2S', function() { - let sandbox = sinon.sandbox.create(); - beforeEach(function () { - sandbox = sinon.sandbox.create(); - }); - afterEach(function() { - sandbox.restore(); - }); - it('Should append JW player segment data to dctr values in auction endpoint', function() { - var videoAdUnit = { - 'bidderCode': 'pubmatic', - 'bids': [ - { - 'bidder': 'pubmatic', - 'params': { - 'publisherId': '156276', - 'adSlot': 'pubmatic_video2', - 'dctr': 'key1=123|key2=345', - 'pmzoneid': '1243', - 'video': { - 'mimes': ['video/mp4', 'video/x-flv'], - 'skippable': true, - 'minduration': 5, - 'maxduration': 30, - 'startdelay': 5, - 'playbackmethod': [1, 3], - 'api': [1, 2], - 'protocols': [2, 3], - 'battr': [13, 14], - 'linearity': 1, - 'placement': 2, - 'minbitrate': 10, - 'maxbitrate': 10 - } - }, - 'rtd': { - 'jwplayer': { - 'targeting': { - 'segments': ['80011026', '80011035'], - 'content': { - 'id': 'jw_d9J2zcaA' - } - } - } - }, - 'bid_id': '17a6771be26cc4', - 'ortb2Imp': { - 'ext': { - 'data': { - 'pbadslot': 'abcd', - 'jwTargeting': { - 'playerID': 'myElement1', - 'mediaID': 'd9J2zcaA' - } - } - } - } - } - ], - 'auctionStart': 1630923178417, - 'timeout': 1000, - 'src': 's2s' - } - - spec.transformBidParams(bidRequests[0].params, true, videoAdUnit); - expect(bidRequests[0].params.dctr).to.equal('key1:val1,val2|key2:val1|jw-id=jw_d9J2zcaA|jw-80011026=1|jw-80011035=1'); - }); - it('Should send only JW player segment data in auction endpoint, if dctr is missing', function() { - var videoAdUnit = { - 'bidderCode': 'pubmatic', - 'bids': [ - { - 'bidder': 'pubmatic', - 'params': { - 'publisherId': '156276', - 'adSlot': 'pubmatic_video2', - 'dctr': 'key1=123|key2=345', - 'pmzoneid': '1243', - 'video': { - 'mimes': ['video/mp4', 'video/x-flv'], - 'skippable': true, - 'minduration': 5, - 'maxduration': 30, - 'startdelay': 5, - 'playbackmethod': [1, 3], - 'api': [1, 2], - 'protocols': [2, 3], - 'battr': [13, 14], - 'linearity': 1, - 'placement': 2, - 'minbitrate': 10, - 'maxbitrate': 10 - } - }, - 'rtd': { - 'jwplayer': { - 'targeting': { - 'segments': ['80011026', '80011035'], - 'content': { - 'id': 'jw_d9J2zcaA' - } - } - } - }, - 'bid_id': '17a6771be26cc4', - 'ortb2Imp': { - 'ext': { - 'data': { - 'pbadslot': 'abcd', - 'jwTargeting': { - 'playerID': 'myElement1', - 'mediaID': 'd9J2zcaA' - } - } - } - } - } - ], - 'auctionStart': 1630923178417, - 'timeout': 1000, - 'src': 's2s' - } - - delete bidRequests[0].params.dctr; - spec.transformBidParams(bidRequests[0].params, true, videoAdUnit); - expect(bidRequests[0].params.dctr).to.equal('jw-id=jw_d9J2zcaA|jw-80011026=1|jw-80011035=1'); - }); - - it('Should not send any JW player segment data in auction endpoint, if it is not available', function() { - var videoAdUnit = { - 'bidderCode': 'pubmatic', - 'bids': [ - { - 'bidder': 'pubmatic', - 'params': { - 'publisherId': '156276', - 'adSlot': 'pubmatic_video2', - 'dctr': 'key1=123|key2=345', - 'pmzoneid': '1243', - 'video': { - 'mimes': ['video/mp4', 'video/x-flv'], - 'skippable': true, - 'minduration': 5, - 'maxduration': 30, - 'startdelay': 5, - 'playbackmethod': [1, 3], - 'api': [1, 2], - 'protocols': [2, 3], - 'battr': [13, 14], - 'linearity': 1, - 'placement': 2, - 'minbitrate': 10, - 'maxbitrate': 10 - } - }, - 'bid_id': '17a6771be26cc4', - 'ortb2Imp': { - 'ext': { - 'data': { - 'pbadslot': 'abcd', - 'jwTargeting': { - 'playerID': 'myElement1', - 'mediaID': 'd9J2zcaA' - } - } - } - } - } - ], - 'auctionStart': 1630923178417, - 'timeout': 1000, - 'src': 's2s' - } - spec.transformBidParams(bidRequests[0].params, true, videoAdUnit); - expect(bidRequests[0].params.dctr).to.equal('key1:val1,val2|key2:val1'); - }); - }) - - describe('Checking for Video.Placement property', function() { - let sandbox, utilsMock; - const adUnit = 'Div1'; - const msg_placement_missing = 'Video.Placement param missing for Div1'; - let videoData = { - battr: [6, 7], - skipafter: 15, - maxduration: 50, - context: 'instream', - playerSize: [640, 480], - skip: 0, - connectiontype: [1, 2, 6], - skipmin: 10, - minduration: 10, - mimes: ['video/mp4', 'video/x-flv'], - } - beforeEach(() => { - utilsMock = sinon.mock(utils); - sandbox = sinon.sandbox.create(); - sandbox.spy(utils, 'logWarn'); - }); - - afterEach(() => { - utilsMock.restore(); - sandbox.restore(); - }) - - it('should log Video.Placement param missing', function() { - checkVideoPlacement(videoData, adUnit); - sinon.assert.calledWith(utils.logWarn, msg_placement_missing); - }) - it('shoud not log Video.Placement param missing', function() { - videoData['placement'] = 1; - checkVideoPlacement(videoData, adUnit); - sinon.assert.neverCalledWith(utils.logWarn, msg_placement_missing); - }) - }); }); }); diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index e6a1c063a86..3d9be082be3 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -28,7 +28,6 @@ describe('pubxai analytics adapter', function() { }; let location = utils.getWindowLocation(); - let storage = window.top['sessionStorage']; let prebidEvent = { 'auctionInit': { @@ -515,11 +514,6 @@ describe('pubxai analytics adapter', function() { 'path': location.pathname, 'search': location.search }, - 'pmcDetail': { - 'bidDensity': storage.getItem('pbx:dpbid'), - 'maxBid': storage.getItem('pbx:mxbid'), - 'auctionId': storage.getItem('pbx:aucid') - } }; let expectedAfterBid = { @@ -583,11 +577,6 @@ describe('pubxai analytics adapter', function() { 'deviceOS': getOS(), 'browser': getBrowser() }, - 'pmcDetail': { - 'bidDensity': storage.getItem('pbx:dpbid'), - 'maxBid': storage.getItem('pbx:mxbid'), - 'auctionId': storage.getItem('pbx:aucid') - }, 'initOptions': initOptions }; diff --git a/test/spec/modules/pulsepointBidAdapter_spec.js b/test/spec/modules/pulsepointBidAdapter_spec.js index 92f7aa0b70d..6630cb0907c 100644 --- a/test/spec/modules/pulsepointBidAdapter_spec.js +++ b/test/spec/modules/pulsepointBidAdapter_spec.js @@ -637,7 +637,7 @@ describe('PulsePoint Adapter Tests', function () { expect(ortbRequest.user.ext).to.not.be.undefined; expect(ortbRequest.user.ext.eids).to.not.be.undefined; expect(ortbRequest.user.ext.eids).to.have.lengthOf(2); - expect(ortbRequest.user.ext.eids[0].source).to.equal('pubcid.org'); + expect(ortbRequest.user.ext.eids[0].source).to.equal('pubcommon'); expect(ortbRequest.user.ext.eids[0].uids).to.have.lengthOf(1); expect(ortbRequest.user.ext.eids[0].uids[0].id).to.equal('userid_pubcid'); expect(ortbRequest.user.ext.eids[1].source).to.equal('adserver.org'); @@ -659,16 +659,6 @@ describe('PulsePoint Adapter Tests', function () { parrableId: { eid: 'parrable_id234' }, lipb: { lipbid: 'liveintent_id123' - }, - haloId: { - haloId: 'halo_user1' - }, - lotamePanoramaId: 'lotame_user2', - merkleId: 'merkle_user3', - fabrickId: 'fabrick_user4', - connectid: 'connect_user5', - uid2: { - id: 'uid2_user6' } }; const userVerify = function(obj, source, id) { @@ -687,19 +677,13 @@ describe('PulsePoint Adapter Tests', function () { expect(ortbRequest.user).to.not.be.undefined; expect(ortbRequest.user.ext).to.not.be.undefined; expect(ortbRequest.user.ext.eids).to.not.be.undefined; - expect(ortbRequest.user.ext.eids).to.have.lengthOf(12); + expect(ortbRequest.user.ext.eids).to.have.lengthOf(6); userVerify(ortbRequest.user.ext.eids[0], 'britepool.com', 'britepool_id123'); - userVerify(ortbRequest.user.ext.eids[1], 'criteo.com', 'criteo_id234'); - userVerify(ortbRequest.user.ext.eids[2], 'liveramp.com', 'idl_id123'); + userVerify(ortbRequest.user.ext.eids[1], 'criteo', 'criteo_id234'); + userVerify(ortbRequest.user.ext.eids[2], 'identityLink', 'idl_id123'); userVerify(ortbRequest.user.ext.eids[3], 'id5-sync.com', 'id5id_234'); userVerify(ortbRequest.user.ext.eids[4], 'parrable.com', 'parrable_id234'); - userVerify(ortbRequest.user.ext.eids[5], 'neustar.biz', 'fabrick_user4'); - userVerify(ortbRequest.user.ext.eids[6], 'audigent.com', 'halo_user1'); - userVerify(ortbRequest.user.ext.eids[7], 'merkleinc.com', 'merkle_user3'); - userVerify(ortbRequest.user.ext.eids[8], 'crwdcntrl.net', 'lotame_user2'); - userVerify(ortbRequest.user.ext.eids[9], 'verizonmedia.com', 'connect_user5'); - userVerify(ortbRequest.user.ext.eids[10], 'uidapi.com', 'uid2_user6'); - userVerify(ortbRequest.user.ext.eids[11], 'liveintent.com', 'liveintent_id123'); + userVerify(ortbRequest.user.ext.eids[5], 'liveintent.com', 'liveintent_id123'); }); it('Verify multiple adsizes', function () { const bidRequests = deepClone(slotConfigs); diff --git a/test/spec/modules/realTimeDataModule_spec.js b/test/spec/modules/realTimeDataModule_spec.js index 6538dec37c4..b84aef15feb 100644 --- a/test/spec/modules/realTimeDataModule_spec.js +++ b/test/spec/modules/realTimeDataModule_spec.js @@ -1,9 +1,6 @@ import * as rtdModule from 'modules/rtdModule/index.js'; -import {config} from 'src/config.js'; +import { config } from 'src/config.js'; import * as sinon from 'sinon'; -import {default as CONSTANTS} from '../../../src/constants.json'; -import {default as events} from '../../../src/events.js'; -import 'src/prebid.js'; const getBidRequestDataSpy = sinon.spy(); @@ -61,87 +58,33 @@ const conf = { }; describe('Real time module', function () { - let eventHandlers; - let sandbox; - - function mockEmitEvent(event, ...args) { - (eventHandlers[event] || []).forEach((h) => h(...args)); - } - - before(() => { - eventHandlers = {}; - sandbox = sinon.sandbox.create(); - sandbox.stub(events, 'on').callsFake((event, handler) => { - if (!eventHandlers.hasOwnProperty(event)) { - eventHandlers[event] = []; - } - eventHandlers[event].push(handler); - }); + before(function () { + rtdModule.attachRealTimeDataProvider(validSM); + rtdModule.attachRealTimeDataProvider(invalidSM); + rtdModule.attachRealTimeDataProvider(failureSM); + rtdModule.attachRealTimeDataProvider(nonConfSM); + rtdModule.attachRealTimeDataProvider(validSMWait); }); - after(() => { - sandbox.restore(); + after(function () { + config.resetConfig(); }); - describe('', () => { - const PROVIDERS = [validSM, invalidSM, failureSM, nonConfSM, validSMWait]; - let _detachers; - - beforeEach(function () { - _detachers = PROVIDERS.map(rtdModule.attachRealTimeDataProvider); - rtdModule.init(config); - config.setConfig(conf); - }); - - afterEach(function () { - _detachers.forEach((f) => f()); - config.resetConfig(); - }); - - it('should use only valid modules', function () { - expect(rtdModule.subModules).to.eql([validSMWait, validSM]); - }); - - it('should be able to modify bid request', function (done) { - rtdModule.setBidRequestsData(() => { - assert(getBidRequestDataSpy.calledTwice); - assert(getBidRequestDataSpy.calledWith({bidRequest: {}})); - done(); - }, {bidRequest: {}}) - }); - - it('sould place targeting on adUnits', function (done) { - const auction = { - adUnitCodes: ['ad1', 'ad2'], - adUnits: [ - { - code: 'ad1' - }, - { - code: 'ad2', - adserverTargeting: {preKey: 'preValue'} - } - ] - }; + beforeEach(function () { + config.setConfig(conf); + }); - const expectedAdUnits = [ - { - code: 'ad1', - adserverTargeting: {key: 'validSMWait'} - }, - { - code: 'ad2', - adserverTargeting: { - preKey: 'preValue', - key: 'validSM' - } - } - ]; + it('should use only valid modules', function () { + rtdModule.init(config); + expect(rtdModule.subModules).to.eql([validSMWait, validSM]); + }); - const adUnits = rtdModule.getAdUnitTargeting(auction); - assert.deepEqual(expectedAdUnits, adUnits) + it('should be able to modify bid request', function (done) { + rtdModule.setBidRequestsData(() => { + assert(getBidRequestDataSpy.calledTwice); + assert(getBidRequestDataSpy.calledWith({bidRequest: {}})); done(); - }) + }, {bidRequest: {}}) }); it('deep merge object', function () { @@ -182,78 +125,36 @@ describe('Real time module', function () { assert.deepEqual(expected, merged); }); - describe('event', () => { - const EVENTS = { - [CONSTANTS.EVENTS.AUCTION_INIT]: 'onAuctionInitEvent', - [CONSTANTS.EVENTS.AUCTION_END]: 'onAuctionEndEvent', - [CONSTANTS.EVENTS.BID_RESPONSE]: 'onBidResponseEvent', - [CONSTANTS.EVENTS.BID_REQUESTED]: 'onBidRequestEvent' - } - const conf = { - 'realTimeData': { - dataProviders: [ - { - 'name': 'tp1', - }, - { - 'name': 'tp2', - } - ] - } + it('sould place targeting on adUnits', function (done) { + const auction = { + adUnitCodes: ['ad1', 'ad2'], + adUnits: [ + { + code: 'ad1' + }, + { + code: 'ad2', + adserverTargeting: {preKey: 'preValue'} + } + ] }; - let providers; - let _detachers; - function eventHandlingProvider(name) { - const provider = { - name: name, - init: () => true, + const expectedAdUnits = [ + { + code: 'ad1', + adserverTargeting: {key: 'validSMWait'} + }, + { + code: 'ad2', + adserverTargeting: { + preKey: 'preValue', + key: 'validSM' + } } - Object.values(EVENTS).forEach((ev) => provider[ev] = sinon.spy()); - return provider; - } - - beforeEach(() => { - providers = [eventHandlingProvider('tp1'), eventHandlingProvider('tp2')]; - _detachers = providers.map(rtdModule.attachRealTimeDataProvider); - rtdModule.init(config); - config.setConfig(conf); - }); - - afterEach(() => { - _detachers.forEach((d) => d()) - config.resetConfig(); - }); - - it('should set targeting for auctionEnd', () => { - providers.forEach(p => p.getTargetingData = sinon.spy()); - const auction = { - adUnitCodes: ['a1'], - adUnits: [{code: 'a1'}] - }; - mockEmitEvent(CONSTANTS.EVENTS.AUCTION_END, auction); - providers.forEach(p => { - expect(p.getTargetingData.calledWith(auction.adUnitCodes)).to.be.true; - }); - }); - - Object.entries(EVENTS).forEach(([event, hook]) => { - it(`'${event}' should be propagated to providers through '${hook}'`, () => { - const eventArg = {}; - mockEmitEvent(event, eventArg); - providers.forEach((provider) => { - const providerConf = conf.realTimeData.dataProviders.find((cfg) => cfg.name === provider.name); - expect(provider[hook].called).to.be.true; - expect(provider[hook].args).to.have.length(1); - expect(provider[hook].args[0]).to.include.members([eventArg, providerConf]) - }) - }); + ]; - it(`${event} should not fail to propagate elsewhere if a provider throws in its event handler`, () => { - providers[0][hook] = function () { throw new Error() }; - mockEmitEvent(event); - expect(providers[1][hook].called).to.be.true; - }); - }); + const adUnits = rtdModule.getAdUnitTargeting(auction); + assert.deepEqual(expectedAdUnits, adUnits) + done(); }) }); diff --git a/test/spec/modules/relaidoBidAdapter_spec.js b/test/spec/modules/relaidoBidAdapter_spec.js index 51850e5f357..e372c67bb4e 100644 --- a/test/spec/modules/relaidoBidAdapter_spec.js +++ b/test/spec/modules/relaidoBidAdapter_spec.js @@ -20,12 +20,8 @@ describe('RelaidoAdapter', function () { let bidderRequest; let serverResponse; let serverRequest; - let generateUUIDStub; - let triggerPixelStub; beforeEach(function () { - generateUUIDStub = sinon.stub(utils, 'generateUUID').returns(relaido_uuid); - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); bidRequest = { bidder: 'relaido', params: { @@ -57,42 +53,26 @@ describe('RelaidoAdapter', function () { serverResponse = { body: { status: 'ok', - ads: [{ - placementId: 100000, - width: 640, - height: 360, - bidId: '2ed93003f7bb99', - price: 500, - model: 'vcpm', - currency: 'JPY', - creativeId: 1000, - vast: '', - syncUrl: 'https://relaido/sync.html', - adomain: ['relaido.co.jp', 'www.cmertv.co.jp'], - mediaType: 'video' - }], - playerUrl: 'https://relaido/player.js', - syncUrl: 'https://api-dev.ulizaex.com/tr/v1/prebid/sync.html', + price: 500, + model: 'vcpm', + currency: 'JPY', + creativeId: 1000, uuid: relaido_uuid, + vast: '', + playerUrl: 'https://relaido/player.js', + syncUrl: 'https://relaido/sync.html', + adomain: ['relaido.co.jp', 'www.cmertv.co.jp'] } }; serverRequest = { - method: 'POST', - data: { - bids: [{ - bidId: bidRequest.bidId, - width: bidRequest.mediaTypes.video.playerSize[0][0], - height: bidRequest.mediaTypes.video.playerSize[0][1], - mediaType: 'video'}] - } + method: 'GET', + bidId: bidRequest.bidId, + width: bidRequest.mediaTypes.video.playerSize[0][0], + height: bidRequest.mediaTypes.video.playerSize[0][1], + mediaType: 'video', }; }); - afterEach(() => { - generateUUIDStub.restore(); - triggerPixelStub.restore(); - }); - describe('spec.isBidRequestValid', function () { it('should return true when the required params are passed by video', function () { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); @@ -206,23 +186,27 @@ describe('RelaidoAdapter', function () { describe('spec.buildRequests', function () { it('should build bid requests by video', function () { const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - expect(bidRequests.method).to.equal('POST'); - expect(bidRequests.url).to.equal('https://api.relaido.jp/bid/v1/sprebid'); - expect(data.ref).to.equal(bidderRequest.refererInfo.referer); - expect(data.timeout_ms).to.equal(bidderRequest.timeout); - expect(request.ad_unit_code).to.equal(bidRequest.adUnitCode); - expect(request.auction_id).to.equal(bidRequest.auctionId); - expect(data.bidder).to.equal(bidRequest.bidder); - expect(request.bidder_request_id).to.equal(bidRequest.bidderRequestId); - expect(data.bid_requests_count).to.equal(bidRequest.bidRequestsCount); - expect(request.bid_id).to.equal(bidRequest.bidId); - expect(request.transaction_id).to.equal(bidRequest.transactionId); - expect(request.media_type).to.equal('video'); - expect(data.uuid).to.equal(relaido_uuid); - expect(data.pv).to.equal('$prebid.version$'); + expect(bidRequests).to.have.lengthOf(1); + const request = bidRequests[0]; + expect(request.method).to.equal('GET'); + expect(request.url).to.equal('https://api.relaido.jp/bid/v1/prebid/100000'); + expect(request.bidId).to.equal(bidRequest.bidId); + expect(request.width).to.equal(bidRequest.mediaTypes.video.playerSize[0][0]); + expect(request.height).to.equal(bidRequest.mediaTypes.video.playerSize[0][1]); + expect(request.mediaType).to.equal('video'); + expect(request.data.ref).to.equal(bidderRequest.refererInfo.referer); + expect(request.data.timeout_ms).to.equal(bidderRequest.timeout); + expect(request.data.ad_unit_code).to.equal(bidRequest.adUnitCode); + expect(request.data.auction_id).to.equal(bidRequest.auctionId); + expect(request.data.bidder).to.equal(bidRequest.bidder); + expect(request.data.bidder_request_id).to.equal(bidRequest.bidderRequestId); + expect(request.data.bid_requests_count).to.equal(bidRequest.bidRequestsCount); + expect(request.data.bid_id).to.equal(bidRequest.bidId); + expect(request.data.transaction_id).to.equal(bidRequest.transactionId); + expect(request.data.media_type).to.equal('video'); + expect(request.data.uuid).to.equal(relaido_uuid); + expect(request.data.width).to.equal(bidRequest.mediaTypes.video.playerSize[0][0]); + expect(request.data.height).to.equal(bidRequest.mediaTypes.video.playerSize[0][1]); }); it('should build bid requests by banner', function () { @@ -242,10 +226,9 @@ describe('RelaidoAdapter', function () { } }; const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - expect(request.media_type).to.equal('banner'); + expect(bidRequests).to.have.lengthOf(1); + const request = bidRequests[0]; + expect(request.mediaType).to.equal('banner'); }); it('should take 1x1 size', function () { @@ -265,30 +248,22 @@ describe('RelaidoAdapter', function () { } }; const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; + expect(bidRequests).to.have.lengthOf(1); + const request = bidRequests[0]; + // eslint-disable-next-line no-console + console.log(bidRequests); expect(request.width).to.equal(1); }); it('The referrer should be the last', function () { const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const keys = Object.keys(data); + expect(bidRequests).to.have.lengthOf(1); + const request = bidRequests[0]; + const keys = Object.keys(request.data); expect(keys[0]).to.equal('version'); expect(keys[keys.length - 1]).to.equal('ref'); }); - - it('should get imuid', function () { - bidRequest.userId = {} - bidRequest.userId.imuid = 'i.tjHcK_7fTcqnbrS_YA2vaw'; - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - expect(data.imuid).to.equal('i.tjHcK_7fTcqnbrS_YA2vaw'); - }); }); describe('spec.interpretResponse', function () { @@ -296,29 +271,29 @@ describe('RelaidoAdapter', function () { const bidResponses = spec.interpretResponse(serverResponse, serverRequest); expect(bidResponses).to.have.lengthOf(1); const response = bidResponses[0]; - expect(response.requestId).to.equal(serverRequest.data.bids[0].bidId); - expect(response.width).to.equal(serverRequest.data.bids[0].width); - expect(response.height).to.equal(serverRequest.data.bids[0].height); - expect(response.cpm).to.equal(serverResponse.body.ads[0].price); - expect(response.currency).to.equal(serverResponse.body.ads[0].currency); - expect(response.creativeId).to.equal(serverResponse.body.ads[0].creativeId); - expect(response.vastXml).to.equal(serverResponse.body.ads[0].vast); - expect(response.meta.advertiserDomains).to.equal(serverResponse.body.ads[0].adomain); + expect(response.requestId).to.equal(serverRequest.bidId); + expect(response.width).to.equal(serverRequest.width); + expect(response.height).to.equal(serverRequest.height); + expect(response.cpm).to.equal(serverResponse.body.price); + expect(response.currency).to.equal(serverResponse.body.currency); + expect(response.creativeId).to.equal(serverResponse.body.creativeId); + expect(response.vastXml).to.equal(serverResponse.body.vast); + expect(response.meta.advertiserDomains).to.equal(serverResponse.body.adomain); expect(response.meta.mediaType).to.equal(VIDEO); expect(response.ad).to.be.undefined; }); it('should build bid response by banner', function () { - serverResponse.body.ads[0].mediaType = 'banner'; + serverRequest.mediaType = 'banner'; const bidResponses = spec.interpretResponse(serverResponse, serverRequest); expect(bidResponses).to.have.lengthOf(1); const response = bidResponses[0]; - expect(response.requestId).to.equal(serverRequest.data.bids[0].bidId); - expect(response.width).to.equal(serverRequest.data.bids[0].width); - expect(response.height).to.equal(serverRequest.data.bids[0].height); - expect(response.cpm).to.equal(serverResponse.body.ads[0].price); - expect(response.currency).to.equal(serverResponse.body.ads[0].currency); - expect(response.creativeId).to.equal(serverResponse.body.ads[0].creativeId); + expect(response.requestId).to.equal(serverRequest.bidId); + expect(response.width).to.equal(serverRequest.width); + expect(response.height).to.equal(serverRequest.height); + expect(response.cpm).to.equal(serverResponse.body.price); + expect(response.currency).to.equal(serverResponse.body.currency); + expect(response.creativeId).to.equal(serverResponse.body.creativeId); expect(response.vastXml).to.be.undefined; expect(response.ad).to.include(`
`); expect(response.ad).to.include(``); @@ -375,11 +350,19 @@ describe('RelaidoAdapter', function () { }); describe('spec.onBidWon', function () { + let stub; + beforeEach(() => { + stub = sinon.stub(utils, 'triggerPixel'); + }); + afterEach(() => { + stub.restore(); + }); + it('Should create nurl pixel if bid nurl', function () { let bid = { bidder: bidRequest.bidder, - creativeId: serverResponse.body.ads[0].creativeId, - cpm: serverResponse.body.ads[0].price, + creativeId: serverResponse.body.creativeId, + cpm: serverResponse.body.price, params: [bidRequest.params], auctionId: bidRequest.auctionId, requestId: bidRequest.bidId, @@ -388,7 +371,7 @@ describe('RelaidoAdapter', function () { ref: window.location.href, } spec.onBidWon(bid); - const parser = utils.parseUrl(triggerPixelStub.getCall(0).args[0]); + const parser = utils.parseUrl(stub.getCall(0).args[0]); const query = parser.search; expect(parser.hostname).to.equal('api.relaido.jp'); expect(parser.pathname).to.equal('/tr/v1/prebid/win.gif'); @@ -404,6 +387,14 @@ describe('RelaidoAdapter', function () { }); describe('spec.onTimeout', function () { + let stub; + beforeEach(() => { + stub = sinon.stub(utils, 'triggerPixel'); + }); + afterEach(() => { + stub.restore(); + }); + it('Should create nurl pixel if bid nurl', function () { const data = [{ bidder: bidRequest.bidder, @@ -414,7 +405,7 @@ describe('RelaidoAdapter', function () { timeout: bidderRequest.timeout, }]; spec.onTimeout(data); - const parser = utils.parseUrl(triggerPixelStub.getCall(0).args[0]); + const parser = utils.parseUrl(stub.getCall(0).args[0]); const query = parser.search; expect(parser.hostname).to.equal('api.relaido.jp'); expect(parser.pathname).to.equal('/tr/v1/prebid/timeout.gif'); diff --git a/test/spec/modules/richaudienceBidAdapter_spec.js b/test/spec/modules/richaudienceBidAdapter_spec.js index 9e9366072be..00ae55823b0 100644 --- a/test/spec/modules/richaudienceBidAdapter_spec.js +++ b/test/spec/modules/richaudienceBidAdapter_spec.js @@ -791,46 +791,6 @@ describe('Richaudience adapter tests', function () { })).to.equal(true); }); - it('should pass schain', function() { - let schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'richaudience.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'richaudience-2.com', - 'sid': '00002', - 'hp': 1 - }] - } - - DEFAULT_PARAMS_NEW_SIZES[0].schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'richaudience.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'richaudience-2.com', - 'sid': '00002', - 'hp': 1 - }] - } - - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: {} - }) - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('schain').to.deep.equal(schain); - }) - describe('userSync', function () { it('Verifies user syncs iframe include', function () { config.setConfig({ @@ -945,7 +905,7 @@ describe('Richaudience adapter tests', function () { }, [], { consentString: null, referer: 'http://domain.com', - gdprApplies: false + gdprApplies: true }) expect(syncs).to.have.lengthOf(1); expect(syncs[0].type).to.equal('image'); @@ -982,7 +942,7 @@ describe('Richaudience adapter tests', function () { }, [], { consentString: null, referer: 'http://domain.com', - gdprApplies: false + gdprApplies: true }) expect(syncs).to.have.lengthOf(0); }); diff --git a/test/spec/modules/riseBidAdapter_spec.js b/test/spec/modules/riseBidAdapter_spec.js index 211c36a254a..61b307eef21 100644 --- a/test/spec/modules/riseBidAdapter_spec.js +++ b/test/spec/modules/riseBidAdapter_spec.js @@ -257,7 +257,7 @@ describe('riseAdapter', function () { const requests = spec.buildRequests(bidRequests, bidderRequest); for (const request of requests) { expect(request.data).to.be.an('object'); - expect(request.data).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); + expect(request.data).to.have.property('schain', '1.0,1!indirectseller.com,00001,,,,'); } }); diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js index f4bcb48474a..d6bee26d73b 100644 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ b/test/spec/modules/rtbhouseBidAdapter_spec.js @@ -68,7 +68,6 @@ describe('RTBHouseAdapter', () => { 'params': { 'publisherId': 'PREBID_TEST', 'region': 'prebid-eu', - 'channel': 'Partner_Site - news', 'test': 1 }, 'adUnitCode': 'adunit-code', @@ -102,25 +101,6 @@ describe('RTBHouseAdapter', () => { expect(JSON.parse(builtTestRequest).test).to.equal(1); }); - it('should build channel param into request.site', () => { - let builtTestRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel).to.equal('Partner_Site - news'); - }) - - it('should not build channel param into request.site if no value is passed', () => { - let bidRequest = Object.assign([], bidRequests); - bidRequest[0].params.channel = undefined; - let builtTestRequest = spec.buildRequests(bidRequest, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel).to.be.undefined - }) - - it('should cap the request.site.channel length to 50', () => { - let bidRequest = Object.assign([], bidRequests); - bidRequest[0].params.channel = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent scelerisque ipsum eu purus lobortis iaculis.'; - let builtTestRequest = spec.buildRequests(bidRequest, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel.length).to.equal(50) - }) - it('should build valid OpenRTB banner object', () => { const request = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); const imp = request.imp[0]; diff --git a/test/spec/modules/rubiconAnalyticsAdapter_spec.js b/test/spec/modules/rubiconAnalyticsAdapter_spec.js index 798e98bb97d..ea8a25ee27d 100644 --- a/test/spec/modules/rubiconAnalyticsAdapter_spec.js +++ b/test/spec/modules/rubiconAnalyticsAdapter_spec.js @@ -168,8 +168,8 @@ const floorMinRequest = { 'zoneId': '335918', 'userId': '12346', 'keywords': ['a', 'b', 'c'], - 'inventory': { 'rating': '4-star', 'prodtype': 'tech' }, - 'visitor': { 'ucat': 'new', 'lastsearch': 'iphone' }, + 'inventory': {'rating': '4-star', 'prodtype': 'tech'}, + 'visitor': {'ucat': 'new', 'lastsearch': 'iphone'}, 'position': 'atf' }, 'mediaTypes': { @@ -195,24 +195,24 @@ const MOCK = { 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', 'timestamp': 1519767010567, 'auctionStatus': 'inProgress', - 'adUnits': [{ + 'adUnits': [ { 'code': '/19968336/header-bid-tag1', 'sizes': [[640, 480]], - 'bids': [{ + 'bids': [ { 'bidder': 'rubicon', 'params': { 'accountId': 1001, 'siteId': 113932, 'zoneId': 535512 } - }], + } ], 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014' } ], 'adUnitCodes': ['/19968336/header-bid-tag1'], - 'bidderRequests': [{ + 'bidderRequests': [ { 'bidderCode': 'rubicon', 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', 'bidderRequestId': '1be65d7958826a', - 'bids': [{ + 'bids': [ { 'bidder': 'rubicon', 'params': { 'accountId': 1001, 'siteId': 113932, 'zoneId': 535512 @@ -259,7 +259,7 @@ const MOCK = { 'userId': '12346', 'keywords': ['a', 'b', 'c'], 'inventory': 'test', - 'visitor': { 'ucat': 'new', 'lastsearch': 'iphone' }, + 'visitor': {'ucat': 'new', 'lastsearch': 'iphone'}, 'position': 'btf', 'video': { 'language': 'en', @@ -296,8 +296,8 @@ const MOCK = { 'zoneId': '335918', 'userId': '12346', 'keywords': ['a', 'b', 'c'], - 'inventory': { 'rating': '4-star', 'prodtype': 'tech' }, - 'visitor': { 'ucat': 'new', 'lastsearch': 'iphone' }, + 'inventory': {'rating': '4-star', 'prodtype': 'tech'}, + 'visitor': {'ucat': 'new', 'lastsearch': 'iphone'}, 'position': 'atf' }, 'mediaTypes': { @@ -655,10 +655,10 @@ describe('rubicon analytics adapter', function () { expect(utils.logError.called).to.equal(true); }); - describe('config subscribe', function () { + describe('config subscribe', function() { it('should update the pvid if user asks', function () { expect(utils.generateUUID.called).to.equal(false); - config.setConfig({ rubicon: { updatePageView: true } }); + config.setConfig({rubicon: {updatePageView: true}}); expect(utils.generateUUID.called).to.equal(true); }); it('should merge in and preserve older set configs', function () { @@ -859,7 +859,7 @@ describe('rubicon analytics adapter', function () { criteoId: 'sadfe4334', lotamePanoramaId: 'asdf3gf4eg', pubcid: 'dsfa4545-svgdfs5', - sharedId: { id1: 'asdf', id2: 'sadf4344' } + sharedId: {id1: 'asdf', id2: 'sadf4344'} }; events.emit(AUCTION_INIT, auctionInit); @@ -881,10 +881,10 @@ describe('rubicon analytics adapter', function () { expect(message.auctions[0].user).to.deep.equal({ ids: [ - { provider: 'criteoId', 'hasId': true }, - { provider: 'lotamePanoramaId', 'hasId': true }, - { provider: 'pubcid', 'hasId': true }, - { provider: 'sharedId', 'hasId': true }, + {provider: 'criteoId', 'hasId': true}, + {provider: 'lotamePanoramaId', 'hasId': true}, + {provider: 'pubcid', 'hasId': true}, + {provider: 'sharedId', 'hasId': true}, ] }); }); @@ -987,28 +987,6 @@ describe('rubicon analytics adapter', function () { expect(message.auctions[0].adUnits[1].bids[0].bidResponse.adomains).to.be.undefined; }); - it('should not pass empty adServerTargeting values', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - - const mockTargeting = utils.deepClone(MOCK.SET_TARGETING); - mockTargeting['/19968336/header-bid-tag-0'].hb_test = ''; - mockTargeting['/19968336/header-bid-tag1'].hb_test = 'NOT_EMPTY'; - events.emit(SET_TARGETING, mockTargeting); - - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - let message = JSON.parse(server.requests[0].requestBody); - validate(message); - expect(message.auctions[0].adUnits[0].adserverTargeting.hb_test).to.be.undefined; - expect(message.auctions[0].adUnits[1].adserverTargeting.hb_test).to.equal('NOT_EMPTY'); - }); - function performFloorAuction(provider) { let auctionInit = utils.deepClone(MOCK.AUCTION_INIT); auctionInit.bidderRequests[0].bids[0].floorData = { @@ -1206,7 +1184,7 @@ describe('rubicon analytics adapter', function () { describe('with session handling', function () { const expectedPvid = STUBBED_UUID.slice(0, 8); beforeEach(function () { - config.setConfig({ rubicon: { updatePageView: true } }); + config.setConfig({rubicon: {updatePageView: true}}); }); it('should not log any session data if local storage is not enabled', function () { @@ -1230,14 +1208,12 @@ describe('rubicon analytics adapter', function () { }); it('should should pass along custom rubicon kv and pvid when defined', function () { - config.setConfig({ - rubicon: { - fpkvs: { - source: 'fb', - link: 'email' - } + config.setConfig({rubicon: { + fpkvs: { + source: 'fb', + link: 'email' } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); let request = server.requests[0]; @@ -1247,24 +1223,22 @@ describe('rubicon analytics adapter', function () { let expectedMessage = utils.deepClone(ANALYTICS_MESSAGE); expectedMessage.session.pvid = STUBBED_UUID.slice(0, 8); expectedMessage.fpkvs = [ - { key: 'source', value: 'fb' }, - { key: 'link', value: 'email' } + {key: 'source', value: 'fb'}, + {key: 'link', value: 'email'} ] expect(message).to.deep.equal(expectedMessage); }); it('should convert kvs to strings before sending', function () { - config.setConfig({ - rubicon: { - fpkvs: { - number: 24, - boolean: false, - string: 'hello', - array: ['one', 2, 'three'], - object: { one: 'two' } - } + config.setConfig({rubicon: { + fpkvs: { + number: 24, + boolean: false, + string: 'hello', + array: ['one', 2, 'three'], + object: {one: 'two'} } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); let request = server.requests[0]; @@ -1274,26 +1248,24 @@ describe('rubicon analytics adapter', function () { let expectedMessage = utils.deepClone(ANALYTICS_MESSAGE); expectedMessage.session.pvid = STUBBED_UUID.slice(0, 8); expectedMessage.fpkvs = [ - { key: 'number', value: '24' }, - { key: 'boolean', value: 'false' }, - { key: 'string', value: 'hello' }, - { key: 'array', value: 'one,2,three' }, - { key: 'object', value: '[object Object]' } + {key: 'number', value: '24'}, + {key: 'boolean', value: 'false'}, + {key: 'string', value: 'hello'}, + {key: 'array', value: 'one,2,three'}, + {key: 'object', value: '[object Object]'} ] expect(message).to.deep.equal(expectedMessage); }); it('should use the query utm param rubicon kv value and pass updated kv and pvid when defined', function () { - sandbox.stub(utils, 'getWindowLocation').returns({ 'search': '?utm_source=other', 'pbjs_debug': 'true' }); + sandbox.stub(utils, 'getWindowLocation').returns({'search': '?utm_source=other', 'pbjs_debug': 'true'}); - config.setConfig({ - rubicon: { - fpkvs: { - source: 'fb', - link: 'email' - } + config.setConfig({rubicon: { + fpkvs: { + source: 'fb', + link: 'email' } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); let request = server.requests[0]; @@ -1303,8 +1275,8 @@ describe('rubicon analytics adapter', function () { let expectedMessage = utils.deepClone(ANALYTICS_MESSAGE); expectedMessage.session.pvid = STUBBED_UUID.slice(0, 8); expectedMessage.fpkvs = [ - { key: 'source', value: 'other' }, - { key: 'link', value: 'email' } + {key: 'source', value: 'other'}, + {key: 'link', value: 'email'} ] message.fpkvs.sort((left, right) => left.key < right.key); @@ -1324,13 +1296,11 @@ describe('rubicon analytics adapter', function () { }; getDataFromLocalStorageStub.withArgs('rpaSession').returns(btoa(JSON.stringify(inputlocalStorage))); - config.setConfig({ - rubicon: { - fpkvs: { - link: 'email' // should merge this with what is in the localStorage! - } + config.setConfig({rubicon: { + fpkvs: { + link: 'email' // should merge this with what is in the localStorage! } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); let request = server.requests[0]; @@ -1345,8 +1315,8 @@ describe('rubicon analytics adapter', function () { pvid: expectedPvid } expectedMessage.fpkvs = [ - { key: 'source', value: 'tw' }, - { key: 'link', value: 'email' } + {key: 'source', value: 'tw'}, + {key: 'link', value: 'email'} ] expect(message).to.deep.equal(expectedMessage); @@ -1368,7 +1338,7 @@ describe('rubicon analytics adapter', function () { }); it('should overwrite matching localstorge value and use its remaining values', function () { - sandbox.stub(utils, 'getWindowLocation').returns({ 'search': '?utm_source=fb&utm_click=dog' }); + sandbox.stub(utils, 'getWindowLocation').returns({'search': '?utm_source=fb&utm_click=dog'}); // set some localStorage let inputlocalStorage = { @@ -1380,13 +1350,11 @@ describe('rubicon analytics adapter', function () { }; getDataFromLocalStorageStub.withArgs('rpaSession').returns(btoa(JSON.stringify(inputlocalStorage))); - config.setConfig({ - rubicon: { - fpkvs: { - link: 'email' // should merge this with what is in the localStorage! - } + config.setConfig({rubicon: { + fpkvs: { + link: 'email' // should merge this with what is in the localStorage! } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); let request = server.requests[0]; @@ -1401,9 +1369,9 @@ describe('rubicon analytics adapter', function () { pvid: expectedPvid } expectedMessage.fpkvs = [ - { key: 'source', value: 'fb' }, - { key: 'link', value: 'email' }, - { key: 'click', value: 'dog' } + {key: 'source', value: 'fb'}, + {key: 'link', value: 'email'}, + {key: 'click', value: 'dog'} ] message.fpkvs.sort((left, right) => left.key < right.key); @@ -1439,13 +1407,11 @@ describe('rubicon analytics adapter', function () { }; getDataFromLocalStorageStub.withArgs('rpaSession').returns(btoa(JSON.stringify(inputlocalStorage))); - config.setConfig({ - rubicon: { - fpkvs: { - link: 'email' // should merge this with what is in the localStorage! - } + config.setConfig({rubicon: { + fpkvs: { + link: 'email' // should merge this with what is in the localStorage! } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); @@ -1459,7 +1425,7 @@ describe('rubicon analytics adapter', function () { // the saved fpkvs should have been thrown out since session expired expectedMessage.fpkvs = [ - { key: 'link', value: 'email' } + {key: 'link', value: 'email'} ] expect(message).to.deep.equal(expectedMessage); @@ -1491,13 +1457,11 @@ describe('rubicon analytics adapter', function () { }; getDataFromLocalStorageStub.withArgs('rpaSession').returns(btoa(JSON.stringify(inputlocalStorage))); - config.setConfig({ - rubicon: { - fpkvs: { - link: 'email' // should merge this with what is in the localStorage! - } + config.setConfig({rubicon: { + fpkvs: { + link: 'email' // should merge this with what is in the localStorage! } - }); + }}); performStandardAuction(); expect(server.requests.length).to.equal(1); @@ -1511,7 +1475,7 @@ describe('rubicon analytics adapter', function () { // the saved fpkvs should have been thrown out since session expired expectedMessage.fpkvs = [ - { key: 'link', value: 'email' } + {key: 'link', value: 'email'} ] expect(message).to.deep.equal(expectedMessage); @@ -1537,7 +1501,7 @@ describe('rubicon analytics adapter', function () { let gptSlotRenderEnded0, gptSlotRenderEnded1; beforeEach(function () { mockGpt.enable(); - gptSlot0 = mockGpt.makeSlot({ code: '/19968336/header-bid-tag-0' }); + gptSlot0 = mockGpt.makeSlot({code: '/19968336/header-bid-tag-0'}); gptSlotRenderEnded0 = { eventName: 'slotRenderEnded', params: { @@ -1549,7 +1513,7 @@ describe('rubicon analytics adapter', function () { } }; - gptSlot1 = mockGpt.makeSlot({ code: '/19968336/header-bid-tag1' }); + gptSlot1 = mockGpt.makeSlot({code: '/19968336/header-bid-tag1'}); gptSlotRenderEnded1 = { eventName: 'slotRenderEnded', params: { @@ -1985,7 +1949,6 @@ describe('rubicon analytics adapter', function () { let timedOutBid = message.auctions[0].adUnits[0].bids[0]; expect(timedOutBid.status).to.equal('error'); expect(timedOutBid.error.code).to.equal('timeout-error'); - expect(timedOutBid.error.description).to.equal('prebid.js timeout'); expect(timedOutBid).to.not.have.property('bidResponse'); }); @@ -2066,7 +2029,7 @@ describe('rubicon analytics adapter', function () { // Now add the bidResponse hook which hooks on the currenct conversion function onto the bid response let innerBid; - addBidResponseHook(function (adCodeId, bid) { + addBidResponseHook(function(adCodeId, bid) { innerBid = bid; }, 'elementId', bidCopy); @@ -2079,11 +2042,9 @@ describe('rubicon analytics adapter', function () { describe('config with integration type', () => { it('should use the integration type provided in the config instead of the default', () => { - config.setConfig({ - rubicon: { - int_type: 'testType' - } - }) + config.setConfig({rubicon: { + int_type: 'testType' + }}) rubiconAnalyticsAdapter.enableAnalytics({ options: { @@ -2105,13 +2066,11 @@ describe('rubicon analytics adapter', function () { describe('wrapper details passed in', () => { it('should correctly pass in the wrapper details if provided', () => { - config.setConfig({ - rubicon: { - wrapperName: '1001_wrapperName_exp.4', - wrapperFamily: '1001_wrapperName', - rule_name: 'na-mobile' - } - }); + config.setConfig({rubicon: { + wrapperName: '1001_wrapperName_exp.4', + wrapperFamily: '1001_wrapperName', + rule_name: 'na-mobile' + }}); rubiconAnalyticsAdapter.enableAnalytics({ options: { diff --git a/test/spec/modules/rubiconAnalyticsSchema.json b/test/spec/modules/rubiconAnalyticsSchema.json index 39a33867edd..a8fdeae5268 100644 --- a/test/spec/modules/rubiconAnalyticsSchema.json +++ b/test/spec/modules/rubiconAnalyticsSchema.json @@ -263,9 +263,7 @@ }, "isSlotEmpty": { "type": "boolean", - "enum": [ - true - ] + "enum": [true] } } }, @@ -371,7 +369,6 @@ }, "error": { "type": "object", - "additionalProperties": false, "required": [ "code" ], @@ -451,4 +448,4 @@ } } } -} \ No newline at end of file +} diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index ea839bc7ae3..6210640f79f 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -1408,7 +1408,7 @@ describe('the rubicon adapter', function () { expect(data['tg_i.pbadslot']).to.equal('abc'); }); - it('should send \"tg_i.pbadslot\" if \"ortb2Imp.ext.data.pbadslot\" value is a valid string', function () { + it('should send \"tg_i.pbadslot\" if \"ortb2Imp.ext.data.pbadslot\" value is a valid string, but all leading slash characters should be removed', function () { bidderRequest.bids[0].ortb2Imp = { ext: { data: { @@ -1422,45 +1422,7 @@ describe('the rubicon adapter', function () { expect(data).to.be.an('Object'); expect(data).to.have.property('tg_i.pbadslot'); - expect(data['tg_i.pbadslot']).to.equal('/a/b/c'); - }); - - it('should send gpid as p_gpid if valid', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - gpid: '/1233/sports&div1' - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = parseQuery(request.data); - - expect(data).to.be.an('Object'); - expect(data).to.have.property('p_gpid'); - expect(data['p_gpid']).to.equal('/1233/sports&div1'); - }); - - it('should send gpid and pbadslot since it is prefered over dfp code', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - gpid: '/1233/sports&div1', - data: { - pbadslot: 'pb_slot', - adserver: { - adslot: '/1234/sports', - name: 'gam' - } - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = parseQuery(request.data); - - expect(data).to.be.an('Object'); - expect(data['p_gpid']).to.equal('/1233/sports&div1'); - expect(data).to.not.have.property('tg_i.dfp_ad_unit_code'); - expect(data['tg_i.pbadslot']).to.equal('pb_slot'); + expect(data['tg_i.pbadslot']).to.equal('a/b/c'); }); }); @@ -1508,13 +1470,12 @@ describe('the rubicon adapter', function () { expect(data).to.not.have.property('tg_i.dfp_ad_unit_code'); }); - it('should send NOT \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string but not gam', function () { + it('should send \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string', function () { bidderRequest.bids[0].ortb2Imp = { ext: { data: { adserver: { - adslot: '/a/b/c', - name: 'not gam' + adslot: 'abc' } } } @@ -1524,16 +1485,16 @@ describe('the rubicon adapter', function () { const data = parseQuery(request.data); expect(data).to.be.an('Object'); - expect(data).to.not.have.property('tg_i.dfp_ad_unit_code'); + expect(data).to.have.property('tg_i.dfp_ad_unit_code'); + expect(data['tg_i.dfp_ad_unit_code']).to.equal('abc'); }); - it('should send \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string and name is gam', function () { + it('should send \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string, but all leading slash characters should be removed', function () { bidderRequest.bids[0].ortb2Imp = { ext: { data: { adserver: { - name: 'gam', - adslot: '/a/b/c' + adslot: 'a/b/c' } } } @@ -1544,7 +1505,7 @@ describe('the rubicon adapter', function () { expect(data).to.be.an('Object'); expect(data).to.have.property('tg_i.dfp_ad_unit_code'); - expect(data['tg_i.dfp_ad_unit_code']).to.equal('/a/b/c'); + expect(data['tg_i.dfp_ad_unit_code']).to.equal('a/b/c'); }); }); }); @@ -3382,23 +3343,6 @@ describe('the rubicon adapter', function () { type: 'iframe', url: `${emilyUrl}?gdpr_consent=foo&us_privacy=1NYN` }); }); - - it('should pass gdprApplies', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: true - }, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=1&us_privacy=1NYN` - }); - }); - - it('should pass all correctly', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: true, - consentString: 'foo' - }, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN` - }); - }); }); describe('get price granularity', function () { diff --git a/test/spec/modules/seedingAllianceAdapter_spec.js b/test/spec/modules/seedingAllianceAdapter_spec.js deleted file mode 100755 index 81af9546ff0..00000000000 --- a/test/spec/modules/seedingAllianceAdapter_spec.js +++ /dev/null @@ -1,186 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -import {assert, expect} from 'chai'; -import {spec} from 'modules/seedingAllianceBidAdapter.js'; -import { NATIVE } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; - -describe('SeedingAlliance adapter', function () { - let serverResponse, bidRequest, bidResponses; - let bid = { - 'bidder': 'seedingAlliance', - 'params': { - 'adUnitId': '1hq8' - } - }; - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when AdUnitId is not set', function () { - delete bid.params.adUnitId; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - it('should send request with correct structure', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - - let request = spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }); - - assert.equal(request.method, 'POST'); - assert.ok(request.data); - }); - - it('should have default request structure', function () { - let keys = 'site,device,cur,imp,user,regs'.split(','); - let validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); - let data = Object.keys(request); - - assert.deepEqual(keys, data); - }); - - it('Verify the auction ID', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {}, - auctionId: 'auctionId' - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' }, auctionId: validBidRequests[0].auctionId }).data); - - assert.equal(request.id, validBidRequests[0].auctionId); - }); - - it('Verify the device', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - let request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); - - assert.equal(request.device.ua, navigator.userAgent); - }); - - it('Verify native asset ids', function () { - let validBidRequests = [{ - bidId: 'bidId', - params: {}, - nativeParams: { - body: { - required: true, - len: 350 - }, - image: { - required: true - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - cta: { - required: true - }, - icon: { - required: true - } - } - }]; - - let assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; - - assert.equal(assets[0].id, 1); - assert.equal(assets[1].id, 3); - assert.equal(assets[2].id, 0); - assert.equal(assets[3].id, 2); - assert.equal(assets[4].id, 4); - assert.equal(assets[5].id, 5); - }); - }); - - describe('interpretResponse', function () { - const goodResponse = { - body: { - cur: 'EUR', - id: '4b516b80-886e-4ec0-82ae-9209e6d625fb', - seatbid: [ - { - seat: 'seedingAlliance', - bid: [{ - adm: { - native: { - assets: [ - {id: 0, title: {text: 'this is a title'}} - ], - imptrackers: ['https://domain.for/imp/tracker?price=${AUCTION_PRICE}'], - link: { - clicktrackers: ['https://domain.for/imp/tracker?price=${AUCTION_PRICE}'], - url: 'https://domain.for/ad/' - } - } - }, - impid: 1, - price: 0.55 - }] - } - ] - } - }; - const badResponse = { body: { - cur: 'EUR', - id: '4b516b80-886e-4ec0-82ae-9209e6d625fb', - seatbid: [] - }}; - - const bidRequest = { - data: {}, - bids: [{ bidId: 'bidId1' }] - }; - - it('should return null if body is missing or empty', function () { - const result = spec.interpretResponse(badResponse, bidRequest); - assert.equal(result.length, 0); - - delete badResponse.body - - const result1 = spec.interpretResponse(badResponse, bidRequest); - assert.equal(result.length, 0); - }); - - it('should return the correct params', function () { - const result = spec.interpretResponse(goodResponse, bidRequest); - const bid = goodResponse.body.seatbid[0].bid[0]; - - assert.deepEqual(result[0].currency, goodResponse.body.cur); - assert.deepEqual(result[0].requestId, bidRequest.bids[0].bidId); - assert.deepEqual(result[0].cpm, bid.price); - assert.deepEqual(result[0].creativeId, bid.crid); - assert.deepEqual(result[0].mediaType, 'native'); - assert.deepEqual(result[0].bidderCode, 'seedingAlliance'); - }); - - it('should return the correct tracking links', function () { - const result = spec.interpretResponse(goodResponse, bidRequest); - const bid = goodResponse.body.seatbid[0].bid[0]; - const regExpPrice = new RegExp('price=' + bid.price); - - result[0].native.clickTrackers.forEach(function (clickTracker) { - assert.ok(clickTracker.search(regExpPrice) > -1); - }); - - result[0].native.impressionTrackers.forEach(function (impTracker) { - assert.ok(impTracker.search(regExpPrice) > -1); - }); - }); - }); -}); diff --git a/test/spec/modules/seedtagBidAdapter_spec.js b/test/spec/modules/seedtagBidAdapter_spec.js index 159645ff6d6..3aa378379dd 100644 --- a/test/spec/modules/seedtagBidAdapter_spec.js +++ b/test/spec/modules/seedtagBidAdapter_spec.js @@ -274,9 +274,6 @@ describe('Seedtag Adapter', function() { expect(data.ga).to.equal(true) expect(data.cd).to.equal('consentString') }) - it('should expose gvlid', function() { - expect(spec.gvlid).to.equal(157) - }) }) }) diff --git a/test/spec/modules/sharedIdSystem_spec.js b/test/spec/modules/sharedIdSystem_spec.js index 8ef34a1599e..534d0b3f381 100644 --- a/test/spec/modules/sharedIdSystem_spec.js +++ b/test/spec/modules/sharedIdSystem_spec.js @@ -50,10 +50,10 @@ describe('SharedId System', function () { expect(callbackSpy.calledOnce).to.be.true; expect(callbackSpy.lastCall.lastArg).to.equal(UUID); }); - it('should abort if coppa is set', function () { + it('should log message if coppa is set', function () { coppaDataHandlerDataStub.returns('true'); - const result = sharedIdSystemSubmodule.getId({}); - expect(result).to.be.undefined; + sharedIdSystemSubmodule.getId({}); + expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); }); }); describe('SharedId System extendId()', function () { @@ -85,56 +85,10 @@ describe('SharedId System', function () { let pubcommId = sharedIdSystemSubmodule.extendId(config, undefined, 'TestId').id; expect(pubcommId).to.equal('TestId'); }); - it('should abort if coppa is set', function () { + it('should log message if coppa is set', function () { coppaDataHandlerDataStub.returns('true'); - const result = sharedIdSystemSubmodule.extendId({params: {extend: true}}, undefined, 'TestId'); - expect(result).to.be.undefined; - }); - }); - - describe('SharedID System domainOverride', () => { - let sandbox, domain, cookies, rejectCookiesFor; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(document, 'domain').get(() => domain); - cookies = {}; - sandbox.stub(storage, 'getCookie').callsFake((key) => cookies[key]); - rejectCookiesFor = null; - sandbox.stub(storage, 'setCookie').callsFake((key, value, expires, sameSite, domain) => { - if (domain !== rejectCookiesFor) { - if (expires != null) { - expires = new Date(expires); - } - if (expires == null || expires > Date.now()) { - cookies[key] = value; - } else { - delete cookies[key]; - } - } - }); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should return TLD if cookies can be set there', () => { - domain = 'sub.domain.com'; - rejectCookiesFor = 'com'; - expect(sharedIdSystemSubmodule.domainOverride()).to.equal('domain.com'); - }); - - it('should return undefined when cookies cannot be set', () => { - domain = 'sub.domain.com'; - rejectCookiesFor = 'sub.domain.com'; - expect(sharedIdSystemSubmodule.domainOverride()).to.be.undefined; - }); - - it('should return half-way domain if parent domain rejects cookies', () => { - domain = 'inner.outer.domain.com'; - rejectCookiesFor = 'domain.com'; - expect(sharedIdSystemSubmodule.domainOverride()).to.equal('outer.domain.com'); + sharedIdSystemSubmodule.extendId({}, undefined, 'TestId'); + expect(utils.logInfo.args[0][0]).to.exist.and.to.equal('PubCommonId: IDs not provided for coppa requests, exiting PubCommonId'); }); }); }); diff --git a/test/spec/modules/sharethroughBidAdapter_spec.js b/test/spec/modules/sharethroughBidAdapter_spec.js index 39238cc877f..3e406e1af44 100644 --- a/test/spec/modules/sharethroughBidAdapter_spec.js +++ b/test/spec/modules/sharethroughBidAdapter_spec.js @@ -1,649 +1,632 @@ import { expect } from 'chai'; -import * as sinon from 'sinon'; import { sharethroughAdapterSpec, sharethroughInternal } from 'modules/sharethroughBidAdapter.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; +import * as utils from '../../../src/utils.js'; import { config } from 'src/config'; -import * as utils from 'src/utils'; const spec = newBidder(sharethroughAdapterSpec).getSpec(); +const bidRequests = [ + { + bidder: 'sharethrough', + bidId: 'bidId1', + sizes: [[600, 300]], + placementCode: 'foo', + params: { + pkey: 'aaaa1111' + }, + ortb2Imp: { + ext: { + data: { + pbadslot: 'adslot-id-1' + } + } + }, + userId: { + tdid: 'fake-tdid', + pubcid: 'fake-pubcid', + idl_env: 'fake-identity-link', + id5id: { + uid: 'fake-id5id', + ext: { + linkType: 2 + } + }, + lipb: { + lipbid: 'fake-lipbid' + } + }, + crumbs: { + pubcid: 'fake-pubcid-in-crumbs-obj' + } + }, + { + bidder: 'sharethrough', + bidId: 'bidId2', + sizes: [[700, 400]], + placementCode: 'bar', + params: { + pkey: 'bbbb2222', + iframe: true + } + }, + { + bidder: 'sharethrough', + bidId: 'bidId3', + sizes: [[700, 400]], + placementCode: 'coconut', + params: { + pkey: 'cccc3333', + iframe: true, + iframeSize: [500, 500] + } + }, + { + bidder: 'sharethrough', + bidId: 'bidId4', + sizes: [[700, 400]], + placementCode: 'bar', + params: { + pkey: 'dddd4444', + badv: ['domain1.com', 'domain2.com'] + } + }, + { + bidder: 'sharethrough', + bidId: 'bidId5', + sizes: [[700, 400]], + placementCode: 'bar', + params: { + pkey: 'eeee5555', + bcat: ['IAB1-1', 'IAB1-2'] + } + }, +]; + +const prebidRequests = [ + { + method: 'POST', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', + data: { + bidId: 'bidId', + placement_key: 'pKey' + }, + strData: { + skipIframeBusting: false, + sizes: [] + } + }, + { + method: 'POST', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', + data: { + bidId: 'bidId', + placement_key: 'pKey' + }, + strData: { + skipIframeBusting: true, + sizes: [[300, 250], [300, 300], [250, 250], [600, 50]] + } + }, + { + method: 'POST', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', + data: { + bidId: 'bidId', + placement_key: 'pKey' + }, + strData: { + skipIframeBusting: true, + iframeSize: [500, 500], + sizes: [[300, 250], [300, 300], [250, 250], [600, 50]] + } + }, + { + method: 'POST', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', + data: { + bidId: 'bidId', + placement_key: 'pKey' + }, + strData: { + skipIframeBusting: false, + sizes: [[0, 0]] + } + }, + { + method: 'POST', + url: 'https://btlr.sharethrough.com/WYu2BXv1/v1', + data: { + bidId: 'bidId', + placement_key: 'pKey' + }, + strData: { + skipIframeBusting: false, + sizes: [[300, 250], [300, 300], [250, 250], [600, 50]] + } + } +]; + +const bidderResponse = { + body: { + 'adserverRequestId': '40b6afd5-6134-4fbb-850a-bb8972a46994', + 'bidId': 'bidId1', + 'version': 1, + 'creatives': [{ + 'auctionWinId': 'b2882d5e-bf8b-44da-a91c-0c11287b8051', + 'cpm': 12.34, + 'creative': { + 'deal_id': 'aDealId', + 'creative_key': 'aCreativeId', + 'title': '✓ à la mode' + } + }], + 'stxUserId': '' + }, + header: { get: (header) => header } +}; + +const setUserAgent = (uaString) => { + window.navigator['__defineGetter__']('userAgent', function() { + return uaString; + }); +}; + +describe('sharethrough internal spec', function() { + let windowStub, windowTopStub; + let stubbedReturn = [{ + appendChild: () => undefined + }] + beforeEach(function() { + windowStub = sinon.stub(window.document, 'getElementsByTagName'); + windowTopStub = sinon.stub(window.top.document, 'getElementsByTagName'); + windowStub.withArgs('body').returns(stubbedReturn); + windowTopStub.withArgs('body').returns(stubbedReturn); + }); + + afterEach(function() { + windowStub.restore(); + windowTopStub.restore(); + window.STR = undefined; + window.top.STR = undefined; + }); + + describe('we cannot access top level document', function() { + beforeEach(function() { + window.lockedInFrame = true; + }); + + afterEach(function() { + window.lockedInFrame = false; + }); -describe('sharethrough adapter spec', function () { - let protocolStub; - let inIframeStub; + it('appends sfp.js to the safeframe', function() { + sharethroughInternal.handleIframe(); + expect(windowStub.calledOnce).to.be.true; + }); - beforeEach(() => { - protocolStub = sinon.stub(sharethroughInternal, 'getProtocol').returns('https'); - inIframeStub = sinon.stub(utils, 'inIframe').returns(false); + it('does not append anything if sfp.js is already loaded in the safeframe', function() { + window.STR = { Tag: true }; + sharethroughInternal.handleIframe(); + expect(windowStub.notCalled).to.be.true; + expect(windowTopStub.notCalled).to.be.true; + }); }); - afterEach(() => { - protocolStub.restore(); - inIframeStub.restore(); + describe('we are able to bust out of the iframe', function() { + it('appends sfp.js to window.top', function() { + sharethroughInternal.handleIframe(); + expect(windowStub.calledOnce).to.be.true; + expect(windowTopStub.calledOnce).to.be.true; + }); + + it('only appends sfp-set-targeting.js if sfp.js is already loaded on the page', function() { + window.top.STR = { Tag: true }; + sharethroughInternal.handleIframe(); + expect(windowStub.calledOnce).to.be.true; + expect(windowTopStub.notCalled).to.be.true; + }); }); +}); - describe('code', function () { - it('should return a bidder code of sharethrough', function () { +describe('sharethrough adapter spec', function() { + describe('.code', function() { + it('should return a bidder code of sharethrough', function() { expect(spec.code).to.eql('sharethrough'); }); }); - describe('isBidRequestValid', function () { - it('should return false if req has no pkey', function () { + describe('.isBidRequestValid', function() { + it('should return false if req has no pkey', function() { const invalidBidRequest = { bidder: 'sharethrough', params: { - notPKey: 'abc123', - }, + notPKey: 'abc123' + } }; expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); }); - it('should return false if req has wrong bidder code', function () { + it('should return false if req has wrong bidder code', function() { const invalidBidRequest = { bidder: 'notSharethrough', params: { - pkey: 'abc123', - }, + notPKey: 'abc123' + } }; expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); }); - it('should return true if req is correct', function () { - const validBidRequest = { - bidder: 'sharethrough', - params: { - pkey: 'abc123', - }, - }; - expect(spec.isBidRequestValid(validBidRequest)).to.eq(true); + it('should return true if req is correct', function() { + expect(spec.isBidRequestValid(bidRequests[0])).to.eq(true); + expect(spec.isBidRequestValid(bidRequests[1])).to.eq(true); }); }); - describe('open rtb', () => { - let bidRequests, bidderRequest; + describe('.buildRequests', function() { + it('should return an array of requests', function() { + const builtBidRequests = spec.buildRequests(bidRequests); - beforeEach(() => { - config.setConfig({ - bidderTimeout: 242, - coppa: true, - }); - - bidRequests = [ - { - bidder: 'sharethrough', - bidId: 'bidId1', - sizes: [[300, 250], [300, 600]], - params: { - pkey: 'aaaa1111', - bcat: ['cat1', 'cat2'], - badv: ['adv1', 'adv2'], - }, - mediaTypes: { - banner: { - pos: 1, - }, - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'universal-id', - }, - }, - }, - userId: { - tdid: 'fake-tdid', - pubcid: 'fake-pubcid', - idl_env: 'fake-identity-link', - id5id: { - uid: 'fake-id5id', - ext: { - linkType: 2, - }, - }, - lipb: { - lipbid: 'fake-lipbid', - }, - criteoId: 'fake-criteo', - britepoolid: 'fake-britepool', - intentIqId: 'fake-intentiq', - lotamePanoramaId: 'fake-lotame', - parrableId: { - eid: 'fake-parrable', - }, - netId: 'fake-netid', - sharedid: { - id: 'fake-sharedid', - }, - flocId: { - id: 'fake-flocid', - version: '42', - }, - }, - crumbs: { - pubcid: 'fake-pubcid-in-crumbs-obj', - }, - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1, - }, - ], - }, - getFloor: () => ({ currency: 'USD', floor: 42 }), - }, - { - bidder: 'sharethrough', - bidId: 'bidId2', - sizes: [[600, 300]], - params: { - pkey: 'bbbb2222', - }, - mediaTypes: { - video: { - pos: 3, - skip: 1, - linearity: 0, - minduration: 10, - maxduration: 30, - playbackmethod: [1], - api: [3], - mimes: ['video/3gpp'], - protocols: [2, 3], - playerSize: [640, 480], - startdelay: 42, - skipmin: 10, - skipafter: 20, - delivery: 1, - companiontype: 'companion type', - companionad: 'companion ad', - context: 'instream', - }, - }, - getFloor: () => ({ currency: 'USD', floor: 42 }), - }, - ]; - - bidderRequest = { - refererInfo: { - referer: 'https://referer.com', - }, - }; + expect(builtBidRequests[0].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1'); + expect(builtBidRequests[1].url).to.eq('https://btlr.sharethrough.com/WYu2BXv1/v1'); + expect(builtBidRequests[0].method).to.eq('POST'); }); - describe('buildRequests', function () { - describe('top level object', () => { - it('should build openRTB request', () => { - const builtRequests = spec.buildRequests(bidRequests, bidderRequest); - - const expectedImpValues = [ - { - id: 'bidId1', - tagid: 'aaaa1111', - secure: 1, - bidfloor: 42, - }, - { - id: 'bidId2', - tagid: 'bbbb2222', - secure: 1, - bidfloor: 42, - }, - ]; - - builtRequests.map((builtRequest, rIndex) => { - expect(builtRequest.method).to.equal('POST'); - expect(builtRequest.url).not.to.be.undefined; - expect(builtRequest.options).to.be.undefined; - - const openRtbReq = builtRequest.data; - expect(openRtbReq.id).not.to.be.undefined; - expect(openRtbReq.cur).to.deep.equal(['USD']); - expect(openRtbReq.tmax).to.equal(242); - - expect(Object.keys(openRtbReq.site)).to.have.length(3); - expect(openRtbReq.site.domain).not.to.be.undefined; - expect(openRtbReq.site.page).not.to.be.undefined; - expect(openRtbReq.site.ref).to.equal('https://referer.com'); - - const expectedEids = { - 'liveramp.com': { id: 'fake-identity-link' }, - 'id5-sync.com': { id: 'fake-id5id' }, - 'pubcid.org': { id: 'fake-pubcid' }, - 'adserver.org': { id: 'fake-tdid' }, - 'criteo.com': { id: 'fake-criteo' }, - 'britepool.com': { id: 'fake-britepool' }, - 'liveintent.com': { id: 'fake-lipbid' }, - 'intentiq.com': { id: 'fake-intentiq' }, - 'crwdcntrl.net': { id: 'fake-lotame' }, - 'parrable.com': { id: 'fake-parrable' }, - 'netid.de': { id: 'fake-netid' }, - 'chrome.com': { id: 'fake-flocid' }, - }; - expect(openRtbReq.user.ext.eids).to.be.an('array').that.have.length(Object.keys(expectedEids).length); - for (const eid of openRtbReq.user.ext.eids) { - expect(Object.keys(expectedEids)).to.include(eid.source); - expect(eid.uids[0].id).to.equal(expectedEids[eid.source].id); - expect(eid.uids[0].atype).to.be.ok; - } - - expect(openRtbReq.device.ua).to.equal(navigator.userAgent); - expect(openRtbReq.regs.coppa).to.equal(1); - - expect(openRtbReq.source.ext.version).not.to.be.undefined; - expect(openRtbReq.source.ext.str).not.to.be.undefined; - expect(openRtbReq.source.ext.schain).to.deep.equal(bidRequests[0].schain); - - expect(openRtbReq.bcat).to.deep.equal(bidRequests[0].params.bcat); - expect(openRtbReq.badv).to.deep.equal(bidRequests[0].params.badv); - - expect(openRtbReq.imp).to.have.length(1); - - expect(openRtbReq.imp[0].id).to.equal(expectedImpValues[rIndex].id); - expect(openRtbReq.imp[0].tagid).to.equal(expectedImpValues[rIndex].tagid); - expect(openRtbReq.imp[0].secure).to.equal(expectedImpValues[rIndex].secure); - expect(openRtbReq.imp[0].bidfloor).to.equal(expectedImpValues[rIndex].bidfloor); - }); - }); + it('should set the instant_play_capable parameter correctly based on browser userAgent string', function() { + setUserAgent('Android Chrome/60'); + let builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.true; - it('should have empty eid array if no id is provided', () => { - const openRtbReq = spec.buildRequests([bidRequests[1]], bidderRequest)[0].data; + setUserAgent('iPhone Version/11'); + builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.true; - expect(openRtbReq.user.ext.eids).to.deep.equal([]); - }); - }); + setUserAgent('iPhone CriOS/60'); + builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.true; - describe('no referer provided', () => { - beforeEach(() => { - bidderRequest = {}; - }); + setUserAgent('Android Chrome/50'); + builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.false; - it('should set referer to undefined', () => { - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - expect(openRtbReq.site.ref).to.be.undefined; - }); - }); - - describe('regulation', () => { - describe('gdpr', () => { - it('should populate request accordingly when gdpr applies', () => { - bidderRequest.gdprConsent = { - gdprApplies: true, - consentString: 'consent', - }; + setUserAgent('Android Chrome'); + builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.false; - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + setUserAgent(undefined); + builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0].data.instant_play_capable).to.be.false; + }); - expect(openRtbReq.regs.ext.gdpr).to.equal(1); - expect(openRtbReq.user.ext.consent).to.equal('consent'); - }); + it('should set the secure parameter to false when the protocol is http', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('http:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.false; + stub.restore(); + }); - it('should populate request accordingly when gdpr explicitly does not apply', () => { - bidderRequest.gdprConsent = { - gdprApplies: false, - }; + it('should set the secure parameter to true when the protocol is https', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('https:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.true; + stub.restore(); + }); - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + it('should set the secure parameter to true when the protocol is neither http or https', function() { + const stub = sinon.stub(sharethroughInternal, 'getProtocol').returns('about:'); + const bidRequest = spec.buildRequests(bidRequests, null)[0]; + expect(bidRequest.data.secure).to.be.true; + stub.restore(); + }); - expect(openRtbReq.regs.ext.gdpr).to.equal(0); - expect(openRtbReq.user.ext.consent).to.be.undefined; - }); - }); + it('should add ccpa parameter if uspConsent is present', function() { + const uspConsent = '1YNN'; + const bidderRequest = { uspConsent: uspConsent }; + const bidRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(bidRequest.data.us_privacy).to.eq(uspConsent); + }); - describe('US privacy', () => { - it('should populate request accordingly when us privacy applies', () => { - bidderRequest.uspConsent = 'consent'; + it('should add consent parameters if gdprConsent is present', function() { + const gdprConsent = { consentString: 'consent_string123', gdprApplies: true }; + const bidderRequest = { gdprConsent: gdprConsent }; + const bidRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(bidRequest.data.consent_required).to.eq(true); + expect(bidRequest.data.consent_string).to.eq('consent_string123'); + }); - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + it('should handle gdprConsent is present but values are undefined case', function() { + const gdprConsent = { consent_string: undefined, gdprApplies: undefined }; + const bidderRequest = { gdprConsent: gdprConsent }; + const bidRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(bidRequest.data).to.not.include.any.keys('consent_string'); + }); - expect(openRtbReq.regs.ext.us_privacy).to.equal('consent'); - }); - }); + it('should add the ttduid parameter if a bid request contains a value for Unified ID from The Trade Desk', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.ttduid).to.eq('fake-tdid'); + }); - describe('coppa', () => { - it('should populate request accordingly when coppa does not apply', () => { - config.setConfig({ coppa: false }); + it('should add the pubcid parameter if a bid request contains a value for the Publisher Common ID Module in the' + + ' userId object of the bidrequest', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.pubcid).to.eq('fake-pubcid'); + }); - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + it('should add the pubcid parameter if a bid request contains a value for the Publisher Common ID Module in the' + + ' crumbs object of the bidrequest', function() { + const bidData = utils.deepClone(bidRequests); + delete bidData[0].userId.pubcid; - expect(openRtbReq.regs.coppa).to.equal(0); - }); - }); - }); + const bidRequest = spec.buildRequests(bidData)[0]; + expect(bidRequest.data.pubcid).to.eq('fake-pubcid-in-crumbs-obj'); + }); - describe('universal id', () => { - it('should include gpid when universal id is provided', () => { - const requests = spec.buildRequests(bidRequests, bidderRequest); + it('should add the pubcid parameter if a bid request contains a value for the Publisher Common ID Module in the' + + ' crumbs object of the bidrequest', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + delete bidRequest.userId; + expect(bidRequest.data.pubcid).to.eq('fake-pubcid'); + }); - expect(requests[0].data.imp[0].ext.gpid).to.equal('universal-id'); - expect(requests[1].data.imp[0].ext).to.be.undefined; - }); - }); + it('should add the idluid parameter if a bid request contains a value for Identity Link from Live Ramp', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.idluid).to.eq('fake-identity-link'); + }); - describe('secure flag', () => { - it('should be positive when protocol is https', () => { - protocolStub.returns('https'); - const requests = spec.buildRequests(bidRequests, bidderRequest); + it('should add the id5uid parameter if a bid request contains a value for ID5', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.id5uid.id).to.eq('fake-id5id'); + expect(bidRequest.data.id5uid.linkType).to.eq(2); + }); - expect(requests[0].data.imp[0].secure).to.equal(1); - expect(requests[1].data.imp[0].secure).to.equal(1); - }); + it('should add the liuid parameter if a bid request contains a value for LiveIntent ID', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.liuid).to.eq('fake-lipbid'); + }); - it('should be negative when protocol is http', () => { - protocolStub.returns('http'); - const requests = spec.buildRequests(bidRequests, bidderRequest); + it('should add Sharethrough specific parameters', function() { + const builtBidRequests = spec.buildRequests(bidRequests); + expect(builtBidRequests[0]).to.deep.include({ + strData: { + skipIframeBusting: undefined, + iframeSize: undefined, + sizes: [[600, 300]] + } + }); + }); - expect(requests[0].data.imp[0].secure).to.equal(0); - expect(requests[1].data.imp[0].secure).to.equal(0); - }); + it('should add a supply chain parameter if schain is present', function() { + // shallow copy of the first bidRequest obj, so we don't mutate + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest['schain'] = { + ver: '1.0', + complete: 1, + nodes: [ + { + asi: 'directseller.com', + sid: '00001', + rid: 'BidRequest1', + hp: 1 + } + ] + }; - it('should be positive when protocol is neither http nor https', () => { - protocolStub.returns('about'); - const requests = spec.buildRequests(bidRequests, bidderRequest); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data.schain).to.eq(JSON.stringify(bidRequest.schain)); + }); - expect(requests[0].data.imp[0].secure).to.equal(1); - expect(requests[1].data.imp[0].secure).to.equal(1); - }); + describe('gpid', () => { + it('should include the gpid param if pbadslot is found in ortb2Imp in the bid request', () => { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data.gpid).to.eq('adslot-id-1') }); - describe('banner imp', () => { - it('should generate open rtb banner imp', () => { - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; + it('should not include the gpid param if pbadslot is not found in ortb2Imp in the bid request', () => { + const bidRequest = spec.buildRequests(bidRequests)[1]; + expect(bidRequest.data).to.not.include.any.keys('gpid'); + }); + }); - const bannerImp = builtRequest.data.imp[0].banner; - expect(bannerImp.pos).to.equal(1); - expect(bannerImp.topframe).to.equal(1); - expect(bannerImp.format).to.deep.equal([{ w: 300, h: 250 }, { w: 300, h: 600 }]); - }); + it('should add badv if provided', () => { + const builtBidRequest = spec.buildRequests([bidRequests[3]])[0]; - it('should default to pos 0 if not provided', () => { - delete bidRequests[0].mediaTypes; - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(builtBidRequest.data.badv).to.have.members(['domain1.com', 'domain2.com']) + }); - const bannerImp = builtRequest.data.imp[0].banner; - expect(bannerImp.pos).to.equal(0); - }); - }); + it('should add bcat if provided', () => { + const builtBidRequest = spec.buildRequests([bidRequests[4]])[0]; - describe('video imp', () => { - it('should generate open rtb video imp', () => { - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - - const videoImp = builtRequest.data.imp[0].video; - expect(videoImp.pos).to.equal(3); - expect(videoImp.topframe).to.equal(1); - expect(videoImp.skip).to.equal(1); - expect(videoImp.linearity).to.equal(0); - expect(videoImp.minduration).to.equal(10); - expect(videoImp.maxduration).to.equal(30); - expect(videoImp.playbackmethod).to.deep.equal([1]); - expect(videoImp.api).to.deep.equal([3]); - expect(videoImp.mimes).to.deep.equal(['video/3gpp']); - expect(videoImp.protocols).to.deep.equal([2, 3]); - expect(videoImp.w).to.equal(640); - expect(videoImp.h).to.equal(480); - expect(videoImp.startdelay).to.equal(42); - expect(videoImp.skipmin).to.equal(10); - expect(videoImp.skipafter).to.equal(20); - expect(videoImp.placement).to.equal(1); - expect(videoImp.delivery).to.equal(1); - expect(videoImp.companiontype).to.equal('companion type'); - expect(videoImp.companionad).to.equal('companion ad'); - }); + expect(builtBidRequest.data.bcat).to.have.members(['IAB1-1', 'IAB1-2']) + }); - it('should set defaults if no value provided', () => { - delete bidRequests[1].mediaTypes.video.pos; - delete bidRequests[1].mediaTypes.video.skip; - delete bidRequests[1].mediaTypes.video.linearity; - delete bidRequests[1].mediaTypes.video.minduration; - delete bidRequests[1].mediaTypes.video.maxduration; - delete bidRequests[1].mediaTypes.video.playbackmethod; - delete bidRequests[1].mediaTypes.video.api; - delete bidRequests[1].mediaTypes.video.mimes; - delete bidRequests[1].mediaTypes.video.protocols; - delete bidRequests[1].mediaTypes.video.playerSize; - delete bidRequests[1].mediaTypes.video.startdelay; - delete bidRequests[1].mediaTypes.video.skipmin; - delete bidRequests[1].mediaTypes.video.skipafter; - delete bidRequests[1].mediaTypes.video.placement; - delete bidRequests[1].mediaTypes.video.delivery; - delete bidRequests[1].mediaTypes.video.companiontype; - delete bidRequests[1].mediaTypes.video.companionad; - - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - - const videoImp = builtRequest.data.imp[0].video; - expect(videoImp.pos).to.equal(0); - expect(videoImp.skip).to.equal(0); - expect(videoImp.linearity).to.equal(1); - expect(videoImp.minduration).to.equal(5); - expect(videoImp.maxduration).to.equal(60); - expect(videoImp.playbackmethod).to.deep.equal([2]); - expect(videoImp.api).to.deep.equal([2]); - expect(videoImp.mimes).to.deep.equal(['video/mp4']); - expect(videoImp.protocols).to.deep.equal([2, 3, 5, 6, 7, 8]); - expect(videoImp.w).to.equal(640); - expect(videoImp.h).to.equal(360); - expect(videoImp.startdelay).to.equal(0); - expect(videoImp.skipmin).to.equal(0); - expect(videoImp.skipafter).to.equal(0); - expect(videoImp.placement).to.equal(1); - expect(videoImp.delivery).to.be.undefined; - expect(videoImp.companiontype).to.be.undefined; - expect(videoImp.companionad).to.be.undefined; - }); + it('should not add a supply chain parameter if schain is missing', function() { + const bidRequest = spec.buildRequests(bidRequests)[0]; + expect(bidRequest.data).to.not.include.any.keys('schain'); + }); - describe('outstream', () => { - it('should use placement value if provided', () => { - bidRequests[1].mediaTypes.video.context = 'outstream'; - bidRequests[1].mediaTypes.video.placement = 3; + it('should include the bidfloor parameter if it is present in the bid request', function() { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest['getFloor'] = () => ({ currency: 'USD', floor: 0.5 }); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data.bidfloor).to.eq(0.5); + }); - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - const videoImp = builtRequest.data.imp[0].video; + it('should not include the bidfloor parameter if it is missing in the bid request', function() { + const bidRequest = Object.assign({}, bidRequests[0]); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data).to.not.include.any.keys('bidfloor'); + }); - expect(videoImp.placement).to.equal(3); - }); + describe('coppa', function() { + it('should add coppa to request if enabled', function() { + config.setConfig({coppa: true}); + const bidRequest = Object.assign({}, bidRequests[0]); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data.coppa).to.eq(true); + }); - it('should default placement to 4 if not provided', () => { - bidRequests[1].mediaTypes.video.context = 'outstream'; + it('should not add coppa to request if disabled', function() { + config.setConfig({coppa: false}); + const bidRequest = Object.assign({}, bidRequests[0]); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data.coppa).to.be.undefined; + }); - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - const videoImp = builtRequest.data.imp[0].video; + it('should not add coppa to request if unknown value', function() { + config.setConfig({coppa: 'something'}); + const bidRequest = Object.assign({}, bidRequests[0]); + const builtBidRequest = spec.buildRequests([bidRequest])[0]; + expect(builtBidRequest.data.coppa).to.be.undefined; + }); + }); + }); - expect(videoImp.placement).to.equal(4); - }); + describe('.interpretResponse', function() { + it('returns a correctly parsed out response', function() { + expect(spec.interpretResponse(bidderResponse, prebidRequests[0])[0]).to.deep.include( + { + width: 1, + height: 1, + cpm: 12.34, + creativeId: 'aCreativeId', + dealId: 'aDealId', + currency: 'USD', + netRevenue: true, + ttl: 360, + meta: { advertiserDomains: [] } }); - }); + }); - describe('first party data', () => { - const firstPartyData = { - site: { - name: 'example', - keywords: 'power tools, drills', - search: 'drill', - content: { - userrating: '4', - }, - ext: { - data: { - pageType: 'article', - category: 'repair', - }, - }, - }, - user: { - yob: 1985, - gender: 'm', - ext: { - data: { - registered: true, - interests: ['cars'], - }, - }, - }, - }; - - let configStub; - - beforeEach(() => { - configStub = sinon.stub(config, 'getConfig'); - configStub.withArgs('ortb2').returns(firstPartyData); + it('returns a correctly parsed out response with largest size when strData.skipIframeBusting is true', function() { + expect(spec.interpretResponse(bidderResponse, prebidRequests[1])[0]).to.include( + { + width: 300, + height: 300, + cpm: 12.34, + creativeId: 'aCreativeId', + dealId: 'aDealId', + currency: 'USD', + netRevenue: true, + ttl: 360 }); + }); - afterEach(() => { - configStub.restore(); + it('returns a correctly parsed out response with explicitly defined size when strData.skipIframeBusting is true and strData.iframeSize is provided', function() { + expect(spec.interpretResponse(bidderResponse, prebidRequests[2])[0]).to.include( + { + width: 500, + height: 500, + cpm: 12.34, + creativeId: 'aCreativeId', + dealId: 'aDealId', + currency: 'USD', + netRevenue: true, + ttl: 360 }); + }); - it('should include first party data in open rtb request, site section', () => { - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + it('returns a correctly parsed out response with explicitly defined size when strData.skipIframeBusting is false and strData.sizes contains [0, 0] only', function() { + expect(spec.interpretResponse(bidderResponse, prebidRequests[3])[0]).to.include( + { + width: 0, + height: 0, + cpm: 12.34, + creativeId: 'aCreativeId', + dealId: 'aDealId', + currency: 'USD', + netRevenue: true, + ttl: 360 + }); + }); - expect(openRtbReq.site.name).to.equal(firstPartyData.site.name); - expect(openRtbReq.site.keywords).to.equal(firstPartyData.site.keywords); - expect(openRtbReq.site.search).to.equal(firstPartyData.site.search); - expect(openRtbReq.site.content).to.deep.equal(firstPartyData.site.content); - expect(openRtbReq.site.ext).to.deep.equal(firstPartyData.site.ext); + it('returns a correctly parsed out response with explicitly defined size when strData.skipIframeBusting is false and strData.sizes contains multiple sizes', function() { + expect(spec.interpretResponse(bidderResponse, prebidRequests[4])[0]).to.include( + { + width: 300, + height: 300, + cpm: 12.34, + creativeId: 'aCreativeId', + dealId: 'aDealId', + currency: 'USD', + netRevenue: true, + ttl: 360 }); + }); - it('should include first party data in open rtb request, user section', () => { - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; + it('returns a blank array if there are no creatives', function() { + const bidResponse = { body: { creatives: [] } }; + expect(spec.interpretResponse(bidResponse, prebidRequests[0])).to.be.an('array').that.is.empty; + }); - expect(openRtbReq.user.yob).to.equal(firstPartyData.user.yob); - expect(openRtbReq.user.gender).to.equal(firstPartyData.user.gender); - expect(openRtbReq.user.ext.data).to.deep.equal(firstPartyData.user.ext.data); - expect(openRtbReq.user.ext.eids).not.to.be.undefined; - }); - }); + it('returns a blank array if body object is empty', function() { + const bidResponse = { body: {} }; + expect(spec.interpretResponse(bidResponse, prebidRequests[0])).to.be.an('array').that.is.empty; }); - describe('interpretResponse', function () { - let request; - let response; - - describe('banner', () => { - beforeEach(() => { - request = spec.buildRequests(bidRequests, bidderRequest)[0]; - response = { - body: { - seatbid: [{ - bid: [{ - id: '123', - impid: 'bidId1', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - }, { - id: '456', - impid: 'bidId2', - w: 640, - h: 480, - price: 42, - adm: 'vastTag', - }], - }], - }, - }; - }); + it('returns a blank array if body is null', function() { + const bidResponse = { body: null }; + expect(spec.interpretResponse(bidResponse, prebidRequests[0])).to.be.an('array').that.is.empty; + }); - it('should return a banner bid', () => { - const resp = spec.interpretResponse(response, request); - - const bannerBid = resp[0]; - expect(bannerBid.requestId).to.equal('bidId1'); - expect(bannerBid.width).to.equal(300); - expect(bannerBid.height).to.equal(250); - expect(bannerBid.cpm).to.equal(42); - expect(bannerBid.creativeId).to.equal('creative'); - expect(bannerBid.dealId).to.equal('deal'); - expect(bannerBid.mediaType).to.equal('banner'); - expect(bannerBid.currency).to.equal('USD'); - expect(bannerBid.netRevenue).to.equal(true); - expect(bannerBid.ttl).to.equal(360); - expect(bannerBid.ad).to.equal('markup'); - expect(bannerBid.meta.advertiserDomains).to.deep.equal(['domain.com']); - expect(bannerBid.vastXml).to.be.undefined; - }); - }); + it('correctly generates ad markup when skipIframeBusting is false', function() { + const adMarkup = spec.interpretResponse(bidderResponse, prebidRequests[0])[0].ad; + let resp = null; - describe('video', () => { - beforeEach(() => { - request = spec.buildRequests(bidRequests, bidderRequest)[1]; - response = { - body: { - seatbid: [{ - bid: [{ - id: '456', - impid: 'bidId2', - w: 640, - h: 480, - price: 42, - adm: 'vastTag', - }], - }], - }, - }; - }); + expect(() => btoa(JSON.stringify(bidderResponse))).to.throw(); + expect(() => resp = sharethroughInternal.b64EncodeUnicode(JSON.stringify(bidderResponse))).not.to.throw(); + expect(adMarkup).to.match( + /data-str-native-key="pKey" data-stx-response-name="str_response_bidId"/); + expect(!!adMarkup.indexOf(resp)).to.eql(true); - it('should return a video bid', () => { - const resp = spec.interpretResponse(response, request); - - const bannerBid = resp[0]; - expect(bannerBid.requestId).to.equal('bidId2'); - expect(bannerBid.width).to.equal(640); - expect(bannerBid.height).to.equal(480); - expect(bannerBid.cpm).to.equal(42); - expect(bannerBid.creativeId).to.be.undefined; - expect(bannerBid.dealId).to.be.null; - expect(bannerBid.mediaType).to.equal('video'); - expect(bannerBid.currency).to.equal('USD'); - expect(bannerBid.netRevenue).to.equal(true); - expect(bannerBid.ttl).to.equal(3600); - expect(bannerBid.ad).to.equal('vastTag'); - expect(bannerBid.meta.advertiserDomains).to.deep.equal([]); - expect(bannerBid.vastXml).to.equal('vastTag'); - }); - }); + // insert functionality to autodetect whether or not in safeframe, and handle JS insertion + expect(adMarkup).to.match(/isLockedInFrame/); + expect(adMarkup).to.match(/handleIframe/); }); - describe('getUserSyncs', function () { - const cookieSyncs = ['cookieUrl1', 'cookieUrl2', 'cookieUrl3']; - const serverResponses = [{ body: { cookieSyncUrls: cookieSyncs } }]; + it('correctly generates ad markup when skipIframeBusting is true', function() { + const adMarkup = spec.interpretResponse(bidderResponse, prebidRequests[1])[0].ad; + let resp = null; + + expect(() => btoa(JSON.stringify(bidderResponse))).to.throw(); + expect(() => resp = sharethroughInternal.b64EncodeUnicode(JSON.stringify(bidderResponse))).not.to.throw(); + expect(adMarkup).to.match( + /data-str-native-key="pKey" data-stx-response-name="str_response_bidId"/); + expect(!!adMarkup.indexOf(resp)).to.eql(true); + expect(adMarkup).to.match( + /"'; -describe('slimcutBidAdapter', function() { - const adapter = newBidder(spec); - describe('inherited functions', function() { - it('exists and is a function', function() { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - describe('isBidRequestValid', function() { - let bid = { - 'bidder': 'slimcut', - 'params': { - 'placementId': 83 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '3c871ffa8ef14c', - 'bidderRequestId': 'b41642f1aee381', - 'auctionId': '4e156668c977d7' - }; - it('should return true when required params found', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false when placementId is not valid (letters)', function() { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = { - 'placementId': 'ABCD' - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when placementId < 0', function() { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = { - 'placementId': -1 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when required params are not passed', function() { - let bid = Object.assign({}, bid); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - describe('buildRequests', function() { - let bidRequests = [{ - 'bidder': 'teads', - 'params': { - 'placementId': 10433394 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '3c871ffa8ef14c', - 'bidderRequestId': 'b41642f1aee381', - 'auctionId': '4e156668c977d7', - 'deviceWidth': 1680 - }]; - let bidderResquestDefault = { - 'auctionId': '4e156668c977d7', - 'bidderRequestId': 'b41642f1aee381', - 'timeout': 3000 - }; - it('sends bid request to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderResquestDefault); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - it('should send GDPR to endpoint', function() { - let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - let bidderRequest = { - 'auctionId': '4e156668c977d7', - 'bidderRequestId': 'b41642f1aee381', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'hasGlobalConsent': false - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - }); - it('should add referer info to payload', function() { - const bidRequest = Object.assign({}, bidRequests[0]) - const bidderRequest = { - refererInfo: { - referer: 'https://example.com/page.html', - reachedTop: true, - numIframes: 2 - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.referrer).to.exist; - expect(payload.referrer).to.deep.equal('https://example.com/page.html') - }); - }); - describe('getUserSyncs', () => { - let bids = { - 'body': { - 'responses': [{ - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 250, - 'netRevenue': true, - 'requestId': '3ede2a3fa0db94', - 'ttl': 360, - 'width': 300, - 'creativeId': 'er2ee', - 'transactionId': 'deadb33f', - 'winUrl': 'https://sb.freeskreen.com/win' - }] - } - }; - it('should get the correct number of sync urls', () => { - let urls = spec.getUserSyncs({ - iframeEnabled: true - }, bids); - expect(urls.length).to.equal(1); - expect(urls[0].url).to.equal('https://sb.freeskreen.com/async_usersync.html'); - }); - it('should return no url if not iframe enabled', () => { - let urls = spec.getUserSyncs({ - iframeEnabled: false - }, bids); - expect(urls.length).to.equal(0); - }); - }); - describe('interpretResponse', function() { - let bids = { - 'body': { - 'responses': [{ - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 250, - 'netRevenue': true, - 'requestId': '3ede2a3fa0db94', - 'ttl': 360, - 'width': 300, - 'creativeId': 'er2ee', - 'transactionId': 'deadb33f', - 'winUrl': 'https://sb.freeskreen.com/win' - }] - } - }; - it('should get correct bid response', function() { - let expectedResponse = [{ - 'cpm': 0.5, - 'width': 300, - 'height': 250, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 360, - 'ad': AD_SCRIPT, - 'requestId': '3ede2a3fa0db94', - 'creativeId': 'er2ee', - 'transactionId': 'deadb33f', - 'winUrl': 'https://sb.freeskreen.com/win', - 'meta': { - 'advertiserDomains': [] - } - }]; - let result = spec.interpretResponse(bids); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - }); - it('handles nobid responses', function() { - let bids = { - 'body': { - 'responses': [] - } - }; - let result = spec.interpretResponse(bids); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/smaatoBidAdapter_spec.js b/test/spec/modules/smaatoBidAdapter_spec.js index 9803d1df103..faa288306a5 100644 --- a/test/spec/modules/smaatoBidAdapter_spec.js +++ b/test/spec/modules/smaatoBidAdapter_spec.js @@ -287,23 +287,6 @@ describe('smaatoBidAdapterTest', () => { expect(req.regs.ext.us_privacy).to.equal('uspConsentString'); }); - it('sends no schain if no schain exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.source.ext.schain).to.not.exist; - }); - - it('sends instl if instl exists', () => { - const instl = { instl: 1 }; - const bidRequestWithInstl = Object.assign({}, singleBannerBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - }); - it('sends tmax', () => { const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); @@ -452,16 +435,6 @@ describe('smaatoBidAdapterTest', () => { expect(req.imp[0].bidfloor).to.be.equal(0.456); }); - it('sends instl if instl exists', () => { - const instl = { instl: 1 }; - const bidRequestWithInstl = Object.assign({}, singleVideoBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - }); - it('splits multi format bid requests', () => { const combinedBannerAndVideoBidRequest = { bidder: 'smaato', @@ -543,17 +516,6 @@ describe('smaatoBidAdapterTest', () => { expect(req.imp[1].video.sequence).to.be.equal(2); }); - it('sends instl if instl exists', () => { - const instl = { instl: 1 }; - const bidRequestWithInstl = Object.assign({}, longFormVideoBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - expect(req.imp[1].instl).to.equal(1); - }); - it('sends bidfloor when configured', () => { const longFormVideoBidRequestWithFloor = Object.assign({}, longFormVideoBidRequest); longFormVideoBidRequestWithFloor.getFloor = function(arg) { @@ -892,29 +854,6 @@ describe('smaatoBidAdapterTest', () => { expect(req.user.ext.eids).to.have.length(2); }); }); - - describe('schain in request', () => { - it('schain is added to source.ext.schain', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'asi', - 'sid': 'sid', - 'rid': 'rid', - 'hp': 1 - } - ] - }; - const bidRequestWithSchain = Object.assign({}, singleBannerBidRequest, {schain: schain}); - - const reqs = spec.buildRequests([bidRequestWithSchain], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.source.ext.schain).to.deep.equal(schain); - }); - }); }); describe('interpretResponse', () => { diff --git a/test/spec/modules/smartxBidAdapter_spec.js b/test/spec/modules/smartxBidAdapter_spec.js index ddee2fa3347..89c03034ba4 100644 --- a/test/spec/modules/smartxBidAdapter_spec.js +++ b/test/spec/modules/smartxBidAdapter_spec.js @@ -189,14 +189,6 @@ describe('The smartx adapter', function () { domain: '', publisher: { id: '__name__' - }, - content: { - ext: { - prebid: { - name: 'pbjs', - version: '$prebid.version$' - } - } } }); }); @@ -503,7 +495,7 @@ describe('The smartx adapter', function () { }; }); - it('should attempt to insert the script without outstream config options set', function () { + it('should attempt to insert the script', function () { var scriptTag; sinon.stub(window.document, 'getElementById').returns({ appendChild: sinon.stub().callsFake(function (script) { @@ -514,52 +506,8 @@ describe('The smartx adapter', function () { responses[0].renderer.render(responses[0]); - expect(responses[0].renderer.url).to.equal('https://dco.smartclip.net/?plc=7777778'); - - window.document.getElementById.restore(); - }); - - it('should attempt to insert the script with outstream config options set', function () { - var scriptTag; - sinon.stub(window.document, 'getElementById').returns({ - appendChild: sinon.stub().callsFake(function (script) { - scriptTag = script - }) - }); - var responses = spec.interpretResponse(serverResponse, bidderRequestObj); - - bidderRequestObj.bidRequest.bids[0].params.outstream_options.startOpen = 'true'; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.endingScreen = 'true'; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.title = 'abc'; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.skipOffset = 2; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.desiredBitrate = 123; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.visibilityThreshold = 30; - - responses[0].renderer.render(responses[0]); - - bidderRequestObj.bidRequest.bids[0].params.outstream_options.startOpen = 'false'; - bidderRequestObj.bidRequest.bids[0].params.outstream_options.endingScreen = 'false'; - - responses[0].renderer.render(responses[0]); - - expect(responses[0].renderer.url).to.equal('https://dco.smartclip.net/?plc=7777778'); - - window.document.getElementById.restore(); - }); - - it('should attempt to insert the script without defined slot', function () { - var scriptTag; - sinon.stub(window.document, 'getElementById').returns({ - appendChild: sinon.stub().callsFake(function (script) { - scriptTag = script - }) - }); - var responses = spec.interpretResponse(serverResponse, bidderRequestObj); - - delete bidderRequestObj.bidRequest.bids[0].params.outstream_options.slot; - - responses[0].renderer.render(responses[0]); - + // expect(scriptTag.getAttribute('type')).to.equal('text/javascript'); + // expect(scriptTag.getAttribute('src')).to.equal('https://dco.smartclip.net/?plc=7777778'); expect(responses[0].renderer.url).to.equal('https://dco.smartclip.net/?plc=7777778'); window.document.getElementById.restore(); @@ -592,7 +540,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 3.21); }); - it('obtain floor from params', function () { + it('obtain floor from params', function() { bid.getFloor = () => { return { currency: 'EUR', @@ -605,7 +553,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 0.64); }); - it('check currency USD', function () { + it('check currency USD', function() { bid.getFloor = () => { return { currency: 'USD', @@ -619,7 +567,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 1.23); }); - it('check defaut currency EUR', function () { + it('check defaut currency EUR', function() { delete bid.params.bidfloorcur; bid.getFloor = () => { @@ -634,7 +582,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 4.56); }); - it('bad floor value', function () { + it('bad floor value', function() { bid.getFloor = () => { return { currency: 'EUR', @@ -646,7 +594,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 0); }); - it('empty floor object', function () { + it('empty floor object', function() { bid.getFloor = () => { return {}; }; @@ -655,7 +603,7 @@ describe('The smartx adapter', function () { expect(payload.data.imp[0]).to.have.property('bidfloor', 0); }); - it('undefined floor result', function () { + it('undefined floor result', function() { bid.getFloor = () => {}; const payload = spec.buildRequests([bid], bidRequestObj)[0]; diff --git a/test/spec/modules/smartyadsBidAdapter_spec.js b/test/spec/modules/smartyadsBidAdapter_spec.js index 3474753c838..14363329a9e 100644 --- a/test/spec/modules/smartyadsBidAdapter_spec.js +++ b/test/spec/modules/smartyadsBidAdapter_spec.js @@ -7,19 +7,17 @@ describe('SmartyadsAdapter', function () { bidId: '23fhj33i987f', bidder: 'smartyads', params: { - host: 'prebid', - sourceid: '0', - accountid: '0', + placementId: 0, traffic: 'banner' } }; describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and sourceid parameters present', function () { + it('Should return true if there are bidId, params and placementId parameters present', function () { expect(spec.isBidRequestValid(bid)).to.be.true; }); it('Should return false if at least one of parameters is not present', function () { - delete bid.params.sourceid; + delete bid.params.placementId; expect(spec.isBidRequestValid(bid)).to.be.false; }); }); @@ -36,7 +34,7 @@ describe('SmartyadsAdapter', function () { expect(serverRequest.method).to.equal('POST'); }); it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'); + expect(serverRequest.url).to.equal('https://ssp-nj.webtradehub.com/?c=o&m=multi'); }); it('Returns valid data if array of bids is valid', function () { let data = serverRequest.data; @@ -50,8 +48,8 @@ describe('SmartyadsAdapter', function () { expect(data.host).to.be.a('string'); expect(data.page).to.be.a('string'); let placement = data['placements'][0]; - expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'sizes', 'publisherId'); - expect(placement.placementId).to.equal('0'); + expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'sizes'); + expect(placement.placementId).to.equal(0); expect(placement.bidId).to.equal('23fhj33i987f'); expect(placement.traffic).to.equal('banner'); }); @@ -243,18 +241,13 @@ describe('SmartyadsAdapter', function () { }); }); describe('getUserSyncs', function () { - const syncUrl = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a&gdpr=0&gdpr_consent=&type=iframe&us_privacy='; - const syncOptions = { - iframeEnabled: true - }; - let userSync = spec.getUserSyncs(syncOptions); + let userSync = spec.getUserSyncs(); it('Returns valid URL and type', function () { expect(userSync).to.be.an('array').with.lengthOf(1); expect(userSync[0].type).to.exist; expect(userSync[0].url).to.exist; - expect(userSync).to.deep.equal([ - { type: 'iframe', url: syncUrl } - ]); + expect(userSync[0].type).to.be.equal('image'); + expect(userSync[0].url).to.be.equal('https://ssp-nj.webtradehub.com/?c=o&m=cookie'); }); }); }); diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js index f56f4e0c12b..8eee973794a 100644 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ b/test/spec/modules/sonobiBidAdapter_spec.js @@ -238,17 +238,14 @@ describe('SonobiBidAdapter', function () { }); describe('.buildRequests', function () { - let sandbox; beforeEach(function() { sinon.stub(userSync, 'canBidderRegisterSync'); sinon.stub(utils, 'getGptSlotInfoForAdUnitCode') - .onFirstCall().returns({gptSlot: '/123123/gpt_publisher/adunit-code-3', divId: 'adunit-code-3-div-id'}); - sandbox = sinon.createSandbox(); + .onFirstCall().returns({gptSlot: '/123123/gpt_publisher/adunit-code-3', divId: 'adunit-code-3-div-id'}) }); afterEach(function() { userSync.canBidderRegisterSync.restore(); utils.getGptSlotInfoForAdUnitCode.restore(); - sandbox.restore(); }); let bidRequest = [{ 'schain': { @@ -336,36 +333,6 @@ describe('SonobiBidAdapter', function () { uspConsent: 'someCCPAString' }; - it('should set fpd if there is any data in ortb2', function() { - const ortb2 = { - site: { - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }, - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - }; - - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - ortb2: ortb2 - }; - return utils.deepAccess(config, key); - }); - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.fpd).to.equal(JSON.stringify(ortb2)); - }); - it('should populate coppa as 1 if set in config', function () { config.setConfig({coppa: true}); const bidRequests = spec.buildRequests(bidRequest, bidderRequests); @@ -785,7 +752,6 @@ describe('SonobiBidAdapter', function () { expect(resp.width).to.equal(prebidResponse[i].width); expect(resp.height).to.equal(prebidResponse[i].height); expect(resp.renderer).to.be.ok; - expect(resp.ad).to.equal(undefined); } else if (resp.mediaType === 'video') { expect(resp.vastUrl.indexOf('vast.xml')).to.be.greaterThan(0); expect(resp.ad).to.be.undefined; diff --git a/test/spec/modules/sortableBidAdapter_spec.js b/test/spec/modules/sortableBidAdapter_spec.js index 7357fa77952..17f77e96d51 100644 --- a/test/spec/modules/sortableBidAdapter_spec.js +++ b/test/spec/modules/sortableBidAdapter_spec.js @@ -112,13 +112,6 @@ describe('sortableBidAdapter', function() { 'key2': 'val2' } }, - 'ortb2Imp': { - 'ext': { - 'data': { - 'pbadslot': 'abc/123' - } - } - }, 'sizes': [ [300, 250] ], @@ -183,10 +176,6 @@ describe('sortableBidAdapter', function() { expect(requestBody.imp[0].floor).to.equal(0.21); }); - it('includes pbadslot in the bid request', function () { - expect(requestBody.imp[0].ext.gpid).to.equal('abc/123'); - }); - it('sets domain and href correctly', function () { expect(requestBody.site.domain).to.equal('example.com'); expect(requestBody.site.page).to.equal('http://example.com/page?param=val'); diff --git a/test/spec/modules/spotxBidAdapter_spec.js b/test/spec/modules/spotxBidAdapter_spec.js index d536976092b..2db8a1c9d2c 100644 --- a/test/spec/modules/spotxBidAdapter_spec.js +++ b/test/spec/modules/spotxBidAdapter_spec.js @@ -403,42 +403,6 @@ describe('the spotx adapter', function () { expect(request.data.ext.wrap_response).to.equal(0); config.getConfig.restore(); }); - - it('should pass price floor in USD from the floors module if available', function () { - var request; - - bid.getFloor = function () { - return { currency: 'USD', floor: 3 }; - } - - bid.params.price_floor = 2; - - request = spec.buildRequests([bid], bidRequestObj)[0]; - - expect(request.data.imp.bidfloor).to.equal(3); - }); - - it('should not pass price floor if price floors module gives a non-USD currency', function () { - var request; - - bid.getFloor = function () { - return { currency: 'EUR', floor: 3 }; - } - - request = spec.buildRequests([bid], bidRequestObj)[0]; - - expect(request.data.imp.bidfloor).to.be.undefined; - }); - - it('if floors module is not available, should pass price floor from price_floor param if available', function () { - var request; - - bid.params.price_floor = 2; - - request = spec.buildRequests([bid], bidRequestObj)[0]; - - expect(request.data.imp.bidfloor).to.equal(2); - }); }); describe('interpretResponse', function() { diff --git a/test/spec/modules/sspBCBidAdapter_spec.js b/test/spec/modules/sspBCBidAdapter_spec.js index d9f3ca84a3a..ae27cf8deea 100644 --- a/test/spec/modules/sspBCBidAdapter_spec.js +++ b/test/spec/modules/sspBCBidAdapter_spec.js @@ -40,6 +40,13 @@ describe('SSPBC adapter', function () { bidderRequestId, bidId: auctionId + '1', transactionId, + ortb2Imp: { + ext: { + data: { + pbadslot: 'test_wideboard' + } + } + } }, { adUnitCode: 'test_rectangle', @@ -62,85 +69,46 @@ describe('SSPBC adapter', function () { bidderRequestId, bidId: auctionId + '2', transactionId, - } - ]; - const bid_OneCode = { - adUnitCode: 'test_wideboard', + }, + { + adUnitCode: 'test_rectangle_2', bidder: BIDDER_CODE, mediaTypes: { banner: { sizes: [ - [728, 90], - [750, 100], - [750, 200] + [300, 250] ] } }, sizes: [ - [728, 90], - [750, 100], - [750, 200] + [300, 250] ], - auctionId, - bidderRequestId, - bidId: auctionId + '1', - transactionId, - }; - const bid_native = { - adUnitCode: 'test_native', - bidder: BIDDER_CODE, - mediaTypes: { - native: { - image: { - required: true, - sizes: [150, 50], - }, - title: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true, - }, - clickUrl: { - required: true, - }, - privacyLink: { - required: false, - }, - body: { - required: true, - }, - icon: { - required: true, - sizes: [50, 50] - } - } + params: { + id: '011', + siteId: '8816', }, - sizes: [ - [1, 1], - ], auctionId, bidderRequestId, - bidId: auctionId + '1', + bidId: auctionId + '3', transactionId, - }; - const bid_video = { - adUnitCode: 'test_video', + } + ]; + const bid_OneCode = { + adUnitCode: 'test_wideboard', bidder: BIDDER_CODE, mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - mimes: ['video/mp4', 'video/x-ms-wmv', 'video/webm', 'video/3gpp', 'application/javascript'], - protocols: [2, 3, 5, 6], - api: [2], - maxduration: 30, - linearity: 1 + banner: { + sizes: [ + [728, 90], + [750, 100], + [750, 200] + ] } }, sizes: [ - [640, 480], + [728, 90], + [750, 100], + [750, 200] ], auctionId, bidderRequestId, @@ -225,30 +193,6 @@ describe('SSPBC adapter', function () { stack: ['https://test.site.pl/'], } }; - const bidRequestNative = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bid_native], - gdprConsent, - refererInfo: { - reachedTop: true, - referer: 'https://test.site.pl/', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestVideo = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bid_video], - gdprConsent, - refererInfo: { - reachedTop: true, - referer: 'https://test.site.pl/', - stack: ['https://test.site.pl/'], - } - }; const bidRequestOneCode = { auctionId, bidderCode: BIDDER_CODE, @@ -320,6 +264,21 @@ describe('SSPBC adapter', function () { }], 'seat': 'dsp2', 'group': 0 + }, { + 'bid': [{ + 'id': '2d766853-ea07-4529-8299-5f0ebaddfaza', + 'impid': '011', + 'siteid': '8816', + 'slotid': '011', + 'price': 2, + 'adm': 'AD CODE 3', + 'cid': '57745', + 'crid': '858253', + 'w': 300, + 'h': 250 + }], + 'seat': 'dsp3', + 'group': 0 }], 'cur': 'PLN' } @@ -376,58 +335,6 @@ describe('SSPBC adapter', function () { 'cur': 'PLN' } }; - const serverResponseVideo = { - 'body': { - 'id': auctionId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': 'bidid-' + auctionId + '1', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'adnxs', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 640, - 'h': 480, - 'ext': { - 'siteid': '8816', - 'slotid': '150', - }, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const serverResponseNative = { - 'body': { - 'id': auctionId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': 'bidid-' + auctionId + '1', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': '{\"native\":{\"assets\":[{\"id\":3,\"img\":{\"url\":\"native_image\",\"w\":300,\"h\":150}},{\"id\":2,\"img\":{\"url\":\"native_icon\",\"w\":50,\"h\":50}},{\"id\":0,\"title\":{\"text\":\"native_title\"}},{\"id\":5,\"data\":{\"value\":\"native adomain\"}},{\"id\":4,\"data\":{\"value\":\"native_text\"}}],\"link\":{\"url\":\"native_url\"},\"imptrackers\":[\"native_tracker\"]}}', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'ext': { - 'siteid': '8816', - 'slotid': '80', - }, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; const emptyResponse = { 'body': { 'id': auctionId, @@ -438,20 +345,14 @@ describe('SSPBC adapter', function () { bids, bids_test, bids_timeouted, - bid_native, - bid_video, bidRequest, bidRequestOneCode, bidRequestSingle, - bidRequestNative, - bidRequestVideo, bidRequestTest, bidRequestTestNoGDPR, serverResponse, serverResponseOneCode, serverResponseSingle, - serverResponseVideo, - serverResponseNative, emptyResponse }; }; @@ -476,15 +377,14 @@ describe('SSPBC adapter', function () { }); describe('buildRequests', function () { - const { bids, bid_native, bid_video, bidRequest, bidRequestSingle, bidRequestNative, bidRequestVideo } = prepareTestData(); + const { bids, bidRequest, bidRequestSingle } = prepareTestData(); const request = spec.buildRequests(bids, bidRequest); const requestSingle = spec.buildRequests([bids[0]], bidRequestSingle); - const requestNative = spec.buildRequests([bid_native], bidRequestNative); - const requestVideo = spec.buildRequests([bid_video], bidRequestVideo); const payload = request ? JSON.parse(request.data) : { site: false, imp: false }; - const payloadSingle = requestSingle ? JSON.parse(requestSingle.data) : { site: false, imp: false }; - const payloadNative = requestNative ? JSON.parse(requestNative.data) : { site: false, imp: false }; - const payloadVideo = requestVideo ? JSON.parse(requestVideo.data) : { site: false, imp: false }; + const payloadSingle = request ? JSON.parse(requestSingle.data) : { site: false, imp: false }; + const payloadExt0 = payload.imp ? payload.imp[0].ext : {}; + const payloadExt1 = payload.imp ? payload.imp[1].ext : {}; + const payloadExt2 = payload.imp ? payload.imp[2].ext : {}; it('should send bid request to endpoint via POST', function () { expect(request.url).to.contain(BIDDER_URL); @@ -501,6 +401,17 @@ describe('SSPBC adapter', function () { expect(payloadSingle.imp.length).to.equal(1); }); + it('should add first party data (pbslot)', function () { + expect(payloadExt0.data).to.be.an('object').and.to.have.property('pbadslot'); + }); + + it('should add maximum size of adunit, and how many times this size has been requested (pbsize)', function () { + expect(payloadExt0.data).to.be.an('object').and.to.have.property('pbsize'); + expect(payloadExt0.data.pbsize).to.equal('750x200_1'); + expect(payloadExt1.data.pbsize).to.equal('300x250_1'); + expect(payloadExt2.data.pbsize).to.equal('300x250_2'); + }); + it('should save bidder request data', function () { expect(request.bidderRequest).to.deep.equal(bidRequest); }); @@ -517,79 +428,13 @@ describe('SSPBC adapter', function () { expect(payload.regs).to.be.an('object').and.to.have.property('[ortb_extensions.gdpr]', 1); 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; - - expect(payloadNative.imp.length).to.equal(1); - expect(nativeAssets).to.contain('{"id":0,"required":true,"title":{"len":80}}'); - expect(nativeAssets).to.contain('{"id":2,"required":true,"img":{"type":1,"w":50,"h":50}}'); - expect(nativeAssets).to.contain('{"id":3,"required":true,"img":{"type":3,"w":150,"h":50}}'); - expect(nativeAssets).to.contain('{"id":4,"required":true,"data":{"type":2}'); - expect(nativeAssets).to.contain('{"id":5,"required":true,"data":{"type":1}'); - }); - - it('should build correct video payload', function () { - const videoAssets = payloadVideo.imp && payloadVideo.imp[0].video; - - expect(payloadVideo.imp.length).to.equal(1); - expect(videoAssets).to.have.property('w').that.equals(640); - expect(videoAssets).to.have.property('h').that.equals(480); - expect(videoAssets).to.have.property('context').that.equals('instream'); - expect(videoAssets).to.have.property('maxduration').that.equals(30); - expect(videoAssets).to.have.property('linearity').that.equals(1); - expect(videoAssets).to.have.property('mimes').that.is.an('array'); - expect(videoAssets).to.have.property('protocols').that.is.an('array'); - expect(videoAssets).to.have.property('api').that.is.an('array'); - }); - - 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 - 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_1') - }); }); describe('interpretResponse', function () { - const { bid_OneCode, bid_video, bid_native, bids, emptyResponse, serverResponse, serverResponseOneCode, serverResponseSingle, serverResponseVideo, serverResponseNative, bidRequest, bidRequestOneCode, bidRequestSingle, bidRequestVideo, bidRequestNative } = prepareTestData(); + const { bid_OneCode, bids, emptyResponse, serverResponse, serverResponseOneCode, serverResponseSingle, bidRequest, bidRequestOneCode, bidRequestSingle } = prepareTestData(); const request = spec.buildRequests(bids, bidRequest); const requestSingle = spec.buildRequests([bids[0]], bidRequestSingle); const requestOneCode = spec.buildRequests([bid_OneCode], bidRequestOneCode); - const requestVideo = spec.buildRequests([bid_video], bidRequestVideo); - const requestNative = spec.buildRequests([bid_native], bidRequestNative); it('should handle nobid responses', function () { let result = spec.interpretResponse(emptyResponse, request); @@ -631,30 +476,7 @@ describe('SSPBC adapter', function () { expect(adcode).to.contain('window.mcad'); expect(adcode).to.contain('window.gdpr'); expect(adcode).to.contain('window.page'); - }); - - it('should create a correct video bid', function () { - let resultVideo = spec.interpretResponse(serverResponseVideo, requestVideo); - - expect(resultVideo.length).to.equal(1); - - let videoBid = resultVideo[0]; - expect(videoBid).to.have.keys('adType', 'bidderCode', 'cpm', 'creativeId', 'currency', 'width', 'height', 'meta', 'mediaType', 'netRevenue', 'requestId', 'ttl', 'vastContent', 'vastXml'); - expect(videoBid.adType).to.equal('instream'); - expect(videoBid.mediaType).to.equal('video'); - expect(videoBid.vastXml).to.match(/^<\?xml.*<\/VAST>$/); - expect(videoBid.vastContent).to.match(/^<\?xml.*<\/VAST>$/); - }); - - it('should create a correct native bid', function () { - let resultNative = spec.interpretResponse(serverResponseNative, requestNative); - - expect(resultNative.length).to.equal(1); - - let nativeBid = resultNative[0]; - expect(nativeBid).to.have.keys('bidderCode', 'cpm', 'creativeId', 'currency', 'width', 'height', 'meta', 'mediaType', 'netRevenue', 'requestId', 'ttl', 'native'); - expect(nativeBid.native).to.have.keys('image', 'icon', 'title', 'sponsoredBy', 'body', 'clickUrl', 'impressionTrackers'); - }); + }) }); describe('getUserSyncs', function () { diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js index e687ff0970f..5c72c6c4dc5 100644 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ b/test/spec/modules/sublimeBidAdapter_spec.js @@ -1,177 +1,11 @@ import { expect } from 'chai'; import { spec } from 'modules/sublimeBidAdapter.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; -const sinon = require('sinon'); - -const utils = require('src/utils'); - -const USER_AGENT = { - // UNKOWN - 'Opera/9.80 (S60; SymbOS; Opera Mobi/1209; U; sk) Presto/2.5.28 Version/10.1': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: '', version: 0 }, - }, - 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02': { - type: 'tablet', os: { name: 'android', version: 4.1 }, browser: { name: '', version: 0 }, - }, - - // MOBILES - // Android Mobile User Agents - 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)': { - type: 'mobile', os: { name: 'windowsPhone', version: 7.5 }, browser: { name: 'Internet Explorer', version: 9 }, - }, - 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1': { - type: 'mobile', os: { name: 'android', version: 2.3 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: 'android', version: 4 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; U; Android 4.4.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: 'android', version: 4.4 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-G930VC Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 58 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G935S Build/MMB29K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G920V Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 5.1.1; SM-G928X Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 5.1 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 6P Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 7.1.1; G8231 Build/41.2.A.0.219; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/59.0.3071.125 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7.1 }, browser: { name: 'Chrome', version: 59 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; E6653 Build/32.2.A.0.253) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; HTC One X10 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 61 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.3': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; U; 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 4 }, - }, - // iPhone User Agents - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5370a Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone9,3; U; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1': { - type: 'mobile', os: { name: 'iOS', version: 10 }, browser: { name: 'Safari', version: 10 }, - }, - 'Mozilla/5.0 (iPhone9,4; U; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1': { - type: 'mobile', os: { name: 'iOS', version: 10 }, browser: { name: 'Safari', version: 10 }, - }, - 'Mozilla/5.0 (Apple-iPhone7C2/1202.466; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 3 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; RM-1152) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15254': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 15.15254 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; RM-1127_16056) AppleWebKit/537.36(KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10536': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 12.10536 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/13.1058': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 13.1058 }, - }, - 'Mozilla/5.0 (Linux; 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11.3 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G903F Build/MMB29K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36 ACHEETAHI/1': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 44 }, - }, - - // TABLETS - 'Mozilla/5.0 (Linux; Android 5.0.2; SAMSUNG SM-T550 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.3 Chrome/38.0.2125.102 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5 }, browser: { name: 'Chrome', version: 38 }, - }, - 'Mozilla/5.0 (Linux; Android 5.1.1; SHIELD Tablet Build/LMY48C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5.1 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; Pixel C Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SGP771 Build/32.2.A.0.253; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SHIELD Tablet K1 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-T827R4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.116 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (Linux; Android 4.4.3; KFTHWI Build/KTU84M) AppleWebKit/537.36 (KHTML, like Gecko) Silk/47.1.79 like Chrome/47.0.2526.80 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 4.4 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 5.0.2; LG-V410/V41020c Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/34.0.1847.118 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5 }, browser: { name: 'Chrome', version: 34 }, - }, - 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1': { - type: 'tablet', os: { name: 'iOS', version: 9.3 }, browser: { name: 'Safari', version: 9 }, - }, - 'Mozilla/5.0 (iPad; CPU OS 11_0_2 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A421 Safari/604.1': { - type: 'tablet', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Android 7.0; Tablet; rv:62.0) Gecko/62.0 Firefox/62.0': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Firefox', version: 62 }, - }, - - // DESKTOP - 'Mozilla/ 5.0(Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari / 537.36': { - type: 'desktop', os: { name: 'Windows', version: 6.1 }, browser: { name: 'Chrome', version: 41 }, - }, - 'Mozilla/5.0 (hone; CPU one OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246': { - type: 'desktop', os: { name: 'Windows', version: 10 }, browser: { name: 'Edge', version: 12.246 }, - }, - 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: 'Chrome', version: 51 }, - }, - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9': { - type: 'desktop', os: { name: 'Mac', version: 10.11 }, browser: { name: 'Safari', version: 9 }, - }, - 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36': { - type: 'desktop', os: { name: 'Windows', version: 6.1 }, browser: { name: 'Chrome', version: 47 }, - }, -}; -describe('Sublime Adapter', function () { - describe('detectDevice', function () { - it('should correctly detect device', function () { - const uaStub = sinon.stub(window.navigator, 'userAgent'); - - Object.keys(USER_AGENT).forEach(userAgent => { - const value = USER_AGENT[userAgent]; - uaStub.value(userAgent); - expect(spec.detectDevice()).to.equal(value.type.charAt(0)); - }); +let utils = require('src/utils'); - uaStub.restore(); - }) - }); +describe('Sublime Adapter', function () { + const adapter = newBidder(spec); describe('sendEvent', function () { let sandbox; @@ -208,98 +42,28 @@ describe('Sublime Adapter', function () { describe('inherited functions', function () { it('exists and is a function', function () { - const adapter = newBidder(spec); expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); describe('isBidRequestValid', function () { - let bid; - beforeEach(function () { - bid = { - bidder: 'sublime', - params: { - zoneId: 24549, - endpoint: '', - }, - }; - }) - - afterEach(function () { - delete window.sublime; - }) + const bid = { + bidder: 'sublime', + params: { + zoneId: 24549, + endpoint: '', + }, + }; it('should return true when required params found', function () { expect(spec.isBidRequestValid(bid)).to.equal(true); }); - it('should return true when a valid notifyId is provided', function () { - bid.params.notifyId = 'f1514724-0922-4b45-a297-27531aeb829a'; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when an invalid notifyId is provided', function () { - bid.params.notifyId = 'some_invalid_notify_id'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when required params are not passed', function () { + const bid = Object.assign({}, bid); bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - - it('should return false when the notifyId does not match sublime one', function () { - bid.params.notifyId = 'f1514724-0922-4b45-a297-27531aeb829a'; - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - expect(spec.isBidRequestValid(bid)).to.equal(false); // FIX THIS - delete window.sublime; - }); - }); - - describe('getNotifyId', function () { - afterEach(function () { - delete window.sublime; - }); - - it('generates a notifyId (not in params, not in sublime)', function () { - const params = Object.freeze({}); - window.sublime = {}; - const notifyId = spec.getNotifyId(params); - expect(spec.isValidNotifyId(notifyId)).to.be.true; - expect(window.sublime.notifyId).to.equal(notifyId); - }); - - it('uses sublime notifyId (not in params, present in sublime)', function () { - const params = Object.freeze({}); - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); - expect(window.sublime.notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); - }); - - it('assigns notifyId from params to sublime (present in params, not in sublime)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = {}; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - }); - - it('returns notifyId from params (same in params & in sublime)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = { notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - }); - - it('returns notifyId from params (present in params & in sublime, with mismatch)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); // did not change - }); }); describe('buildRequests', function () { @@ -312,8 +76,7 @@ describe('Sublime Adapter', function () { requestId: 'xyz654', params: { zoneId: 123, - callbackName: 'false', - notifyId: 'ea252d4f-93d9-4c2f-8cca-88cec3a0a347' + callbackName: 'false' } }, { bidder: 'sublime', @@ -338,32 +101,23 @@ describe('Sublime Adapter', function () { } }; + const request = spec.buildRequests(bidRequests, bidderRequest); + it('should have a post method', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); expect(request[0].method).to.equal('POST'); expect(request[1].method).to.equal('POST'); }); it('should contains a request id equals to the bid id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); for (let i = 0; i < request.length; i = i + 1) { expect(JSON.parse(request[i].data).requestId).to.equal(bidRequests[i].bidId); } }); it('should have an url that contains bid keyword', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); expect(request[0].url).to.match(/bid/); expect(request[1].url).to.match(/bid/); }); - - it('should contains a request notifyId', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - for (let i = 0; i < request.length; i = i + 1) { - const { notifyId } = JSON.parse(request[i].data); - expect(spec.isValidNotifyId(notifyId)).to.be.true; - } - }); }); describe('buildRequests: default arguments', function () { @@ -378,8 +132,9 @@ describe('Sublime Adapter', function () { } }]; + const request = spec.buildRequests(bidRequests); + it('should have an url that match the default endpoint', function () { - const request = spec.buildRequests(bidRequests); expect(request[0].url).to.equal('https://pbjs.sskzlabs.com/bid'); }); }); @@ -412,7 +167,7 @@ describe('Sublime Adapter', function () { sspname: 'foo', netRevenue: true, ttl: 600, - pbav: '0.8.0', + pbav: '0.7.3', ad: '', }, ]; @@ -455,7 +210,7 @@ describe('Sublime Adapter', function () { netRevenue: true, ttl: 600, ad: '', - pbav: '0.8.0', + pbav: '0.7.3', sspname: 'sublime' }; @@ -508,7 +263,7 @@ describe('Sublime Adapter', function () { netRevenue: true, ttl: 600, ad: '', - pbav: '0.8.0', + pbav: '0.7.3', }; expect(result[0]).to.deep.equal(expectedResponse); @@ -604,7 +359,7 @@ describe('Sublime Adapter', function () { it('should set timeout value in state', function () { spec.onTimeout(timeoutData); - expect(spec.state).to.deep.include({ timeout: 1234 }); + expect(spec.state).to.deep.equal({ timeout: 1234, debug: false, notifyId: undefined, transactionId: undefined, zoneId: 123 }); }); afterEach(function () { diff --git a/test/spec/modules/synacormediaBidAdapter_spec.js b/test/spec/modules/synacormediaBidAdapter_spec.js index c053771c296..5f3633ec311 100644 --- a/test/spec/modules/synacormediaBidAdapter_spec.js +++ b/test/spec/modules/synacormediaBidAdapter_spec.js @@ -1231,74 +1231,4 @@ describe('synacormediaBidAdapter ', function () { expect(usersyncs).to.be.an('array').that.is.empty; }); }); - - describe('Bid Requests with price module should use if available', function () { - let validVideoBidRequest = { - bidder: 'synacormedia', - params: { - bidfloor: '0.50', - seatId: 'prebid', - placementId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39', - sizes: [[300, 250]], - bidId: '22b3a2268d9f0e', - bidderRequestId: '1d195910597e13', - auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - let validBannerBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - bidfloor: '0.50', - seatId: 'prebid', - placementId: '1234', - } - }; - - let bidderRequest = { - refererInfo: { - referer: 'http://localhost:9999/' - }, - bidderCode: 'synacormedia', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110' - }; - - it('should return valid bidfloor using price module for banner/video impression', function () { - let bannerRequest = spec.buildRequests([validBannerBidRequest], bidderRequest); - let videoRequest = spec.buildRequests([validVideoBidRequest], bidderRequest); - - expect(bannerRequest.data.imp[0].bidfloor).to.equal(0.5); - expect(videoRequest.data.imp[0].bidfloor).to.equal(0.5); - - let priceModuleFloor = 3; - let floorResponse = { currency: 'USD', floor: priceModuleFloor }; - - validBannerBidRequest.getFloor = () => { return floorResponse; }; - validVideoBidRequest.getFloor = () => { return floorResponse; }; - - bannerRequest = spec.buildRequests([validBannerBidRequest], bidderRequest); - videoRequest = spec.buildRequests([validVideoBidRequest], bidderRequest); - - expect(bannerRequest.data.imp[0].bidfloor).to.equal(priceModuleFloor); - expect(videoRequest.data.imp[0].bidfloor).to.equal(priceModuleFloor); - }); - }); }); diff --git a/test/spec/modules/talkadsBidAdapter_spec.js b/test/spec/modules/talkadsBidAdapter_spec.js deleted file mode 100644 index 00f52ba7b6a..00000000000 --- a/test/spec/modules/talkadsBidAdapter_spec.js +++ /dev/null @@ -1,231 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/talkadsBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {config} from '../../../src/config'; -import {server} from '../../mocks/xhr'; - -describe('TalkAds adapter', function () { - const commonBidderRequest = { - refererInfo: { - referer: 'https://example.com/' - }, - timeout: 3000, - } - const commonBidRequest = { - bidder: 'talkads', - params: { - tag_id: 999999, - bidder_url: 'https://test.natexo-programmatic.com/tad/tag/prebid', - }, - bidId: '1a2b3c4d56e7f0', - auctionId: '12345678-1234-1a2b-3c4d-1a2b3c4d56e7', - transactionId: '4f68b713-04ba-4d7f-8df9-643bcdab5efb', - }; - const nativeBidRequestParams = { - nativeParams: {}, - }; - const bannerBidRequestParams = { - sizes: [[300, 250], [300, 600]], - }; - - /** - * isBidRequestValid - */ - describe('isBidRequestValid1', function() { - it('should fail when config is invalid', function () { - const bidRequest = { - ...commonBidRequest, - ...bannerBidRequestParams, - }; - bidRequest.params = Object.assign({}, bidRequest.params); - delete bidRequest.params; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); // isBidRequestValid1 - describe('isBidRequestValid2', function() { - it('should fail when config is invalid', function () { - const bidRequest = { - ...commonBidRequest, - ...bannerBidRequestParams, - }; - bidRequest.params = Object.assign({}, bidRequest.params); - delete bidRequest.params.bidder_url; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); // isBidRequestValid2 - describe('isBidRequestValid3', function() { - it('should fail when config is invalid', function () { - const bidRequest = { - ...commonBidRequest, - ...bannerBidRequestParams, - }; - bidRequest.params = Object.assign({}, bidRequest.params); - delete bidRequest.params.tag_id; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); // isBidRequestValid3 - describe('isBidRequestValid4', function() { - let bidRequest = { - ...commonBidRequest, - ...bannerBidRequestParams, - }; - it('should succeed when a banner bid is valid', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - }; - it('should succeed when a native bid is valid', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - }); // isBidRequestValid4 - - /** - * buildRequests - */ - describe('buildRequests1', function() { - let bidRequest = { - ...commonBidRequest, - ...bannerBidRequestParams, - }; - const loServerRequest = { - cur: 'EUR', - timeout: commonBidderRequest.timeout, - auction_id: commonBidRequest.auctionId, - transaction_id: commonBidRequest.transactionId, - bids: [{ id: 0, bid_id: commonBidRequest.bidId, type: 'banner', size: bannerBidRequestParams.sizes }], - gdpr: { applies: false, consent: false }, - }; - it('should generate a valid banner bid request', function () { - let laResponse = spec.buildRequests([bidRequest], commonBidderRequest); - expect(laResponse.method).to.equal('POST'); - expect(laResponse.url).to.equal('https://test.natexo-programmatic.com/tad/tag/prebid/999999'); - expect(laResponse.data).to.equal(JSON.stringify(loServerRequest)); - }); - }); // buildRequests1 - describe('buildRequests2', function() { - let bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - }; - const loServerRequest = { - cur: 'EUR', - timeout: commonBidderRequest.timeout, - auction_id: commonBidRequest.auctionId, - transaction_id: commonBidRequest.transactionId, - bids: [{ id: 0, bid_id: commonBidRequest.bidId, type: 'native', size: [] }], - gdpr: { applies: false, consent: false }, - }; - it('should generate a valid native bid request', function () { - let laResponse = spec.buildRequests([bidRequest], commonBidderRequest); - expect(laResponse.method).to.equal('POST'); - expect(laResponse.url).to.equal('https://test.natexo-programmatic.com/tad/tag/prebid/999999'); - expect(laResponse.data).to.equal(JSON.stringify(loServerRequest)); - }); - const bidderRequest = { - ...commonBidderRequest, - gdprConsent: { gdprApplies: true, consentString: 'yes' } - }; - const loServerRequest2 = { - ...loServerRequest, - gdpr: { applies: true, consent: 'yes' }, - }; - it('should generate a valid native bid request', function () { - let laResponse = spec.buildRequests([bidRequest], bidderRequest); - expect(laResponse.method).to.equal('POST'); - expect(laResponse.url).to.equal('https://test.natexo-programmatic.com/tad/tag/prebid/999999'); - expect(laResponse.data).to.equal(JSON.stringify(loServerRequest2)); - }); - }); // buildRequests2 - - /** - * interpretResponse - */ - describe('interpretResponse1', function() { - it('should return empty array if no valid bids', function () { - const laResult = spec.interpretResponse({}, []) - expect(laResult).to.be.an('array').that.is.empty; - }); - const loServerResult = { - body: { status: 'error', error: 'aie' } - }; - it('should return empty array if there is an error', function () { - const laResult = spec.interpretResponse(loServerResult, []) - expect(laResult).to.be.an('array').that.is.empty; - }); - }); // interpretResponse1 - describe('interpretResponse2', function() { - const loServerResult = { - body: { - status: 'ok', - error: '', - pbid: '6147833a65749742875ace47', - bids: [{ - requestId: commonBidRequest.bidId, - cpm: 0.10, - currency: 'EUR', - width: 300, - height: 250, - ad: 'test ad', - ttl: 60, - creativeId: 'c123a456', - netRevenue: false, - }] - } - }; - const loExpected = [{ - requestId: '1a2b3c4d56e7f0', - cpm: 0.1, - currency: 'EUR', - width: 300, - height: 250, - ad: 'test ad', - ttl: 60, - creativeId: 'c123a456', - netRevenue: false, - pbid: '6147833a65749742875ace47' - }]; - it('should return a correct bid response', function () { - const laResult = spec.interpretResponse(loServerResult, []) - expect(JSON.stringify(laResult)).to.equal(JSON.stringify(loExpected)); - }); - }); // interpretResponse2 - - /** - * onBidWon - */ - describe('onBidWon', function() { - it('should not make an ajax call if pbid is null', function () { - const loBid = { - requestId: '1a2b3c4d56e7f0', - cpm: 0.1, - currency: 'EUR', - width: 300, - height: 250, - ad: 'test ad', - ttl: 60, - creativeId: 'c123a456', - netRevenue: false, - } - spec.onBidWon(loBid) - expect(server.requests.length).to.equals(0); - }); - it('should make an ajax call', function () { - const loBid = { - requestId: '1a2b3c4d56e7f0', - cpm: 0.1, - currency: 'EUR', - width: 300, - height: 250, - ad: 'test ad', - ttl: 60, - creativeId: 'c123a456', - netRevenue: false, - pbid: '6147833a65749742875ace47' - } - spec.onBidWon(loBid) - expect(server.requests[0].url).to.equals('https://test.natexo-programmatic.com/tad/tag/prebidwon/6147833a65749742875ace47'); - }); - }); // onBidWon -}); diff --git a/test/spec/modules/tappxBidAdapter_spec.js b/test/spec/modules/tappxBidAdapter_spec.js index 8866670df77..c4e0329de17 100644 --- a/test/spec/modules/tappxBidAdapter_spec.js +++ b/test/spec/modules/tappxBidAdapter_spec.js @@ -1,6 +1,6 @@ import { assert } from 'chai'; import { spec } from 'modules/tappxBidAdapter.js'; -import { _checkParamDataType, _getHostInfo, _extractPageUrl } from '../../../modules/tappxBidAdapter.js'; +import { _checkParamDataType, _getHostInfo } from '../../../modules/tappxBidAdapter.js'; const c_BIDREQUEST = { data: { @@ -70,10 +70,7 @@ const c_SERVERRESPONSE_B = { adm: "\t", w: 320, h: 480, - lurl: 'https:\/\/ssp.api.tappx.com\/burlURL', - burl: 'https:\/\/ssp.api.tappx.com\/burlURL', - nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL', - dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7', + lurl: 'http://testing.ssp.tappx.com/rtb/RTBv2Loss?id=3811165568213389257&ep=ZZ1234PBJS&au=test&bu=localhost&sz=320x480&pu=0.005&pt=0.01&cid=&crid=&adv=&aid=${AUCTION_ID}&bidid=${AUCTION_BID_ID}&impid=${AUCTION_IMP_ID}&sid=${AUCTION_SEAT_ID}&adid=${AUCTION_AD_ID}&ap=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}&mbr=${AUCTION_MBR}&l=${AUCTION_LOSS}', cid: '01744fbb521e9fb10ffea926190effea', crid: 'a13cf884e66e7c660afec059c89d98b6', adomain: [ @@ -101,10 +98,7 @@ const c_SERVERRESPONSE_V = { impid: 1, price: 0.05, adm: "Tappx<\/AdSystem>Tappx<\/AdTitle><\/Impression><\/Error>00:00:22<\/Duration><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/TrackingEvents><\/ClickThrough><\/ClickTracking><\/VideoClicks><\/MediaFile><\/MediaFiles><\/Linear><\/Creative><\/Creatives><\/InLine><\/Ad><\/VAST>", - lurl: 'https:\/\/ssp.api.tappx.com\/lurlURL', - burl: 'https:\/\/ssp.api.tappx.com\/burlURL', - nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL', - dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7', + 'lurl': 'https:\/\/ssp.api.tappx.com\/rtb\/RTBv2Loss?id=5001829913749291152&ep=VZ12TESTCTV&au=test&bu=localhost&sz=6x6&pu=0.005&pt=0.01&cid=&crid=&adv=&aid=${AUCTION_ID}&bidid=${AUCTION_BID_ID}&impid=${AUCTION_IMP_ID}&sid=${AUCTION_SEAT_ID}&adid=${AUCTION_AD_ID}&ap=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}&mbr=${AUCTION_MBR}&l=${AUCTION_LOSS}', cid: '01744fbb521e9fb10ffea926190effea', crid: 'a13cf884e66e7c660afec059c89d98b6', adomain: [ @@ -123,7 +117,6 @@ const c_VALIDBIDREQUESTS = [{'bidder': 'tappx', 'params': {'host': 'testing.ssp. const c_VALIDBIDAPPREQUESTS = [{'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com\/rtb\/v2\/', 'tappxkey': 'pub-1234-android-1234', 'endpoint': 'ZZ1234PBJS', 'bidfloor': 0.005, 'test': 1, 'app': {'name': 'Tappx Test', 'bundle': 'com.test.tappx', 'domain': 'tappx.com', 'publisher': { 'name': 'Tappx', 'domain': 'tappx.com' }}}, 'userId': {'haloId': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'id5id': {'uid': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'ext': {'linkType': 0}}, 'intentIqId': 'GIF89a\u0001\u0000\u0001\u0000�\u0000\u0000���\u0000\u0000\u0000!�\u0004\u0001\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;', 'lotamePanoramaId': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'parrableId': {'eid': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0'}, 'pubcid': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'pubProvidedId': [{'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}]}, 'userIdAsEids': [{'source': 'audigent.com', 'uids': [{'id': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'atype': 1}]}, {'source': 'id5-sync.com', 'uids': [{'id': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'atype': 1, 'ext': {'linkType': 0}}]}, {'source': 'intentiq.com', 'uids': [{'id': 'GIF89a\u0001\u0000\u0001\u0000�\u0000\u0000���\u0000\u0000\u0000!�\u0004\u0001\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;', 'atype': 1}]}, {'source': 'crwdcntrl.net', 'uids': [{'id': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'atype': 1}]}, {'source': 'parrable.com', 'uids': [{'id': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0', 'atype': 1}]}, {'source': 'pubcid.org', 'uids': [{'id': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'atype': 1}]}, {'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}], 'ortb2Imp': {'ext': {'data': {'adserver': {'name': 'gam', 'adslot': '/19968336/header-bid-tag-0'}, 'pbadslot': '/19968336/header-bid-tag-0'}}}, 'mediaTypes': {'banner': {'sizes': [[320, 480], [320, 50]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '71c0d86b-4b47-4aff-a6da-1af0b1712439', 'sizes': [[320, 480], [320, 50]], 'bidId': '264d7969b125a5', 'bidderRequestId': '1c674c14a3889c', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}]; const c_BIDDERREQUEST_B = {'bidderCode': 'tappx', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'bidderRequestId': '1c674c14a3889c', 'bids': [{'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com\/rtb\/v2\/', 'tappxkey': 'pub-1234-android-1234', 'endpoint': 'ZZ1234PBJS', 'bidfloor': 0.005, 'test': 1}, 'userId': {'haloId': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'id5id': {'uid': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'ext': {'linkType': 0}}, 'intentIqId': 'GIF89a\u0000\u0000\u0000\u0000�\u0000\u0000���\u0000\u0000\u0000?�\u0000\u0000\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000A\u0000\u0000;', 'lotamePanoramaId': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'parrableId': {'eid': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0'}, 'pubcid': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'pubProvidedId': [{'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}]}, 'userIdAsEids': [{'source': 'audigent.com', 'uids': [{'id': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'atype': 1}]}, {'source': 'id5-sync.com', 'uids': [{'id': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'atype': 1, 'ext': {'linkType': 0}}]}], 'ortb2Imp': {'ext': {'data': {'adserver': {'name': 'gam', 'adslot': '/19968336/header-bid-tag-0'}, 'pbadslot': '/19968336/header-bid-tag-0'}}}, 'mediaTypes': {'banner': {'sizes': [[320, 480], [320, 50]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '71c0d86b-4b47-4aff-a6da-1af0b1712439', 'sizes': [[320, 480], [320, 50]], 'bidId': '264d7969b125a5', 'bidderRequestId': '1c674c14a3889c', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}], 'auctionStart': 1617088922120, 'timeout': 700, 'refererInfo': {'referer': 'http://localhost:9999/integrationExamples/gpt/gdpr_hello_world.html?pbjs_debug=true', 'reachedTop': true, 'isAmp': false, 'numIframes': 0, 'stack': ['http://localhost:9999/integrationExamples/gpt/gdpr_hello_world.html?pbjs_debug=true'], 'canonicalUrl': null}, 'gdprConsent': {'consentString': c_CONSENTSTRING, 'vendorData': {'metadata': 'BO-JeiTPABAOkAAABAENABA', 'gdprApplies': true, 'hasGlobalScope': false, 'cookieVersion': 1, 'created': '2020-12-09T09:22:09.900Z', 'lastUpdated': '2021-01-14T15:44:03.600Z', 'cmpId': 0, 'cmpVersion': 1, 'consentScreen': 0, 'consentLanguage': 'EN', 'vendorListVersion': 1, 'maxVendorId': 0, 'purposeConsents': {}, 'vendorConsents': {}}, 'gdprApplies': true, 'apiVersion': 1}, 'uspConsent': '1YCC', 'start': 1611308859099}; const c_BIDDERREQUEST_V = {'method': 'POST', 'url': 'https://testing.ssp.tappx.com/rtb/v2//VZ12TESTCTV?type_cnn=prebidjs&v=0.1.10329', 'data': '{"site":{"name":"localhost","bundle":"localhost","domain":"localhost"},"user":{"ext":{}},"id":"0fecfa84-c541-49f8-8c45-76b90fddc30e","test":1,"at":1,"tmax":1000,"bidder":"tappx","imp":[{"video":{"mimes":["video/mp4","application/javascript"],"minduration":3,"maxduration":30,"startdelay":5,"playbackmethod":[1,3],"api":[1,2],"protocols":[2,3],"battr":[13,14],"linearity":1,"placement":2,"minbitrate":10,"maxbitrate":10,"w":320,"h":250},"id":"2398241a5a860b","tagid":"localhost_typeAdBanVid_windows","secure":1,"bidfloor":0.005,"ext":{"bidder":{"tappxkey":"pub-1234-desktop-1234","endpoint":"vz34906po","host":"https://vz34906po.pub.tappx.com/rtb/","bidfloor":0.005}}}],"device":{"os":"windows","ip":"peer","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36","h":864,"w":1536,"dnt":0,"language":"en","make":"Google Inc."},"params":{"host":"tappx.com","bidfloor":0.005},"regs":{"gdpr":0,"ext":{}}}', 'bids': {'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com/rtb/v2/', 'tappxkey': 'pub-1234-desktop-1234', 'endpoint': 'VZ12TESTCTV', 'bidfloor': 0.005, 'test': true}, 'crumbs': {'pubcid': 'dccfe922-3823-4676-b7b2-e5ed8743154e'}, 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video-ad-div'}}}, 'renderer': {'options': {'text': 'Tappx Outstream Video'}}, 'mediaTypes': {'video': {'mimes': ['video/mp4', 'application/javascript'], 'minduration': 3, 'maxduration': 30, 'startdelay': 5, 'playbackmethod': [1, 3], 'api': [1, 2], 'protocols': [2, 3], 'battr': [13, 14], 'linearity': 1, 'placement': 2, 'minbitrate': 10, 'maxbitrate': 10, 'w': 320, 'h': 250}}, 'adUnitCode': 'video-ad-div', 'transactionId': 'ed41c805-d14c-49c3-954d-26b98b2aa2c2', 'sizes': [[320, 250]], 'bidId': '28f49c71b13f2f', 'bidderRequestId': '1401710496dc7', 'auctionId': 'e807363f-3095-43a8-a4a6-f44196cb7318', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}} -const c_BIDDERREQUEST_VOutstream = {'method': 'POST', 'url': 'https://testing.ssp.tappx.com/rtb/v2//VZ12TESTCTV?type_cnn=prebidjs&v=0.1.10329', 'data': '{"site":{"name":"localhost","bundle":"localhost","domain":"localhost"},"user":{"ext":{}},"id":"0fecfa84-c541-49f8-8c45-76b90fddc30e","test":1,"at":1,"tmax":1000,"bidder":"tappx","imp":[{"video":{"context": "outstream","playerSize":[640, 480],"mimes":["video/mp4","application/javascript"],"minduration":3,"maxduration":30,"startdelay":5,"playbackmethod":[1,3],"api":[1,2],"protocols":[2,3],"battr":[13,14],"linearity":1,"placement":2,"minbitrate":10,"maxbitrate":10,"w":320,"h":250},"id":"2398241a5a860b","tagid":"localhost_typeAdBanVid_windows","secure":1,"bidfloor":0.005,"ext":{"bidder":{"tappxkey":"pub-1234-desktop-1234","endpoint":"vz34906po","host":"https://vz34906po.pub.tappx.com/rtb/","bidfloor":0.005}}}],"device":{"os":"windows","ip":"peer","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36","h":864,"w":1536,"dnt":0,"language":"en","make":"Google Inc."},"params":{"host":"tappx.com","bidfloor":0.005},"regs":{"gdpr":0,"ext":{}}}', 'bids': {'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com/rtb/v2/', 'tappxkey': 'pub-1234-desktop-1234', 'endpoint': 'VZ12TESTCTV', 'bidfloor': 0.005, 'test': true}, 'crumbs': {'pubcid': 'dccfe922-3823-4676-b7b2-e5ed8743154e'}, 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video-ad-div'}}}, 'renderer': {'options': {'text': 'Tappx Outstream Video'}}, 'mediaTypes': {'video': {'mimes': ['video/mp4', 'application/javascript'], 'minduration': 3, 'maxduration': 30, 'startdelay': 5, 'playbackmethod': [1, 3], 'api': [1, 2], 'protocols': [2, 3], 'battr': [13, 14], 'linearity': 1, 'placement': 2, 'minbitrate': 10, 'maxbitrate': 10, 'w': 320, 'h': 250}}, 'adUnitCode': 'video-ad-div', 'transactionId': 'ed41c805-d14c-49c3-954d-26b98b2aa2c2', 'sizes': [[320, 250]], 'bidId': '28f49c71b13f2f', 'bidderRequestId': '1401710496dc7', 'auctionId': 'e807363f-3095-43a8-a4a6-f44196cb7318', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}} describe('Tappx bid adapter', function () { /** @@ -134,6 +127,12 @@ describe('Tappx bid adapter', function () { assert.isTrue(spec.isBidRequestValid(c_BIDREQUEST.bids[0]), JSON.stringify(c_BIDREQUEST)); }); + it('should return false when params are missing', function () { + let badBidRequestParam = JSON.parse(JSON.stringify(c_BIDREQUEST)); + delete badBidRequestParam.bids[0].params; + assert.isFalse(spec.isBidRequestValid(badBidRequestParam.bids[0])); + }); + it('should return false when tappxkey is missing', function () { let badBidRequestTpxkey = JSON.parse(JSON.stringify(c_BIDREQUEST)); ; delete badBidRequestTpxkey.bids[0].params.tappxkey; @@ -159,18 +158,24 @@ describe('Tappx bid adapter', function () { assert.isTrue(spec.isBidRequestValid(badBidRequestNwEp.bids[0])); }); - it('should return false for not instream/outstream requests', function () { + it('should return false mimes param is missing', function () { + let badBidRequest_mimes = c_BIDDERREQUEST_V; + delete badBidRequest_mimes.bids.mediaTypes.video; + badBidRequest_mimes.bids.mediaTypes.video = {}; + badBidRequest_mimes.bids.mediaTypes.video.context = 'instream'; + badBidRequest_mimes.bids.mediaTypes.video.playerSize = [320, 250]; + assert.isFalse(spec.isBidRequestValid(badBidRequest_mimes.bids), badBidRequest_mimes); + }); + + it('should return false for not instream requests', function () { let badBidRequest_v = c_BIDDERREQUEST_V; delete badBidRequest_v.bids.mediaTypes.banner; badBidRequest_v.bids.mediaTypes.video = {}; - badBidRequest_v.bids.mediaTypes.video.context = ''; + badBidRequest_v.bids.mediaTypes.video.context = 'outstream'; + badBidRequest_v.bids.mediaTypes.video.mimes = [ 'video/mp4', 'application/javascript' ]; badBidRequest_v.bids.mediaTypes.video.playerSize = [320, 250]; assert.isFalse(spec.isBidRequestValid(badBidRequest_v.bids)); }); - - it('should export the TCF vendor ID', function () { - expect(spec.gvlid).to.equal(628); - }) }); /** @@ -180,13 +185,11 @@ describe('Tappx bid adapter', function () { // Web Test let validBidRequests = c_VALIDBIDREQUESTS; let validBidRequests_V = c_VALIDBIDREQUESTS; - let validBidRequests_Voutstream = c_VALIDBIDREQUESTS; // App Test let validAppBidRequests = c_VALIDBIDAPPREQUESTS; let bidderRequest = c_BIDDERREQUEST_B; let bidderRequest_V = c_BIDDERREQUEST_V; - let bidderRequest_VOutstream = c_BIDDERREQUEST_VOutstream; it('should add gdpr/usp consent information to the request', function () { const request = spec.buildRequests(validBidRequests, bidderRequest); @@ -212,13 +215,6 @@ describe('Tappx bid adapter', function () { }); it('should properly build a video request', function () { - delete validBidRequests_V[0].mediaTypes.banner - validBidRequests_V[0].mediaTypes.video = {}; - validBidRequests_V[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_V[0].mediaTypes.video.context = 'instream'; - - bidderRequest_V.bids.mediaTypes.context = 'instream'; - const request = spec.buildRequests(validBidRequests_V, bidderRequest_V); expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); expect(request[0].method).to.equal('POST'); @@ -227,46 +223,9 @@ describe('Tappx bid adapter', function () { expect(data.site).to.not.equal(null); expect(data.imp).to.have.lengthOf(1); expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); - }); - - it('should properly build a video outstream request', function () { - delete validBidRequests_Voutstream[0].mediaTypes.banner - validBidRequests_Voutstream[0].mediaTypes.video = {}; - validBidRequests_Voutstream[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_Voutstream[0].mediaTypes.video.context = 'outstream'; - - bidderRequest_VOutstream.bids.mediaTypes.context = 'outstream'; - - const request = spec.buildRequests(validBidRequests_Voutstream, bidderRequest_VOutstream); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); - }); - - it('should properly create video rewarded request', function () { - delete validBidRequests_Voutstream[0].mediaTypes.banner - validBidRequests_Voutstream[0].mediaTypes.video = {}; - validBidRequests_Voutstream[0].mediaTypes.video.rewarded = 1; - validBidRequests_Voutstream[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_Voutstream[0].mediaTypes.video.context = 'outstream'; - - bidderRequest_VOutstream.bids.mediaTypes.context = 'outstream'; - - const request = spec.buildRequests(validBidRequests_Voutstream, bidderRequest_VOutstream); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); + expect(data.imp[0].banner).to.not.equal(null); + expect(data.imp[0].banner.w).to.be.oneOf([320, 50, 250, 480]); + expect(data.imp[0].banner.h).to.be.oneOf([320, 50, 250, 480]); }); it('should set user eids array', function () { @@ -455,13 +414,4 @@ describe('Tappx bid adapter', function () { expect(_checkParamDataType('Wrong array', false, 'array')).to.be.undefined; }); }) - - describe('_extractPageUrl tests', function() { - let validBidRequests = c_VALIDBIDREQUESTS; - let bidderRequest = c_BIDDERREQUEST_B; - it('should return the Domain of the site', function () { - validBidRequests[0].params.domainUrl = 'testUrl.com'; - assert.isString(_extractPageUrl(validBidRequests, bidderRequest)); - }); - }) }); diff --git a/test/spec/modules/targetVideoBidAdapter_spec.js b/test/spec/modules/targetVideoBidAdapter_spec.js deleted file mode 100644 index 0ce6f0fb70d..00000000000 --- a/test/spec/modules/targetVideoBidAdapter_spec.js +++ /dev/null @@ -1,96 +0,0 @@ -import { spec } from '../../../modules/targetVideoBidAdapter.js' - -describe('TargetVideo Bid Adapter', function() { - const bannerRequest = [{ - bidder: 'targetVideo', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - params: { - placementId: 12345, - } - }]; - - it('Test the bid validation function', function() { - const validBid = spec.isBidRequestValid(bannerRequest[0]); - const invalidBid = spec.isBidRequestValid(null); - - expect(validBid).to.be.true; - expect(invalidBid).to.be.false; - }); - - it('Test the request processing function', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - expect(request).to.not.be.empty; - - const payload = JSON.parse(request.data); - expect(payload).to.not.be.empty; - expect(payload.sdk).to.deep.equal({ - source: 'pbjs', - version: '$prebid.version$' - }); - expect(payload.tags[0].id).to.equal(12345); - expect(payload.tags[0].gpid).to.equal('targetVideo'); - expect(payload.tags[0].ad_types[0]).to.equal('video'); - }); - - it('Handle nobid responses', function () { - const responseBody = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }] - }; - const bidderRequest = null; - - const bidResponse = spec.interpretResponse({ body: responseBody }, {bidderRequest}); - expect(bidResponse.length).to.equal(0); - }); - - it('Test the response parsing function', function () { - const responseBody = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'https://www.target-video.com/', - 'rtb': { - 'video': { - 'player_width': 640, - 'player_height': 360, - 'asset_url': 'https://www.target-video.com/' - } - } - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }] - }; - - const bidResponse = spec.interpretResponse({ body: responseBody }, {bidderRequest}); - expect(bidResponse).to.not.be.empty; - - const bid = bidResponse[0]; - expect(bid).to.not.be.empty; - expect(bid.cpm).to.equal(0.675); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ad).to.include('') - expect(bid.ad).to.include('initPlayer') - }); -}); diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js index 75ed7452b57..7fd3b70398b 100644 --- a/test/spec/modules/teadsBidAdapter_spec.js +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -582,93 +582,6 @@ describe('teadsBidAdapter', () => { }); }); - describe('Global Placement Id', function () { - let bidRequests = [ - { - 'bidder': 'teads', - 'params': { - 'placementId': 10433394, - 'pageId': 1234 - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ee', - 'deviceWidth': 1680 - }, - { - 'bidder': 'teads', - 'params': { - 'placementId': 10433395, - 'pageId': 1234 - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1f', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ef', - 'deviceWidth': 1680 - } - ]; - - it('should add gpid if ortb2Imp.ext.gpid is present and is non empty', function () { - const updatedBidRequests = bidRequests.map(function(bidRequest, index) { - return { - ...bidRequest, - ortb2Imp: { - ext: { - gpid: '1111/home-left-' + index - } - } - }; - } - ); - const request = spec.buildRequests(updatedBidRequests, bidderResquestDefault); - const payload = JSON.parse(request.data); - - expect(payload.data[0].gpid).to.equal('1111/home-left-0'); - expect(payload.data[1].gpid).to.equal('1111/home-left-1'); - }); - - it('should not add gpid if ortb2Imp.ext.gpid is present but empty', function () { - const updatedBidRequests = bidRequests.map(bidRequest => ({ - ...bidRequest, - ortb2Imp: { - ext: { - gpid: '' - } - } - })); - - const request = spec.buildRequests(updatedBidRequests, bidderResquestDefault); - const payload = JSON.parse(request.data); - - return payload.data.forEach(bid => { - expect(bid).not.to.have.property('gpid'); - }); - }); - - it('should not add gpid if ortb2Imp.ext.gpid is not present', function () { - const updatedBidRequests = bidRequests.map(bidRequest => ({ - ...bidRequest, - ortb2Imp: { - ext: { - } - } - })); - - const request = spec.buildRequests(updatedBidRequests, bidderResquestDefault); - const payload = JSON.parse(request.data); - - return payload.data.forEach(bid => { - expect(bid).not.to.have.property('gpid'); - }); - }); - }); - function checkMediaTypesSizes(mediaTypes, expectedSizes) { const bidRequestWithBannerSizes = Object.assign(bidRequests[0], mediaTypes); const requestWithBannerSizes = spec.buildRequests([bidRequestWithBannerSizes], bidderResquestDefault); diff --git a/test/spec/modules/timeoutRtdProvider_spec.js b/test/spec/modules/timeoutRtdProvider_spec.js deleted file mode 100644 index 88415a99b5e..00000000000 --- a/test/spec/modules/timeoutRtdProvider_spec.js +++ /dev/null @@ -1,339 +0,0 @@ - -import { timeoutRtdFunctions, timeoutSubmodule } from '../../../modules/timeoutRtdProvider' -import { expect } from 'chai'; -import * as ajax from 'src/ajax.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; - -const DEFAULT_USER_AGENT = window.navigator.userAgent; -const DEFAULT_CONNECTION = window.navigator.connection; - -const PC_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'; -const MOBILE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'; -const TABLET_USER_AGENT = 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'; - -function resetUserAgent() { - window.navigator.__defineGetter__('userAgent', () => DEFAULT_USER_AGENT); -}; - -function setUserAgent(userAgent) { - window.navigator.__defineGetter__('userAgent', () => userAgent); -} - -function resetConnection() { - window.navigator.__defineGetter__('connection', () => DEFAULT_CONNECTION); -} -function setConnectionType(connectionType) { - window.navigator.__defineGetter__('connection', () => { return {'type': connectionType} }); -} - -describe('getDeviceType', () => { - afterEach(() => { - resetUserAgent(); - }); - - [ - // deviceType, userAgent, deviceTypeNum - ['pc', PC_USER_AGENT, 2], - ['mobile', MOBILE_USER_AGENT, 4], - ['tablet', TABLET_USER_AGENT, 5], - ].forEach(function(args) { - const [deviceType, userAgent, deviceTypeNum] = args; - it(`should be able to recognize ${deviceType} devices`, () => { - setUserAgent(userAgent); - const res = timeoutRtdFunctions.getDeviceType(); - expect(res).to.equal(deviceTypeNum) - }) - }) -}); - -describe('getConnectionSpeed', () => { - afterEach(() => { - resetConnection(); - }); - [ - // connectionType, connectionSpeed - ['slow-2g', 'slow'], - ['2g', 'slow'], - ['3g', 'medium'], - ['bluetooth', 'fast'], - ['cellular', 'fast'], - ['ethernet', 'fast'], - ['wifi', 'fast'], - ['wimax', 'fast'], - ['4g', 'fast'], - ['not known', 'unknown'], - [undefined, 'unknown'], - ].forEach(function(args) { - const [connectionType, connectionSpeed] = args; - it(`should be able to categorize connection speed when the connection type is ${connectionType}`, () => { - setConnectionType(connectionType); - const res = timeoutRtdFunctions.getConnectionSpeed(); - expect(res).to.equal(connectionSpeed) - }) - }) -}); - -describe('Timeout modifier calculations', () => { - let sandbox; - beforeEach(() => { - sandbox = sinon.sandbox.create(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should be able to detect video ad units', () => { - let adUnits = [] - let res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.false; - - adUnits = [{ - mediaTypes: { - video: [] - } - }]; - res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.true; - - adUnits = [{ - mediaTypes: { - banner: [] - } - }]; - res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.false; - }); - - it('should calculate the timeout modifier for video', () => { - sandbox.stub(timeoutRtdFunctions, 'checkVideo').returns(true); - const rules = { - includesVideo: { - 'true': 200, - 'false': 50 - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(200) - }); - - it('should calculate the timeout modifier for connectionSpeed', () => { - sandbox.stub(timeoutRtdFunctions, 'getConnectionSpeed').returns('slow'); - const rules = { - connectionSpeed: { - 'slow': 200, - 'medium': 100, - 'fast': 50 - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(200); - }); - - it('should calculate the timeout modifier for deviceType', () => { - sandbox.stub(timeoutRtdFunctions, 'getDeviceType').returns(4); - const rules = { - deviceType: { - '2': 50, - '4': 100, - '5': 200 - }, - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(100) - }); - - it('should calculate the timeout modifier for ranged numAdunits', () => { - const rules = { - numAdUnits: { - '1-5': 100, - '6-10': 200, - '11-15': 300, - } - } - const adUnits = [1, 2, 3, 4, 5, 6]; - const res = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules); - expect(res).to.equal(200) - }); - - it('should calculate the timeout modifier for exact numAdunits', () => { - const rules = { - numAdUnits: { - '1': 100, - '2': 200, - '3': 300, - '4-5': 400, - } - } - const adUnits = [1, 2]; - const res = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules); - expect(res).to.equal(200); - }); - - it('should add up all the modifiers when all the rules are present', () => { - sandbox.stub(timeoutRtdFunctions, 'getConnectionSpeed').returns('slow'); - sandbox.stub(timeoutRtdFunctions, 'getDeviceType').returns(4); - const rules = { - connectionSpeed: { - 'slow': 200, - 'medium': 100, - 'fast': 50 - }, - deviceType: { - '2': 50, - '4': 100, - '5': 200 - }, - includesVideo: { - 'true': 200, - 'false': 50 - }, - numAdUnits: { - '1': 100, - '2': 200, - '3': 300, - '4-5': 400, - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([{ - mediaTypes: { - video: [] - } - }], rules); - expect(res).to.equal(600); - }); -}); - -describe('Timeout RTD submodule', () => { - let sandbox; - beforeEach(() => { - sandbox = sinon.sandbox.create(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should init successfully', () => { - expect(timeoutSubmodule.init()).to.equal(true); - }); - - it('should make a request to the endpoint url if it is provided, and handle the response', () => { - const response = '{"deviceType":{ "2": 50, "4": 100, "5": 200 }}' - const ajaxStub = sandbox.stub().callsFake(function (url, callbackObj) { - callbackObj.success(response); - }); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(function () { return ajaxStub }); - - const reqBidsConfigObj = {} - const expectedLink = 'https://somelink.json' - const config = { - 'name': 'timeout', - 'params': { - 'endpoint': { - url: expectedLink - } - } - } - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - timeoutSubmodule.getBidRequestData(reqBidsConfigObj, function() {}, config) - - expect(ajaxStub.calledWith(expectedLink)).to.be.true; - expect(handleTimeoutIncrementStub.calledWith(reqBidsConfigObj, JSON.parse(response))).to.be.true; - }); - - it('should make a request to the endpoint url and ignore the rules object if the endpoint is provided', () => { - const ajaxStub = sandbox.stub().callsFake((url, callbackObj) => {}); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(() => ajaxStub); - const expectedLink = 'https://somelink.json' - const config = { - 'name': 'timeout', - 'params': { - 'endpoint': { - url: expectedLink - }, - 'rules': { - 'includesVideo': { - 'true': 200, - }, - } - } - } - timeoutSubmodule.getBidRequestData({}, function() {}, config); - expect(ajaxStub.calledWith(expectedLink)).to.be.true; - }); - - it('should use the rules object if there is no endpoint url', () => { - const config = { - 'name': 'timeout', - 'params': { - 'rules': { - 'includesVideo': { - 'true': 200, - }, - } - } - } - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - const reqBidsConfigObj = {}; - timeoutSubmodule.getBidRequestData(reqBidsConfigObj, function() {}, config); - expect(handleTimeoutIncrementStub.calledWith(reqBidsConfigObj, config.params.rules)).to.be.true; - }); - - it('should exit quietly if no relevant timeout config is found', () => { - const callback = sandbox.stub() - const ajaxStub = sandbox.stub().callsFake((url, callbackObj) => {}); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(function() { return ajaxStub }); - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - - timeoutSubmodule.getBidRequestData({}, callback, {}); - - expect(handleTimeoutIncrementStub.called).to.be.false; - expect(callback.called).to.be.true; - expect(ajaxStub.called).to.be.false; - }); - - it('should be able to increment the timeout with the calculated timeout modifier', () => { - const baseTimeout = 100; - const getConfigStub = sandbox.stub().returns(baseTimeout); - sandbox.stub(prebidGlobal, 'getGlobal').callsFake(() => { - return { - getConfig: getConfigStub - } - }); - - const reqBidsConfigObj = {adUnits: [1, 2, 3]} - const addedTimeout = 400; - const rules = { - numAdUnits: { - '3-5': addedTimeout, - } - } - - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules) - expect(reqBidsConfigObj.timeout).to.be.equal(baseTimeout + addedTimeout); - }); - - it('should be able to increment the timeout with the calculated timeout modifier when there are multiple matching rules', () => { - const baseTimeout = 100; - const getConfigStub = sandbox.stub().returns(baseTimeout); - sandbox.stub(prebidGlobal, 'getGlobal').callsFake(() => { - return { - getConfig: getConfigStub - } - }); - - const reqBidsConfigObj = {adUnits: [1, 2, 3]} - const addedTimeout = 400; - const rules = { - numAdUnits: { - '3-5': addedTimeout / 2, - }, - includesVideo: { - 'false': addedTimeout / 2, - } - } - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules) - expect(reqBidsConfigObj.timeout).to.be.equal(baseTimeout + addedTimeout); - }); -}); diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index 6f2674dadc5..30377ec0a5d 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -568,134 +568,6 @@ describe('triplelift adapter', function () { expect(payload.user.ext.eids).to.have.lengthOf(4); }); - it('should remove malformed ids that would otherwise break call', function () { - let tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - let idlEnvId = null; // fail; can't be null - let criteoId = '53e30ea700424f7bbdd793b02abc5d7'; - let pubcid = ''; // fail; can't be empty string - - let bidRequestsMultiple = [ - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } } - ]; - - let request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest); - let payload = request.data; - - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'adserver.org', - uids: [ - { - id: tdidId, - ext: { rtiPartner: 'TDID' } - } - ], - }, - { - source: 'criteo.com', - uids: [ - { - id: criteoId, - ext: { rtiPartner: 'criteoId' } - } - ] - } - ] - } - }); - - expect(payload.user.ext.eids).to.be.an('array'); - expect(payload.user.ext.eids).to.have.lengthOf(2); - - tdidId = {}; // fail; can't be empty object - idlEnvId = { id: '987654' }; // pass - criteoId = [{ id: '123456' }]; // fail; can't be an array - pubcid = '3261d8ad-435d-481d-abd1-9f1a9ec99f0e'; // pass - - bidRequestsMultiple = [ - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } } - ]; - - request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest); - payload = request.data; - - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'liveramp.com', - uids: [ - { - id: '987654', - ext: { rtiPartner: 'idl' } - } - ] - }, - { - source: 'pubcid.org', - uids: [ - { - id: pubcid, - ext: { rtiPartner: 'pubcid' } - } - ] - } - ] - } - }); - - expect(payload.user.ext.eids).to.be.an('array'); - expect(payload.user.ext.eids).to.have.lengthOf(2); - - tdidId = { id: '987654' }; // pass - idlEnvId = { id: 987654 }; // fail; can't be an int - criteoId = '53e30ea700424f7bbdd793b02abc5d7'; // pass - pubcid = { id: '' }; // fail; can't be an empty string - - bidRequestsMultiple = [ - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }, - { ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } } - ]; - - request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest); - payload = request.data; - - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'adserver.org', - uids: [ - { - id: '987654', - ext: { rtiPartner: 'TDID' } - } - ], - }, - { - source: 'criteo.com', - uids: [ - { - id: criteoId, - ext: { rtiPartner: 'criteoId' } - } - ] - } - ] - } - }); - - expect(payload.user.ext.eids).to.be.an('array'); - expect(payload.user.ext.eids).to.have.lengthOf(2); - }); - it('should return a query string for TL call', function () { const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); const url = request.url; @@ -937,8 +809,6 @@ describe('triplelift adapter', function () { expect(result).to.have.length(2); expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); expect(Object.keys(result[1])).to.have.members(Object.keys(expectedResponse[1])); - expect(result[0].ttl).to.equal(300); - expect(result[1].ttl).to.equal(3600); }); it('should return multiple responses to support SRA', function () { diff --git a/test/spec/modules/trustxBidAdapter_spec.js b/test/spec/modules/trustxBidAdapter_spec.js index e710bd6d00f..a8caed3ad0e 100644 --- a/test/spec/modules/trustxBidAdapter_spec.js +++ b/test/spec/modules/trustxBidAdapter_spec.js @@ -40,6 +40,229 @@ describe('TrustXAdapter', function () { }); describe('buildRequests', function () { + function parseRequest(url) { + const res = {}; + url.split('&').forEach((it) => { + const couple = it.split('='); + res[couple[0]] = decodeURIComponent(couple[1]); + }); + return res; + } + + const bidderRequest = { + refererInfo: { + referer: 'https://example.com' + } + }; + const referrer = bidderRequest.refererInfo.referer; + + let bidRequests = [ + { + 'bidder': 'trustx', + 'params': { + 'uid': '43' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '30b31c1838de1e', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'trustx', + 'params': { + 'uid': '43' + }, + 'adUnitCode': 'adunit-code-2', + 'sizes': [[728, 90], [300, 250]], + 'bidId': '3150ccb55da321', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + }, + { + 'bidder': 'trustx', + 'params': { + 'uid': '45' + }, + 'adUnitCode': 'adunit-code-1', + 'sizes': [[300, 250], [300, 600]], + 'bidId': '42dbe3a7168a6a', + 'bidderRequestId': '22edbae2733bf6', + 'auctionId': '1d1a030790a475', + } + ]; + + it('should attach valid params to the tag', function () { + const request = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '43'); + expect(payload).to.have.property('sizes', '300x250,300x600'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('wrapperType', 'Prebid_js'); + expect(payload).to.have.property('wrapperVersion', '$prebid.version$'); + }); + + it('sizes must not be duplicated', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '43,43,45'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + }); + + it('pt parameter must be "gross" if params.priceType === "gross"', function () { + bidRequests[1].params.priceType = 'gross'; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'gross'); + expect(payload).to.have.property('auids', '43,43,45'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + delete bidRequests[1].params.priceType; + }); + + it('pt parameter must be "net" or "gross"', function () { + bidRequests[1].params.priceType = 'some'; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '43,43,45'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + delete bidRequests[1].params.priceType; + }); + + it('if gdprConsent is present payload must have gdpr params', function () { + const bidderRequestWithGDPR = Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: true}}, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + + it('if gdprApplies is false gdpr_applies must be 0', function () { + const bidderRequestWithGDPR = Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: false}}, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '0'); + }); + + it('if gdprApplies is undefined gdpr_applies must be 1', function () { + const bidderRequestWithGDPR = Object.assign({gdprConsent: {consentString: 'AAA'}}, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', '1'); + }); + + it('if usPrivacy is present payload must have us_privacy param', function () { + const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequestWithUSP)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload).to.have.property('us_privacy', '1YNN'); + }); + + it('should convert keyword params to proper form and attaches to request', function () { + const bidRequestWithKeywords = [].concat(bidRequests); + bidRequestWithKeywords[1] = Object.assign({}, + bidRequests[1], + { + params: { + uid: '43', + keywords: { + single: 'val', + singleArr: ['val'], + singleArrNum: [5], + multiValMixed: ['value1', 2, 'value3'], + singleValNum: 123, + emptyStr: '', + emptyArr: [''], + badValue: {'foo': 'bar'} // should be dropped + } + } + } + ); + + const request = spec.buildRequests(bidRequestWithKeywords, bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload.keywords).to.be.an('string'); + payload.keywords = JSON.parse(payload.keywords); + + expect(payload.keywords).to.deep.equal([{ + 'key': 'single', + 'value': ['val'] + }, { + 'key': 'singleArr', + 'value': ['val'] + }, { + 'key': 'singleArrNum', + 'value': ['5'] + }, { + 'key': 'multiValMixed', + 'value': ['value1', '2', 'value3'] + }, { + 'key': 'singleValNum', + 'value': ['123'] + }, { + 'key': 'emptyStr' + }, { + 'key': 'emptyArr' + }]); + }); + + it('should attach rtd segments as keywords', function () { + const bidRequestWithKeywords = [].concat(bidRequests); + bidRequestWithKeywords[1] = Object.assign({}, + bidRequests[1], + { + rtd: { + p_standard: { + targeting: { + segments: ['perm_seg_1', 'perm_seg_2'] + } + }, + jwplayer: { + targeting: { + segments: ['jwp_seg_1', 'jwp_seg_2'] + } + } + } + } + ); + + const request = spec.buildRequests(bidRequestWithKeywords, bidderRequest)[0]; + expect(request.data).to.be.an('string'); + const payload = parseRequest(request.data); + expect(payload.keywords).to.be.an('string'); + payload.keywords = JSON.parse(payload.keywords); + + expect(payload.keywords).to.deep.equal([{ + 'key': 'jwpseg', + 'value': ['jwp_seg_1', 'jwp_seg_2'] + }, { + 'key': 'p_standard', + 'value': ['perm_seg_1', 'perm_seg_2'] + }]); + }); + }); + + describe('buildRequests with new format', function () { function parseRequest(data) { return JSON.parse(data); } @@ -57,6 +280,7 @@ describe('TrustXAdapter', function () { 'params': { 'uid': '43', 'bidFloor': 1.25, + 'useNewFormat': true }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], @@ -73,6 +297,7 @@ describe('TrustXAdapter', function () { 'bidder': 'trustx', 'params': { 'uid': '44', + 'useNewFormat': true }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], @@ -84,6 +309,7 @@ describe('TrustXAdapter', function () { 'bidder': 'trustx', 'params': { 'uid': '45', + 'useNewFormat': true }, 'adUnitCode': 'adunit-code-2', 'sizes': [[728, 90]], @@ -101,6 +327,7 @@ describe('TrustXAdapter', function () { 'bidder': 'trustx', 'params': { 'uid': '41', + 'useNewFormat': true }, 'adUnitCode': 'adunit-code-2', 'sizes': [[728, 90]], @@ -120,7 +347,7 @@ describe('TrustXAdapter', function () { ]; it('should attach valid params to the tag', function () { - const request = spec.buildRequests([bidRequests[0]], bidderRequest); + const request = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.deep.equal({ @@ -148,7 +375,7 @@ describe('TrustXAdapter', function () { }); it('make possible to process request without mediaTypes', function () { - const request = spec.buildRequests([bidRequests[0], bidRequests[1]], bidderRequest); + const request = spec.buildRequests([bidRequests[0], bidRequests[1]], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.deep.equal({ @@ -185,7 +412,7 @@ describe('TrustXAdapter', function () { }); it('should attach valid params to the video tag', function () { - const request = spec.buildRequests(bidRequests.slice(0, 3), bidderRequest); + const request = spec.buildRequests(bidRequests.slice(0, 3), bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.deep.equal({ @@ -231,7 +458,7 @@ describe('TrustXAdapter', function () { }); it('should support mixed mediaTypes', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.deep.equal({ @@ -292,7 +519,7 @@ describe('TrustXAdapter', function () { it('if gdprConsent is present payload must have gdpr params', function () { const gdprBidderRequest = Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: true}}, bidderRequest); - const request = spec.buildRequests(bidRequests, gdprBidderRequest); + const request = spec.buildRequests(bidRequests, gdprBidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('user'); @@ -305,7 +532,7 @@ describe('TrustXAdapter', function () { it('if usPrivacy is present payload must have us_privacy param', function () { const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); + const request = spec.buildRequests(bidRequests, bidderRequestWithUSP)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('regs'); @@ -338,7 +565,7 @@ describe('TrustXAdapter', function () { userIdAsEids: eids }, bid); }); - const request = spec.buildRequests(bidRequestsWithUserIds, bidderRequest); + const request = spec.buildRequests(bidRequestsWithUserIds, bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('user'); @@ -362,7 +589,7 @@ describe('TrustXAdapter', function () { schain: schain }, bid); }); - const request = spec.buildRequests(bidRequestsWithSChain, bidderRequest); + const request = spec.buildRequests(bidRequestsWithSChain, bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('source'); @@ -386,7 +613,7 @@ describe('TrustXAdapter', function () { } }, bid); }); - const request = spec.buildRequests(bidRequestsWithJwTargeting, bidderRequest); + const request = spec.buildRequests(bidRequestsWithJwTargeting, bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('user'); @@ -402,7 +629,7 @@ describe('TrustXAdapter', function () { }); it('if segment is present in permutive targeting, payload must have right params', function () { - const permSegments = [{id: 'test_perm_1'}, {id: 'test_perm_2'}]; + const permSegments = ['test_perm_1', 'test_perm_2']; const bidRequestsWithPermutiveTargeting = bidRequests.map((bid) => { return Object.assign({ rtd: { @@ -414,97 +641,33 @@ describe('TrustXAdapter', function () { } }, bid); }); - const request = spec.buildRequests(bidRequestsWithPermutiveTargeting, bidderRequest); + const request = spec.buildRequests(bidRequestsWithPermutiveTargeting, bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload).to.have.property('user'); expect(payload.user.data).to.deep.equal([{ name: 'permutive', segment: [ - {name: 'p_standard', value: permSegments[0].id}, - {name: 'p_standard', value: permSegments[1].id} + {name: 'p_standard', value: permSegments[0]}, + {name: 'p_standard', value: permSegments[1]} ] }]); }); it('should contain the keyword values if it present in ortb2.(site/user)', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( - arg => arg === 'ortb2.user' ? {'keywords': 'foo,any'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null)); - const keywords = { - 'site': { - 'somePublisher': [ - { - 'name': 'someName', - 'brandsafety': ['disaster'], - 'topic': ['stress', 'fear'] - } - ] - }, - 'user': { - 'formatedPublisher': [ - { - 'name': 'fomatedName', - 'segments': [ - { 'name': 'segName1', 'value': 'segVal1' }, - { 'name': 'segName2', 'value': 'segVal2' } - ] - } - ] - } - }; - const bidRequestWithKW = { ...bidRequests[0], params: { ...bidRequests[0].params, keywords } } - const request = spec.buildRequests([bidRequestWithKW], bidderRequest); + arg => arg === 'ortb2.user' ? {'keywords': 'foo'} : (arg === 'ortb2.site' ? {'keywords': 'bar'} : null)); + const request = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); - expect(payload.ext.keywords).to.deep.equal({ - 'site': { - 'somePublisher': [ - { - 'name': 'someName', - 'segments': [ - { 'name': 'brandsafety', 'value': 'disaster' }, - { 'name': 'topic', 'value': 'stress' }, - { 'name': 'topic', 'value': 'fear' } - ] - } - ], - 'ortb2': [ - { - 'name': 'keywords', - 'segments': [ - { 'name': 'keywords', 'value': 'bar' } - ] - } - ] - }, - 'user': { - 'formatedPublisher': [ - { - 'name': 'fomatedName', - 'segments': [ - { 'name': 'segName1', 'value': 'segVal1' }, - { 'name': 'segName2', 'value': 'segVal2' } - ] - } - ], - 'ortb2': [ - { - 'name': 'keywords', - 'segments': [ - { 'name': 'keywords', 'value': 'foo' }, - { 'name': 'keywords', 'value': 'any' } - ] - } - ] - } - }); + expect(payload.ext.keywords).to.deep.equal([{'key': 'user', 'value': ['foo']}, {'key': 'context', 'value': ['bar']}]); getConfigStub.restore(); }); it('shold be right tmax when timeout in config is less then timeout in bidderRequest', function() { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'bidderTimeout' ? 2000 : null); - const request = spec.buildRequests([bidRequests[0]], bidderRequest); + const request = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload.tmax).to.equal(2000); @@ -513,99 +676,12 @@ describe('TrustXAdapter', function () { it('shold be right tmax when timeout in bidderRequest is less then timeout in config', function() { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'bidderTimeout' ? 5000 : null); - const request = spec.buildRequests([bidRequests[0]], bidderRequest); + const request = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload.tmax).to.equal(3000); getConfigStub.restore(); }); - it('should contain imp[].ext.data.adserver if available', function() { - const ortb2Imp = [{ - ext: { - data: { - adserver: { - name: 'ad_server_name', - adslot: '/111111/slot' - }, - pbadslot: '/111111/slot' - } - } - }, { - ext: { - data: { - adserver: { - name: 'ad_server_name', - adslot: '/222222/slot' - }, - pbadslot: '/222222/slot' - } - } - }]; - const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 3).map((bid, ind) => { - return Object.assign(ortb2Imp[ind] ? { ortb2Imp: ortb2Imp[ind] } : {}, bid); - }); - const request = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].ext).to.deep.equal({ - divid: bidRequests[0].adUnitCode, - data: ortb2Imp[0].ext.data, - gpid: ortb2Imp[0].ext.data.adserver.adslot - }); - expect(payload.imp[1].ext).to.deep.equal({ - divid: bidRequests[1].adUnitCode, - data: ortb2Imp[1].ext.data, - gpid: ortb2Imp[1].ext.data.adserver.adslot - }); - expect(payload.imp[2].ext).to.deep.equal({ - divid: bidRequests[2].adUnitCode - }); - }); - it('all id like request fields must be a string', function () { - const bidderRequestWithNumId = Object.assign({}, bidderRequest, { bidderRequestId: 123123, auctionId: 345345543 }); - - let bidRequestWithNumId = { - 'bidder': 'trustx', - 'params': { - 'uid': 43, - }, - 'adUnitCode': 111111, - 'sizes': [[300, 250], [300, 600]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': 23423423, - 'bidderRequestId': 123123, - 'auctionId': 345345543, - }; - - const request = spec.buildRequests([bidRequestWithNumId], bidderRequestWithNumId); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': '123123', - 'site': { - 'page': referrer - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': '345345543', - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'imp': [{ - 'id': '23423423', - 'tagid': '43', - 'ext': {'divid': '111111'}, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }] - }); - }); describe('floorModule', function () { const floorTestData = { @@ -618,7 +694,7 @@ describe('TrustXAdapter', function () { } }, bidRequests[1]); it('should return the value from getFloor if present', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); + const request = spec.buildRequests([bidRequest], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload.imp[0].bidfloor).to.equal(floorTestData.floor); @@ -627,7 +703,7 @@ describe('TrustXAdapter', function () { const bidfloor = 0.80; const bidRequestsWithFloor = { ...bidRequest }; bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params); - const request = spec.buildRequests([bidRequestsWithFloor], bidderRequest); + const request = spec.buildRequests([bidRequestsWithFloor], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload.imp[0].bidfloor).to.equal(floorTestData.floor); @@ -636,7 +712,7 @@ describe('TrustXAdapter', function () { const bidfloor = 1.80; const bidRequestsWithFloor = { ...bidRequest }; bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params); - const request = spec.buildRequests([bidRequestsWithFloor], bidderRequest); + const request = spec.buildRequests([bidRequestsWithFloor], bidderRequest)[0]; expect(request.data).to.be.an('string'); const payload = parseRequest(request.data); expect(payload.imp[0].bidfloor).to.equal(bidfloor); @@ -646,10 +722,10 @@ describe('TrustXAdapter', function () { describe('interpretResponse', function () { const responses = [ - {'bid': [{'impid': '659423fff799cb', 'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300, 'adomain': ['somedomain.com']}], 'seat': '1'}, - {'bid': [{'impid': '4dff80cc4ee346', 'price': 0.5, 'adm': '
test content 2
', 'auid': 44, 'h': 600, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '5703af74d0472a', 'price': 0.15, 'adm': '
test content 3
', 'auid': 43, 'h': 90, 'w': 728}], 'seat': '1'}, - {'bid': [{'impid': '659423faac49cb', 'price': 0, 'auid': 45, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300, 'adomain': ['somedomain.com']}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 44, 'h': 600, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 3
', 'auid': 43, 'h': 90, 'w': 728}], 'seat': '1'}, + {'bid': [{'price': 0, 'auid': 45, 'h': 250, 'w': 300}], 'seat': '1'}, {'bid': [{'price': 0, 'adm': '
test content 5
', 'h': 250, 'w': 300}], 'seat': '1'}, undefined, {'bid': [], 'seat': '1'}, @@ -670,7 +746,7 @@ describe('TrustXAdapter', function () { 'auctionId': '1cbd2feafe5e8b', } ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { 'requestId': '659423fff799cb', @@ -682,7 +758,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 1
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': ['somedomain.com'] @@ -703,7 +779,7 @@ describe('TrustXAdapter', function () { }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], - 'bidId': '659423fff799cb', + 'bidId': '300bfeb0d71a5b', 'bidderRequestId': '2c2bb1972df9a', 'auctionId': '1fa09aee5c8c99', }, @@ -730,10 +806,10 @@ describe('TrustXAdapter', function () { 'auctionId': '1fa09aee5c8c99', } ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { - 'requestId': '659423fff799cb', + 'requestId': '300bfeb0d71a5b', 'cpm': 1.15, 'creativeId': 43, 'dealId': undefined, @@ -742,7 +818,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 1
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': ['somedomain.com'] @@ -758,7 +834,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 2
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -774,7 +850,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 3
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -822,18 +898,18 @@ describe('TrustXAdapter', function () { 'auctionId': '1fa09aee5c84d34', } ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const result = spec.interpretResponse({'body': {'seatbid': responses.slice(3)}}, request); expect(result.length).to.equal(0); }); it('complicated case', function () { const fullResponse = [ - {'bid': [{'impid': '2164be6358b9', 'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '4e111f1b66e4', 'price': 0.5, 'adm': '
test content 2
', 'auid': 44, 'h': 600, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '26d6f897b516', 'price': 0.15, 'adm': '
test content 3
', 'auid': 43, 'h': 90, 'w': 728}], 'seat': '1'}, - {'bid': [{'impid': '326bde7fbf69', 'price': 0.15, 'adm': '
test content 4
', 'auid': 43, 'h': 600, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '1751cd90161', 'price': 0.5, 'adm': '
test content 5
', 'auid': 44, 'h': 600, 'w': 350}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 44, 'h': 600, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 3
', 'auid': 43, 'h': 90, 'w': 728}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 4
', 'auid': 43, 'h': 600, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 5
', 'auid': 44, 'h': 600, 'w': 350}], 'seat': '1'}, ]; const bidRequests = [ { @@ -892,7 +968,7 @@ describe('TrustXAdapter', function () { 'auctionId': '32a1f276cb87cb8', } ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { 'requestId': '2164be6358b9', @@ -904,7 +980,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 1
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -920,7 +996,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 2
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -936,7 +1012,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 3
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -952,23 +1028,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 4
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, - 'ttl': 360, - 'meta': { - 'advertiserDomains': [] - }, - }, - { - 'requestId': '1751cd90161', - 'cpm': 0.5, - 'creativeId': 44, - 'dealId': undefined, - 'width': 350, - 'height': 600, - 'ad': '
test content 5
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -982,8 +1042,8 @@ describe('TrustXAdapter', function () { it('dublicate uids and sizes in one slot', function () { const fullResponse = [ - {'bid': [{'impid': '5126e301f4be', 'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '57b2ebe70e16', 'price': 0.5, 'adm': '
test content 2
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 43, 'h': 250, 'w': 300}], 'seat': '1'}, ]; const bidRequests = [ { @@ -1020,7 +1080,7 @@ describe('TrustXAdapter', function () { 'auctionId': '35bcbc0f7e79c', } ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { 'requestId': '5126e301f4be', @@ -1032,7 +1092,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 1
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -1048,7 +1108,7 @@ describe('TrustXAdapter', function () { 'ad': '
test content 2
', 'currency': 'USD', 'mediaType': 'banner', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -1094,30 +1154,13 @@ describe('TrustXAdapter', function () { 'context': 'instream' } } - }, - { - 'bidder': 'trustx', - 'params': { - 'uid': '52' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '23312a43bc42', - 'bidderRequestId': '20394420a762a2', - 'auctionId': '140132d07b031', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } } ]; const response = [ - {'bid': [{'impid': '57dfefb80eca', 'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 50, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, - {'bid': [{'impid': '5126e301f4be', 'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 51, content_type: 'video'}], 'seat': '2'}, - {'bid': [{'impid': '23312a43bc42', 'price': 2.00, 'nurl': 'https://some_test_vast_url.com', 'auid': 52, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, + {'bid': [{'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 50, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, + {'bid': [{'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 51, content_type: 'video'}], 'seat': '2'} ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { 'requestId': '57dfefb80eca', @@ -1128,7 +1171,7 @@ describe('TrustXAdapter', function () { 'height': 600, 'currency': 'USD', 'mediaType': 'video', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -1137,23 +1180,7 @@ describe('TrustXAdapter', function () { 'adResponse': { 'content': '\n<\/Ad>\n<\/VAST>' } - }, - { - 'requestId': '23312a43bc42', - 'cpm': 2.00, - 'creativeId': 52, - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'currency': 'USD', - 'mediaType': 'video', - 'netRevenue': false, - 'ttl': 360, - 'meta': { - 'advertiserDomains': [] - }, - 'vastUrl': 'https://some_test_vast_url.com', - }, + } ]; const result = spec.interpretResponse({'body': {'seatbid': response}}, request); @@ -1211,11 +1238,11 @@ describe('TrustXAdapter', function () { } ]; const response = [ - {'bid': [{'impid': 'e6e65553fc8', 'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 50, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, - {'bid': [{'impid': 'c8fdcb3f269f', 'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 51, content_type: 'video', w: 300, h: 250}], 'seat': '2'}, - {'bid': [{'impid': '1de036c37685', 'price': 1.20, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 52, content_type: 'video', w: 300, h: 250}], 'seat': '2'} + {'bid': [{'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 50, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, + {'bid': [{'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 51, content_type: 'video', w: 300, h: 250}], 'seat': '2'}, + {'bid': [{'price': 1.20, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 52, content_type: 'video', w: 300, h: 250}], 'seat': '2'} ]; - const request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests)[0]; const expectedResponse = [ { 'requestId': 'e6e65553fc8', @@ -1226,7 +1253,7 @@ describe('TrustXAdapter', function () { 'height': 600, 'currency': 'USD', 'mediaType': 'video', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -1246,7 +1273,7 @@ describe('TrustXAdapter', function () { 'height': 250, 'currency': 'USD', 'mediaType': 'video', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] @@ -1266,7 +1293,7 @@ describe('TrustXAdapter', function () { 'height': 250, 'currency': 'USD', 'mediaType': 'video', - 'netRevenue': false, + 'netRevenue': true, 'ttl': 360, 'meta': { 'advertiserDomains': [] diff --git a/test/spec/modules/undertoneBidAdapter_spec.js b/test/spec/modules/undertoneBidAdapter_spec.js index 56217fe3561..0faa321be5f 100644 --- a/test/spec/modules/undertoneBidAdapter_spec.js +++ b/test/spec/modules/undertoneBidAdapter_spec.js @@ -60,23 +60,6 @@ const videoBidReq = [{ bidId: '263be71e91dd9d', auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' }]; -const schainObj = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 2 - } - ] -}; const bidReq = [{ adUnitCode: 'div-gpt-ad-1460505748561-0', bidder: BIDDER_CODE, @@ -89,29 +72,6 @@ const bidReq = [{ auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' }, { - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - publisherId: 12345 - }, - sizes: [[1, 1]], - bidId: '453cf42d72bb3c', - auctionId: '6c22f5a5-59df-4dc6-b92c-f433bcf0a874', - schain: schainObj -}]; - -const supplyChainedBidReqs = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345, - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', - schain: schainObj -}, { adUnitCode: 'div-gpt-ad-1460505748561-0', bidder: BIDDER_CODE, params: { @@ -276,18 +236,6 @@ describe('Undertone Adapter', () => { sandbox.restore(); }); - describe('supply chain', function () { - it('should send supply chain if found on first bid', function () { - const request = spec.buildRequests(supplyChainedBidReqs, bidderReq); - const commons = JSON.parse(request.data)['commons']; - expect(commons.schain).to.deep.equal(schainObj); - }); - it('should not send supply chain if not found on first bid', function () { - const request = spec.buildRequests(bidReq, bidderReq); - const commons = JSON.parse(request.data)['commons']; - expect(commons.schain).to.not.exist; - }); - }); it('should send request to correct url via POST not in GDPR or CCPA', function () { const request = spec.buildRequests(bidReq, bidderReq); const domainStart = bidderReq.refererInfo.referer.indexOf('//'); diff --git a/test/spec/modules/unicornBidAdapter_spec.js b/test/spec/modules/unicornBidAdapter_spec.js index 1ab428d58b6..615eac2ecf2 100644 --- a/test/spec/modules/unicornBidAdapter_spec.js +++ b/test/spec/modules/unicornBidAdapter_spec.js @@ -332,14 +332,14 @@ const openRTBRequest = { tagid: 'rectangle-ad-2' } ], - cur: ['JPY'], + cur: 'JPY', ext: { accountId: 12345 }, site: { id: 'example', publisher: { - id: '99999' + id: 99999 }, domain: 'uni-corn.net', page: 'https://uni-corn.net/', @@ -357,7 +357,7 @@ const openRTBRequest = { ext: { stype: 'prebid_uncn', bidder: 'unicorn', - prebid_version: '1.1' + prebid_version: '1.0' } } }; @@ -444,7 +444,7 @@ const serverResponse = { const request = { method: 'POST', url: 'https://ds.uncn.jp/pb/0/bid.json', - data: '{"id":"5ebea288-f13a-4754-be6d-4ade66c68877","at":1,"imp":[{"id":"216255f234b602","banner":{"w":300,"h":250},"format":[{"w":300,"h":250},{"w":336,"h":280}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-0"},{"id":"31e2b28ced2475","banner":{"w":"300","h":"250"},"format":[{"w":"300","h":"250"}],"secure":1,"bidfloor":0"tagid":"/19968336/header-bid-tag-1"},{"id":"40a333e047a9bd","banner":{"w":300,"h":250},"format":[{"w":300,"h":250}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-2"}],"cur":"JPY","site":{"id":"uni-corn.net","publisher":{"id":12345},"domain":"uni-corn.net","page":"https://uni-corn.net/","ref":"https://uni-corn.net/"},"device":{"language":"ja","ua":"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36"},"user":{"id":"69d9e1c2-801e-4901-a665-fad467550fec"},"bcat":[],"source":{"ext":{"stype":"prebid_uncn","bidder":"unicorn","prebid_version":"1.1"}}}' + data: '{"id":"5ebea288-f13a-4754-be6d-4ade66c68877","at":1,"imp":[{"id":"216255f234b602","banner":{"w":300,"h":250},"format":[{"w":300,"h":250},{"w":336,"h":280}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-0"},{"id":"31e2b28ced2475","banner":{"w":"300","h":"250"},"format":[{"w":"300","h":"250"}],"secure":1,"bidfloor":0"tagid":"/19968336/header-bid-tag-1"},{"id":"40a333e047a9bd","banner":{"w":300,"h":250},"format":[{"w":300,"h":250}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-2"}],"cur":"JPY","site":{"id":"uni-corn.net","publisher":{"id":12345},"domain":"uni-corn.net","page":"https://uni-corn.net/","ref":"https://uni-corn.net/"},"device":{"language":"ja","ua":"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36"},"user":{"id":"69d9e1c2-801e-4901-a665-fad467550fec"},"bcat":[],"source":{"ext":{"stype":"prebid_uncn","bidder":"unicorn","prebid_version":"1.0"}}}' }; const interpretedBids = [ diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index 8ddb02138f5..0190bceca70 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -49,8 +49,6 @@ import {flocIdSubmodule} from 'modules/flocIdSystem.js' import {amxIdSubmodule} from '../../../modules/amxIdSystem.js'; import {akamaiDAPIdSubmodule} from 'modules/akamaiDAPIdSystem.js' import {kinessoIdSubmodule} from 'modules/kinessoIdSystem.js' -import {adqueryIdSubmodule} from 'modules/adqueryIdSystem.js'; -import * as mockGpt from '../integration/faker/googletag.js'; let assert = require('chai').assert; let expect = require('chai').expect; @@ -116,21 +114,15 @@ describe('User ID', function () { describe('Decorate Ad Units', function () { beforeEach(function () { - // reset mockGpt so nothing else interferes - mockGpt.disable(); - mockGpt.enable(); coreStorage.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); coreStorage.setCookie('pubcid_alt', 'altpubcid200000', (new Date(Date.now() + 5000).toUTCString())); sinon.spy(coreStorage, 'setCookie'); - sinon.stub(utils, 'logWarn'); }); afterEach(function () { - mockGpt.enable(); $$PREBID_GLOBAL$$.requestBids.removeAll(); config.resetConfig(); coreStorage.setCookie.restore(); - utils.logWarn.restore(); }); after(function () { @@ -329,50 +321,6 @@ describe('User ID', function () { expect((getGlobal()).getUserIdsAsEids()).to.deep.equal(createEidsArray((getGlobal()).getUserIds())); }); - it('should set googletag ppid correctly', function () { - let adUnits = [getAdUnitMock()]; - setSubmoduleRegistry([amxIdSubmodule, sharedIdSystemSubmodule, identityLinkSubmodule]); - init(config); - - config.setConfig({ - userSync: { - ppid: 'pubcid.org', - userIds: [ - { name: 'amxId', value: {'amxId': 'amx-id-value-amx-id-value-amx-id-value'} }, - { name: 'pubCommonId', value: {'pubcid': 'pubCommon-id-value-pubCommon-id-value'} }, - { name: 'identityLink', value: {'idl_env': 'identityLink-id-value-identityLink-id-value'} }, - ] - } - }); - // before ppid should not be set - expect(window.googletag._ppid).to.equal(undefined); - requestBidsHook(() => {}, {adUnits}); - // ppid should have been set without dashes and stuff - expect(window.googletag._ppid).to.equal('pubCommonidvaluepubCommonidvalue'); - }); - - it('should log a warning if PPID too big or small', function () { - let adUnits = [getAdUnitMock()]; - setSubmoduleRegistry([sharedIdSystemSubmodule]); - init(config); - - config.setConfig({ - userSync: { - ppid: 'pubcid.org', - userIds: [ - { name: 'pubCommonId', value: {'pubcid': 'pubcommonIdValue'} }, - ] - } - }); - // before ppid should not be set - expect(window.googletag._ppid).to.equal(undefined); - requestBidsHook(() => {}, {adUnits}); - // ppid should NOT have been set - expect(window.googletag._ppid).to.equal(undefined); - // a warning should have been emmited - expect(utils.logWarn.args[0][0]).to.exist.and.to.contain('User ID - Googletag Publisher Provided ID for pubcid.org is not between 32 and 150 characters - pubcommonIdValue'); - }); - it('pbjs.refreshUserIds refreshes', function() { let sandbox = sinon.createSandbox(); @@ -560,7 +508,7 @@ describe('User ID', function () { }); it('handles config with no usersync object', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({}); // usersync is undefined, and no logInfo message for 'User ID - usersync config updated' @@ -568,14 +516,14 @@ describe('User ID', function () { }); it('handles config with empty usersync object', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({userSync: {}}); expect(typeof utils.logInfo.args[0]).to.equal('undefined'); }); it('handles config with usersync and userIds that are empty objs', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ userSync: { @@ -586,7 +534,7 @@ describe('User ID', function () { }); it('handles config with usersync and userIds with empty names or that dont match a submodule.name', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, merkleIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ userSync: { @@ -603,7 +551,7 @@ describe('User ID', function () { }); it('config with 1 configurations should create 1 submodules', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig(getConfigMock(['unifiedId', 'unifiedid', 'cookie'])); @@ -624,8 +572,8 @@ describe('User ID', function () { expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 1 submodules'); }); - it('config with 24 configurations should result in 24 submodules add', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, liveIntentIdSubmodule, britepoolIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + it('config with 23 configurations should result in 23 submodules add', function () { + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, liveIntentIdSubmodule, britepoolIdSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ userSync: { @@ -690,17 +638,14 @@ describe('User ID', function () { }, { name: 'kpuid', storage: {name: 'kpuid', type: 'cookie'} - }, { - name: 'qid', - storage: {name: 'qid', type: 'html5'} }] } }); - expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 24 submodules'); + expect(utils.logInfo.args[0][0]).to.exist.and.to.contain('User ID - usersync config updated for 23 submodules'); }); it('config syncDelay updates module correctly', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ @@ -716,7 +661,7 @@ describe('User ID', function () { }); it('config auctionDelay updates module correctly', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ userSync: { @@ -731,7 +676,7 @@ describe('User ID', function () { }); it('config auctionDelay defaults to 0 if not a number', function () { - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, netIdSubmodule, nextrollIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, pubProvidedIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, flocIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ userSync: { @@ -1827,38 +1772,7 @@ describe('User ID', function () { }, {adUnits}); }); - it('test hook from qid html5', (done) => { - // simulate existing localStorage values - localStorage.setItem('qid', 'testqid'); - localStorage.setItem('qid_exp', ''); - - setSubmoduleRegistry([adqueryIdSubmodule]); - init(config); - config.setConfig(getConfigMock(['qid', 'qid', 'html5'])); - - requestBidsHook(() => { - adUnits.forEach((adUnit) => { - adUnit.bids.forEach((bid) => { - expect(bid).to.have.deep.nested.property('userId.qid'); - expect(bid.userId.qid).to.equal('testqid'); - expect(bid.userIdAsEids[0]).to.deep.equal({ - source: 'adquery.io', - uids: [{ - id: 'testqid', - atype: 1, - }] - }); - }); - }); - - // clear LS - localStorage.removeItem('qid'); - localStorage.removeItem('qid_exp'); - done(); - }, {adUnits}); - }); - - it('test hook when pubCommonId, unifiedId, id5Id, identityLink, britepoolId, intentIqId, zeotapIdPlus, netId, haloId, Criteo, UID 2.0, admixerId, amxId, dmdId, kpuid, qid and mwOpenLinkId have data to pass', function (done) { + it('test hook when pubCommonId, unifiedId, id5Id, identityLink, britepoolId, intentIqId, zeotapIdPlus, netId, haloId, Criteo, UID 2.0, admixerId, amxId, dmdId, kpuid and mwOpenLinkId have data to pass', function (done) { coreStorage.setCookie('pubcid', 'testpubcid', (new Date(Date.now() + 5000).toUTCString())); coreStorage.setCookie('unifiedid', JSON.stringify({'TDID': 'testunifiedid'}), (new Date(Date.now() + 5000).toUTCString())); coreStorage.setCookie('id5id', JSON.stringify({'universal_uid': 'testid5id'}), (new Date(Date.now() + 5000).toUTCString())); @@ -1875,13 +1789,12 @@ describe('User ID', function () { coreStorage.setCookie('admixerId', 'testadmixerId', (new Date(Date.now() + 5000).toUTCString())); coreStorage.setCookie('deepintentId', 'testdeepintentId', (new Date(Date.now() + 5000).toUTCString())); coreStorage.setCookie('kpuid', 'KINESSO_ID', (new Date(Date.now() + 5000).toUTCString())); + // amxId only supports localStorage localStorage.setItem('amxId', 'test_amxid_id'); localStorage.setItem('amxId_exp', (new Date(Date.now() + 5000)).toUTCString()); - // qid only supports localStorage - localStorage.setItem('qid', 'testqid'); - localStorage.setItem('qid_exp', (new Date(Date.now() + 5000)).toUTCString()); - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, criteoIdSubmodule, mwOpenLinkIdSubModule, tapadIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig(getConfigMock(['pubCommonId', 'pubcid', 'cookie'], ['unifiedId', 'unifiedid', 'cookie'], @@ -1900,8 +1813,7 @@ describe('User ID', function () { ['admixerId', 'admixerId', 'cookie'], ['amxId', 'amxId', 'html5'], ['deepintentId', 'deepintentId', 'cookie'], - ['kpuid', 'kpuid', 'cookie'], - ['qid', 'qid', 'html5'])); + ['kpuid', 'kpuid', 'cookie'])); requestBidsHook(function () { adUnits.forEach(unit => { @@ -1959,10 +1871,7 @@ describe('User ID', function () { expect(bid).to.have.deep.nested.property('userId.kpuid'); expect(bid.userId.kpuid).to.equal('KINESSO_ID'); - expect(bid).to.have.deep.nested.property('userId.qid'); - expect(bid.userId.qid).to.equal('testqid'); - - expect(bid.userIdAsEids.length).to.equal(18); + expect(bid.userIdAsEids.length).to.equal(17); }); }); coreStorage.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); @@ -1983,8 +1892,6 @@ describe('User ID', function () { coreStorage.setCookie('kpuid', EXPIRED_COOKIE_DATE); localStorage.removeItem('amxId'); localStorage.removeItem('amxId_exp'); - localStorage.removeItem('qid'); - localStorage.removeItem('qid_exp'); done(); }, {adUnits}); }); @@ -2174,10 +2081,8 @@ describe('User ID', function () { localStorage.setItem('amxId', 'test_amxid_id'); localStorage.setItem('amxId_exp', new Date(Date.now() + 5000).toUTCString()) coreStorage.setCookie('kpuid', 'KINESSO_ID', (new Date(Date.now() + 5000).toUTCString())); - localStorage.setItem('qid', 'testqid'); - localStorage.setItem('qid_exp', new Date(Date.now() + 5000).toUTCString()) - setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule, adqueryIdSubmodule]); + setSubmoduleRegistry([sharedIdSystemSubmodule, unifiedIdSubmodule, id5IdSubmodule, identityLinkSubmodule, britepoolIdSubmodule, netIdSubmodule, intentIqIdSubmodule, zeotapIdPlusSubmodule, haloIdSubmodule, uid2IdSubmodule, admixerIdSubmodule, deepintentDpesSubmodule, dmdIdSubmodule, akamaiDAPIdSubmodule, amxIdSubmodule, kinessoIdSubmodule]); init(config); config.setConfig({ @@ -2215,8 +2120,6 @@ describe('User ID', function () { name: 'amxId', storage: {name: 'amxId', type: 'html5'} }, { name: 'kpuid', storage: {name: 'kpuid', type: 'cookie'} - }, { - name: 'qid', storage: {name: 'qid', type: 'html5'} }] } }); @@ -2288,10 +2191,7 @@ describe('User ID', function () { expect(bid).to.have.deep.nested.property('userId.kpuid'); expect(bid.userId.kpuid).to.equal('KINESSO_ID'); - - expect(bid).to.have.deep.nested.property('userId.qid'); - expect(bid.userId.qid).to.equal('testqid'); - expect(bid.userIdAsEids.length).to.equal(16); + expect(bid.userIdAsEids.length).to.equal(15); }); }); coreStorage.setCookie('pubcid', '', EXPIRED_COOKIE_DATE); diff --git a/test/spec/modules/validationFpdModule_spec.js b/test/spec/modules/validationFpdModule_spec.js index b60360733d6..9e8072cb9ed 100644 --- a/test/spec/modules/validationFpdModule_spec.js +++ b/test/spec/modules/validationFpdModule_spec.js @@ -309,87 +309,5 @@ describe('the first party data validation module', function () { validated = validateFpd(duplicate); expect(validated).to.deep.equal(expected); }); - - it('filters bcat, badv for invalid data type', function () { - const duplicate = utils.deepClone(ortb2); - duplicate.badv = 'adadadbcd.com'; - duplicate.bcat = ['IAB25', 'IAB7-39']; - - const expected = { - device: { - h: 911, - w: 1733 - }, - user: { - data: [{ - segment: [{ - id: 'foo' - }], - name: 'bar' - }] - }, - site: { - content: { - data: [{ - segment: [{ - id: 'test' - }], - name: 'content', - ext: { - foo: 'bar' - } - }] - } - }, - bcat: ['IAB25', 'IAB7-39'] - }; - - const validated = validateFpd(duplicate); - expect(validated).to.deep.equal(expected); - }); - - it('filters site.publisher object properties for invalid data type', function () { - const duplicate = utils.deepClone(ortb2); - duplicate.site.publisher = { - id: '1', - domain: ['xyz.com'], - name: 'xyz', - }; - - const expected = { - device: { - h: 911, - w: 1733 - }, - user: { - data: [{ - segment: [{ - id: 'foo' - }], - name: 'bar' - }] - }, - site: { - content: { - data: [{ - segment: [{ - id: 'test' - }], - name: 'content', - ext: { - foo: 'bar' - } - }] - }, - publisher: { - id: '1', - name: 'xyz', - } - } - }; - - const validated = validateFpd(duplicate); - expect(validated).to.deep.equal(expected); - }); }); }); diff --git a/test/spec/modules/ventesBidAdapter_spec.js b/test/spec/modules/ventesBidAdapter_spec.js deleted file mode 100644 index 219c24deced..00000000000 --- a/test/spec/modules/ventesBidAdapter_spec.js +++ /dev/null @@ -1,845 +0,0 @@ -import { expect } from 'chai'; -import * as utils from 'src/utils.js'; -import { spec } from 'modules/ventesBidAdapter.js'; - -const BIDDER_URL = 'http://13.234.201.146:8088/va/ad'; - -describe('Ventes Adapter', function () { - const examples = { - adUnit_banner: { - adUnitCode: 'ad_unit_banner', - bidder: 'ventes', - bidderRequestId: 'bid_request_id', - bidId: 'bid_id', - params: { - publisherId: 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV', - placementId: 'VA-062-0013-0183', - device: { - ip: '123.145.167.189', - ifa: 'AEBE52E7-03EE-455A-B3C4-E57283966239', - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }, - - adUnitContext: { - refererInfo: { - referer: 'https://ventesavenues.in', - } - }, - - serverRequest_banner: { - method: 'POST', - url: 'http://13.234.201.146:8088/va/ad', - data: { - id: 'bid_request_id', - imp: [ - { - id: 'imp_id_banner', - banner: { - format: [{ - w: 300, - h: 200 - }] - } - } - ], - site: { - page: 'https://ventesavenues.in', - domain: 'ventesavenues.in', - name: 'ventesavenues.in' - }, - device: { - ua: '', - ip: '123.145.167.189', - ifa: 'AEBE52E7-03EE-455A-B3C4-E57283966239', - language: 'en' - }, - user: null, - regs: null, - at: 1 - } - }, - serverResponse_banner: { - body: { - cur: 'USD', - seatbid: [ - { - seat: '4', - bid: [ - { - id: 'id', - impid: 'imp_id_banner', - cid: 'campaign_id', - crid: 'creative_id', - adm: '..', - price: 1.5, - w: 300, - h: 200 - } - ] - } - ] - } - } - }; - - describe('isBidRequestValid', function () { - describe('General', function () { - it('should return false when not given an ad unit', function () { - const adUnit = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an invalid ad unit', function () { - const adUnit = 'bad_bid'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without bidder code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidder = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a bad bidder code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidder = 'unknownBidder'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without ad unit code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.adUnitCode = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid ad unit code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.adUnitCode = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without bid request identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidderRequestId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid bid request identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidderRequestId = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without impression identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid impression identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidId = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with empty media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with invalid media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = 'bad_media_types'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - }); - - describe('Banner', function () { - it('should return true when given a valid ad unit', function () { - const adUnit = examples.adUnit_banner; - - expect(spec.isBidRequestValid(adUnit)).to.equal(true); - }); - - it('should return true when given a valid ad unit with invalid publisher id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return true when given a valid ad unit without placement id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return true when given a valid ad unit with invalid placement id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV'; - adUnit.params.placementId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = 'bad_banner_size'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an empty size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = []; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid size value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = ['bad_banner_size_value']; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a size value with less than 2 dimensions', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a size value with more than 2 dimensions', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, 250, 30]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a negative width value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[-300, 250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a negative height value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, -250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid width value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[false, 250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid height value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, {}]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - }); - }); - - describe('buildRequests', function () { - describe('ServerRequest', function () { - it('should return a server request when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - expect(serverRequests[0].method).to.exist.and.to.be.a('string').and.to.equal('POST'); - expect(serverRequests[0].url).to.exist.and.to.be.a('string').and.to.equal(BIDDER_URL); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - }); - - it('should return an empty server request list when given an empty ad unit list and a valid ad unit context', function () { - const adUnits = []; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.length(0); - }); - - it('should not return a server request when given no ad unit and a valid ad unit context', function () { - const serverRequests = spec.buildRequests(null, examples.adUnitContext); - expect(serverRequests).to.equal(null); - }); - - it('should not return a server request when given a valid ad unit and no ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, null); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - }); - - it('should not return a server request when given a valid ad unit and an invalid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, {}); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - }); - }); - - describe('BidRequest', function () { - it('should return a valid server request when given a valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.id).to.exist.and.to.be.a('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.at).to.exist.and.to.be.a('number').and.to.equal(1); - }); - - it('should return one server request when given one valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.id).to.exist.and.to.be.a('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - - describe('Impression', function () { - describe('Banner', function () { - it('should return a server request with one impression when given a valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp).to.exist.and.to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.imp[0]).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp[0].id).to.exist.and.to.be.a('string').and.to.equal(`${adUnits[0].bidId}`); - expect(serverRequests[0].data.imp[0].banner).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp[0].banner.w).to.exist.and.to.be.a('number').and.to.equal(adUnits[0].mediaTypes.banner.sizes[0][0]); - expect(serverRequests[0].data.imp[0].banner.h).to.exist.and.to.be.a('number').and.to.equal(adUnits[0].mediaTypes.banner.sizes[0][1]); - expect(serverRequests[0].data.imp[0].banner.format).to.exist.and.to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.imp[0].banner.format[0]).to.exist.and.to.be.an('object').and.to.deep.equal({ - w: adUnits[0].mediaTypes.banner.sizes[0][0], - h: adUnits[0].mediaTypes.banner.sizes[0][1] - }); - }); - }); - }); - - describe('Site', function () { - it('should return a server request with site information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = examples.adUnitContext; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.site).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.site.page).to.exist.and.to.be.an('string').and.to.equal(adUnitContext.refererInfo.referer); - expect(serverRequests[0].data.site.domain).to.exist.and.to.be.an('string').and.to.equal('ventesavenues.in'); - expect(serverRequests[0].data.site.name).to.exist.and.to.be.an('string').and.to.equal('ventesavenues.in'); - }); - - it('should return a server request without site information when given an ad unit context without referer information', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with invalid referer information', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo = 'bad_referer_information'; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context without referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with an invalid referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = {}; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with a misformatted referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = 'we-are-adot'; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - - describe('Device', function () { - it('should return a server request with device information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.device).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.device.ua).to.exist.and.to.be.a('string'); - expect(serverRequests[0].data.device.language).to.exist.and.to.be.a('string'); - }); - }); - - describe('User', function () { - it('should return a server request with user information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = examples.adUnitContext; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.user).to.exist.and.to.be.an('object'); - }); - - it('should return a server request without user information when not given an ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - }); - - describe('interpretResponse', function () { - describe('General', function () { - it('should return an ad when given a valid server response with one bid with USD currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = 'USD'; - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(1); - expect(ads[0].creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].crid); - expect(ads[0].cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(ads[0].currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.cur); - expect(ads[0].netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(true); - expect(ads[0].ttl).to.exist.and.to.be.a('number').and.to.equal(10); - expect(ads[0].height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(ads[0].width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(ads[0].mediaType).to.exist.and.to.be.a('string').and.to.equal('banner'); - }); - - it('should return no ad when not given a server response', function () { - const ads = spec.interpretResponse(null); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when not given a server response body', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given an invalid server response body', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body = 'invalid_body'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response without seat bids', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with invalid seat bids', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = 'invalid_seat_bids'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an empty seat bids array', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = []; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an invalid seat bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = 'invalid_bids'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an empty bids array', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = []; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an invalid bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = ['invalid_bid']; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without impression identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].impid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid impression identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].impid = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without creative identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].crid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid creative identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].crid = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without ad markup and ad serving URL', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].adm = undefined; - serverResponse.body.seatbid[0].bid[0].nurl = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid ad markup', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].adm = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without bid price', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].price = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid bid price', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].price = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and no server request', function () { - const serverRequest = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and an invalid server request', function () { - const serverRequest = 'bad_server_request'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request without bid request', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request with an invalid bid request', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data = 'bad_bid_request'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request without impression', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data.imp = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request with an invalid impression field', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data.imp = 'invalid_impressions'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - - describe('Banner', function () { - it('should return an ad when given a valid server response with one bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(1); - expect(ads[0].adUrl).to.equal(null); - expect(ads[0].creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].crid); - expect(ads[0].cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(ads[0].currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.cur); - expect(ads[0].netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(true); - expect(ads[0].ttl).to.exist.and.to.be.a('number').and.to.equal(10); - expect(ads[0].height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(ads[0].width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(ads[0].mediaType).to.exist.and.to.be.a('string').and.to.equal('banner'); - }); - - it('should return no ad when given a server response with a bid without height', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].h = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid height', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].h = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without width', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].w = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid width', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].w = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - }); -}); diff --git a/test/spec/modules/videobyteBidAdapter_spec.js b/test/spec/modules/videobyteBidAdapter_spec.js index f7ea0698956..b8e41829031 100644 --- a/test/spec/modules/videobyteBidAdapter_spec.js +++ b/test/spec/modules/videobyteBidAdapter_spec.js @@ -153,7 +153,7 @@ describe('VideoByteBidAdapter', function () { it('should create a POST request for every bid', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(spec.ENDPOINT + '?pid=' + bidRequest.params.pubId); + expect(requests[0].url).to.equal(spec.ENDPOINT + bidRequest.params.pubId); }); it('should attach request data', function () { @@ -172,7 +172,7 @@ describe('VideoByteBidAdapter', function () { bidRequest.params.video.e2etest = true; const requests = spec.buildRequests([bidRequest], bidderRequest); expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(spec.ENDPOINT + '?pid=e2etest'); + expect(requests[0].url).to.equal(spec.ENDPOINT + 'e2etest'); }); it('should attach End 2 End test data', function () { diff --git a/test/spec/modules/vidoomyBidAdapter_spec.js b/test/spec/modules/vidoomyBidAdapter_spec.js index 52f522bdcfc..37452914e79 100644 --- a/test/spec/modules/vidoomyBidAdapter_spec.js +++ b/test/spec/modules/vidoomyBidAdapter_spec.js @@ -4,7 +4,6 @@ import { newBidder } from 'src/adapters/bidderFactory.js'; import { INSTREAM } from '../../../src/video'; const ENDPOINT = `https://d.vidoomy.com/api/rtbserver/prebid/`; -const PIXELS = ['/test.png', '/test2.png?gdpr={{GDPR}}&gdpr_consent={{GDPR_CONSENT}}'] describe('vidoomyBidAdapter', function() { const adapter = newBidder(spec); @@ -102,24 +101,24 @@ describe('vidoomyBidAdapter', function() { }); it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT); - expect(request[1].url).to.equal(ENDPOINT); + expect(request[0].url).to.include(ENDPOINT); + expect(request[1].url).to.include(ENDPOINT); }); it('only accepts first width and height sizes', function () { - expect('' + request[0].data.w).to.equal('300'); - expect('' + request[0].data.h).to.equal('250'); - expect('' + request[0].data.w).to.not.equal('200'); - expect('' + request[0].data.h).to.not.equal('100'); - expect('' + request[1].data.w).to.equal('400'); - expect('' + request[1].data.h).to.equal('225'); + expect(request[0].url).to.include('w=300'); + expect(request[0].url).to.include('h=250'); + expect(request[0].url).to.not.include('w=200'); + expect(request[0].url).to.not.include('h=100'); + expect(request[1].url).to.include('w=400'); + expect(request[1].url).to.include('h=225'); }); it('should send id and pid parameters', function () { - expect('' + request[0].data.id).to.equal('123123'); - expect('' + request[0].data.pid).to.equal('123123'); - expect('' + request[1].data.id).to.equal('456456'); - expect('' + request[1].data.pid).to.equal('456456'); + expect(request[0].url).to.include('id=123123'); + expect(request[0].url).to.include('pid=123123'); + expect(request[1].url).to.include('id=456456'); + expect(request[1].url).to.include('pid=456456'); }); }); @@ -183,8 +182,7 @@ describe('vidoomyBidAdapter', function() { 'networkName': null, 'primaryCatId': 'IAB3-1', 'secondaryCatIds': null - }, - 'pixels': PIXELS + } } } @@ -208,22 +206,5 @@ describe('vidoomyBidAdapter', function() { expect(result[0].requestId).to.equal(serverResponseBanner.body.requestId); }); - - it('should sync user cookies', function () { - const GDPR_CONSENT = 'GDPR_TEST' - const result = spec.getUserSyncs({ - pixelEnabled: true - }, [serverResponseBanner], { consentString: GDPR_CONSENT, gdprApplies: 1 }, null) - expect(result).to.eql([ - { - type: 'image', - url: PIXELS[0] - }, - { - type: 'image', - url: `/test2.png?gdpr=1&gdpr_consent=${GDPR_CONSENT}` - } - ]) - }); }); }); diff --git a/test/spec/modules/visxBidAdapter_spec.js b/test/spec/modules/visxBidAdapter_spec.js index d29eb6c25dc..4a8207768ab 100755 --- a/test/spec/modules/visxBidAdapter_spec.js +++ b/test/spec/modules/visxBidAdapter_spec.js @@ -3,7 +3,6 @@ import { spec } from 'modules/visxBidAdapter.js'; import { config } from 'src/config.js'; import { newBidder } from 'src/adapters/bidderFactory.js'; import * as utils from 'src/utils.js'; -import { makeSlot } from '../integration/faker/googletag.js'; describe('VisxAdapter', function () { const adapter = newBidder(spec); @@ -45,8 +44,7 @@ describe('VisxAdapter', function () { videoBid.mediaTypes = { video: { context: 'instream', - mimes: ['video/mp4'], - protocols: [3, 6] + playerSize: [400, 300] } }; expect(spec.isBidRequestValid(videoBid)).to.equal(false); @@ -57,7 +55,9 @@ describe('VisxAdapter', function () { videoBid.mediaTypes = { video: { context: 'instream', - playerSize: [[400, 300]] + playerSize: [400, 300], + mimes: ['video/mp4'], + protocols: [3, 6] } }; expect(spec.isBidRequestValid(videoBid)).to.equal(true); @@ -65,16 +65,7 @@ describe('VisxAdapter', function () { }); describe('buildRequests', function () { - function parseRequest(url) { - const res = {}; - (url.split('?')[1] || '').split('&').forEach((it) => { - const couple = it.split('='); - res[couple[0]] = decodeURIComponent(couple[1]); - }); - return res; - } const bidderRequest = { - timeout: 3000, refererInfo: { referer: 'https://example.com' } @@ -87,11 +78,12 @@ describe('VisxAdapter', function () { {asi: 'exchange1.com', sid: '1234!abcd', hp: 1, name: 'publisher, Inc.', domain: 'publisher.com'} ] }; + const schainString = JSON.stringify(schainObject); let bidRequests = [ { 'bidder': 'visx', 'params': { - 'uid': 903535 + 'uid': '903535' }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], @@ -102,7 +94,7 @@ describe('VisxAdapter', function () { { 'bidder': 'visx', 'params': { - 'uid': 903535 + 'uid': '903535' }, 'adUnitCode': 'adunit-code-2', 'sizes': [[728, 90], [300, 250]], @@ -113,7 +105,7 @@ describe('VisxAdapter', function () { { 'bidder': 'visx', 'params': { - 'uid': 903536 + 'uid': '903536' }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], @@ -124,13 +116,13 @@ describe('VisxAdapter', function () { { 'bidder': 'visx', 'params': { - 'uid': 903537 + 'uid': '903537' }, 'adUnitCode': 'adunit-code-video-3', 'mediaTypes': { 'video': { 'context': 'instream', - 'playerSize': [[400, 300]], + 'playerSize': [400, 300], 'mimes': ['video/mp4', 'video/mpeg'], 'protocols': [3, 6], 'minduration': 5, @@ -143,91 +135,83 @@ describe('VisxAdapter', function () { } ]; - const expectedFullImps = [{ - 'id': '30b31c1838de1e', - 'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]}, - 'ext': {'bidder': {'uid': 903535, 'adslotExists': false}} - }, - { - 'id': '3150ccb55da321', - 'banner': {'format': [{'w': 728, 'h': 90}, {'w': 300, 'h': 250}]}, - 'ext': {'bidder': {'uid': 903535, 'adslotExists': false}} - }, - { - 'id': '42dbe3a7168a6a', - 'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]}, - 'ext': {'bidder': {'uid': 903536, 'adslotExists': false}} - }, - { - 'id': '39a4e3a7168a6a', - 'video': { - 'w': 400, - 'h': 300, - 'mimes': ['video/mp4', 'video/mpeg'], - 'protocols': [3, 6], - 'minduration': 5, - 'maxduration': 30 - }, - 'ext': {'bidder': {'uid': 903537}} - }]; - it('should attach valid params to the tag', function () { - const firstBid = bidRequests[0]; - const bids = [firstBid]; - const request = spec.buildRequests(bids, bidderRequest); - const payload = parseRequest(request.url); - expect(request.url).to.be.an('string'); + const request = spec.buildRequests([bidRequests[0]], bidderRequest); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535'); + expect(payload).to.have.property('sizes', '300x250,300x600'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); + }); - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': [expectedFullImps[0]], - 'tmax': 3000, - 'cur': ['EUR'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer} - }); + it('sizes must not be duplicated', function () { + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '903535,903535,903536,903537'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); }); - it('should attach valid params to the tag with multiformat request', function () { + it('pt parameter must be "net" if params.priceType === "gross"', function () { + bidRequests[1].params.priceType = 'gross'; const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = parseRequest(request.url); + const payload = request.data; expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535,903535,903536,903537'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); + delete bidRequests[1].params.priceType; + }); + it('pt parameter must be "net" if params.priceType === "net"', function () { + bidRequests[1].params.priceType = 'net'; + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '903535,903535,903536,903537'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); + delete bidRequests[1].params.priceType; + }); - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['EUR'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer} - }); + it('pt parameter must be "net" if params.priceType === "undefined"', function () { + bidRequests[1].params.priceType = 'undefined'; + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); + expect(payload).to.have.property('auids', '903535,903535,903536,903537'); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); + delete bidRequests[1].params.priceType; }); it('should add currency from currency.bidderCurrencyDefault', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'currency.bidderCurrencyDefault.visx' ? 'GBP' : 'USD'); const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = parseRequest(request.url); + const payload = request.data; expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535,903535,903536,903537'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['GBP'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer} - }); - + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'GBP'); getConfigStub.restore(); }); @@ -235,73 +219,39 @@ describe('VisxAdapter', function () { const getConfigStub = sinon.stub(config, 'getConfig').callsFake( arg => arg === 'currency.bidderCurrencyDefault.visx' ? '' : 'USD'); const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = parseRequest(request.url); + const payload = request.data; expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535,903535,903536,903537'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['USD'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer} - }); - + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'USD'); getConfigStub.restore(); }); it('if gdprConsent is present payload must have gdpr params', function () { - const request = spec.buildRequests(bidRequests, Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: true}}, bidderRequest)); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['EUR'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer}, - 'user': {'ext': {'consent': 'AAA'}}, - 'regs': {'ext': {'gdpr': 1}} - }); + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: true}}); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', 1); }); it('if gdprApplies is false gdpr_applies must be 0', function () { - const request = spec.buildRequests(bidRequests, Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: false}}, bidderRequest)); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['EUR'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer}, - 'user': {'ext': {'consent': 'AAA'}}, - 'regs': {'ext': {'gdpr': 0}} - }); + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA', gdprApplies: false}}); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', 0); }); it('if gdprApplies is undefined gdpr_applies must be 1', function () { - const request = spec.buildRequests(bidRequests, Object.assign({gdprConsent: {consentString: 'AAA'}}, bidderRequest)); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['EUR'], - 'source': {'ext': {'wrapperType': 'Prebid_js', 'wrapperVersion': '$prebid.version$'}}, - 'site': {'page': referrer}, - 'user': {'ext': {'consent': 'AAA'}}, - 'regs': {'ext': {'gdpr': 1}} - }); + const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'AAA'}}); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('gdpr_consent', 'AAA'); + expect(payload).to.have.property('gdpr_applies', 1); }); it('if schain is present payload must have schain param', function () { @@ -311,110 +261,49 @@ describe('VisxAdapter', function () { bidRequests[2] ]; const request = spec.buildRequests(schainBidRequests, bidderRequest); - const payload = parseRequest(request.url); + const payload = request.data; expect(payload).to.be.an('object'); + expect(payload).to.have.property('schain', schainString); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903535,903535,903536'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps.slice(0, -1), - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$', - 'schain': schainObject - } - }, - 'site': {'page': referrer}, - }); + expect(payload).to.have.property('sizes', '300x250,300x600,728x90'); + expect(payload).to.have.property('r', '22edbae2733bf6'); + expect(payload).to.have.property('cur', 'EUR'); }); it('if userId is available payload must have appropriate params', function () { - const eids = [ - { - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - } - ]; - const userIdBidRequests = [ + const schainBidRequests = [ Object.assign({userId: { tdid: '111', id5id: { uid: '222' }, digitrustid: {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}} - }, - userIdAsEids: eids}, bidRequests[0]), + }}, bidRequests[0]), bidRequests[1], bidRequests[2] ]; - const request = spec.buildRequests(userIdBidRequests, bidderRequest); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps.slice(0, -1), - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$' - } - }, - 'site': {'page': referrer}, - 'user': {'ext': {'eids': eids}} - }); + const request = spec.buildRequests(schainBidRequests, bidderRequest); + const payload = request.data; + expect(payload).to.be.an('object'); + expect(payload).to.have.property('tdid', '111'); + expect(payload).to.have.property('id5', '222'); + expect(payload).to.have.property('dtid', 'DTID'); }); it('should pass grouped video bid\'s params in payload', function () { const request = spec.buildRequests(bidRequests, bidderRequest); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': expectedFullImps, - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$' - } - }, - 'site': {'page': referrer} - }); + const payload = request.data; + expect(payload).to.have.property('protocols', ',,,3|6'); + expect(payload).to.have.property('mimes', ',,,video/mp4|video/mpeg'); + expect(payload).to.have.property('playerSize', ',,,400x300'); + expect(payload).to.have.property('minduration', ',,,5'); + expect(payload).to.have.property('maxduration', ',,,30'); + expect(payload).to.not.have.property('skip'); }); }); describe('buildRequests (multiple media types w/ unsupported video+outstream)', function () { - function parseRequest(url) { - const res = {}; - (url.split('?')[1] || '').split('&').forEach((it) => { - const couple = it.split('='); - res[couple[0]] = decodeURIComponent(couple[1]); - }); - return res; - } const bidderRequest = { - timeout: 3000, refererInfo: { referer: 'https://example.com' } @@ -431,164 +320,33 @@ describe('VisxAdapter', function () { 'mediaTypes': { 'video': { 'context': 'outstream', - 'playerSize': [[400, 300]] + 'playerSize': [400, 300] } }, 'bidId': '39aff3a7169a6a', - 'bidderRequestId': '22edbae2733bf6', + 'bidderRequestId': '22edffe2733bf6', 'auctionId': '1d1a030790a476', } ]; it('should send requst for banner bid', function () { const request = spec.buildRequests([bidRequests[0]], bidderRequest); - const payload = parseRequest(request.url); + const payload = request.data; expect(payload).to.be.an('object'); + expect(payload).to.have.property('u', referrer); + expect(payload).to.have.property('pt', 'net'); expect(payload).to.have.property('auids', '903538'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': [{ - 'id': '39aff3a7169a6a', - 'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]}, - 'ext': {'bidder': {'uid': 903538, 'adslotExists': false}} - }], - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$' - } - }, - 'site': {'page': referrer} - }); - }); - }); - - describe('buildRequests (check ad slot exists)', function () { - function parseRequest(url) { - const res = {}; - (url.split('?')[1] || '').split('&').forEach((it) => { - const couple = it.split('='); - res[couple[0]] = decodeURIComponent(couple[1]); - }); - return res; - } - const bidderRequest = { - timeout: 3000, - refererInfo: { - referer: 'https://example.com' - } - }; - const referrer = bidderRequest.refererInfo.referer; - const bidRequests = [ - { - 'bidder': 'visx', - 'params': { - 'uid': 903535 - }, - 'adUnitCode': 'visx-adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }, - { - 'bidder': 'visx', - 'params': { - 'uid': 903535 - }, - 'adUnitCode': 'visx-adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - let sandbox; - let documentStub; - - before(function() { - sandbox = sinon.sandbox.create(); - documentStub = sandbox.stub(document, 'getElementById'); - documentStub.withArgs('visx-adunit-code-1').returns({ - id: 'visx-adunit-code-1' - }); - documentStub.withArgs('visx-adunit-element-2').returns({ - id: 'visx-adunit-element-2' - }); - }); - - after(function() { - sandbox.restore(); - }); - - it('should find ad slot by ad unit code as element id', function () { - const request = spec.buildRequests([bidRequests[0]], bidderRequest); - const payload = parseRequest(request.url); - expect(payload).to.be.an('object'); - expect(payload).to.have.property('auids', '903535'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': [{ - 'id': '30b31c1838de1e', - 'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]}, - 'ext': {'bidder': {'uid': 903535, 'adslotExists': true}} - }], - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$' - } - }, - 'site': {'page': referrer} - }); - }); - - it('should find ad slot by ad unit code as adUnitPath', function () { - makeSlot({code: 'visx-adunit-code-2', divId: 'visx-adunit-element-2'}); - - const request = spec.buildRequests([bidRequests[1]], bidderRequest); - const payload = parseRequest(request.url); - expect(payload).to.be.an('object'); - expect(payload).to.have.property('auids', '903535'); - - const postData = request.data; - expect(postData).to.be.an('object'); - expect(postData).to.deep.equal({ - 'id': '22edbae2733bf6', - 'imp': [{ - 'id': '30b31c1838de1e', - 'banner': {'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}]}, - 'ext': {'bidder': {'uid': 903535, 'adslotExists': true}} - }], - 'tmax': 3000, - 'cur': ['EUR'], - 'source': { - 'ext': { - 'wrapperType': 'Prebid_js', - 'wrapperVersion': '$prebid.version$' - } - }, - 'site': {'page': referrer} - }); + expect(payload).to.have.property('sizes', '300x250,300x600'); + expect(payload).to.not.have.property('playerSize'); }); }); describe('interpretResponse', function () { const responses = [ - {'bid': [{'price': 1.15, 'impid': '300bfeb0d71a5b', 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner', 'advertiserDomains': ['some_domain.com'], 'ext': {'prebid': {'targeting': {'hb_visx_product': 'understitial', 'hb_visx_width': 300, 'hb_visx_height': 250}}}}], 'seat': '1'}, - {'bid': [{'price': 0.5, 'impid': '4dff80cc4ee346', 'adm': '
test content 2
', 'auid': 903536, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0.15, 'impid': '5703af74d0472a', 'adm': '
test content 3
', 'auid': 903535, 'h': 90, 'w': 728, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0, 'impid': '300bfeb0d7190gf', 'auid': 903537, 'h': 250, 'w': 300, 'cur': 'EUR'}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner', 'advertiserDomains': ['some_domain.com']}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 903536, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 3
', 'auid': 903535, 'h': 90, 'w': 728, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0, 'auid': 903537, 'h': 250, 'w': 300, 'cur': 'EUR'}], 'seat': '1'}, {'bid': [{'price': 0, 'adm': '
test content 5
', 'h': 250, 'w': 300, 'cur': 'EUR'}], 'seat': '1'}, undefined, {'bid': [], 'seat': '1'}, @@ -604,7 +362,7 @@ describe('VisxAdapter', function () { }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], - 'bidId': '300bfeb0d71a5b', + 'bidId': '659423fff799cb', 'bidderRequestId': '5f2009617a7c0a', 'auctionId': '1cbd2feafe5e8b', } @@ -612,7 +370,7 @@ describe('VisxAdapter', function () { const request = spec.buildRequests(bidRequests); const expectedResponse = [ { - 'requestId': '300bfeb0d71a5b', + 'requestId': '659423fff799cb', 'cpm': 1.15, 'creativeId': 903535, 'dealId': undefined, @@ -626,18 +384,6 @@ describe('VisxAdapter', function () { 'advertiserDomains': ['some_domain.com'], 'mediaType': 'banner', }, - 'adserverTargeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - }, - 'ext': { - 'targeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - } - } } ]; @@ -698,18 +444,6 @@ describe('VisxAdapter', function () { 'advertiserDomains': ['some_domain.com'], 'mediaType': 'banner', }, - 'adserverTargeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - }, - 'ext': { - 'targeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - } - } }, { 'requestId': '4dff80cc4ee346', @@ -758,7 +492,7 @@ describe('VisxAdapter', function () { }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], - 'bidId': '300bfeb0d71a5b', + 'bidId': '659423fff799cb', 'bidderRequestId': '5f2009617a7c0a', 'auctionId': '1cbd2feafe5e8b', } @@ -767,7 +501,7 @@ describe('VisxAdapter', function () { const request = spec.buildRequests(bidRequests); const expectedResponse = [ { - 'requestId': '300bfeb0d71a5b', + 'requestId': '659423fff799cb', 'cpm': 1.15, 'creativeId': 903535, 'dealId': undefined, @@ -781,18 +515,6 @@ describe('VisxAdapter', function () { 'advertiserDomains': ['some_domain.com'], 'mediaType': 'banner', }, - 'adserverTargeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - }, - 'ext': { - 'targeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - } - } } ]; @@ -846,11 +568,11 @@ describe('VisxAdapter', function () { it('complicated case', function () { const fullResponse = [ - {'bid': [{'price': 1.15, 'impid': '2164be6358b9', 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner', 'advertiserDomains': ['some_domain.com']}], 'seat': '1'}, - {'bid': [{'price': 0.5, 'impid': '4e111f1b66e4', 'adm': '
test content 2
', 'auid': 903536, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0.15, 'impid': '26d6f897b516', 'adm': '
test content 3
', 'auid': 903535, 'h': 90, 'w': 728, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0.15, 'impid': '326bde7fbf69', 'adm': '
test content 4
', 'auid': 903535, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0.5, 'impid': '1751cd90161', 'adm': '
test content 5
', 'auid': 903536, 'h': 600, 'w': 350, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner', 'advertiserDomains': ['some_domain.com']}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 903536, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 3
', 'auid': 903535, 'h': 90, 'w': 728, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0.15, 'adm': '
test content 4
', 'auid': 903535, 'h': 600, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 5
', 'auid': 903536, 'h': 600, 'w': 350, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, ]; const bidRequests = [ { @@ -999,8 +721,8 @@ describe('VisxAdapter', function () { it('dublicate uids and sizes in one slot', function () { const fullResponse = [ - {'bid': [{'price': 1.15, 'impid': '5126e301f4be', 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, - {'bid': [{'price': 0.5, 'impid': '57b2ebe70e16', 'adm': '
test content 2
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 1.15, 'adm': '
test content 1
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '
test content 2
', 'auid': 903535, 'h': 250, 'w': 300, 'cur': 'EUR', 'mediaType': 'banner'}], 'seat': '1'}, ]; const bidRequests = [ { @@ -1079,7 +801,7 @@ describe('VisxAdapter', function () { it('handles video bid', function () { const fullResponse = [ - {'bid': [{'price': 0.5, 'impid': '2164be6358b9', 'adm': '', 'auid': 903537, 'w': 400, 'h': 300, 'cur': 'EUR', 'mediaType': 'video'}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '', 'auid': 903537, 'w': 400, 'h': 300, 'cur': 'EUR', 'mediaType': 'video'}], 'seat': '1'}, ]; const bidRequests = [ { @@ -1091,7 +813,7 @@ describe('VisxAdapter', function () { 'mediaTypes': { 'video': { 'context': 'instream', - 'playerSize': [[400, 300]], + 'playerSize': [400, 300], 'mimes': ['video/mp4'], 'protocols': [3, 6] } @@ -1128,7 +850,7 @@ describe('VisxAdapter', function () { it('handles multiformat bid response with outstream+banner as banner', function () { const fullResponse = [ - {'bid': [{'price': 0.5, 'impid': '2164be6358b9', 'adm': '', 'auid': 903537, 'w': 400, 'h': 300, 'cur': 'EUR', 'mediaType': 'video'}], 'seat': '1'}, + {'bid': [{'price': 0.5, 'adm': '', 'auid': 903537, 'w': 400, 'h': 300, 'cur': 'EUR', 'mediaType': 'video'}], 'seat': '1'}, ]; const bidRequests = [ { @@ -1140,7 +862,7 @@ describe('VisxAdapter', function () { 'mediaTypes': { 'video': { 'context': 'outstream', - 'playerSize': [[400, 300]], + 'playerSize': [400, 300], 'mimes': ['video/mp4'], 'protocols': [3, 6] } @@ -1186,7 +908,7 @@ describe('VisxAdapter', function () { }, 'adUnitCode': 'adunit-code-1', 'sizes': [[300, 250], [300, 600]], - 'bidId': '300bfeb0d71a5b', + 'bidId': '659423fff799cb', 'bidderRequestId': '5f2009617a7c0a', 'auctionId': '1cbd2feafe5e8b', } @@ -1196,7 +918,7 @@ describe('VisxAdapter', function () { const winUrl = 'https://t.visx.net/track/win/53245341'; const expectedResponse = [ { - 'requestId': '300bfeb0d71a5b', + 'requestId': '659423fff799cb', 'cpm': 1.15, 'creativeId': 903535, 'dealId': undefined, @@ -1210,31 +932,23 @@ describe('VisxAdapter', function () { 'advertiserDomains': ['some_domain.com'], 'mediaType': 'banner', }, - 'adserverTargeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, - }, 'ext': { 'events': { 'pending': pendingUrl, 'win': winUrl - }, - 'targeting': { - 'hb_visx_product': 'understitial', - 'hb_visx_width': 300, - 'hb_visx_height': 250, } } } ]; const serverResponse = Object.assign({}, responses[0]); - serverResponse.bid = [Object.assign({}, serverResponse.bid[0])]; - serverResponse.bid[0].ext.prebid = Object.assign({}, serverResponse.bid[0].ext.prebid); - utils.deepSetValue(serverResponse.bid[0], 'ext.prebid.events', { - pending: pendingUrl, - win: winUrl, - }); + serverResponse.bid = [Object.assign({}, {ext: { + prebid: { + events: { + 'pending': pendingUrl, + 'win': winUrl + } + } + }}, serverResponse.bid[0])]; const result = spec.interpretResponse({'body': {'seatbid': [serverResponse]}}, request); expect(result).to.deep.equal(expectedResponse); }); @@ -1265,52 +979,7 @@ describe('VisxAdapter', function () { it('onTimeout', function () { const data = { timeout: 3000, bidId: '23423', params: { uid: 1 } }; spec.onTimeout(data); - expect(utils.triggerPixel.calledOnceWith('https://t.visx.net/track/bid_timeout//' + JSON.stringify(data))).to.equal(true); - }); - }); - - describe('user sync', function () { - function parseUrl(url) { - const [, path, querySt] = url.match(/^https?:\/\/[^\/]+(?:\/([^?]+)?)?(?:\?(.+)?)?$/) || []; - const query = {}; - (querySt || '').split('&').forEach((q) => { - var kv = q.split('='); - if (kv[0]) { - query[kv[0]] = decodeURIComponent(kv[1] || ''); - } - }); - return { path, query }; - } - it('should call iframe', function () { - let syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - - expect(Array.isArray(syncs)).to.equal(true); - expect(syncs.length).to.equal(1); - expect(syncs[0]).to.have.property('type', 'iframe'); - expect(syncs[0]).to.have.property('url'); - expect(syncs[0].url).to.be.an('string'); - - const { path, query } = parseUrl(syncs[0].url); - expect(path).to.equal('push_sync'); - expect(query).to.deep.equal({iframe: '1'}); - }); - - it('should call image', function () { - let syncs = spec.getUserSyncs({ - pixelEnabled: true - }); - - expect(Array.isArray(syncs)).to.equal(true); - expect(syncs.length).to.equal(1); - expect(syncs[0]).to.have.property('type', 'image'); - expect(syncs[0]).to.have.property('url'); - expect(syncs[0].url).to.be.an('string'); - - const { path, query } = parseUrl(syncs[0].url); - expect(path).to.equal('push_sync'); - expect(query).to.deep.equal({}); + expect(utils.triggerPixel.calledOnceWith('https://t.visx.net/track/bid_timeout?data=' + JSON.stringify(data))).to.equal(true); }); }); }); diff --git a/test/spec/modules/vrtcalBidAdapter_spec.js b/test/spec/modules/vrtcalBidAdapter_spec.js index 66440130860..a5f2d475a29 100644 --- a/test/spec/modules/vrtcalBidAdapter_spec.js +++ b/test/spec/modules/vrtcalBidAdapter_spec.js @@ -29,7 +29,7 @@ describe('vrtcalBidAdapter', function () { } ]; - let request = spec.buildRequests(bidRequests); + const request = spec.buildRequests(bidRequests); it('sends bid request to our endpoint via POST', function () { expect(request[0].method).to.equal('POST'); @@ -38,18 +38,6 @@ describe('vrtcalBidAdapter', function () { it('adUnitCode should be sent as prebidAdUnitCode parameters on any requests', function () { expect(request[0].data).to.match(/"prebidAdUnitCode":"adunit0001"/); }); - - it('if the publisher has NOT set a floor via the floors module, zero should be sent as bidfloor parameter on any requests', function () { - expect(request[0].data).to.match(/"bidfloor":0/); - }); - - it('if the publisher has set a floor via the floors module, it should be sent as bidfloor parameter on any requests', function () { - let floorInfo; - bidRequests[0].getFloor = () => floorInfo; - floorInfo = {currency: 'USD', floor: 0.55}; - request = spec.buildRequests(bidRequests); - expect(request[0].data).to.match(/"bidfloor":0.55/); - }); }); describe('interpretResponse', function () { diff --git a/test/spec/modules/weboramaRtdProvider_spec.js b/test/spec/modules/weboramaRtdProvider_spec.js deleted file mode 100644 index 081a6f06876..00000000000 --- a/test/spec/modules/weboramaRtdProvider_spec.js +++ /dev/null @@ -1,482 +0,0 @@ -import { - weboramaSubmodule -} from 'modules/weboramaRtdProvider.js'; -import { - server -} from 'test/mocks/xhr.js'; -import { - storage, - DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY -} from '../../../modules/weboramaRtdProvider.js'; - -const responseHeader = { - 'Content-Type': 'application/json' -}; - -describe('weboramaRtdProvider', function() { - describe('weboramaSubmodule', function() { - it('successfully instantiates and call contextual api', function() { - const moduleConfig = { - params: { - weboCtxConf: { - token: 'foo', - targetURL: 'https://prebid.org', - } - } - }; - - expect(weboramaSubmodule.init(moduleConfig)).to.equal(true); - }); - - it('instantiate without contextual token should fail', function() { - const moduleConfig = { - params: { - weboCtxConf: {} - } - }; - expect(weboramaSubmodule.init(moduleConfig)).to.equal(false); - }); - - it('instantiate with empty weboUserData conf should return true', function() { - const moduleConfig = { - params: { - weboUserDataConf: {} - } - }; - expect(weboramaSubmodule.init(moduleConfig)).to.equal(true); - }); - }); - - describe('Handle Set Targeting', function() { - let sandbox; - - beforeEach(function() { - sandbox = sinon.sandbox.create(); - - storage.removeDataFromLocalStorage('webo_wam2gam_entry'); - }); - - afterEach(function() { - sandbox.restore(); - }); - - describe('Add Contextual Data', function() { - it('should set gam targeting and send to bidders by default', function() { - const moduleConfig = { - params: { - weboCtxConf: { - token: 'foo', - targetURL: 'https://prebid.org', - } - } - }; - const data = { - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - }; - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver' - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - let request = server.requests[0]; - - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://ctx.weborama.com/api/profile?token=foo&url=https%3A%2F%2Fprebid.org&'); - expect(request.withCredentials).to.be.false; - - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': data, - 'adunit2': data, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('webo_ctx=foo;webo_ctx=bar;webo_ds=baz'); - }); - - it('should set gam targeting but not send to bidders with setPrebidTargeting=true/sendToBidders=false', function() { - const moduleConfig = { - params: { - weboCtxConf: { - token: 'foo', - targetURL: 'https://prebid.org', - setPrebidTargeting: true, - sendToBidders: false, - } - } - }; - const data = { - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - }; - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - let request = server.requests[0]; - - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://ctx.weborama.com/api/profile?token=foo&url=https%3A%2F%2Fprebid.org&'); - expect(request.withCredentials).to.be.false; - - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': data, - 'adunit2': data, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar'); - }); - - it('should not set gam targeting with setPrebidTargeting=false but send to bidders', function() { - const moduleConfig = { - params: { - weboCtxConf: { - token: 'foo', - targetURL: 'https://prebid.org', - setPrebidTargeting: false, - } - } - }; - const data = { - webo_ctx: ['foo', 'bar'], - webo_ds: ['baz'], - }; - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }] - }] - } - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - let request = server.requests[0]; - - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://ctx.weborama.com/api/profile?token=foo&url=https%3A%2F%2Fprebid.org&'); - expect(request.withCredentials).to.be.false; - - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({}); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar;webo_ctx=foo;webo_ctx=bar;webo_ds=baz'); - }); - - it('should use default profile in case of api error', function() { - const defaultProfile = { - webo_ctx: ['baz'], - }; - const moduleConfig = { - params: { - weboCtxConf: { - token: 'foo', - targetURL: 'https://prebid.org', - setPrebidTargeting: true, - defaultProfile: defaultProfile, - } - } - }; - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver' - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - let request = server.requests[0]; - - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://ctx.weborama.com/api/profile?token=foo&url=https%3A%2F%2Fprebid.org&'); - expect(request.withCredentials).to.be.false; - - request.respond(500, responseHeader); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': defaultProfile, - 'adunit2': defaultProfile, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('webo_ctx=baz'); - }); - }); - - describe('Add WAM2GAM Data', function() { - it('should set gam targeting from local storage and send to bidders by default', function() { - const moduleConfig = { - params: { - weboUserDataConf: {} - } - }; - const data = { - webo_cs: ['foo', 'bar'], - webo_audiences: ['baz'], - }; - - const entry = { - targeting: data, - }; - - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - sandbox.stub(storage, 'getDataFromLocalStorage') - .withArgs(DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY) - .returns(JSON.stringify(entry)); - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver' - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': data, - 'adunit2': data, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('webo_cs=foo;webo_cs=bar;webo_audiences=baz'); - }); - - it('should set gam targeting but not send to bidders with setPrebidTargeting=true/sendToBidders=false', function() { - const moduleConfig = { - params: { - weboUserDataConf: { - setPrebidTargeting: true, - sendToBidders: false - } - } - }; - const data = { - webo_cs: ['foo', 'bar'], - webo_audiences: ['baz'], - }; - - const entry = { - targeting: data, - }; - - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - sandbox.stub(storage, 'getDataFromLocalStorage') - .withArgs(DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY) - .returns(JSON.stringify(entry)); - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': data, - 'adunit2': data, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar'); - }); - - it('should not set gam targeting with setPrebidTargeting=false but send to bidders', function() { - const moduleConfig = { - params: { - weboUserDataConf: { - setPrebidTargeting: false, - } - } - }; - const data = { - webo_cs: ['foo', 'bar'], - webo_audiences: ['baz'], - }; - - const entry = { - targeting: data, - }; - - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - sandbox.stub(storage, 'getDataFromLocalStorage') - .withArgs(DEFAULT_LOCAL_STORAGE_USER_PROFILE_KEY) - .returns(JSON.stringify(entry)); - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver', - params: { - target: 'foo=bar' - } - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({}); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('foo=bar;webo_cs=foo;webo_cs=bar;webo_audiences=baz'); - }); - - it('should use default profile in case of nothing on local storage', function() { - const defaultProfile = { - webo_audiences: ['baz'] - }; - const moduleConfig = { - params: { - weboUserDataConf: { - setPrebidTargeting: true, - defaultProfile: defaultProfile, - } - } - }; - - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver' - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': defaultProfile, - 'adunit2': defaultProfile, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('webo_audiences=baz'); - }); - - it('should use default profile if cant read from local storage', function() { - const defaultProfile = { - webo_audiences: ['baz'] - }; - const moduleConfig = { - params: { - weboUserDataConf: { - setPrebidTargeting: true, - defaultProfile: defaultProfile, - } - } - }; - - sandbox.stub(storage, 'localStorageIsEnabled').returns(false); - - const adUnitsCodes = ['adunit1', 'adunit2']; - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'smartadserver' - }] - }] - }; - const onDoneSpy = sinon.spy(); - - expect(weboramaSubmodule.init(moduleConfig)).to.be.true; - weboramaSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, moduleConfig); - - expect(onDoneSpy.calledOnce).to.be.true; - - const targeting = weboramaSubmodule.getTargetingData(adUnitsCodes, moduleConfig); - - expect(targeting).to.deep.equal({ - 'adunit1': defaultProfile, - 'adunit2': defaultProfile, - }); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.target).to.equal('webo_audiences=baz'); - }); - }); - }); -}); diff --git a/test/spec/modules/welectBidAdapter_spec.js b/test/spec/modules/welectBidAdapter_spec.js deleted file mode 100644 index 2f2af35eaec..00000000000 --- a/test/spec/modules/welectBidAdapter_spec.js +++ /dev/null @@ -1,211 +0,0 @@ -import { expect } from 'chai'; -import { spec as adapter } from 'modules/welectBidAdapter.js'; - -describe('WelectAdapter', function () { - describe('Check methods existance', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - }); - - describe('Check method isBidRequestValid return', function () { - let bid = { - bidder: 'welect', - params: { - placementId: 'exampleAlias', - domain: 'www.welect.de' - }, - sizes: [[640, 360]], - mediaTypes: { - video: { - context: 'instream' - } - }, - }; - let bid2 = { - bidder: 'welect', - params: { - domain: 'www.welect.de' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 360] - } - }, - }; - - it('should be true', function () { - expect(adapter.isBidRequestValid(bid)).to.be.true; - }); - - it('should be false because the placementId is missing', function () { - expect(adapter.isBidRequestValid(bid2)).to.be.false; - }); - }); - - describe('Check buildRequests method', function () { - // Bids to be formatted - let bid1 = { - bidder: 'welect', - params: { - placementId: 'exampleAlias' - }, - sizes: [[640, 360]], - mediaTypes: { - video: { - context: 'instream' - } - }, - bidId: 'abdc' - }; - let bid2 = { - bidder: 'welect', - params: { - placementId: 'exampleAlias', - domain: 'www.welect2.de' - }, - sizes: [[640, 360]], - mediaTypes: { - video: { - context: 'instream' - } - }, - bidId: 'abdc', - gdprConsent: { - gdprApplies: 1, - gdprConsent: 'some_string' - } - }; - - let data1 = { - bid_id: 'abdc', - width: 640, - height: 360 - } - - let data2 = { - bid_id: 'abdc', - width: 640, - height: 360, - gdpr_consent: { - gdprApplies: 1, - tcString: 'some_string' - } - } - - // Formatted requets - let request1 = { - method: 'POST', - url: 'https://www.welect.de/api/v2/preflight/exampleAlias', - data: data1, - options: { - contentType: 'application/json', - withCredentials: false, - crossOrigin: true, - } - }; - - let request2 = { - method: 'POST', - url: 'https://www.welect2.de/api/v2/preflight/exampleAlias', - data: data2, - options: { - contentType: 'application/json', - withCredentials: false, - crossOrigin: true, - } - } - - it('defaults to www.welect.de, without gdpr object', function () { - expect(adapter.buildRequests([bid1])).to.deep.equal([request1]); - }) - - it('must return the right formatted requests, with gdpr object', function () { - expect(adapter.buildRequests([bid2])).to.deep.equal([request2]); - }); - }); - - describe('Check interpretResponse method return', function () { - // invalid server response - let unavailableResponse = { - body: { - available: false - } - }; - - let availableResponse = { - body: { - available: true, - bidResponse: { - ad: { - video: 'some vast url' - }, - meta: { - advertiserDomains: [], - }, - cpm: 17, - creativeId: 'svmpreview', - currency: 'EUR', - netRevenue: true, - requestId: 'some bid id', - ttl: 120, - vastUrl: 'some vast url', - height: 640, - width: 320 - } - } - } - // bid Request - let bid = { - data: { - bid_id: 'some bid id', - width: 640, - height: 320, - gdpr_consent: { - gdprApplies: 1, - tcString: 'some_string' - } - }, - method: 'POST', - url: 'https://www.welect.de/api/v2/preflight/exampleAlias', - options: { - contentType: 'application/json', - withCredentials: false, - crossOrigin: true, - } - }; - // Formatted reponse - let result = { - ad: { - video: 'some vast url' - }, - meta: { - advertiserDomains: [] - }, - cpm: 17, - creativeId: 'svmpreview', - currency: 'EUR', - height: 640, - netRevenue: true, - requestId: 'some bid id', - ttl: 120, - vastUrl: 'some vast url', - width: 320 - } - - it('if response reflects unavailability, should be empty', function () { - expect(adapter.interpretResponse(unavailableResponse, bid)).to.deep.equal([]); - }); - - it('if response reflects availability, should equal result', function () { - expect(adapter.interpretResponse(availableResponse, bid)).to.deep.equal([result]) - }) - }); -}); diff --git a/test/spec/modules/yahoosspBidAdapter_spec.js b/test/spec/modules/yahoosspBidAdapter_spec.js deleted file mode 100644 index e0af8784605..00000000000 --- a/test/spec/modules/yahoosspBidAdapter_spec.js +++ /dev/null @@ -1,1359 +0,0 @@ -import { expect } from 'chai'; -import { config } from 'src/config.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { spec } from 'modules/yahoosspBidAdapter.js'; - -const DEFAULT_BID_ID = '84ab500420319d'; -const DEFAULT_BID_DCN = '2093845709823475'; -const DEFAULT_BID_POS = 'header'; -const DEFAULT_PUBID = 'PubId'; -const DEFAULT_AD_UNIT_CODE = '/19968336/header-bid-tag-1'; -const DEFAULT_AD_UNIT_TYPE = 'banner'; -const DEFAULT_PARAMS_BID_OVERRIDE = {}; -const DEFAULT_VIDEO_CONTEXT = 'instream'; -const ADAPTER_VERSION = '1.0.2'; -const PREBID_VERSION = '$prebid.version$'; -const INTEGRATION_METHOD = 'prebid.js'; - -// Utility functions -const generateBidRequest = ({bidId, pos, adUnitCode, adUnitType, bidOverrideObject, videoContext, pubIdMode}) => { - const bidRequest = { - adUnitCode, - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId, - bidderRequestsCount: 1, - bidder: 'yahoossp', - bidderRequestId: '7101db09af0db2', - bidderWinsCount: 0, - mediaTypes: {}, - params: { - bidOverride: bidOverrideObject - }, - src: 'client', - transactionId: '5b17b67d-7704-4732-8cc9-5b1723e9bcf9' - }; - - const bannerObj = { - sizes: [[300, 250], [300, 600]] - }; - - const videoObject = { - context: videoContext, - playerSize: [[300, 250]], - mimes: ['video/mp4', 'application/javascript'], - api: [2] - }; - - if (videoContext === 'outstream') { - bidRequest.renderer = undefined - }; - - if (adUnitType === 'banner' || adUnitType === 'dap-o2' || adUnitType === 'dap-up') { - bidRequest.mediaTypes.banner = bannerObj; - bidRequest.sizes = [[300, 250], [300, 600]]; - } else if (adUnitType === 'video') { - bidRequest.mediaTypes.video = videoObject; - } else if (adUnitType === 'multi-format') { - bidRequest.mediaTypes.banner = bannerObj; - bidRequest.sizes = [[300, 250], [300, 600]]; - bidRequest.mediaTypes.video = videoObject; - } else if (adUnitType === 'native') { - bidRequest.mediaTypes.native = {a: 123, b: 456}; - } - - if (pubIdMode === true) { - bidRequest.params.pubId = DEFAULT_PUBID; - } else { - bidRequest.params.dcn = DEFAULT_BID_DCN; - bidRequest.params.pos = pos || DEFAULT_BID_POS; - }; - - return bidRequest; -} - -let generateBidderRequest = (bidRequestArray, adUnitCode) => { - const bidderRequest = { - adUnitCode: adUnitCode || 'default-adUnitCode', - auctionId: 'd4c83a3b-18e4-4208-b98b-63848449c7aa', - auctionStart: new Date().getTime(), - bidderCode: 'yahoossp', - bidderRequestId: '112f1c7c5d399a', - bids: bidRequestArray, - refererInfo: { - referer: 'https://publisher-test.com', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: ['https://publisher-test.com'], - }, - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - vendorData: {}, - gdprApplies: true - }, - start: new Date().getTime(), - timeout: 1000, - }; - - return bidderRequest; -}; - -const generateBuildRequestMock = ({bidId, pos, adUnitCode, adUnitType, bidOverrideObject, videoContext, pubIdMode}) => { - const bidRequestConfig = { - bidId: bidId || DEFAULT_BID_ID, - pos: pos || DEFAULT_BID_POS, - adUnitCode: adUnitCode || DEFAULT_AD_UNIT_CODE, - adUnitType: adUnitType || DEFAULT_AD_UNIT_TYPE, - bidOverrideObject: bidOverrideObject || DEFAULT_PARAMS_BID_OVERRIDE, - videoContext: videoContext || DEFAULT_VIDEO_CONTEXT, - pubIdMode: pubIdMode || false - }; - const bidRequest = generateBidRequest(bidRequestConfig); - const validBidRequests = [bidRequest]; - const bidderRequest = generateBidderRequest(validBidRequests, adUnitCode); - - return { bidRequest, validBidRequests, bidderRequest } -}; - -const generateAdmPayload = (admPayloadType) => { - let ADM_PAYLOAD; - switch (admPayloadType) { - case 'banner': - ADM_PAYLOAD = ''; // banner - break; - case 'video': - ADM_PAYLOAD = ''; // VAST xml - break; - case 'multi-format': - const admPayloads = [ - '', // banner - '' // VAST xml - ] - const random = Math.floor(Math.random() * admPayloads.length); - ADM_PAYLOAD = admPayloads[random] - break; - case 'dap-o2': - ADM_PAYLOAD = ''; // O2 player - break; - case 'dap-up': - ADM_PAYLOAD = ''; // Unified Player - break; - }; - return ADM_PAYLOAD; -}; - -const generateResponseMock = (admPayloadType, vastVersion, videoContext) => { - const bidResponse = { - id: 'fc0c35df-21fb-4f93-9ebd-88759dbe31f9', - impid: '274395c06a24e5', - adm: generateAdmPayload(admPayloadType), - price: 1, - w: 300, - h: 250, - crid: 'ssp-placement-name', - adomain: ['advertiser-domain.com'] - }; - - if (vastVersion === 'vast') { - bidResponse.nurl = 'https://yahoo.com?event=adAttempt'; - }; - - const serverResponse = { - body: { - id: 'fc0c35df-21fb-4f93-9ebd-88759dbe31f9', - seatbid: [{ bid: [ bidResponse ], seat: 13107 }] - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: admPayloadType, videoContext: videoContext}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - - return {serverResponse, data, bidderRequest}; -} - -// Unit tests -describe('YahooSSP Bid Adapter:', () => { - it('PLACEHOLDER TO PASS GULP', () => { - const obj = {}; - expect(obj).to.be.an('object'); - }); - - describe('getUserSyncs()', () => { - const IMAGE_PIXEL_URL = 'http://image-pixel.com/foo/bar?1234&baz=true'; - const IFRAME_ONE_URL = 'http://image-iframe.com/foo/bar?1234&baz=true'; - const IFRAME_TWO_URL = 'http://image-iframe-two.com/foo/bar?1234&baz=true'; - - let serverResponses = []; - beforeEach(() => { - serverResponses[0] = { - body: { - ext: { - pixels: `` - } - } - } - }); - - after(() => { - serverResponses = undefined; - }); - - it('for only iframe enabled syncs', () => { - let syncOptions = { - iframeEnabled: true, - pixelEnabled: false - }; - let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses); - expect(pixelsObjects.length).to.equal(2); - expect(pixelsObjects).to.deep.equal( - [ - {type: 'iframe', 'url': IFRAME_ONE_URL}, - {type: 'iframe', 'url': IFRAME_TWO_URL} - ] - ) - }); - - it('for only pixel enabled syncs', () => { - let syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses); - expect(pixelsObjects.length).to.equal(1); - expect(pixelsObjects).to.deep.equal( - [ - {type: 'image', 'url': IMAGE_PIXEL_URL} - ] - ) - }); - - it('for both pixel and iframe enabled syncs', () => { - let syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses); - expect(pixelsObjects.length).to.equal(3); - expect(pixelsObjects).to.deep.equal( - [ - {type: 'iframe', 'url': IFRAME_ONE_URL}, - {type: 'image', 'url': IMAGE_PIXEL_URL}, - {type: 'iframe', 'url': IFRAME_TWO_URL} - ] - ) - }); - }); - - // Validate Bid Requests - describe('isBidRequestValid()', () => { - const INVALID_INPUT = [ - {}, - {params: {}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012'}}, - {params: {dcn: 1234, pos: 'header'}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', pos: 1234}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', pos: ''}}, - {params: {dcn: '', pos: 'header'}}, - ]; - - INVALID_INPUT.forEach(input => { - it(`should determine that the bid is INVALID for the input ${JSON.stringify(input)}`, () => { - expect(spec.isBidRequestValid(input)).to.be.false; - }); - }); - - it('should determine that the bid is VALID if dcn and pos are present on the params object', () => { - const validBid = { - params: { - dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', - pos: 'header' - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should mark bid as VALID if bid.params.testing.e2etest = "true" (dcn & pos not required)', () => { - const validBid = { - params: { - dcn: 8888, - pos: 9999, - testing: { - e2etest: true - } - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should mark bid ad VALID if pubId exists instead of dcn & pos', () => { - const validBid = { - params: { - pubId: DEFAULT_PUBID - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - }); - - describe('Price Floor module support:', () => { - it('should get bidfloor from getFloor method', () => { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - bidRequest.params.bidOverride = {cur: 'EUR'}; - bidRequest.getFloor = (floorObj) => { - return { - floor: bidRequest.floors.values[floorObj.mediaType + '|640x480'], - currency: floorObj.currency, - mediaType: floorObj.mediaType - } - }; - bidRequest.floors = { - currency: 'EUR', - values: { - 'banner|640x480': 5.55 - } - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.cur).to.deep.equal(['EUR']); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(5.55); - }); - }); - - describe('Schain module support:', () => { - it('should send Global or Bidder specific schain', function () { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'some-platform.com', - sid: '111111', - rid: bidRequest.bidId, - hp: 1 - }] - }; - bidRequest.schain = globalSchain; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const schain = data.source.ext.schain; - expect(schain.nodes.length).to.equal(1); - expect(schain).to.equal(globalSchain); - }); - }); - - describe('First party data module - "Site" support (ortb2):', () => { - // Should not allow invalid "site" data types - const INVALID_ORTB2_TYPES = [ null, [], 123, 'unsupportedKeyName', true, false, undefined ]; - INVALID_ORTB2_TYPES.forEach(param => { - const ortb2 = { site: param } - config.setConfig({ortb2}); - it(`should not allow invalid site types to be added to bid-request: ${JSON.stringify(param)}`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.be.undefined; - }); - }); - - // Should add valid "site" params - const VALID_SITE_STRINGS = ['name', 'domain', 'page', 'ref', 'keywords', 'search']; - const VALID_SITE_ARRAYS = ['cat', 'sectioncat', 'pagecat']; - - VALID_SITE_STRINGS.forEach(param => { - it(`should allow supported site keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - [param]: 'something' - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.exist; - expect(data.site[param]).to.be.a('string'); - expect(data.site[param]).to.be.equal(ortb2.site[param]); - }); - }); - - VALID_SITE_ARRAYS.forEach(param => { - it(`should determine that the ortb2.site Array key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - [param]: ['something'] - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.exist; - expect(data.site[param]).to.be.a('array'); - expect(data.site[param]).to.be.equal(ortb2.site[param]); - }); - }); - - // Should not allow invalid "site.content" data types - INVALID_ORTB2_TYPES.forEach(param => { - it(`should determine that the ortb2.site.content key is invalid and should not be added to bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: param - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content).to.be.undefined; - }); - }); - - // Should not allow invalid "site.content" keys - it(`should not allow invalid ortb2.site.content object keys to be added to bid-request: {custom object}`, () => { - const ortb2 = { - site: { - content: { - fake: 'news', - unreal: 'param', - counterfit: 'data' - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content).to.be.a('object'); - }); - - // Should append valid "site.content" keys - const VALID_CONTENT_STRINGS = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language']; - VALID_CONTENT_STRINGS.forEach(param => { - it(`should determine that the ortb2.site String key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: 'something' - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.exist; - expect(data.site.content[param]).to.be.a('string'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_CONTENT_NUMBERS = ['episode', 'prodq', 'context', 'livestream', 'len']; - VALID_CONTENT_NUMBERS.forEach(param => { - it(`should determine that the ortb2.site.content Number key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: 1234 - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('number'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_CONTENT_ARRAYS = ['cat']; - VALID_CONTENT_ARRAYS.forEach(param => { - it(`should determine that the ortb2.site Array key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: ['something', 'something-else'] - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('array'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_CONTENT_OBJECTS = ['ext']; - VALID_CONTENT_OBJECTS.forEach(param => { - it(`should determine that the ortb2.site.content Object key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: {a: '123', b: '456'} - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('object'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - config.setConfig({ortb2: {}}); - }); - }); - }); - - describe('First party data module - "User" support (ortb2):', () => { - // Global ortb2.user validations - // Should not allow invalid "user" data types - const INVALID_ORTB2_TYPES = [ null, [], 'unsupportedKeyName', true, false, undefined ]; - INVALID_ORTB2_TYPES.forEach(param => { - const ortb2 = { user: param } - config.setConfig({ortb2}); - it(`should not allow invalid site types to be added to bid-request: ${JSON.stringify(param)}`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.be.undefined; - }); - }); - - // Should add valid "user" params - const VALID_USER_STRINGS = ['id', 'buyeruid', 'gender', 'keywords', 'customdata']; - VALID_USER_STRINGS.forEach(param => { - it(`should allow supported user string keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: 'something' - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('string'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_NUMBERS = ['yob']; - VALID_USER_NUMBERS.forEach(param => { - it(`should allow supported user number keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: 1982 - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('number'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_ARRAYS = ['data']; - VALID_USER_ARRAYS.forEach(param => { - it(`should allow supported user Array keys to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: ['something'] - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('array'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_OBJECTS = ['ext']; - VALID_USER_OBJECTS.forEach(param => { - it(`should allow supported user extObject keys to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: {a: '123', b: '456'} - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.be.a('object'); - expect(data.user[param]).to.be.deep.include({[param]: {a: '123', b: '456'}}); - config.setConfig({ortb2: {}}); - }); - }); - - // Should allow valid user.data && site.content.data - const VALID_USER_DATA_STRINGS = ['id', 'name']; - VALID_USER_DATA_STRINGS.forEach(param => { - it(`should allow supported user.data & site.content.data strings to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: 'string'}] - }, - site: { - content: { - data: [{[param]: 'string'}] - } - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user.data[0][param]).to.exist; - expect(data.user.data[0][param]).to.be.a('string'); - expect(data.user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - expect(data.site.content.data[0][param]).to.exist; - expect(data.site.content.data[0][param]).to.be.a('string'); - expect(data.site.content.data[0][param]).to.be.equal(ortb2.site.content.data[0][param]); - }); - }); - - const VALID_USER_DATA_ARRAYS = ['segment'] - VALID_USER_DATA_ARRAYS.forEach(param => { - it(`should allow supported user data arrays to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: [{id: 1}]}] - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user.data[0][param]).to.exist; - expect(data.user.data[0][param]).to.be.a('array'); - expect(data.user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - }); - }); - - const VALID_USER_DATA_OBJECTS = ['ext']; - VALID_USER_DATA_OBJECTS.forEach(param => { - it(`should allow supported user data objects to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: {id: 'ext'}}] - } - }; - config.setConfig({ortb2}); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user.data[0][param]).to.exist; - expect(data.user.data[0][param]).to.be.a('object'); - expect(data.user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - config.setConfig({ortb2: {}}); - }); - }); - - // adUnit.ortb2Imp.ext.data - it(`should allow adUnit.ortb2Imp.ext.data object to be added to the bid-request`, () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].ext.data).to.deep.equal(validBidRequests[0].ortb2Imp.ext.data); - }); - // adUnit.ortb2Imp.instl - it(`should allow adUnit.ortb2Imp.instl numeric boolean "1" to be added to the bid-request`, () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: 1 - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.deep.equal(validBidRequests[0].ortb2Imp.instl); - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean "true" to be added to the bid-request`, () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: true - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean "false" to be added to the bid-request`, () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: false - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - }); - - describe('e2etest mode support:', () => { - it(`should override DCN & POS when params.testing.e2etest = "true".`, () => { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const params = { - dcn: '1234', - pos: '5678', - testing: { - e2etest: true - } - } - bidRequest.params = params; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.id).to.be.equal('8a969516017a7a396ec539d97f540011'); - expect(data.imp[0].tagid).to.be.equal('8a969978017a7aaabab4ab0bc01a0009'); - expect(data.imp[0].ext.e2eTestMode).to.be.true; - }); - }); - - describe('GDPR & Consent:', () => { - it('should return request objects that do not send cookies if purpose 1 consent is not provided', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - bidderRequest.gdprConsent = { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - apiVersion: 2, - vendorData: { - purpose: { - consents: { - '1': false - } - } - }, - gdprApplies: true - }; - const options = spec.buildRequests(validBidRequests, bidderRequest)[0].options; - expect(options.withCredentials).to.be.false; - }); - }); - - describe('Endpoint & Impression Request Mode:', () => { - it('should route request to config override endpoint', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const testOverrideEndpoint = 'http://foo.bar.baz.com/bidderRequest'; - config.setConfig({ - yahoossp: { - endpoint: testOverrideEndpoint - } - }); - const response = spec.buildRequests(validBidRequests, bidderRequest)[0]; - expect(response).to.deep.include( - { - method: 'POST', - url: testOverrideEndpoint - }); - }); - - it('should route request to /bidRequest endpoint when dcn & pos present', () => { - config.setConfig({ - yahoossp: {} - }); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const response = spec.buildRequests(validBidRequests, bidderRequest); - expect(response[0]).to.deep.include({ - method: 'POST', - url: 'https://c2shb.pubgw.yahoo.com/bidRequest' - }); - }); - - it('should route request to /partners endpoint when pubId is present', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - const response = spec.buildRequests(validBidRequests, bidderRequest); - expect(response[0]).to.deep.include({ - method: 'POST', - url: 'https://c2shb.pubgw.yahoo.com/admax/bid/partners/PBJS' - }); - }); - - it('should return a single request object for single request mode', () => { - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2}); - validBidRequests = [bidRequest, bidRequest2]; - bidderRequest.bids = validBidRequests; - - config.setConfig({ - yahoossp: { - singleRequestMode: true - } - }); - - const data = spec.buildRequests(validBidRequests, bidderRequest).data; - expect(data.imp).to.be.an('array').with.lengthOf(2); - - expect(data.imp[0]).to.deep.include({ - id: DEFAULT_BID_ID, - ext: { - pos: DEFAULT_BID_POS, - dfp_ad_unit_code: DEFAULT_AD_UNIT_CODE - } - }); - - expect(data.imp[1]).to.deep.include({ - id: BID_ID_2, - ext: { - pos: BID_POS_2, - dfp_ad_unit_code: AD_UNIT_CODE_2 - } - }); - }); - }); - - describe('Validate request filtering:', () => { - it('should not return request when no bids are present', function () { - let request = spec.buildRequests([]); - expect(request).to.be.undefined; - }); - - it('buildRequests(): should return an array with the correct amount of request objects', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const response = spec.buildRequests(validBidRequests, bidderRequest).bidderRequest; - expect(response.bids).to.be.an('array').to.have.lengthOf(1); - }); - }); - - describe('Request Headers validation:', () => { - it('should return request objects with the relevant custom headers and content type declaration', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const options = spec.buildRequests(validBidRequests, bidderRequest).options; - expect(options).to.deep.equal( - { - contentType: 'application/json', - customHeaders: { - 'x-openrtb-version': '2.5' - }, - withCredentials: true - }); - }); - }); - - describe('Request Payload oRTB bid validation:', () => { - it('should generate a valid openRTB bid-request object in the data field', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest).data; - expect(data.site).to.deep.equal({ - id: bidderRequest.bids[0].params.dcn, - page: bidderRequest.refererInfo.referer - }); - - expect(data.device).to.deep.equal({ - dnt: 0, - ua: navigator.userAgent, - ip: undefined - }); - - expect(data.regs).to.deep.equal({ - ext: { - 'us_privacy': '', - gdpr: 1 - } - }); - - expect(data.source).to.deep.equal({ - ext: { - hb: 1, - adapterver: ADAPTER_VERSION, - prebidver: PREBID_VERSION, - integration: { - name: INTEGRATION_METHOD, - ver: PREBID_VERSION - } - }, - fd: 1 - }); - - expect(data.user).to.deep.equal({ - ext: { - consent: bidderRequest.gdprConsent.consentString, - eids: [] - } - }); - - expect(data.cur).to.deep.equal(['USD']); - }); - - it('should generate a valid openRTB imp.ext object in the bid-request', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const bid = validBidRequests[0]; - const data = spec.buildRequests(validBidRequests, bidderRequest).data; - expect(data.imp[0].ext).to.deep.equal({ - pos: bid.params.pos, - dfp_ad_unit_code: DEFAULT_AD_UNIT_CODE - }); - }); - - it('should use siteId value as site.id in the outbound bid-request when using "pubId" integration mode', () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - validBidRequests[0].params.siteId = '1234567'; - const data = spec.buildRequests(validBidRequests, bidderRequest).data; - expect(data.site.id).to.equal('1234567'); - }); - - it('should use placementId value as imp.tagid in the outbound bid-request when using "pubId" integration mode', () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - validBidRequests[0].params.placementId = 'header-300x250'; - const data = spec.buildRequests(validBidRequests, bidderRequest).data; - expect(data.imp[0].tagid).to.deep.equal('header-300x250'); - }); - }); - - describe('Request Payload oRTB bid.imp validation:', () => { - // Validate Banner imp imp when yahoossp.mode=undefined - it('should generate a valid "Banner" imp object', () => { - config.setConfig({ - yahoossp: {} - }); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.not.exist; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - - // Validate Banner imp when yahoossp.mode="banner" - it('should generate a valid "Banner" imp object', () => { - config.setConfig({ - yahoossp: { mode: 'banner' } - }); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.not.exist; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - - // Validate Video imp - it('should generate a valid "Video" only imp object', () => { - config.setConfig({ - yahoossp: { mode: 'video' } - }); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'video'}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].banner).to.not.exist; - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined - }); - }); - - // Validate multi-format Video+banner imp - it('should generate a valid multi-format "Video + Banner" imp object', () => { - config.setConfig({ - yahoossp: { mode: 'all' } - }); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'multi-format'}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined - }); - }); - - // Validate Key-Value Pairs - it('should generate supported String, Number, Array of Strings, Array of Numbers key-value pairs and append to imp.ext.kvs', () => { - let { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].params.kvp = { - key1: 'String', - key2: 123456, - key3: ['String', 'String', 'String'], - key4: [1, 2, 3], - invalidKey1: true, - invalidKey2: null, - invalidKey3: ['string', 1234], - invalidKey4: {a: 1, b: 2}, - invalidKey5: undefined - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - - expect(data.imp[0].ext.kvs).to.deep.equal({ - key1: 'String', - key2: 123456, - key3: ['String', 'String', 'String'], - key4: [1, 2, 3] - }); - }); - }); - - describe('Multiple adUnit validations:', () => { - // Multiple banner adUnits - it('should generate multiple bid-requests for each adUnit - 2 banner only', () => { - config.setConfig({ - yahoossp: { mode: 'banner' } - }); - - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'video-ad-unit'; - - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); // banner - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2}); // banner - const { bidRequest: bidRequest3 } = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3, adUnitType: 'video'}); // video (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const response = spec.buildRequests(validBidRequests, bidderRequest) - expect(response).to.be.a('array'); - expect(response.length).to.equal(2); - response.forEach((obj) => { - expect(obj.data.imp[0].video).to.not.exist - expect(obj.data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - }); - - // Multiple video adUnits - it('should generate multiple bid-requests for each adUnit - 2 video only', () => { - config.setConfig({ - yahoossp: { mode: 'video' } - }); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'video-ad-unit'; - - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'video'}); // video - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2, adUnitType: 'video'}); // video - const { bidRequest: bidRequest3 } = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3}); // banner (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const response = spec.buildRequests(validBidRequests, bidderRequest) - expect(response).to.be.a('array'); - expect(response.length).to.equal(2); - response.forEach((obj) => { - expect(obj.data.imp[0].banner).to.not.exist - expect(obj.data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined - }); - }); - }); - // Mixed adUnits 1-banner, 1-video, 1-native (should filter out native) - it('should generate multiple bid-requests for both "video & banner" adUnits', () => { - config.setConfig({ - yahoossp: { mode: 'all' } - }); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'video-ad-unit'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'native-ad-unit'; - - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'banner'}); // banner - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2, adUnitType: 'video'}); // video - const { bidRequest: bidRequest3 } = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3, adUnitType: 'native'}); // native (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const response = spec.buildRequests(validBidRequests, bidderRequest); - expect(response).to.be.a('array'); - expect(response.length).to.equal(2); - response.forEach((obj) => { - expect(obj.data.imp[0].native).to.not.exist; - }); - - const data1 = response[0].data; - expect(data1.imp[0].video).to.not.exist; - expect(data1.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - - const data2 = response[1].data; - expect(data2.imp[0].banner).to.not.exist; - expect(data2.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined - }); - }); - }); - - describe('Video params firstlook & bidOverride validations:', () => { - it('should first look at params.bidOverride for video placement data', () => { - config.setConfig({ - yahoossp: { mode: 'video' } - }); - const bidOverride = { - imp: { - video: { - mimes: ['video/mp4'], - w: 400, - h: 350, - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - rewarded: 1, - placement: 1 - } - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'video', bidOverrideObject: bidOverride}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.deep.equal(bidOverride.imp.video); - }); - - it('should second look at bid.mediaTypes.video for video placement data', () => { - config.setConfig({ - yahoossp: { mode: 'video' } - }); - let { bidRequest, bidderRequest } = generateBuildRequestMock({adUnitType: 'video'}); - bidRequest.mediaTypes.video = { - mimes: ['video/mp4'], - playerSize: [400, 350], - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - placement: 1 - } - const validBidRequests = [bidRequest]; - bidderRequest.bids = validBidRequests; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4'], - w: 400, - h: 350, - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - placement: 1, - rewarded: undefined - }); - }); - - it('should use params.bidOverride.device.ip override', () => { - config.setConfig({ - yahoossp: { mode: 'all' } - }); - const bidOverride = { - device: { - ip: '1.2.3.4' - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'video', bidOverrideObject: bidOverride}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.device.ip).to.deep.equal(bidOverride.device.ip); - }); - }); - // #endregion buildRequests(): - - describe('interpretResponse()', () => { - describe('for mediaTypes: "banner"', () => { - it('should insert banner payload into response[0].ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].mediaType).to.equal('banner'); - }) - }); - - describe('for mediaTypes: "video"', () => { - it('should insert video VPAID payload into vastXml', () => { - const { serverResponse, bidderRequest } = generateResponseMock('video'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.be.undefined; - expect(response[0].vastXml).to.equal(''); - expect(response[0].mediaType).to.equal('video'); - }) - - it('should insert video VAST win notification into vastUrl', () => { - const { serverResponse, bidderRequest } = generateResponseMock('video', 'vast'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.be.undefined; - expect(response[0].vastUrl).to.equal('https://yahoo.com?event=adAttempt'); - expect(response[0].vastXml).to.equal(''); - expect(response[0].mediaType).to.equal('video'); - }) - - it('should insert video DAP O2 Player into ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('dap-o2', 'vpaid'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].vastUrl).to.be.undefined; - expect(response[0].vastXml).to.be.undefined; - expect(response[0].mediaType).to.equal('banner'); - }); - - it('should insert video DAP Unified Player into ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('dap-up', 'vpaid'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].vastUrl).to.be.undefined; - expect(response[0].vastXml).to.be.undefined; - expect(response[0].mediaType).to.equal('banner'); - }) - }); - - describe('Support Advertiser domains', () => { - it('should append bid-response adomain to meta.advertiserDomains', () => { - const { serverResponse, bidderRequest } = generateResponseMock('video', 'vpaid'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].meta.advertiserDomains).to.be.a('array'); - expect(response[0].meta.advertiserDomains[0]).to.equal('advertiser-domain.com'); - }) - }); - - describe('bid response Ad ID / Creative ID', () => { - it('should use adId if it exists in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const adId = 'bid-response-adId'; - serverResponse.body.seatbid[0].bid[0].adId = adId; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(adId); - }); - - it('should use impid if adId does not exist in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const impid = '25b6c429c1f52f'; - serverResponse.body.seatbid[0].bid[0].impid = impid; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(impid); - }); - - it('should use crid if adId & impid do not exist in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const crid = 'passback-12579'; - serverResponse.body.seatbid[0].bid[0].impid = undefined; - serverResponse.body.seatbid[0].bid[0].crid = crid; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(crid); - }); - }); - - describe('Time To Live (ttl)', () => { - const UNSUPPORTED_TTL_FORMATS = ['string', [1, 2, 3], true, false, null, undefined]; - UNSUPPORTED_TTL_FORMATS.forEach(param => { - it('should not allow unsupported global yahoossp.ttl formats and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - config.setConfig({ - yahoossp: { ttl: param } - }); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not allow unsupported params.ttl formats and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - bidderRequest.bids[0].params.ttl = param; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - const UNSUPPORTED_TTL_VALUES = [-1, 3601]; - UNSUPPORTED_TTL_VALUES.forEach(param => { - it('should not allow invalid global yahoossp.ttl values 3600 < ttl < 0 and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - config.setConfig({ - yahoossp: { ttl: param } - }); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not allow invalid params.ttl values 3600 < ttl < 0 and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - bidderRequest.bids[0].params.ttl = param; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - it('should give presedence to Gloabl ttl over params.ttl ', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - config.setConfig({ - yahoossp: { ttl: 500 } - }); - bidderRequest.bids[0].params.ttl = 400; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(500); - }); - }); - }); -}); diff --git a/test/spec/modules/yieldlabBidAdapter_spec.js b/test/spec/modules/yieldlabBidAdapter_spec.js index f80cad46d50..d150646851f 100644 --- a/test/spec/modules/yieldlabBidAdapter_spec.js +++ b/test/spec/modules/yieldlabBidAdapter_spec.js @@ -1,4 +1,3 @@ -import { config } from 'src/config.js'; import { expect } from 'chai' import { spec } from 'modules/yieldlabBidAdapter.js' import { newBidder } from 'src/adapters/bidderFactory.js' @@ -17,22 +16,7 @@ const REQUEST = { 'extraParam': true, 'foo': 'bar' }, - 'extId': 'abc', - 'iabContent': { - 'id': 'foo_id', - 'episode': '99', - 'title': 'foo_title,bar_title', - 'series': 'foo_series', - 'season': 's1', - 'artist': 'foo bar', - 'genre': 'baz', - 'isrc': 'CC-XXX-YY-NNNNN', - 'url': 'http://foo_url.de', - 'cat': ['cat1', 'cat2,ppp', 'cat3|||//'], - 'context': '7', - 'keywords': ['k1,', 'k2..'], - 'live': '0' - } + 'extId': 'abc' }, 'bidderRequestId': '143346cf0f1731', 'auctionId': '2e41f65424c87c', @@ -73,12 +57,6 @@ const VIDEO_REQUEST = Object.assign({}, REQUEST, { } }) -const NATIVE_REQUEST = Object.assign({}, REQUEST, { - 'mediaTypes': { - 'native': { } - } -}) - const RESPONSE = { advertiser: 'yieldlab', curl: 'https://www.yieldlab.de', @@ -90,42 +68,6 @@ const RESPONSE = { adtype: 'BANNER' } -const NATIVE_RESPONSE = Object.assign({}, RESPONSE, { - 'adtype': 'NATIVE', - 'native': { - 'link': { - 'url': 'https://www.yieldlab.de' - }, - 'assets': [ - { - 'id': 1, - 'title': { - 'text': 'This is a great headline' - } - }, - { - 'id': 2, - 'img': { - 'url': 'https://localhost:8080/yl-logo100x100.jpg', - 'w': 100, - 'h': 100 - } - }, - { - 'id': 3, - 'data': { - 'value': 'Native body value' - } - } - ], - 'imptrackers': [ - 'http://localhost:8080/ve?d=ODE9ZSY2MTI1MjAzNjMzMzYxPXN0JjA0NWUwZDk0NTY5Yi05M2FiLWUwZTQtOWFjNy1hYWY0MzFiZj1kaXQmMj12', - 'http://localhost:8080/md/1111/9efa4e76-2030-4f04-bb9f-322541f8d611?mdata=false&pvid=false&ids=x:1', - 'http://localhost:8080/imp?s=13216&d=2171514&a=12548955&ts=1633363025216&tid=fb134faa-7ca9-4e0e-ba39-b96549d0e540&l=0' - ] - } -}) - const VIDEO_RESPONSE = Object.assign({}, RESPONSE, { 'adtype': 'VIDEO' }) @@ -144,10 +86,6 @@ const REQPARAMS_GDPR = Object.assign({}, REQPARAMS, { consent: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA' }) -const REQPARAMS_IAB_CONTENT = Object.assign({}, REQPARAMS, { - iab_content: 'id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0' -}) - describe('yieldlabBidAdapter', function () { const adapter = newBidder(spec) @@ -201,40 +139,6 @@ describe('yieldlabBidAdapter', function () { expect(request.url).to.include('schain=1.0,1!indirectseller.com,1,1,,,,!indirectseller2.com,2,1,,indirectseller2%20name%20with%20comma%20%2C%20and%20bang%20%21,,') }) - it('passes iab_content string to bid request', function () { - expect(request.url).to.include('iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0') - }) - - const siteConfig = { - 'ortb2': { - 'site': { - 'content': { - 'id': 'id_from_config' - } - } - } - } - - it('generates iab_content string from bidder params', function () { - config.setConfig(siteConfig); - const request = spec.buildRequests([REQUEST]) - expect(request.url).to.include('iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0') - config.resetConfig(); - }) - - it('generates iab_content string from first party data if not provided in bidder params', function () { - const requestWithoutIabContent = { - 'params': { - 'adslotId': '1111', - 'supplyId': '2222' - } - } - config.setConfig(siteConfig); - const request = spec.buildRequests([requestWithoutIabContent]) - expect(request.url).to.include('iab_content=id%3Aid_from_config') - config.resetConfig(); - }) - const refererRequest = spec.buildRequests(bidRequests, { refererInfo: { canonicalUrl: undefined, @@ -299,11 +203,6 @@ describe('yieldlabBidAdapter', function () { expect(result[0].ad).to.include('&consent=BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA') }) - it('should append iab_content to adtag', function () { - const result = spec.interpretResponse({body: [RESPONSE]}, {validBidRequests: [REQUEST], queryParams: REQPARAMS_IAB_CONTENT}) - expect(result[0].ad).to.include('&iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0') - }) - it('should get correct bid response when passing more than one size', function () { const REQUEST2 = Object.assign({}, REQUEST, { 'sizes': [ @@ -339,45 +238,6 @@ describe('yieldlabBidAdapter', function () { expect(result[0].vastUrl).to.include('&id=abc') }) - it('should add adUrl and native assets when type is Native', function () { - const result = spec.interpretResponse({body: [NATIVE_RESPONSE]}, {validBidRequests: [NATIVE_REQUEST], queryParams: REQPARAMS}) - - expect(result[0].requestId).to.equal('2d925f27f5079f') - expect(result[0].cpm).to.equal(0.01) - expect(result[0].mediaType).to.equal('native') - expect(result[0].adUrl).to.include('https://ad.yieldlab.net/d/1111/2222/?ts=') - expect(result[0].native.title).to.equal('This is a great headline') - expect(result[0].native.body).to.equal('Native body value') - expect(result[0].native.image.url).to.equal('https://localhost:8080/yl-logo100x100.jpg') - expect(result[0].native.image.width).to.equal(100) - expect(result[0].native.image.height).to.equal(100) - expect(result[0].native.clickUrl).to.equal('https://www.yieldlab.de') - expect(result[0].native.impressionTrackers.length).to.equal(3) - }) - - it('should add adUrl and default native assets when type is Native', function () { - const NATIVE_RESPONSE_2 = Object.assign({}, NATIVE_RESPONSE, { - 'native': { - 'link': { - 'url': 'https://www.yieldlab.de' - }, - 'assets': [], - 'imptrackers': [] - } - }) - const result = spec.interpretResponse({body: [NATIVE_RESPONSE_2]}, {validBidRequests: [NATIVE_REQUEST], queryParams: REQPARAMS}) - - expect(result[0].requestId).to.equal('2d925f27f5079f') - expect(result[0].cpm).to.equal(0.01) - expect(result[0].mediaType).to.equal('native') - expect(result[0].adUrl).to.include('https://ad.yieldlab.net/d/1111/2222/?ts=') - expect(result[0].native.title).to.equal('') - expect(result[0].native.body).to.equal('') - expect(result[0].native.image.url).to.equal('') - expect(result[0].native.image.width).to.equal(0) - expect(result[0].native.image.height).to.equal(0) - }) - it('should append gdpr parameters to vastUrl', function () { const result = spec.interpretResponse({body: [VIDEO_RESPONSE]}, {validBidRequests: [VIDEO_REQUEST], queryParams: REQPARAMS_GDPR}) @@ -408,10 +268,5 @@ describe('yieldlabBidAdapter', function () { expect(result[0].ad).to.include('&pvid=43513f11-55a0-4a83-94e5-0ebc08f54a2c') expect(result[0].vastUrl).to.include('&pvid=43513f11-55a0-4a83-94e5-0ebc08f54a2c') }) - - it('should append iab_content to vastUrl', function () { - const result = spec.interpretResponse({body: [VIDEO_RESPONSE]}, {validBidRequests: [VIDEO_REQUEST], queryParams: REQPARAMS_IAB_CONTENT}) - expect(result[0].vastUrl).to.include('&iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0') - }) }) }) diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js index 3eee9e44453..378c5d89113 100644 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ b/test/spec/modules/yieldmoBidAdapter_spec.js @@ -307,7 +307,7 @@ describe('YieldmoAdapter', function () { }); it('should only shortcut properties rather then completely remove it', () => { - const longString = new Array(8000).join('a'); + const longString = new Array(7516).join('a'); const localWindow = utils.getWindowTop(); const originalTitle = localWindow.document.title; @@ -319,7 +319,7 @@ describe('YieldmoAdapter', function () { refererInfo: { numIframes: 1, reachedTop: true, - title: longString, + referer: longString, }, }) )[0]; @@ -328,37 +328,6 @@ describe('YieldmoAdapter', function () { localWindow.document.title = originalTitle; }); - - it('should add ats_envelope to banner bid request', function() { - const envelope = 'test_envelope'; - const requests = build([mockBannerBid({}, { lr_env: envelope })]); - - expect(requests[0].data.ats_envelope).to.equal(envelope); - }); - - it('should add gpid to the banner bid request', function () { - let bidArray = [mockBannerBid({ - ortb2Imp: { - ext: { data: { pbadslot: '/6355419/Travel/Europe/France/Paris' } }, - } - })]; - let placementInfo = buildAndGetPlacementInfo(bidArray); - expect(placementInfo).to.include('"gpid":"/6355419/Travel/Europe/France/Paris"'); - }); - - it('should add eids to the banner bid request', function () { - const params = { - userId: {pubcid: 'fake_pubcid'}, - fakeUserIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - id: 'fake_pubcid', - atype: 1 - }] - }] - }; - expect(buildAndGetData([mockBannerBid({...params})]).eids).equal(JSON.stringify(params.fakeUserIdAsEids)); - }); }); describe('Instream video:', function () { @@ -470,38 +439,11 @@ describe('YieldmoAdapter', function () { expect(requests[0].data.ats_envelope).to.equal(envelope); }); - it('should add schain if it is in the bidRequest', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - }], - }; - expect(buildAndGetData([mockVideoBid({schain})]).schain).to.deep.equal(schain); - }); + it('should add ats_envelope to banner bid request', function() { + const envelope = 'test_envelope'; + const requests = build([mockBannerBid({}, { lr_env: envelope })]); - it('should add gpid to the video request', function () { - const ortb2Imp = { - ext: { data: { pbadslot: '/6355419/Travel/Europe/France/Paris' } }, - }; - expect(buildAndGetData([mockVideoBid({ortb2Imp})]).imp[0].ext.gpid).to.be.equal(ortb2Imp.ext.data.pbadslot); - }); - - it('should add eids to the video bid request', function () { - const params = { - userId: {pubcid: 'fake_pubcid'}, - fakeUserIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - id: 'fake_pubcid', - atype: 1 - }] - }] - }; - expect(buildAndGetData([mockVideoBid({...params})]).user.eids).to.eql(params.fakeUserIdAsEids); + expect(requests[0].data.ats_envelope).to.equal(envelope); }); }); }); diff --git a/test/spec/modules/yieldmoSyntheticInventoryModule_spec.js b/test/spec/modules/yieldmoSyntheticInventoryModule_spec.js deleted file mode 100644 index 55b4e7255f7..00000000000 --- a/test/spec/modules/yieldmoSyntheticInventoryModule_spec.js +++ /dev/null @@ -1,89 +0,0 @@ -import { expect } from 'chai'; -import { - init, - MODULE_NAME, - validateConfig -} from 'modules/yieldmoSyntheticInventoryModule'; - -const mockedYmConfig = { - placementId: '123456', - adUnitPath: '/6355419/ad_unit_name_used_in_gam' -}; - -const setGoogletag = () => { - window.googletag = { - cmd: [], - defineSlot: sinon.stub(), - addService: sinon.stub(), - pubads: sinon.stub(), - setTargeting: sinon.stub(), - enableServices: sinon.stub(), - display: sinon.stub(), - }; - window.googletag.defineSlot.returns(window.googletag); - window.googletag.addService.returns(window.googletag); - window.googletag.pubads.returns({getSlots: sinon.stub()}); - return window.googletag; -} - -describe('Yieldmo Synthetic Inventory Module', function() { - let config = Object.assign({}, mockedYmConfig); - let googletagBkp; - - beforeEach(function () { - googletagBkp = window.googletag; - delete window.googletag; - }); - - afterEach(function () { - window.googletag = googletagBkp; - }); - - it('should be enabled with valid required params', function() { - expect(function () { - init(mockedYmConfig); - }).not.to.throw() - }); - - it('should throw an error if placementId is missed', function() { - const {placementId, ...config} = mockedYmConfig; - - expect(function () { - validateConfig(config); - }).throw(`${MODULE_NAME}: placementId required`) - }); - - it('should throw an error if adUnitPath is missed', function() { - const {adUnitPath, ...config} = mockedYmConfig; - - expect(function () { - validateConfig(config); - }).throw(`${MODULE_NAME}: adUnitPath required`) - }); - - it('should add correct googletag.cmd', function() { - const containerName = 'ym_sim_container_' + mockedYmConfig.placementId; - const gtag = setGoogletag(); - - init(mockedYmConfig); - - expect(gtag.cmd.length).to.equal(1); - - gtag.cmd[0](); - - expect(gtag.addService.getCall(0)).to.not.be.null; - expect(gtag.setTargeting.getCall(0)).to.not.be.null; - expect(gtag.setTargeting.getCall(0).args[0]).to.exist.and.to.equal('ym_sim_p_id'); - expect(gtag.setTargeting.getCall(0).args[1]).to.exist.and.to.equal(mockedYmConfig.placementId); - expect(gtag.defineSlot.getCall(0)).to.not.be.null; - expect(gtag.enableServices.getCall(0)).to.not.be.null; - expect(gtag.display.getCall(0)).to.not.be.null; - expect(gtag.display.getCall(0).args[0]).to.exist.and.to.equal(containerName); - expect(gtag.pubads.getCall(0)).to.not.be.null; - - const gamContainerEl = window.document.getElementById(containerName); - expect(gamContainerEl).to.not.be.null; - - gamContainerEl.parentNode.removeChild(gamContainerEl); - }); -}); diff --git a/test/spec/modules/yieldoneBidAdapter_spec.js b/test/spec/modules/yieldoneBidAdapter_spec.js index 1b38bb94a8c..4186c5da41a 100644 --- a/test/spec/modules/yieldoneBidAdapter_spec.js +++ b/test/spec/modules/yieldoneBidAdapter_spec.js @@ -7,8 +7,6 @@ const ENDPOINT = 'https://y.one.impact-ad.jp/h_bid'; const USER_SYNC_URL = 'https://y.one.impact-ad.jp/push_sync'; const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/dac-video-prebid.min.js'; -const DEFAULT_VIDEO_SIZE = {w: 640, h: 360}; - describe('yieldoneBidAdapter', function() { const adapter = newBidder(spec); @@ -42,7 +40,32 @@ describe('yieldoneBidAdapter', function() { }); describe('buildRequests', function () { - const bidderRequest = { + let bidRequests = [ + { + 'bidder': 'yieldone', + 'params': { + placementId: '36891' + }, + 'adUnitCode': 'adunit-code1', + 'sizes': [[300, 250], [336, 280]], + 'bidId': '23beaa6af6cdde', + 'bidderRequestId': '19c0c1efdf37e7', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + }, + { + 'bidder': 'yieldone', + 'params': { + placementId: '47919' + }, + 'adUnitCode': 'adunit-code2', + 'sizes': [[300, 250]], + 'bidId': '382091349b149f"', + 'bidderRequestId': '"1f9c98192de251"', + 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', + } + ]; + + let bidderRequest = { refererInfo: { numIframes: 0, reachedTop: true, @@ -51,318 +74,49 @@ describe('yieldoneBidAdapter', function() { } }; - describe('Basic', function () { - const bidRequests = [ - { - 'bidder': 'yieldone', - 'params': {placementId: '36891'}, - 'adUnitCode': 'adunit-code1', - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }, - { - 'bidder': 'yieldone', - 'params': {placementId: '47919'}, - 'adUnitCode': 'adunit-code2', - 'bidId': '382091349b149f"', - 'bidderRequestId': '"1f9c98192de251"', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - } - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); + const request = spec.buildRequests(bidRequests, bidderRequest); - it('sends bid request to our endpoint via GET', function () { - expect(request[0].method).to.equal('GET'); - expect(request[1].method).to.equal('GET'); - }); - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT); - expect(request[1].url).to.equal(ENDPOINT); - }); - it('adUnitCode should be sent as uc parameters on any requests', function () { - expect(request[0].data.uc).to.equal('adunit-code1'); - expect(request[1].data.uc).to.equal('adunit-code2'); - }); + it('sends bid request to our endpoint via GET', function () { + expect(request[0].method).to.equal('GET'); + expect(request[1].method).to.equal('GET'); }); - describe('Old Format', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - mediaType: 'banner', - sizes: [[300, 250], [336, 280]], - }, - { - params: {placementId: '1'}, - mediaType: 'banner', - sizes: [[336, 280]], - }, - { - // It doesn't actually exist. - params: {placementId: '2'}, - }, - { - params: {placementId: '3'}, - mediaType: 'video', - sizes: [[1280, 720], [1920, 1080]], - }, - { - params: {placementId: '4'}, - mediaType: 'video', - sizes: [[1920, 1080]], - }, - { - params: {placementId: '5'}, - mediaType: 'video', - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data.sz).to.equal('336x280'); - expect(request[2].data.sz).to.equal(''); - expect(request[3].data).to.not.have.property('sz'); - expect(request[4].data).to.not.have.property('sz'); - expect(request[5].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[1].data).to.not.have.property('w'); - expect(request[2].data).to.not.have.property('w'); - expect(request[3].data.w).to.equal(1280); - expect(request[3].data.h).to.equal(720); - expect(request[4].data.w).to.equal(1920); - expect(request[4].data.h).to.equal(1080); - expect(request[5].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[5].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); + it('attaches source and version to endpoint URL as query params', function () { + expect(request[0].url).to.equal(ENDPOINT); + expect(request[1].url).to.equal(ENDPOINT); }); - describe('New Format', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - }, - }, - { - params: {placementId: '1'}, - mediaTypes: { - banner: { - sizes: [[336, 280]], - }, - }, - }, - { - // It doesn't actually exist. - params: {placementId: '2'}, - mediaTypes: { - banner: { - }, - }, - }, - { - params: {placementId: '3'}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[1280, 720], [1920, 1080]], - }, - }, - }, - { - params: {placementId: '4'}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - { - params: {placementId: '5'}, - mediaTypes: { - video: { - context: 'outstream', - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data.sz).to.equal('336x280'); - expect(request[2].data.sz).to.equal(''); - expect(request[3].data).to.not.have.property('sz'); - expect(request[4].data).to.not.have.property('sz'); - expect(request[5].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[1].data).to.not.have.property('w'); - expect(request[2].data).to.not.have.property('w'); - expect(request[3].data.w).to.equal(1280); - expect(request[3].data.h).to.equal(720); - expect(request[4].data.w).to.equal(1920); - expect(request[4].data.h).to.equal(1080); - expect(request[5].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[5].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); + it('parameter sz has more than one size on banner requests', function () { + expect(request[0].data.sz).to.equal('300x250,336x280'); + expect(request[1].data.sz).to.equal('300x250'); }); - describe('Multiple Format', function () { - const bidRequests = [ - { - // It will be treated as a banner. - params: { - placementId: '0', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '1', - playerParams: {}, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[1].data.w).to.equal(1920); - expect(request[1].data.h).to.equal(1080); - }); + it('width and height should be set as separate parameters on outstream requests', function () { + const bidRequest = Object.assign({}, bidRequests[0]); + bidRequest.mediaTypes = {}; + bidRequest.mediaTypes.video = {context: 'outstream'}; + const request = spec.buildRequests([bidRequest], bidderRequest); + expect(request[0].data.w).to.equal('300'); + expect(request[0].data.h).to.equal('250'); }); - describe('FLUX Format', function () { - const bidRequests = [ - { - // It will be treated as a banner. - params: { - placementId: '0', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '1', - playerParams: {}, - playerSize: [1920, 1080], - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '2', - playerParams: {}, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data).to.not.have.property('sz'); - expect(request[2].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[1].data.w).to.equal(1920); - expect(request[1].data.h).to.equal(1080); - expect(request[2].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[2].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); + it('adUnitCode should be sent as uc parameters on any requests', function () { + expect(request[0].data.uc).to.equal('adunit-code1'); + expect(request[1].data.uc).to.equal('adunit-code2'); }); - describe('LiveRampID', function () { + describe('userid idl_env should be passed to querystring', function () { + const bid = deepClone([bidRequests[0]]); + it('dont send LiveRampID if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); + bid[0].userId = {}; + const request = spec.buildRequests(bid, bidderRequest); expect(request[0].data).to.not.have.property('lr_env'); - expect(request[1].data).to.not.have.property('lr_env'); - expect(request[2].data).to.not.have.property('lr_env'); }); it('should send LiveRampID if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {idl_env: 'idl_env_sample'}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); + bid[0].userId = {idl_env: 'idl_env_sample'}; + const request = spec.buildRequests(bid, bidderRequest); expect(request[0].data.lr_env).to.equal('idl_env_sample'); }); }); diff --git a/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js b/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js deleted file mode 100644 index 15a1155f378..00000000000 --- a/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js +++ /dev/null @@ -1,427 +0,0 @@ -import zetaAnalyticsAdapter from 'modules/zeta_global_sspAnalyticsAdapter.js'; -import {config} from 'src/config'; -import CONSTANTS from 'src/constants.json'; -import {logError} from '../../../src/utils'; - -let utils = require('src/utils'); -let events = require('src/events'); - -const MOCK = { - STUB: { - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' - }, - AUCTION_END: { - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'timestamp': 1638441234544, - 'auctionEnd': 1638441234784, - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': '/19968336/header-bid-tag-0', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'zeta_global_ssp', - 'params': { - 'sid': 111, - 'tags': { - 'shortname': 'prebid_analytics_event_test_shortname', - 'position': 'test_position' - } - } - }, - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - } - } - ], - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'transactionId': '6b29369c-0c2e-414e-be1f-5867aec18d83' - } - ], - 'adUnitCodes': [ - '/19968336/header-bid-tag-0' - ], - 'bidderRequests': [ - { - 'bidderCode': 'zeta_global_ssp', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'bidderRequestId': '1207cb49191887', - 'bids': [ - { - 'bidder': 'zeta_global_ssp', - 'params': { - 'sid': 111, - 'tags': { - 'shortname': 'prebid_analytics_event_test_shortname', - 'position': 'test_position' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c-0c2e-414e-be1f-5867aec18d83', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '206be9a13236af', - 'bidderRequestId': '1207cb49191887', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1638441234544, - 'timeout': 400, - 'refererInfo': { - 'referer': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1638441234547 - }, - { - 'bidderCode': 'appnexus', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'bidderRequestId': '32b97f0a935422', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c-0c2e-414e-be1f-5867aec18d83', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1638441234544, - 'timeout': 400, - 'refererInfo': { - 'referer': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1638441234550 - } - ], - 'noBids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c-0c2e-414e-be1f-5867aec18d83', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'bidsReceived': [ - { - 'bidderCode': 'zeta_global_ssp', - 'width': 480, - 'height': 320, - 'statusMessage': 'Bid available', - 'adId': '5759bb3ef7be1e8', - 'requestId': '206be9a13236af', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 2.258302852806723, - 'currency': 'USD', - 'ad': 'test_ad', - 'ttl': 200, - 'creativeId': '456456456', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'viaplay.fi' - ] - }, - 'originalCpm': 2.258302852806723, - 'originalCurrency': 'USD', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'responseTimestamp': 1638441234670, - 'requestTimestamp': 1638441234547, - 'bidder': 'zeta_global_ssp', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 123, - 'pbLg': '2.00', - 'pbMg': '2.20', - 'pbHg': '2.25', - 'pbAg': '2.25', - 'pbDg': '2.25', - 'pbCg': '', - 'size': '480x320', - 'adserverTargeting': { - 'hb_bidder': 'zeta_global_ssp', - 'hb_adid': '5759bb3ef7be1e8', - 'hb_pb': '2.20', - 'hb_size': '480x320', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'viaplay.fi' - } - } - ], - 'winningBids': [], - 'timeout': 400 - }, - AD_RENDER_SUCCEEDED: { - 'doc': { - 'location': { - 'href': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'protocol': 'http:', - 'host': 'localhost:63342', - 'hostname': 'localhost', - 'port': '63342', - 'pathname': '/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'hash': '', - 'origin': 'http://test-zeta-ssp.net:63342', - 'ancestorOrigins': { - '0': 'http://test-zeta-ssp.net:63342' - } - } - }, - 'bid': { - 'bidderCode': 'zeta_global_ssp', - 'width': 480, - 'height': 320, - 'statusMessage': 'Bid available', - 'adId': '5759bb3ef7be1e8', - 'requestId': '206be9a13236af', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 2.258302852806723, - 'currency': 'USD', - 'ad': 'test_ad', - 'ttl': 200, - 'creativeId': '456456456', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'viaplay.fi' - ] - }, - 'originalCpm': 2.258302852806723, - 'originalCurrency': 'USD', - 'auctionId': '75e394d9-ccce-4978-9238-91e6a1ac88a1', - 'responseTimestamp': 1638441234670, - 'requestTimestamp': 1638441234547, - 'bidder': 'zeta_global_ssp', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 123, - 'pbLg': '2.00', - 'pbMg': '2.20', - 'pbHg': '2.25', - 'pbAg': '2.25', - 'pbDg': '2.25', - 'pbCg': '', - 'size': '480x320', - 'adserverTargeting': { - 'hb_bidder': 'zeta_global_ssp', - 'hb_adid': '5759bb3ef7be1e8', - 'hb_pb': '2.20', - 'hb_size': '480x320', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'viaplay.fi' - }, - 'status': 'rendered', - 'params': [ - { - 'sid': 111, - 'tags': { - 'shortname': 'prebid_analytics_event_test_shortname', - 'position': 'test_position' - } - } - ] - }, - 'adId': '5759bb3ef7be1e8' - } -} - -describe('Zeta Global SSP Analytics Adapter', function() { - let sandbox; - let xhr; - let requests; - - beforeEach(function() { - sandbox = sinon.sandbox.create(); - requests = []; - xhr = sandbox.useFakeXMLHttpRequest(); - xhr.onCreate = request => requests.push(request); - sandbox.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - }); - - it('should require publisherId', function () { - sandbox.stub(utils, 'logError'); - zetaAnalyticsAdapter.enableAnalytics({ - options: {} - }); - expect(utils.logError.called).to.equal(true); - }); - - describe('handle events', function() { - beforeEach(function() { - zetaAnalyticsAdapter.enableAnalytics({ - options: { - sid: 111 - } - }); - }); - - afterEach(function () { - zetaAnalyticsAdapter.disableAnalytics(); - }); - - it('events are sent', function() { - this.timeout(5000); - events.emit(CONSTANTS.EVENTS.AUCTION_INIT, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.AUCTION_END, MOCK.AUCTION_END); - events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BID_TIMEOUT, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BID_REQUESTED, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BID_RESPONSE, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.NO_BID, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BID_WON, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BIDDER_DONE, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BIDDER_ERROR, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.SET_TARGETING, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BEFORE_REQUEST_BIDS, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.REQUEST_BIDS, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.ADD_AD_UNITS, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.AD_RENDER_FAILED, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.AD_RENDER_SUCCEEDED, MOCK.AD_RENDER_SUCCEEDED); - events.emit(CONSTANTS.EVENTS.TCF2_ENFORCEMENT, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.AUCTION_DEBUG, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.BID_VIEWABLE, MOCK.STUB); - events.emit(CONSTANTS.EVENTS.STALE_RENDER, MOCK.STUB); - - expect(requests.length).to.equal(2); - expect(JSON.parse(requests[0].requestBody)).to.deep.equal(MOCK.AUCTION_END); - expect(JSON.parse(requests[1].requestBody)).to.deep.equal(MOCK.AD_RENDER_SUCCEEDED); - }); - }); -}); diff --git a/test/spec/modules/zeta_global_sspBidAdapter_spec.js b/test/spec/modules/zeta_global_sspBidAdapter_spec.js index 7d4a115958e..740ea855fca 100644 --- a/test/spec/modules/zeta_global_sspBidAdapter_spec.js +++ b/test/spec/modules/zeta_global_sspBidAdapter_spec.js @@ -1,5 +1,4 @@ import {spec} from '../../../modules/zeta_global_sspBidAdapter.js' -import {BANNER, VIDEO} from '../../../src/mediaTypes'; describe('Zeta Ssp Bid Adapter', function () { const eids = [ @@ -56,36 +55,6 @@ describe('Zeta Ssp Bid Adapter', function () { userIdAsEids: eids }]; - const videoRequest = [{ - bidId: 112233, - auctionId: 667788, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[720, 340]], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - protocols: [2, 3] - } - }, - refererInfo: { - referer: 'http://www.zetaglobal.com/page?param=video' - }, - params: { - placement: 111, - user: { - uid: 222, - buyeruid: 333 - }, - tags: { - someTag: 444, - sid: 'publisherId' - }, - test: 1 - }, - }]; - it('Test the bid validation function', function () { const validBid = spec.isBidRequestValid(bannerRequest[0]); const invalidBid = spec.isBidRequestValid(null); @@ -144,22 +113,7 @@ describe('Zeta Ssp Bid Adapter', function () { 'https://example2.com' ], h: 150, - w: 200, - ext: { - bidtype: 'video' - } - }, - { - id: 'auctionId3', - impid: 'impId3', - price: 0.2, - adm: '', - crid: 'creativeId3', - adomain: [ - 'https://example3.com' - ], - h: 400, - w: 300 + w: 200 } ] } @@ -175,8 +129,6 @@ describe('Zeta Ssp Bid Adapter', function () { const receivedBid1 = response.body.seatbid[0].bid[0]; expect(bid1).to.not.be.empty; expect(bid1.ad).to.equal(receivedBid1.adm); - expect(bid1.vastXml).to.be.undefined; - expect(bid1.mediaType).to.equal(BANNER); expect(bid1.cpm).to.equal(receivedBid1.price); expect(bid1.height).to.equal(receivedBid1.h); expect(bid1.width).to.equal(receivedBid1.w); @@ -187,25 +139,11 @@ describe('Zeta Ssp Bid Adapter', function () { const receivedBid2 = response.body.seatbid[0].bid[1]; expect(bid2).to.not.be.empty; expect(bid2.ad).to.equal(receivedBid2.adm); - expect(bid2.vastXml).to.equal(receivedBid2.adm); - expect(bid2.mediaType).to.equal(VIDEO); expect(bid2.cpm).to.equal(receivedBid2.price); expect(bid2.height).to.equal(receivedBid2.h); expect(bid2.width).to.equal(receivedBid2.w); expect(bid2.requestId).to.equal(receivedBid2.impid); expect(bid2.meta.advertiserDomains).to.equal(receivedBid2.adomain); - - const bid3 = bidResponse[2]; - const receivedBid3 = response.body.seatbid[0].bid[2]; - expect(bid3).to.not.be.empty; - expect(bid3.ad).to.equal(receivedBid3.adm); - expect(bid3.vastXml).to.equal(receivedBid3.adm); - expect(bid3.mediaType).to.equal(VIDEO); - expect(bid3.cpm).to.equal(receivedBid3.price); - expect(bid3.height).to.equal(receivedBid3.h); - expect(bid3.width).to.equal(receivedBid3.w); - expect(bid3.requestId).to.equal(receivedBid3.impid); - expect(bid3.meta.advertiserDomains).to.equal(receivedBid3.adomain); }); it('Different cases for user syncs', function () { @@ -248,18 +186,4 @@ describe('Zeta Ssp Bid Adapter', function () { expect(payload.user.buyeruid).to.eql(333); expect(payload.user.ext.consent).to.eql('consentString'); }); - - it('Test video object', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].video.minduration).to.eql(videoRequest[0].mediaTypes.video.minduration); - expect(payload.imp[0].video.maxduration).to.eql(videoRequest[0].mediaTypes.video.maxduration); - expect(payload.imp[0].video.protocols).to.eql(videoRequest[0].mediaTypes.video.protocols); - expect(payload.imp[0].video.mimes).to.eql(videoRequest[0].mediaTypes.video.mimes); - expect(payload.imp[0].video.w).to.eql(720); - expect(payload.imp[0].video.h).to.eql(340); - - expect(payload.imp[0].banner).to.be.undefined; - }); }); diff --git a/test/spec/unit/core/adapterManager_spec.js b/test/spec/unit/core/adapterManager_spec.js index f414febcebe..f33c9139e5f 100644 --- a/test/spec/unit/core/adapterManager_spec.js +++ b/test/spec/unit/core/adapterManager_spec.js @@ -162,7 +162,7 @@ describe('adapterManager tests', function () { 'bidderCode': 'appnexus', 'auctionId': '1863e370099523', 'bidderRequestId': '2946b569352ef2', - 'uniquePbsTid': '34566b569352ef2', + 'tid': '34566b569352ef2', 'bids': [ { 'bidder': 'appnexus', @@ -436,38 +436,6 @@ describe('adapterManager tests', function () { }); }); // end onBidViewable - describe('onBidderError', function () { - const bidder = 'appnexus'; - const appnexusSpec = { onBidderError: sinon.stub() }; - const appnexusAdapter = { - bidder, - getSpec: function() { return appnexusSpec; }, - } - before(function () { - config.setConfig({s2sConfig: { enabled: false }}); - }); - - beforeEach(function () { - adapterManager.bidderRegistry[bidder] = appnexusAdapter; - }); - - afterEach(function () { - delete adapterManager.bidderRegistry[bidder]; - }); - - it('should call spec\'s onBidderError callback when callBidderError is called', function () { - const bidRequests = getBidRequests(); - const bidderRequest = find(bidRequests, bidRequest => bidRequest.bidderCode === bidder); - const xhrErrorMock = { - status: 500, - statusText: 'Internal Server Error' - }; - adapterManager.callBidderError(bidder, xhrErrorMock, bidderRequest); - sinon.assert.calledOnce(appnexusSpec.onBidderError); - sinon.assert.calledWithExactly(appnexusSpec.onBidderError, { error: xhrErrorMock, bidderRequest }); - }); - }); // end onBidderError - describe('S2S tests', function () { beforeEach(function () { config.setConfig({s2sConfig: CONFIG}); @@ -479,7 +447,7 @@ describe('adapterManager tests', function () { 'bidderCode': 'appnexus', 'auctionId': '1863e370099523', 'bidderRequestId': '2946b569352ef2', - 'uniquePbsTid': '34566b569352ef2', + 'tid': '34566b569352ef2', 'timeout': 1000, 'src': 's2s', 'adUnitsS2SCopy': [ @@ -708,7 +676,7 @@ describe('adapterManager tests', function () { 'bidderCode': 'appnexus', 'auctionId': '1863e370099523', 'bidderRequestId': '2946b569352ef2', - 'uniquePbsTid': '34566b569352ef2', + 'tid': '34566b569352ef2', 'timeout': 1000, 'src': 's2s', 'adUnitsS2SCopy': [ @@ -844,7 +812,7 @@ describe('adapterManager tests', function () { 'bidderCode': 'pubmatic', 'auctionId': '1863e370099523', 'bidderRequestId': '2946b569352ef2', - 'uniquePbsTid': '2342342342lfi23', + 'tid': '2342342342lfi23', 'timeout': 1000, 'src': 's2s', 'adUnitsS2SCopy': [ @@ -1041,21 +1009,6 @@ describe('adapterManager tests', function () { sinon.assert.calledTwice(prebidServerAdapterMock.callBids); }); - it('should have one tid for ALL s2s bidRequests', function () { - let adUnits = utils.deepClone(getAdUnits()).map(adUnit => { - adUnit.bids = adUnit.bids.filter(bid => includes(['appnexus', 'pubmatic'], bid.bidder)); - return adUnit; - }) - let bidRequests = adapterManager.makeBidRequests(adUnits, 1111, 2222, 1000); - adapterManager.callBids(adUnits, bidRequests, () => {}, () => {}); - sinon.assert.calledTwice(prebidServerAdapterMock.callBids); - const firstBid = prebidServerAdapterMock.callBids.firstCall.args[0]; - const secondBid = prebidServerAdapterMock.callBids.secondCall.args[0]; - - // TIDS should be the same - expect(firstBid.tid).to.equal(secondBid.tid); - }); - it('should fire for simultaneous s2s and client requests', function () { adapterManager.bidderRegistry['adequant'] = adequantAdapterMock; let adUnits = utils.deepClone(getAdUnits()).map(adUnit => { @@ -1712,17 +1665,14 @@ describe('adapterManager tests', function () { }); describe('sizeMapping', function () { - let sandbox; beforeEach(function () { - sandbox = sinon.sandbox.create(); allS2SBidders.length = 0; clientTestAdapters.length = 0; - // always have matchMedia return true for us - sandbox.stub(utils.getWindowTop(), 'matchMedia').callsFake(() => ({matches: true})); + sinon.stub(window, 'matchMedia').callsFake(() => ({matches: true})); }); afterEach(function () { - sandbox.restore(); + matchMedia.restore(); config.resetConfig(); setSizeConfig([]); }); diff --git a/test/spec/unit/core/bidderFactory_spec.js b/test/spec/unit/core/bidderFactory_spec.js index 4dc79deaf85..a7e8a0d7871 100644 --- a/test/spec/unit/core/bidderFactory_spec.js +++ b/test/spec/unit/core/bidderFactory_spec.js @@ -6,8 +6,6 @@ import { userSync } from 'src/userSync.js' import * as utils from 'src/utils.js'; import { config } from 'src/config.js'; import { server } from 'test/mocks/xhr.js'; -import CONSTANTS from 'src/constants.json'; -import events from 'src/events.js'; const CODE = 'sampleBidder'; const MOCK_BIDS_REQUEST = { @@ -316,28 +314,6 @@ describe('bidders created by newBidder', function () { expect(addBidResponseStub.callCount).to.equal(0); }); - - it('should emit BEFORE_BIDDER_HTTP events before network requests', function () { - const bidder = newBidder(spec); - const req = { - method: 'POST', - url: 'test.url.com', - data: { arg: 2 } - }; - - spec.isBidRequestValid.returns(true); - spec.buildRequests.returns([req, req]); - - const eventEmitterSpy = sinon.spy(events, 'emit'); - bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback); - - expect(ajaxStub.calledTwice).to.equal(true); - expect(eventEmitterSpy.getCalls() - .filter(call => call.args[0] === CONSTANTS.EVENTS.BEFORE_BIDDER_HTTP) - ).to.length(2); - - eventEmitterSpy.restore(); - }); }); describe('when the ajax call succeeds', function () { @@ -552,27 +528,17 @@ describe('bidders created by newBidder', function () { describe('when the ajax call fails', function () { let ajaxStub; - let callBidderErrorStub; - let eventEmitterStub; - let xhrErrorMock = { - status: 500, - statusText: 'Internal Server Error' - }; beforeEach(function () { ajaxStub = sinon.stub(ajax, 'ajax').callsFake(function(url, callbacks) { - callbacks.error('ajax call failed.', xhrErrorMock); + callbacks.error('ajax call failed.'); }); - callBidderErrorStub = sinon.stub(adapterManager, 'callBidderError'); - eventEmitterStub = sinon.stub(events, 'emit'); addBidResponseStub.reset(); doneStub.reset(); }); afterEach(function () { ajaxStub.restore(); - callBidderErrorStub.restore(); - eventEmitterStub.restore(); }); it('should not spec.interpretResponse()', function () { @@ -590,14 +556,6 @@ describe('bidders created by newBidder', function () { expect(spec.interpretResponse.called).to.equal(false); expect(doneStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.firstCall.args[0]).to.equal(CODE); - expect(callBidderErrorStub.firstCall.args[1]).to.equal(xhrErrorMock); - expect(callBidderErrorStub.firstCall.args[2]).to.equal(MOCK_BIDS_REQUEST); - sinon.assert.calledWith(eventEmitterStub, CONSTANTS.EVENTS.BIDDER_ERROR, { - error: xhrErrorMock, - bidderRequest: MOCK_BIDS_REQUEST - }); }); it('should not add bids for each adunit code into the auction', function () { @@ -616,40 +574,6 @@ describe('bidders created by newBidder', function () { expect(addBidResponseStub.callCount).to.equal(0); expect(doneStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.firstCall.args[0]).to.equal(CODE); - expect(callBidderErrorStub.firstCall.args[1]).to.equal(xhrErrorMock); - expect(callBidderErrorStub.firstCall.args[2]).to.equal(MOCK_BIDS_REQUEST); - sinon.assert.calledWith(eventEmitterStub, CONSTANTS.EVENTS.BIDDER_ERROR, { - error: xhrErrorMock, - bidderRequest: MOCK_BIDS_REQUEST - }); - }); - - it('should call spec.getUserSyncs() with no responses', function () { - const bidder = newBidder(spec); - - spec.isBidRequestValid.returns(true); - spec.buildRequests.returns({ - method: 'POST', - url: 'test.url.com', - data: {} - }); - spec.getUserSyncs.returns([]); - - bidder.callBids(MOCK_BIDS_REQUEST, addBidResponseStub, doneStub, ajaxStub, onTimelyResponseStub, wrappedCallback); - - expect(spec.getUserSyncs.calledOnce).to.equal(true); - expect(spec.getUserSyncs.firstCall.args[1]).to.deep.equal([]); - expect(doneStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.firstCall.args[0]).to.equal(CODE); - expect(callBidderErrorStub.firstCall.args[1]).to.equal(xhrErrorMock); - expect(callBidderErrorStub.firstCall.args[2]).to.equal(MOCK_BIDS_REQUEST); - sinon.assert.calledWith(eventEmitterStub, CONSTANTS.EVENTS.BIDDER_ERROR, { - error: xhrErrorMock, - bidderRequest: MOCK_BIDS_REQUEST - }); }); it('should call spec.getUserSyncs() with no responses', function () { @@ -668,14 +592,6 @@ describe('bidders created by newBidder', function () { expect(spec.getUserSyncs.calledOnce).to.equal(true); expect(spec.getUserSyncs.firstCall.args[1]).to.deep.equal([]); expect(doneStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.calledOnce).to.equal(true); - expect(callBidderErrorStub.firstCall.args[0]).to.equal(CODE); - expect(callBidderErrorStub.firstCall.args[1]).to.equal(xhrErrorMock); - expect(callBidderErrorStub.firstCall.args[2]).to.equal(MOCK_BIDS_REQUEST); - sinon.assert.calledWith(eventEmitterStub, CONSTANTS.EVENTS.BIDDER_ERROR, { - error: xhrErrorMock, - bidderRequest: MOCK_BIDS_REQUEST - }); }); }); }); diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index 4eaf414bf85..f83bd2f6635 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -5,7 +5,6 @@ import { createBidReceived } from 'test/fixtures/fixtures.js'; import CONSTANTS from 'src/constants.json'; import { auctionManager } from 'src/auctionManager.js'; import * as utils from 'src/utils.js'; -import {deepClone} from 'src/utils.js'; const bid1 = { 'bidderCode': 'rubicon', @@ -310,10 +309,10 @@ describe('targeting tests', function () { ['string', '2.3', '2.3'], ['number', 2.3, '2.3'], ['boolean', true, 'true'], - ['string-separated', '2.3, 4.5', '2.3,4.5'], - ['array-of-string', ['2.3', '4.5'], '2.3,4.5'], - ['array-of-number', [2.3, 4.5], '2.3,4.5'], - ['array-of-boolean', [true, false], 'true,false'] + ['string-separated', '2.3,4.5', '2.3, 4.5'], + ['array-of-string', ['2.3', '4.5'], '2.3, 4.5'], + ['array-of-number', [2.3, 4.5], '2.3, 4.5'], + ['array-of-boolean', [true, false], 'true, false'] ]; pairs.forEach(([type, value, result]) => { it(`accepts ${type}`, function() { @@ -462,50 +461,6 @@ describe('targeting tests', function () { }); }); - describe('targetingControls.allowZeroCpmBids', function () { - let bid4; - let bidderSettingsStorage; - - before(function() { - bidderSettingsStorage = $$PREBID_GLOBAL$$.bidderSettings; - }); - - beforeEach(function () { - bid4 = utils.deepClone(bid1); - bid4.adserverTargeting = { - hb_pb: '0.0', - hb_adid: '567891011', - hb_bidder: 'appnexus', - }; - bid4.bidder = bid4.bidderCode = 'appnexus'; - bid4.cpm = 0; - bidsReceived = [bid4]; - }); - - after(function() { - bidsReceived = [bid1, bid2, bid3]; - $$PREBID_GLOBAL$$.bidderSettings = bidderSettingsStorage; - }) - - it('targeting should not include a 0 cpm by default', function() { - bid4.adserverTargeting = {}; - const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); - expect(targeting['/123456/header-bid-tag-0']).to.deep.equal({}); - }); - - it('targeting should allow a 0 cpm with targetingControls.allowZeroCpmBids set to true', function () { - $$PREBID_GLOBAL$$.bidderSettings = { - standard: { - allowZeroCpmBids: true - } - }; - - const targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']); - expect(targeting['/123456/header-bid-tag-0']).to.include.all.keys('hb_pb', 'hb_bidder', 'hb_adid', 'hb_bidder_appnexus', 'hb_adid_appnexus', 'hb_pb_appnexus'); - expect(targeting['/123456/header-bid-tag-0']['hb_pb']).to.equal('0.0') - }); - }); - describe('targetingControls.allowTargetingKeys', function () { let bid4; @@ -546,77 +501,6 @@ describe('targeting tests', function () { }); }); - describe('targetingControls.addTargetingKeys', function () { - let winningBid = null; - - beforeEach(function () { - bidsReceived = [bid1, bid2, nativeBid1, nativeBid2].map(deepClone); - bidsReceived.forEach((bid) => { - bid.adserverTargeting[CONSTANTS.TARGETING_KEYS.SOURCE] = 'test-source'; - bid.adUnitCode = 'adunit'; - if (winningBid == null || bid.cpm > winningBid.cpm) { - winningBid = bid; - } - }); - enableSendAllBids = true; - }); - - const expandKey = function (key) { - const keys = new Set(); - if (winningBid.adserverTargeting[key] != null) { - keys.add(key); - } - bidsReceived - .filter((bid) => bid.adserverTargeting[key] != null) - .map((bid) => bid.bidderCode) - .forEach((code) => keys.add(`${key}_${code}`.substr(0, 20))); - return new Array(...keys); - } - - const targetingResult = function () { - return targetingInstance.getAllTargeting(['adunit'])['adunit']; - } - - it('should include added keys', function () { - config.setConfig({ - targetingControls: { - addTargetingKeys: ['SOURCE'] - } - }); - expect(targetingResult()).to.include.all.keys(...expandKey(CONSTANTS.TARGETING_KEYS.SOURCE)); - }); - - it('should keep default and native keys', function() { - config.setConfig({ - targetingControls: { - addTargetingKeys: ['SOURCE'] - } - }); - const defaultKeys = new Set(Object.values(CONSTANTS.DEFAULT_TARGETING_KEYS)); - Object.values(CONSTANTS.NATIVE_KEYS).forEach((k) => defaultKeys.add(k)); - - const expectedKeys = new Set(); - bidsReceived - .map((bid) => Object.keys(bid.adserverTargeting)) - .reduce((left, right) => left.concat(right), []) - .filter((key) => defaultKeys.has(key)) - .map(expandKey) - .reduce((left, right) => left.concat(right), []) - .forEach((k) => expectedKeys.add(k)); - expect(targetingResult()).to.include.all.keys(...expectedKeys); - }); - - it('should not be allowed together with allowTargetingKeys', function () { - config.setConfig({ - targetingControls: { - allowTargetingKeys: [CONSTANTS.TARGETING_KEYS.BIDDER], - addTargetingKeys: [CONSTANTS.TARGETING_KEYS.SOURCE] - } - }); - expect(targetingResult).to.throw(); - }); - }); - describe('targetingControls.allowSendAllBidsTargetingKeys', function () { let bid4; diff --git a/test/spec/unit/pbjs_api_spec.js b/test/spec/unit/pbjs_api_spec.js index 2522887bb98..199ce699dc8 100644 --- a/test/spec/unit/pbjs_api_spec.js +++ b/test/spec/unit/pbjs_api_spec.js @@ -75,10 +75,6 @@ var Slot = function Slot(elementId, pathId) { clearTargeting: function clearTargeting() { this.targeting = {}; return this; - }, - - updateTargetingFromMap: function updateTargetingFromMap(targetingMap) { - Object.keys(targetingMap).forEach(key => this.setTargeting(key, targetingMap[key])) } }; slot.spySetTargeting = sinon.spy(slot, 'setTargeting'); @@ -98,6 +94,7 @@ var createSlotArrayScenario2 = function createSlotArrayScenario2() { var slot1 = new Slot(config.adUnitElementIDs[0], config.adUnitCodes[0]); slot1.setTargeting('pos1', '750x350'); var slot2 = new Slot(config.adUnitElementIDs[1], config.adUnitCodes[0]); + slot2.setTargeting('gender', ['male', 'female']); return [ slot1, slot2 @@ -861,9 +858,6 @@ describe('Unit: Prebid Module', function () { it('should set googletag targeting keys after calling setTargetingForGPTAsync function', function () { var slots = createSlotArrayScenario2(); - - // explicitly setting some PBJS key value pairs to verify whether these are removed befor new keys are set - window.googletag.pubads().setSlots(slots); $$PREBID_GLOBAL$$.setTargetingForGPTAsync([config.adUnitCodes[0]]); @@ -871,7 +865,7 @@ describe('Unit: Prebid Module', function () { // googletag's targeting structure // googletag setTargeting will override old value if invoked with same key - let targeting = []; + const targeting = []; slots[1].getTargetingKeys().map(function (key) { const value = slots[1].getTargeting(key); targeting.push([key, value]); @@ -889,39 +883,6 @@ describe('Unit: Prebid Module', function () { invokedTargeting.push([key, value]); }); assert.deepEqual(targeting, invokedTargeting, 'google tag targeting options not matching'); - - // resetPresetTargeting: initiate a new auction with no winning bids, now old targeting should be removed - - resetAuction(); - auction.getBidsReceived = function() { return [] }; - - var slots = createSlotArrayScenario2(); - window.googletag.pubads().setSlots(slots); - - $$PREBID_GLOBAL$$.setTargetingForGPTAsync([config.adUnitCodes[0]]); - - targeting = []; - slots[1].getTargetingKeys().map(function (key) { - const value = slots[1].getTargeting(key); - targeting.push([key, value]); - }); - - invokedTargetingMap = {}; - slots[1].spySetTargeting.args.map(function (entry) { - invokedTargetingMap[entry[0]] = entry[1]; - }); - - var invokedTargeting = []; - - Object.getOwnPropertyNames(invokedTargetingMap).map(function (key) { - const value = Array.isArray(invokedTargetingMap[key]) ? invokedTargetingMap[key] : [invokedTargetingMap[key]]; // values are always returned as array in googletag - invokedTargeting.push([key, value]); - }); - assert.deepEqual(targeting, invokedTargeting, 'google tag targeting options not matching'); - targeting.forEach(function(e) { - // here e[0] is key and e[1] is value in array that should be [null] as we are un-setting prebid keys in resetPresetTargeting - assert.deepEqual(e[1], [null], 'resetPresetTargeting: the value of the key ' + e[0] + ' should be [null]'); - }); }); it('should set googletag targeting keys to specific slot with customSlotMatching', function () { @@ -1135,15 +1096,13 @@ describe('Unit: Prebid Module', function () { height: 0 } }, - getElementsByTagName: sinon.stub(), - querySelector: sinon.stub() + getElementsByTagName: sinon.stub() }; elStub = { insertBefore: sinon.stub() }; doc.getElementsByTagName.returns([elStub]); - doc.querySelector.returns(elStub); spyLogError = sinon.spy(utils, 'logError'); spyLogMessage = sinon.spy(utils, 'logMessage'); diff --git a/test/spec/unit/secureCreatives_spec.js b/test/spec/unit/secureCreatives_spec.js index cee416bd1be..eca00e8c8fa 100644 --- a/test/spec/unit/secureCreatives_spec.js +++ b/test/spec/unit/secureCreatives_spec.js @@ -116,7 +116,7 @@ describe('secureCreatives', () => { beforeEach(function() { spyAddWinningBid = sinon.spy(auctionManager, 'addWinningBid'); spyLogWarn = sinon.spy(utils, 'logWarn'); - stubFireNativeTrackers = sinon.stub(native, 'fireNativeTrackers').callsFake(message => { return message.action; }); + stubFireNativeTrackers = sinon.stub(native, 'fireNativeTrackers'); stubGetAllAssetsMessage = sinon.stub(native, 'getAllAssetsMessage'); stubEmit = sinon.stub(events, 'emit'); }); @@ -263,9 +263,10 @@ describe('secureCreatives', () => { sinon.assert.calledOnce(stubGetAllAssetsMessage); sinon.assert.calledWith(stubGetAllAssetsMessage, data, adResponse); sinon.assert.calledOnce(ev.source.postMessage); - sinon.assert.notCalled(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); + sinon.assert.calledOnce(stubFireNativeTrackers); + sinon.assert.calledWith(stubFireNativeTrackers, data, adResponse); + sinon.assert.calledOnce(spyAddWinningBid); + sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); }); @@ -292,11 +293,14 @@ describe('secureCreatives', () => { sinon.assert.calledOnce(stubGetAllAssetsMessage); sinon.assert.calledWith(stubGetAllAssetsMessage, data, adResponse); sinon.assert.calledOnce(ev.source.postMessage); - sinon.assert.notCalled(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); + sinon.assert.calledOnce(stubFireNativeTrackers); + sinon.assert.calledWith(stubFireNativeTrackers, data, adResponse); + sinon.assert.calledOnce(spyAddWinningBid); + sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); + expect(adResponse).to.have.property('status', CONSTANTS.BID_STATUS.RENDERED); + resetHistories(ev.source.postMessage); receiveMessage(ev); @@ -305,9 +309,10 @@ describe('secureCreatives', () => { sinon.assert.calledOnce(stubGetAllAssetsMessage); sinon.assert.calledWith(stubGetAllAssetsMessage, data, adResponse); sinon.assert.calledOnce(ev.source.postMessage); - sinon.assert.notCalled(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); + sinon.assert.calledOnce(stubFireNativeTrackers); + sinon.assert.calledWith(stubFireNativeTrackers, data, adResponse); + sinon.assert.calledOnce(spyAddWinningBid); + sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); }); @@ -336,11 +341,14 @@ describe('secureCreatives', () => { sinon.assert.calledOnce(stubGetAllAssetsMessage); sinon.assert.calledWith(stubGetAllAssetsMessage, data, adResponse); sinon.assert.calledOnce(ev.source.postMessage); - sinon.assert.notCalled(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); + sinon.assert.calledOnce(stubFireNativeTrackers); + sinon.assert.calledWith(stubFireNativeTrackers, data, adResponse); + sinon.assert.calledOnce(spyAddWinningBid); + sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); + expect(adResponse).to.have.property('status', CONSTANTS.BID_STATUS.RENDERED); + resetHistories(ev.source.postMessage); receiveMessage(ev); @@ -349,50 +357,13 @@ describe('secureCreatives', () => { sinon.assert.calledOnce(stubGetAllAssetsMessage); sinon.assert.calledWith(stubGetAllAssetsMessage, data, adResponse); sinon.assert.calledOnce(ev.source.postMessage); - sinon.assert.notCalled(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); - - configObj.setConfig({'auctionOptions': {}}); - }); - - it('Prebid native should fire trackers', function () { - pushBidResponseToAuction({}); - - const data = { - adId: bidId, - message: 'Prebid Native', - action: 'click', - }; - - const ev = { - data: JSON.stringify(data), - source: { - postMessage: sinon.stub() - }, - origin: 'any origin' - }; - - receiveMessage(ev); - - sinon.assert.neverCalledWith(spyLogWarn, warning); - sinon.assert.calledOnce(stubFireNativeTrackers); - sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.BID_WON); - sinon.assert.notCalled(spyAddWinningBid); - - resetHistories(ev.source.postMessage); - - delete data.action; - ev.data = JSON.stringify(data); - receiveMessage(ev); - - sinon.assert.neverCalledWith(spyLogWarn, warning); sinon.assert.calledOnce(stubFireNativeTrackers); - sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); + sinon.assert.calledWith(stubFireNativeTrackers, data, adResponse); sinon.assert.calledOnce(spyAddWinningBid); + sinon.assert.calledWith(stubEmit, CONSTANTS.EVENTS.BID_WON, adResponse); + sinon.assert.neverCalledWith(stubEmit, CONSTANTS.EVENTS.STALE_RENDER); - expect(adResponse).to.have.property('status', CONSTANTS.BID_STATUS.RENDERED); + configObj.setConfig({'auctionOptions': {}}); }); }); }); diff --git a/test/spec/userSync_spec.js b/test/spec/userSync_spec.js index 910ffe7b2d6..55b613ce929 100644 --- a/test/spec/userSync_spec.js +++ b/test/spec/userSync_spec.js @@ -401,33 +401,6 @@ describe('user sync', function () { expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); }); - it('should not fire image pixel for a bidder if iframe pixel is fired for same bidder', function() { - const userSync = newUserSync({ - config: config.getConfig('userSync'), - browserSupportsCookies: true - }); - - config.setConfig({ - userSync: { - filterSettings: { - iframe: { - bidders: ['bidderXYZ'], - filter: 'include' - } - } - } - }); - // we are registering iframe and image sync for bidderXYZ and we expect image sync not to execute. - userSync.registerSync('image', 'testBidder', 'http://testBidder.example.com/image'); - userSync.registerSync('iframe', 'bidderXYZ', 'http://bidderXYZ.example.com/iframe'); - userSync.registerSync('image', 'bidderXYZ', 'http://bidderXYZ.example.com/image'); - userSync.syncUsers(); - expect(triggerPixelStub.getCall(0)).to.not.be.null; - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://testBidder.example.com/image'); - expect(triggerPixelStub.callCount).to.equal(1); // should not be 2 for 2 registered image syncs - expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://bidderXYZ.example.com/iframe'); - }); - it('should override default image syncs if setConfig used image filter', function () { const userSync = newUserSync({ config: config.getConfig('userSync'), @@ -475,9 +448,8 @@ describe('user sync', function () { userSync.registerSync('iframe', 'testBidder', 'http://example.com/iframe'); userSync.registerSync('iframe', 'bidderXYZ', 'http://example.com/iframe-blocked'); userSync.syncUsers(); - // expect(triggerPixelStub.getCall(0)).to.not.be.null; - expect(triggerPixelStub.getCall(0)).to.be.null;// image sync will not execute as iframe sync has executed for same bidder - // expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://example.com'); + expect(triggerPixelStub.getCall(0)).to.not.be.null; + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://example.com'); expect(triggerPixelStub.getCall(1)).to.be.null; expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); expect(insertUserSyncIframeStub.getCall(1)).to.be.null; diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index 898b79cdcb5..6494ead78e7 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -2,7 +2,6 @@ import { getAdServerTargeting } from 'test/fixtures/fixtures.js'; import { expect } from 'chai'; import CONSTANTS from 'src/constants.json'; import * as utils from 'src/utils.js'; -import {waitForElementToLoad} from 'src/utils.js'; var assert = require('assert'); @@ -1199,41 +1198,4 @@ describe('Utils', function () { }); }); }); - - describe('waitForElementToLoad', () => { - let element; - let callbacks; - - function callback() { - callbacks++; - } - - function delay(delay = 0) { - return new Promise((resolve) => { - window.setTimeout(resolve, delay); - }) - } - - beforeEach(() => { - callbacks = 0; - element = window.document.createElement('div'); - }); - - it('should respect timeout if set', () => { - waitForElementToLoad(element, 50).then(callback); - return delay(60).then(() => { - expect(callbacks).to.equal(1); - }); - }); - - ['load', 'error'].forEach((event) => { - it(`should complete on '${event} event'`, () => { - waitForElementToLoad(element).then(callback); - element.dispatchEvent(new Event(event)); - return delay().then(() => { - expect(callbacks).to.equal(1); - }) - }); - }); - }); }); diff --git a/test/test_deps.js b/test/test_deps.js deleted file mode 100644 index e535154b799..00000000000 --- a/test/test_deps.js +++ /dev/null @@ -1,3 +0,0 @@ -require('test/helpers/prebidGlobal.js'); -require('test/mocks/adloaderStub.js'); -require('test/mocks/xhr.js'); diff --git a/test/test_index.js b/test/test_index.js index 883f4d0590c..53d75e36176 100644 --- a/test/test_index.js +++ b/test/test_index.js @@ -1,4 +1,6 @@ -require('./test_deps.js'); +require('test/helpers/prebidGlobal.js'); +require('test/mocks/adloaderStub.js'); +require('test/mocks/xhr.js'); var testsContext = require.context('.', true, /_spec$/); testsContext.keys().forEach(testsContext); diff --git a/wdio.conf.js b/wdio.conf.js index 4865c03f339..c9aaa3f160d 100644 --- a/wdio.conf.js +++ b/wdio.conf.js @@ -9,7 +9,7 @@ function getCapabilities() { return platformMap[os]; } - // only Chrome 80 & Firefox 73 run as part of functional tests + // only IE 11, Chrome 80 & Firefox 73 run as part of functional tests // rest of the browsers are discarded. delete browsers['bs_chrome_79_windows_10']; delete browsers['bs_firefox_72_windows_10']; From 3c06e2cb5402bfc134b60f2ad153aff389c40569 Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Thu, 23 Sep 2021 14:04:57 -0400 Subject: [PATCH 08/14] dchain module + appnexus dchain support --- modules/dchain.js | 135 +++++++++++++++++++++++++++++++ modules/dchain.md | 45 +++++++++++ test/spec/modules/dchain_spec.js | 112 +++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 modules/dchain.js create mode 100644 modules/dchain.md create mode 100644 test/spec/modules/dchain_spec.js diff --git a/modules/dchain.js b/modules/dchain.js new file mode 100644 index 00000000000..721cbf1eb7e --- /dev/null +++ b/modules/dchain.js @@ -0,0 +1,135 @@ +import includes from 'core-js-pure/features/array/includes.js'; +import { config } from '../src/config.js'; +import { getHook } from '../src/hook.js'; +import { _each, isStr, isArray, isPlainObject, hasOwn, deepClone, deepAccess, logWarn, logError } from '../src/utils.js'; + +const shouldBeAString = ' should be a string'; +const shouldBeAnObject = ' should be an object'; +const shouldBeAnArray = ' should be an Array'; +const MODE = { + STRICT: 'strict', + RELAXED: 'relaxed', + OFF: 'off' +}; +const MODES = []; // an array of modes +_each(MODE, mode => MODES.push(mode)); + +export function checkDchainSyntax(bid, mode) { + let dchainObj = deepClone(bid.meta.dchain); + let failPrefix = 'Detected something wrong in bid.meta.dchain object for bid:'; + let failMsg = ''; + + function appendFailMsg(msg) { + failMsg += '\n' + msg; + } + + function printFailMsg() { + if (mode === MODE.STRICT) { + logError(failPrefix, bid, '\n', dchainObj, failMsg); + } else { + logWarn(failPrefix, bid, `\n`, dchainObj, failMsg); + } + } + + if (dchainObj.complete !== 0 && dchainObj.complete !== 1) { + appendFailMsg(`dchain.complete should be 0 or 1`); + } + + if (!isStr(dchainObj.ver)) { + appendFailMsg(`dchain.ver` + shouldBeAString); + } + + if (hasOwn(dchainObj, 'ext')) { + if (!isPlainObject(dchainObj.ext)) { + appendFailMsg(`dchain.ext` + shouldBeAnObject); + } + } + + if (!isArray(dchainObj.nodes)) { + appendFailMsg(`dchain.nodes` + shouldBeAnArray); + printFailMsg(); + if (mode === MODE.STRICT) return false; + } else { + const propList = ['asi', 'bsid', 'rid', 'name', 'domain', 'ext']; + dchainObj.nodes.forEach((node, index) => { + if (!isPlainObject(node)) { + appendFailMsg(`dchain.nodes[${index}]` + shouldBeAnObject); + } else { + let nodeProps = Object.keys(node); + nodeProps.forEach(prop => { + if (!includes(propList, prop)) { + appendFailMsg(`dchain.nodes[${index}].${prop} is not a valid dchain property.`); + } else { + if (prop === 'ext') { + if (!isPlainObject(node.ext)) { + appendFailMsg(`dchain.nodes[${index}].ext` + shouldBeAnObject); + } + } else { + if (!isStr(node[prop])) { + appendFailMsg(`dchain.nodes[${index}].${prop}` + shouldBeAString); + } + } + } + }); + } + }); + } + + if (failMsg.length > 0) { + printFailMsg(); + if (mode === MODE.STRICT) { + return false; + } + } + return true; +} + +function isValidDchain(bid) { + let mode = MODE.STRICT; + const dchainConfig = config.getConfig('dchain'); + + if (dchainConfig && isStr(dchainConfig.validation) && MODES.indexOf(dchainConfig.validation) != -1) { + mode = dchainConfig.validation; + } + + if (mode === MODE.OFF) { + return true; + } else { + return checkDchainSyntax(bid, mode); + } +} + +export function addBidResponseHook(fn, adUnitCode, bid) { + const basicDchain = { + ver: '1.0', + complete: 0, + nodes: [{ name: bid.bidderCode }] + }; + + let bidDchain = deepAccess(bid, 'meta.dchain'); + if (bidDchain && isPlainObject(bidDchain)) { + let result = isValidDchain(bid); + + if (result) { + // extra check in-case mode is OFF and there is a setup issue + if (isArray(bidDchain.nodes)) { + bid.meta.dchain.nodes.push({ asi: bid.bidderCode }); + } else { + logWarn('bid.meta.dchain.nodes did not exist or was not an array; did not append prebid dchain.', bid); + } + } else { + // bid.meta.dchain = basicDchain; // should we assign a backup dchain if bidder's dchain was invalid? + delete bid.meta.dchain; // or delete the bad object? + } + } else { + bid.meta.dchain = basicDchain; + } + + fn(adUnitCode, bid); +} + +export function init() { + getHook('addBidResponse').before(addBidResponseHook, 35); +} + +init(); diff --git a/modules/dchain.md b/modules/dchain.md new file mode 100644 index 00000000000..f01b3483f3c --- /dev/null +++ b/modules/dchain.md @@ -0,0 +1,45 @@ +# dchain module + +Refer: +- https://iabtechlab.com/buyers-json-demand-chain/ + +## Sample code for dchain setConfig and dchain object +``` +pbjs.setConfig({ + "dchain": { + "validation": "strict" + } +}); +``` + +``` +bid.meta.dchain: { + "complete": 0, + "ver": "1.0", + "ext": {...}, + "nodes": [{ + "asi": "abc", + "bsid": "123", + "rid": "d4e5f6", + "name": "xyz", + "domain": "mno", + "ext": {...} + }, ...] +} +``` + +## Workflow +The dchain module is not enabled by default as it may not be necessary for all publishers. +If required, dchain module can be included as following +``` + $ gulp build --modules=dchain,pubmaticBidAdapter,openxBidAdapter,rubiconBidAdapter,sovrnBidAdapter +``` + +The dchain module will validate a bidder's dchain object (if it was defined). Bidders should assign their dchain object into `bid.meta` field. If the dchain object is valid, it will remain in the bid object for later use. + +If it was not defined, the dchain will create a default dchain object for prebid. + +## Validation modes +- ```strict```: It is the default validation mode. In this mode, dchain object will not be accpeted from adapters if it is invalid. Errors are thrown for invalid dchain object. +- ```relaxed```: In this mode, errors are thrown for an invalid dchain object but the invalid dchain object is still accepted from adapters. +- ```off```: In this mode, no validations are performed and dchain object is accepted as is from adapters. \ No newline at end of file diff --git a/test/spec/modules/dchain_spec.js b/test/spec/modules/dchain_spec.js new file mode 100644 index 00000000000..2e0036045ff --- /dev/null +++ b/test/spec/modules/dchain_spec.js @@ -0,0 +1,112 @@ +import { checkDchainSyntax, addBidResponseHook } from '../../../modules/dchain.js'; +import { deepClone } from '../../../src/utils.js'; +import { config } from '../../../src/config.js'; +import { expect } from 'chai'; + +describe.only('dchain module', function () { + describe('checkDchainSyntax', function () { + let bid; + const STRICT = 'strict'; + + beforeEach(function () { + bid = { + meta: { + dchain: { + 'ver': '1.0', + 'complete': 0, + 'ext': {}, + 'nodes': [{ + 'asi': 'domain.com', + 'bsid': '12345', + }, { + 'name': 'bidder', + 'domain': 'bidder.com', + 'ext': {} + }] + } + } + }; + }); + + // complete + it('Returns false if complete param is not 0 or 1', function () { + let dchainConfig = bid.meta.dchain; + dchainConfig.complete = 0; // integer + expect(checkDchainSyntax(bid, STRICT)).to.true; + dchainConfig.complete = 1; // integer + expect(checkDchainSyntax(bid, STRICT)).to.true; + dchainConfig.complete = '1'; // string + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.complete = 1.1; // float + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.complete = {}; // object + expect(checkDchainSyntax(bid, STRICT)).to.false; + delete dchainConfig.complete; // undefined + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.complete = true; // boolean + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.complete = []; // array + expect(checkDchainSyntax(bid, STRICT)).to.false; + }); + + // version + it('Returns false if ver param is not a String', function () { + let dchainConfig = bid.meta.dchain; + dchainConfig.ver = 1; // integer + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ver = '1'; // string + expect(checkDchainSyntax(bid, STRICT)).to.true; + dchainConfig.ver = 1.1; // float + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ver = {}; // object + expect(checkDchainSyntax(bid, STRICT)).to.false; + delete dchainConfig.ver; // undefined + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ver = true; // boolean + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ver = []; // array + expect(checkDchainSyntax(bid, STRICT)).to.false; + }); + + // ext + it('Returns false if ext param is not an Object', function () { + let dchainConfig = bid.meta.dchain; + dchainConfig.ext = 1; // integer + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ext = '1'; // string + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ext = 1.1; // float + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ext = {}; // object + expect(checkDchainSyntax(bid, STRICT)).to.true; + delete dchainConfig.ext; // undefined + expect(checkDchainSyntax(bid, STRICT)).to.true; + dchainConfig.ext = true; // boolean + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.ext = []; // array + expect(checkDchainSyntax(bid, STRICT)).to.false; + }); + + // nodes + it('Returns false if nodes param is not an Array', function () { + let dchainConfig = bid.meta.dchain; + expect(checkDchainSyntax(bid, STRICT)).to.true; + dchainConfig.nodes = 1; // integer + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.nodes = '1'; // string + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.nodes = 1.1; // float + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.nodes = {}; // object + expect(checkDchainSyntax(bid, STRICT)).to.false; + delete dchainConfig.nodes; // undefined + expect(checkDchainSyntax(bid, STRICT)).to.false; + dchainConfig.nodes = true; // boolean + expect(checkDchainSyntax(bid, STRICT)).to.false; + }); + }); + + describe('addBidResponseHook', function () { + + }); +}); From 2e0fe0852159d2bc7d8a68df3070e7e0cc95924e Mon Sep 17 00:00:00 2001 From: jessoventes <82361050+jessoventes@users.noreply.github.com> Date: Wed, 1 Dec 2021 19:51:21 +0530 Subject: [PATCH 09/14] Ventes Bid Adapter: fix web support and code maintenance (#7766) * Ventes Avenues initial changes * Ventes Avenues initial changes * Support Web Placments * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placements * Support Web Placments From b5d874930518234b154519af91ea5465c1ea851c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mar=C3=ADn?= Date: Tue, 7 Dec 2021 21:39:05 +0100 Subject: [PATCH 10/14] Index Exchange adapter: Webpack v5 complain about named export from JSON modules (#7774) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Webpack v5 complain about named export from JSON modules * Index Exchange Adapter: fix "Should not import the named export 'EVENTS'.'AUCTION_DEBUG' (imported as 'EVENTS') from default-exporting module (only default export is available soon)"" Co-authored-by: Javier Marín From 32824ffafc47a81fec34eeae1279407574516557 Mon Sep 17 00:00:00 2001 From: Maxim Pakhomov Date: Tue, 7 Dec 2021 18:59:08 +0400 Subject: [PATCH 11/14] EX-3448 Update Adapter to support video --- modules/sovrnBidAdapter.js | 86 +++++++++++++++-------- test/spec/modules/sovrnBidAdapter_spec.js | 73 ++++++++++++++++++- 2 files changed, 126 insertions(+), 33 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 70883f151b4..033ea646120 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,12 +1,15 @@ -import * as utils from '../src/utils.js' +import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' -import { BANNER } from '../src/mediaTypes.js' +import { BANNER, VIDEO } from '../src/mediaTypes.js' import { createEidsArray } from './userId/eids.js'; import {config} from '../src/config.js'; +export const DEFAULT_MIMES = ['video/3gpp', 'video/mov', 'video/mp4', 'video/mpv', 'application/javascript'] +export const DEFAULT_PROTOCOLS = [1, 2, 3, 4, 5, 6] + export const spec = { code: 'sovrn', - supportedMediaTypes: [BANNER], + supportedMediaTypes: [BANNER, VIDEO], gvlid: 13, /** @@ -32,7 +35,7 @@ export const spec = { let tpid = [] let criteoId; - utils._each(bidReqs, function (bid) { + _each(bidReqs, function (bid) { if (!eids && bid.userId) { eids = createEidsArray(bid.userId) eids.forEach(function (id) { @@ -48,34 +51,55 @@ export const spec = { if (bid.schain) { schain = schain || bid.schain } - iv = iv || utils.getBidIdParameter('iv', bid.params) + iv = iv || getBidIdParameter('iv', bid.params) - let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes - bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]) - bidSizes = bidSizes.filter(size => utils.isArray(size)) - const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) const floorInfo = (bid.getFloor && typeof bid.getFloor === 'function') ? bid.getFloor({ currency: 'USD', - mediaType: 'banner', + mediaType: bid.mediaTypes && bid.mediaTypes.banner ? 'banner' : 'video', size: '*' }) : {} - floorInfo.floor = floorInfo.floor || utils.getBidIdParameter('bidfloor', bid.params) + floorInfo.floor = floorInfo.floor || getBidIdParameter('bidfloor', bid.params) const imp = { adunitcode: bid.adUnitCode, id: bid.bidId, - banner: { + tagid: String(utils.getBidIdParameter('tagid', bid.params)), + bidfloor: floorInfo.floor + } + + if (bid.mediaTypes && bid.mediaTypes.banner) { + let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes + bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]) + bidSizes = bidSizes.filter(size => utils.isArray(size)) + const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) + + imp.banner = { format: processedSizes, w: 1, h: 1, - }, - tagid: String(utils.getBidIdParameter('tagid', bid.params)), - bidfloor: floorInfo.floor + }; + } + if (bid.mediaTypes && bid.mediaTypes.video) { + let bidSizes = bid.mediaTypes.video.playerSize + bidSizes = (utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes] + bidSizes = bidSizes.filter(size => utils.isArray(size)) + + const video = utils.deepAccess(bid, 'mediaTypes.video') || {} + + imp.video = { + w: bidSizes[0][0], + h: bidSizes[0][1], + mimes: video.mimes || DEFAULT_MIMES, + protocols: video.protocols || DEFAULT_PROTOCOLS, + minduration: video.minduration, + maxduration: video.maxduration, + startdelay: video.startdelay + } } - imp.ext = utils.getBidIdParameter('ext', bid.ortb2Imp) || undefined + imp.ext = getBidIdParameter('ext', bid.ortb2Imp) || undefined - const segmentsString = utils.getBidIdParameter('segments', bid.params) + const segmentsString = getBidIdParameter('segments', bid.params) if (segmentsString) { imp.ext = imp.ext || {} imp.ext.deals = segmentsString.split(',').map(deal => deal.trim()) @@ -83,15 +107,15 @@ export const spec = { sovrnImps.push(imp) }) - const fpd = utils.deepClone(config.getConfig('ortb2')) + const fpd = deepClone(config.getConfig('ortb2')) const site = fpd.site || {} site.page = bidderRequest.refererInfo.referer // clever trick to get the domain - site.domain = utils.parseUrl(site.page).hostname + site.domain = parseUrl(site.page).hostname const sovrnBidReq = { - id: utils.getUniqueIdentifierStr(), + id: getUniqueIdentifierStr(), imp: sovrnImps, site: site, user: fpd.user || {} @@ -106,18 +130,18 @@ export const spec = { } if (bidderRequest.gdprConsent) { - utils.deepSetValue(sovrnBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); - utils.deepSetValue(sovrnBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString) + deepSetValue(sovrnBidReq, 'regs.ext.gdpr', +bidderRequest.gdprConsent.gdprApplies); + deepSetValue(sovrnBidReq, 'user.ext.consent', bidderRequest.gdprConsent.consentString) } if (bidderRequest.uspConsent) { - utils.deepSetValue(sovrnBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent); + deepSetValue(sovrnBidReq, 'regs.ext.us_privacy', bidderRequest.uspConsent); } if (eids) { - utils.deepSetValue(sovrnBidReq, 'user.ext.eids', eids) - utils.deepSetValue(sovrnBidReq, 'user.ext.tpid', tpid) + deepSetValue(sovrnBidReq, 'user.ext.eids', eids) + deepSetValue(sovrnBidReq, 'user.ext.tpid', tpid) if (criteoId) { - utils.deepSetValue(sovrnBidReq, 'user.ext.prebid_criteoid', criteoId) + deepSetValue(sovrnBidReq, 'user.ext.prebid_criteoid', criteoId) } } @@ -131,7 +155,7 @@ export const spec = { options: {contentType: 'text/plain'} } } catch (e) { - utils.logError('Could not build bidrequest, error deatils:', e); + logError('Could not build bidrequest, error deatils:', e); } }, @@ -158,7 +182,7 @@ export const spec = { dealId: sovrnBid.dealid || null, currency: 'USD', netRevenue: true, - mediaType: BANNER, + mediaType: sovrnBid.mediaType || BANNER, ad: decodeURIComponent(`${sovrnBid.adm}`), ttl: sovrnBid.ext ? (sovrnBid.ext.ttl || 90) : 90, meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } @@ -167,7 +191,7 @@ export const spec = { } return sovrnBidResponses } catch (e) { - utils.logError('Could not intrepret bidresponse, error deatils:', e); + logError('Could not intrepret bidresponse, error deatils:', e); } }, @@ -176,7 +200,7 @@ export const spec = { const tracks = [] if (serverResponses && serverResponses.length !== 0) { if (syncOptions.iframeEnabled) { - const iidArr = serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.iid')) + const iidArr = serverResponses.filter(resp => deepAccess(resp, 'body.ext.iid')) .map(resp => resp.body.ext.iid); const params = []; if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { @@ -196,7 +220,7 @@ export const spec = { } if (syncOptions.pixelEnabled) { - serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.sync.pixels')) + serverResponses.filter(resp => deepAccess(resp, 'body.ext.sync.pixels')) .reduce((acc, resp) => acc.concat(resp.body.ext.sync.pixels), []) .map(pixel => pixel.url) .forEach(url => tracks.push({ type: 'image', url })) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index 6fd5eecfb78..c3d871e8e19 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import {spec} from 'modules/sovrnBidAdapter.js'; +import {spec, DEFAULT_MIMES, DEFAULT_PROTOCOLS} from 'modules/sovrnBidAdapter.js'; import {config} from 'src/config.js'; import * as utils from 'src/utils.js' @@ -67,6 +67,15 @@ describe('sovrnBidAdapter', function() { }); it('sets the proper banner object', function() { + const bannerBidRequest = { + ...baseBidRequest, + 'mediaTypes': { + banner: {} + } + } + const request = spec.buildRequests([bannerBidRequest], baseBidderRequest) + + const payload = JSON.parse(request.data) const impression = payload.imp[0] expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) @@ -74,6 +83,63 @@ describe('sovrnBidAdapter', function() { expect(impression.banner.h).to.equal(1) }) + it('sets the proper video object', function() { + const width = 640 + const height = 480 + const mimes = ['video/mp4', 'application/javascript'] + const protocols = [2, 5] + const minduration = 5 + const maxduration = 60 + const startdelay = 0 + const videoBidRequest = { + ...baseBidRequest, + 'mediaTypes': { + video: { + mimes, + protocols, + playerSize: [[width, height], [360, 240]], + minduration, + maxduration, + startdelay + } + } + } + const request = spec.buildRequests([videoBidRequest], baseBidderRequest) + + const payload = JSON.parse(request.data) + const impression = payload.imp[0] + + expect(impression.video.w).to.equal(width) + expect(impression.video.h).to.equal(height) + expect(impression.video.mimes).to.have.same.members(mimes) + expect(impression.video.protocols).to.have.same.members(protocols) + expect(impression.video.minduration).to.equal(minduration) + expect(impression.video.maxduration).to.equal(maxduration) + expect(impression.video.startdelay).to.equal(startdelay) + }) + + it('sets the proper video object with default values', function() { + const width = 640 + const height = 480 + const videoBidRequest = { + ...baseBidRequest, + 'mediaTypes': { + video: { + playerSize: [width, height], + } + } + } + const request = spec.buildRequests([videoBidRequest], baseBidderRequest) + + const payload = JSON.parse(request.data) + const impression = payload.imp[0] + + expect(impression.video.w).to.equal(width) + expect(impression.video.h).to.equal(height) + expect(impression.video.mimes).to.have.same.members(DEFAULT_MIMES) + expect(impression.video.protocols).to.have.same.members(DEFAULT_PROTOCOLS) + }) + it('gets correct site info', function() { expect(payload.site.page).to.equal('http://example.com/page.html'); expect(payload.site.domain).to.equal('example.com'); @@ -95,7 +161,10 @@ describe('sovrnBidAdapter', function() { 'params': { 'iv': 'vet' }, - 'sizes': [300, 250] + 'sizes': [300, 250], + 'mediaTypes': { + banner: {} + }, } const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) From 264da88c6d82a8007c3409cd9dccc592c05b8c96 Mon Sep 17 00:00:00 2001 From: Maxim Pakhomov Date: Fri, 10 Dec 2021 21:32:21 +0400 Subject: [PATCH 12/14] EX-3448 Update interpretResponse function --- modules/sovrnBidAdapter.js | 106 +++++++++++++----- test/spec/modules/sovrnBidAdapter_spec.js | 128 ++++++++++++++++++---- 2 files changed, 183 insertions(+), 51 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 033ea646120..e4600b9f862 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,11 +1,34 @@ import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' -import { BANNER, VIDEO } from '../src/mediaTypes.js' +import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js' import { createEidsArray } from './userId/eids.js'; import {config} from '../src/config.js'; -export const DEFAULT_MIMES = ['video/3gpp', 'video/mov', 'video/mp4', 'video/mpv', 'application/javascript'] -export const DEFAULT_PROTOCOLS = [1, 2, 3, 4, 5, 6] +export const ORTB_VIDEO_PARAMS = { + 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), + 'minduration': (value) => utils.isInteger(value), + 'maxduration': (value) => utils.isInteger(value), + 'protocols': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 10), + 'w': (value) => utils.isInteger(value), + 'h': (value) => utils.isInteger(value), + 'startdelay': (value) => utils.isInteger(value), + 'placement': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 5), + 'linearity': (value) => [1, 2].indexOf(value) !== -1, + 'skip': (value) => [0, 1].indexOf(value) !== -1, + 'skipmin': (value) => utils.isInteger(value), + 'skipafter': (value) => utils.isInteger(value), + 'sequence': (value) => utils.isInteger(value), + 'battr': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 17), + 'maxextended': (value) => utils.isInteger(value), + 'minbitrate': (value) => utils.isInteger(value), + 'maxbitrate': (value) => utils.isInteger(value), + 'boxingallowed': (value) => [0, 1].indexOf(value) !== -1, + 'playbackmethod': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6), + 'playbackend': (value) => [1, 2, 3].indexOf(value) !== -1, + 'delivery': (value) => [1, 2, 3].indexOf(value) !== -1, + 'pos': (value) => [0, 1, 2, 3, 4, 5, 6, 7].indexOf(value) !== -1, + 'api': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6) +} export const spec = { code: 'sovrn', @@ -67,9 +90,9 @@ export const spec = { bidfloor: floorInfo.floor } - if (bid.mediaTypes && bid.mediaTypes.banner) { - let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes - bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes]) + if (utils.deepAccess(bid, 'mediaTypes.banner')) { + let bidSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes + bidSizes = (utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes] bidSizes = bidSizes.filter(size => utils.isArray(size)) const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) @@ -79,22 +102,11 @@ export const spec = { h: 1, }; } - if (bid.mediaTypes && bid.mediaTypes.video) { - let bidSizes = bid.mediaTypes.video.playerSize - bidSizes = (utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes] - bidSizes = bidSizes.filter(size => utils.isArray(size)) - - const video = utils.deepAccess(bid, 'mediaTypes.video') || {} - - imp.video = { - w: bidSizes[0][0], - h: bidSizes[0][1], - mimes: video.mimes || DEFAULT_MIMES, - protocols: video.protocols || DEFAULT_PROTOCOLS, - minduration: video.minduration, - maxduration: video.maxduration, - startdelay: video.startdelay - } + if ( + utils.deepAccess(bid, 'mediaTypes.video') && + utils.deepAccess(bid, 'mediaTypes.video.context') !== ADPOD + ) { + imp.video = _buildVideoRequestObj(bid); } imp.ext = getBidIdParameter('ext', bid.ortb2Imp) || undefined @@ -173,7 +185,7 @@ export const spec = { seatbid[0].bid && seatbid[0].bid.length > 0) { seatbid[0].bid.map(sovrnBid => { - sovrnBidResponses.push({ + const bid = { requestId: sovrnBid.impid, cpm: parseFloat(sovrnBid.price), width: parseInt(sovrnBid.w), @@ -182,11 +194,21 @@ export const spec = { dealId: sovrnBid.dealid || null, currency: 'USD', netRevenue: true, - mediaType: sovrnBid.mediaType || BANNER, - ad: decodeURIComponent(`${sovrnBid.adm}`), ttl: sovrnBid.ext ? (sovrnBid.ext.ttl || 90) : 90, meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } - }); + } + + const videoRegex = new RegExp(/VAST\s+version/) + + if (videoRegex.test(sovrnBid.adm)) { + bid.mediaType = VIDEO + bid.ad = decodeURIComponent(sovrnBid.adm) + bid.vastXml = sovrnBid.adm + } else { + bid.mediaType = BANNER + bid.ad = decodeURIComponent(`${sovrnBid.adm}`) + } + sovrnBidResponses.push(bid); }); } return sovrnBidResponses @@ -233,4 +255,34 @@ export const spec = { }, } -registerBidder(spec); +function _buildVideoRequestObj(bid) { + const videoObj = {} + const videoAdUnitParams = utils.deepAccess(bid, 'mediaTypes.video', {}) + const videoBidderParams = utils.deepAccess(bid, 'params.video', {}) + const computedParams = {} + + if (Array.isArray(videoAdUnitParams.playerSize)) { + const sizes = (Array.isArray(videoAdUnitParams.playerSize[0])) ? videoAdUnitParams.playerSize[0] : videoAdUnitParams.playerSize + computedParams.w = sizes[0] + computedParams.h = sizes[1] + } + + const videoParams = { + ...computedParams, + ...videoAdUnitParams, + ...videoBidderParams + }; + + Object.keys(ORTB_VIDEO_PARAMS).forEach(paramName => { + if (videoParams.hasOwnProperty(paramName)) { + if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) { + videoObj[paramName] = videoParams[paramName] + } else { + utils.logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); + } + } + }) + return videoObj +} + +registerBidder(spec) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index c3d871e8e19..b6629970055 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import {spec, DEFAULT_MIMES, DEFAULT_PROTOCOLS} from 'modules/sovrnBidAdapter.js'; +import {spec} from 'modules/sovrnBidAdapter.js'; import {config} from 'src/config.js'; import * as utils from 'src/utils.js' @@ -118,28 +118,6 @@ describe('sovrnBidAdapter', function() { expect(impression.video.startdelay).to.equal(startdelay) }) - it('sets the proper video object with default values', function() { - const width = 640 - const height = 480 - const videoBidRequest = { - ...baseBidRequest, - 'mediaTypes': { - video: { - playerSize: [width, height], - } - } - } - const request = spec.buildRequests([videoBidRequest], baseBidderRequest) - - const payload = JSON.parse(request.data) - const impression = payload.imp[0] - - expect(impression.video.w).to.equal(width) - expect(impression.video.h).to.equal(height) - expect(impression.video.mimes).to.have.same.members(DEFAULT_MIMES) - expect(impression.video.protocols).to.have.same.members(DEFAULT_PROTOCOLS) - }) - it('gets correct site info', function() { expect(payload.site.page).to.equal('http://example.com/page.html'); expect(payload.site.domain).to.equal('example.com'); @@ -447,7 +425,7 @@ describe('sovrnBidAdapter', function() { const result = spec.interpretResponse(response); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) + expect(result[0]).to.have.deep.keys(expectedResponse) }); it('crid should default to the bid id if not on the response', function () { @@ -503,6 +481,108 @@ describe('sovrnBidAdapter', function() { }); }); + describe('interpretResponse video', function () { + let videoResponse; + const baseVideoResponse = { + 'requestId': '263c448586f5a1', + 'cpm': 0.45882675, + 'width': 640, + 'height': 480, + 'creativeId': 'creativelycreatedcreativecreative', + 'dealId': null, + 'currency': 'USD', + 'netRevenue': true, + 'mediaType': 'video', + 'ad': decodeURIComponent(`key%3Dvalue`), + 'ttl': 90, + 'meta': { advertiserDomains: [] }, + 'vastXml': `key%3Dvalue` + } + beforeEach(function () { + videoResponse = { + body: { + 'id': '37386aade21a71', + 'seatbid': [{ + 'bid': [{ + 'id': 'a_403370_332fdb9b064040ddbec05891bd13ab28', + 'crid': 'creativelycreatedcreativecreative', + 'impid': '263c448586f5a1', + 'price': 0.45882675, + 'nurl': '', + 'adm': 'key%3Dvalue', + 'h': 480, + 'w': 640 + }] + }] + } + }; + }); + + it('should get the correct bid response', function () { + const expectedResponse = { + ...baseVideoResponse, + 'ad': decodeURIComponent(`key%3Dvalue`), + 'ttl': 60000, + }; + + const result = spec.interpretResponse(videoResponse); + + expect(result[0]).to.have.deep.keys(expectedResponse) + }); + + it('crid should default to the bid id if not on the response', function () { + delete videoResponse.body.seatbid[0].bid[0].crid; + + const expectedResponse = { + ...baseVideoResponse, + 'creativeId': videoResponse.body.seatbid[0].bid[0].id, + 'ad': decodeURIComponent(`key%3Dvalue`), + } + + const result = spec.interpretResponse(videoResponse); + + expect(result[0]).to.deep.equal(expectedResponse); + }); + + it('should get correct bid response when dealId is passed', function () { + videoResponse.body.seatbid[0].bid[0].dealid = 'baking'; + const expectedResponse = { + ...baseVideoResponse, + 'dealId': 'baking', + } + + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.deep.equal(expectedResponse); + }); + + it('should get correct bid response when ttl is set', function () { + videoResponse.body.seatbid[0].bid[0].ext = { 'ttl': 480 } + + const expectedResponse = { + ...baseVideoResponse, + 'ttl': 480, + } + + const result = spec.interpretResponse(videoResponse) + + expect(result[0]).to.deep.equal(expectedResponse) + }) + + it('handles empty bid response', function () { + const response = { + body: { + 'id': '37386aade21a71', + 'seatbid': [] + } + }; + + const result = spec.interpretResponse(response) + + expect(result.length).to.equal(0); + }); + }); + describe('getUserSyncs ', function() { const syncOptions = { iframeEnabled: true, pixelEnabled: false }; const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false }; From 179abb998190ac1ac996daea356d3f79b9628808 Mon Sep 17 00:00:00 2001 From: Maxim Pakhomov Date: Tue, 14 Dec 2021 19:26:59 +0400 Subject: [PATCH 13/14] EX-3448 updated condition for video response --- modules/sovrnBidAdapter.js | 9 +++------ test/spec/modules/sovrnBidAdapter_spec.js | 9 ++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index e4600b9f862..79da2563646 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -4,7 +4,7 @@ import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js' import { createEidsArray } from './userId/eids.js'; import {config} from '../src/config.js'; -export const ORTB_VIDEO_PARAMS = { +const ORTB_VIDEO_PARAMS = { 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), 'minduration': (value) => utils.isInteger(value), 'maxduration': (value) => utils.isInteger(value), @@ -198,12 +198,9 @@ export const spec = { meta: { advertiserDomains: sovrnBid && sovrnBid.adomain ? sovrnBid.adomain : [] } } - const videoRegex = new RegExp(/VAST\s+version/) - - if (videoRegex.test(sovrnBid.adm)) { + if (!sovrnBid.nurl) { bid.mediaType = VIDEO - bid.ad = decodeURIComponent(sovrnBid.adm) - bid.vastXml = sovrnBid.adm + bid.vastXml = decodeURIComponent(sovrnBid.adm) } else { bid.mediaType = BANNER bid.ad = decodeURIComponent(`${sovrnBid.adm}`) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js index b6629970055..09a61c82b6c 100644 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ b/test/spec/modules/sovrnBidAdapter_spec.js @@ -483,6 +483,8 @@ describe('sovrnBidAdapter', function() { describe('interpretResponse video', function () { let videoResponse; + const bidAdm = 'key%3Dvalue'; + const decodedBidAdm = decodeURIComponent(bidAdm); const baseVideoResponse = { 'requestId': '263c448586f5a1', 'cpm': 0.45882675, @@ -493,10 +495,9 @@ describe('sovrnBidAdapter', function() { 'currency': 'USD', 'netRevenue': true, 'mediaType': 'video', - 'ad': decodeURIComponent(`key%3Dvalue`), 'ttl': 90, 'meta': { advertiserDomains: [] }, - 'vastXml': `key%3Dvalue` + 'vastXml': decodedBidAdm } beforeEach(function () { videoResponse = { @@ -509,7 +510,7 @@ describe('sovrnBidAdapter', function() { 'impid': '263c448586f5a1', 'price': 0.45882675, 'nurl': '', - 'adm': 'key%3Dvalue', + 'adm': bidAdm, 'h': 480, 'w': 640 }] @@ -521,7 +522,6 @@ describe('sovrnBidAdapter', function() { it('should get the correct bid response', function () { const expectedResponse = { ...baseVideoResponse, - 'ad': decodeURIComponent(`key%3Dvalue`), 'ttl': 60000, }; @@ -536,7 +536,6 @@ describe('sovrnBidAdapter', function() { const expectedResponse = { ...baseVideoResponse, 'creativeId': videoResponse.body.seatbid[0].bid[0].id, - 'ad': decodeURIComponent(`key%3Dvalue`), } const result = spec.interpretResponse(videoResponse); From 3fcf028461efb23641d9f6461a42144e34169789 Mon Sep 17 00:00:00 2001 From: Chris Pabst Date: Mon, 10 Jan 2022 11:08:56 -0700 Subject: [PATCH 14/14] EX-3448: Standardized util function usage. --- modules/sovrnBidAdapter.js | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/modules/sovrnBidAdapter.js b/modules/sovrnBidAdapter.js index 79da2563646..060bfc335dc 100644 --- a/modules/sovrnBidAdapter.js +++ b/modules/sovrnBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess } from '../src/utils.js'; +import { _each, getBidIdParameter, isArray, deepClone, parseUrl, getUniqueIdentifierStr, deepSetValue, logError, deepAccess, isInteger, logWarn } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js' import { ADPOD, BANNER, VIDEO } from '../src/mediaTypes.js' import { createEidsArray } from './userId/eids.js'; @@ -6,22 +6,22 @@ import {config} from '../src/config.js'; const ORTB_VIDEO_PARAMS = { 'mimes': (value) => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string'), - 'minduration': (value) => utils.isInteger(value), - 'maxduration': (value) => utils.isInteger(value), + 'minduration': (value) => isInteger(value), + 'maxduration': (value) => isInteger(value), 'protocols': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 10), - 'w': (value) => utils.isInteger(value), - 'h': (value) => utils.isInteger(value), - 'startdelay': (value) => utils.isInteger(value), + 'w': (value) => isInteger(value), + 'h': (value) => isInteger(value), + 'startdelay': (value) => isInteger(value), 'placement': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 5), 'linearity': (value) => [1, 2].indexOf(value) !== -1, 'skip': (value) => [0, 1].indexOf(value) !== -1, - 'skipmin': (value) => utils.isInteger(value), - 'skipafter': (value) => utils.isInteger(value), - 'sequence': (value) => utils.isInteger(value), + 'skipmin': (value) => isInteger(value), + 'skipafter': (value) => isInteger(value), + 'sequence': (value) => isInteger(value), 'battr': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 17), - 'maxextended': (value) => utils.isInteger(value), - 'minbitrate': (value) => utils.isInteger(value), - 'maxbitrate': (value) => utils.isInteger(value), + 'maxextended': (value) => isInteger(value), + 'minbitrate': (value) => isInteger(value), + 'maxbitrate': (value) => isInteger(value), 'boxingallowed': (value) => [0, 1].indexOf(value) !== -1, 'playbackmethod': (value) => Array.isArray(value) && value.every(v => v >= 1 && v <= 6), 'playbackend': (value) => [1, 2, 3].indexOf(value) !== -1, @@ -86,14 +86,14 @@ export const spec = { const imp = { adunitcode: bid.adUnitCode, id: bid.bidId, - tagid: String(utils.getBidIdParameter('tagid', bid.params)), + tagid: String(getBidIdParameter('tagid', bid.params)), bidfloor: floorInfo.floor } - if (utils.deepAccess(bid, 'mediaTypes.banner')) { - let bidSizes = utils.deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes - bidSizes = (utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes] - bidSizes = bidSizes.filter(size => utils.isArray(size)) + if (deepAccess(bid, 'mediaTypes.banner')) { + let bidSizes = deepAccess(bid, 'mediaTypes.banner.sizes') || bid.sizes + bidSizes = (isArray(bidSizes) && isArray(bidSizes[0])) ? bidSizes : [bidSizes] + bidSizes = bidSizes.filter(size => isArray(size)) const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)})) imp.banner = { @@ -103,8 +103,8 @@ export const spec = { }; } if ( - utils.deepAccess(bid, 'mediaTypes.video') && - utils.deepAccess(bid, 'mediaTypes.video.context') !== ADPOD + deepAccess(bid, 'mediaTypes.video') && + deepAccess(bid, 'mediaTypes.video.context') !== ADPOD ) { imp.video = _buildVideoRequestObj(bid); } @@ -254,8 +254,8 @@ export const spec = { function _buildVideoRequestObj(bid) { const videoObj = {} - const videoAdUnitParams = utils.deepAccess(bid, 'mediaTypes.video', {}) - const videoBidderParams = utils.deepAccess(bid, 'params.video', {}) + const videoAdUnitParams = deepAccess(bid, 'mediaTypes.video', {}) + const videoBidderParams = deepAccess(bid, 'params.video', {}) const computedParams = {} if (Array.isArray(videoAdUnitParams.playerSize)) { @@ -275,7 +275,7 @@ function _buildVideoRequestObj(bid) { if (ORTB_VIDEO_PARAMS[paramName](videoParams[paramName])) { videoObj[paramName] = videoParams[paramName] } else { - utils.logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); + logWarn(`The OpenRTB video param ${paramName} has been skipped due to misformating. Please refer to OpenRTB 2.5 spec.`); } } })