@@ -95,7 +95,8 @@ export function getModuleConfig(customModuleConfig) {
95
95
/**
96
96
* Sets ortb2 config for ac bidders
97
97
* @param {Object } bidderOrtb2 - The ortb2 object for the all bidders
98
- * @param {Object } customModuleConfig - Publisher config for module
98
+ * @param {Object } moduleConfig - Publisher config for module
99
+ * @param {Object } segmentData - Segment data grouped by bidder or type
99
100
*/
100
101
export function setBidderRtb ( bidderOrtb2 , moduleConfig , segmentData ) {
101
102
const acBidders = deepAccess ( moduleConfig , 'params.acBidders' )
@@ -129,13 +130,13 @@ export function setBidderRtb (bidderOrtb2, moduleConfig, segmentData) {
129
130
130
131
/**
131
132
* Updates `user.data` object in existing bidder config with Permutive segments
132
- * @param string bidder - The bidder
133
+ * @param { string } bidder - The bidder identifier
133
134
* @param {Object } currConfig - Current bidder config
134
- * @param {Object[] } transformationConfigs - array of objects with `id` and `config` properties, used to determine
135
- * the transformations on user data to include the ORTB2 object
136
135
* @param {string[] } segmentIDs - Permutive segment IDs
137
136
* @param {string[] } sspSegmentIDs - Permutive SSP segment IDs
138
137
* @param {Object } topics - Privacy Sandbox Topics, keyed by IAB taxonomy version (600, 601, etc.)
138
+ * @param {Object[] } transformationConfigs - array of objects with `id` and `config` properties, used to determine
139
+ * the transformations on user data to include the ORTB2 object
139
140
* @param {Object } segmentData - The segments available for targeting
140
141
* @return {Object } Merged ortb2 object
141
142
*/
@@ -270,7 +271,7 @@ function setSegments (reqBidsConfigObj, moduleConfig, segmentData) {
270
271
*/
271
272
function makeSafe ( fn ) {
272
273
try {
273
- fn ( )
274
+ return fn ( )
274
275
} catch ( e ) {
275
276
logError ( e )
276
277
}
@@ -310,23 +311,71 @@ export function isPermutiveOnPage () {
310
311
* @param {number } maxSegs - Maximum number of segments to be included
311
312
* @return {Object }
312
313
*/
313
- export function getSegments ( maxSegs ) {
314
- const legacySegs = readSegments ( '_psegs' , [ ] ) . map ( Number ) . filter ( seg => seg >= 1000000 ) . map ( String )
315
- const _ppam = readSegments ( '_ppam' , [ ] )
316
- const _pcrprs = readSegments ( '_pcrprs' , [ ] )
317
-
314
+ export function getSegments ( maxSegs ) {
318
315
const segments = {
319
- ac : [ ..._pcrprs , ..._ppam , ...legacySegs ] ,
320
- ix : readSegments ( '_pindexs' , [ ] ) ,
321
- rubicon : readSegments ( '_prubicons' , [ ] ) ,
322
- appnexus : readSegments ( '_papns' , [ ] ) ,
323
- gam : readSegments ( '_pdfps' , [ ] ) ,
324
- ssp : readSegments ( '_pssps' , {
325
- cohorts : [ ] ,
326
- ssps : [ ]
316
+ ac :
317
+ makeSafe ( ( ) => {
318
+ const legacySegs =
319
+ makeSafe ( ( ) =>
320
+ readSegments ( '_psegs' , [ ] )
321
+ . map ( Number )
322
+ . filter ( ( seg ) => seg >= 1000000 )
323
+ . map ( String ) ,
324
+ ) || [ ] ;
325
+ const _ppam = makeSafe ( ( ) => readSegments ( '_ppam' , [ ] ) . map ( String ) ) || [ ] ;
326
+ const _pcrprs = makeSafe ( ( ) => readSegments ( '_pcrprs' , [ ] ) . map ( String ) ) || [ ] ;
327
+
328
+ return [ ..._pcrprs , ..._ppam , ...legacySegs ] ;
329
+ } ) || [ ] ,
330
+
331
+ ix :
332
+ makeSafe ( ( ) => {
333
+ const _pindexs = readSegments ( '_pindexs' , [ ] ) ;
334
+ return _pindexs . map ( String ) ;
335
+ } ) || [ ] ,
336
+
337
+ rubicon :
338
+ makeSafe ( ( ) => {
339
+ const _prubicons = readSegments ( '_prubicons' , [ ] ) ;
340
+ return _prubicons . map ( String ) ;
341
+ } ) || [ ] ,
342
+
343
+ appnexus :
344
+ makeSafe ( ( ) => {
345
+ const _papns = readSegments ( '_papns' , [ ] ) ;
346
+ return _papns . map ( String ) ;
347
+ } ) || [ ] ,
348
+
349
+ gam :
350
+ makeSafe ( ( ) => {
351
+ const _pdfps = readSegments ( '_pdfps' , [ ] ) ;
352
+ return _pdfps . map ( String ) ;
353
+ } ) || [ ] ,
354
+
355
+ ssp : makeSafe ( ( ) => {
356
+ const _pssps = readSegments ( '_pssps' , {
357
+ cohorts : [ ] ,
358
+ ssps : [ ] ,
359
+ } ) ;
360
+
361
+ return {
362
+ cohorts : makeSafe ( ( ) => _pssps . cohorts . map ( String ) ) || [ ] ,
363
+ ssps : makeSafe ( ( ) => _pssps . ssps . map ( String ) ) || [ ] ,
364
+ } ;
327
365
} ) ,
328
- topics : readSegments ( '_ppsts' , { } ) ,
329
- }
366
+
367
+ topics :
368
+ makeSafe ( ( ) => {
369
+ const _ppsts = readSegments ( '_ppsts' , { } ) ;
370
+
371
+ const topics = { } ;
372
+ for ( const [ k , value ] of Object . entries ( _ppsts ) ) {
373
+ topics [ k ] = makeSafe ( ( ) => value . map ( String ) ) || [ ] ;
374
+ }
375
+
376
+ return topics ;
377
+ } ) || { } ,
378
+ } ;
330
379
331
380
for ( const bidder in segments ) {
332
381
if ( bidder === 'ssp' ) {
@@ -342,7 +391,8 @@ export function getSegments (maxSegs) {
342
391
}
343
392
}
344
393
345
- return segments
394
+ logger . logInfo ( `Read segments` , segments )
395
+ return segments ;
346
396
}
347
397
348
398
/**
@@ -393,7 +443,7 @@ function iabSegmentId(permutiveSegmentId, iabIds) {
393
443
* Pull the latest configuration and cohort information and update accordingly.
394
444
*
395
445
* @param reqBidsConfigObj - Bidder provided config for request
396
- * @param customModuleConfig - Publisher provide config
446
+ * @param moduleConfig - Publisher provided config
397
447
*/
398
448
export function readAndSetCohorts ( reqBidsConfigObj , moduleConfig ) {
399
449
const segmentData = getSegments ( deepAccess ( moduleConfig , 'params.maxSegs' ) )
0 commit comments