Skip to content

Commit

Permalink
Consumable Bid Adapter: fix us privacy format and make gpp applicable…
Browse files Browse the repository at this point in the history
… sections optional (#10707)

* consumableBidAdapter: fix usp and gpp handling

* make gpp applicable sections optional
  • Loading branch information
jpiros authored Nov 9, 2023
1 parent 51ca28c commit a3c64d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 47 deletions.
13 changes: 8 additions & 5 deletions modules/consumableBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,20 @@ export const spec = {
if (syncOptions.iframeEnabled) {
if (gdprConsent && gdprConsent.consentString) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
syncUrl = appendUrlParam(syncUrl, `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`);
syncUrl = appendUrlParam(syncUrl, `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${encodeURIComponent(gdprConsent.consentString) || ''}`);
} else {
syncUrl = appendUrlParam(syncUrl, `gdpr=0&gdpr_consent=${gdprConsent.consentString}`);
syncUrl = appendUrlParam(syncUrl, `gdpr=0&gdpr_consent=${encodeURIComponent(gdprConsent.consentString) || ''}`);
}
}
if (gppConsent && gppConsent.gppString) {
syncUrl = appendUrlParam(syncUrl, `gpp=${gppConsent.gppString}&gpp_sid=${gppConsent.applicableSections}`);
syncUrl = appendUrlParam(syncUrl, `gpp=${encodeURIComponent(gppConsent.gppString)}`);
if (gppConsent.applicableSections && gppConsent.applicableSections.length > 0) {
syncUrl = appendUrlParam(syncUrl, `gpp_sid=${encodeURIComponent(gppConsent.applicableSections.join(','))}`);
}
}

if (uspConsent && uspConsent.consentString) {
syncUrl = appendUrlParam(syncUrl, `us_privacy=${uspConsent.consentString}`);
if (uspConsent) {
syncUrl = appendUrlParam(syncUrl, `us_privacy=${encodeURIComponent(uspConsent)}`);
}

if (!serverResponses || serverResponses.length === 0 || !serverResponses[0].body.bdr || serverResponses[0].body.bdr !== 'cx') {
Expand Down
63 changes: 21 additions & 42 deletions test/spec/modules/consumableBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,21 +651,30 @@ describe('Consumable BidAdapter', function () {
expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gdpr=0&gdpr_consent=GDPR_CONSENT_STRING');
})

it('should return a sync url if iframe syncs are enabled and GPP applies', function () {
it('should return a sync url if iframe syncs are enabled and has GPP consent with applicable sections', function () {
let gppConsent = {
applicableSections: [1, 2],
gppString: 'GPP_CONSENT_STRING'
}
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, {}, gppConsent);
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, '', gppConsent);

expect(opts.length).to.equal(1);
expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gpp=GPP_CONSENT_STRING&gpp_sid=1,2');
expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gpp=GPP_CONSENT_STRING&gpp_sid=1%2C2');
})

it('should return a sync url if iframe syncs are enabled and USP applies', function () {
let uspConsent = {
consentString: 'USP_CONSENT_STRING',
it('should return a sync url if iframe syncs are enabled and has GPP consent without applicable sections', function () {
let gppConsent = {
applicableSections: [],
gppString: 'GPP_CONSENT_STRING'
}
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, '', gppConsent);

expect(opts.length).to.equal(1);
expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gpp=GPP_CONSENT_STRING');
})

it('should return a sync url if iframe syncs are enabled and USP applies', function () {
let uspConsent = 'USP_CONSENT_STRING';
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, uspConsent);

expect(opts.length).to.equal(1);
Expand All @@ -677,9 +686,7 @@ describe('Consumable BidAdapter', function () {
consentString: 'GDPR_CONSENT_STRING',
gdprApplies: true,
}
let uspConsent = {
consentString: 'USP_CONSENT_STRING',
}
let uspConsent = 'USP_CONSENT_STRING';
let opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], gdprConsent, uspConsent);

expect(opts.length).to.equal(1);
Expand All @@ -704,50 +711,22 @@ describe('Consumable BidAdapter', function () {
sandbox.restore();
});

it('Request should have unifiedId config params', function() {
it('Request should have EIDs', function() {
bidderRequest.bidRequest[0].userId = {};
bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID';
bidderRequest.bidRequest[0].userIdAsEids = createEidsArray(bidderRequest.bidRequest[0].userId);
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
bidderRequest.bidRequest[0].userIdAsEids = [{
'source': 'adserver.org',
'uids': [{
'id': 'TTD_ID',
'id': 'TTD_ID_FROM_USER_ID_MODULE',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}]
}]);
});

it('Request should have adsrvrOrgId from UserId Module if config and userId module both have TTD ID', function() {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
adsrvrOrgId: {
'TDID': 'TTD_ID_FROM_CONFIG',
'TDID_LOOKUP': 'TRUE',
'TDID_CREATED_AT': '2022-06-21T09:47:00'
}
};
return config[key];
});
bidderRequest.bidRequest[0].userId = {};
bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID';
bidderRequest.bidRequest[0].userIdAsEids = createEidsArray(bidderRequest.bidRequest[0].userId);
}];
let request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1);
let data = JSON.parse(request.data);
expect(data.user.eids).to.deep.equal([{
'source': 'adserver.org',
'uids': [{
'id': 'TTD_ID',
'atype': 1,
'ext': {
'rtiPartner': 'TDID'
}
}]
}]);
expect(data.user.eids).to.deep.equal(bidderRequest.bidRequest[0].userIdAsEids);
});

it('Request should NOT have adsrvrOrgId params if userId is NOT object', function() {
Expand Down

0 comments on commit a3c64d4

Please sign in to comment.