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

Adyoulike Bid Adapter : support getUserSyncs #10319

Merged
merged 1 commit into from
Sep 20, 2023
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
45 changes: 45 additions & 0 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {buildUrl, deepAccess, parseSizesInput} from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import {find} from '../src/polyfill.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
Expand Down Expand Up @@ -166,6 +167,50 @@ export const spec = {
}
});
return bidResponses;
},

/**
* List user sync endpoints.
* Legal information have to be added to the request.
* Only iframe syncs are supported.
*
* @param {*} syncOptions Publisher prebid configuration.
* @param {*} serverResponses A successful response from the server.
* @return {syncs[]} An array of syncs that should be executed.
*/
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
if (!syncOptions.iframeEnabled) {
return [];
}

let params = '';

// GDPR
if (gdprConsent) {
params += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
params += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}

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

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

// GPP
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
params += '&gpp=' + encodeURIComponent(gppConsent.gppString);
params += '&gpp_sid=' + encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

return [{
type: 'iframe',
url: `https://visitor.omnitagjs.com/visitor/isync?uid=19340f4f097d16f41f34fc0274981ca4${params}`
}];
}
}

Expand Down
112 changes: 112 additions & 0 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';

import { spec } from 'modules/adyoulikeBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { config } from 'src/config.js';

describe('Adyoulike Adapter', function () {
const canonicalUrl = 'https://canonical.url/?t=%26';
Expand Down Expand Up @@ -887,4 +888,115 @@ describe('Adyoulike Adapter', function () {
expect(spec.gvlid).to.equal(259)
})
});

describe('getUserSyncs', function () {
const syncurl_iframe = 'https://visitor.omnitagjs.com/visitor/isync?uid=19340f4f097d16f41f34fc0274981ca4';

const emptySync = [];

describe('with iframe enabled', function() {
const userSyncConfig = { iframeEnabled: true };

it('should not add parameters if not provided', function() {
expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should add GDPR parameters if provided', function() {
expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=`
}]);

expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: 'foo?'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=foo%3F`
}]);
expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: false, consentString: 'bar'}, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gdpr=0&gdpr_consent=bar`
}]);
});

it('should add CCPA parameters if provided', function() {
expect(spec.getUserSyncs(userSyncConfig, {}, undefined, 'foo?')).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&us_privacy=foo%3F`
}]);
});

describe('COPPA', function() {
let sandbox;

this.beforeEach(function() {
sandbox = sinon.sandbox.create();
});

this.afterEach(function() {
sandbox.restore();
});

it('should add coppa parameters if provided', function() {
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
'coppa': true
};
return config[key];
});

expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&coppa=1`
}]);
});
});

describe('GPP', function() {
it('should not apply if not gppConsent.gppString', function() {
const gppConsent = { gppString: '', applicableSections: [123] };
const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should not apply if not gppConsent.applicableSections', function() {
const gppConsent = { gppString: '', applicableSections: undefined };
const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should not apply if empty gppConsent.applicableSections', function() {
const gppConsent = { gppString: '', applicableSections: [] };
const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}`
}]);
});

it('should apply if all above are available', function() {
const gppConsent = { gppString: 'foo?', applicableSections: [123] };
const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gpp=foo%3F&gpp_sid=123`
}]);
});

it('should support multiple sections', function() {
const gppConsent = { gppString: 'foo', applicableSections: [123, 456] };
const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent);
expect(result).to.deep.equal([{
type: 'iframe', url: `${syncurl_iframe}&gpp=foo&gpp_sid=123%2C456`
}]);
});
});
});

describe('with iframe disabled', function() {
const userSyncConfig = { iframeEnabled: false };

it('should return empty list of syncs', function() {
expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal(emptySync);
expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: 'foo'}, 'bar')).to.deep.equal(emptySync);
});
});
});
});