From fa0c6e10ce3f9ada32a050b4aaa5161d8d54ae1c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 17 Apr 2019 16:23:42 +0200 Subject: [PATCH 1/3] Add Video Reach adapter --- modules/videoreachBidAdapter.js | 85 +++++++++++ modules/videoreachBidAdapter.md | 27 ++++ .../spec/modules/videoreachBidAdapter_spec.js | 141 ++++++++++++++++++ 3 files changed, 253 insertions(+) create mode 100644 modules/videoreachBidAdapter.js create mode 100644 modules/videoreachBidAdapter.md create mode 100644 test/spec/modules/videoreachBidAdapter_spec.js diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js new file mode 100644 index 00000000000..c24a431efe6 --- /dev/null +++ b/modules/videoreachBidAdapter.js @@ -0,0 +1,85 @@ +import {registerBidder} from '../src/adapters/bidderFactory'; +const utils = require('../src/utils'); +const BIDDER_CODE = 'videoreach'; +const ENDPOINT_URL = '//a.videoreach.de/hb/'; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: ['video', 'banner'], + + isBidRequestValid: function(bid) { + return !!(bid.params.TagId); + }, + + buildRequests: function(validBidRequests, bidderRequest) { + var data = { + referrer: utils.getTopWindowUrl(), + data: validBidRequests.map(function(bid) { + return { + TagId: utils.getValue(bid.params, 'TagId'), + bidId: utils.getBidIdParameter('bidId', bid), + bidderRequestId: utils.getBidIdParameter('bidderRequestId', bid), + auctionId: utils.getBidIdParameter('auctionId', bid), + transactionId: utils.getBidIdParameter('transactionId', bid) + } + }) + }; + + if (bidderRequest && bidderRequest.gdprConsent) { + data.gdpr = { + consent_string: bidderRequest.gdprConsent.consentString, + consent_required: bidderRequest.gdprConsent.gdprApplies + }; + } + + return { + method: 'POST', + url: ENDPOINT_URL, + data: JSON.stringify(data) + }; + }, + + interpretResponse: function(serverResponse) { + const bidResponses = []; + serverResponse = serverResponse.body; + + if (serverResponse.responses) { + serverResponse.responses.forEach(function (bid) { + const bidResponse = { + cpm: bid.cpm, + width: bid.width, + height: bid.height, + currency: bid.currency, + netRevenue: true, + ttl: bid.ttl, + ad: bid.ad, + requestId: bid.bidId, + creativeId: bid.creativeId + }; + bidResponses.push(bidResponse); + }); + } + return bidResponses; + }, + + getUserSyncs: function(syncOptions, responses) { + const syncs = []; + + if (syncOptions.pixelEnabled && responses.length) { + const SyncPixels = responses[0].body.responses[0].sync; + + if (SyncPixels) { + SyncPixels.forEach(sync => { + syncs.push({ + type: 'image', + url: sync + }); + }); + } + } + + return syncs; + } +}; + +registerBidder(spec); diff --git a/modules/videoreachBidAdapter.md b/modules/videoreachBidAdapter.md new file mode 100644 index 00000000000..cdd1ecc04c5 --- /dev/null +++ b/modules/videoreachBidAdapter.md @@ -0,0 +1,27 @@ +# Overview + +**Module Name**: Video Reach Bidder Adapter +**Module Type**: Bidder Adapter +**Maintainer**: hello@videoreach.de + +# Description + +Video Reach Bidder Adapter for Prebid.js. + +Use `videoreach` as bidder. + +`TagId` ist required. + +## AdUnits configuration example +``` + var adUnits = [{ + code: 'your-slot', //use exactly the same code as your slot div id. + sizes: [[1, 1]], + bids: [{ + bidder: 'videoreach', + params: { + TagId: 'XXXXX' + } + }] + }]; +``` diff --git a/test/spec/modules/videoreachBidAdapter_spec.js b/test/spec/modules/videoreachBidAdapter_spec.js new file mode 100644 index 00000000000..b74a0236551 --- /dev/null +++ b/test/spec/modules/videoreachBidAdapter_spec.js @@ -0,0 +1,141 @@ +import {expect} from 'chai'; +import {spec} from 'modules/videoreachBidAdapter'; +import {newBidder} from 'src/adapters/bidderFactory'; + +const ENDPOINT_URL = '//a.videoreach.de/hb/'; + +describe('videoreachBidAdapter', function () { + describe('isBidRequestValid', function () { + let bid = { + 'params': { + 'TagId': 'ABCDE' + }, + 'bidId': '242d506d4e4f15', + 'bidderRequestId': '1893a2136a84a2', + 'auctionId': '8fb7b1c7-317b-4edf-83f0-c4669a318522', + 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622' + }; + + it('should return true when required params found', function () { + expect(spec.isBidRequestValid(bid)).to.equal(true); + }); + + it('should return false when required params are not passed', function () { + let bid = Object.assign({}, bid); + delete bid.params; + bid.params = { + 'TagId': '' + }; + expect(spec.isBidRequestValid(bid)).to.equal(false); + }); + }); + + describe('buildRequests', function () { + let bidRequests = [ + { + 'bidder': 'videoreach', + 'params': { + 'TagId': 'ABCDE' + }, + 'adUnitCode': 'adzone', + 'auctionId': '8fb7b1c7-317b-4edf-83f0-c4669a318522', + 'sizes': [[1, 1]], + 'bidId': '242d506d4e4f15', + 'bidderRequestId': '1893a2136a84a2', + 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622', + 'mediaTypes': { + 'banner': { + 'sizes': [1, 1] + }, + } + } + ]; + + it('send bid request to endpoint', function () { + const request = spec.buildRequests(bidRequests); + + expect(request.url).to.equal(ENDPOINT_URL); + expect(request.method).to.equal('POST'); + }); + + it('send bid request with GDPR to endpoint', function () { + let consentString = 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA'; + + let bidderRequest = { + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true + } + }; + + const request = spec.buildRequests(bidRequests, bidderRequest); + const payload = JSON.parse(request.data); + + expect(payload.gdpr.consent_required).to.exist; + expect(payload.gdpr.consent_string).to.equal(consentString); + }); + }); + + describe('interpretResponse', function () { + let serverResponse = + { + 'body': { + 'responses': [{ + 'bidId': '242d506d4e4f15', + 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622', + 'cpm': 10.0, + 'width': '1', + 'height': '1', + 'ad': '', + 'ttl': 360, + 'creativeId': '5cb5dc9375c0e', + 'netRevenue': true, + 'currency': 'EUR', + 'sync': ['https:\/\/SYNC_URL'] + }] + } + }; + + it('should handle response', function() { + let expectedResponse = [ + { + cpm: 10.0, + width: '1', + height: '1', + currency: 'EUR', + netRevenue: true, + ttl: 360, + ad: '', + requestId: '242d506d4e4f15', + creativeId: '5cb5dc9375c0e' + } + ]; + + let result = spec.interpretResponse(serverResponse); + expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); + }); + + it('should handles empty response', function() { + let serverResponse = { + 'body': { + 'responses': [] + } + }; + + let result = spec.interpretResponse(serverResponse); + expect(result.length).to.equal(0); + }); + + describe('getUserSyncs', () => { + it('should push user sync images if enabled', () => { + const syncOptions = { pixelEnabled: true }; + const syncs = spec.getUserSyncs(syncOptions, [serverResponse]); + + expect(syncs[0]).to.deep.equal({ + type: 'image', + url: 'https://SYNC_URL' + }); + }) + }); + }); +}); From 9cb95c500b39a77c5d43c99c229d3c31dd089681 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 2 May 2019 14:24:03 +0200 Subject: [PATCH 2/3] Add Video Reach adapter --- modules/videoreachBidAdapter.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js index c24a431efe6..f1c0b9c1dd1 100644 --- a/modules/videoreachBidAdapter.js +++ b/modules/videoreachBidAdapter.js @@ -5,7 +5,7 @@ const ENDPOINT_URL = '//a.videoreach.de/hb/'; export const spec = { code: BIDDER_CODE, - supportedMediaTypes: ['video', 'banner'], + supportedMediaTypes: ['banner'], isBidRequestValid: function(bid) { return !!(bid.params.TagId); @@ -62,17 +62,29 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions, responses) { + getUserSyncs: function(syncOptions, responses, gdprConsent) { const syncs = []; if (syncOptions.pixelEnabled && responses.length) { const SyncPixels = responses[0].body.responses[0].sync; + let params = ''; + if (gdprConsent && typeof gdprConsent.consentString === 'string') { + if (typeof gdprConsent.gdprApplies === 'boolean') { + params += 'gdpr='+gdprConsent.gdprApplies+'&gdpr_consent='+gdprConsent.consentString; + } else { + params += 'gdpr_consent='+gdprConsent.consentString; + } + } + + var gdpr; if (SyncPixels) { SyncPixels.forEach(sync => { + gdpr = (params) ? ((sync.split('?')[1] ? '&':'?') + params) : ''; + syncs.push({ type: 'image', - url: sync + url: sync + gdpr }); }); } From 71849ec222b22f0ebbe30ac62ffae478434f0091 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 2 May 2019 14:28:54 +0200 Subject: [PATCH 3/3] Add Video Reach adapter --- modules/videoreachBidAdapter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/videoreachBidAdapter.js b/modules/videoreachBidAdapter.js index f1c0b9c1dd1..03290c9b79c 100644 --- a/modules/videoreachBidAdapter.js +++ b/modules/videoreachBidAdapter.js @@ -71,16 +71,16 @@ export const spec = { let params = ''; if (gdprConsent && typeof gdprConsent.consentString === 'string') { if (typeof gdprConsent.gdprApplies === 'boolean') { - params += 'gdpr='+gdprConsent.gdprApplies+'&gdpr_consent='+gdprConsent.consentString; + params += 'gdpr=' + gdprConsent.gdprApplies + '&gdpr_consent=' + gdprConsent.consentString; } else { - params += 'gdpr_consent='+gdprConsent.consentString; + params += 'gdpr_consent=' + gdprConsent.consentString; } } var gdpr; if (SyncPixels) { SyncPixels.forEach(sync => { - gdpr = (params) ? ((sync.split('?')[1] ? '&':'?') + params) : ''; + gdpr = (params) ? ((sync.split('?')[1] ? '&' : '?') + params) : ''; syncs.push({ type: 'image',