Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonobi - Add ius param to bid request endpoint #3657

Merged
merged 6 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { parseSizesInput, logError, generateUUID, isEmpty, deepAccess, logWarn,
import { BANNER, VIDEO } from '../src/mediaTypes';
import { config } from '../src/config';
import { Renderer } from '../src/Renderer';
import { userSync } from '../src/userSync';

const BIDDER_CODE = 'sonobi';
const STR_ENDPOINT = 'https://apex.go.sonobi.com/trinity.json';
Expand Down Expand Up @@ -62,6 +63,13 @@ export const spec = {
payload.us = config.getConfig('userSync').syncsPerBidder;
}

// use userSync's internal function to determine if we can drop an iframe sync pixel
if (_iframeAllowed()) {
payload.ius = 1;
} else {
payload.ius = 0;
}

if (deepAccess(validBidRequests[0], 'params.hfa')) {
payload.hfa = deepAccess(validBidRequests[0], 'params.hfa');
} else if (deepAccess(validBidRequests[0], 'userId.pubcid')) {
Expand Down Expand Up @@ -327,4 +335,8 @@ function outstreamRender(bid) {
});
}

function _iframeAllowed() {
return userSync.canBidderRegisterSync('iframe', BIDDER_CODE);
}

registerBidder(spec);
Empty file added sonobi_video.html
Empty file.
25 changes: 18 additions & 7 deletions src/userSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,9 @@ export function newUserSync(userSyncDependencies) {
return utils.logWarn(`Number of user syncs exceeded for "${bidder}"`);
}

if (usConfig.filterSettings) {
if (shouldBidderBeBlocked(type, bidder)) {
return utils.logWarn(`Bidder '${bidder}' is not permitted to register their userSync ${type} pixels as per filterSettings config.`);
}
// 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 utils.logWarn(`Bidder "${bidder}" not permitted to register their userSync pixels.`);
const canBidderRegisterSync = publicApi.canBidderRegisterSync(type, bidder);
if (!canBidderRegisterSync) {
return utils.logWarn(`Bidder "${bidder}" not permitted to register their "${type}" userSync pixels.`);
}

// the bidder's pixel has passed all checks and is allowed to register
Expand Down Expand Up @@ -262,6 +258,21 @@ export function newUserSync(userSyncDependencies) {
}
};

publicApi.canBidderRegisterSync = (type, bidder) => {
if (usConfig.filterSettings) {
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;
}
return publicApi;
}

Expand Down
19 changes: 19 additions & 0 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai'
import { spec, _getPlatform } from 'modules/sonobiBidAdapter'
import { newBidder } from 'src/adapters/bidderFactory'
import {userSync} from '../../../src/userSync';

describe('SonobiBidAdapter', function () {
const adapter = newBidder(spec)
Expand Down Expand Up @@ -101,6 +102,12 @@ describe('SonobiBidAdapter', function () {
})

describe('.buildRequests', function () {
beforeEach(function() {
sinon.stub(userSync, 'canBidderRegisterSync');
});
afterEach(function() {
userSync.canBidderRegisterSync.restore();
});
let bidRequest = [{
'bidder': 'sonobi',
'params': {
Expand Down Expand Up @@ -318,6 +325,18 @@ describe('SonobiBidAdapter', function () {
expect(bidRequests.data.s).not.to.be.empty
expect(bidRequests.data.hfa).to.equal('hfakey')
})

it('should set ius as 0 if Sonobi cannot drop iframe pixels', function () {
userSync.canBidderRegisterSync.returns(false);
const bidRequests = spec.buildRequests(bidRequest, bidderRequests);
expect(bidRequests.data.ius).to.equal(0);
});

it('should set ius as 1 if Sonobi can drop iframe pixels', function() {
userSync.canBidderRegisterSync.returns(true);
const bidRequests = spec.buildRequests(bidRequest, bidderRequests);
expect(bidRequests.data.ius).to.equal(1);
});
})

describe('.interpretResponse', function () {
Expand Down
101 changes: 101 additions & 0 deletions test/spec/userSync_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,105 @@ describe('user sync', function () {
expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.equal('http://example.com/1');
expect(insertUserSyncIframeStub.getCall(0)).to.be.null;
});

describe('publicAPI', function () {
describe('canBidderRegisterSync', function() {
describe('with filterSettings', function() {
it('should return false if filter settings does not allow it', function () {
const userSync = newUserSync({
config: {
filterSettings: {
image: {
bidders: '*',
filter: 'include'
},
iframe: {
bidders: ['testBidder'],
filter: 'include'
}
}
}
});
expect(userSync.canBidderRegisterSync('iframe', 'otherTestBidder')).to.equal(false);
});
it('should return true if filter settings does allow it', function () {
const userSync = newUserSync({
config: {
filterSettings: {
image: {
bidders: '*',
filter: 'include'
},
iframe: {
bidders: ['testBidder'],
filter: 'include'
}
}
}
});
expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(true);
});
});
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: {
pixelEnabled: true,
iframeEnabled: false,
enabledBidders: ['testBidder'],
}
});
expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(false);
});

it('should return true if type is iframe and iframeEnabled is true', function () {
const userSync = newUserSync({
config: {
pixelEnabled: true,
iframeEnabled: true,
enabledBidders: ['testBidder'],
}
});
expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(true);
});

it('should return false if type is image and pixelEnabled is false', function () {
const userSync = newUserSync({
config: {
pixelEnabled: false,
iframeEnabled: true,
enabledBidders: ['testBidder'],
}
});
expect(userSync.canBidderRegisterSync('image', 'testBidder')).to.equal(false);
});

it('should return true if type is image and pixelEnabled is true', function () {
const userSync = newUserSync({
config: {
pixelEnabled: true,
iframeEnabled: true,
enabledBidders: ['testBidder'],
}
});
expect(userSync.canBidderRegisterSync('image', 'testBidder')).to.equal(true);
});
});

describe('enabledBidders does not container testBidder', function() {
it('should return false since testBidder is not in enabledBidders', function() {
const userSync = newUserSync({
config: {
pixelEnabled: true,
iframeEnabled: true,
enabledBidders: ['otherTestBidder'],
}
});
expect(userSync.canBidderRegisterSync('iframe', 'testBidder')).to.equal(false);
});
});
});
});
});
});