@@ -17,10 +17,11 @@ import CONSTANTS from '../src/constants.json';
17
17
const BIDDER_CODE = 'setupad' ;
18
18
const ENDPOINT = 'https://prebid.setupad.io/openrtb2/auction' ;
19
19
const SYNC_ENDPOINT = 'https://cookie.stpd.cloud/sync?' ;
20
- const REPORT_ENDPOINT = 'https://adapter-analytics.azurewebsites.net/api/adapter-analytics ' ;
20
+ const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io ' ;
21
21
const GVLID = 1241 ;
22
22
const TIME_TO_LIVE = 360 ;
23
- const allBidders = { } ;
23
+ const biddersCpms = { } ;
24
+ const biddersCreativeIds = { } ;
24
25
25
26
const sendingDataStatistic = initSendingDataStatistic ( ) ;
26
27
events . on ( CONSTANTS . EVENTS . AUCTION_INIT , ( ) => {
@@ -75,7 +76,6 @@ export const spec = {
75
76
device,
76
77
site,
77
78
imp : [ ] ,
78
- test : 1 ,
79
79
} ;
80
80
81
81
const imp = {
@@ -171,10 +171,8 @@ export const spec = {
171
171
} ;
172
172
173
173
// Set all bidders obj for later use in getPixelUrl()
174
- allBidders [ res . seat ] = { } ;
175
- allBidders [ res . seat ] . cpm = bidResponse . cpm ;
176
- allBidders [ res . seat ] . currency = bidResponse . currency ;
177
- allBidders [ res . seat ] . creativeId = bidResponse . creativeId ;
174
+ biddersCpms [ res . seat ] = bidResponse . cpm ;
175
+ biddersCreativeIds [ res . seat ] = bidResponse . creativeId ;
178
176
179
177
bidResponse . ad = ad ;
180
178
bidResponse . adUrl = adUrl ;
@@ -215,7 +213,7 @@ export const spec = {
215
213
getPixelUrl : function ( eventName , bid , timestamp ) {
216
214
let bidder = bid . bidder || bid . bidderCode ;
217
215
const auctionId = bid . auctionId ;
218
- if ( bidder != BIDDER_CODE ) return ;
216
+ if ( bidder !== BIDDER_CODE ) return ;
219
217
220
218
let params ;
221
219
if ( bid . params ) {
@@ -239,31 +237,28 @@ export const spec = {
239
237
if ( ! placementIds ) return ;
240
238
241
239
let extraBidParams = '' ;
242
- // additional params on bidWon
243
- if ( eventName === 'bidWon' ) {
244
- extraBidParams = `&cpm=${ bid . originalCpm } ¤cy=${ bid . originalCurrency } ` ;
240
+
241
+ if ( eventName === CONSTANTS . EVENTS . BID_RESPONSE ) {
242
+ bidder = JSON . stringify ( biddersCpms ) ;
243
+
244
+ // Add extra parameters
245
+ extraBidParams = `¤cy=${ bid . originalCurrency } ` ;
245
246
}
246
247
247
- if ( eventName === 'bidResponse' ) {
248
- // Exclude not needed creativeId key for bidResponse bidders
249
- const filteredBidders = Object . fromEntries (
250
- Object . entries ( allBidders ) . map ( ( [ bidderKey , bidderObj ] ) => [
251
- bidderKey ,
252
- Object . fromEntries ( Object . entries ( bidderObj ) . filter ( ( [ key ] ) => key !== 'creativeId' ) ) ,
253
- ] )
254
- ) ;
255
- bidder = JSON . stringify ( filteredBidders ) ;
256
- } else if ( eventName === 'bidWon' ) {
248
+ if ( eventName === CONSTANTS . EVENTS . BID_WON ) {
257
249
// Iterate through all bidders to find the winning bidder by using creativeId as identification
258
- for ( const bidderName in allBidders ) {
250
+ for ( const bidderName in biddersCreativeIds ) {
259
251
if (
260
- allBidders . hasOwnProperty ( bidderName ) &&
261
- allBidders [ bidderName ] . creativeId === bid . creativeId
252
+ biddersCreativeIds . hasOwnProperty ( bidderName ) &&
253
+ biddersCreativeIds [ bidderName ] === bid . creativeId
262
254
) {
263
255
bidder = bidderName ;
264
- break ; // Exit the loop once a match is found
256
+ break ; // Exit the loop if a match is found
265
257
}
266
258
}
259
+
260
+ // Add extra parameters
261
+ extraBidParams = `&cpm=${ bid . originalCpm } ¤cy=${ bid . originalCurrency } ` ;
267
262
}
268
263
269
264
const url = `${ REPORT_ENDPOINT } ?event=${ eventName } &bidder=${ bidder } &placementIds=${ placementIds } &auctionId=${ auctionId } ${ extraBidParams } ×tamp=${ timestamp } ` ;
@@ -357,6 +352,7 @@ function initSendingDataStatistic() {
357
352
358
353
disabledSending = false ;
359
354
enabledSending = false ;
355
+ auctionIds = { } ;
360
356
eventHendlers = { } ;
361
357
362
358
initEvents ( ) {
@@ -393,24 +389,21 @@ function initSendingDataStatistic() {
393
389
}
394
390
395
391
eventHandler ( eventName ) {
396
- const eventHandlerFunc = this . getEventHandler ( eventName ) ;
397
- if ( eventName == CONSTANTS . EVENTS . BID_TIMEOUT ) {
398
- return ( bids ) => {
399
- if ( this . disabledSending || ! Array . isArray ( bids ) ) return ;
400
-
401
- for ( let bid of bids ) {
402
- eventHandlerFunc ( bid ) ;
403
- }
404
- } ;
405
- }
406
-
407
- return eventHandlerFunc ;
392
+ return this . getEventHandler ( eventName ) ;
408
393
}
409
394
410
395
getEventHandler ( eventName ) {
411
396
return ( bid ) => {
412
397
if ( this . disabledSending ) return ;
413
-
398
+ if (
399
+ this . auctionIds [ bid . auctionId ] === bid . bidder &&
400
+ eventName === CONSTANTS . EVENTS . BID_RESPONSE
401
+ ) {
402
+ return ;
403
+ }
404
+ if ( eventName === CONSTANTS . EVENTS . BID_RESPONSE ) {
405
+ this . auctionIds [ bid . auctionId ] = bid . bidder ;
406
+ }
414
407
const url = spec . getPixelUrl ( eventName , bid , Date . now ( ) ) ;
415
408
if ( ! url ) return ;
416
409
triggerPixel ( url ) ;
0 commit comments