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

Added user sync support into adapter #5934

Merged
merged 16 commits into from
Nov 12, 2020
34 changes: 30 additions & 4 deletions modules/lemmaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js';
var BIDDER_CODE = 'lemma';
var LOG_WARN_PREFIX = 'LEMMA: ';
var ENDPOINT = 'https://ads.lemmatechnologies.com/lemma/servad';
var USER_SYNC = 'https://sync.lemmatechnologies.com/js/usersync.html?';
var DEFAULT_CURRENCY = 'USD';
var AUCTION_TYPE = 2;
var DEFAULT_TMAX = 300;
var DEFAULT_NET_REVENUE = false;
var pubId = 0;
var adunitId = 0;

export var spec = {

Expand Down Expand Up @@ -57,6 +60,29 @@ export var spec = {
interpretResponse: (response, request) => {
return parseRTBResponse(request, response.body);
},
getUserSyncs: (syncOptions, responses, gdprConsent, uspConsent) => {
let syncurl = USER_SYNC + 'pid=' + pubId;

// 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);
}

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: syncurl
}];
} else {
utils.logWarn(LOG_WARN_PREFIX + 'Please enable iframe based user sync.');
}
},
};

function _initConf(refererInfo) {
Expand Down Expand Up @@ -167,8 +193,8 @@ function _getImpressionArray(request) {
function endPointURL(request) {
var params = request && request[0].params ? request[0].params : null;
if (params) {
var pubId = params.pubId ? params.pubId : 0;
var adunitId = params.adunitId ? params.adunitId : 0;
pubId = params.pubId ? params.pubId : 0;
adunitId = params.adunitId ? params.adunitId : 0;
return ENDPOINT + '?pid=' + pubId + '&aid=' + adunitId;
}
return null;
Expand All @@ -183,7 +209,7 @@ function _getDomain(url) {
function _getSiteObject(request, conf) {
var params = request && request.params ? request.params : null;
if (params) {
var pubId = params.pubId ? params.pubId : '0';
pubId = params.pubId ? params.pubId : '0';
var siteId = params.siteId ? params.siteId : '0';
var appParams = params.app;
if (!appParams) {
Expand All @@ -204,7 +230,7 @@ function _getSiteObject(request, conf) {
function _getAppObject(request) {
var params = request && request.params ? request.params : null;
if (params) {
var pubId = params.pubId ? params.pubId : 0;
pubId = params.pubId ? params.pubId : 0;
var appParams = params.app;
if (appParams) {
return {
Expand Down
34 changes: 34 additions & 0 deletions test/spec/modules/lemmaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,39 @@ describe('lemmaBidAdapter', function() {
});
});
});
describe('getUserSyncs', function() {
const syncurl_iframe = 'https://sync.lemmatechnologies.com/js/usersync.html?pid=1001';
let sandbox;
beforeEach(function() {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
});

it('execute as per config', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: syncurl_iframe
}]);
});

it('CCPA/USP', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&us_privacy=1NYN`
}]);
});

it('GDPR', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: 'foo' }, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false, consentString: 'foo' }, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=0&gdpr_consent=foo`
}]);
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: undefined }, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=`
}]);
});
});
});
});