Skip to content

Commit

Permalink
Merge pull request #2 from kubient/kubient_ccpa
Browse files Browse the repository at this point in the history
add uspConsent to sunc URL
  • Loading branch information
Marsel authored Dec 13, 2021
2 parents 08695ba + 3511dcc commit 3810334
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 64 deletions.
26 changes: 15 additions & 11 deletions modules/kubientBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isArray, deepAccess } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import URLSearchParams from 'core-js-pure/web/url-search-params';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'kubient';
const END_POINT = 'https://kssp.kbntx.ch/kubprebidjs';
Expand Down Expand Up @@ -59,7 +61,11 @@ export const spec = {
gdpr: (bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies) ? 1 : 0,
consentGiven: kubientGetConsentGiven(bidderRequest.gdprConsent),
uspConsent: bidderRequest.uspConsent
};
}

if (config.getConfig('coppa') === true) {
data.coppa = 1
}

if (bidderRequest.refererInfo && bidderRequest.refererInfo.referer) {
data.referer = bidderRequest.refererInfo.referer
Expand Down Expand Up @@ -110,24 +116,22 @@ export const spec = {
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
let gdprParams = '';
let values = new URLSearchParams();

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
gdprParams = `?consent_str=${gdprConsent.consentString}`;
values.append('consent', gdprConsent.consentString);
if (typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = gdprParams + `&gdpr=${Number(gdprConsent.gdprApplies)}`;
values.append('gdpr', Number(gdprConsent.gdprApplies));
}
gdprParams = gdprParams + `&consent_given=` + kubientGetConsentGiven(gdprConsent);
}
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://kdmp.kbntx.ch/init.html' + gdprParams
});
if (uspConsent) {
values.append('usp', uspConsent);
}

if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: 'https://kdmp.kbntx.ch/init.png' + gdprParams
url: 'https://matching.kubient.net/match/sp?' + values.toString()
});
}
return syncs;
Expand Down
171 changes: 118 additions & 53 deletions test/spec/modules/kubientBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect, assert } from 'chai';
import { spec } from 'modules/kubientBidAdapter.js';
import { BANNER, VIDEO } from '../../../src/mediaTypes.js';
import URLSearchParams from 'core-js-pure/web/url-search-params';
import {config} from '../../../src/config';

