Skip to content

Commit

Permalink
Outbrain Bid Adapter: fix usersync query parameter formatting (prebid…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rok Sušnik authored and stsepelin committed May 28, 2021
1 parent 1a76585 commit 5cfba10
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
10 changes: 6 additions & 4 deletions modules/outbrainBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,20 @@ export const spec = {
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => {
const syncs = [];
let syncUrl = config.getConfig('outbrain.usersyncUrl');

let query = [];
if (syncOptions.pixelEnabled && syncUrl) {
if (gdprConsent) {
syncUrl += '&gdpr=' + (gdprConsent.gdprApplies & 1);
syncUrl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
query.push('gdpr=' + (gdprConsent.gdprApplies & 1));
query.push('gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || ''));
}
if (uspConsent) {
syncUrl += '&us_privacy=' + encodeURIComponent(uspConsent);
query.push('us_privacy=' + encodeURIComponent(uspConsent));
}

syncs.push({
type: 'image',
url: syncUrl
url: syncUrl + (query.length ? '?' + query.join('&') : '')
});
}
return syncs;
Expand Down
22 changes: 6 additions & 16 deletions test/spec/modules/outbrainBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,19 +493,9 @@ describe('Outbrain Adapter', function () {
config.resetConfig()
})

it('should return user sync if pixel enabled', function () {
const ret = spec.getUserSyncs({pixelEnabled: true})
expect(ret).to.deep.equal([{type: 'image', url: 'https://usersync-url.com'}])
})
it('should return user sync if pixel enabled with outbrain config', function () {
config.resetConfig()
config.setConfig({
outbrain: {
usersyncUrl: 'https://usersync-url.com',
}
})
const ret = spec.getUserSyncs({pixelEnabled: true})
expect(ret).to.deep.equal([{type: 'image', url: 'https://usersync-url.com'}])
expect(ret).to.deep.equal([{type: 'image', url: usersyncUrl}])
})

it('should not return user sync if pixel disabled', function () {
Expand All @@ -521,25 +511,25 @@ describe('Outbrain Adapter', function () {

it('should pass GDPR consent', function() {
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'image', url: `${usersyncUrl}&gdpr=1&gdpr_consent=foo`
type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'image', url: `${usersyncUrl}&gdpr=0&gdpr_consent=foo`
type: 'image', url: `${usersyncUrl}?gdpr=0&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{
type: 'image', url: `${usersyncUrl}&gdpr=1&gdpr_consent=`
type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=`
}]);
});

it('should pass US consent', function() {
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{
type: 'image', url: `${usersyncUrl}&us_privacy=1NYN`
type: 'image', url: `${usersyncUrl}?us_privacy=1NYN`
}]);
});

it('should pass GDPR and US consent', function() {
expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.deep.equal([{
type: 'image', url: `${usersyncUrl}&gdpr=1&gdpr_consent=foo&us_privacy=1NYN`
type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN`
}]);
});
})
Expand Down

0 comments on commit 5cfba10

Please sign in to comment.