Skip to content

Commit

Permalink
Stv Bid Adapter: add schain support (#10010)
Browse files Browse the repository at this point in the history
* initial commit

* adapted buildRequests function

* refinement pfilter and bcat

* refinement

* adapted tests for isBidRequestValid,buildRequests

* adaptations for test

* finished building stvBidAdapter.js

* finished: ran tests, coverage 99%

* update: rename w->srw, h->srh

* adapt stvBidAdapter.md

* remove dspx from stv adapters

* some changes (missing: getUserSyncs, but is the same as in
radsBidAdapter)

* added checks in getUserSyncs; ran tests

* added schain support (94.8% coverage)

* correct schain encoding

---------

Co-authored-by: theo_ <theo_@IDEA3>
  • Loading branch information
theo-stv and theo_ authored May 31, 2023
1 parent 122d624 commit 62200e3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
35 changes: 34 additions & 1 deletion modules/stvBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ export const spec = {
ref: referrer,
bid_id: bidId,
pbver: '$prebid.version$',
schain: '',
};
if (!isVideoRequest(bidRequest)) {
payload._f = 'html';
}
if (bidRequest.schain) {
payload.schain = serializeSChain(bidRequest.schain);
} else {
delete payload.schain;
}

payload.pfilter = { ...params };
delete payload.pfilter.placement;
Expand Down Expand Up @@ -195,12 +201,39 @@ function objectToQueryString(obj, prefix) {
let v = obj[p];
str.push((v !== null && typeof v === 'object')
? objectToQueryString(v, k)
: encodeURIComponent(k) + '=' + encodeURIComponent(v));
: (k == 'schain' ? k + '=' + v : encodeURIComponent(k) + '=' + encodeURIComponent(v)));
}
}
return str.join('&');
}

function serializeSChain(schain) {
let ret = '';

ret += encodeURIComponent(schain.ver);
ret += ',';
ret += encodeURIComponent(schain.complete);

for (let node of schain.nodes) {
ret += '!';
ret += encodeURIComponent(node.asi);
ret += ',';
ret += encodeURIComponent(node.sid);
ret += ',';
ret += encodeURIComponent(node.hp);
ret += ',';
ret += encodeURIComponent(node.rid ?? '');
ret += ',';
ret += encodeURIComponent(node.name ?? '');
ret += ',';
ret += encodeURIComponent(node.domain ?? '');
ret += ',';
ret += encodeURIComponent(node.ext ?? '');
}

return ret;
}

/**
* Check if it's a banner bid request
*
Expand Down
14 changes: 13 additions & 1 deletion test/spec/modules/stvBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ describe('stvAdapter', function() {
'bidderRequestId': '22edbae2733bf61',
'auctionId': '1d1a030790a475',
'adUnitCode': 'testDiv1',
'schain': {
'ver': '1.0',
'complete': 0,
'nodes': [
{
'asi': 'reseller.com',
'sid': 'aaaaa',
'rid': 'BidRequest4',
'hp': 1
}
]
}
},
{
'bidder': 'stv',
Expand Down Expand Up @@ -169,7 +181,7 @@ describe('stvAdapter', function() {
expect(request1.method).to.equal('GET');
expect(request1.url).to.equal(ENDPOINT_URL);
let data = request1.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&');
expect(data).to.equal('_f=html&alternative=prebid_js&_ps=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e1&pbver=test&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&bcat=IAB2%2CIAB4&dvt=desktop&pbcode=testDiv1&media_types%5Bbanner%5D=300x250');
expect(data).to.equal('_f=html&alternative=prebid_js&_ps=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e1&pbver=test&schain=1.0,0!reseller.com,aaaaa,1,BidRequest4,,,&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&bcat=IAB2%2CIAB4&dvt=desktop&pbcode=testDiv1&media_types%5Bbanner%5D=300x250');
});

var request2 = spec.buildRequests([bidRequests[1]], bidderRequest)[0];
Expand Down

0 comments on commit 62200e3

Please sign in to comment.