From 8433b2d551b7ee55b6ad57e40c2351f22cb2b107 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 18 Jun 2018 23:12:41 +1000 Subject: [PATCH] Playground xyz - GDPR integration. (#2699) * add playground adapters * clean up * update with upstream master * add test file clean up adapter by removing native referecnes * test file * replace appnexus with playground reference in error logs * remove commented code * change key in response object from appnexus to playgroundxyz * change tests so we test for ordering by cpm as well * dont drop other bids, just set cpm to 0 and send it through * clean up * restore glulp file * fix documentation * remove cpm logic from adapter * change application type to application\json for playground adapter * update adaptor to use openRtb * add device and site to bid * add extra space on error msg * remove package-lock * update pg details * Update playgroundxyzBidAdapter.md * add GDPR remove video sample config form .md file --- modules/playgroundxyzBidAdapter.js | 12 +++-- modules/playgroundxyzBidAdapter.md | 42 ---------------- .../modules/playgroundxyzBidAdapter_spec.js | 49 +++++++++++++++++++ 3 files changed, 58 insertions(+), 45 deletions(-) diff --git a/modules/playgroundxyzBidAdapter.js b/modules/playgroundxyzBidAdapter.js index 75861bd63f10..0e0da35b66f6 100644 --- a/modules/playgroundxyzBidAdapter.js +++ b/modules/playgroundxyzBidAdapter.js @@ -28,7 +28,7 @@ export const spec = { */ buildRequests: function (bidRequests, bidderRequest) { const topLocation = utils.getTopWindowLocation(); - const payload = JSON.stringify({ + const payload = { id: bidRequests[0].auctionId, site: { domain: window.location.protocol + '//' + topLocation.hostname, @@ -41,17 +41,23 @@ export const spec = { devicetype: isMobile() ? 1 : isConnectedTV() ? 3 : 2, }, imp: bidRequests.map(mapImpression) - }); + }; const options = { contentType: 'application/json', withCredentials: false }; + if (bidderRequest && bidderRequest.gdprConsent) { + payload.user = {ext: {consent: bidderRequest.gdprConsent.consentString}}; + const gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + payload.regs = {ext: {gdpr: gdpr}}; + } + return { method: 'POST', url: URL, - data: payload, + data: JSON.stringify(payload), options, bidderRequest }; diff --git a/modules/playgroundxyzBidAdapter.md b/modules/playgroundxyzBidAdapter.md index 345bf7d06931..c72b9f34dd3b 100644 --- a/modules/playgroundxyzBidAdapter.md +++ b/modules/playgroundxyzBidAdapter.md @@ -25,48 +25,6 @@ var adUnits = [ placementId: '10433394' } }] - }, - // Video instream adUnit - { - code: 'video-instream', - sizes: [640, 480], - mediaTypes: { - video: { - context: 'instream' - }, - }, - bids: [{ - bidder: 'playgroundxyz', - params: { - placementId: '9333431', - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'] - } - } - }] - }, - // Video outstream adUnit - { - code: 'video-outstream', - sizes: [[640, 480]], - mediaTypes: { - video: { - context: 'outstream' - } - }, - bids: [ - { - bidder: 'playgroundxyz', - params: { - placementId: '5768085', - video: { - skippable: true, - playback_method: ['auto_play_sound_off'] - } - } - } - ] } ]; ``` diff --git a/test/spec/modules/playgroundxyzBidAdapter_spec.js b/test/spec/modules/playgroundxyzBidAdapter_spec.js index 72cd1205c45c..becd8612a9c8 100644 --- a/test/spec/modules/playgroundxyzBidAdapter_spec.js +++ b/test/spec/modules/playgroundxyzBidAdapter_spec.js @@ -4,6 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory'; import { deepClone } from 'src/utils'; const URL = 'https://ads.playground.xyz/host-config/prebid'; +const GDPR_CONSENT = 'XYZ-CONSENT'; describe('playgroundxyzBidAdapter', () => { const adapter = newBidder(spec); @@ -133,4 +134,52 @@ describe('playgroundxyzBidAdapter', () => { expect(result.length).to.equal(0); }); }); + + describe('buildRequests', () => { + let bidRequests = [ + { + 'bidder': 'playgroundxyz', + 'params': { + 'publisherId': 'PUB_FAKE' + }, + 'adUnitCode': 'adunit-code', + 'sizes': [[300, 250]], + 'bidId': '321db112312as', + 'bidderRequestId': '23edabce2731sd6', + 'auctionId': '12as040790a475' + } + ]; + + it('should not populate GDPR', () => { + let bidRequest = Object.assign([], bidRequests); + const request = spec.buildRequests(bidRequest); + let data = JSON.parse(request.data); + expect(data).to.not.have.property('user'); + expect(data).to.not.have.property('regs'); + }); + + it('should populate GDPR and consent string when consetString is presented but not gdpApplies', () => { + let bidRequest = Object.assign([], bidRequests); + const request = spec.buildRequests(bidRequest, {gdprConsent: {consentString: GDPR_CONSENT}}); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(0); + expect(data.user.ext.consent).to.equal('XYZ-CONSENT'); + }); + + it('should populate GDPR and consent string when gdpr is set to true', () => { + let bidRequest = Object.assign([], bidRequests); + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: true, consentString: GDPR_CONSENT}}); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(1); + expect(data.user.ext.consent).to.equal('XYZ-CONSENT'); + }); + + it('should populate GDPR and consent string when gdpr is set to false', () => { + let bidRequest = Object.assign([], bidRequests); + const request = spec.buildRequests(bidRequest, {gdprConsent: {gdprApplies: false, consentString: GDPR_CONSENT}}); + let data = JSON.parse(request.data); + expect(data.regs.ext.gdpr).to.equal(0); + expect(data.user.ext.consent).to.equal('XYZ-CONSENT'); + }); + }); });