@@ -194,18 +194,36 @@ function _createServerRequest({bidRequest, gdprConsent = {}, uspConsent, pageUrl
194
194
// therefore in ad targetting process
195
195
ttxRequest . id = bidRequest . bidId ;
196
196
197
- // Set GDPR related fields
198
- ttxRequest . user = {
199
- ext : {
200
- consent : gdprConsent . consentString
201
- }
202
- } ;
203
- ttxRequest . regs = {
204
- ext : {
205
- gdpr : ( gdprConsent . gdprApplies === true ) ? 1 : 0 ,
206
- us_privacy : uspConsent || null
207
- }
208
- } ;
197
+ if ( gdprConsent . consentString ) {
198
+ ttxRequest . user = setExtension (
199
+ ttxRequest . user ,
200
+ 'consent' ,
201
+ gdprConsent . consentString
202
+ )
203
+ }
204
+
205
+ if ( Array . isArray ( bidRequest . userIdAsEids ) && bidRequest . userIdAsEids . length > 0 ) {
206
+ ttxRequest . user = setExtension (
207
+ ttxRequest . user ,
208
+ 'eids' ,
209
+ bidRequest . userIdAsEids
210
+ )
211
+ }
212
+
213
+ ttxRequest . regs = setExtension (
214
+ ttxRequest . regs ,
215
+ 'gdpr' ,
216
+ Number ( gdprConsent . gdprApplies )
217
+ ) ;
218
+
219
+ if ( uspConsent ) {
220
+ ttxRequest . regs = setExtension (
221
+ ttxRequest . regs ,
222
+ 'us_privacy' ,
223
+ uspConsent
224
+ )
225
+ }
226
+
209
227
ttxRequest . ext = {
210
228
ttx : {
211
229
prebidStartedAt : Date . now ( ) ,
@@ -217,11 +235,11 @@ function _createServerRequest({bidRequest, gdprConsent = {}, uspConsent, pageUrl
217
235
} ;
218
236
219
237
if ( bidRequest . schain ) {
220
- ttxRequest . source = {
221
- ext : {
222
- schain : bidRequest . schain
223
- }
224
- }
238
+ ttxRequest . source = setExtension (
239
+ ttxRequest . source ,
240
+ ' schain' ,
241
+ bidRequest . schain
242
+ )
225
243
}
226
244
227
245
// Finally, set the openRTB 'test' param if this is to be a test bid
@@ -250,6 +268,15 @@ function _createServerRequest({bidRequest, gdprConsent = {}, uspConsent, pageUrl
250
268
}
251
269
}
252
270
271
+ // BUILD REQUESTS: SET EXTENSIONS
272
+ function setExtension ( obj = { } , key , value ) {
273
+ return Object . assign ( { } , obj , {
274
+ ext : Object . assign ( { } , obj . ext , {
275
+ [ key ] : value
276
+ } )
277
+ } ) ;
278
+ }
279
+
253
280
// BUILD REQUESTS: SIZE INFERENCE
254
281
function _transformSizes ( sizes ) {
255
282
if ( utils . isArray ( sizes ) && sizes . length === 2 && ! utils . isArray ( sizes [ 0 ] ) ) {
0 commit comments