33import type { WitnessProperties } from "../../edge/witness" ;
44import type OptableSDK from "../../sdk" ;
55
6+ import * as Bowser from "bowser" ;
7+
68declare const SDK_WRAPPER_VERSION : string ;
79
810declare global {
@@ -168,17 +170,9 @@ class OptablePrebidAnalytics {
168170 auctionId,
169171 timeout,
170172 bidderRequests : bidderRequests . map ( ( br : any ) => {
171- const {
172- bidderCode,
173- bidderRequestId,
174- ortb2 : {
175- site : { domain } ,
176- user : {
177- ext : { eids } ,
178- } ,
179- } ,
180- bids = [ ] ,
181- } = br ;
173+ const { bidderCode, bidderRequestId, bids = [ ] } = br ;
174+ const domain = br . ortb2 . site ?. domain ?? "unknown" ;
175+ const eids = br . ortb2 . user ?. eids ?? [ ] ;
182176
183177 // Optable EIDs
184178 const optableEIDS = eids . filter ( ( e : { inserter : string } ) => e . inserter === "optable.co" ) ;
@@ -313,6 +307,8 @@ class OptablePrebidAnalytics {
313307 } ;
314308 this . log ( "bidWon filtered event" , filteredEvent ) ;
315309
310+ this . log ( "bidWon event" , event ) ;
311+
316312 const auction = this . auctions . get ( event . auctionId ) ;
317313 if ( ! auction ) {
318314 this . log ( "Missing 'auctionEnd' event. Skipping." ) ;
@@ -356,17 +352,9 @@ class OptablePrebidAnalytics {
356352 let totalBids = 0 ;
357353
358354 const requests = bidderRequests . map ( ( br : any ) => {
359- const {
360- bidderCode,
361- bidderRequestId,
362- ortb2 : {
363- site : { domain } ,
364- user : {
365- ext : { eids } ,
366- } ,
367- } ,
368- bids = [ ] ,
369- } = br ;
355+ const { bidderCode, bidderRequestId, bids = [ ] } = br ;
356+ const domain = br . ortb2 . site ?. domain ?? "unknown" ;
357+ const eids = br . ortb2 . user ?. eids ?? [ ] ;
370358
371359 // Optable EIDs
372360 const optableEIDS = eids . filter ( ( e : { inserter : string } ) => e . inserter === "optable.co" ) ;
@@ -377,6 +365,7 @@ class OptablePrebidAnalytics {
377365 bidderCode,
378366 bidderRequestId,
379367 domain,
368+ device : br . ortb2 . device ,
380369 optableTargetingDone : optableEIDS . length > 0 ,
381370 optableMatchers,
382371 optableSources,
@@ -408,22 +397,11 @@ class OptablePrebidAnalytics {
408397 br . optableMatchers . forEach ( ( m : unknown ) => oMatchersSet . add ( m ) ) ;
409398 br . optableSources . forEach ( ( s : unknown ) => oSourcesSet . add ( s ) ) ;
410399
411- return {
412- optableTargetingDone : br . optableTargetingDone ,
413- bidderCode : br . bidderCode ,
414- bids : br . bids . map ( ( b : any ) => {
415- adUnitCode = adUnitCode || b . adUnitCode ;
416-
417- if ( b . cpm != null ) totalBids += 1 ;
418-
419- return { floorMin : b . floorMin , cpm : b . cpm , size : b . size , bidId : b . bidId } ;
420- } ) ,
421- } ;
400+ return br ;
422401 } ) ,
423402 auctionId,
424403 adUnitCode,
425404 totalRequests : bidderRequests . length ,
426- totalBids,
427405 optableSampling : this . config . samplingRate || 1 ,
428406 optableTargetingDone : oMatchersSet . size || oSourcesSet . size ,
429407 optableMatchers : Array . from ( oMatchersSet ) ,
@@ -438,14 +416,15 @@ class OptablePrebidAnalytics {
438416 " CPM" ,
439417 bidderCode : bidWonEvent . bidderCode ,
440418 adUnitCode : bidWonEvent . adUnitCode ,
441- cpm : bidWonEvent . cmp ,
419+ cpm : bidWonEvent . cpm ,
442420 } ,
443421 missed,
444422 url : `${ window . location . hostname } ${ window . location . pathname } ` ,
445423 tenant : this . config . tenant ! ,
446424 // eslint-disable-next-line no-undef
447425 optableWrapperVersion : SDK_WRAPPER_VERSION || "unknown" ,
448- userAgent : window . navigator . userAgent ,
426+ userAgentRaw : window . navigator . userAgent ,
427+ userAgent : Bowser . parse ( window . navigator . userAgent ) as unknown as Record < string , any > ,
449428 } ;
450429
451430 // Log summary with bid counts
0 commit comments