From 2c13cb9756d2d0339849134698cb0f2aa26f426f Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Thu, 18 Jun 2020 16:10:33 +0200 Subject: [PATCH 1/2] Mediasquare: Add support for uspConsent + schain userIds support. Plus enhance userSync --- modules/mediasquareBidAdapter.js | 55 +++++++++++-------- .../modules/mediasquareBidAdapter_spec.js | 33 +++++++++-- 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/modules/mediasquareBidAdapter.js b/modules/mediasquareBidAdapter.js index 91adfacb64d..c6f51ecd013 100644 --- a/modules/mediasquareBidAdapter.js +++ b/modules/mediasquareBidAdapter.js @@ -21,7 +21,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function(bid) { - return !!(bid.params.owner || bid.params.code); + return !!(bid.params.owner && bid.params.code); }, /** * Make a server request from the list of BidRequests. @@ -49,13 +49,17 @@ export const spec = { const payload = { codes: codes, referer: encodeURIComponent(bidderRequest.refererInfo.referer) - // schain: validBidRequests.schain, }; - if (bidderRequest && bidderRequest.gdprConsent) { - payload.gdpr = { - consent_string: bidderRequest.gdprConsent.consentString, - consent_required: bidderRequest.gdprConsent.gdprApplies - }; + if (bidderRequest) { // modules informations (gdpr, ccpa, schain, userId) + if (bidderRequest.gdprConsent) { + payload.gdpr = { + consent_string: bidderRequest.gdprConsent.consentString, + consent_required: bidderRequest.gdprConsent.gdprApplies + }; + } + if (bidderRequest.uspConsent) { payload.uspConsent = bidderRequest.uspConsent; } + if (bidderRequest.schain) { payload.schain = bidderRequest.schain; } + if (bidderRequest.userId) { payload.userId = bidderRequest.userId; } }; if (test) { payload.debug = true; } const payloadString = JSON.stringify(payload); @@ -109,25 +113,30 @@ export const spec = { * @param {ServerResponse[]} serverResponses List of server's responses. * @return {UserSync[]} The user syncs which should be dropped. */ - getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { + getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { let params = ''; let endpoint = document.location.search.match(/msq_test=true/) ? BIDDER_URL_TEST : BIDDER_URL_PROD; - if (gdprConsent && typeof gdprConsent.consentString === 'string') { - if (typeof gdprConsent.gdprApplies === 'boolean') { params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; } else { params += `&gdpr_consent=${gdprConsent.consentString}`; } - } - if (syncOptions.iframeEnabled) { - return { - type: 'iframe', - url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=iframe' + params - }; - } - if (syncOptions.pixelEnabled) { - return { - type: 'image', - url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=pixel' + params - }; + if (serverResponses[0].body.hasOwnProperty('cookies') && typeof serverResponses[0].body.cookies === 'object') { + return serverResponses[0].body.cookies; + } else { + if (gdprConsent && typeof gdprConsent.consentString === 'string') { + if (typeof gdprConsent.gdprApplies === 'boolean') { params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; } else { params += `&gdpr_consent=${gdprConsent.consentString}`; } + } + if (uspConsent && typeof uspConsent === 'string') { params += '&uspConsent=' + uspConsent } + if (syncOptions.iframeEnabled) { + return { + type: 'iframe', + url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=iframe' + params + }; + } + if (syncOptions.pixelEnabled) { + return { + type: 'image', + url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=pixel' + params + }; + } + return false; } - return false; }, /** diff --git a/test/spec/modules/mediasquareBidAdapter_spec.js b/test/spec/modules/mediasquareBidAdapter_spec.js index 56c1fd105fe..586016056bc 100644 --- a/test/spec/modules/mediasquareBidAdapter_spec.js +++ b/test/spec/modules/mediasquareBidAdapter_spec.js @@ -39,7 +39,7 @@ describe('MediaSquare bid adapter tests', function () { 'bidder': 'msqClassic', 'code': 'test/publishername_atf_desktop_rg_pave', 'bid_id': 'aaaa1234', - }] + }], }}; const DEFAULT_OPTIONS = { @@ -51,7 +51,21 @@ describe('MediaSquare bid adapter tests', function () { refererInfo: { referer: 'https://www.prebid.org', canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - } + }, + uspConsent: '111222333', + userId: {'id5id': '1111'}, + schain: { + 'ver': '1.0', + 'complete': 1, + 'nodes': [{ + 'asi': 'exchange1.com', + 'sid': '1234', + 'hp': 1, + 'rid': 'bid-request-1', + 'name': 'publisher', + 'domain': 'publisher.com' + }] + }, }; it('Verify build request', function () { const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); @@ -103,11 +117,11 @@ describe('MediaSquare bid adapter tests', function () { const won = spec.onBidWon(response[0]); expect(won).to.equal(true); }); - it('Verifies user sync', function () { + it('Verifies user sync without cookie in bid response', function () { var syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: false, - }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); + }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); expect(syncs).to.have.property('type').and.to.equal('iframe'); syncs = spec.getUserSyncs({ iframeEnabled: false, @@ -119,5 +133,16 @@ describe('MediaSquare bid adapter tests', function () { pixelEnabled: false, }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); expect(syncs).to.equal(false); + BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; + }); + it('Verifies user sync with cookies in bid response', function () { + BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; + var syncs = spec.getUserSyncs({ + iframeEnabled: true, + pixelEnabled: false, + }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); + expect(syncs).to.have.lengthOf(1); + expect(syncs[0]).to.have.property('type').and.to.equal('image'); + expect(syncs[0]).to.have.property('url').and.to.equal('http://www.cookie.sync.org/'); }); }); From f4b0be6e9442b6d30f48fed968e7bc1ce421f4b0 Mon Sep 17 00:00:00 2001 From: matthieularere-msq Date: Fri, 26 Jun 2020 11:53:05 +0200 Subject: [PATCH 2/2] fix iframeEnabled and pixelEnabled + suggested shortand statement --- modules/mediasquareBidAdapter.js | 21 +++++-------------- .../modules/mediasquareBidAdapter_spec.js | 21 ++----------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/modules/mediasquareBidAdapter.js b/modules/mediasquareBidAdapter.js index c6f51ecd013..cb52c288caf 100644 --- a/modules/mediasquareBidAdapter.js +++ b/modules/mediasquareBidAdapter.js @@ -119,23 +119,12 @@ export const spec = { if (serverResponses[0].body.hasOwnProperty('cookies') && typeof serverResponses[0].body.cookies === 'object') { return serverResponses[0].body.cookies; } else { - if (gdprConsent && typeof gdprConsent.consentString === 'string') { - if (typeof gdprConsent.gdprApplies === 'boolean') { params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; } else { params += `&gdpr_consent=${gdprConsent.consentString}`; } - } + 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 } - if (syncOptions.iframeEnabled) { - return { - type: 'iframe', - url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=iframe' + params - }; - } - if (syncOptions.pixelEnabled) { - return { - type: 'image', - url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=pixel' + params - }; - } - return false; + return { + type: 'iframe', + url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=iframe' + params + }; } }, diff --git a/test/spec/modules/mediasquareBidAdapter_spec.js b/test/spec/modules/mediasquareBidAdapter_spec.js index 586016056bc..351fbb40228 100644 --- a/test/spec/modules/mediasquareBidAdapter_spec.js +++ b/test/spec/modules/mediasquareBidAdapter_spec.js @@ -118,29 +118,12 @@ describe('MediaSquare bid adapter tests', function () { expect(won).to.equal(true); }); it('Verifies user sync without cookie in bid response', function () { - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: false, - }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); + var syncs = spec.getUserSyncs({}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); expect(syncs).to.have.property('type').and.to.equal('iframe'); - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true, - }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); - expect(syncs).to.have.property('type').and.to.equal('image'); - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false, - }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); - expect(syncs).to.equal(false); - BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; }); it('Verifies user sync with cookies in bid response', function () { BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: false, - }, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); + var syncs = spec.getUserSyncs({}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); expect(syncs).to.have.lengthOf(1); expect(syncs[0]).to.have.property('type').and.to.equal('image'); expect(syncs[0]).to.have.property('url').and.to.equal('http://www.cookie.sync.org/');