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

VIS.X Bid Adapter: iframe sync support & optional video params #7527

Merged
merged 1 commit into from
Oct 9, 2021
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
37 changes: 15 additions & 22 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,21 @@ export const spec = {
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
if (syncOptions.pixelEnabled) {
var query = [];
if (gdprConsent) {
if (gdprConsent.consentString) {
query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString));
}
query.push('gdpr_applies=' + encodeURIComponent(
(typeof gdprConsent.gdprApplies === 'boolean')
? Number(gdprConsent.gdprApplies) : 1));
var query = [];
if (gdprConsent) {
if (gdprConsent.consentString) {
query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString));
}
query.push('gdpr_applies=' + encodeURIComponent(
(typeof gdprConsent.gdprApplies === 'boolean')
? Number(gdprConsent.gdprApplies) : 1));
}
if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: buildUrl(ADAPTER_SYNC_PATH) + '?iframe=1' + (query.length ? '&' + query.join('&') : '')
}];
} else if (syncOptions.pixelEnabled) {
return [{
type: 'image',
url: buildUrl(ADAPTER_SYNC_PATH) + (query.length ? '?' + query.join('&') : '')
Expand Down Expand Up @@ -230,7 +235,7 @@ function makeVideo(videoParams = {}) {
return result;
}, { w: deepAccess(videoParams, 'playerSize.0.0'), h: deepAccess(videoParams, 'playerSize.0.1') });

if (video.w && video.h && video.mimes) {
if (video.w && video.h) {
return video;
}
}
Expand Down Expand Up @@ -347,18 +352,6 @@ function _isValidVideoBid(bid, logErrors = false) {
}
result = false;
}
if (!videoMediaType.mimes) {
if (logErrors) {
logError(LOG_ERROR_MESS.videoMissing + 'mimes');
}
result = false;
}
if (!videoMediaType.protocols) {
if (logErrors) {
logError(LOG_ERROR_MESS.videoMissing + 'protocols');
}
result = false;
}
return result;
}

Expand Down
52 changes: 48 additions & 4 deletions test/spec/modules/visxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ describe('VisxAdapter', function () {
videoBid.mediaTypes = {
video: {
context: 'instream',
playerSize: [[400, 300]]
mimes: ['video/mp4'],
protocols: [3, 6]
}
};
expect(spec.isBidRequestValid(videoBid)).to.equal(false);
Expand All @@ -55,9 +56,7 @@ describe('VisxAdapter', function () {
videoBid.mediaTypes = {
video: {
context: 'instream',
playerSize: [[400, 300]],
mimes: ['video/mp4'],
protocols: [3, 6]
playerSize: [[400, 300]]
}
};
expect(spec.isBidRequestValid(videoBid)).to.equal(true);
Expand Down Expand Up @@ -1153,4 +1152,49 @@ describe('VisxAdapter', function () {
expect(utils.triggerPixel.calledOnceWith('https://t.visx.net/track/bid_timeout?data=' + JSON.stringify(data))).to.equal(true);
});
});

describe('user sync', function () {
function parseUrl(url) {
const [, path, querySt] = url.match(/^https?:\/\/[^\/]+(?:\/([^?]+)?)?(?:\?(.+)?)?$/) || [];
const query = {};
(querySt || '').split('&').forEach((q) => {
var kv = q.split('=');
if (kv[0]) {
query[kv[0]] = decodeURIComponent(kv[1] || '');
}
});
return { path, query };
}
it('should call iframe', function () {
let syncs = spec.getUserSyncs({
iframeEnabled: true
});

expect(Array.isArray(syncs)).to.equal(true);
expect(syncs.length).to.equal(1);
expect(syncs[0]).to.have.property('type', 'iframe');
expect(syncs[0]).to.have.property('url');
expect(syncs[0].url).to.be.an('string');

const { path, query } = parseUrl(syncs[0].url);
expect(path).to.equal('push_sync');
expect(query).to.deep.equal({iframe: '1'});
});

it('should call image', function () {
let syncs = spec.getUserSyncs({
pixelEnabled: true
});

expect(Array.isArray(syncs)).to.equal(true);
expect(syncs.length).to.equal(1);
expect(syncs[0]).to.have.property('type', 'image');
expect(syncs[0]).to.have.property('url');
expect(syncs[0].url).to.be.an('string');

const { path, query } = parseUrl(syncs[0].url);
expect(path).to.equal('push_sync');
expect(query).to.deep.equal({});
});
});
});