diff --git a/modules/adtrueBidAdapter.js b/modules/adtrueBidAdapter.js index fa83f9f29f7..b4dc7f7ea89 100644 --- a/modules/adtrueBidAdapter.js +++ b/modules/adtrueBidAdapter.js @@ -14,9 +14,8 @@ const UNDEFINED = undefined; const DEFAULT_WIDTH = 0; const DEFAULT_HEIGHT = 0; const NET_REVENUE = false; -const USER_SYNC_URL_IFRAME = 'https://hb.adtrue.com/prebid/usersync?t=iframe&p='; -const USER_SYNC_URL_IMAGE = 'https://hb.adtrue.com/prebid/usersync?t=img&p='; let publisherId = 0; +let zoneId = 0; let NATIVE_ASSET_ID_TO_KEY_MAP = {}; const DATA_TYPES = { 'NUMBER': 'number', @@ -25,6 +24,11 @@ const DATA_TYPES = { 'ARRAY': 'array', 'OBJECT': 'object' }; +const SYNC_TYPES = Object.freeze({ + 1: 'iframe', + 2: 'image' +}); + const VIDEO_CUSTOM_PARAMS = { 'mimes': DATA_TYPES.ARRAY, 'minduration': DATA_TYPES.NUMBER, @@ -440,6 +444,14 @@ export const spec = { utils.logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId'); return false; } + if (!utils.isStr(bid.params.publisherId)) { + utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric'); + return false; + } + if (!utils.isStr(bid.params.zoneId)) { + utils.logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric'); + return false; + } return true; } return false; @@ -478,6 +490,7 @@ export const spec = { return; } publisherId = conf.pubId.trim(); + zoneId = conf.zoneId.trim(); payload.site.publisher.id = conf.pubId.trim(); payload.ext.wrapper = {}; @@ -498,9 +511,7 @@ export const spec = { if (typeof config.getConfig('device') === 'object') { payload.device = Object.assign(payload.device, config.getConfig('device')); } - utils.deepSetValue(payload, 'source.tid', conf.transactionId); - // test bids if (window.location.href.indexOf('adtrueTest=true') !== -1) { payload.test = 1; @@ -509,7 +520,6 @@ export const spec = { if (validBidRequests[0].schain) { utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain); } - // Attaching GDPR Consent Params if (bidderRequest && bidderRequest.gdprConsent) { utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString); @@ -520,7 +530,6 @@ export const spec = { if (bidderRequest && bidderRequest.uspConsent) { utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } - // coppa compliance if (config.getConfig('coppa') === true) { utils.deepSetValue(payload, 'regs.coppa', 1); @@ -576,7 +585,6 @@ export const spec = { } }); } - newBid.meta = {}; if (bid.ext && bid.ext.dspid) { newBid.meta.networkId = bid.ext.dspid; @@ -588,14 +596,12 @@ export const spec = { newBid.meta.advertiserDomains = bid.adomain; newBid.meta.clickUrl = bid.adomain[0]; } - // adserverTargeting if (seatbidder.ext && seatbidder.ext.buyid) { newBid.adserverTargeting = { 'hb_buyid_adtrue': seatbidder.ext.buyid }; } - bidResponses.push(newBid); }); }); @@ -606,32 +612,28 @@ export const spec = { return bidResponses; }, getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) { - let syncurl = '' + publisherId; - - if (gdprConsent) { - syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0); - syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || ''); - } - if (uspConsent) { - syncurl += '&us_privacy=' + encodeURIComponent(uspConsent); - } - - // coppa compliance - if (config.getConfig('coppa') === true) { - syncurl += '&coppa=1'; - } - - if (syncOptions.iframeEnabled) { - return [{ - type: 'iframe', - url: USER_SYNC_URL_IFRAME + syncurl - }]; - } else { - return [{ - type: 'image', - url: USER_SYNC_URL_IMAGE + syncurl - }]; + if (!responses || responses.length === 0 || (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled)) { + return []; } + return responses.reduce((accum, rsp) => { + let cookieSyncs = utils.deepAccess(rsp, 'body.ext.cookie_sync'); + if (cookieSyncs) { + let cookieSyncObjects = cookieSyncs.map(cookieSync => { + return { + type: SYNC_TYPES[cookieSync.type], + url: cookieSync.url + + '&publisherId=' + publisherId + + '&zoneId=' + zoneId + + '&gdpr=' + (gdprConsent && gdprConsent.gdprApplies ? 1 : 0) + + '&gdpr_consent=' + encodeURIComponent((gdprConsent ? gdprConsent.consentString : '')) + + '&us_privacy=' + encodeURIComponent((uspConsent || '')) + + '&coppa=' + (config.getConfig('coppa') === true ? 1 : 0) + }; + }); + return accum.concat(cookieSyncObjects); + } + }, []); } }; + registerBidder(spec); diff --git a/test/spec/modules/adtrueBidAdapter_spec.js b/test/spec/modules/adtrueBidAdapter_spec.js index a7732d6aeb7..8e1c872d460 100644 --- a/test/spec/modules/adtrueBidAdapter_spec.js +++ b/test/spec/modules/adtrueBidAdapter_spec.js @@ -8,6 +8,7 @@ describe('AdTrueBidAdapter', function () { const adapter = newBidder(spec) let bidRequests; let bidResponses; + let bidResponses2; beforeEach(function () { bidRequests = [ { @@ -48,34 +49,85 @@ describe('AdTrueBidAdapter', function () { } ]; bidResponses = { - 'body': { - 'id': '1610681506302', - 'seatbid': [ + body: { + id: '1610681506302', + seatbid: [ { - 'bid': [ + bid: [ { - 'id': '1', - 'impid': '201fb513ca24e9', - 'price': 2.880000114440918, - 'burl': 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}', - 'adm': '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>', - 'adid': '1610681506302', - 'adomain': [ + id: '1', + impid: '201fb513ca24e9', + price: 2.880000114440918, + burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}', + adm: '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>', + adid: '1610681506302', + adomain: [ 'adtrue.com' ], - 'cid': 'f6l0r6n', - 'crid': 'abc77au4', - 'attr': [], - 'w': 300, - 'h': 250 + cid: 'f6l0r6n', + crid: 'abc77au4', + attr: [], + w: 300, + h: 250 } ], - 'seat': 'adtrue', - 'group': 0 + seat: 'adtrue', + group: 0 } ], - 'bidid': '1610681506302', - 'cur': 'USD' + bidid: '1610681506302', + cur: 'USD', + ext: { + cookie_sync: [ + { + type: 1, + url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue' + } + ] + } + } + }; + bidResponses2 = { + body: { + id: '1610681506302', + seatbid: [ + { + bid: [ + { + id: '1', + impid: '201fb513ca24e9', + price: 2.880000114440918, + burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}', + adm: '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>', + adid: '1610681506302', + adomain: [ + 'adtrue.com' + ], + cid: 'f6l0r6n', + crid: 'abc77au4', + attr: [], + w: 300, + h: 250 + } + ], + seat: 'adtrue', + group: 0 + } + ], + bidid: '1610681506302', + cur: 'USD', + ext: { + cookie_sync: [ + { + type: 2, + url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image' + }, + { + type: 1, + url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus' + } + ] + } } }; }); @@ -349,8 +401,6 @@ describe('AdTrueBidAdapter', function () { }); }); describe('getUserSyncs', function () { - let USER_SYNC_URL_IFRAME = 'https://hb.adtrue.com/prebid/usersync?t=iframe&p=1212'; - let USER_SYNC_URL_IMAGE = 'https://hb.adtrue.com/prebid/usersync?t=img&p=1212'; let sandbox; beforeEach(function () { sandbox = sinon.sandbox.create(); @@ -359,12 +409,23 @@ describe('AdTrueBidAdapter', function () { sandbox.restore(); }); it('execute as per config', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: USER_SYNC_URL_IFRAME - }]); - expect(spec.getUserSyncs({iframeEnabled: false}, {}, undefined, undefined)).to.deep.equal([{ - type: 'image', url: USER_SYNC_URL_IMAGE + expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses], undefined, undefined)).to.deep.equal([{ + type: 'iframe', + url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' }]); }); + // Multiple user sync output + it('execute as per config', function () { + expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses2], undefined, undefined)).to.deep.equal([ + { + type: 'image', + url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' + }, + { + type: 'iframe', + url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' + } + ]); + }); }); });