1
- // import * as utils from 'src/utils';
2
1
import { registerBidder } from '../src/adapters/bidderFactory.js' ;
3
- // import { config } from 'src/config';
4
2
import { VIDEO } from '../src/mediaTypes.js' ;
3
+ import {
4
+ isFn ,
5
+ deepAccess ,
6
+ deepSetValue } from '../src/utils.js' ;
7
+ import { config } from '../src/config.js' ;
5
8
6
9
const BIDDER_CODE = 'jwplayer' ;
10
+ const URL = 'https://ib.adnxs.com/openrtb2/prebid' ;
11
+
7
12
const GVLID = 1046 ;
8
13
const SUPPORTED_AD_TYPES = [ VIDEO ] ;
9
14
15
+ // Video Parameters
16
+ // https://docs.prebid.org/dev-docs/bidder-adaptor.html#step-2-accept-video-parameters-and-pass-them-to-your-server
17
+ const VIDEO_ORTB_PARAMS = [
18
+ 'mimes' ,
19
+ 'minduration' ,
20
+ 'maxduration' ,
21
+ 'protocols' ,
22
+ 'startdelay' ,
23
+ 'placement' ,
24
+ 'skip' ,
25
+ 'skipafter' ,
26
+ 'minbitrate' ,
27
+ 'maxbitrate' ,
28
+ 'delivery' ,
29
+ 'playbackmethod' ,
30
+ 'api' ,
31
+ 'linearity'
32
+ ] ;
33
+
10
34
export const spec = {
11
35
code : BIDDER_CODE ,
12
36
gvlid : GVLID ,
@@ -29,10 +53,25 @@ export const spec = {
29
53
/**
30
54
* Make a server request from the list of BidRequests.
31
55
*
32
- * @param {BidRequest[] } bidRequests A non-empty list of bid requests which should be sent to the Server.
56
+ * @param {BidRequest[] } bidRequests A non-empty list of bid requests, or ad units, which should be sent to the server.
57
+ * @param bidderRequest
33
58
* @return ServerRequest Info describing the request to the server.
34
59
*/
35
- buildRequests : function ( validBidRequests , bidderRequest ) { } ,
60
+ buildRequests : function ( bidRequests , bidderRequest ) {
61
+ if ( ! bidRequests ) {
62
+ return ;
63
+ }
64
+
65
+ return bidRequests . map ( bidRequest => {
66
+ const payload = buildRequest ( bidRequest , bidderRequest ) ;
67
+
68
+ return {
69
+ method : 'POST' ,
70
+ url : URL ,
71
+ data : payload
72
+ }
73
+ } ) ;
74
+ } ,
36
75
37
76
/**
38
77
* Unpack the response from the server into a list of bids.
@@ -50,4 +89,105 @@ export const spec = {
50
89
// onBidderError: function({ error, bidderRequest }) {}
51
90
} ;
52
91
92
+ function buildRequest ( bidRequest , bidderRequest ) {
93
+ const openrtbRequest = {
94
+ id : bidRequest . bidId ,
95
+ imp : buildRequestImpression ( bidRequest , bidderRequest ) ,
96
+ site : buildRequestSite ( bidderRequest ) ,
97
+ device : buildRequestDevice ( )
98
+ } ;
99
+
100
+ // Attaching GDPR Consent Params
101
+ if ( bidderRequest . gdprConsent ) {
102
+ deepSetValue ( openrtbRequest , 'user.ext.consent' , bidderRequest . gdprConsent . consentString ) ;
103
+ deepSetValue ( openrtbRequest , 'regs.ext.gdpr' , ( bidderRequest . gdprConsent . gdprApplies ? 1 : 0 ) ) ;
104
+ }
105
+
106
+ // CCPA
107
+ if ( bidderRequest . uspConsent ) {
108
+ deepSetValue ( openrtbRequest , 'regs.ext.us_privacy' , bidderRequest . uspConsent ) ;
109
+ }
110
+
111
+ return JSON . stringify ( openrtbRequest ) ;
112
+ }
113
+
114
+ function buildRequestImpression ( bidRequest ) {
115
+ const impressionObject = {
116
+ id : bidRequest . adUnitCode ,
117
+ } ;
118
+
119
+ impressionObject . video = buildImpressionVideo ( bidRequest ) ;
120
+
121
+ const bidFloorData = buildBidFloorData ( bidRequest ) ;
122
+ if ( bidFloorData ) {
123
+ impressionObject . bidfloor = bidFloorData . floor ;
124
+ impressionObject . bidfloorcur = bidFloorData . currency ;
125
+ }
126
+
127
+ impressionObject . ext = buildImpressionExtension ( bidRequest ) ;
128
+
129
+ return [ impressionObject ] ;
130
+ }
131
+
132
+ function buildImpressionVideo ( bidRequest ) {
133
+ const videoParams = deepAccess ( bidRequest , 'mediaTypes.video' , { } ) ;
134
+
135
+ const video = { } ;
136
+
137
+ VIDEO_ORTB_PARAMS . forEach ( ( param ) => {
138
+ if ( videoParams . hasOwnProperty ( param ) ) {
139
+ video [ param ] = videoParams [ param ] ;
140
+ }
141
+ } ) ;
142
+
143
+ return video ;
144
+ }
145
+
146
+ function buildImpressionExtension ( bidRequest ) {
147
+ return {
148
+ appnexus : {
149
+ placement_id : bidRequest . params . placementId
150
+ }
151
+ } ;
152
+ }
153
+
154
+ function buildBidFloorData ( bidRequest ) {
155
+ const { params} = bidRequest ;
156
+ const currency = params . currency || 'USD' ;
157
+
158
+ let floorData ;
159
+ if ( isFn ( bidRequest . getFloor ) ) {
160
+ const bidFloorRequest = {
161
+ currency : currency ,
162
+ mediaType : VIDEO ,
163
+ size : '*'
164
+ } ;
165
+ floorData = bidRequest . getFloor ( bidFloorRequest ) ;
166
+ } else if ( params . bidfloor ) {
167
+ floorData = { floor : params . bidfloor , currency : currency } ;
168
+ }
169
+
170
+ return floorData ;
171
+ }
172
+
173
+ function buildRequestSite ( bidderRequest ) {
174
+ const site = config . getConfig ( 'ortb2.site' ) || { } ;
175
+
176
+ site . domain = site . domain || config . publisherDomain || window . location . hostname ;
177
+ site . page = site . page || config . pageUrl || window . location . href ;
178
+
179
+ const referer = bidderRequest . refererInfo && bidderRequest . refererInfo . referer ;
180
+ if ( ! site . ref && referer ) {
181
+ site . ref = referer ;
182
+ }
183
+
184
+ return site ;
185
+ }
186
+
187
+ function buildRequestDevice ( ) {
188
+ return {
189
+ ua : navigator . userAgent
190
+ } ;
191
+ }
192
+
53
193
registerBidder ( spec ) ;
0 commit comments