Skip to content

Commit

Permalink
Kubient Bid Adapter: support coppa, update sync URL (#7855)
Browse files Browse the repository at this point in the history
* add uspConsent to sunc URL

* kubient: add coppa

* added test for coppa

* fix-test

* replace kdmp.kbntx.ch by matching.kubient.net
remove iframe pixel support
rename us_privacy -> usp
rename consent_str -> consent
use URLSearchParams for GET params

* fix-test-and-code

* removed URLSearchParams

* early exit for getUserSyncs, updated test

* test-back

* test-filter-settings

* test-filter-settings

* test-filter-settings

* test-filter-settings

* fix for review

* fix for review

* fix test for ci passing

* fix 2 for ci passing

* refactored-test-for-ci

* fix-for-review

* fix

* fix

Co-authored-by: Artem Aleksashkin <[email protected]>
Co-authored-by: Artem Aleksashkin <[email protected]>
  • Loading branch information
3 people authored Feb 8, 2022
1 parent c1b9590 commit 12f675d
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 103 deletions.
69 changes: 50 additions & 19 deletions modules/kubientBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isArray, deepAccess } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
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 +60,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 @@ -109,31 +114,39 @@ export const spec = {
return bidResponses;
},
getUserSyncs: function (syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];
let gdprParams = '';
if (gdprConsent && typeof gdprConsent.consentString === 'string') {
gdprParams = `?consent_str=${gdprConsent.consentString}`;
let kubientSync = kubientGetSyncInclude(config);

if (!syncOptions.pixelEnabled || kubientSync.image === 'exclude') {
return [];
}

let values = {};
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = gdprParams + `&gdpr=${Number(gdprConsent.gdprApplies)}`;
values['gdpr'] = Number(gdprConsent.gdprApplies);
}
if (typeof gdprConsent.consentString === 'string') {
values['consent'] = gdprConsent.consentString;
}
gdprParams = gdprParams + `&consent_given=` + kubientGetConsentGiven(gdprConsent);
}
if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: 'https://kdmp.kbntx.ch/init.html' + gdprParams
});
}
if (syncOptions.pixelEnabled) {
syncs.push({
type: 'image',
url: 'https://kdmp.kbntx.ch/init.png' + gdprParams
});

if (uspConsent) {
values['usp'] = uspConsent;
}
return syncs;

return [{
type: 'image',
url: 'https://matching.kubient.net/match/sp?' + encodeQueryData(values)
}];
}
};

function encodeQueryData(data) {
return Object.keys(data).map(function(key) {
return [key, data[key]].map(encodeURIComponent).join('=');
}).join('&');
}

function kubientGetConsentGiven(gdprConsent) {
let consentGiven = 0;
if (typeof gdprConsent !== 'undefined') {
Expand All @@ -149,4 +162,22 @@ function kubientGetConsentGiven(gdprConsent) {
}
return consentGiven;
}

function kubientGetSyncInclude(config) {
try {
let kubientSync = {};
if (config.getConfig('userSync').filterSettings != null && typeof config.getConfig('userSync').filterSettings != 'undefined') {
let filterSettings = config.getConfig('userSync').filterSettings
if (filterSettings.iframe !== null && typeof filterSettings.iframe !== 'undefined') {
kubientSync.iframe = ((isArray(filterSettings.image.bidders) && filterSettings.iframe.bidders.indexOf('kubient') !== -1) || filterSettings.iframe.bidders === '*') ? filterSettings.iframe.filter : 'exclude';
}
if (filterSettings.image !== null && typeof filterSettings.image !== 'undefined') {
kubientSync.image = ((isArray(filterSettings.image.bidders) && filterSettings.image.bidders.indexOf('kubient') !== -1) || filterSettings.image.bidders === '*') ? filterSettings.image.filter : 'exclude';
}
}
return kubientSync;
} catch (e) {
return null;
}
}
registerBidder(spec);
Loading

0 comments on commit 12f675d

Please sign in to comment.