Skip to content

Commit

Permalink
add schain support (#11111)
Browse files Browse the repository at this point in the history
  • Loading branch information
0tarof authored Feb 20, 2024
1 parent 67210fa commit 969e417
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
31 changes: 27 additions & 4 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ export const spec = {
queryString = tryAppendQueryString(queryString, 'cdep', bidRequest.ortb2?.device?.ext?.cdep)
queryString = tryAppendQueryString(queryString, 'prebid_id', bidRequest.bidId);
queryString = tryAppendQueryString(queryString, 'prebid_ver', '$prebid.version$');

if (pageUrl) {
queryString = tryAppendQueryString(queryString, 'page_url', pageUrl);
}
queryString = tryAppendQueryString(queryString, 'page_url', pageUrl);
queryString = tryAppendQueryString(queryString, 'schain', spec.serializeSupplyChain(bidRequest.schain || []))

const adFormatIDs = pickAdFormats(bidRequest)
if (adFormatIDs && adFormatIDs.length > 0) {
Expand Down Expand Up @@ -172,6 +170,31 @@ export const spec = {

return syncs;
},

/**
* Serialize supply chain object
* @param {Object} supplyChain
* @returns {String | undefined}
*/
serializeSupplyChain: function(supplyChain) {
if (!supplyChain || !supplyChain.nodes) return undefined
const { ver, complete, nodes } = supplyChain
return `${ver},${complete}!${spec.serializeSupplyChainNodes(nodes)}`
},

/**
* Serialize each supply chain nodes
* @param {Array} nodes
* @returns {String}
*/
serializeSupplyChainNodes: function(nodes) {
const fields = ['asi', 'sid', 'hp', 'rid', 'name', 'domain']
return nodes.map((n) => {
return fields.map((f) => {
return encodeURIComponent(n[f] || '').replace(/!/g, '%21')
}).join(',')
}).join('!')
}
}

function pickAdFormats(bidRequest) {
Expand Down
27 changes: 25 additions & 2 deletions test/spec/modules/ajaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,32 @@ describe('AjaAdapter', function () {
tid: 'cea1eb09-d970-48dc-8585-634d3a7b0544',
gpid: '/1111/homepage#300x250'
}
}
},
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 serializedSchain = encodeURIComponent('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com')

const bidderRequest = {
refererInfo: {
Expand All @@ -87,7 +110,7 @@ describe('AjaAdapter', function () {
const requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests[0].url).to.equal(ENDPOINT);
expect(requests[0].method).to.equal('GET');
expect(requests[0].data).to.equal('asi=123456&skt=5&gpid=%2F1111%2Fhomepage%23300x250&tid=cea1eb09-d970-48dc-8585-634d3a7b0544&cdep=example_label_1&prebid_id=30b31c1838de1e&prebid_ver=$prebid.version$&page_url=https%3A%2F%2Fhoge.com&ad_format_ids=2&sua=%7B%22source%22%3A2%2C%22platform%22%3A%7B%22brand%22%3A%22Android%22%2C%22version%22%3A%5B%228%22%2C%220%22%2C%220%22%5D%7D%2C%22browsers%22%3A%5B%7B%22brand%22%3A%22Not_A%20Brand%22%2C%22version%22%3A%5B%2299%22%2C%220%22%2C%220%22%2C%220%22%5D%7D%2C%7B%22brand%22%3A%22Google%20Chrome%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%2C%7B%22brand%22%3A%22Chromium%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%5D%2C%22mobile%22%3A1%2C%22model%22%3A%22SM-G955U%22%2C%22bitness%22%3A%2264%22%2C%22architecture%22%3A%22%22%7D&');
expect(requests[0].data).to.equal(`asi=123456&skt=5&gpid=%2F1111%2Fhomepage%23300x250&tid=cea1eb09-d970-48dc-8585-634d3a7b0544&cdep=example_label_1&prebid_id=30b31c1838de1e&prebid_ver=$prebid.version$&page_url=https%3A%2F%2Fhoge.com&schain=${serializedSchain}&ad_format_ids=2&sua=%7B%22source%22%3A2%2C%22platform%22%3A%7B%22brand%22%3A%22Android%22%2C%22version%22%3A%5B%228%22%2C%220%22%2C%220%22%5D%7D%2C%22browsers%22%3A%5B%7B%22brand%22%3A%22Not_A%20Brand%22%2C%22version%22%3A%5B%2299%22%2C%220%22%2C%220%22%2C%220%22%5D%7D%2C%7B%22brand%22%3A%22Google%20Chrome%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%2C%7B%22brand%22%3A%22Chromium%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%5D%2C%22mobile%22%3A1%2C%22model%22%3A%22SM-G955U%22%2C%22bitness%22%3A%2264%22%2C%22architecture%22%3A%22%22%7D&`);
});
});

Expand Down

0 comments on commit 969e417

Please sign in to comment.