From 6014da62e00c259be09b330e23b649733be3ed51 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 28 Apr 2024 22:25:31 +0300 Subject: [PATCH 1/3] Update adapter SmartHub --- modules/smarthubBidAdapter.js | 32 ++++++++++++++------ test/spec/modules/smarthubBidAdapter_spec.js | 30 +++++++++++++++--- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/modules/smarthubBidAdapter.js b/modules/smarthubBidAdapter.js index 2889bd5358b..da534b6fd6c 100644 --- a/modules/smarthubBidAdapter.js +++ b/modules/smarthubBidAdapter.js @@ -2,9 +2,22 @@ import {deepAccess, isFn, logError, logMessage} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; const BIDDER_CODE = 'smarthub'; +const ALIASES = [{code: 'markapp', skipPbsAliasing: true}]; +const BASE_URLS = { + smarthub: 'https://prebid.smart-hub.io/pbjs', + markapp: 'https://markapp-prebid.smart-hub.io/pbjs' +}; + +function getUrl(partnerName) { + const aliases = ALIASES.map(el => el.code); + if (aliases.includes(partnerName)) { + return BASE_URLS[partnerName]; + } + + return `${BASE_URLS[BIDDER_CODE]}?partnerName=${partnerName}`; +} function isBidResponseValid(bid) { if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency || !bid.hasOwnProperty('netRevenue')) { @@ -23,13 +36,13 @@ function isBidResponseValid(bid) { } function getPlacementReqData(bid) { - const { params, bidId, mediaTypes } = bid; + const { params, bidId, mediaTypes, bidder } = bid; const schain = bid.schain || {}; const { partnerName, seat, token, iabCat, minBidfloor, pos } = params; const bidfloor = getBidFloor(bid); const placement = { - partnerName: partnerName.toLowerCase(), + partnerName: String(partnerName || bidder).toLowerCase(), seat, token, iabCat, @@ -37,7 +50,7 @@ function getPlacementReqData(bid) { pos, bidId, schain, - bidfloor + bidfloor, }; if (mediaTypes && mediaTypes[BANNER]) { @@ -101,7 +114,7 @@ function buildRequestParams(bidderRequest = {}, placements = []) { winLocation = window.location; } - const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.page; + const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; let refferLocation; try { refferLocation = refferUrl && new URL(refferUrl); @@ -125,17 +138,18 @@ function buildRequestParams(bidderRequest = {}, placements = []) { coppa: config.getConfig('coppa') === true ? 1 : 0, ccpa: bidderRequest.uspConsent || undefined, gdpr: bidderRequest.gdprConsent || undefined, - tmax: bidderRequest.timeout + tmax: config.getConfig('bidderTimeout') }; } export const spec = { code: BIDDER_CODE, + aliases: ALIASES, supportedMediaTypes: [BANNER, VIDEO, NATIVE], isBidRequestValid: (bid = {}) => { const { params, bidId, mediaTypes } = bid; - let valid = Boolean(bidId && params && params.partnerName && params.seat && params.token); + let valid = Boolean(bidId && params && params.seat && params.token); if (mediaTypes && mediaTypes[BANNER]) { valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes); @@ -150,8 +164,6 @@ export const spec = { }, buildRequests: (validBidRequests = [], bidderRequest = {}) => { - // convert Native ORTB definition to old-style prebid native definition - validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests); const tempObj = {}; const len = validBidRequests.length; @@ -166,7 +178,7 @@ export const spec = { const request = buildRequestParams(bidderRequest, tempObj[key]); return { method: 'POST', - url: `https://${key}-prebid.smart-hub.io/pbjs`, + url: getUrl(key), data: request, } }); diff --git a/test/spec/modules/smarthubBidAdapter_spec.js b/test/spec/modules/smarthubBidAdapter_spec.js index e01d0c72f6b..af9cde2a27e 100644 --- a/test/spec/modules/smarthubBidAdapter_spec.js +++ b/test/spec/modules/smarthubBidAdapter_spec.js @@ -4,6 +4,7 @@ import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; import { getUniqueIdentifierStr } from '../../../src/utils.js'; const bidder = 'smarthub' +const bidderAlias = 'markapp' describe('SmartHubBidAdapter', function () { const bids = [ @@ -24,6 +25,22 @@ describe('SmartHubBidAdapter', function () { pos: 1, } }, + { + bidId: getUniqueIdentifierStr(), + bidder: bidderAlias, + mediaTypes: { + [BANNER]: { + sizes: [[400, 350]] + } + }, + params: { + seat: 'testSeat', + token: 'testBanner', + iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], + minBidfloor: 9, + pos: 1, + } + }, { bidId: getUniqueIdentifierStr(), bidder: bidder, @@ -90,9 +107,8 @@ describe('SmartHubBidAdapter', function () { uspConsent: '1---', gdprConsent: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', refererInfo: { - page: 'https://test.com' - }, - timeout: 500 + referer: 'https://test.com' + } }; describe('isBidRequestValid', function () { @@ -105,7 +121,7 @@ describe('SmartHubBidAdapter', function () { }); describe('buildRequests', function () { - let [serverRequest] = spec.buildRequests(bids, bidderRequest); + let [serverRequest, requestAlias] = spec.buildRequests(bids, bidderRequest); it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; @@ -119,7 +135,11 @@ describe('SmartHubBidAdapter', function () { }); it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://testname-prebid.smart-hub.io/pbjs'); + expect(serverRequest.url).to.equal(`https://prebid.smart-hub.io/pbjs?partnerName=testname`); + }); + + it('Returns valid URL if alias', function () { + expect(requestAlias.url).to.equal(`https://${bidderAlias}-prebid.smart-hub.io/pbjs`); }); it('Returns general data valid', function () { From caa8bf2f84c8155ea41fca2d0bb035499ed2be29 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 28 Apr 2024 22:30:47 +0300 Subject: [PATCH 2/3] revert previous fixes --- modules/smarthubBidAdapter.js | 6 ++++-- test/spec/modules/smarthubBidAdapter_spec.js | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/smarthubBidAdapter.js b/modules/smarthubBidAdapter.js index da534b6fd6c..7be1a298299 100644 --- a/modules/smarthubBidAdapter.js +++ b/modules/smarthubBidAdapter.js @@ -114,7 +114,7 @@ function buildRequestParams(bidderRequest = {}, placements = []) { winLocation = window.location; } - const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + const refferUrl = bidderRequest.refererInfo && bidderRequest.refererInfo.page; let refferLocation; try { refferLocation = refferUrl && new URL(refferUrl); @@ -138,7 +138,7 @@ function buildRequestParams(bidderRequest = {}, placements = []) { coppa: config.getConfig('coppa') === true ? 1 : 0, ccpa: bidderRequest.uspConsent || undefined, gdpr: bidderRequest.gdprConsent || undefined, - tmax: config.getConfig('bidderTimeout') + tmax: bidderRequest.timeout }; } @@ -164,6 +164,8 @@ export const spec = { }, buildRequests: (validBidRequests = [], bidderRequest = {}) => { + // convert Native ORTB definition to old-style prebid native definition + validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests); const tempObj = {}; const len = validBidRequests.length; diff --git a/test/spec/modules/smarthubBidAdapter_spec.js b/test/spec/modules/smarthubBidAdapter_spec.js index af9cde2a27e..dcbfd297013 100644 --- a/test/spec/modules/smarthubBidAdapter_spec.js +++ b/test/spec/modules/smarthubBidAdapter_spec.js @@ -107,8 +107,9 @@ describe('SmartHubBidAdapter', function () { uspConsent: '1---', gdprConsent: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', refererInfo: { - referer: 'https://test.com' - } + page: 'https://test.com' + }, + timeout: 500 }; describe('isBidRequestValid', function () { From b78833c16c0c33a2af2c49ffa7668f74bb9c2b6d Mon Sep 17 00:00:00 2001 From: Chris Huie Date: Mon, 6 May 2024 12:48:59 -0600 Subject: [PATCH 3/3] Add back convertOrtbRequestToNative function --- modules/smarthubBidAdapter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/smarthubBidAdapter.js b/modules/smarthubBidAdapter.js index 7be1a298299..0be3e6831e7 100644 --- a/modules/smarthubBidAdapter.js +++ b/modules/smarthubBidAdapter.js @@ -2,6 +2,7 @@ import {deepAccess, isFn, logError, logMessage} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; +import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; const BIDDER_CODE = 'smarthub'; const ALIASES = [{code: 'markapp', skipPbsAliasing: true}];