From f424cd2c74b28159cc31134536f037cecdd267b8 Mon Sep 17 00:00:00 2001 From: Gena Date: Mon, 10 Dec 2018 18:52:39 +0100 Subject: [PATCH] Add user sync pixel logic in Adtelligent adapter (#3359) * Add user sync pixel logic in Adtelligent adapter * Add gdpr support * Add gdpr support * Update tests --- modules/adtelligentBidAdapter.js | 37 ++++++++++++++++++- .../modules/adtelligentBidAdapter_spec.js | 37 ++++++++++++++++++- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/modules/adtelligentBidAdapter.js b/modules/adtelligentBidAdapter.js index 65181c70ed9..95087b56f21 100644 --- a/modules/adtelligentBidAdapter.js +++ b/modules/adtelligentBidAdapter.js @@ -17,7 +17,35 @@ export const spec = { isBidRequestValid: function (bid) { return bid && bid.params && bid.params.aid; }, + getUserSyncs: function (syncOptions, serverResponses) { + var syncs = []; + + function addSyncs(_s) { + if (_s && _s.length) { + _s.forEach(s => { + syncs.push({ + type: 'image', + url: s + }) + }) + } + } + if (syncOptions.pixelEnabled) { + serverResponses && serverResponses.length && serverResponses.forEach((response) => { + if (response.body) { + if (utils.isArray(response.body)) { + response.body.forEach(b => { + addSyncs(b.cookieURLs); + }) + } else { + addSyncs(response.body.cookieURLs) + } + } + }) + } + return syncs; + }, /** * Make a server request from the list of BidRequests * @param bidRequests @@ -25,7 +53,7 @@ export const spec = { */ buildRequests: function (bidRequests, bidderRequest) { return { - data: bidToTag(bidRequests), + data: bidToTag(bidRequests, bidderRequest), bidderRequest, method: 'GET', url: URL @@ -83,11 +111,16 @@ function parseRTBResponse(serverResponse, bidderRequest) { return bids; } -function bidToTag(bidRequests) { +function bidToTag(bidRequests, bidderRequest) { let tag = { domain: utils.getTopWindowLocation().hostname }; + if (bidderRequest && bidderRequest.gdprConsent) { + tag.gdpr = 1; + tag.gdpr_consent = bidderRequest.gdprConsent.consentString; + } + for (let i = 0, length = bidRequests.length; i < length; i++) { Object.assign(tag, prepareRTBRequestParams(i, bidRequests[i])); } diff --git a/test/spec/modules/adtelligentBidAdapter_spec.js b/test/spec/modules/adtelligentBidAdapter_spec.js index 6190f53fdc4..0ee2bb2726f 100644 --- a/test/spec/modules/adtelligentBidAdapter_spec.js +++ b/test/spec/modules/adtelligentBidAdapter_spec.js @@ -46,6 +46,7 @@ const SERVER_VIDEO_RESPONSE = { } ] }; + const SERVER_DISPLAY_RESPONSE = { 'source': {'aid': 12345, 'pubId': 54321}, 'bids': [{ @@ -57,7 +58,8 @@ const SERVER_DISPLAY_RESPONSE = { 'cur': 'USD', 'width': 300, 'cpm': 0.9 - }] + }], + 'cookieURLs': ['link1', 'link2'] }; const videoBidderRequest = { @@ -70,6 +72,14 @@ const displayBidderRequest = { bids: [{bidId: '2e41f65424c87c'}] }; +const displayBidderRequestWithGdpr = { + bidderCode: 'bidderCode', + bids: [{bidId: '2e41f65424c87c'}], + gdprConsent: { + consentString: 'test' + } +}; + const videoEqResponse = [{ vastUrl: 'http://rtb.adtelligent.com/vast/?adid=44F2AEB9BFC881B3', requestId: '2e41f65424c87c', @@ -96,9 +106,25 @@ const displayEqResponse = [{ cpm: 0.9 }]; -describe('adtelligentBidAdapter', function () { +describe('adtelligentBidAdapter', function () { // todo remove only const adapter = newBidder(spec); + describe('user syncs', function () { + it('should be returned if pixel enabled', function () { + const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE}]); + + expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE.cookieURLs); + }) + }) + + describe('user syncs', function () { + it('should not be returned if pixel not set', function () { + const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE}]); + + expect(syncs).to.be.empty; + }) + }) + describe('inherited functions', function () { it('exists and is a function', function () { expect(adapter.callBids).to.exist.and.to.be.a('function'); @@ -212,6 +238,13 @@ describe('adtelligentBidAdapter', function () { bidServerResponseCheck(); }); + it('should set gdpr data correctly', function () { + const builtRequestData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithGdpr); + + expect(builtRequestData.data.gdpr).to.be.equal(1); + expect(builtRequestData.data.gdpr_consent).to.be.equal(displayBidderRequestWithGdpr.gdprConsent.consentString); + }); + function bidServerResponseCheck() { const result = spec.interpretResponse({body: serverResponse}, {bidderRequest});