Skip to content

Commit

Permalink
GumGum: adds tradedesk id param (prebid#3896)
Browse files Browse the repository at this point in the history
* adds tradedesk id param

* adds more tests

* removes only from test spec

* linting fix

* updates one of the unit tests
  • Loading branch information
susyt authored and sa1omon committed Nov 28, 2019
1 parent 52cc135 commit f8fa4a2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ function getWrapperCode(wrapper, data) {
return wrapper.replace('AD_JSON', window.btoa(JSON.stringify(data)))
}

function _getTradeDeskIDParam(bidRequest) {
const unifiedIdObj = {};
if (bidRequest.userId && bidRequest.userId.tdid) {
unifiedIdObj.tdid = bidRequest.userId.tdid;
}
return unifiedIdObj;
}

// TODO: use getConfig()
function _getDigiTrustQueryParams() {
function getDigiTrustId () {
Expand Down Expand Up @@ -170,7 +178,7 @@ function buildRequests (validBidRequests, bidderRequest) {
sizes: bidRequest.sizes,
url: BID_ENDPOINT,
method: 'GET',
data: Object.assign(data, _getBrowserParams(), _getDigiTrustQueryParams())
data: Object.assign(data, _getBrowserParams(), _getDigiTrustQueryParams(), _getTradeDeskIDParam(bidRequest))
})
});
return bids;
Expand Down
54 changes: 54 additions & 0 deletions test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ describe('gumgumAdapter', function () {
expect(request.method).to.equal('GET');
expect(request.id).to.equal('30b31c1838de1e');
});
it('should correctly set the request paramters depending on params field', function () {
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.params = {
'inScreen': '10433394',
'bidfloor': 0.05
};
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(2);
expect(bidRequest.data).to.include.any.keys('t');
expect(bidRequest.data).to.include.any.keys('fp');
});
it('should correctly set the request paramters depending on params field', function () {
const request = Object.assign({}, bidRequests[0]);
delete request.params;
request.params = {
'ICV': '10433395'
};
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.pi).to.equal(5);
expect(bidRequest.data).to.include.any.keys('ni');
});
it('should not add additional parameters depending on params field', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.data).to.not.include.any.keys('ni');
expect(request.data).to.not.include.any.keys('t');
expect(request.data).to.not.include.any.keys('eAdBuyId');
expect(request.data).to.not.include.any.keys('adBuyId');
});
it('should add consent parameters if gdprConsent is present', function () {
const gdprConsent = { consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', gdprApplies: true };
const fakeBidRequest = { gdprConsent: gdprConsent };
Expand All @@ -93,6 +122,31 @@ describe('gumgumAdapter', function () {
const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0];
expect(bidRequest.data).to.not.include.any.keys('gdprConsent')
});
it('should add a tdid parameter if request contains unified id from TradeDesk', function () {
const unifiedId = {
'userId': {
'tdid': 'tradedesk-id'
}
}
const request = Object.assign(unifiedId, bidRequests[0]);
const bidRequest = spec.buildRequests([request])[0];
expect(bidRequest.data.tdid).to.eq(unifiedId.userId.tdid);
});
it('should not add a tdid parameter if unified id is not found', function () {
const request = spec.buildRequests(bidRequests)[0];
expect(request.data).to.not.include.any.keys('tdid');
});
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;
if (connection) {
const downlink = connection.downlink || connection.bandwidth;
expect(bidRequest.data).to.include.any.keys('ns');
expect(bidRequest.data.ns).to.eq(Math.round(downlink * 1024));
} else {
expect(bidRequest.data).to.not.include.any.keys('ns');
}
});
})

describe('interpretResponse', function () {
Expand Down

0 comments on commit f8fa4a2

Please sign in to comment.