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

Optidigital Bid Adapter : update getUserSync method (legacy) #10194

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 21 additions & 14 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 @@ -136,21 +137,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 +221,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