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 support for GDPR, COPPA, and USP #5210

Merged
merged 14 commits into from
May 21, 2020
Merged
33 changes: 29 additions & 4 deletions modules/cpmstarBidAdapter.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import {VIDEO, BANNER} from '../src/mediaTypes.js';
import { VIDEO, BANNER } from '../src/mediaTypes.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'cpmstar';

Expand All @@ -17,12 +18,12 @@ export const spec = {
supportedMediaTypes: [BANNER, VIDEO],
pageID: Math.floor(Math.random() * 10e6),

getMediaType: function(bidRequest) {
getMediaType: function (bidRequest) {
if (bidRequest == null) return BANNER;
return !utils.deepAccess(bidRequest, 'mediaTypes.video') ? BANNER : VIDEO;
},

getPlayerSize: function(bidRequest) {
getPlayerSize: function (bidRequest) {
var playerSize = utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize');
if (playerSize == null) return [640, 440];
if (playerSize[0] != null) playerSize = playerSize[0];
Expand All @@ -46,9 +47,33 @@ export const spec = {
var mediaType = spec.getMediaType(bidRequest);
var playerSize = spec.getPlayerSize(bidRequest);
var videoArgs = '&fv=0' + (playerSize ? ('&w=' + playerSize[0] + '&h=' + playerSize[1]) : '');

var url = ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') +
'&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) +
'&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) +
'&requestid=' + bidRequest.bidId +
'&referer=' + encodeURIComponent(referer);

if (bidderRequest.gdprConsent) {
if (bidderRequest.gdprConsent.consentString != null) {
url += '&gdpr_consent=' + bidderRequest.gdprConsent.consentString;
}
if (bidderRequest.gdprConsent.gdprApplies != null) {
url += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0);
}
}

if (bidderRequest.uspConsent != null) {
url += '&us_privacy=' + bidderRequest.uspConsent;
}

if (config.getConfig('coppa')) {
url += '&tfcd=' + (config.getConfig('coppa') ? 1 : 0);
}

requests.push({
method: 'GET',
url: ENDPOINT + '?media=' + mediaType + (mediaType == VIDEO ? videoArgs : '') + '&json=c_b&mv=1&poolid=' + utils.getBidIdParameter('placementId', bidRequest.params) + '&reachedTop=' + encodeURIComponent(bidderRequest.refererInfo.reachedTop) + '&requestid=' + bidRequest.bidId + '&referer=' + referer,
url: url,
bidRequest: bidRequest,
});
}
Expand Down
3 changes: 3 additions & 0 deletions modules/cpmstarBidAdapter.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
Module Name: Cpmstar Bidder Adapter
Module Type: Bidder Adapter
Maintainer: josh@cpmstar.com
gdpr_supported: true
usp_supported: true
coppa_supported: true
```

# Description
Expand Down
50 changes: 40 additions & 10 deletions test/spec/modules/cpmstarBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { spec } from 'modules/cpmstarBidAdapter.js';
import { deepClone } from 'src/utils.js';
import { config } from 'src/config.js';

describe('Cpmstar Bid Adapter', function () {
describe('isBidRequestValid', function () {
Expand All @@ -15,22 +16,26 @@ describe('Cpmstar Bid Adapter', function () {
expect(spec.isBidRequestValid(bid)).to.equal(false);
})

it('should return a valid player size', function() {
var bid = { mediaTypes: {
video: {
playerSize: [[960, 540]]
it('should return a valid player size', function () {
var bid = {
mediaTypes: {
video: {
playerSize: [[960, 540]]
}
}
}}
}
expect(spec.getPlayerSize(bid)[0]).to.equal(960);
expect(spec.getPlayerSize(bid)[1]).to.equal(540);
})

it('should return a default player size', function() {
var bid = { mediaTypes: {
video: {
playerSize: null
it('should return a default player size', function () {
var bid = {
mediaTypes: {
video: {
playerSize: null
}
}
}}
}
expect(spec.getPlayerSize(bid)[0]).to.equal(640);
expect(spec.getPlayerSize(bid)[1]).to.equal(440);
})
Expand Down Expand Up @@ -79,6 +84,31 @@ describe('Cpmstar Bid Adapter', function () {
expect(requests[0]).to.have.property('bidRequest');
expect(requests[0].url).to.include('https://dev.server.cpmstar.com/view.aspx');
});
it('should produce a request with support for GDPR', function () {
var gdpr_bidderRequest = deepClone(bidderRequest);
gdpr_bidderRequest.gdprConsent = {
consentString: 'consentString',
gdprApplies: true
};
var requests = spec.buildRequests(valid_bid_requests, gdpr_bidderRequest);
expect(requests[0]).to.have.property('url');
expect(requests[0].url).to.include('gdpr_consent=consentString');
expect(requests[0].url).to.include('gdpr=1');
});
it('should produce a request with support for USP', function () {
var usp_bidderRequest = deepClone(bidderRequest);
usp_bidderRequest.uspConsent = '1YYY';
var requests = spec.buildRequests(valid_bid_requests, usp_bidderRequest);
expect(requests[0]).to.have.property('url');
expect(requests[0].url).to.include('us_privacy=1YYY');
});
it('should produce a request with support for COPPA', function () {
sinon.stub(config, 'getConfig').withArgs('coppa').returns(true);
var requests = spec.buildRequests(valid_bid_requests, bidderRequest);
config.getConfig.restore();
expect(requests[0]).to.have.property('url');
expect(requests[0].url).to.include('tfcd=1');
});
})

describe('interpretResponse', function () {
Expand Down