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

Insticator Bid Adapter: add support schain and eids #8123

Merged
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
55 changes: 50 additions & 5 deletions modules/insticatorBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {config} from '../src/config.js';
import {BANNER} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {deepAccess, generateUUID, logError, } from '../src/utils.js';
import {deepAccess, generateUUID, logError, isArray} from '../src/utils.js';
import {getStorageManager} from '../src/storageManager.js';
import {find} from '../src/polyfill.js';

Expand Down Expand Up @@ -117,6 +117,24 @@ function buildUser() {
};
}

function extractSchain(bids, requestId) {
if (!bids || bids.length === 0 || !bids[0].schain) return;

const schain = bids[0].schain;
if (schain && schain.nodes && schain.nodes.length && schain.nodes[0]) {
schain.nodes[0].rid = requestId;
}

return schain;
}

function extractEids(bids) {
if (!bids) return;

const bid = bids.find(bid => isArray(bid.userIdAsEids) && bid.userIdAsEids.length > 0);
return bid ? bid.userIdAsEids : bids[0].userIdAsEids;
}

function buildRequest(validBidRequests, bidderRequest) {
const req = {
id: bidderRequest.bidderRequestId,
Expand All @@ -134,21 +152,50 @@ function buildRequest(validBidRequests, bidderRequest) {
regs: buildRegs(bidderRequest),
user: buildUser(),
imp: validBidRequests.map((bidRequest) => buildImpression(bidRequest)),
ext: {
insticator: {
adapter: {
vendor: 'prebid',
prebid: '$prebid.version$'
}
}
}
};

const params = config.getConfig('insticator.params');

if (params) {
req.ext = {
insticator: params,
insticator: {...req.ext.insticator, ...params},
};
}

const schain = extractSchain(validBidRequests, bidderRequest.bidderRequestId);

if (schain) {
req.source.ext = { schain };
}

const eids = extractEids(validBidRequests);

if (eids) {
req.user.ext = { eids };
}

return req;
}

function buildBid(bid, bidderRequest) {
const originalBid = find(bidderRequest.bids, (b) => b.bidId === bid.impid);
let meta = {}

if (bid.ext && bid.ext.meta) {
meta = bid.ext.meta
}

if (bid.adomain) {
meta.advertiserDomains = bid.adomain
}

return {
requestId: bid.impid,
Expand All @@ -162,9 +209,7 @@ function buildBid(bid, bidderRequest) {
mediaType: 'banner',
ad: bid.adm,
adUnitCode: originalBid.adUnitCode,
meta: {
advertiserDomains: bid.bidADomain && bid.bidADomain.length ? bid.bidADomain : []
},
...(Object.keys(meta).length > 0 ? {meta} : {})
};
}

Expand Down
81 changes: 71 additions & 10 deletions test/spec/modules/insticatorBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ let utils = require('src/utils.js');
describe('InsticatorBidAdapter', function () {
const adapter = newBidder(spec);

const bidderRequestId = '22edbae2733bf6'
let bidRequest = {
bidder: 'insticator',
adUnitCode: 'adunit-code',
params: {
adUnitId: '1a2b3c4d5e6f1a2b3c4d'
adUnitId: '1a2b3c4d5e6f1a2b3c4d',
},
sizes: [[300, 250], [300, 600]],
mediaTypes: {
Expand All @@ -25,10 +26,33 @@ describe('InsticatorBidAdapter', function () {
}
},
bidId: '30b31c1838de1e',
schain: {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'insticator.com',
sid: '00001',
hp: 1,
rid: bidderRequestId
}
]
},
userIdAsEids: [
{
source: 'criteo.com',
uids: [
{
id: '123',
atype: 1
}
]
}
],
};

let bidderRequest = {
bidderRequestId: '22edbae2733bf6',
bidderRequestId,
auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2',
timeout: 300,
gdprConsent: {
Expand Down Expand Up @@ -144,12 +168,23 @@ describe('InsticatorBidAdapter', function () {
const data = JSON.parse(requests[0].data);

expect(data).to.be.an('object');
expect(data).to.have.all.keys('id', 'tmax', 'source', 'site', 'device', 'regs', 'user', 'imp');
expect(data).to.have.all.keys('id', 'tmax', 'source', 'site', 'device', 'regs', 'user', 'imp', 'ext');
expect(data.id).to.equal(bidderRequest.bidderRequestId);
expect(data.tmax).to.equal(bidderRequest.timeout);
expect(data.source).to.eql({
fd: 1,
tid: bidderRequest.auctionId,
expect(data.source).to.have.all.keys('fd', 'tid', 'ext');
expect(data.source.fd).to.equal(1);
expect(data.source.tid).to.equal(bidderRequest.auctionId);
expect(data.source.ext).to.have.property('schain').to.deep.equal({
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'insticator.com',
sid: '00001',
hp: 1,
rid: bidderRequest.bidderRequestId
}
]
});
expect(data.site).to.be.an('object');
expect(data.site.domain).not.to.be.empty;
Expand All @@ -167,6 +202,18 @@ 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.ext).to.have.property('eids');
expect(data.user.ext.eids).to.deep.equal([
{
source: 'criteo.com',
uids: [
{
id: '123',
atype: 1
}
]
}
]);
expect(data.imp).to.be.an('array').that.have.lengthOf(1);
expect(data.imp).to.deep.equal([{
id: bidRequest.bidId,
Expand All @@ -183,6 +230,14 @@ describe('InsticatorBidAdapter', function () {
},
}
}]);
expect(data.ext).to.be.an('object');
expect(data.ext.insticator).to.be.an('object')
expect(data.ext.insticator).to.deep.equal({
adapter: {
vendor: 'prebid',
prebid: '$prebid.version$'
}
});
});

it('should generate new userId if not valid user is stored', function () {
Expand Down Expand Up @@ -281,7 +336,12 @@ describe('InsticatorBidAdapter', function () {
h: 200,
adm: 'adm1',
exp: 60,
bidADomain: ['test1.com'],
adomain: ['test1.com'],
ext: {
meta: {
test: 1
}
}
},
{
impid: 'bid2',
Expand All @@ -290,7 +350,7 @@ describe('InsticatorBidAdapter', function () {
w: 600,
h: 200,
adm: 'adm2',
bidADomain: ['test2.com'],
adomain: ['test2.com'],
},
{
impid: 'bid3',
Expand All @@ -299,7 +359,7 @@ describe('InsticatorBidAdapter', function () {
w: 300,
h: 200,
adm: 'adm3',
bidADomain: ['test3.com'],
adomain: ['test3.com'],
}
],
},
Expand All @@ -321,7 +381,8 @@ describe('InsticatorBidAdapter', function () {
meta: {
advertiserDomains: [
'test1.com'
]
],
test: 1
},
ad: 'adm1',
adUnitCode: 'adunit-code-1',
Expand Down