From ea3d10b502fb42ef03cae4a9e6aa9af11a7376e0 Mon Sep 17 00:00:00 2001 From: Onome Oyibo Date: Thu, 31 Jan 2019 18:50:56 +0000 Subject: [PATCH] feat(unrulyBidAdapter): add userSync functionality (#3460) * feat(unrulyBidAdapter): add userSync functionality * feat(unrulyBidAdapter): add gdpr consent functionality to getUserSyncs * fix(unrulyBidAdapter): fix empty object pattern in tests --- integrationExamples/gpt/unruly_example.html | 4 ++ modules/unrulyBidAdapter.js | 20 +++++++ test/spec/modules/unrulyBidAdapter_spec.js | 60 +++++++++++++++++++++ 3 files changed, 84 insertions(+) diff --git a/integrationExamples/gpt/unruly_example.html b/integrationExamples/gpt/unruly_example.html index 77a9b02b3dd..038951b9eb8 100644 --- a/integrationExamples/gpt/unruly_example.html +++ b/integrationExamples/gpt/unruly_example.html @@ -55,6 +55,10 @@ pbjs.setConfig({ "currency": { "adServerCurrency": "USD", + }, + "userSync": { + "iframeEnabled": true, + "enabledBidders": ['unruly'] } }); }); diff --git a/modules/unrulyBidAdapter.js b/modules/unrulyBidAdapter.js index 8aa2dba2007..f8e1cc45296 100644 --- a/modules/unrulyBidAdapter.js +++ b/modules/unrulyBidAdapter.js @@ -98,6 +98,26 @@ export const adapter = { return isInvalidResponse ? noBidsResponse : buildPrebidResponseAndInstallRenderer(serverResponseBody.bids); + }, + + getUserSyncs: function(syncOptions, response, gdprConsent) { + let params = ''; + if (gdprConsent && 'gdprApplies' in gdprConsent) { + if (gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') { + params += `?gdpr=1&gdpr_consent=${gdprConsent.consentString}`; + } else { + params += `?gdpr=0`; + } + } + + const syncs = [] + if (syncOptions.iframeEnabled) { + syncs.push({ + type: 'iframe', + url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html' + params + }); + } + return syncs; } }; diff --git a/test/spec/modules/unrulyBidAdapter_spec.js b/test/spec/modules/unrulyBidAdapter_spec.js index 59f919ed5f5..2cea833be7e 100644 --- a/test/spec/modules/unrulyBidAdapter_spec.js +++ b/test/spec/modules/unrulyBidAdapter_spec.js @@ -205,4 +205,64 @@ describe('UnrulyAdapter', function () { expect(supplyMode).to.equal('prebid'); }); }); + + describe('getUserSyncs', () => { + it('should push user sync iframe if enabled', () => { + const mockConsent = {} + const response = {} + const syncOptions = { iframeEnabled: true } + const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent) + expect(syncs[0]).to.deep.equal({ + type: 'iframe', + url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html' + }); + }) + + it('should not push user sync iframe if not enabled', () => { + const mockConsent = {} + const response = {} + const syncOptions = { iframeEnabled: false } + const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent); + expect(syncs).to.be.empty; + }); + }); + + it('should not append consent params if gdpr does not apply', () => { + const mockConsent = {} + const response = {} + const syncOptions = { iframeEnabled: true } + const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent) + expect(syncs[0]).to.deep.equal({ + type: 'iframe', + url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html' + }) + }) + + it('should append consent params if gdpr does apply and consent is given', () => { + const mockConsent = { + gdprApplies: true, + consentString: 'hello' + } + const response = {} + const syncOptions = { iframeEnabled: true } + const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent) + expect(syncs[0]).to.deep.equal({ + type: 'iframe', + url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html?gdpr=1&gdpr_consent=hello' + }) + }) + + it('should append consent param if gdpr applies and no consent is given', () => { + const mockConsent = { + gdprApplies: true, + consentString: {} + } + const response = {} + const syncOptions = { iframeEnabled: true } + const syncs = adapter.getUserSyncs(syncOptions, response, mockConsent) + expect(syncs[0]).to.deep.equal({ + type: 'iframe', + url: 'https://video.unrulymedia.com/iframes/third-party-iframes.html?gdpr=0' + }) + }) });