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

GothamAds Bid Adapter: add at, ccpa, gdpr and coppa support #6470

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 45 additions & 7 deletions modules/gothamadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import {
registerBidder
} from '../src/adapters/bidderFactory.js';
import {
BANNER,
NATIVE,
VIDEO
} from '../src/mediaTypes.js';
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {
config
} from '../src/config.js';
FilipStamenkovic marked this conversation as resolved.
Show resolved Hide resolved

const BIDDER_CODE = 'gothamads';
const ACCOUNTID_MACROS = '[account_id]';
const URL_ENDPOINT = `https://us-e-node1.gothamads.com/bid?pass=${ACCOUNTID_MACROS}&integration=prebidjs`;
const NATIVE_ASSET_IDS = { 0: 'title', 2: 'icon', 3: 'image', 5: 'sponsoredBy', 4: 'body', 1: 'cta' };
const NATIVE_ASSET_IDS = {
0: 'title',
2: 'icon',
3: 'image',
5: 'sponsoredBy',
4: 'body',
1: 'cta'
};
const NATIVE_PARAMS = {
title: {
id: 0,
Expand Down Expand Up @@ -94,9 +109,23 @@ export const spec = {
source: {
tid: bidRequest.transactionId
},
regs: {
coppa: config.getConfig('coppa') === true ? 1 : 0,
ext: {}
},
tmax: bidRequest.timeout,
imp: [impObject],
};
if (bidRequest) {
FilipStamenkovic marked this conversation as resolved.
Show resolved Hide resolved
if (bidRequest.gdprConsent && bidRequest.gdprConsent.gdprApplies) {
utils.deepSetValue(data, 'regs.ext.gdpr', bidRequest.gdprConsent.gdprApplies ? 1 : 0);
utils.deepSetValue(data, 'user.ext.consent', bidRequest.gdprConsent.consentString);
}

if (bidRequest.uspConsent !== undefined) {
utils.deepSetValue(data, 'regs.ext.us_privacy', bidRequest.uspConsent);
}
}
bids.push(data)
}
return {
Expand Down Expand Up @@ -164,18 +193,27 @@ const checkRequestType = (bidRequest, type) => {
}

const parseNative = admObject => {
const { assets, link, imptrackers, jstracker } = admObject.native;
const {
assets,
link,
imptrackers,
jstracker
} = admObject.native;
const result = {
clickUrl: link.url,
clickTrackers: link.clicktrackers || undefined,
impressionTrackers: imptrackers || undefined,
javascriptTrackers: jstracker ? [ jstracker ] : undefined
javascriptTrackers: jstracker ? [jstracker] : undefined
};
assets.forEach(asset => {
const kind = NATIVE_ASSET_IDS[asset.id];
const content = kind && asset[NATIVE_PARAMS[kind].name];
if (content) {
result[kind] = content.text || content.value || { url: content.url, width: content.w, height: content.h };
result[kind] = content.text || content.value || {
url: content.url,
width: content.w,
height: content.h
};
}
});

Expand Down
127 changes: 87 additions & 40 deletions test/spec/modules/gothamadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { expect } from 'chai';
import { spec } from 'modules/gothamadsBidAdapter.js';
import {
expect
} from 'chai';
import {
spec
} from 'modules/gothamadsBidAdapter.js';
import {
config
} from 'src/config.js';

const NATIVE_BID_REQUEST = {
code: 'native_example',
Expand Down Expand Up @@ -44,7 +51,10 @@ const BANNER_BID_REQUEST = {
code: 'banner_example',
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
sizes: [
[300, 250],
[300, 600]
]
}
},
bidder: 'gothamads',
Expand All @@ -53,7 +63,11 @@ const BANNER_BID_REQUEST = {
accountId: 'accountId'
},
timeout: 1000,

gdprConsent: {
consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA',
gdprApplies: 1,
},
uspConsent: 'uspConsent'
}

const bidRequest = {
Expand All @@ -65,26 +79,27 @@ const bidRequest = {
const VIDEO_BID_REQUEST = {
code: 'video1',
sizes: [640, 480],
mediaTypes: { video: {
minduration: 0,
maxduration: 999,
boxingallowed: 1,
skip: 0,
mimes: [
'application/javascript',
'video/mp4'
],
w: 1920,
h: 1080,
protocols: [
2
],
linearity: 1,
api: [
1,
2
]
}
mediaTypes: {
video: {
minduration: 0,
maxduration: 999,
boxingallowed: 1,
skip: 0,
mimes: [
'application/javascript',
'video/mp4'
],
w: 1920,
h: 1080,
protocols: [
2
],
linearity: 1,
api: [
1,
2
]
}
},

bidder: 'gothamads',
Expand Down Expand Up @@ -148,20 +163,29 @@ const NATIVE_BID_RESPONSE = {
impid: 'request_imp_id',
price: 5,
adomain: ['example.com'],
adm: { native:
adm: {
native: {
assets: [{
id: 0,
title: 'dummyText'
},
{
id: 3,
image: imgData
},
{
assets: [
{id: 0, title: 'dummyText'},
{id: 3, image: imgData},
{
id: 5,
data: {value: 'organization.name'}
}
],
link: {url: 'example.com'},
imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'],
jstracker: 'tracker1.com'
id: 5,
data: {
value: 'organization.name'
}
}
],
link: {
url: 'example.com'
},
imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'],
jstracker: 'tracker1.com'
}
},
crid: 'crid',
ext: {
Expand All @@ -171,8 +195,23 @@ const NATIVE_BID_RESPONSE = {
}],
};

describe('GothamAdsAdapter', function() {
describe('isBidRequestValid', function() {
describe('GothamAdsAdapter', function () {
describe('with COPPA', function () {
beforeEach(function () {
sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(true);
});
afterEach(function () {
config.getConfig.restore();
});

it('should send the Coppa "required" flag set to "1" in the request', function () {
let serverRequest = spec.buildRequests([BANNER_BID_REQUEST]);
expect(serverRequest.data[0].regs.coppa).to.equal(1);
});
});
describe('isBidRequestValid', function () {
it('should return true when required params found', function () {
expect(spec.isBidRequestValid(NATIVE_BID_REQUEST)).to.equal(true);
});
Expand Down Expand Up @@ -221,6 +260,12 @@ describe('GothamAdsAdapter', function() {
expect(request.data).to.exist;
});

it('check consent and ccpa string is set properly', function () {
expect(request.data[0].regs.ext.gdpr).to.equal(1);
expect(request.data[0].user.ext.consent).to.equal(BANNER_BID_REQUEST.gdprConsent.consentString);
expect(request.data[0].regs.ext.us_privacy).to.equal(BANNER_BID_REQUEST.uspConsent);
})

it('sends bid request to our endpoint via POST', function () {
expect(request.method).to.equal('POST');
});
Expand Down Expand Up @@ -250,7 +295,7 @@ describe('GothamAdsAdapter', function() {
});

describe('interpretResponse', function () {
it('Empty response must return empty array', function() {
it('Empty response must return empty array', function () {
const emptyResponse = null;
let response = spec.interpretResponse(emptyResponse);

Expand Down Expand Up @@ -346,7 +391,9 @@ describe('GothamAdsAdapter', function() {
creativeId: NATIVE_BID_RESPONSE.seatbid[0].bid[0].crid,
dealId: NATIVE_BID_RESPONSE.seatbid[0].bid[0].dealid,
mediaType: 'native',
native: {clickUrl: NATIVE_BID_RESPONSE.seatbid[0].bid[0].adm.native.link.url}
native: {
clickUrl: NATIVE_BID_RESPONSE.seatbid[0].bid[0].adm.native.link.url
}
}

let nativeResponses = spec.interpretResponse(nativeResponse);
Expand Down