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

ImproveDigital bid adapter GDPR support #2599

Merged
merged 1 commit into from
May 23, 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
38 changes: 19 additions & 19 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { userSync } from 'src/userSync';
const BIDDER_CODE = 'improvedigital';

export const spec = {
version: '4.1.0',
version: '4.2.0',
code: BIDDER_CODE,
aliases: ['id'],

Expand All @@ -26,19 +26,22 @@ export const spec = {
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (bidRequests) {
buildRequests: function (bidRequests, bidderRequest) {
let normalizedBids = bidRequests.map((bidRequest) => {
return getNormalizedBidRequest(bidRequest);
});

let idClient = new ImproveDigitalAdServerJSClient('hb');
let requestParameters = {
singleRequestMode: false,
httpRequestType: idClient.CONSTANTS.HTTP_REQUEST_TYPE.GET,
returnObjType: idClient.CONSTANTS.RETURN_OBJ_TYPE.PREBID,
returnObjType: idClient.CONSTANTS.RETURN_OBJ_TYPE.URL_PARAMS_SPLIT,
libVersion: this.version
};

if (bidderRequest && bidderRequest.gdprConsent && bidderRequest.gdprConsent.consentString) {
requestParameters.gdpr = bidderRequest.gdprConsent.consentString;
}

let requestObj = idClient.createRequest(
normalizedBids, // requestObject
requestParameters
Expand Down Expand Up @@ -154,27 +157,22 @@ registerBidder(spec);

function ImproveDigitalAdServerJSClient(endPoint) {
this.CONSTANTS = {
HTTP_REQUEST_TYPE: {
GET: 0,
POST: 1
},
HTTP_SECURITY: {
STANDARD: 0,
SECURE: 1
},
AD_SERVER_BASE_URL: 'ad.360yield.com',
END_POINT: endPoint || 'hb',
AD_SERVER_URL_PARAM: 'jsonp=',
CLIENT_VERSION: 'JS-4.3.3',
CLIENT_VERSION: 'JS-5.1',
MAX_URL_LENGTH: 2083,
ERROR_CODES: {
BAD_HTTP_REQUEST_TYPE_PARAM: 1,
MISSING_PLACEMENT_PARAMS: 2,
LIB_VERSION_MISSING: 3
},
RETURN_OBJ_TYPE: {
DEFAULT: 0,
PREBID: 1
URL_PARAMS_SPLIT: 1
}
};

Expand All @@ -187,9 +185,6 @@ function ImproveDigitalAdServerJSClient(endPoint) {
};

this.createRequest = function(requestObject, requestParameters, extraRequestParameters) {
if (requestParameters.httpRequestType !== this.CONSTANTS.HTTP_REQUEST_TYPE.GET) {
return this.getErrorReturn(this.CONSTANTS.ERROR_CODES.BAD_HTTP_REQUEST_TYPE_PARAM);
}
if (!requestParameters.libVersion) {
return this.getErrorReturn(this.CONSTANTS.ERROR_CODES.LIB_VERSION_MISSING);
}
Expand All @@ -198,9 +193,8 @@ function ImproveDigitalAdServerJSClient(endPoint) {

let impressionObjects = [];
let impressionObject;
let counter;
if (utils.isArray(requestObject)) {
for (counter = 0; counter < requestObject.length; counter++) {
for (let counter = 0; counter < requestObject.length; counter++) {
impressionObject = this.createImpressionObject(requestObject[counter]);
impressionObjects.push(impressionObject);
}
Expand All @@ -210,7 +204,7 @@ function ImproveDigitalAdServerJSClient(endPoint) {
}

let returnIdMappings = true;
if (requestParameters.returnObjType === this.CONSTANTS.RETURN_OBJ_TYPE.PREBID) {
if (requestParameters.returnObjType === this.CONSTANTS.RETURN_OBJ_TYPE.URL_PARAMS_SPLIT) {
returnIdMappings = false;
}

Expand All @@ -226,7 +220,7 @@ function ImproveDigitalAdServerJSClient(endPoint) {
let bidRequestObject = {
bid_request: this.createBasicBidRequestObject(requestParameters, extraRequestParameters)
};
for (counter = 0; counter < impressionObjects.length; counter++) {
for (let counter = 0; counter < impressionObjects.length; counter++) {
impressionObject = impressionObjects[counter];

if (impressionObject.errorCode) {
Expand Down Expand Up @@ -279,7 +273,7 @@ function ImproveDigitalAdServerJSClient(endPoint) {

this.formatRequest = function(requestParameters, bidRequestObject) {
switch (requestParameters.returnObjType) {
case this.CONSTANTS.RETURN_OBJ_TYPE.PREBID:
case this.CONSTANTS.RETURN_OBJ_TYPE.URL_PARAMS_SPLIT:
return {
method: 'GET',
url: `//${this.CONSTANTS.AD_SERVER_BASE_URL}/${this.CONSTANTS.END_POINT}`,
Expand Down Expand Up @@ -320,6 +314,12 @@ function ImproveDigitalAdServerJSClient(endPoint) {
if (requestParameters.libVersion) {
impressionBidRequestObject.version = requestParameters.libVersion + '-' + this.CONSTANTS.CLIENT_VERSION;
}
if (requestParameters.referrer) {
impressionBidRequestObject.referrer = requestParameters.referrer;
}
if (requestParameters.gdpr) {
impressionBidRequestObject.gdpr = requestParameters.gdpr;
}
if (extraRequestParameters) {
for (let prop in extraRequestParameters) {
impressionBidRequestObject[prop] = extraRequestParameters[prop];
Expand Down
29 changes: 19 additions & 10 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('Improve Digital Adapter Tests', function () {
}
};

const bidderRequest = {
'gdprConsent': {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'vendorData': {},
'gdprApplies': true
},
};

describe('isBidRequestValid', () => {
it('should return false when no bid', () => {
expect(spec.isBidRequestValid()).to.equal(false);
Expand Down Expand Up @@ -139,6 +147,13 @@ describe('Improve Digital Adapter Tests', function () {
getConfigStub.restore();
});

it('should add GDPR consent string', () => {
const bidRequest = Object.assign({}, simpleBidRequest);
const request = spec.buildRequests([bidRequest], bidderRequest)[0];
const params = JSON.parse(request.data.substring(PARAM_PREFIX.length));
expect(params.bid_request.gdpr).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
});

it('should return 2 requests', () => {
const requests = spec.buildRequests([
simpleBidRequest,
Expand All @@ -150,14 +165,6 @@ describe('Improve Digital Adapter Tests', function () {
});

describe('interpretResponse', () => {
let registerSyncStub;
beforeEach(() => {
registerSyncStub = sinon.stub(userSync, 'registerSync');
});

afterEach(() => {
registerSyncStub.restore();
});
const serverResponse = {
'body': {
'id': '687a06c541d8d1',
Expand Down Expand Up @@ -254,9 +261,11 @@ describe('Improve Digital Adapter Tests', function () {
});

it('should register user syncs', () => {
const registerSyncSpy = sinon.spy(userSync, 'registerSync');
const bids = spec.interpretResponse(serverResponse);
expect(registerSyncStub.withArgs('image', 'improvedigital', 'http://link1').calledOnce).to.equal(true);
expect(registerSyncStub.withArgs('image', 'improvedigital', 'http://link2').calledOnce).to.equal(true);
expect(registerSyncSpy.withArgs('image', 'improvedigital', 'http://link1').calledOnce).to.equal(true);
expect(registerSyncSpy.withArgs('image', 'improvedigital', 'http://link2').calledOnce).to.equal(true);
registerSyncSpy.restore();
});

it('should set dealId correctly', () => {
Expand Down