From bb77747d6dc31f4397d2ad97c764928a0ded01e1 Mon Sep 17 00:00:00 2001 From: fawke Date: Mon, 23 Sep 2019 18:05:48 +0530 Subject: [PATCH 1/5] deprecate some properties of userSync object --- integrationExamples/gpt/hello_world.html | 11 ++++++----- src/adapters/bidderFactory.js | 4 ++-- src/userSync.js | 20 ++++++++------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html index 337c762adc5..030342d81d8 100644 --- a/integrationExamples/gpt/hello_world.html +++ b/integrationExamples/gpt/hello_world.html @@ -24,11 +24,12 @@ }, // Replace this object to test a new Adapter! bids: [{ - bidder: 'appnexus', - params: { - placementId: 13144370 - } - }] + bidder: 'inskin', + params: { + networkId: '9874', + siteId: '983808' + } + }] }]; diff --git a/src/adapters/bidderFactory.js b/src/adapters/bidderFactory.js index 90cab154fd4..6f53dee3a03 100644 --- a/src/adapters/bidderFactory.js +++ b/src/adapters/bidderFactory.js @@ -331,8 +331,8 @@ export function newBidder(spec) { if (spec.getUserSyncs) { let filterConfig = config.getConfig('userSync.filterSettings'); let syncs = spec.getUserSyncs({ - iframeEnabled: !!(config.getConfig('userSync.iframeEnabled') || (filterConfig && (filterConfig.iframe || filterConfig.all))), - pixelEnabled: !!(config.getConfig('userSync.pixelEnabled') || (filterConfig && (filterConfig.image || filterConfig.all))), + iframeEnabled: !!(filterConfig && (filterConfig.iframe || filterConfig.all)), + pixelEnabled: !!(filterConfig && (filterConfig.image || filterConfig.all)), }, responses, gdprConsent); if (syncs) { if (!Array.isArray(syncs)) { diff --git a/src/userSync.js b/src/userSync.js index e2bd4e3f04a..ca28291b014 100644 --- a/src/userSync.js +++ b/src/userSync.js @@ -6,7 +6,12 @@ import includes from 'core-js/library/fn/array/includes'; config.setDefaults({ 'userSync': { syncEnabled: true, - pixelEnabled: true, + filterSettings: { + image: { + bidders: '*', + filter: 'include' + } + }, syncsPerBidder: 5, syncDelay: 3000 } @@ -93,7 +98,7 @@ export function newUserSync(userSyncDependencies) { * @private */ function fireImagePixels() { - if (!(usConfig.pixelEnabled || permittedPixels.image)) { + if (!permittedPixels.image) { return; } forEachFire(queue.image, (sync) => { @@ -110,7 +115,7 @@ export function newUserSync(userSyncDependencies) { * @private */ function loadIframes() { - if (!(usConfig.iframeEnabled || permittedPixels.iframe)) { + if (!(permittedPixels.iframe)) { return; } forEachFire(queue.iframe, (sync) => { @@ -271,13 +276,6 @@ export function newUserSync(userSyncDependencies) { if (shouldBidderBeBlocked(type, bidder)) { return false; } - // TODO remove this else if code that supports deprecated fields (sometime in 2.x); for now - only run if filterSettings config is not present - } else if (usConfig.enabledBidders && usConfig.enabledBidders.length && usConfig.enabledBidders.indexOf(bidder) < 0) { - return false - } else if (type === 'iframe' && !(usConfig.iframeEnabled || permittedPixels.iframe)) { - return false; - } else if (type === 'image' && !(usConfig.pixelEnabled || permittedPixels.image)) { - return false; } return true; } @@ -303,8 +301,6 @@ export const userSync = newUserSync({ * * @property {boolean} enableOverride * @property {boolean} syncEnabled - * @property {boolean} pixelEnabled - * @property {boolean} iframeEnabled * @property {int} syncsPerBidder * @property {string[]} enabledBidders * @property {Object} filterSettings From 57a85d966ae15f2d282d4f7429b6c154e42b79c4 Mon Sep 17 00:00:00 2001 From: Neelanjan Sen Date: Wed, 25 Sep 2019 18:40:59 +0530 Subject: [PATCH 2/5] change bid adapter to Appnexus --- integrationExamples/gpt/hello_world.html | 164 +++++++++++------------ 1 file changed, 82 insertions(+), 82 deletions(-) diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html index 030342d81d8..39f68bb5573 100644 --- a/integrationExamples/gpt/hello_world.html +++ b/integrationExamples/gpt/hello_world.html @@ -8,85 +8,85 @@ --> - - - - - - - - - - - -

Prebid.js Test

-
Div-1
-
- -
- - + + + + + + + + + + + + +

