Skip to content

Commit

Permalink
Lemma bid adapter: Add user sync support (#5934)
Browse files Browse the repository at this point in the history
* lemmaBidAdapter.js

Added lemma bid adapter file

* lemmaBidAdapter.md

Added lemma bid adapter md file

* lemmaBidAdapter_spec.js

Added lemma bid adapter test spec file

* Update lemmaBidAdapter.js

Fixed automated code review alert comparison between inconvertible types

* Update lemmaBidAdapter.js

Fixed review changes

* Update lemmaBidAdapter.md

Correct parameter value.

* Update lemmaBidAdapter.js

Lemma Bid Adapter - v3.0 compliance

* Update lemmaBidAdapter_spec.js

Lemma Bid Adapter - v3.0 compliance

* Update lemmaBidAdapter.md

Lemma Bid Adapter - v3.0 compliance

* Update lemmaBidAdapter.js

Added user sync support into bid adapter.

* updated include modules file extension.

updated include modules js file extension.

* Update lemmaBidAdapter_spec.js

Added unit test for user sync feature.

* Update lemmaBidAdapter.js

Fixed format error.

* Update lemmaBidAdapter_spec.js

Fixed format error and typo error.
  • Loading branch information
lm-abhijit authored Nov 12, 2020
1 parent 7d97720 commit 2b0bd53
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
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=`
}]);
});
});
});
});

0 comments on commit 2b0bd53

Please sign in to comment.