Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediasquare: Add support for uspConsent + schain userIds support. Plu… #5396

Merged
merged 2 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/');
});
});