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

Ttd Bid adapter: support for transaction id, bcat, and consolidate params #8679

Merged
merged 5 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 19 additions & 20 deletions modules/ttdBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createEidsArray } from './userId/eids.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDADAPTERVERSION = 'TTD-PREBID-2022.02.18';
const BIDADAPTERVERSION = 'TTD-PREBID-2022.06.28';
const BIDDER_CODE = 'ttd';
const BIDDER_CODE_LONG = 'thetradedesk';
const BIDDER_ENDPOINT = 'https://direct.adsrvr.org/bid/bidder/';
Expand Down Expand Up @@ -58,7 +58,9 @@ function getBidFloor(bid) {
}

function getSource(validBidRequests) {
let source = {};
let source = {
tid: validBidRequests[0].transactionId
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
};
if (validBidRequests[0].schain) {
utils.deepSetValue(source, 'ext.schain', validBidRequests[0].schain);
}
Expand Down Expand Up @@ -124,7 +126,6 @@ function getUser(bidderRequest) {

function getSite(bidderRequest, firstPartyData) {
var site = {
id: utils.deepAccess(bidderRequest, 'bids.0.params.siteId'),
page: utils.deepAccess(bidderRequest, 'refererInfo.page'),
publisher: {
id: utils.deepAccess(bidderRequest, 'bids.0.params.publisherId'),
Expand All @@ -141,17 +142,21 @@ function getSite(bidderRequest, firstPartyData) {

function getImpression(bidRequest) {
let impression = {
id: bidRequest.bidId,
tagid: bidRequest.params.placementId
id: bidRequest.bidId
};

let gpid = utils.deepAccess(bidRequest, 'ortb2Imp.ext.gpid');
const gpid = utils.deepAccess(bidRequest, 'ortb2Imp.ext.gpid');
patmmccann marked this conversation as resolved.
Show resolved Hide resolved
if (gpid) {
impression.ext = {
gpid: gpid
}
}

const tagid = gpid || bidRequest.params.placementId;
if (tagid) {
impression.tagid = tagid
}

const mediaTypesVideo = utils.deepAccess(bidRequest, 'mediaTypes.video');
const mediaTypesBanner = utils.deepAccess(bidRequest, 'mediaTypes.banner');

Expand Down Expand Up @@ -318,20 +323,10 @@ export const spec = {
utils.logWarn(BIDDER_CODE + ': params.publisherId must be 32 characters or less');
return false;
}
if (!bid.params.siteId) {
utils.logWarn(BIDDER_CODE + ': Missing required parameter params.siteId');
return false;
}
if (bid.params.siteId.length > 50) {
utils.logWarn(BIDDER_CODE + ': params.siteId must be 50 characters or less');
return false;
}
if (!bid.params.placementId) {
utils.logWarn(BIDDER_CODE + ': Missing required parameter params.placementId');
return false;
}
if (bid.params.placementId.length > 128) {
utils.logWarn(BIDDER_CODE + ': params.placementId must be 128 characters or less');

const gpid = utils.deepAccess(bid, 'ortb2Imp.ext.gpid');
if (!bid.params.placementId && !gpid) {
utils.logWarn(BIDDER_CODE + ': one of params.placementId or gpid (via the GPT module https://docs.prebid.org/dev-docs/modules/gpt-pre-auction.html) must be passed');
return false;
}

Expand Down Expand Up @@ -387,6 +382,10 @@ export const spec = {
ext: getExt(firstPartyData)
}

if (firstPartyData && firstPartyData.bcat) {
topLevel.bcat = firstPartyData.bcat;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you document if this overwrites or appends existing settings for an account on the backend? I think append is not particularly workable, and overwrite is preferred.

Why not battr and badomain as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, badv

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would also like to see support for battr and badv here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add battr/badv. We're still discussing behavior internally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to make the blocking additive (docs will reflect this).

Copy link
Collaborator

@patmmccann patmmccann Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we discuss? This decision breaks much of the utility of this feature

Generally ad management companies likes Rubicon, Cafemedia, Mediavine, & Freestar have a set of opt outs that are default and quite conservative, that typically match the defaults in GAM sensitive categories on AdX. They then have clients (publishers) opt in to more sensitive categories. If the ad management company, eg Cafemedia, sets up the normal blocking as default blocks on your backend, the opt in is impossible to communicate. In order to use this feature, Cafe and others would have to set up only very minimal blocking on the backend, which might be difficult to transition to logistically.

All that being said, as long as you document it clearly, no concerns from a code perspective and I'm sure we can make it work.

Copy link
Collaborator

@patmmccann patmmccann Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julian-burger-ttd can you confirm the badv battr changes above are planned for this pr or if they are planned for a follow up?

Copy link
Contributor Author

@julian-burger-ttd julian-burger-ttd Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming for this PR. Haven't had a chance to get to it yet, though. As for overwrite vs. additive we are having some internal discussion as there are multiple use cases to consider.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code. Docs updates (separate MR anyway) will follow.

}

let url = BIDDER_ENDPOINT + bidderRequest.bids[0].params.supplySourceId;

let serverRequest = {
Expand Down
14 changes: 4 additions & 10 deletions modules/ttdBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ The Trade Desk bid adapter supports Banner and Video.
bidder: 'ttd',
params: {
supplySourceId: 'supplier',
publisherId: '1427ab10f2e448057ed3b422',
siteId: 'site-123',
placementId: 'footer1'
publisherId: '1427ab10f2e448057ed3b422'
}
}
]
Expand All @@ -51,8 +49,7 @@ The Trade Desk bid adapter supports Banner and Video.
params: {
supplySourceId: 'supplier',
publisherId: '1427ab10f2e448057ed3b422',
siteId: 'site-123',
placementId: 'footer1',
placementId: '/1111/home#header',
banner: {
expdir: [1, 3]
},
Expand All @@ -77,9 +74,7 @@ The Trade Desk bid adapter supports Banner and Video.
bidder: 'ttd',
params: {
supplySourceId: 'supplier',
publisherId: '1427ab10f2e448057ed3b422',
siteId: 'site-123',
placementId: 'footer1'
publisherId: '1427ab10f2e448057ed3b422'
}
}
]
Expand Down Expand Up @@ -112,8 +107,7 @@ The Trade Desk bid adapter supports Banner and Video.
params: {
supplySourceId: 'supplier',
publisherId: '1427ab10f2e448057ed3b422',
siteId: 'site-123',
placementId: 'footer1'
placementId: '/1111/home#header'
}
}
]
Expand Down
87 changes: 58 additions & 29 deletions test/spec/modules/ttdBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ describe('ttdBidAdapter', function () {
'params': {
'supplySourceId': 'supplier',
'publisherId': '22222222',
'placementId': 'some-PlacementId_1',
'siteId': 'testSiteId'
'placementId': 'some-PlacementId_1'
},
'mediaTypes': {
'banner': {
Expand Down Expand Up @@ -57,27 +56,20 @@ describe('ttdBidAdapter', function () {
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when siteId not passed', function () {
let bid = makeBid();
delete bid.params.siteId;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when siteId is longer than 50 characters', function () {
let bid = makeBid();
bid.params.siteId = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when placementId not passed', function () {
it('should return true if placementId is not passed and gpid is passed', function () {
let bid = makeBid();
delete bid.params.placementId;
expect(spec.isBidRequestValid(bid)).to.equal(false);
bid.ortb2Imp = {
ext: {
gpid: '/1111/home#header'
}
}
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when the placementId is longer than 128 characters', function () {
it('should return false if neither placementId nor gpid is passed', function () {
let bid = makeBid();
bid.params.placementId = '1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'; // 130 characters
delete bid.params.placementId;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

Expand All @@ -103,7 +95,6 @@ describe('ttdBidAdapter', function () {
'params': {
'supplySourceId': 'supplier',
'publisherId': '22222222',
'siteId': 'testSiteId123',
'placementId': 'somePlacementId'
},
'mediaTypes': {
Expand Down Expand Up @@ -187,8 +178,7 @@ describe('ttdBidAdapter', function () {
'params': {
'supplySourceId': 'supplier',
'publisherId': '13144370',
'placementId': '1gaa015',
'siteId': 'testSiteId123'
'placementId': '1gaa015'
},
'mediaTypes': {
'banner': {
Expand Down Expand Up @@ -240,16 +230,49 @@ describe('ttdBidAdapter', function () {
expect(url).to.equal('https://direct.adsrvr.org/bid/bidder/supplier');
});

it('sends publisher id, site id, and placement id', function () {
it('sends publisher id', function () {
const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data;
expect(requestBody.site).to.be.not.null;
expect(requestBody.site.publisher).to.be.not.null;
expect(requestBody.imp[0].tagid).to.be.not.null;
expect(requestBody.site.publisher.id).to.equal(baseBannerBidRequests[0].params.publisherId);
expect(requestBody.site.id).to.equal(baseBannerBidRequests[0].params.siteId);
});

it('sends placement id in tagid', function () {
const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data;
expect(requestBody.imp[0].tagid).to.equal(baseBannerBidRequests[0].params.placementId);
});

it('sends gpid in tagid if present', function () {
let clonedBannerRequests = deepClone(baseBannerBidRequests);
const gpid = '/1111/home#header';
clonedBannerRequests[0].ortb2Imp = {
ext: {
gpid: gpid
}
};
const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data;
expect(requestBody.imp[0].tagid).to.equal(gpid);
});

it('sends gpid in ext.gpid if present', function () {
let clonedBannerRequests = deepClone(baseBannerBidRequests);
const gpid = '/1111/home#header';
clonedBannerRequests[0].ortb2Imp = {
ext: {
gpid: gpid
}
};
const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data;
expect(requestBody.imp[0].ext).to.be.not.null;
expect(requestBody.imp[0].ext.gpid).to.equal(gpid);
});

it('sends transaction id in source.tid', function () {
const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data;
expect(requestBody.source).to.be.not.null;
expect(requestBody.source.tid).to.equal('8651474f-58b1-4368-b812-84f8c937a099');
});

it('includes the ad size in the bid request', function () {
const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data;
expect(requestBody.imp[0].banner.format[0].w).to.equal(300);
Expand Down Expand Up @@ -283,18 +306,25 @@ describe('ttdBidAdapter', function () {
});

it('sets keywords properly if sent', function () {
let clonedBannerRequests = deepClone(baseBannerBidRequests);

const ortb2 = {
site: {
keywords: 'highViewability, clothing, holiday shopping'
}
};
const requestBody = testBuildRequests(clonedBannerRequests, {...baseBidderRequest, ortb2}).data;
const requestBody = testBuildRequests(baseBannerBidRequests, {...baseBidderRequest, ortb2}).data;
config.resetConfig();
expect(requestBody.ext.ttdprebid.keywords).to.deep.equal(['highViewability', 'clothing', 'holiday shopping']);
});

it('sets bcat properly if sent', function () {
const ortb2 = {
bcat: ['IAB1-1', 'IAB2-9']
};
const requestBody = testBuildRequests(baseBannerBidRequests, {...baseBidderRequest, ortb2}).data;
config.resetConfig();
expect(requestBody.bcat).to.deep.equal(['IAB1-1', 'IAB2-9']);
});

it('sets ext properly', function () {
let clonedBannerRequests = deepClone(baseBannerBidRequests);

Expand Down Expand Up @@ -454,8 +484,7 @@ describe('ttdBidAdapter', function () {
'bidder': 'ttd',
'params': {
'publisherId': '13144370',
'placementId': 'top',
'siteId': 'testSite123'
'placementId': 'top'
},
'mediaTypes': {
'banner': {
Expand Down