Skip to content

Commit

Permalink
fix usersync gdpr (prebid#7785)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrmartinez authored and Chris Pabst committed Jan 10, 2022
1 parent 68aea86 commit 724ddae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 10 additions & 8 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mergeDeep, _each, logError, deepAccess, deepSetValue, isStr, isNumber, logWarn, convertTypes, isArray, parseSizesInput, logMessage } from '../src/utils.js';
import { mergeDeep, _each, logError, deepAccess, deepSetValue, isStr, isNumber, logWarn, convertTypes, isArray, parseSizesInput, logMessage, formatQS } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
Expand Down Expand Up @@ -765,21 +765,23 @@ export const spec = {
getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
if (!hasSynced && syncOptions.iframeEnabled) {
// data is only assigned if params are available to pass to syncEndpoint
let params = '';
let params = {};

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
// add 'gdpr' only if 'gdprApplies' is defined
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
params += `?gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
params += `?gdpr_consent=${gdprConsent.consentString}`;
params['gdpr'] = Number(gdprConsent.gdprApplies);
}
if (typeof gdprConsent.consentString === 'string') {
params['gdpr_consent'] = gdprConsent.consentString;
}
}

if (uspConsent) {
params += `${params ? '&' : '?'}us_privacy=${encodeURIComponent(uspConsent)}`;
params['us_privacy'] = encodeURIComponent(uspConsent);
}

params = Object.keys(params).length ? `?${formatQS(params)}` : '';

hasSynced = true;
return {
type: 'iframe',
Expand Down
17 changes: 17 additions & 0 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3343,6 +3343,23 @@ describe('the rubicon adapter', function () {
type: 'iframe', url: `${emilyUrl}?gdpr_consent=foo&us_privacy=1NYN`
});
});

it('should pass gdprApplies', function () {
expect(spec.getUserSyncs({iframeEnabled: true}, {}, {
gdprApplies: true
}, '1NYN')).to.deep.equal({
type: 'iframe', url: `${emilyUrl}?gdpr=1&us_privacy=1NYN`
});
});

it('should pass all correctly', function () {
expect(spec.getUserSyncs({iframeEnabled: true}, {}, {
gdprApplies: true,
consentString: 'foo'
}, '1NYN')).to.deep.equal({
type: 'iframe', url: `${emilyUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN`
});
});
});

describe('get price granularity', function () {
Expand Down

0 comments on commit 724ddae

Please sign in to comment.