Skip to content

Commit

Permalink
adds schain param (prebid#4442)
Browse files Browse the repository at this point in the history
  • Loading branch information
susyt authored and tadam75 committed Jan 9, 2020
1 parent cb528f6 commit ccd1982
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
26 changes: 26 additions & 0 deletions modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ function _getDigiTrustQueryParams(userId) {
};
}

/**
* Serializes the supply chain object according to IAB standards
* @see https://github.com/InteractiveAdvertisingBureau/openrtb/blob/master/supplychainobject.md
* @param {Object} schainObj supply chain object
* @returns {string}
*/
function _serializeSupplyChainObj(schainObj) {
let serializedSchain = `${schainObj.ver},${schainObj.complete}`;

// order of properties: asi,sid,hp,rid,name,domain
schainObj.nodes.map(node => {
serializedSchain += `!${encodeURIComponent(node['asi'] || '')},`;
serializedSchain += `${encodeURIComponent(node['sid'] || '')},`;
serializedSchain += `${encodeURIComponent(node['hp'] || '')},`;
serializedSchain += `${encodeURIComponent(node['rid'] || '')},`;
serializedSchain += `${encodeURIComponent(node['name'] || '')},`;
serializedSchain += `${encodeURIComponent(node['domain'] || '')}`;
})

return serializedSchain;
}

/**
* Determines whether or not the given bid request is valid.
*
Expand Down Expand Up @@ -141,6 +163,7 @@ function buildRequests (validBidRequests, bidderRequest) {
const {
bidId,
params = {},
schain,
transactionId,
userId = {}
} = bidRequest;
Expand Down Expand Up @@ -171,6 +194,9 @@ function buildRequests (validBidRequests, bidderRequest) {
if (data.gdprApplies) {
data.gdprConsent = gdprConsent.consentString;
}
if (schain && schain.nodes) {
data.schain = _serializeSupplyChainObj(schain);
}

bids.push({
id: bidId,
Expand Down
30 changes: 29 additions & 1 deletion test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,29 @@ describe('gumgumAdapter', function () {
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250], [300, 600]],
'bidId': '30b31c1838de1e'
'bidId': '30b31c1838de1e',
'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'
}
]
}
}
];

Expand Down Expand Up @@ -140,6 +162,12 @@ describe('gumgumAdapter', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.data).to.not.include.any.keys('tdid');
});
it('should send schain parameter in serialized form', function () {
const serializedForm = '1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com'
const request = spec.buildRequests(bidRequests)[0];
expect(request.data).to.include.any.keys('schain');
expect(request.data.schain).to.eq(serializedForm);
});
it('should send ns parameter if browser contains navigator.connection property', function () {
const bidRequest = spec.buildRequests(bidRequests)[0];
const connection = window.navigator && window.navigator.connection;
Expand Down

0 comments on commit ccd1982

Please sign in to comment.