describe('KubientAdapter', function () {
let bidBanner = {
Expand Down Expand Up @@ -175,6 +177,94 @@ describe('KubientAdapter', function () {
});
}
});
describe('buildRequestBanner', function () {
config.setConfig({coppa: true});
let serverRequests = spec.buildRequests([bidBanner], Object.assign({}, bidderRequest, {bids: [bidBanner]}));
config.resetConfig();
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequests).to.be.an('array');
});
for (let i = 0; i < serverRequests.length; i++) {
let serverRequest = serverRequests[i];
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequest.method).to.be.a('string');
expect(serverRequest.url).to.be.a('string');
expect(serverRequest.data).to.be.a('string');
});
it('Returns POST method', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs');
});
it('Returns valid data if array of bids is valid', function () {
let data = JSON.parse(serverRequest.data);
expect(data).to.be.an('object');
expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent');
expect(data.v).to.exist.and.to.be.a('string');
expect(data.requestId).to.exist.and.to.be.a('string');
expect(data.coppa).to.be.a('number').and.to.equal(1);
expect(data.referer).to.be.a('string');
expect(data.tmax).to.exist.and.to.be.a('number');
expect(data.gdpr).to.exist.and.to.be.within(0, 1);
expect(data.consent).to.equal(consentString);
expect(data.uspConsent).to.exist.and.to.equal(uspConsentData);
for (let j = 0; j < data['adSlots'].length; j++) {
let adSlot = data['adSlots'][i];
expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'banner', 'schain');
expect(adSlot.bidId).to.be.a('string').and.to.equal(bidBanner.bidId);
expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidBanner.params.zoneid);
expect(adSlot.floor).to.be.a('number');
expect(adSlot.schain).to.be.an('object');
expect(adSlot.banner).to.be.an('object');
}
});
}
});
describe('buildRequestVideo', function () {
config.setConfig({coppa: true});
let serverRequests = spec.buildRequests([bidVideo], Object.assign({}, bidderRequest, {bids: [bidVideo]}));
config.resetConfig();
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequests).to.be.an('array');
});
for (let i = 0; i < serverRequests.length; i++) {
let serverRequest = serverRequests[i];
it('Creates a ServerRequest object with method, URL and data', function () {
expect(serverRequest.method).to.be.a('string');
expect(serverRequest.url).to.be.a('string');
expect(serverRequest.data).to.be.a('string');
});
it('Returns POST method', function () {
expect(serverRequest.method).to.equal('POST');
});
it('Returns valid URL', function () {
expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs');
});
it('Returns valid data if array of bids is valid', function () {
let data = JSON.parse(serverRequest.data);
expect(data).to.be.an('object');
expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent');
expect(data.v).to.exist.and.to.be.a('string');
expect(data.requestId).to.exist.and.to.be.a('string');
expect(data.coppa).to.be.a('number').and.to.equal(1);
expect(data.referer).to.be.a('string');
expect(data.tmax).to.exist.and.to.be.a('number');
expect(data.gdpr).to.exist.and.to.be.within(0, 1);
expect(data.consent).to.equal(consentString);
expect(data.uspConsent).to.exist.and.to.equal(uspConsentData);
for (let j = 0; j < data['adSlots'].length; j++) {
let adSlot = data['adSlots'][i];
expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'video', 'schain');
expect(adSlot.bidId).to.be.a('string').and.to.equal(bidVideo.bidId);
expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidVideo.params.zoneid);
expect(adSlot.floor).to.be.a('number');
expect(adSlot.schain).to.be.an('object');
expect(adSlot.video).to.be.an('object');
}
});
}
});

describe('isBidRequestValid', function () {
it('Should return true when required params are found', function () {
Expand Down Expand Up @@ -293,89 +383,45 @@ describe('KubientAdapter', function () {
});

describe('getUserSyncs', function () {
it('should register the sync iframe without gdpr', function () {
let syncOptions = {
iframeEnabled: true
};
let serverResponses = null;
let gdprConsent = {
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.html?consent_str=' + consentString + '&consent_given=0');
});
it('should register the sync iframe with gdpr', function () {
let syncOptions = {
iframeEnabled: true
};
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.html?consent_str=' + consentString + '&gdpr=1&consent_given=0');
});
it('should register the sync iframe with gdpr vendor', function () {
let syncOptions = {
iframeEnabled: true
};
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
consentString: consentString,
apiVersion: 1,
vendorData: {
vendorConsents: {
794: 1
}
}
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('iframe');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.html?consent_str=' + consentString + '&gdpr=1&consent_given=1');
});
it('should register the sync image without gdpr', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.png?consent_str=' + consentString + '&consent_given=0');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image with gdpr', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
consentString: consentString
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('gdpr', 1);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.png?consent_str=' + consentString + '&gdpr=1&consent_given=0');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image with gdpr vendor', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
gdprApplies: true,
Expand All @@ -391,9 +437,28 @@ describe('KubientAdapter', function () {
};
let uspConsent = null;
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('gdpr', 1);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
it('should register the sync image without gdpr and with uspConsent', function () {
let syncOptions = {
pixelEnabled: true
};
let values = new URLSearchParams();
let serverResponses = null;
let gdprConsent = {
consentString: consentString
};
let uspConsent = '1YNN';
let syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent);
values.append('consent', consentString);
values.append('usp', uspConsent);
expect(syncs).to.be.an('array').and.to.have.length(1);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://kdmp.kbntx.ch/init.png?consent_str=' + consentString + '&gdpr=1&consent_given=1');
expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + values.toString());
});
})
});

0 comments on commit 3810334

Please sign in to comment.