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

PE-110: Add user sync logic to the Prebid Adapter #3

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
41 changes: 41 additions & 0 deletions modules/BTBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js';
const BIDDER_CODE = 'blockthrough';
const GVLID = 815;
const ENDPOINT_URL = 'https://pbs.btloader.com/openrtb2/auction';
const SYNC_URL = 'http://temp/sync.html';

const CONVERTER = ortbConverter({
context: {
Expand Down Expand Up @@ -121,13 +122,53 @@ function interpretResponse(serverResponse, request) {
}).bids;
}

/**
* Generates user synchronization data based on provided options and consents.
*
* @param {Object} syncOptions - Synchronization options.
* @param {Object[]} serverResponses - An array of server responses.
* @param {Object} gdprConsent - GDPR consent information.
* @param {string} uspConsent - US Privacy consent string.
* @param {Object} gppConsent - Google Publisher Policies (GPP) consent information.
* @returns {Object[]} An array of user synchronization objects.
*/
function getUserSyncs(
syncOptions,
serverResponses,
gdprConsent,
uspConsent,
gppConsent
) {
let syncs = [];
const syncUrl = new URL(SYNC_URL);

if (gdprConsent) {
syncUrl.searchParams.set('gdpr', Number(gdprConsent.gdprApplies));
syncUrl.searchParams.set('gdpr_consent', gdprConsent.consentString);
}
if (gppConsent) {
syncUrl.searchParams.set('gpp', gppConsent.gppString);
syncUrl.searchParams.set('gpp_sid', gppConsent.applicableSections);
}
if (uspConsent) {
syncUrl.searchParams.set('us_privacy', uspConsent);
}

if (syncOptions.iframeEnabled) {

Choose a reason for hiding this comment

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

wondering if it makes sense to check this before combining sync URL

syncs.push({ type: 'iframe', url: syncUrl.href });
}

return syncs;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
isBidRequestValid,
buildRequests,
interpretResponse,
getUserSyncs,
};

registerBidder(spec);
45 changes: 45 additions & 0 deletions test/spec/modules/BTBidAdapte_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,49 @@ describe('BT Bid Adapter', () => {
expect(bids).to.deep.equal(expectedBids);
});
});

describe('getUserSyncs', () => {
const SYNC_URL = 'http://temp/sync.html';

it('should return an empty array if no sync options are provided', () => {
const syncs = spec.getUserSyncs({}, [], null, null, null);

expect(syncs).to.deep.equal([]);
});

it('should include consent parameters in sync URL if they are provided', () => {
const gdprConsent = {
gdprApplies: true,
consentString: 'GDPRConsentString123',
};
const gppConsent = {
gppString: 'GPPString123',
applicableSections: ['sectionA'],
};
const us_privacy = '1YNY';
const expectedSyncUrl = `${SYNC_URL}?gdpr=1&gdpr_consent=${gdprConsent.consentString}&gpp=${gppConsent.gppString}&gpp_sid=sectionA&us_privacy=${us_privacy}`;

const syncs = spec.getUserSyncs(
{ iframeEnabled: true },
[],
gdprConsent,
us_privacy,
gppConsent
);

expect(syncs).to.deep.equal([{ type: 'iframe', url: expectedSyncUrl }]);
});

it('should not include any consent parameters if no consents are provided', () => {
const syncs = spec.getUserSyncs(
{ iframeEnabled: true },
[],
null,
null,
null
);

expect(syncs).to.deep.equal([{ type: 'iframe', url: SYNC_URL }]);
});
});
});