Skip to content

Commit

Permalink
ttd bid adapter: configurable endpoint (#12004)
Browse files Browse the repository at this point in the history
* support endpoint params for ttd adapter

* update to support http2 endpoint only

* remove dup code

* add missing file

* fix battr issue

* fix warning

* update connection type

* add 5g

---------

Co-authored-by: Tong Wu <[email protected]>
  • Loading branch information
tongwu-sh and Tong Wu authored Jul 26, 2024
1 parent 5cefb01 commit d6a58ae
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 60 deletions.
33 changes: 33 additions & 0 deletions libraries/connectionInfo/connectionUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Returns the type of connection.
*
* @returns {number} - Type of connection.
*/
export function getConnectionType() {
const connection = navigator.connection || navigator.webkitConnection;
if (!connection) {
return 0;
}
switch (connection.type) {
case 'ethernet':
return 1;
case 'wifi':
return 2;
case 'wimax':
return 6;
default:
switch (connection.effectiveType) {
case 'slow-2g':
case '2g':
return 4;
case '3g':
return 5;
case '4g':
return 6;
case '5g':
return 7;
default:
return connection.type == 'cellular' ? 3 : 0;
}
}
}
28 changes: 1 addition & 27 deletions modules/prismaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {getANKeywordParam} from '../libraries/appnexusUtils/anKeywords.js';
import {getConnectionType} from '../libraries/connectionInfo/connectionUtils.js'

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand All @@ -20,33 +21,6 @@ const METRICS_TRACKER_URL = 'https://prisma.nexx360.io/track-imp';

const GVLID = 965;

function getConnectionType() {
const connection = navigator.connection || navigator.webkitConnection;
if (!connection) {
return 0;
}
switch (connection.type) {
case 'ethernet':
return 1;
case 'wifi':
return 2;
case 'cellular':
switch (connection.effectiveType) {
case 'slow-2g':
case '2g':
return 4;
case '3g':
return 5;
case '4g':
return 6;
default:
return 3;
}
default:
return 0;
}
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down
46 changes: 14 additions & 32 deletions modules/ttdBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as utils from '../src/utils.js';
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {isNumber} from '../src/utils.js';
import { isNumber } from '../src/utils.js';
import { getConnectionType } from '../libraries/connectionInfo/connectionUtils.js'

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand All @@ -13,10 +14,11 @@ import {isNumber} from '../src/utils.js';
* @typedef {import('../src/adapters/bidderFactory.js').UserSync} UserSync
*/

const BIDADAPTERVERSION = 'TTD-PREBID-2023.09.05';
const BIDADAPTERVERSION = 'TTD-PREBID-2024.07.26';
const BIDDER_CODE = 'ttd';
const BIDDER_CODE_LONG = 'thetradedesk';
const BIDDER_ENDPOINT = 'https://direct.adsrvr.org/bid/bidder/';
const BIDDER_ENDPOINT_HTTP2 = 'https://d2.adsrvr.org/bid/bidder/';
const USER_SYNC_ENDPOINT = 'https://match.adsrvr.org';

const MEDIA_TYPE = {
Expand Down Expand Up @@ -99,33 +101,6 @@ function getDevice(firstPartyData) {
return device;
};

function getConnectionType() {
const connection = navigator.connection || navigator.webkitConnection;
if (!connection) {
return 0;
}
switch (connection.type) {
case 'ethernet':
return 1;
case 'wifi':
return 2;
case 'cellular':
switch (connection.effectiveType) {
case 'slow-2g':
case '2g':
return 4;
case '3g':
return 5;
case '4g':
return 6;
default:
return 3;
}
default:
return 0;
}
}

function getUser(bidderRequest, firstPartyData) {
let user = {};
if (bidderRequest.gdprConsent) {
Expand Down Expand Up @@ -241,7 +216,7 @@ function banner(bid) {
},
optionalParams);

const battr = utils.deepAccess(bid, 'ortb2Imp.battr');
const battr = utils.deepAccess(bid, 'ortb2Imp.banner.battr');
if (battr) {
banner.battr = battr;
}
Expand Down Expand Up @@ -318,7 +293,7 @@ function video(bid) {
video.maxbitrate = maxbitrate;
}

const battr = utils.deepAccess(bid, 'ortb2Imp.battr');
const battr = utils.deepAccess(bid, 'ortb2Imp.video.battr');
if (battr) {
video.battr = battr;
}
Expand All @@ -327,6 +302,13 @@ function video(bid) {
}
}

function selectEndpoint(params) {
if (params.useHttp2) {
return BIDDER_ENDPOINT_HTTP2;
}
return BIDDER_ENDPOINT;
}

export const spec = {
code: BIDDER_CODE,
gvlid: 21,
Expand Down Expand Up @@ -443,7 +425,7 @@ export const spec = {
topLevel.pmp = firstPartyData.pmp
}

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

let serverRequest = {
method: 'POST',
Expand Down
11 changes: 10 additions & 1 deletion test/spec/modules/ttdBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ describe('ttdBidAdapter', function () {
expect(url).to.equal('https://direct.adsrvr.org/bid/bidder/supplier');
});

it('sends bid requests to the correct custom endpoint', function () {
let bannerBidRequestsWithCustomEndpoint = deepClone(baseBannerBidRequests);
bannerBidRequestsWithCustomEndpoint[0].params.useHttp2 = true;
const url = testBuildRequests(bannerBidRequestsWithCustomEndpoint, baseBidderRequest).url;
expect(url).to.equal('https://d2.adsrvr.org/bid/bidder/supplier');
});

it('sends publisher id', function () {
const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data;
expect(requestBody.site).to.be.not.null;
Expand Down Expand Up @@ -442,7 +449,9 @@ describe('ttdBidAdapter', function () {
let clonedBannerRequests = deepClone(baseBannerBidRequests);
const battr = [1, 2, 3];
clonedBannerRequests[0].ortb2Imp = {
battr: battr
banner: {
battr: battr
}
};
const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data;
expect(requestBody.imp[0].banner.battr).to.equal(battr);
Expand Down

0 comments on commit d6a58ae

Please sign in to comment.