Skip to content

Commit

Permalink
Insticator Bid adapter: added support for additional attributes (#8342)
Browse files Browse the repository at this point in the history
* feat: added support for yob, gender, instl, secure, pos

* fix: fix getStorageManager

* refactor: changed the order of vars
  • Loading branch information
EugeneVigonny authored May 3, 2022
1 parent ceaa4ba commit 32f4a5c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
18 changes: 14 additions & 4 deletions modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,25 @@ function buildImpression(bidRequest) {
ext.gpid = gpid;
}

const instl = deepAccess(bidRequest, 'ortb2Imp.instl')
const secure = location.protocol === 'https:' ? 1 : 0;
const pos = deepAccess(bidRequest, 'mediaTypes.banner.pos');

return {
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode,
instl,
secure,
banner: {
format,
pos,
},
ext,
};
}

function buildDevice() {
const deviceConfig = config.getConfig('device');
const device = {
w: window.innerWidth,
h: window.innerHeight,
Expand All @@ -93,8 +101,6 @@ function buildDevice() {
},
};

const deviceConfig = config.getConfig('device');

if (typeof deviceConfig === 'object') {
Object.assign(device, deviceConfig);
}
Expand All @@ -115,13 +121,17 @@ function buildRegs(bidderRequest) {
return {};
}

function buildUser() {
function buildUser(bid) {
const userId = getUserId() || generateUUID();
const yob = deepAccess(bid, 'params.user.yob')
const gender = deepAccess(bid, 'params.user.gender')

setUserId(userId);

return {
id: userId,
yob,
gender,
};
}

Expand Down Expand Up @@ -158,7 +168,7 @@ function buildRequest(validBidRequests, bidderRequest) {
},
device: buildDevice(),
regs: buildRegs(bidderRequest),
user: buildUser(),
user: buildUser(validBidRequests[0]),
imp: validBidRequests.map((bidRequest) => buildImpression(bidRequest)),
ext: {
insticator: {
Expand Down
39 changes: 24 additions & 15 deletions test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from 'chai';
import { spec, storage } from '../../../modules/insticatorBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js'
import { userSync } from '../../../src/userSync.js';

const USER_ID_KEY = 'hb_insticator_uid';
const USER_ID_DUMMY_VALUE = '74f78609-a92d-4cf1-869f-1b244bbfb5d2';
Expand All @@ -18,15 +17,21 @@ describe('InsticatorBidAdapter', function () {
adUnitCode: 'adunit-code',
params: {
adUnitId: '1a2b3c4d5e6f1a2b3c4d',
user: {
yob: 1984,
gender: 'M'
},
},
sizes: [[300, 250], [300, 600]],
mediaTypes: {
banner: {
sizes: [[300, 250], [300, 600]]
sizes: [[300, 250], [300, 600]],
pos: 4,
}
},
bidId: '30b31c1838de1e',
ortb2Imp: {
instl: 1,
ext: {
gpid: '1111/homepage'
}
Expand Down Expand Up @@ -91,16 +96,16 @@ describe('InsticatorBidAdapter', function () {
});

it('should return false if there is no adUnitId param', () => {
expect(spec.isBidRequestValid({...bidRequest, ...{params: {}}})).to.be.false;
expect(spec.isBidRequestValid({ ...bidRequest, ...{ params: {} } })).to.be.false;
});

it('should return false if there is no mediaTypes', () => {
expect(spec.isBidRequestValid({...bidRequest, ...{mediaTypes: {}}})).to.be.false;
expect(spec.isBidRequestValid({ ...bidRequest, ...{ mediaTypes: {} } })).to.be.false;
});

it('should return false if there are no banner sizes and no sizes', () => {
bidRequest.mediaTypes.banner = {};
expect(spec.isBidRequestValid({...bidRequest, ...{sizes: {}}})).to.be.false;
expect(spec.isBidRequestValid({ ...bidRequest, ...{ sizes: {} } })).to.be.false;
});

it('should return true if there is sizes and no banner sizes', () => {
Expand All @@ -109,7 +114,7 @@ describe('InsticatorBidAdapter', function () {

it('should return true if there is banner sizes and no sizes', () => {
bidRequest.mediaTypes.banner.sizes = [[300, 250], [300, 600]];
expect(spec.isBidRequestValid({...bidRequest, ...{sizes: {}}})).to.be.true;
expect(spec.isBidRequestValid({ ...bidRequest, ...{ sizes: {} } })).to.be.true;
});
});

Expand Down Expand Up @@ -207,6 +212,10 @@ describe('InsticatorBidAdapter', function () {
expect(data.regs.ext.gdprConsentString).to.equal(bidderRequest.gdprConsent.consentString);
expect(data.user).to.be.an('object');
expect(data.user.id).to.equal(USER_ID_DUMMY_VALUE);
expect(data.user).to.have.property('yob');
expect(data.user.yob).to.equal(1984);
expect(data.user).to.have.property('gender');
expect(data.user.gender).to.equal('M');
expect(data.user.ext).to.have.property('eids');
expect(data.user.ext.eids).to.deep.equal([
{
Expand All @@ -223,10 +232,12 @@ describe('InsticatorBidAdapter', function () {
expect(data.imp).to.deep.equal([{
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode,
instl: 1,
secure: 0,
banner: {
format: [
{w: 300, h: 250},
{w: 300, h: 600},
{ w: 300, h: 250 },
{ w: 300, h: 600 },
]
},
ext: {
Expand Down Expand Up @@ -256,7 +267,7 @@ describe('InsticatorBidAdapter', function () {
expect(data.user.id).to.equal(USER_ID_STUBBED);
});
it('should return empty regs object if no gdprConsent is passed', function () {
const requests = spec.buildRequests([bidRequest], {...bidderRequest, ...{gdprConsent: false}});
const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } });
const data = JSON.parse(requests[0].data);
expect(data.regs).to.be.an('object').that.is.empty;
});
Expand Down Expand Up @@ -384,14 +395,12 @@ describe('InsticatorBidAdapter', function () {
width: 300,
height: 200,
mediaType: 'banner',
meta: {
advertiserDomains: [
'test1.com'
],
test: 1
},
ad: 'adm1',
adUnitCode: 'adunit-code-1',
meta: {
advertiserDomains: ['test1.com'],
test: 1
}
},
{
requestId: 'bid2',
Expand Down

0 comments on commit 32f4a5c

Please sign in to comment.