From 1c0ca9fa5f02feae89b63fa047c3ba8dfda244e7 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 26 Jul 2019 15:17:15 +0200 Subject: [PATCH] Teads-adapter: Read placementId from response and add sync informations (#3963) * Read placementId and add informations * Secure gdprConsent object access --- modules/teadsBidAdapter.js | 28 ++++++-- test/spec/modules/teadsBidAdapter_spec.js | 87 ++++++++++++++++++++--- 2 files changed, 102 insertions(+), 13 deletions(-) diff --git a/modules/teadsBidAdapter.js b/modules/teadsBidAdapter.js index 92cfce312b1..121232a6605 100644 --- a/modules/teadsBidAdapter.js +++ b/modules/teadsBidAdapter.js @@ -42,7 +42,8 @@ export const spec = { const payload = { referrer: getReferrerInfo(bidderRequest), data: bids, - deviceWidth: screen.width + deviceWidth: screen.width, + hb_version: '$prebid.version$' }; let gdpr = bidderRequest.gdprConsent; @@ -84,7 +85,8 @@ export const spec = { ttl: bid.ttl, ad: bid.ad, requestId: bid.bidId, - creativeId: bid.creativeId + creativeId: bid.creativeId, + placementId: bid.placementId }; bidResponses.push(bidResponse); }); @@ -92,11 +94,29 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions, responses, gdprApplies) { + 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: '//sync.teads.tv/iframe' + url: '//sync.teads.tv/iframe?' + utils.parseQueryStringParameters(queryParams) }]; } } diff --git a/test/spec/modules/teadsBidAdapter_spec.js b/test/spec/modules/teadsBidAdapter_spec.js index 57484d79b05..af1c7a9c01b 100644 --- a/test/spec/modules/teadsBidAdapter_spec.js +++ b/test/spec/modules/teadsBidAdapter_spec.js @@ -5,11 +5,11 @@ import {newBidder} from 'src/adapters/bidderFactory'; const ENDPOINT = '//a.teads.tv/hb/bid-request'; const AD_SCRIPT = '"'; -describe('teadsBidAdapter', function() { +describe('teadsBidAdapter', () => { const adapter = newBidder(spec); - describe('inherited functions', function() { - it('exists and is a function', function() { + describe('inherited functions', () => { + it('exists and is a function', () => { expect(adapter.callBids).to.exist.and.to.be.a('function'); }); }); @@ -286,16 +286,17 @@ describe('teadsBidAdapter', function() { 'currency': 'USD', 'height': 250, 'netRevenue': true, - 'requestId': '3ede2a3fa0db94', + 'bidId': '3ede2a3fa0db94', 'ttl': 360, 'width': 300, - 'creativeId': 'er2ee' + 'creativeId': 'er2ee', + 'placementId': 34 }] } }; it('should get correct bid response', function() { - let expectedResponse = [{ + let expectedResponse = { 'cpm': 0.5, 'width': 300, 'height': 250, @@ -304,11 +305,12 @@ describe('teadsBidAdapter', function() { 'ttl': 360, 'ad': AD_SCRIPT, 'requestId': '3ede2a3fa0db94', - 'creativeId': 'er2ee' - }]; + 'creativeId': 'er2ee', + 'placementId': 34 + }; let result = spec.interpretResponse(bids); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + expect(result[0]).to.deep.equal(expectedResponse); }); it('handles nobid responses', function() { @@ -322,4 +324,71 @@ describe('teadsBidAdapter', function() { expect(result.length).to.equal(0); }); }); + + it('should call userSync with good params', function() { + let bids = [{ + 'body': { + 'responses': [{ + 'ad': '