Prebid.js Test

+
Div-1
+
+ +
+ + + From 17163e1d55ea3231d819c8df1f38b0d3f5cd33d7 Mon Sep 17 00:00:00 2001 From: Neelanjan Sen Date: Wed, 25 Sep 2019 18:42:23 +0530 Subject: [PATCH 3/5] fix 3 failing test cases --- test/spec/userSync_spec.js | 52 +++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/test/spec/userSync_spec.js b/test/spec/userSync_spec.js index f55fe13c528..6a5e838ba73 100644 --- a/test/spec/userSync_spec.js +++ b/test/spec/userSync_spec.js @@ -85,21 +85,31 @@ describe('user sync', function () { }); it('should not register pixel URL since it is not supported', function () { - const userSync = newTestUserSync({pixelEnabled: false}); + const userSync = newTestUserSync({filterSettings: { + image: { + bidders: '*', + filter: 'exclude' + } + }}); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); expect(triggerPixelStub.getCall(0)).to.be.null; }); it('should register and load an iframe', function () { - const userSync = newTestUserSync({iframeEnabled: true}); + const userSync = newTestUserSync({filterSettings: { + iframe: { + bidders: '*', + filter: 'include' + } + }}); userSync.registerSync('iframe', 'testBidder', 'http://example.com/iframe'); userSync.syncUsers(); expect(insertUserSyncIframeStub.getCall(0).args[0]).to.equal('http://example.com/iframe'); }); it('should only trigger syncs once per page per bidder', function () { - const userSync = newTestUserSync({pixelEnabled: true}); + const userSync = newTestUserSync({ pixelEnabled: true }); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.syncUsers(); userSync.registerSync('image', 'testBidder', 'http://example.com/2'); @@ -113,7 +123,7 @@ describe('user sync', function () { }); it('should not fire syncs if cookies are not supported', function () { - const userSync = newTestUserSync({pixelEnabled: true}, true); + const userSync = newTestUserSync({ pixelEnabled: true }, true); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); expect(triggerPixelStub.getCall(0)).to.be.null; @@ -132,14 +142,14 @@ describe('user sync', function () { userSync.triggerUserSyncs(); expect(syncUsersSpy.notCalled).to.be.true; // triggerUserSyncs should trigger syncUsers if enableOverride is on - userSync = newTestUserSync({enableOverride: true}); + userSync = newTestUserSync({ enableOverride: true }); syncUsersSpy = sinon.spy(userSync, 'syncUsers'); userSync.triggerUserSyncs(); expect(syncUsersSpy.called).to.be.true; }); it('should limit the number of syncs per bidder', function () { - const userSync = newTestUserSync({syncsPerBidder: 2}); + const userSync = newTestUserSync({ syncsPerBidder: 2 }); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.registerSync('image', 'testBidder', 'http://example.com/2'); userSync.registerSync('image', 'testBidder', 'http://example.com/3'); @@ -151,8 +161,8 @@ describe('user sync', function () { expect(triggerPixelStub.getCall(2)).to.be.null; }); - it('should not limit the number of syncs per bidder when set to 0', function() { - const userSync = newTestUserSync({syncsPerBidder: 0}); + it('should not limit the number of syncs per bidder when set to 0', function () { + const userSync = newTestUserSync({ syncsPerBidder: 0 }); userSync.registerSync('image', 'testBidder', 'http://example.com/1'); userSync.registerSync('image', 'testBidder', 'http://example.com/2'); userSync.registerSync('image', 'testBidder', 'http://example.com/3'); @@ -182,7 +192,7 @@ describe('user sync', function () { }); it('should disable user sync', function () { - const userSync = newTestUserSync({syncEnabled: false}); + const userSync = newTestUserSync({ syncEnabled: false }); userSync.registerSync('pixel', 'testBidder', 'http://example.com'); expect(logWarnStub.getCall(0).args[0]).to.exist; userSync.syncUsers(); @@ -190,7 +200,12 @@ describe('user sync', function () { }); it('should only sync enabled bidders', function () { - const userSync = newTestUserSync({enabledBidders: ['testBidderA']}); + const userSync = newTestUserSync({filterSettings: { + image: { + bidders: ['testBidderA'], + filter: 'include' + } + }}); userSync.registerSync('image', 'testBidderA', 'http://example.com/1'); userSync.registerSync('image', 'testBidderB', 'http://example.com/2'); userSync.syncUsers(); @@ -201,9 +216,9 @@ describe('user sync', function () { it('should register config set after instantiation', function () { // start with userSync off - const userSync = newTestUserSync({syncEnabled: false}); + const userSync = newTestUserSync({ syncEnabled: false }); // turn it on with setConfig() - config.setConfig({userSync: {syncEnabled: true}}); + config.setConfig({ userSync: { syncEnabled: true } }); userSync.registerSync('image', 'testBidder', 'http://example.com'); userSync.syncUsers(); expect(triggerPixelStub.getCall(0)).to.not.be.null; @@ -250,6 +265,7 @@ describe('user sync', function () { it('should throw a warning and default to basic resgistration rules when filterSettings config is invalid', function () { // invalid config - passed invalid filter option + debugger; // eslint-disable-line const userSync1 = newTestUserSync({ filterSettings: { iframe: { @@ -360,8 +376,8 @@ describe('user sync', function () { }); describe('publicAPI', function () { - describe('canBidderRegisterSync', function() { - describe('with filterSettings', function() { + describe('canBidderRegisterSync', function () { + describe('with filterSettings', function () { it('should return false if filter settings does not allow it', function () { const userSync = newUserSync({ config: { @@ -397,8 +413,8 @@ describe('user sync', function () { expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(true); }); }); - describe('almost deprecated - without filterSettings', function() { - describe('enabledBidders contains testBidder', function() { + describe('almost deprecated - without filterSettings', function () { + describe('enabledBidders contains testBidder', function () { it('should return false if type is iframe and iframeEnabled is false', function () { const userSync = newUserSync({ config: { @@ -444,8 +460,8 @@ describe('user sync', function () { }); }); - describe('enabledBidders does not container testBidder', function() { - it('should return false since testBidder is not in enabledBidders', function() { + describe('enabledBidders does not container testBidder', function () { + it('should return false since testBidder is not in enabledBidders', function () { const userSync = newUserSync({ config: { pixelEnabled: true, From 733d53195a0a00498801159b8a0d475d995e9770 Mon Sep 17 00:00:00 2001 From: Neelanjan Sen Date: Thu, 26 Sep 2019 15:20:43 +0530 Subject: [PATCH 4/5] make all unit test cases pass --- src/userSync.js | 2 +- test/spec/userSync_spec.js | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/userSync.js b/src/userSync.js index ca28291b014..751a7dc0995 100644 --- a/src/userSync.js +++ b/src/userSync.js @@ -36,7 +36,7 @@ export function newUserSync(userSyncDependencies) { // for now - default both to false in case filterSettings config is absent/misconfigured let permittedPixels = { - image: false, + image: true, iframe: false }; diff --git a/test/spec/userSync_spec.js b/test/spec/userSync_spec.js index 6a5e838ba73..ce2d9b8182c 100644 --- a/test/spec/userSync_spec.js +++ b/test/spec/userSync_spec.js @@ -418,9 +418,12 @@ describe('user sync', function () { it('should return false if type is iframe and iframeEnabled is false', function () { const userSync = newUserSync({ config: { - pixelEnabled: true, - iframeEnabled: false, - enabledBidders: ['testBidder'], + filterSettings: { + iframe: { + bidders: ['testBidder'], + filter: 'exclude' + } + } } }); expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(false); @@ -440,9 +443,12 @@ describe('user sync', function () { it('should return false if type is image and pixelEnabled is false', function () { const userSync = newUserSync({ config: { - pixelEnabled: false, - iframeEnabled: true, - enabledBidders: ['testBidder'], + filterSettings: { + image: { + bidders: ['testBidder'], + filter: 'exclude' + } + } } }); expect(userSync.canBidderRegisterSync('image', 'testBidder')).to.equal(false); @@ -464,9 +470,16 @@ describe('user sync', function () { it('should return false since testBidder is not in enabledBidders', function () { const userSync = newUserSync({ config: { - pixelEnabled: true, - iframeEnabled: true, - enabledBidders: ['otherTestBidder'], + filterSettings: { + image: { + bidders: ['otherTestBidder'], + filter: 'include' + }, + iframe: { + bidders: ['otherTestBidder'], + filter: 'include' + } + } } }); expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(false); From 31e7d8dde56669f7f6251d6a6c92d4af90aa27b0 Mon Sep 17 00:00:00 2001 From: Neelanjan Sen Date: Tue, 12 Nov 2019 13:01:11 +0530 Subject: [PATCH 5/5] remove debugger --- test/spec/userSync_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/userSync_spec.js b/test/spec/userSync_spec.js index ce2d9b8182c..806e86e998b 100644 --- a/test/spec/userSync_spec.js +++ b/test/spec/userSync_spec.js @@ -265,7 +265,6 @@ describe('user sync', function () { it('should throw a warning and default to basic resgistration rules when filterSettings config is invalid', function () { // invalid config - passed invalid filter option - debugger; // eslint-disable-line const userSync1 = newTestUserSync({ filterSettings: { iframe: {