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

Add Supply Supply Chain Object Module support for Yieldlab Adapter #5521

Merged
merged 5 commits into from
Sep 15, 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
34 changes: 33 additions & 1 deletion modules/yieldlabBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const spec = {
query[prop] = bid.params.customParams[prop]
}
}
if (bid.schain && utils.isPlainObject(bid.schain) && Array.isArray(bid.schain.nodes)) {
query.schain = createSchainString(bid.schain)
}
})

if (bidderRequest) {
Expand Down Expand Up @@ -202,7 +205,12 @@ function createQueryString (obj) {
let str = []
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]))
let val = obj[p]
if (p !== 'schain') {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(val))
} else {
str.push(p + '=' + val)
}
}
}
return str.join('&')
Expand All @@ -225,6 +233,30 @@ function createTargetingString (obj) {
return str.join('&')
}

/**
* Creates a string out of a schain object
* @param {Object} schain
* @returns {String}
*/
function createSchainString (schain) {
const ver = schain.ver || ''
const complete = schain.complete || ''
const keys = ['asi', 'sid', 'hp', 'rid', 'name', 'domain', 'ext']
const nodesString = schain.nodes.reduce((acc, node) => {
return acc += `!${keys.map(key => node[key] ? encodeURIComponentWithBangIncluded(node[key]) : '').join(',')}`
}, '')
return `${ver},${complete}${nodesString}`
}

/**
* Encodes URI Component with exlamation mark included. Needed for schain object.
* @param {String} str
* @returns {String}
*/
function encodeURIComponentWithBangIncluded(str) {
return encodeURIComponent(str).replace(/!/g, '%21')
}

/**
* Handles an outstream response after the library is loaded
* @param {Object} bid
Expand Down
23 changes: 22 additions & 1 deletion test/spec/modules/yieldlabBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,24 @@ const REQUEST = {
'id': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg',
'atype': 1
}]
}]
}],
'schain': {
'ver': '1.0',
'complete': 1,
'nodes': [
{
'asi': 'indirectseller.com',
'sid': '1',
'hp': 1
},
{
'asi': 'indirectseller2.com',
'name': 'indirectseller2 name with comma , and bang !',
'sid': '2',
'hp': 1
}
]
}
}

const RESPONSE = {
Expand Down Expand Up @@ -107,6 +124,10 @@ describe('yieldlabBidAdapter', function () {
expect(request.url).to.include('extraParam=true&foo=bar')
})

it('passes unencoded schain string to bid request', function () {
expect(request.url).to.include('schain=1.0,1!indirectseller.com,1,1,,,,!indirectseller2.com,2,1,,indirectseller2%20name%20with%20comma%20%2C%20and%20bang%20%21,,')
})

const refererRequest = spec.buildRequests(bidRequests, {
refererInfo: {
canonicalUrl: undefined,
Expand Down