8
8
logError ,
9
9
logInfo ,
10
10
triggerPixel ,
11
- uniques
11
+ uniques ,
12
+ deepSetValue
12
13
} from '../src/utils.js' ;
13
14
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js' ;
14
15
import adapterManager from '../src/adapterManager.js' ;
@@ -18,6 +19,7 @@ import {getRefererInfo} from '../src/refererDetection.js';
18
19
import { AUCTION_COMPLETED , AUCTION_IN_PROGRESS , getPriceGranularity } from '../src/auction.js' ;
19
20
import { includes } from '../src/polyfill.js' ;
20
21
import { getGlobal } from '../src/prebidGlobal.js' ;
22
+ import { convertCurrency } from '../libraries/currencyUtils/currency.js' ;
21
23
22
24
const analyticsType = 'endpoint' ;
23
25
const ENDPOINT = 'https://pb-logs.media.net/log?logid=kfk&evtid=prebid_analytics_events_client' ;
@@ -112,6 +114,7 @@ class Configure {
112
114
pbv : PREBID_VERSION ,
113
115
pbav : ANALYTICS_VERSION ,
114
116
flt : 1 ,
117
+ enableDbf : 1
115
118
}
116
119
}
117
120
@@ -303,21 +306,17 @@ class BidWrapper {
303
306
this . bidObjs . push ( bidObj ) ;
304
307
}
305
308
306
- getAdSlotBids ( adSlot ) {
307
- const bidResponses = this . getAdSlotBidObjs ( adSlot ) ;
308
- return bidResponses . map ( ( bid ) => bid . getLoggingData ( ) ) ;
309
+ getAdSlotBidRequests ( adSlot ) {
310
+ return this . bidReqs . filter ( ( bid ) => bid . adUnitCode === adSlot ) ;
309
311
}
310
312
311
- getAdSlotBidObjs ( adSlot ) {
312
- const bidResponses = this . bidObjs
313
- . filter ( ( bid ) => bid . adUnitCode === adSlot ) ;
314
- const remResponses = this . bidReqs . filter ( bid => ! bid . used && bid . adUnitCode === adSlot ) ;
315
- return [ ...bidResponses , ...remResponses ] ;
313
+ getAdSlotBidResponses ( adSlot ) {
314
+ return this . bidObjs . filter ( ( bid ) => bid . adUnitCode === adSlot ) ;
316
315
}
317
316
}
318
317
319
318
class Bid {
320
- constructor ( bidId , bidder , src , start , adUnitCode , mediaType , allMediaTypeSizes ) {
319
+ constructor ( bidId , bidder , src , start , adUnitCode , mediaType , allMediaTypeSizes , resSizes ) {
321
320
this . bidId = bidId ;
322
321
this . bidder = bidder ;
323
322
this . src = src ;
@@ -348,6 +347,14 @@ class Bid {
348
347
this . used = false ;
349
348
this . originalRequestId = bidId ;
350
349
this . requestId = undefined ;
350
+ this . advUrl = undefined ;
351
+ this . latestAcid = undefined ;
352
+ this . originalCurrency = undefined ;
353
+ this . currMul = undefined ;
354
+ this . inCurrMul = undefined ;
355
+ this . res_mtype = undefined ;
356
+ this . res_sizes = resSizes ;
357
+ this . req_mtype = mediaType ;
351
358
}
352
359
353
360
get size ( ) {
@@ -374,7 +381,7 @@ class Bid {
374
381
cbdp : this . dfpbd ,
375
382
dfpbd : this . dfpbd ,
376
383
szs : this . allMediaTypeSizes . join ( '|' ) ,
377
- size : this . size ,
384
+ size : ( this . res_sizes || [ this . size ] ) . join ( '|' ) ,
378
385
mtype : this . mediaType ,
379
386
dId : this . dealId ,
380
387
winner : this . winner ,
@@ -389,6 +396,13 @@ class Bid {
389
396
flrrule : this . floorRule ,
390
397
ext : JSON . stringify ( this . ext ) ,
391
398
rtime : this . serverLatencyMillis ,
399
+ advurl : this . advUrl ,
400
+ lacid : this . latestAcid ,
401
+ icurr : this . originalCurrency ,
402
+ imul : this . inCurrMul ,
403
+ omul : this . currMul ,
404
+ res_mtype : this . res_mtype ,
405
+ req_mtype : this . req_mtype
392
406
}
393
407
}
394
408
}
@@ -454,11 +468,12 @@ class Auction {
454
468
return this . bidWrapper . findBidObj ( key , value )
455
469
}
456
470
457
- getAdSlotBids ( adSlot ) {
458
- return this . bidWrapper . getAdSlotBids ( adSlot ) ;
471
+ getAdSlotBidRequests ( adSlot ) {
472
+ return this . bidWrapper . getAdSlotBidRequests ( adSlot ) ;
459
473
}
460
- getAdSlotBidObjs ( adSlot ) {
461
- return this . bidWrapper . getAdSlotBidObjs ( adSlot ) ;
474
+
475
+ getAdSlotBidResponses ( adSlot ) {
476
+ return this . bidWrapper . getAdSlotBidResponses ( adSlot ) ;
462
477
}
463
478
464
479
_mergeFieldsToLog ( objParams ) {
@@ -558,8 +573,8 @@ function _getSizes(mediaTypes, sizes) {
558
573
}
559
574
560
575
function bidResponseHandler ( bid ) {
561
- const { width, height, mediaType, cpm, requestId, timeToRespond, auctionId, dealId, originalRequestId, bidder } = bid ;
562
- const { originalCpm, creativeId, adId, currency} = bid ;
576
+ const { width, height, mediaType, cpm, requestId, timeToRespond, auctionId, dealId, originalRequestId, bidder, meta } = bid ;
577
+ let { originalCpm, creativeId, adId, currency, originalCurrency } = bid ;
563
578
564
579
if ( ! ( auctions [ auctionId ] instanceof Auction ) ) {
565
580
return ;
@@ -575,13 +590,26 @@ function bidResponseHandler(bid) {
575
590
bidObj = { } ;
576
591
isBidOverridden = false ;
577
592
}
593
+ currency = currency ? currency . toUpperCase ( ) : '' ;
594
+ originalCurrency = originalCurrency ? originalCurrency . toUpperCase ( ) : currency ;
578
595
Object . assign ( bidObj , bidReq ,
579
596
{ cpm, width, height, mediaType, timeToRespond, dealId, creativeId, originalRequestId, requestId } ,
580
- { adId, currency }
597
+ { adId, currency, originalCurrency }
581
598
) ;
582
599
bidObj . floorPrice = deepAccess ( bid , 'floorData.floorValue' ) ;
583
600
bidObj . floorRule = deepAccess ( bid , 'floorData.floorRule' ) ;
584
601
bidObj . originalCpm = originalCpm || cpm ;
602
+ bidObj . advUrl = meta && meta . advertiserDomains && meta . advertiserDomains . join ( ',' ) ;
603
+ bidObj . currMul = 1 ;
604
+ bidObj . inCurrMul = 1 ;
605
+ if ( bidObj . originalCurrency !== 'USD' ) {
606
+ bidObj . originalCpm = exchangeCurrency ( bidObj . originalCpm , bidObj . originalCurrency , 'USD' ) ;
607
+ bidObj . inCurrMul = exchangeCurrency ( 1 , 'USD' , bidObj . originalCurrency )
608
+ }
609
+ if ( bidObj . currency !== 'USD' ) {
610
+ bidObj . cpm = exchangeCurrency ( bidObj . cpm , bidObj . currency , 'USD' ) ;
611
+ bidObj . currMul = exchangeCurrency ( 1 , 'USD' , bidObj . currency )
612
+ }
585
613
let dfpbd = deepAccess ( bid , 'adserverTargeting.hb_pb' ) ;
586
614
if ( ! dfpbd ) {
587
615
let priceGranularity = getPriceGranularity ( bid ) ;
@@ -606,9 +634,19 @@ function bidResponseHandler(bid) {
606
634
if ( typeof bid . serverResponseTimeMs !== 'undefined' ) {
607
635
bidObj . serverLatencyMillis = bid . serverResponseTimeMs ;
608
636
}
637
+ bidObj . res_mtype = mediaType ;
609
638
! isBidOverridden && auctions [ auctionId ] . addBidObj ( bidObj ) ;
610
639
}
611
640
641
+ function exchangeCurrency ( price , fromCurrency , toCurrency ) {
642
+ try {
643
+ return convertCurrency ( price , fromCurrency , toCurrency , false ) . toFixed ( 4 )
644
+ } catch ( e ) {
645
+ logError ( `Media.net Analytics Adapter: Could not convert ${ fromCurrency } to ${ toCurrency } for price ${ price } ` ) ;
646
+ }
647
+ return price ;
648
+ }
649
+
612
650
function noBidResponseHandler ( { auctionId, bidId } ) {
613
651
if ( ! ( auctions [ auctionId ] instanceof Auction ) ) {
614
652
return ;
@@ -630,7 +668,7 @@ function bidTimeoutHandler(timedOutBids) {
630
668
if ( ! ( auctions [ auctionId ] instanceof Auction ) ) {
631
669
return ;
632
670
}
633
- const bidReq = auctions [ auctionId ] . findReqBid ( 'bidId' , bidId ) ;
671
+ const bidReq = auctions [ auctionId ] . findReqBid ( bidId ) ;
634
672
if ( ! ( bidReq instanceof Bid ) || bidReq . used ) {
635
673
return ;
636
674
}
@@ -710,6 +748,7 @@ function bidWonHandler(bid) {
710
748
} ) . send ( ) ;
711
749
return ;
712
750
}
751
+ bidObj . latestAcid = bid . latestTargetedAuctionId ;
713
752
auctions [ auctionId ] . bidWonTime = Date . now ( ) ;
714
753
bidObj . winner = 1 ;
715
754
sendEvent ( auctionId , adUnitCode , LOG_TYPE . RA , bidObj . adId ) ;
@@ -749,6 +788,43 @@ function getCommonLoggingData(acid, adtag) {
749
788
return Object . assign ( commonParams , adunitParams , auctionParams ) ;
750
789
}
751
790
791
+ function getResponseSizeMap ( acid , adtag ) {
792
+ const responses = auctions [ acid ] . getAdSlotBidResponses ( adtag ) ;
793
+ const receivedResponse = { } ;
794
+ // Set true in map for success bids
795
+ responses . filter ( ( bid ) => bid . size !== '' )
796
+ . forEach ( ( bid ) => deepSetValue ( receivedResponse , `${ bid . bidId } .${ bid . size } ` , true ) ) ;
797
+
798
+ // For non-success bids:
799
+ // 1) set bid.res_sizes = (sizes for which no successful bid received)
800
+ // 2) set true in map
801
+ responses . filter ( ( bid ) => bid . size === '' ) . forEach ( ( bid ) => {
802
+ bid . res_sizes = bid . allMediaTypeSizes . filter ( ( size ) => ! deepAccess ( receivedResponse , `${ bid . bidId } .${ size } ` ) ) ;
803
+ bid . allMediaTypeSizes . forEach ( ( size ) => deepSetValue ( receivedResponse , `${ bid . bidId } .${ size } ` , true ) ) ;
804
+ } ) ;
805
+ return receivedResponse ;
806
+ }
807
+
808
+ function getDummyBids ( acid , adtag , receivedResponse ) {
809
+ const emptyBids = [ ] ;
810
+ auctions [ acid ] . getAdSlotBidRequests ( adtag ) . forEach ( ( { bidId, bidder, src, start, adUnitCode, mediaType, allMediaTypeSizes, status } ) => {
811
+ const emptySizes = allMediaTypeSizes . filter ( ( size ) => ! deepAccess ( receivedResponse , `${ bidId } .${ size } ` ) ) ;
812
+ if ( bidder !== DUMMY_BIDDER && emptySizes . length > 0 ) {
813
+ const bid = new Bid ( bidId , bidder , src , start , adUnitCode , mediaType , allMediaTypeSizes , emptySizes ) ;
814
+ bid . status = status === BID_SUCCESS ? BID_NOBID : status ;
815
+ emptyBids . push ( bid ) ;
816
+ }
817
+ } ) ;
818
+ return emptyBids ;
819
+ }
820
+
821
+ function getLoggingBids ( acid , adtag ) {
822
+ const receivedResponse = getResponseSizeMap ( acid , adtag ) ;
823
+ const dummyBids = getDummyBids ( acid , adtag , receivedResponse ) ;
824
+
825
+ return [ ...auctions [ acid ] . getAdSlotBidResponses ( adtag ) , ...dummyBids ] ;
826
+ }
827
+
752
828
function fireAuctionLog ( acid , adtag , logType , adId ) {
753
829
let commonParams = getCommonLoggingData ( acid , adtag ) ;
754
830
commonParams . lgtp = logType ;
@@ -766,7 +842,7 @@ function fireAuctionLog(acid, adtag, logType, adId) {
766
842
bidParams = [ winLogData ] ;
767
843
commonParams . lper = 1 ;
768
844
} else {
769
- bidParams = auctions [ acid ] . getAdSlotBids ( adtag ) . map ( ( { winner , ... restParams } ) => restParams ) ;
845
+ bidParams = getLoggingBids ( acid , adtag ) . map ( ( bid ) => bid . getLoggingData ( ) )
770
846
delete commonParams . wts ;
771
847
}
772
848
let mnetPresent = bidParams . filter ( b => b . pvnm === MEDIANET_BIDDER_CODE ) . length > 0 ;
0 commit comments