Skip to content

Commit

Permalink
Stv Bid Adapter: added user id support, adaptation of schain support (#…
Browse files Browse the repository at this point in the history
…10849)

* 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

* added serializeUids and adapted serializeSChain

---------

Co-authored-by: theo_ <theo_@IDEA3>
  • Loading branch information
theo-stv and theo_ authored Jan 3, 2024
1 parent ed05478 commit 665c894
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 6 deletions.
59 changes: 56 additions & 3 deletions modules/stvBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const spec = {
bid_id: bidId,
pbver: '$prebid.version$',
schain: '',
uids: '',
};
if (!isVideoRequest(bidRequest)) {
payload._f = 'html';
Expand All @@ -61,6 +62,11 @@ export const spec = {
delete payload.schain;
}

payload.uids = serializeUids(bidRequest);
if (payload.uids == '') {
delete payload.uids;
}

payload.pfilter = { ...params };
delete payload.pfilter.placement;
if (params.bcat !== undefined) { delete payload.pfilter.bcat; }
Expand Down Expand Up @@ -201,7 +207,7 @@ function objectToQueryString(obj, prefix) {
let v = obj[p];
str.push((v !== null && typeof v === 'object')
? objectToQueryString(v, k)
: (k == 'schain' ? k + '=' + v : encodeURIComponent(k) + '=' + encodeURIComponent(v)));
: (k == 'schain' || k == 'uids' ? k + '=' + v : encodeURIComponent(k) + '=' + encodeURIComponent(v)));
}
}
return str.join('&');
Expand All @@ -227,13 +233,60 @@ function serializeSChain(schain) {
ret += encodeURIComponent(node.name ?? '');
ret += ',';
ret += encodeURIComponent(node.domain ?? '');
ret += ',';
ret += encodeURIComponent(node.ext ?? '');
if (node.ext) {
ret += ',';
ret += encodeURIComponent(node.ext ?? '');
}
}

return ret;
}

function serializeUids(bidRequest) {
let uids = [];

let id5 = deepAccess(bidRequest, 'userId.id5id.uid');
if (id5) {
uids.push(encodeURIComponent('id5:' + id5));
let id5Linktype = deepAccess(bidRequest, 'userId.id5id.ext.linkType');
if (id5Linktype) {
uids.push(encodeURIComponent('id5_linktype:' + id5Linktype));
}
}
let netId = deepAccess(bidRequest, 'userId.netId');
if (netId) {
uids.push(encodeURIComponent('netid:' + netId));
}
let uId2 = deepAccess(bidRequest, 'userId.uid2.id');
if (uId2) {
uids.push(encodeURIComponent('uid2:' + uId2));
}
let sharedId = deepAccess(bidRequest, 'userId.sharedid.id');
if (sharedId) {
uids.push(encodeURIComponent('sharedid:' + sharedId));
}
let liverampId = deepAccess(bidRequest, 'userId.idl_env');
if (liverampId) {
uids.push(encodeURIComponent('liverampid:' + liverampId));
}
let criteoId = deepAccess(bidRequest, 'userId.criteoId');
if (criteoId) {
uids.push(encodeURIComponent('criteoid:' + criteoId));
}
// documentation missing...
let utiqId = deepAccess(bidRequest, 'userId.utiq.id');
if (utiqId) {
uids.push(encodeURIComponent('utiq:' + utiqId));
} else {
utiqId = deepAccess(bidRequest, 'userId.utiq');
if (utiqId) {
uids.push(encodeURIComponent('utiq:' + utiqId));
}
}

return uids.join(',');
}

/**
* Check if it's a banner bid request
*
Expand Down
44 changes: 41 additions & 3 deletions test/spec/modules/stvBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ describe('stvAdapter', function() {
'hp': 1
}
]
},
'userId': {
'id5id': {
'uid': '1234',
'ext': {
'linkType': 'abc'
}
},
'netId': '2345',
'uid2': {
'id': '3456',
},
'sharedid': {
'id': '4567',
},
'idl_env': '5678',
'criteoId': '6789',
'utiq': '7890',
}
},
{
Expand All @@ -84,7 +102,27 @@ describe('stvAdapter', function() {
],
'bidId': '30b31c1838de1e2',
'bidderRequestId': '22edbae2733bf62',
'auctionId': '1d1a030790a476'
'auctionId': '1d1a030790a476',
'userId': { // with other utiq variant
'id5id': {
'uid': '1234',
'ext': {
'linkType': 'abc'
}
},
'netId': '2345',
'uid2': {
'id': '3456',
},
'sharedid': {
'id': '4567',
},
'idl_env': '5678',
'criteoId': '6789',
'utiq': {
'id': '7890'
},
}
}, {
'bidder': 'stv',
'params': {
Expand Down Expand Up @@ -181,15 +219,15 @@ 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&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');
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,,&uids=id5%3A1234,id5_linktype%3Aabc,netid%3A2345,uid2%3A3456,sharedid%3A4567,liverampid%3A5678,criteoid%3A6789,utiq%3A7890&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];
it('sends bid request 2 endpoint via GET', function() {
expect(request2.method).to.equal('GET');
expect(request2.url).to.equal(ENDPOINT_URL);
let data = request2.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=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e2&pbver=test&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&prebidDevMode=1&media_types%5Bbanner%5D=300x250');
expect(data).to.equal('_f=html&alternative=prebid_js&_ps=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e2&pbver=test&uids=id5%3A1234,id5_linktype%3Aabc,netid%3A2345,uid2%3A3456,sharedid%3A4567,liverampid%3A5678,criteoid%3A6789,utiq%3A7890&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&prebidDevMode=1&media_types%5Bbanner%5D=300x250');
});

// Without gdprConsent
Expand Down

0 comments on commit 665c894

Please sign in to comment.