Skip to content

Commit

Permalink
Kargo Bid Adapter : add support for client hints (prebid#9184)
Browse files Browse the repository at this point in the history
* pageURL pull from topmostLocation

* Kargo: Support for client hints (#9)

* Starting SUA support

* Kargo: Adding support for client hints

* Adding tests for sua
  • Loading branch information
jsadwith authored Nov 4, 2022
1 parent abf4688 commit 7487bfd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 12 deletions.
22 changes: 14 additions & 8 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(),
Expand All @@ -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));
Expand Down
80 changes: 76 additions & 4 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -330,7 +404,6 @@ describe('kargo adapter tests', function () {
var payload = {
timeout: 200,
uspConsent: '1---',
foo: 'bar',
refererInfo: {
page: 'https://www.prebid.org',
},
Expand All @@ -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) {
Expand Down

0 comments on commit 7487bfd

Please sign in to comment.