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

Teads: Handle TCF 2 #5000

Merged
merged 1 commit into from
Mar 27, 2020
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
42 changes: 11 additions & 31 deletions modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ export const spec = {
if (bidderRequest && gdpr) {
let isCmp = (typeof gdpr.gdprApplies === 'boolean')
let isConsentString = (typeof gdpr.consentString === 'string')
let status = isCmp ? findGdprStatus(gdpr.gdprApplies, gdpr.vendorData) : gdprStatus.CMP_NOT_FOUND_OR_ERROR
let status = isCmp ? findGdprStatus(gdpr) : gdprStatus.CMP_NOT_FOUND_OR_ERROR
payload.gdpr_iab = {
consent: isConsentString ? gdpr.consentString : '',
status: status
status: status,
apiVersion: gdpr.apiVersion
};
}

Expand Down Expand Up @@ -101,33 +102,6 @@ export const spec = {
}
return bidResponses;
},

getUserSyncs: function(syncOptions, responses, gdprConsent) {
let queryParams = {
hb_provider: 'prebid',
hb_version: '$prebid.version$'
};

if (gdprConsent) {
let gdprIab = {
status: findGdprStatus(gdprConsent.gdprApplies, gdprConsent.vendorData),
consent: gdprConsent.consentString
};

queryParams.gdprIab = JSON.stringify(gdprIab)
}

if (utils.deepAccess(responses[0], 'body.responses.0.placementId')) {
queryParams.placementId = responses[0].body.responses[0].placementId
};

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: 'https://sync.teads.tv/iframe?' + utils.parseQueryStringParameters(queryParams)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's no user sync for teads anymore?

}];
}
}
};

function getReferrerInfo(bidderRequest) {
Expand All @@ -138,11 +112,17 @@ function getReferrerInfo(bidderRequest) {
return ref;
}

function findGdprStatus(gdprApplies, gdprData) {
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

if (gdprApplies) {
if (gdprData.hasGlobalScope || gdprData.hasGlobalConsent) status = gdprStatus.GDPR_APPLIES_GLOBAL
if (globalConsent) status = gdprStatus.GDPR_APPLIES_GLOBAL
} else status = gdprStatus.GDPR_DOESNT_APPLY
return status;
}
Expand Down
108 changes: 37 additions & 71 deletions test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ describe('teadsBidAdapter', () => {
'gdprApplies': true,
'vendorData': {
'hasGlobalConsent': false
}
},
'apiVersion': 1
}
};

Expand All @@ -146,6 +147,7 @@ describe('teadsBidAdapter', () => {
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(1);
});

it('should add referer info to payload', function () {
Expand Down Expand Up @@ -175,7 +177,8 @@ describe('teadsBidAdapter', () => {
'gdprApplies': true,
'vendorData': {
'hasGlobalScope': true
}
},
'apiVersion': 1
}
};

Expand All @@ -185,6 +188,32 @@ describe('teadsBidAdapter', () => {
expect(payload.gdpr_iab).to.exist;
expect(payload.gdpr_iab.consent).to.equal(consentString);
expect(payload.gdpr_iab.status).to.equal(11);
expect(payload.gdpr_iab.apiVersion).to.equal(1);
});

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

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(2);
});

it('should send GDPR to endpoint with 22 status', function() {
Expand All @@ -196,7 +225,8 @@ describe('teadsBidAdapter', () => {
'gdprConsent': {
'consentString': undefined,
'gdprApplies': undefined,
'vendorData': undefined
'vendorData': undefined,
'apiVersion': 1
}
};

Expand All @@ -206,6 +236,7 @@ describe('teadsBidAdapter', () => {
expect(payload.gdpr_iab).to.exist;
expect(payload.gdpr_iab.consent).to.equal('');
expect(payload.gdpr_iab.status).to.equal(22);
expect(payload.gdpr_iab.apiVersion).to.equal(1);
});

it('should send GDPR to endpoint with 0 status', function() {
Expand All @@ -219,7 +250,8 @@ describe('teadsBidAdapter', () => {
'gdprApplies': false,
'vendorData': {
'hasGlobalScope': false
}
},
'apiVersion': 1
}
};

Expand All @@ -229,6 +261,7 @@ describe('teadsBidAdapter', () => {
expect(payload.gdpr_iab).to.exist;
expect(payload.gdpr_iab.consent).to.equal(consentString);
expect(payload.gdpr_iab.status).to.equal(0);
expect(payload.gdpr_iab.apiVersion).to.equal(1);
});

it('should use good mediaTypes video playerSizes', function() {
Expand Down Expand Up @@ -368,71 +401,4 @@ describe('teadsBidAdapter', () => {
expect(result.length).to.equal(0);
});
});

it('should call userSync with good params', function() {
let bids = [{
'body': {
'responses': [{
'ad': '<script>',
'cpm': 0.5,
'currency': 'USD',
'height': 250,
'netRevenue': true,
'bidId': '3ede2a3fa0db94',
'ttl': 360,
'width': 300,
'creativeId': 'er2ee',
'placementId': 34
}]
}
}];
let syncOptions = { 'iframeEnabled': true };
let consentString = 'JRJ8FCP29RPZDeBNsERRDCSAAZ+A==';
let gdprConsent = {
'consentString': consentString,
'gdprApplies': true,
'vendorData': {
'hasGlobalConsent': false
}
};
let hb_version = '$prebid.version$'
let finalUrl = `https://sync.teads.tv/iframe?hb_provider=prebid&hb_version=${hb_version}&gdprIab={"status":12,"consent":"${consentString}"}&placementId=34&`;
const userSync = spec.getUserSyncs(syncOptions, bids, gdprConsent);

expect(userSync[0].type).to.equal('iframe');
expect(decodeURIComponent(userSync[0].url)).to.equal(finalUrl);
});

it('should call userSync without placementId param', function() {
let bids = [{
'body': {
'responses': [{
'ad': '<script>',
'cpm': 0.5,
'currency': 'USD',
'height': 250,
'netRevenue': true,
'bidId': '3ede2a3fa0db94',
'ttl': 360,
'width': 300,
'creativeId': 'er2ee'
}]
}
}];
let syncOptions = { 'iframeEnabled': true };
let consentString = 'JRJ8FCP29RPZDeBNsERRDCSAAZ+A==';
let gdprConsent = {
'consentString': consentString,
'gdprApplies': true,
'vendorData': {
'hasGlobalConsent': false
}
};
let hb_version = '$prebid.version$'
let finalUrl = `https://sync.teads.tv/iframe?hb_provider=prebid&hb_version=${hb_version}&gdprIab={"status":12,"consent":"${consentString}"}&`;
const userSync = spec.getUserSyncs(syncOptions, bids, gdprConsent);

expect(userSync[0].type).to.equal('iframe');
expect(decodeURIComponent(userSync[0].url)).to.equal(finalUrl);
});
});