Skip to content

Commit

Permalink
Kargo: Support for client hints (#9)
Browse files Browse the repository at this point in the history
* Starting SUA support

* Kargo: Adding support for client hints
  • Loading branch information
jsadwith authored Nov 1, 2022
1 parent 0bdf068 commit 1bec84d
Showing 1 changed file with 14 additions and 8 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', '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

0 comments on commit 1bec84d

Please sign in to comment.