Skip to content

Commit

Permalink
Dspx Bid Adapter : add user sync support (#6456)
Browse files Browse the repository at this point in the history
* Add sync support for dspx adapter

* Dspx Bid Adapter : add user sync support

Co-authored-by: Alexander <avj83@list.ru>
  • Loading branch information
onlsol and avj83 authored Mar 31, 2021
1 parent 5cc4405 commit 508f72e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
37 changes: 37 additions & 0 deletions modules/dspxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,44 @@ export const spec = {
bidResponses.push(bidResponse);
}
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
if (!serverResponses || serverResponses.length === 0) {
return [];
}

const syncs = []

let gdprParams = '';
if (gdprConsent) {
if ('gdprApplies' in gdprConsent && typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
gdprParams = `gdpr_consent=${gdprConsent.consentString}`;
}
}

if (syncOptions.iframeEnabled) {
serverResponses[0].body.userSync.iframeUrl.forEach((url) => syncs.push({
type: 'iframe',
url: appendToUrl(url, gdprParams)
}));
}
if (syncOptions.pixelEnabled && serverResponses.length > 0) {
serverResponses[0].body.userSync.imageUrl.forEach((url) => syncs.push({
type: 'image',
url: appendToUrl(url, gdprParams)
}));
}
return syncs;
}
}

function appendToUrl(url, what) {
if (!what) {
return url;
}
return url + (url.indexOf('?') !== -1 ? '&' : '?') + what;
}

function objectToQueryString(obj, prefix) {
Expand Down
56 changes: 56 additions & 0 deletions test/spec/modules/dspxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,60 @@ describe('dspxAdapter', function () {
expect(result.length).to.equal(0);
});
});

describe(`getUserSyncs test usage`, function () {
let serverResponses;

beforeEach(function () {
serverResponses = [{
body: {
requestId: '23beaa6af6cdde',
cpm: 0.5,
width: 0,
height: 0,
creativeId: 100500,
dealId: '',
currency: 'EUR',
netRevenue: true,
ttl: 300,
type: 'sspHTML',
ad: '<!-- test creative -->',
userSync: {
iframeUrl: ['anyIframeUrl?a=1'],
imageUrl: ['anyImageUrl', 'anyImageUrl2']
}
}
}];
});

it(`return value should be an array`, function () {
expect(spec.getUserSyncs({ iframeEnabled: true })).to.be.an('array');
});
it(`array should have only one object and it should have a property type = 'iframe'`, function () {
expect(spec.getUserSyncs({ iframeEnabled: true }, serverResponses).length).to.be.equal(1);
let [userSync] = spec.getUserSyncs({ iframeEnabled: true }, serverResponses);
expect(userSync).to.have.property('type');
expect(userSync.type).to.be.equal('iframe');
});
it(`we have valid sync url for iframe`, function () {
let [userSync] = spec.getUserSyncs({ iframeEnabled: true }, serverResponses, {consentString: 'anyString'});
expect(userSync.url).to.be.equal('anyIframeUrl?a=1&gdpr_consent=anyString')
expect(userSync.type).to.be.equal('iframe');
});
it(`we have valid sync url for image`, function () {
let [userSync] = spec.getUserSyncs({ pixelEnabled: true }, serverResponses, {gdprApplies: true, consentString: 'anyString'});
expect(userSync.url).to.be.equal('anyImageUrl?gdpr=1&gdpr_consent=anyString')
expect(userSync.type).to.be.equal('image');
});
it(`we have valid sync url for image and iframe`, function () {
let userSync = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, serverResponses, {gdprApplies: true, consentString: 'anyString'});
expect(userSync.length).to.be.equal(3);
expect(userSync[0].url).to.be.equal('anyIframeUrl?a=1&gdpr=1&gdpr_consent=anyString')
expect(userSync[0].type).to.be.equal('iframe');
expect(userSync[1].url).to.be.equal('anyImageUrl?gdpr=1&gdpr_consent=anyString')
expect(userSync[1].type).to.be.equal('image');
expect(userSync[2].url).to.be.equal('anyImageUrl2?gdpr=1&gdpr_consent=anyString')
expect(userSync[2].type).to.be.equal('image');
});
});
});

0 comments on commit 508f72e

Please sign in to comment.