Skip to content

Commit

Permalink
SmileWanted : add schain support
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinGallard committed Jun 18, 2024
1 parent 566c48f commit 7b65e36
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 23 deletions.
65 changes: 43 additions & 22 deletions modules/smilewantedBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ export const spec = {
return true;
},

/**
* Serialize the supply chain object to a string uri encoded
*
* @param {*} schain object
*/
serializeSupplyChain: function(schain) {
if (!schain?.nodes) return null;
const nodesProperties = ['asi', 'sid', 'hp', 'rid', 'name', 'domain', 'ext'];

const header = `${schain.ver},${schain.complete}!`;
const nodes = schain.nodes.map(node => nodesProperties.map(prop =>
node[prop] ? encodeURIComponent(node[prop]) : '')
.join(','))
.join('!');

return header + nodes;
},

/**
* Make a server request from the list of BidRequests.
*
Expand Down Expand Up @@ -82,7 +100,8 @@ export const spec = {
or from mediaTypes.banner.pos
*/
positionType: bid.params.positionType || '',
prebidVersion: '$prebid.version$'
prebidVersion: '$prebid.version$',
schain: spec.serializeSupplyChain(bid.schain)
};

const floor = getBidFloor(bid);
Expand Down Expand Up @@ -154,16 +173,16 @@ export const spec = {
if (response) {
const dealId = response.dealId || '';
const bidResponse = {
requestId: bidRequestData.bidId,
ad: response.ad,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creativeId,
dealId: response.dealId,
currency: response.currency,
dealId: response.dealId,
height: response.height,
netRevenue: response.isNetCpm,
requestId: bidRequestData.bidId,
ttl: response.ttl,
ad: response.ad,
width: response.width,
};

if (response.formatTypeSw === 'video_instream' || response.formatTypeSw === 'video_outstream') {
Expand Down Expand Up @@ -209,28 +228,30 @@ export const spec = {
* @param {Object} uspConsent The USP consent parameters
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, responses, gdprConsent, uspConsent) {
let params = '';

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
params += `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
params += `?gdpr_consent=${gdprConsent.consentString}`;
getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
const syncs = [];

if (syncOptions.iframeEnabled) {
let params = [];

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
params.push(`gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`);
} else {
params.push(`gdpr_consent=${gdprConsent.consentString}`);
}
}
}

if (uspConsent) {
params += `${params ? '&' : '?'}us_privacy=${encodeURIComponent(uspConsent)}`;
}
if (uspConsent) {
params.push(`us_privacy=${encodeURIComponent(uspConsent)}`);
}

const syncs = []
const paramsStr = params.length > 0 ? '?' + params.join('&') : '';

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://csync.smilewanted.com' + params
url: 'https://csync.smilewanted.com' + paramsStr
});
}

Expand Down
102 changes: 101 additions & 1 deletion test/spec/modules/smilewantedBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,49 @@ const DISPLAY_REQUEST_WITH_POSITION_TYPE = [{
},
}];

const SCHAIN = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.com',
'sid': '1234',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher',
'domain': 'publisher.com'
},
{
'asi': 'exchange2.com',
'sid': 'abcd',
'hp': 1,
'rid': 'bid-request-2',
'name': 'intermediary',
'domain': 'intermediary.com'
}
]
};

const DISPLAY_REQUEST_WITH_SCHAIN = [{
adUnitCode: 'sw_300x250',
bidId: '12345',
sizes: [
[300, 250],
[300, 200]
],
bidder: 'smilewanted',
params: {
zoneId: 1,
},
requestId: 'request_abcd1234',
ortb2Imp: {
ext: {
tid: 'trans_abcd1234',
}
},
schain: SCHAIN,
}];

const BID_RESPONSE_DISPLAY = {
body: {
cpm: 3,
Expand Down Expand Up @@ -580,8 +623,21 @@ describe('smilewantedBidAdapterTests', function () {
expect(requestContent).to.have.property('positionType').and.to.equal('infeed');
});

it('SmileWanted - Verify if schain is well passed', function () {
const request = spec.buildRequests(DISPLAY_REQUEST_WITH_SCHAIN, {});
const requestContent = JSON.parse(request[0].data);
expect(requestContent).to.have.property('schain').and.to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com,!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com,');
});

it('SmileWanted - Verify user sync - empty data', function () {
let syncs = spec.getUserSyncs({iframeEnabled: true}, {}, {}, null);
expect(syncs).to.have.lengthOf(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://csync.smilewanted.com');
});

it('SmileWanted - Verify user sync', function () {
var syncs = spec.getUserSyncs({iframeEnabled: true}, {}, {
let syncs = spec.getUserSyncs({iframeEnabled: true}, {}, {
consentString: 'foo'
}, '1NYN');
expect(syncs).to.have.lengthOf(1);
Expand All @@ -599,3 +655,47 @@ describe('smilewantedBidAdapterTests', function () {
expect(syncs).to.have.lengthOf(1);
});
});

describe('Supply Chain Serializer tests', function () {
it('Verify a multi node supply chain serialization matches iab example', function() {
let schain = {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'exchange1.com',
'sid': '1234',
'hp': 1,
'rid': 'bid-request-1',
'name': 'publisher',
'domain': 'publisher.com'
},
{
'asi': 'exchange2.com',
'sid': 'abcd',
'hp': 1,
'rid': 'bid-request-2',
'name': 'intermediary',
'domain': 'intermediary.com'
}
]
};

let serializedSchain = spec.serializeSupplyChain(schain);
expect(serializedSchain).to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com,!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com,');
});

it('Verify that null schain produce null result', function () {
let actual = spec.serializeSupplyChain(null);
expect(actual).to.equal(null);
});

it('Verify that schain with null nodes produce null result', function () {
let schain = {
'ver': '1.0',
'complete': 1
};
let actual = spec.serializeSupplyChain(null);
expect(actual).to.equal(null);
});
});

0 comments on commit 7b65e36

Please sign in to comment.