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

Updated gdpr in adform adapter #2589

Merged
merged 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 14 additions & 5 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const spec = {
return !!(bid.params.mid);
},
buildRequests: function (validBidRequests, bidderRequest) {
var i, l, j, k, bid, _key, _value, reqParams, netRevenue;
var i, l, j, k, bid, _key, _value, reqParams, netRevenue, gdprObject;
var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ];
var bids = JSON.parse(JSON.stringify(validBidRequests));
Expand All @@ -38,9 +38,13 @@ export const spec = {
request.push('pt=' + netRevenue);
request.push('stid=' + validBidRequests[0].auctionId);

if (bidderRequest && bidderRequest.gdprConsent) {
request.push('gdpr=' + bidderRequest.gdprConsent.gdprApplies);
request.push('gdpr_consent=' + bidderRequest.gdprConsent.consentString);
if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) {
gdprObject = {
gdpr: bidderRequest.gdprConsent.gdprApplies,
gdpr_consent: bidderRequest.gdprConsent.consentString
};
request.push('gdpr=' + gdprObject.gdpr);
request.push('gdpr_consent=' + gdprObject.gdpr_consent);
}

for (i = 1, l = globalParams.length; i < l; i++) {
Expand All @@ -56,7 +60,8 @@ export const spec = {
url: request.join('&'),
bids: validBidRequests,
netRevenue: netRevenue,
bidder: 'adform'
bidder: 'adform',
gdpr: gdprObject
};

function formRequestUrl(reqData) {
Expand Down Expand Up @@ -102,6 +107,10 @@ export const spec = {
vastXml: response.vast_content,
mediaType: type
};
if (bidRequest.gdpr) {
bidObject.gdpr = bidRequest.gdpr.gdpr;
bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent;
}
bidRespones.push(bidObject);
}
}
Expand Down
64 changes: 55 additions & 9 deletions test/spec/modules/adformBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ describe('Adform adapter', () => {
assert.deepEqual(resultBids, bids[0]);
});

it('should send GDPR Consent data to adform', () => {
var resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: 1, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.equal(parsedUrl.gdpr, 1);
assert.equal(parsedUrl.gdpr_consent, 'concentDataString');
});

it('should set gross to the request, if there is any gross priceType', () => {
let request = spec.buildRequests([bids[5], bids[5]]);
let parsedUrl = parseUrl(request.url);
Expand All @@ -119,6 +110,42 @@ describe('Adform adapter', () => {

assert.equal(parsedUrl.query.pt, 'gross');
});

describe('gdpr', () => {
it('should send GDPR Consent data to adform if gdprApplies', () => {
let resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.equal(parsedUrl.gdpr, 'true');
assert.equal(parsedUrl.gdpr_consent, 'concentDataString');
});

it('should not send GDPR Consent data to adform if gdprApplies is false or undefined', () => {
let resultBids = JSON.parse(JSON.stringify(bids[0]));
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: false, consentString: 'concentDataString'}});
let parsedUrl = parseUrl(request.url).query;

assert.ok(!parsedUrl.gdpr);
assert.ok(!parsedUrl.gdpr_consent);

request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: undefined, consentString: 'concentDataString'}});
assert.ok(!parsedUrl.gdpr);
assert.ok(!parsedUrl.gdpr_consent);
});

it('should return GDPR Consent data with request data', () => {
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});

assert.deepEqual(request.gdpr, {
gdpr: true,
gdpr_consent: 'concentDataString'
});

request = spec.buildRequests([bids[0]]);
assert.ok(!request.gdpr);
});
});
});

describe('interpretResponse', () => {
Expand Down Expand Up @@ -205,6 +232,25 @@ describe('Adform adapter', () => {
assert.equal(result[i].netRevenue, false);
}
});

it('should set gdpr if it exist in bidRequest', () => {
bidRequest.gdpr = {
gdpr: true,
gdpr_consent: 'ERW342EIOWT34234KMGds'
};
let result = spec.interpretResponse(serverResponse, bidRequest);
for (let i = 0; i < result.length; i++) {
assert.equal(result[i].gdpr, true);
assert.equal(result[i].gdpr_consent, 'ERW342EIOWT34234KMGds');
};

bidRequest.gdpr = undefined;
result = spec.interpretResponse(serverResponse, bidRequest);
for (let i = 0; i < result.length; i++) {
assert.ok(!result[i].gdpr);
assert.ok(!result[i].gdpr_consent);
};
})
});

beforeEach(() => {
Expand Down