Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bidderRequest.refererInfo in Adhese Adapter #3725

Merged
merged 2 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ export const spec = {
if (validBidRequests.length === 0) {
return null;
}
const gdprConsent = bidderRequest.gdprConsent;
idettman marked this conversation as resolved.
Show resolved Hide resolved
const refererInfo = bidderRequest.refererInfo;

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 ] : [];
idettman marked this conversation as resolved.
Show resolved Hide resolved
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 +169,8 @@ function getAdDetails(ad) {
return { creativeId: creativeId, dealId: dealId };
}

function base64urlEncode(s) {
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
idettman marked this conversation as resolved.
Show resolved Hide resolved
}

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