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

PubMatic Bid Adapter : add GPP support #10165

Merged
merged 14 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
17 changes: 16 additions & 1 deletion modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,15 @@ export const spec = {
deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

// Attaching GPP Consent Params
if (bidderRequest?.gppConsent?.gppString) {
deepSetValue(payload, 'regs.gpp', bidderRequest.gppConsent.gppString);
deepSetValue(payload, 'regs.gpp_sid', bidderRequest.gppConsent.applicableSections);
} else if (bidderRequest?.ortb2?.regs?.gpp) {
deepSetValue(payload, 'regs.gpp', bidderRequest.ortb2.regs.gpp);
deepSetValue(payload, 'regs.gpp_sid', bidderRequest.ortb2.regs.gpp_sid);
}

// coppa compliance
if (config.getConfig('coppa') === true) {
deepSetValue(payload, 'regs.coppa', 1);
Expand Down Expand Up @@ -1352,7 +1361,7 @@ export const spec = {
/**
* Register User Sync.
*/
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => {
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent, gppConsent) => {
let syncurl = '' + publisherId;

// Attaching GDPR Consent Params in UserSync url
Expand All @@ -1366,6 +1375,12 @@ export const spec = {
syncurl += '&us_privacy=' + encodeURIComponent(uspConsent);
}

// GPP Consent
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
syncurl += '&gpp=' + encodeURIComponent(gppConsent.gppString);
syncurl += '&gpp_sid=' + encodeURIComponent(gppConsent?.applicableSections);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in user syncs I think you are supposed to encode as a string, not an array

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Yes, it should encode as string, fixed it.

}

// coppa compliance
if (config.getConfig('coppa') === true) {
syncurl += '&coppa=1';
Expand Down
120 changes: 120 additions & 0 deletions test/spec/modules/pubmaticBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,77 @@ describe('PubMatic adapter', function () {
});
}

describe('GPP', function() {
it('Request params check with GPP Consent', function () {
let bidRequest = {
gppConsent: {
'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN',
'fullGppData': {
'sectionId': 3,
'gppVersion': 1,
'sectionList': [
5,
7
],
'applicableSections': [
5
],
'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN',
'pingData': {
'cmpStatus': 'loaded',
'gppVersion': '1.0',
'cmpDisplayStatus': 'visible',
'supportedAPIs': [
'tcfca',
'usnat',
'usca',
'usva',
'usco',
'usut',
'usct'
],
'cmpId': 31
},
'eventName': 'sectionChange'
},
'applicableSections': [
5
],
'apiVersion': 1
}
};
let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN');
expect(data.regs.gpp_sid[0]).to.equal(5);
});

it('Request params check without GPP Consent', function () {
let bidRequest = {};
let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
expect(data.regs).to.equal(undefined);
});

it('Request params check with GPP Consent read from ortb2', function () {
let bidRequest = {
ortb2: {
regs: {
'gpp': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN',
'gpp_sid': [
5
]
}
}
};
let request = spec.buildRequests(bidRequests, bidRequest);
let data = JSON.parse(request.data);
expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN');
expect(data.regs.gpp_sid[0]).to.equal(5);
});
});


describe('Fledge', function() {
it('should not send imp.ext.ae when FLEDGE is disabled, ', function () {
let bidRequest = Object.assign([], bidRequests);
Expand Down Expand Up @@ -3991,6 +4062,55 @@ describe('PubMatic adapter', function () {
type: 'image', url: `${syncurl_image}&gdpr=1&gdpr_consent=foo&us_privacy=1NYN&coppa=1`
}]);
});

describe('GPP', function() {
it('should return userSync url without Gpp consent if gppConsent is undefined', () => {
const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, undefined);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should return userSync url without Gpp consent if gppConsent.gppString is undefined', () => {
const gppConsent = { applicableSections: ['5'] };
const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should return userSync url without Gpp consent if gppConsent.applicableSections is undefined', () => {
const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' };
const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should return userSync url without Gpp consent if gppConsent.applicableSections is an empty array', () => {
const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [] };
const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should concatenate gppString and applicableSections values in the returned userSync iframe url', () => {
const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5] };
const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gpp=${encodeURIComponent(gppConsent.gppString)}&gpp_sid=${encodeURIComponent(gppConsent.applicableSections)}`
}]);
});

it('should concatenate gppString and applicableSections values in the returned userSync image url', () => {
const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5] };
const result = spec.getUserSyncs({iframeEnabled: false}, undefined, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'image', url: `${syncurl_image}&gpp=${encodeURIComponent(gppConsent.gppString)}&gpp_sid=${encodeURIComponent(gppConsent.applicableSections)}`
}]);
});
});
});

if (FEATURES.VIDEO) {
Expand Down