From ccd198268055c6c40db5b01bb5fb53a3433372a1 Mon Sep 17 00:00:00 2001 From: susyt Date: Thu, 21 Nov 2019 06:27:46 -0800 Subject: [PATCH] adds schain param (#4442) --- modules/gumgumBidAdapter.js | 26 +++++++++++++++++++ test/spec/modules/gumgumBidAdapter_spec.js | 30 +++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/modules/gumgumBidAdapter.js b/modules/gumgumBidAdapter.js index 585d3279a077..df6ca1971ee0 100644 --- a/modules/gumgumBidAdapter.js +++ b/modules/gumgumBidAdapter.js @@ -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. * @@ -141,6 +163,7 @@ function buildRequests (validBidRequests, bidderRequest) { const { bidId, params = {}, + schain, transactionId, userId = {} } = bidRequest; @@ -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, diff --git a/test/spec/modules/gumgumBidAdapter_spec.js b/test/spec/modules/gumgumBidAdapter_spec.js index 0d00eb2b93c9..97897a11ed3b 100644 --- a/test/spec/modules/gumgumBidAdapter_spec.js +++ b/test/spec/modules/gumgumBidAdapter_spec.js @@ -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' + } + ] + } } ]; @@ -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;