Skip to content

Commit

Permalink
Smaato: Use first party data for additional context
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrosinski committed Jun 23, 2020
1 parent cfa4dee commit beca5e1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
5 changes: 5 additions & 0 deletions modules/smaatoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const buildOpenRtbBidRequestPayload = (validBidRequests, bidderRequest) => {
}
};

Object.assign(request.user, config.getConfig('fpd.user'));
Object.assign(request.site, config.getConfig('fpd.context'));

if (bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies === true) {
utils.deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0);
utils.deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
Expand All @@ -80,6 +83,7 @@ const buildOpenRtbBidRequestPayload = (validBidRequests, bidderRequest) => {
utils.deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

/**
const lat = utils.deepAccess(validBidRequests[0], 'params.lat')
const lon = utils.deepAccess(validBidRequests[0], 'params.lon')
if (typeof lat === 'number' && typeof lon === 'number') {
Expand All @@ -103,6 +107,7 @@ const buildOpenRtbBidRequestPayload = (validBidRequests, bidderRequest) => {
if (typeof keywords === 'string') {
request.site.keywords = keywords;
}
*/

utils.logInfo('[SMAATO] OpenRTB Request:', request);
return JSON.stringify(request);
Expand Down
71 changes: 42 additions & 29 deletions test/spec/modules/smaatoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { spec } from 'modules/smaatoBidAdapter.js';
import * as utils from 'src/utils.js';
import {config} from 'src/config.js';

const imageAd = {
image: {
Expand Down Expand Up @@ -39,6 +40,19 @@ const richmediaAd = {
const ADTYPE_IMG = 'Img';
const ADTYPE_RICHMEDIA = 'Richmedia';

const context = {
keywords: ['power tools'],
search: 'drill',
content: { userrating: 4 }
};

const user = {
keywords: ['a', 'b'],
gender: 'M',
yob: '1984',
geo: { country: 'ca' }
};

const openRtbBidResponse = (adType) => {
let adm = '';

Expand Down Expand Up @@ -181,7 +195,13 @@ const singleBannerBidRequest = {
bidderWinsCount: 0
};

describe('smaatoBidAdapterTestOld', () => {
describe('smaatoBidAdapterTest', () => {
let sandbox;

beforeEach(function () {
sandbox = sinon.sandbox.create();
});

describe('isBidRequestValid', () => {
it('has valid params', () => {
expect(spec.isBidRequestValid({params: {publisherId: '123', adspaceId: '456'}})).to.be.true;
Expand Down Expand Up @@ -255,35 +275,28 @@ describe('smaatoBidAdapterTestOld', () => {
expect(req_without_usp.regs.ext.us_privacy).to.not.exist;
});

it('sends lat/lon if available', () => {
let bidRequest = utils.deepClone(singleBannerBidRequest);
bidRequest.params.lat = 3.1415;
bidRequest.params.lon = -3.1415;
let req_with_geo = JSON.parse(spec.buildRequests([bidRequest], minimalBidderRequest).data);
expect(req_with_geo.device.geo.lat).to.equal(bidRequest.params.lat);
expect(req_with_geo.device.geo.lon).to.equal(bidRequest.params.lon);
});

it('sends year of birth if available', () => {
it('sends fp data', () => {
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
fpd: {
context,
user
}
};
return utils.deepAccess(config, key);
});
let bidRequest = utils.deepClone(singleBannerBidRequest);
bidRequest.params.yob = 33;
let req_yob = JSON.parse(spec.buildRequests([bidRequest], minimalBidderRequest).data);
expect(req_yob.user.yob).to.equal(bidRequest.params.yob);
});

it('sends gender if available', () => {
let bidRequest = utils.deepClone(singleBannerBidRequest);
bidRequest.params.gender = 'f';
let req_gender = JSON.parse(spec.buildRequests([bidRequest], minimalBidderRequest).data);
expect(req_gender.user.gender).to.equal(bidRequest.params.gender);
});

it('sends site keywords if available', () => {
let bidRequest = utils.deepClone(singleBannerBidRequest);
bidRequest.params.keywords = 'kw1,kw2,kw3';
let req_kws = JSON.parse(spec.buildRequests([bidRequest], minimalBidderRequest).data);
expect(req_kws.site.keywords).to.equal(bidRequest.params.keywords);
});
let req_fpd = JSON.parse(spec.buildRequests([bidRequest], defaultBidderRequest).data);
expect(req_fpd.user.geo.country).to.equal('ca');
expect(req_fpd.user.gender).to.equal('M');
expect(req_fpd.user.yob).to.equal('1984');
expect(req_fpd.user.keywords).to.eql(['a', 'b']);
expect(req_fpd.user.ext.consent).to.equal('HFIDUYFIUYIUYWIPOI87392DSU');
expect(req_fpd.site.keywords).to.eql(['power tools']);
expect(req_fpd.site.search).to.equal('drill');
expect(req_fpd.site.content.userrating).to.equal(4);
expect(req_fpd.site.publisher.id).to.equal('publisherId');
})
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit beca5e1

Please sign in to comment.