Skip to content

Commit

Permalink
Teads fix production GDPR error (prebid#5122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Souche authored and iggyfisk committed Jun 22, 2020
1 parent a4860fe commit e6e4437
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
25 changes: 14 additions & 11 deletions modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const spec = {
if (bidderRequest && gdpr) {
let isCmp = (typeof gdpr.gdprApplies === 'boolean')
let isConsentString = (typeof gdpr.consentString === 'string')
let status = isCmp ? findGdprStatus(gdpr) : gdprStatus.CMP_NOT_FOUND_OR_ERROR
let status = isCmp
? findGdprStatus(gdpr.gdprApplies, gdpr.vendorData, gdpr.apiVersion)
: gdprStatus.CMP_NOT_FOUND_OR_ERROR
payload.gdpr_iab = {
consent: isConsentString ? gdpr.consentString : '',
status: status,
Expand Down Expand Up @@ -112,21 +114,22 @@ function getReferrerInfo(bidderRequest) {
return ref;
}

function findGdprStatus(gdprConsent) {
const gdprApplies = gdprConsent.gdprApplies
const gdprData = gdprConsent.vendorData
const apiVersion = gdprConsent.apiVersion
let status = gdprStatus.GDPR_APPLIES_PUBLISHER;
const globalConsent = apiVersion === 1
? (gdprData.hasGlobalScope || gdprData.hasGlobalConsent)
: !gdprData.isServiceSpecific

function findGdprStatus(gdprApplies, gdprData, apiVersion) {
let status = gdprStatus.GDPR_APPLIES_PUBLISHER
if (gdprApplies) {
if (globalConsent) status = gdprStatus.GDPR_APPLIES_GLOBAL
if (isGlobalConsent(gdprData, apiVersion)) status = gdprStatus.GDPR_APPLIES_GLOBAL
} else status = gdprStatus.GDPR_DOESNT_APPLY
return status;
}

function isGlobalConsent(gdprData, apiVersion) {
return gdprData && apiVersion === 1
? (gdprData.hasGlobalScope || gdprData.hasGlobalConsent)
: gdprData && apiVersion === 2
? !gdprData.isServiceSpecific
: false
}

function buildRequestObject(bid) {
const reqObj = {};
let placementId = utils.getValue(bid.params, 'placementId');
Expand Down
48 changes: 48 additions & 0 deletions test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,54 @@ describe('teadsBidAdapter', () => {
expect(payload.gdpr_iab.apiVersion).to.equal(1);
});

it('should send GDPR to endpoint with 0 status when gdprApplies = false (vendorData = undefined)', function() {
let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A==';
let bidderRequest = {
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'gdprConsent': {
'consentString': undefined,
'gdprApplies': false,
'vendorData': undefined,
'apiVersion': 1
}
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(request.data);

expect(payload.gdpr_iab).to.exist;
expect(payload.gdpr_iab.consent).to.equal('');
expect(payload.gdpr_iab.status).to.equal(0);
expect(payload.gdpr_iab.apiVersion).to.equal(1);
});

it('should send GDPR to endpoint with 12 status when apiVersion = 0', function() {
let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A==';
let bidderRequest = {
'auctionId': '1d1a030790a475',
'bidderRequestId': '22edbae2733bf6',
'timeout': 3000,
'gdprConsent': {
'consentString': consentString,
'gdprApplies': true,
'vendorData': {
'hasGlobalScope': false
},
'apiVersion': 0
}
};

const request = spec.buildRequests(bidRequests, bidderRequest);
const payload = JSON.parse(request.data);

expect(payload.gdpr_iab).to.exist;
expect(payload.gdpr_iab.consent).to.equal(consentString);
expect(payload.gdpr_iab.status).to.equal(12);
expect(payload.gdpr_iab.apiVersion).to.equal(0);
});

it('should use good mediaTypes video playerSizes', function() {
const mediaTypesPlayerSize = {
'mediaTypes': {
Expand Down

0 comments on commit e6e4437

Please sign in to comment.