Skip to content

Commit

Permalink
Add support for bidderRequest.refererInfo in Adhese Adapter (#3725)
Browse files Browse the repository at this point in the history
* Add support for bidderRequest.refererInfo in Adhese Adapter.

* Apply code review suggestions
  • Loading branch information
mefjush authored and Isaac Dettman committed Apr 30, 2019
1 parent 40a4ac6 commit 8f5ea4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ export const spec = {
if (validBidRequests.length === 0) {
return null;
}
const { gdprConsent, refererInfo } = bidderRequest;

const account = getAccount(validBidRequests);
const targets = validBidRequests.map(bid => bid.params.data).reduce(mergeTargets, {});
const gdprParams = (bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) ? [ 'xt' + bidderRequest.gdprConsent.consentString ] : [];
const gdprParams = (gdprConsent && gdprConsent.consentString) ? [`xt${gdprConsent.consentString}`] : [];
const refererParams = (refererInfo && refererInfo.referer) ? [`xf${base64urlEncode(refererInfo.referer)}`] : [];
const targetsParams = Object.keys(targets).map(targetCode => targetCode + targets[targetCode].join(';'));
const slotsParams = validBidRequests.map(bid => 'sl' + bidToSlotName(bid));
const params = [...slotsParams, ...targetsParams, ...gdprParams].map(s => '/' + s).join('');
const params = [...slotsParams, ...targetsParams, ...gdprParams, ...refererParams].map(s => `/${s}`).join('');
const cacheBuster = '?t=' + new Date().getTime();
const uri = 'https://ads-' + account + '.adhese.com/json' + params + cacheBuster;

Expand Down Expand Up @@ -166,4 +168,8 @@ function getAdDetails(ad) {
return { creativeId: creativeId, dealId: dealId };
}

function base64urlEncode(s) {
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}

registerBidder(spec);
9 changes: 9 additions & 0 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ describe('AdheseAdapter', function () {
gdprConsent: {
gdprApplies: true,
consentString: 'CONSENT_STRING'
},
refererInfo: {
referer: 'http://prebid.org/dev-docs/subjects?_d=1'
}
};

Expand Down Expand Up @@ -91,6 +94,12 @@ describe('AdheseAdapter', function () {
expect(req.url).to.contain('/xtCONSENT_STRING');
});

it('should include referer param in base64url format', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(req.url).to.contain('/xfaHR0cDovL3ByZWJpZC5vcmcvZGV2LWRvY3Mvc3ViamVjdHM_X2Q9MQ');
});

it('should include bids', function () {
let bid = minimalBid();
let req = spec.buildRequests([ bid ], bidderRequest);
Expand Down

0 comments on commit 8f5ea4c

Please sign in to comment.