Skip to content

Commit

Permalink
Zeta Ssp Bid Adapter: Improve user sync logic (prebid#6835)
Browse files Browse the repository at this point in the history
  • Loading branch information
asurovenko-zeta authored and stsepelin committed May 28, 2021
1 parent fa8eb28 commit 44a493c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
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=');
});
});

0 comments on commit 44a493c

Please sign in to comment.