11import { registerBidder } from '../src/adapters/bidderFactory.js' ;
22import { BANNER , NATIVE , VIDEO } from '../src/mediaTypes.js' ;
3- import { isFn , deepAccess , logMessage } from '../src/utils.js' ;
3+ import { deepAccess , logMessage , logError } from '../src/utils.js' ;
44import { convertOrtbRequestToProprietaryNative } from '../src/native.js' ;
55
66const BIDDER_CODE = 'e_volution' ;
77const GVLID = 957 ;
88const AD_URL = 'https://service.e-volution.ai/?c=o&m=multi' ;
9- const URL_SYNC = 'https://service.e-volution.ai/?c=o&m=sync' ;
10- const NO_SYNC = true ;
119
1210function isBidResponseValid ( bid ) {
13- if ( ! bid . requestId || ! bid . cpm || ! bid . creativeId ||
14- ! bid . ttl || ! bid . currency ) {
11+ if ( ! bid . requestId || ! bid . cpm || ! bid . creativeId || ! bid . ttl || ! bid . currency ) {
1512 return false ;
1613 }
14+
1715 switch ( bid . mediaType ) {
1816 case BANNER :
1917 return Boolean ( bid . width && bid . height && bid . ad ) ;
2018 case VIDEO :
21- return Boolean ( bid . vastUrl ) ;
19+ return Boolean ( bid . vastUrl || bid . vastXml ) ;
2220 case NATIVE :
23- return Boolean ( bid . native && bid . native . title && bid . native . image && bid . native . impressionTrackers ) ;
21+ return Boolean ( bid . native && bid . native . impressionTrackers && bid . native . impressionTrackers . length ) ;
2422 default :
2523 return false ;
2624 }
2725}
2826
29- function getBidFloor ( bid ) {
30- if ( ! isFn ( bid . getFloor ) ) {
31- return deepAccess ( bid , 'params.bidfloor' , 0 ) ;
27+ function getPlacementReqData ( bid ) {
28+ const { params, bidId, mediaTypes, transactionId, userIdAsEids } = bid ;
29+ const schain = bid . schain || { } ;
30+ const { placementId, endpointId } = params ;
31+ const bidfloor = getBidFloor ( bid ) ;
32+
33+ const placement = {
34+ bidId,
35+ schain,
36+ bidfloor
37+ } ;
38+
39+ if ( placementId ) {
40+ placement . placementId = placementId ;
41+ placement . type = 'publisher' ;
42+ } else if ( endpointId ) {
43+ placement . endpointId = endpointId ;
44+ placement . type = 'network' ;
45+ }
46+
47+ if ( mediaTypes && mediaTypes [ BANNER ] ) {
48+ placement . adFormat = BANNER ;
49+ placement . sizes = mediaTypes [ BANNER ] . sizes ;
50+ } else if ( mediaTypes && mediaTypes [ VIDEO ] ) {
51+ placement . adFormat = VIDEO ;
52+ placement . playerSize = mediaTypes [ VIDEO ] . playerSize ;
53+ placement . minduration = mediaTypes [ VIDEO ] . minduration ;
54+ placement . maxduration = mediaTypes [ VIDEO ] . maxduration ;
55+ placement . mimes = mediaTypes [ VIDEO ] . mimes ;
56+ placement . protocols = mediaTypes [ VIDEO ] . protocols ;
57+ placement . startdelay = mediaTypes [ VIDEO ] . startdelay ;
58+ placement . plcmt = mediaTypes [ VIDEO ] . plcmt ;
59+ placement . skip = mediaTypes [ VIDEO ] . skip ;
60+ placement . skipafter = mediaTypes [ VIDEO ] . skipafter ;
61+ placement . minbitrate = mediaTypes [ VIDEO ] . minbitrate ;
62+ placement . maxbitrate = mediaTypes [ VIDEO ] . maxbitrate ;
63+ placement . delivery = mediaTypes [ VIDEO ] . delivery ;
64+ placement . playbackmethod = mediaTypes [ VIDEO ] . playbackmethod ;
65+ placement . api = mediaTypes [ VIDEO ] . api ;
66+ placement . linearity = mediaTypes [ VIDEO ] . linearity ;
67+ } else if ( mediaTypes && mediaTypes [ NATIVE ] ) {
68+ placement . native = mediaTypes [ NATIVE ] ;
69+ placement . adFormat = NATIVE ;
70+ }
71+
72+ if ( transactionId ) {
73+ placement . ext = placement . ext || { } ;
74+ placement . ext . tid = transactionId ;
3275 }
3376
77+ if ( userIdAsEids && userIdAsEids . length ) {
78+ placement . eids = userIdAsEids ;
79+ }
80+
81+ return placement ;
82+ }
83+
84+ function getBidFloor ( bid ) {
3485 try {
3586 const bidFloor = bid . getFloor ( {
3687 currency : 'USD' ,
3788 mediaType : '*' ,
3889 size : '*' ,
3990 } ) ;
4091 return bidFloor . floor ;
41- } catch ( _ ) {
42- return 0
43- }
44- }
45-
46- function getUserId ( eids , id , source , uidExt ) {
47- if ( id ) {
48- var uid = { id } ;
49- if ( uidExt ) {
50- uid . ext = uidExt ;
51- }
52- eids . push ( {
53- source,
54- uids : [ uid ]
55- } ) ;
92+ } catch ( err ) {
93+ logError ( err ) ;
94+ return 0 ;
5695 }
5796}
5897
5998export const spec = {
6099 code : BIDDER_CODE ,
61100 gvlid : GVLID ,
62101 supportedMediaTypes : [ BANNER , VIDEO , NATIVE ] ,
63- noSync : NO_SYNC ,
64102
65- isBidRequestValid : ( bid ) => {
66- return Boolean ( bid . bidId && bid . params && ! isNaN ( parseInt ( bid . params . placementId ) ) ) ;
103+ isBidRequestValid : ( bid = { } ) => {
104+ const { params, bidId, mediaTypes } = bid ;
105+ let valid = Boolean ( bidId && params && ( params . placementId || params . endpointId ) ) ;
106+
107+ if ( mediaTypes && mediaTypes [ BANNER ] ) {
108+ valid = valid && Boolean ( mediaTypes [ BANNER ] && mediaTypes [ BANNER ] . sizes ) ;
109+ } else if ( mediaTypes && mediaTypes [ VIDEO ] ) {
110+ valid = valid && Boolean ( mediaTypes [ VIDEO ] && mediaTypes [ VIDEO ] . playerSize ) ;
111+ } else if ( mediaTypes && mediaTypes [ NATIVE ] ) {
112+ valid = valid && Boolean ( mediaTypes [ NATIVE ] ) ;
113+ } else {
114+ valid = false ;
115+ }
116+ return valid ;
67117 } ,
68118
69- buildRequests : ( validBidRequests = [ ] , bidderRequest ) => {
119+ buildRequests : ( validBidRequests = [ ] , bidderRequest = { } ) => {
70120 // convert Native ORTB definition to old-style prebid native definition
71121 validBidRequests = convertOrtbRequestToProprietaryNative ( validBidRequests ) ;
72122
73- let winTop = window ;
74- let location ;
75- // TODO: this odd try-catch block was copied in several adapters; it doesn't seem to be correct for cross-origin
123+ let deviceWidth = 0 ;
124+ let deviceHeight = 0 ;
125+
126+ let winLocation ;
76127 try {
77- location = new URL ( bidderRequest . refererInfo . page ) ;
78- winTop = window . top ;
128+ const winTop = window . top ;
129+ deviceWidth = winTop . screen . width ;
130+ deviceHeight = winTop . screen . height ;
131+ winLocation = winTop . location ;
79132 } catch ( e ) {
80- location = winTop . location ;
81133 logMessage ( e ) ;
82- } ;
83- let placements = [ ] ;
84- let request = {
85- 'deviceWidth' : winTop . screen . width ,
86- 'deviceHeight' : winTop . screen . height ,
87- 'language' : ( navigator && navigator . language ) ? navigator . language . split ( '-' ) [ 0 ] : '' ,
88- 'secure' : 1 ,
89- 'host' : location . host ,
90- 'page' : location . pathname ,
91- 'placements' : placements
92- } ;
93- if ( bidderRequest ) {
94- if ( bidderRequest . uspConsent ) {
95- request . ccpa = bidderRequest . uspConsent ;
96- }
97- if ( bidderRequest . gdprConsent ) {
98- request . gdpr = bidderRequest . gdprConsent ;
99- }
134+ winLocation = window . location ;
100135 }
101- const len = validBidRequests . length ;
102136
103- for ( let i = 0 ; i < len ; i ++ ) {
104- let bid = validBidRequests [ i ] ;
137+ const refferUrl = bidderRequest . refererInfo && bidderRequest . refererInfo . page ;
138+ let refferLocation ;
139+ try {
140+ refferLocation = refferUrl && new URL ( refferUrl ) ;
141+ } catch ( e ) {
142+ logMessage ( e ) ;
143+ }
105144
106- const placement = {
107- placementId : bid . params . placementId ,
108- bidId : bid . bidId ,
109- bidfloor : getBidFloor ( bid ) ,
110- eids : [ ]
111- } ;
145+ let location = refferLocation || winLocation ;
146+ const language = ( navigator && navigator . language ) ? navigator . language . split ( '-' ) [ 0 ] : '' ;
147+ const host = location . host ;
148+ const page = location . pathname ;
149+ const secure = location . protocol === 'https:' ? 1 : 0 ;
150+ const placements = [ ] ;
151+ const request = {
152+ deviceWidth,
153+ deviceHeight,
154+ language,
155+ secure,
156+ host,
157+ page,
158+ placements,
159+ coppa : deepAccess ( bidderRequest , 'ortb2.regs.coppa' ) ? 1 : 0 ,
160+ tmax : bidderRequest . timeout
161+ } ;
112162
113- if ( bid . userId ) {
114- getUserId ( placement . eids , bid . userId . id5id , 'id5-sync.com' ) ;
115- }
163+ if ( bidderRequest . uspConsent ) {
164+ request . ccpa = bidderRequest . uspConsent ;
165+ }
116166
117- if ( bid . mediaTypes && bid . mediaTypes [ BANNER ] && bid . mediaTypes [ BANNER ] . sizes ) {
118- placement . traffic = BANNER ;
119- placement . sizes = bid . mediaTypes [ BANNER ] . sizes ;
120- } else if ( bid . mediaTypes && bid . mediaTypes [ VIDEO ] && bid . mediaTypes [ VIDEO ] . playerSize ) {
121- placement . traffic = VIDEO ;
122- placement . wPlayer = bid . mediaTypes [ VIDEO ] . playerSize [ 0 ] ;
123- placement . hPlayer = bid . mediaTypes [ VIDEO ] . playerSize [ 1 ] ;
124- placement . minduration = bid . mediaTypes [ VIDEO ] . minduration ;
125- placement . maxduration = bid . mediaTypes [ VIDEO ] . maxduration ;
126- placement . mimes = bid . mediaTypes [ VIDEO ] . mimes ;
127- placement . protocols = bid . mediaTypes [ VIDEO ] . protocols ;
128- placement . startdelay = bid . mediaTypes [ VIDEO ] . startdelay ;
129- placement . placement = bid . mediaTypes [ VIDEO ] . placement ;
130- placement . skip = bid . mediaTypes [ VIDEO ] . skip ;
131- placement . skipafter = bid . mediaTypes [ VIDEO ] . skipafter ;
132- placement . minbitrate = bid . mediaTypes [ VIDEO ] . minbitrate ;
133- placement . maxbitrate = bid . mediaTypes [ VIDEO ] . maxbitrate ;
134- placement . delivery = bid . mediaTypes [ VIDEO ] . delivery ;
135- placement . playbackmethod = bid . mediaTypes [ VIDEO ] . playbackmethod ;
136- placement . api = bid . mediaTypes [ VIDEO ] . api ;
137- placement . linearity = bid . mediaTypes [ VIDEO ] . linearity ;
138- } else if ( bid . mediaTypes && bid . mediaTypes [ NATIVE ] ) {
139- placement . traffic = NATIVE ;
140- placement . native = bid . mediaTypes [ NATIVE ] ;
141- }
167+ if ( bidderRequest . gdprConsent ) {
168+ request . gdpr = {
169+ consentString : bidderRequest . gdprConsent . consentString
170+ } ;
171+ }
142172
143- if ( bid . schain ) {
144- placements . schain = bid . schain ;
145- }
173+ if ( bidderRequest . gppConsent ) {
174+ request . gpp = bidderRequest . gppConsent . gppString ;
175+ request . gpp_sid = bidderRequest . gppConsent . applicableSections ;
176+ } else if ( bidderRequest . ortb2 ?. regs ?. gpp ) {
177+ request . gpp = bidderRequest . ortb2 . regs . gpp ;
178+ request . gpp_sid = bidderRequest . ortb2 . regs . gpp_sid ;
179+ }
146180
147- placements . push ( placement ) ;
181+ const len = validBidRequests . length ;
182+ for ( let i = 0 ; i < len ; i ++ ) {
183+ const bid = validBidRequests [ i ] ;
184+ placements . push ( getPlacementReqData ( bid ) ) ;
148185 }
186+
149187 return {
150188 method : 'POST' ,
151189 url : AD_URL ,
@@ -165,19 +203,7 @@ export const spec = {
165203 }
166204 }
167205 return response ;
168- } ,
169-
170- getUserSyncs : ( syncOptions , serverResponses ) => {
171- if ( NO_SYNC ) {
172- return false
173- } else {
174- return [ {
175- type : 'image' ,
176- url : URL_SYNC
177- } ] ;
178- }
179206 }
180-
181207} ;
182208
183209registerBidder ( spec ) ;
0 commit comments