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

Added GDPR consent management to UnderdogMedia Bid Adapter #2679

Merged
merged 4 commits into from
Jun 5, 2018
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
43 changes: 34 additions & 9 deletions modules/underdogmediaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import * as utils from 'src/utils';
import { config } from 'src/config';
import { registerBidder } from 'src/adapters/bidderFactory';
const BIDDER_CODE = 'underdogmedia';
const UDM_ADAPTER_VERSION = '1.0';
const UDM_ADAPTER_VERSION = '1.13V';
const UDM_VENDOR_ID = '159';

utils.logMessage(`Initializing UDM Adapter. PBJS Version: ${$$PREBID_GLOBAL$$.version} with adapter version: ${UDM_ADAPTER_VERSION} Updated 20180604`);

export const spec = {
code: BIDDER_CODE,
Expand All @@ -12,7 +15,7 @@ export const spec = {
return !!((bid.params && bid.params.siteId) && (bid.sizes && bid.sizes.length > 0));
},

buildRequests: function (validBidRequests) {
buildRequests: function (validBidRequests, bidderRequest) {
var sizes = [];
var siteId = 0;

Expand All @@ -21,12 +24,34 @@ export const spec = {
siteId = bidParam.params.siteId;
});

return {
method: 'GET',
url: `${window.location.protocol}//udmserve.net/udm/img.fetch`,
data: `tid=1;dt=10;sid=${siteId};sizes=${sizes.join(',')}`,
bidParams: validBidRequests
};
let data = {
tid: 1,
dt: 10,
sid: siteId,
sizes: sizes.join(',')
}

if (bidderRequest && bidderRequest.gdprConsent) {
if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') {
data.gdprApplies = !!(bidderRequest.gdprConsent.gdprApplies);
}
if (bidderRequest.gdprConsent.vendorData && bidderRequest.gdprConsent.vendorData.vendorConsents &&
typeof bidderRequest.gdprConsent.vendorData.vendorConsents[UDM_VENDOR_ID] !== 'undefined') {
data.consentGiven = !!(bidderRequest.gdprConsent.vendorData.vendorConsents[UDM_VENDOR_ID]);
}
if (typeof bidderRequest.gdprConsent.consentString !== 'undefined') {
data.consentData = bidderRequest.gdprConsent.consentString;
}
}

if (!data.gdprApplies || data.consentGiven) {
return {
method: 'GET',
url: `${window.location.protocol}//udmserve.net/udm/img.fetch`,
data: data,
bidParams: validBidRequests
};
}
},

interpretResponse: function (serverResponse, bidRequest) {
Expand Down Expand Up @@ -84,7 +109,7 @@ export const spec = {
},
};

function makeNotification (bid, mid, bidParam) {
function makeNotification(bid, mid, bidParam) {
var url = mid.notification_url;

url += UDM_ADAPTER_VERSION;
Expand Down
144 changes: 134 additions & 10 deletions test/spec/modules/underdogmediaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spec } from 'modules/underdogmediaBidAdapter';

describe('UnderdogMedia adapter', () => {
let bidRequests;
let bidderRequest;

beforeEach(() => {
bidRequests = [
Expand All @@ -19,6 +20,19 @@ describe('UnderdogMedia adapter', () => {
transactionId: '92489f71-1bf2-49a0-adf9-000cea934729'
}
];

bidderRequest = {
timeout: 3000,
gdprConsent: {
gdprApplies: 1,
consentString: 'consentDataString',
vendorData: {
vendorConsents: {
'159': 1
},
},
},
}
});

describe('implementation', () => {
Expand Down Expand Up @@ -72,9 +86,9 @@ describe('UnderdogMedia adapter', () => {
adUnitCode: '/123456/header-bid-tag-1'
}
];
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request.data).to.have.string('sid=12143');
expect(request.data.sid).to.equal('12143');
});

it('request data should contain sizes', () => {
Expand All @@ -90,9 +104,119 @@ describe('UnderdogMedia adapter', () => {
adUnitCode: '/123456/header-bid-tag-1'
}
];
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request.data.sizes).to.equal('300x250,728x90');
});

it('request data should contain gdpr info', () => {
let bidRequests = [
{
bidId: '3c9408cdbf2f68',
sizes: [[300, 250], [728, 90]],
bidder: 'underdogmedia',
params: {
siteId: '12143'
},
auctionId: '10b327aa396609',
adUnitCode: '/123456/header-bid-tag-1'
}
];
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request.data.gdprApplies).to.equal(true);
expect(request.data.consentGiven).to.equal(true);
expect(request.data.consentData).to.equal('consentDataString');
});

it('should not build a request if no vendorConsent', () => {
let bidRequests = [
{
bidId: '3c9408cdbf2f68',
sizes: [[300, 250], [728, 90]],
bidder: 'underdogmedia',
params: {
siteId: '12143'
},
auctionId: '10b327aa396609',
adUnitCode: '/123456/header-bid-tag-1'
}
];

let bidderRequest = {
timeout: 3000,
gdprConsent: {
gdprApplies: 1,
consentString: 'consentDataString',
vendorData: {
vendorConsents: {
'159': 0
},
},
},
}
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request).to.equal(undefined);
});

it('should properly build a request if no vendorConsent but no gdprApplies', () => {
let bidRequests = [
{
bidId: '3c9408cdbf2f68',
sizes: [[300, 250], [728, 90]],
bidder: 'underdogmedia',
params: {
siteId: '12143'
},
auctionId: '10b327aa396609',
adUnitCode: '/123456/header-bid-tag-1'
}
];

let bidderRequest = {
timeout: 3000,
gdprConsent: {
gdprApplies: 0,
consentString: 'consentDataString',
vendorData: {
vendorConsents: {
'159': 0
},
},
},
}
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request.data.sizes).to.equal('300x250,728x90');
expect(request.data.sid).to.equal('12143');
expect(request.data.gdprApplies).to.equal(false);
expect(request.data.consentGiven).to.equal(false);
expect(request.data.consentData).to.equal('consentDataString');
});

it('should properly build a request if gdprConsent empty', () => {
let bidRequests = [
{
bidId: '3c9408cdbf2f68',
sizes: [[300, 250], [728, 90]],
bidder: 'underdogmedia',
params: {
siteId: '12143'
},
auctionId: '10b327aa396609',
adUnitCode: '/123456/header-bid-tag-1'
}
];

let bidderRequest = {
timeout: 3000,
gdprConsent: {}
}
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request.data).to.have.string('sizes=300x250,728x90');
expect(request.data.sizes).to.equal('300x250,728x90');
expect(request.data.sid).to.equal('12143');
});
});

Expand Down Expand Up @@ -122,7 +246,7 @@ describe('UnderdogMedia adapter', () => {
]
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids).to.be.lengthOf(2);
Expand All @@ -142,7 +266,7 @@ describe('UnderdogMedia adapter', () => {
mids: []
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids).to.be.lengthOf(0);
Expand All @@ -164,7 +288,7 @@ describe('UnderdogMedia adapter', () => {
]
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids).to.be.lengthOf(0);
Expand All @@ -186,7 +310,7 @@ describe('UnderdogMedia adapter', () => {
]
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids).to.be.lengthOf(0);
Expand All @@ -208,7 +332,7 @@ describe('UnderdogMedia adapter', () => {
]
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids).to.be.lengthOf(0);
Expand All @@ -230,7 +354,7 @@ describe('UnderdogMedia adapter', () => {
]
}
};
const request = spec.buildRequests(bidRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);
const bids = spec.interpretResponse(serverResponse, request);

expect(bids[0].ad).to.have.string('notification_url');
Expand Down