1
1
'use strict' ;
2
2
3
- import { getAdUnitSizes , logWarn , deepSetValue } from '../src/utils.js' ;
3
+ import { getAdUnitSizes , logWarn , deepSetValue , isFn , isPlainObject } from '../src/utils.js' ;
4
4
import { registerBidder } from '../src/adapters/bidderFactory.js' ;
5
5
import { BANNER , VIDEO } from '../src/mediaTypes.js' ;
6
6
import includes from 'core-js-pure/features/array/includes.js' ;
@@ -68,10 +68,6 @@ export const spec = {
68
68
seatId = bid . params . seatId ;
69
69
}
70
70
const tagIdOrplacementId = bid . params . tagId || bid . params . placementId ;
71
- const bidFloor = bid . params . bidfloor ? parseFloat ( bid . params . bidfloor ) : null ;
72
- if ( isNaN ( bidFloor ) ) {
73
- logWarn ( `Synacormedia: there is an invalid bid floor: ${ bid . params . bidfloor } ` ) ;
74
- }
75
71
let pos = parseInt ( bid . params . pos , 10 ) ;
76
72
if ( isNaN ( pos ) ) {
77
73
logWarn ( `Synacormedia: there is an invalid POS: ${ bid . params . pos } ` ) ;
@@ -83,9 +79,9 @@ export const spec = {
83
79
84
80
let imps = [ ] ;
85
81
if ( videoOrBannerKey === 'banner' ) {
86
- imps = this . buildBannerImpressions ( adSizes , bid , tagIdOrplacementId , pos , bidFloor , videoOrBannerKey ) ;
82
+ imps = this . buildBannerImpressions ( adSizes , bid , tagIdOrPlacementId , pos , videoOrBannerKey ) ;
87
83
} else if ( videoOrBannerKey === 'video' ) {
88
- imps = this . buildVideoImpressions ( adSizes , bid , tagIdOrplacementId , pos , bidFloor , videoOrBannerKey ) ;
84
+ imps = this . buildVideoImpressions ( adSizes , bid , tagIdOrPlacementId , pos , videoOrBannerKey ) ;
89
85
}
90
86
if ( imps . length > 0 ) {
91
87
imps . forEach ( i => openRtbBidRequest . imp . push ( i ) ) ;
@@ -128,7 +124,7 @@ export const spec = {
128
124
return eids ;
129
125
} ,
130
126
131
- buildBannerImpressions : function ( adSizes , bid , tagIdOrPlacementId , pos , bidFloor , videoOrBannerKey ) {
127
+ buildBannerImpressions : function ( adSizes , bid , tagIdOrPlacementId , pos , videoOrBannerKey ) {
132
128
let format = [ ] ;
133
129
let imps = [ ] ;
134
130
adSizes . forEach ( ( size , i ) => {
@@ -151,6 +147,10 @@ export const spec = {
151
147
} ,
152
148
tagid : tagIdOrPlacementId ,
153
149
} ;
150
+ const bidFloor = getBidFloor ( bid , 'banner' , '*' ) ;
151
+ if ( isNaN ( bidFloor ) ) {
152
+ logWarn ( `Synacormedia: there is an invalid bid floor: ${ bid . params . bidfloor } ` ) ;
153
+ }
154
154
if ( bidFloor !== null && ! isNaN ( bidFloor ) ) {
155
155
imp . bidfloor = bidFloor ;
156
156
}
@@ -159,7 +159,7 @@ export const spec = {
159
159
return imps ;
160
160
} ,
161
161
162
- buildVideoImpressions : function ( adSizes , bid , tagIdOrPlacementId , pos , bidFloor , videoOrBannerKey ) {
162
+ buildVideoImpressions : function ( adSizes , bid , tagIdOrPlacementId , pos , videoOrBannerKey ) {
163
163
let imps = [ ] ;
164
164
adSizes . forEach ( ( size , i ) => {
165
165
if ( ! size || size . length != 2 ) {
@@ -171,6 +171,11 @@ export const spec = {
171
171
id : `${ videoOrBannerKey . substring ( 0 , 1 ) } ${ bid . bidId } -${ size0 } x${ size1 } ` ,
172
172
tagid : tagIdOrPlacementId
173
173
} ;
174
+ const bidFloor = getBidFloor ( bid , 'video' , size ) ;
175
+ if ( isNaN ( bidFloor ) ) {
176
+ logWarn ( `Synacormedia: there is an invalid bid floor: ${ bid . params . bidfloor } ` ) ;
177
+ }
178
+
174
179
if ( bidFloor !== null && ! isNaN ( bidFloor ) ) {
175
180
imp . bidfloor = bidFloor ;
176
181
}
@@ -287,4 +292,20 @@ export const spec = {
287
292
}
288
293
} ;
289
294
295
+ function getBidFloor ( bid , mediaType , size ) {
296
+ if ( ! isFn ( bid . getFloor ) ) {
297
+ return bid . params . bidfloor ? parseFloat ( bid . params . bidfloor ) : null ;
298
+ }
299
+ let floor = bid . getFloor ( {
300
+ currency : 'USD' ,
301
+ mediaType,
302
+ size
303
+ } ) ;
304
+
305
+ if ( isPlainObject ( floor ) && ! isNaN ( floor . floor ) && floor . currency === 'USD' ) {
306
+ return floor . floor ;
307
+ }
308
+ return null ;
309
+ }
310
+
290
311
registerBidder ( spec ) ;
0 commit comments