Skip to content

Commit

Permalink
Widespace GDPR consent management (prebid#2638)
Browse files Browse the repository at this point in the history
* GDPR consent sent to server

* Test coverage increased

* New adapter version and boolean param values 0|1 instead of true|false

* Making sure we dont send param to server if its undefined
  • Loading branch information
mizmaar3 authored and AdSpacesDevelopers committed Jan 30, 2019
1 parent 94fcd92 commit 9b7bf76
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions modules/widespaceBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import includes from 'core-js/library/fn/array/includes';
import find from 'core-js/library/fn/array/find';

const BIDDER_CODE = 'widespace';
const WS_ADAPTER_VERSION = '2.0.0';
const WS_ADAPTER_VERSION = '2.0.1';
const LOCAL_STORAGE_AVAILABLE = window.localStorage;
const COOKIE_ENABLED = cookiesAreEnabled();
const LS_KEYS = {
Expand All @@ -34,7 +34,7 @@ export const spec = {
return false;
},

buildRequests: function(validBidRequests) {
buildRequests: function(validBidRequests, bidderRequest) {
let serverRequests = [];
const REQUEST_SERVER_URL = getEngineUrl();
const DEMO_DATA_PARAMS = ['gender', 'country', 'region', 'postal', 'city', 'yob'];
Expand All @@ -60,6 +60,7 @@ export const spec = {
'sid': bid.params.sid,
'lcuid': LC_UID,
'vol': isInHostileIframe ? '' : visibleOnLoad(document.getElementById(bid.adUnitCode)),
'gdprCmp': bidderRequest && bidderRequest.gdprConsent ? 1 : 0,
'hb': '1',
'hb.cd': CUST_DATA ? encodedParamValue(CUST_DATA) : '',
'hb.floor': bid.bidfloor || '',
Expand Down Expand Up @@ -102,6 +103,15 @@ export const spec = {
data.forceAdId = DEBUG_AD;
}

// GDPR Consent info
if (data.gdprCmp) {
const { gdprApplies, consentString, vendorData } = bidderRequest.gdprConsent;
const hasGlobalScope = vendorData && vendorData.hasGlobalScope;
data.gdprApplies = gdprApplies ? 1 : gdprApplies === undefined ? '' : 0;
data.gdprConsentData = consentString;
data.gdprHasGlobalScope = hasGlobalScope ? 1 : hasGlobalScope === undefined ? '' : 0;
}

// Remove empty params
Object.keys(data).forEach((key) => {
if (data[key] === '' || data[key] === undefined) {
Expand Down
18 changes: 17 additions & 1 deletion test/spec/modules/widespaceBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ describe('+widespaceAdatperTest', () => {
'transactionId': '4f68b713-04ba-4d7f-8df9-643bcdab5efv'
}];

// Dummy bidderRequest object
const bidderRequest = {
auctionId: 'bf1e57ee-fff2-4304-8143-91aaf423a944',
auctionStart: 1527418994278,
bidderCode: 'widespace',
bidderRequestId: '37a5f053efef34',
timeout: 3000,
gdprConsent: {
consentString: 'consentString',
gdprApplies: true,
vendorData: {
hasGlobalScope: false
}
}
};

// Dummy bid response with ad code
const bidResponse = {
body: [{
Expand Down Expand Up @@ -125,7 +141,7 @@ describe('+widespaceAdatperTest', () => {
});

describe('+bidRequest', () => {
const request = spec.buildRequests(bidRequest);
const request = spec.buildRequests(bidRequest, bidderRequest);
const UrlRegExp = /^((ftp|http|https):)?\/\/[^ "]+$/;

it('-bidRequest method is POST', () => {
Expand Down

0 comments on commit 9b7bf76

Please sign in to comment.