Skip to content

Commit

Permalink
Optidigital Bid Adapter : update usersync (prebid#10279)
Browse files Browse the repository at this point in the history
* add new adapter

* update adapter

* update unit tests

* update adapter

---------

Co-authored-by: Dawid W <dawid@optidigital.fr>
  • Loading branch information
2 people authored and Santiago Carabone committed Aug 22, 2023
1 parent 83eb9f5 commit e1cb8f0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
41 changes: 25 additions & 16 deletions modules/optidigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const GVL_ID = 915;
const ENDPOINT_URL = 'https://pbs.optidigital.com/bidder';
const USER_SYNC_URL_IFRAME = 'https://scripts.opti-digital.com/js/presync.html?endpoint=optidigital';
let CUR = 'USD';
let isSynced = false;

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -46,8 +47,6 @@ export const spec = {
referrer: (bidderRequest.refererInfo && bidderRequest.refererInfo.page) ? bidderRequest.refererInfo.page : '',
hb_version: '$prebid.version$',
deviceWidth: document.documentElement.clientWidth,
// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
auctionId: deepAccess(validBidRequests[0], 'auctionId'),
bidderRequestId: deepAccess(validBidRequests[0], 'bidderRequestId'),
publisherId: deepAccess(validBidRequests[0], 'params.publisherId'),
imp: validBidRequests.map(bidRequest => buildImp(bidRequest, ortb2)),
Expand All @@ -56,6 +55,10 @@ export const spec = {
bapp: deepAccess(validBidRequests[0], 'params.bapp') || []
}

if (validBidRequests[0].auctionId) {
payload.auctionId = validBidRequests[0].auctionId;
}

if (validBidRequests[0].params.pageTemplate && validBidRequests[0].params.pageTemplate !== '') {
payload.pageTemplate = validBidRequests[0].params.pageTemplate;
}
Expand Down Expand Up @@ -136,21 +139,23 @@ export const spec = {
*/
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
let syncurl = '';
if (!isSynced) {
// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent && uspConsent.consentString) {
syncurl += `&ccpa_consent=${uspConsent.consentString}`;
}

// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent && uspConsent.consentString) {
syncurl += `&ccpa_consent=${uspConsent.consentString}`;
}

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: USER_SYNC_URL_IFRAME + syncurl
}];
if (syncOptions.iframeEnabled) {
isSynced = true;
return [{
type: 'iframe',
url: USER_SYNC_URL_IFRAME + syncurl
}];
}
}
},
};
Expand Down Expand Up @@ -218,4 +223,8 @@ function _getFloor (bid, sizes, currency) {
return floor !== null ? floor : bid.params.floor;
}

export function resetSync() {
isSynced = false;
}

registerBidder(spec);
11 changes: 9 additions & 2 deletions test/spec/modules/optidigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec } from 'modules/optidigitalBidAdapter.js';
import { spec, resetSync } from 'modules/optidigitalBidAdapter.js';
import * as utils from 'src/utils.js';

const ENDPOINT = 'https://pbs.optidigital.com/bidder';
Expand Down Expand Up @@ -497,6 +497,7 @@ describe('optidigitalAdapterTests', function () {
let test;
beforeEach(function () {
test = sinon.sandbox.create();
resetSync();
});
afterEach(function() {
test.restore();
Expand All @@ -508,16 +509,22 @@ describe('optidigitalAdapterTests', function () {
}]);
});

it('should return appropriate URL', function() {
it('should return appropriate URL with GDPR equals to 1 and GDPR consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo`
}]);
});
it('should return appropriate URL with GDPR equals to 0 and GDPR consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=0&gdpr_consent=foo`
}]);
});
it('should return appropriate URL with GDPR equals to 1 and no consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=`
}]);
});
it('should return appropriate URL with GDPR equals to 1, GDPR consent and CCPA consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, {consentString: 'fooUsp'})).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&ccpa_consent=fooUsp`
}]);
Expand Down

0 comments on commit e1cb8f0

Please sign in to comment.