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

Add userSync in onetagBidAdapter #4358

Merged
merged 7 commits into from
Oct 23, 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
30 changes: 30 additions & 0 deletions modules/onetagBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const { registerBidder } = require('../src/adapters/bidderFactory');

const ENDPOINT = 'https://onetag-sys.com/prebid-request';
const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/';
const BIDDER_CODE = 'onetag';
const BANNER = 'banner';

Expand Down Expand Up @@ -120,8 +121,15 @@ function getPageInfo() {
masked: m,
wWidth: w.innerWidth,
wHeight: w.innerHeight,
oWidth: w.outerWidth,
oHeight: w.outerHeight,
sWidth: s.width,
sHeight: s.height,
aWidth: s.availWidth,
aHeight: s.availHeight,
sLeft: 'screenLeft' in w ? w.screenLeft : w.screenX,
sTop: 'screenTop' in w ? w.screenTop : w.screenY,
hLength: history.length,
date: t.toUTCString(),
timeOffset: t.getTimezoneOffset()
};
Expand Down Expand Up @@ -162,6 +170,27 @@ function requestsToBids(bid) {
return toRet;
}

function getUserSyncs(syncOptions, serverResponses, gdprConsent) {
const syncs = [];
if (syncOptions.iframeEnabled) {
const rnd = new Date().getTime();
let params = '?cb=' + rnd;

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
params += '&gdpr_consent=' + gdprConsent.consentString;
if (typeof gdprConsent.gdprApplies === 'boolean') {
params += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
}
}

syncs.push({
type: 'iframe',
url: USER_SYNC_ENDPOINT + params
});
}
return syncs;
}

export const spec = {

code: BIDDER_CODE,
Expand All @@ -170,6 +199,7 @@ export const spec = {
isBidRequestValid: isBidRequestValid,
buildRequests: buildRequests,
interpretResponse: interpretResponse,
getUserSyncs: getUserSyncs

};

Expand Down
61 changes: 60 additions & 1 deletion test/spec/modules/onetagBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ describe('onetag', function () {
const data = JSON.parse(d);
it('Should contains all keys', function () {
expect(data).to.be.an('object');
expect(data).to.have.all.keys('location', 'masked', 'referrer', 'sHeight', 'sWidth', 'timeOffset', 'date', 'wHeight', 'wWidth', 'bids');
expect(data).to.have.all.keys('location', 'masked', 'referrer', 'sHeight', 'sWidth', 'timeOffset', 'date', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids');
expect(data.location).to.be.a('string');
expect(data.masked).to.be.a('number');
expect(data.referrer).to.be.a('string');
expect(data.sHeight).to.be.a('number');
expect(data.sWidth).to.be.a('number');
expect(data.wWidth).to.be.a('number');
expect(data.wHeight).to.be.a('number');
expect(data.oHeight).to.be.a('number');
expect(data.oWidth).to.be.a('number');
expect(data.aWidth).to.be.a('number');
expect(data.aHeight).to.be.a('number');
expect(data.sLeft).to.be.a('number');
expect(data.sTop).to.be.a('number');
expect(data.hLength).to.be.a('number');
expect(data.timeOffset).to.be.a('number');
expect(data.date).to.be.a('string');
expect(data.bids).to.be.an('array');
Expand Down Expand Up @@ -146,4 +153,56 @@ describe('onetag', function () {
});
});
});
describe('getUserSyncs', function () {
const sync_endpoint = 'https://onetag-sys.com/usync/';
it('Returns an iframe if iframeEnabled is true', function () {
const syncs = spec.getUserSyncs({iframeEnabled: true});
expect(syncs).to.be.an('array');
expect(syncs.length).to.equal(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
});
it('Returns an empty array if iframeEnabled is false', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: false });
expect(syncs).to.be.an('array').that.is.empty;
});
it('Must pass gdpr params when gdprApplies is true', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {
gdprApplies: true, consentString: 'foo'
});
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)|gdpr=1([^&]*)|[^&]*))+$/);
});
it('Must pass gdpr params when gdprApplies is false', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {
gdprApplies: false, consentString: 'foo'
});
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)|gdpr=0([^&]*)))+$/);
});
it('Must pass gdpr consent string param when gdprApplies is undefined', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {
consentString: 'foo'
});
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)))+$/);
});
it('Must pass no gdpr params when consentString is null', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {
consentString: null
});
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
expect(syncs[0].url).to.not.match(/(?:[?&](?:gdpr_consent=([^&]*)|gdpr=([^&]*)))+$/);
});
it('Must pass no gdpr param when gdprConsent is empty', function () {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {});
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.include(sync_endpoint);
expect(syncs[0].url).to.not.match(/(?:[?&](?:gdpr_consent=([^&]*)|gdpr=([^&]*)))+$/);
});
});
});