Skip to content

Commit

Permalink
Sharethrough bid adapter: Populate meta fields when present in bid re…
Browse files Browse the repository at this point in the history
…sponse (for analytics) (prebid#10108)

* when not provided, set meta fields to null

* Fill bid's meta fields when possible

* Comment for spec

* Comment about names

* Remove TODO: Both teams agreed on these names
  • Loading branch information
maxime-dupuis committed Jun 16, 2023
1 parent 8337584 commit a5be17f
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ export const sharethroughAdapterSpec = {
}

return body.seatbid[0].bid.map(bid => {
// Spec: https://docs.prebid.org/dev-docs/bidder-adaptor.html#interpreting-the-response
const response = {
requestId: bid.impid,
width: +bid.w,
Expand All @@ -169,6 +170,19 @@ export const sharethroughAdapterSpec = {
nurl: bid.nurl,
meta: {
advertiserDomains: bid.adomain || [],
networkId: bid.ext?.networkId || null,
networkName: bid.ext?.networkName || null,
agencyId: bid.ext?.agencyId || null,
agencyName: bid.ext?.agencyName || null,
advertiserId: bid.ext?.advertiserId || null,
advertiserName: bid.ext?.advertiserName || null,
brandId: bid.ext?.brandId || null,
brandName: bid.ext?.brandName || null,
demandSource: bid.ext?.demandSource || null,
dchain: bid.ext?.dchain || null,
primaryCatId: bid.ext?.primaryCatId || null,
secondaryCatIds: bid.ext?.secondaryCatIds || null,
mediaType: bid.ext?.mediaType || null,
},
};

Expand Down
75 changes: 75 additions & 0 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,81 @@ describe('sharethrough adapter spec', function () {
expect(bannerBid.vastXml).to.equal('vastTag');
});
});

describe('meta object', () => {
beforeEach(() => {
request = spec.buildRequests(bidRequests, bidderRequest)[0];
response = {
body: {
seatbid: [{
bid: [{
id: '123',
impid: 'bidId1',
w: 300,
h: 250,
price: 42,
crid: 'creative',
dealid: 'deal',
adomain: ['domain.com'],
adm: 'markup',
}],
}],
},
};
});

it('should have null optional fields when the response\'s optional seatbid[].bid[].ext field is empty', () => {
const bid = spec.interpretResponse(response, request)[0];

expect(bid.meta.networkId).to.be.null;
expect(bid.meta.networkName).to.be.null;
expect(bid.meta.agencyId).to.be.null;
expect(bid.meta.agencyName).to.be.null;
expect(bid.meta.advertiserId).to.be.null;
expect(bid.meta.advertiserName).to.be.null;
expect(bid.meta.brandId).to.be.null;
expect(bid.meta.brandName).to.be.null;
expect(bid.meta.demandSource).to.be.null;
expect(bid.meta.dchain).to.be.null;
expect(bid.meta.primaryCatId).to.be.null;
expect(bid.meta.secondaryCatIds).to.be.null;
expect(bid.meta.mediaType).to.be.null;
});

it('should have populated fields when the response\'s optional seatbid[].bid[].ext fields are filled', () => {
response.body.seatbid[0].bid[0].ext = {
networkId: 'my network id',
networkName: 'my network name',
agencyId: 'my agency id',
agencyName: 'my agency name',
advertiserId: 'my advertiser id',
advertiserName: 'my advertiser name',
brandId: 'my brand id',
brandName: 'my brand name',
demandSource: 'my demand source',
dchain: { 'my key': 'my value' },
primaryCatId: 'my primary cat id',
secondaryCatIds: ['my', 'secondary', 'cat', 'ids'],
mediaType: 'my media type',
};

const bid = spec.interpretResponse(response, request)[0];

expect(bid.meta.networkId).to.equal('my network id');
expect(bid.meta.networkName).to.equal('my network name');
expect(bid.meta.agencyId).to.equal('my agency id');
expect(bid.meta.agencyName).to.equal('my agency name');
expect(bid.meta.advertiserId).to.equal('my advertiser id');
expect(bid.meta.advertiserName).to.equal('my advertiser name');
expect(bid.meta.brandId).to.equal('my brand id');
expect(bid.meta.brandName).to.equal('my brand name');
expect(bid.meta.demandSource).to.equal('my demand source');
expect(bid.meta.dchain).to.deep.equal({ 'my key': 'my value' });
expect(bid.meta.primaryCatId).to.equal('my primary cat id');
expect(bid.meta.secondaryCatIds).to.deep.equal(['my', 'secondary', 'cat', 'ids']);
expect(bid.meta.mediaType).to.equal('my media type');
});
});
});

describe('getUserSyncs', function () {
Expand Down

0 comments on commit a5be17f

Please sign in to comment.