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

Conversant Bid Adapter: add getUserSync #7185

Merged
merged 2 commits into from
Aug 14, 2021
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
46 changes: 44 additions & 2 deletions modules/conversantBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getStorageManager} from '../src/storageManager.js';

const GVLID = 24;
export const storage = getStorageManager(GVLID);
Expand Down Expand Up @@ -248,6 +248,48 @@ export const spec = {
'secure': 'number',
'mobile': 'number'
}, params);
},

/**
* Register User Sync.
*/
getUserSyncs: function(syncOptions, responses, gdprConsent, uspConsent) {
let params = {};
const syncs = [];

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

// CCPA
if (uspConsent) {
params.us_privacy = encodeURIComponent(uspConsent);
}

if (responses && responses.ext) {
const pixels = [{urls: responses.ext.fsyncs, type: 'iframe'}, {urls: responses.ext.psyncs, type: 'image'}]
.filter((entry) => {
return entry.urls &&
((entry.type === 'iframe' && syncOptions.iframeEnabled) ||
(entry.type === 'image' && syncOptions.pixelEnabled));
})
.map((entry) => {
return entry.urls.map((endpoint) => {
let urlInfo = utils.parseUrl(endpoint);
utils.mergeDeep(urlInfo.search, params);
if (Object.keys(urlInfo.search).length === 0) {
delete urlInfo.search; // empty search object causes buildUrl to add a trailing ? to the url
}
return {type: entry.type, url: utils.buildUrl(urlInfo)};
})
.reduce((x, y) => x.concat(y), []);
})
.reduce((x, y) => x.concat(y), []);
syncs.push(...pixels);
}
return syncs;
}
};

Expand Down
58 changes: 57 additions & 1 deletion test/spec/modules/conversantBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {expect} from 'chai';
import {spec, storage} from 'modules/conversantBidAdapter.js';
import * as utils from 'src/utils.js';
import { createEidsArray } from 'modules/userId/eids.js';
import {createEidsArray} from 'modules/userId/eids.js';

describe('Conversant adapter tests', function() {
const siteId = '108060';
Expand Down Expand Up @@ -661,4 +661,60 @@ describe('Conversant adapter tests', function() {
expect(payload.imp[0]).to.have.property('bidfloor', 0);
});
});

describe('getUserSyncs', function() {
const syncurl_iframe = 'https://sync.dotomi.com:8080/iframe';
const syncurl_image = 'https://sync.dotomi.com:8080/pixel';
const cnvrResponse = {ext: {psyncs: [syncurl_image], fsyncs: [syncurl_iframe]}};
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
});

it('empty params', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined))
.to.deep.equal([]);
expect(spec.getUserSyncs({ iframeEnabled: true }, {ext: {}}, undefined, undefined))
.to.deep.equal([]);
expect(spec.getUserSyncs({ iframeEnabled: true }, cnvrResponse, undefined, undefined))
.to.deep.equal([{ type: 'iframe', url: syncurl_iframe }]);
expect(spec.getUserSyncs({ pixelEnabled: true }, cnvrResponse, undefined, undefined))
.to.deep.equal([{ type: 'image', url: syncurl_image }]);
expect(spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, cnvrResponse, undefined, undefined))
.to.deep.equal([{type: 'iframe', url: syncurl_iframe}, {type: 'image', url: syncurl_image}]);
});

it('URL building', function() {
expect(spec.getUserSyncs({pixelEnabled: true}, {ext: {psyncs: [`${syncurl_image}?sid=1234`]}}, undefined, undefined))
.to.deep.equal([{type: 'image', url: `${syncurl_image}?sid=1234`}]);
expect(spec.getUserSyncs({pixelEnabled: true}, {ext: {psyncs: [`${syncurl_image}?sid=1234`]}}, undefined, '1NYN'))
.to.deep.equal([{type: 'image', url: `${syncurl_image}?sid=1234&us_privacy=1NYN`}]);
});

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

expect(spec.getUserSyncs({ pixelEnabled: true }, cnvrResponse, {gdprApplies: true, consentString: 'consentstring'}, undefined))
.to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=1&gdpr_consent=consentstring` }]);
expect(spec.getUserSyncs({ pixelEnabled: true }, cnvrResponse, {gdprApplies: false, consentString: 'consentstring'}, undefined))
.to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=0&gdpr_consent=consentstring` }]);
expect(spec.getUserSyncs({ pixelEnabled: true }, cnvrResponse, {gdprApplies: true, consentString: undefined}, undefined))
.to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=1&gdpr_consent=` }]);
});

it('US_Privacy', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, cnvrResponse, undefined, '1NYN'))
.to.deep.equal([{ type: 'iframe', url: `${syncurl_iframe}?us_privacy=1NYN` }]);
expect(spec.getUserSyncs({ pixelEnabled: true }, cnvrResponse, undefined, '1NYN'))
.to.deep.equal([{ type: 'image', url: `${syncurl_image}?us_privacy=1NYN` }]);
});
});
});