Skip to content

Commit

Permalink
Mediasquare: Add support for uspConsent + schain userIds support. Plu… (
Browse files Browse the repository at this point in the history
#5396)

* Mediasquare: Add support for uspConsent + schain userIds support. Plus enhance userSync

* fix iframeEnabled and pixelEnabled + suggested shortand statement
  • Loading branch information
matthieularere-msq authored Jun 30, 2020
1 parent ccf10b6 commit bcfc972
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
36 changes: 17 additions & 19 deletions modules/mediasquareBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -109,25 +113,19 @@ 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) {
if (serverResponses[0].body.hasOwnProperty('cookies') && typeof serverResponses[0].body.cookies === 'object') {
return serverResponses[0].body.cookies;
} else {
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
};
}
if (syncOptions.pixelEnabled) {
return {
type: 'image',
url: endpoint + BIDDER_ENDPOINT_SYNC + '?type=pixel' + params
};
}
return false;
},

/**
Expand Down
42 changes: 25 additions & 17 deletions test/spec/modules/mediasquareBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down Expand Up @@ -103,21 +117,15 @@ describe('MediaSquare bid adapter tests', function () {
const won = spec.onBidWon(response[0]);
expect(won).to.equal(true);
});
it('Verifies user sync', function () {
var syncs = spec.getUserSyncs({
iframeEnabled: true,
pixelEnabled: false,
}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent);
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.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);
});
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({}, [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/');
});
});

0 comments on commit bcfc972

Please sign in to comment.