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

Zeta Ssp Bid Adapter: Improve user sync logic #6835

Merged
merged 8 commits into from
May 27, 2021
Merged
46 changes: 31 additions & 15 deletions modules/zetaSspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {config} from '../src/config.js';

const BIDDER_CODE = 'zeta_global_ssp';
const ENDPOINT_URL = 'https://ssp.disqus.com/bid';
const USER_SYNC_URL = 'https://ssp.disqus.com/match';
const USER_SYNC_URL_IFRAME = 'https://ssp.disqus.com/sync?type=iframe';
const USER_SYNC_URL_IMAGE = 'https://ssp.disqus.com/sync?type=image';
const DEFAULT_CUR = 'USD';
const TTL = 200;
const NET_REV = true;
Expand Down Expand Up @@ -58,7 +59,7 @@ export const spec = {
app: params.app ? params.app : {},
ext: {
tags: params.tags ? params.tags : {},
sid: params.sid ? params.sid : {}
sid: params.sid ? params.sid : undefined
}
};

Expand Down Expand Up @@ -123,23 +124,38 @@ export const spec = {
},

/**
* Register the user sync pixels which should be dropped after the auction.
*
* @param {SyncOptions} syncOptions Which user syncs are allowed?
* @param {ServerResponse[]} serverResponses List of server's responses.
* @param gdprConsent The GDPR consent parameters
* @param uspConsent The USP consent parameters
* @return {UserSync[]} The user syncs which should be dropped.
* Register User Sync.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => {
let syncurl = '';

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

// CCPA
if (uspConsent) {
syncurl += '&us_privacy=' + encodeURIComponent(uspConsent);
}

// coppa compliance
if (config.getConfig('coppa') === true) {
syncurl += '&coppa=1';
}

if (syncOptions.iframeEnabled) {
syncs.push({
return [{
type: 'iframe',
url: USER_SYNC_URL
});
url: USER_SYNC_URL_IFRAME + syncurl
}];
} else {
return [{
type: 'image',
url: USER_SYNC_URL_IMAGE + syncurl
}];
}
return syncs;
}
}

Expand Down
30 changes: 27 additions & 3 deletions test/spec/modules/zetaSspBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { spec } from '../../../modules/zetaSspBidAdapter.js'
import {spec} from '../../../modules/zetaSspBidAdapter.js'

describe('Zeta Ssp Bid Adapter', function() {
describe('Zeta Ssp Bid Adapter', function () {
const bannerRequest = [{
bidId: 12345,
auctionId: 67890,
Expand All @@ -26,7 +26,7 @@ describe('Zeta Ssp Bid Adapter', function() {
}
}];

it('Test the bid validation function', function() {
it('Test the bid validation function', function () {
const validBid = spec.isBidRequestValid(bannerRequest[0]);
const invalidBid = spec.isBidRequestValid(null);

Expand Down Expand Up @@ -82,4 +82,28 @@ describe('Zeta Ssp Bid Adapter', function() {
expect(bid.requestId).to.equal(receivedBid.impid);
expect(bid.meta.advertiserDomains).to.equal(receivedBid.adomain);
});

it('Different cases for user syncs', function () {
const USER_SYNC_URL_IFRAME = 'https://ssp.disqus.com/sync?type=iframe';
const USER_SYNC_URL_IMAGE = 'https://ssp.disqus.com/sync?type=image';

const sync1 = spec.getUserSyncs({iframeEnabled: true})[0];
expect(sync1.type).to.equal('iframe');
expect(sync1.url).to.include(USER_SYNC_URL_IFRAME);

const sync2 = spec.getUserSyncs({iframeEnabled: false})[0];
expect(sync2.type).to.equal('image');
expect(sync2.url).to.include(USER_SYNC_URL_IMAGE);

const sync3 = spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true})[0];
expect(sync3.type).to.equal('iframe');
expect(sync3.url).to.include(USER_SYNC_URL_IFRAME);
expect(sync3.url).to.include('&gdpr=');

const sync4 = spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true}, 'test')[0];
expect(sync4.type).to.equal('iframe');
expect(sync4.url).to.include(USER_SYNC_URL_IFRAME);
expect(sync4.url).to.include('&gdpr=');
expect(sync4.url).to.include('&us_privacy=');
});
});