From 7487bfd79979b0fc10e5b39fe18f1b3fb9bd6861 Mon Sep 17 00:00:00 2001 From: Jeremy Sadwith Date: Fri, 4 Nov 2022 11:09:47 -0400 Subject: [PATCH] Kargo Bid Adapter : add support for client hints (#9184) * pageURL pull from topmostLocation * Kargo: Support for client hints (#9) * Starting SUA support * Kargo: Adding support for client hints * Adding tests for sua --- modules/kargoBidAdapter.js | 22 ++++--- test/spec/modules/kargoBidAdapter_spec.js | 80 +++++++++++++++++++++-- 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index c0faf2490cb..15d706c0410 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -1,4 +1,4 @@ -import { _each, buildUrl, triggerPixel } from '../src/utils.js'; +import { _each, buildUrl, deepAccess, pick, triggerPixel } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -37,10 +37,9 @@ export const spec = { bidSizes[bid.bidId] = bid.sizes; }); - let tdid; - if (validBidRequests.length > 0 && validBidRequests[0].userId && validBidRequests[0].userId.tdid) { - tdid = validBidRequests[0].userId.tdid; - } + const firstBidRequest = validBidRequests[0]; + + const tdid = deepAccess(firstBidRequest, 'userId.tdid') const transformedParams = Object.assign({}, { sessionId: spec._getSessionId(), @@ -62,10 +61,17 @@ export const spec = { prebidRawBidRequests: validBidRequests }, spec._getAllMetadata(bidderRequest, tdid)); + // User Agent Client Hints / SUA + const uaClientHints = deepAccess(firstBidRequest, 'ortb2.device.sua'); + if (uaClientHints) { + transformedParams.device.sua = pick(uaClientHints, ['browsers', 'platform', 'mobile', 'model']); + } + // Pull Social Canvas segments and embed URL - if (validBidRequests.length > 0 && validBidRequests[0].params.socialCanvas) { - transformedParams.socialCanvasSegments = validBidRequests[0].params.socialCanvas.segments; - transformedParams.socialEmbedURL = validBidRequests[0].params.socialCanvas.embedURL; + const socialCanvas = deepAccess(firstBidRequest, 'params.socialCanvas'); + if (socialCanvas) { + transformedParams.socialCanvasSegments = socialCanvas.segments; + transformedParams.socialEmbedURL = socialCanvas.embedURL; } const encodedParams = encodeURIComponent(JSON.stringify(transformedParams)); diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 169ee520f33..565b83704fa 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -69,7 +69,33 @@ describe('kargo adapter tests', function () { userId: { tdid: 'fake-tdid' }, - sizes: [[320, 50], [300, 250], [300, 600]] + sizes: [[320, 50], [300, 250], [300, 600]], + ortb2: { + device: { + sua: { + platform: { + brand: 'macOS', + version: [ '12', '6', '0' ] + }, + browsers: [ + { + brand: 'Chromium', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Google Chrome', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Not;A=Brand', + version: [ '99', '0', '0', '0' ] + } + ], + mobile: 0, + model: '' + } + } + } }, { params: { @@ -259,6 +285,28 @@ describe('kargo adapter tests', function () { device: { width: screen.width, height: screen.height, + sua: { + platform: { + brand: 'macOS', + version: [ '12', '6', '0' ] + }, + browsers: [ + { + brand: 'Chromium', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Google Chrome', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Not;A=Brand', + version: [ '99', '0', '0', '0' ] + } + ], + mobile: 0, + model: '', + }, }, userIDs: { kargoID: '5f108831-302d-11e7-bf6b-4595acd3bf6c', @@ -280,13 +328,39 @@ describe('kargo adapter tests', function () { prebidRawBidRequests: [ { bidId: 1, + ortb2: { + device: { + sua: { + platform: { + brand: 'macOS', + version: [ '12', '6', '0' ] + }, + browsers: [ + { + brand: 'Chromium', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Google Chrome', + version: [ '106', '0', '5249', '119' ] + }, + { + brand: 'Not;A=Brand', + version: [ '99', '0', '0', '0' ] + } + ], + mobile: 0, + model: '' + } + } + }, params: { placementId: 'foo' }, userId: { tdid: 'fake-tdid' }, - sizes: [[320, 50], [300, 250], [300, 600]] + sizes: [[320, 50], [300, 250], [300, 600]], }, { bidId: 2, @@ -330,7 +404,6 @@ describe('kargo adapter tests', function () { var payload = { timeout: 200, uspConsent: '1---', - foo: 'bar', refererInfo: { page: 'https://www.prebid.org', }, @@ -349,7 +422,6 @@ describe('kargo adapter tests', function () { expect(request.method).to.equal('GET'); expect(request.currency).to.equal('USD'); expect(request.timeout).to.equal(200); - expect(request.foo).to.equal('bar'); expect(krakenParams).to.deep.equal(expected); // Make sure session ID stays the same across requests simulating multiple auctions on one page load for (let i in sessionIds) {