• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / 16197995703

10 Jul 2025 02:32PM UTC coverage: 96.232% (+0.003%) from 96.229%
16197995703

push

github

web-flow
Linting: remove exception (#13518)

* bump coveralls

* remove exceptions

* results

* eslint fix

* Update package-lock.json

* Update package-lock.json

* Core: remove codex comments and unused lint rule (#13520)

---------

Co-authored-by: Demetrio Girardi <dgirardi@prebid.org>

39174 of 48116 branches covered (81.42%)

9842 of 9975 new or added lines in 861 files covered. (98.67%)

15 existing lines in 8 files now uncovered.

192483 of 200020 relevant lines covered (96.23%)

88.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.92
/modules/advRedAnalyticsAdapter.js
1
import {generateUUID, logInfo} from '../src/utils.js'
1✔
2
import {ajaxBuilder} from '../src/ajax.js'
3
import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js'
4
import adapterManager from '../src/adapterManager.js'
5
import {EVENTS} from '../src/constants.js'
6
import {getRefererInfo} from '../src/refererDetection.js';
7

8
/**
9
 * advRedAnalyticsAdapter.js - analytics adapter for AdvRed
10
 */
11
const DEFAULT_EVENT_URL = 'https://api.adv.red/api/event'
1✔
12

13
const ajax = ajaxBuilder(10000)
1✔
14
let pwId
15
let initOptions
16
let flushInterval
17
let queue = []
1✔
18

19
const advRedAnalytics = Object.assign(adapter({url: DEFAULT_EVENT_URL, analyticsType: 'endpoint'}), {
1✔
20
  track({eventType, args}) {
14✔
21
    handleEvent(eventType, args)
14✔
22
  }
23
})
24

25
function sendEvents() {
26
  if (queue.length > 0) {
7✔
27
    const message = {
5✔
28
      pwId: pwId,
29
      publisherId: initOptions.publisherId,
30
      events: queue,
31
      pageUrl: getRefererInfo().page
32
    }
33
    queue = []
5✔
34

35
    const url = initOptions.url ? initOptions.url : DEFAULT_EVENT_URL
5!
36
    ajax(
5✔
37
      url,
38
      () => logInfo('AdvRed Analytics sent ' + queue.length + ' events'),
×
39
      JSON.stringify(message),
40
      {
41
        method: 'POST',
42
        contentType: 'application/json',
43
        withCredentials: true
44
      }
45
    )
46
  }
47
}
48

49
function convertAdUnit(adUnit) {
50
  if (!adUnit) return adUnit
×
51

52
  const shortAdUnit = {}
×
53
  shortAdUnit.code = adUnit.code
×
54
  shortAdUnit.sizes = adUnit.sizes
×
55
  return shortAdUnit
×
56
}
57

58
function convertBid(bid) {
59
  if (!bid) return bid
×
60

61
  const shortBid = {}
×
62
  shortBid.adUnitCode = bid.adUnitCode
×
63
  shortBid.bidder = bid.bidder
×
64
  shortBid.cpm = bid.cpm
×
65
  shortBid.currency = bid.currency
×
66
  shortBid.mediaTypes = bid.mediaTypes
×
67
  shortBid.sizes = bid.sizes
×
68
  shortBid.serverResponseTimeMs = bid.serverResponseTimeMs
×
69
  return shortBid
×
70
}
71

72
function convertAuctionInit(origEvent) {
73
  const shortEvent = {}
2✔
74
  shortEvent.auctionId = origEvent.auctionId
2✔
75
  shortEvent.timeout = origEvent.timeout
2✔
76
  shortEvent.adUnits = origEvent.adUnits && origEvent.adUnits.map(convertAdUnit)
2!
77
  return shortEvent
2✔
78
}
79

80
function convertBidRequested(origEvent) {
81
  const shortEvent = {}
2✔
82
  shortEvent.bidderCode = origEvent.bidderCode
2✔
83
  shortEvent.bids = origEvent.bids && origEvent.bids.map(convertBid)
2!
84
  shortEvent.timeout = origEvent.timeout
2✔
85
  return shortEvent
2✔
86
}
87

88
function convertBidTimeout(origEvent) {
NEW
89
  const shortEvent = {}
×
90
  shortEvent.bids = origEvent && origEvent.map ? origEvent.map(convertBid) : origEvent
×
91
  return shortEvent
×
92
}
93

94
function convertBidderError(origEvent) {
NEW
95
  const shortEvent = {}
×
96
  shortEvent.bids = origEvent.bidderRequest && origEvent.bidderRequest.bids && origEvent.bidderRequest.bids.map(convertBid)
×
97
  return shortEvent
×
98
}
99

100
function convertAuctionEnd(origEvent) {
101
  const shortEvent = {}
2✔
102
  shortEvent.adUnitCodes = origEvent.adUnitCodes
2✔
103
  shortEvent.bidsReceived = origEvent.bidsReceived && origEvent.bidsReceived.map(convertBid)
2!
104
  shortEvent.noBids = origEvent.noBids && origEvent.noBids.map(convertBid)
2!
105
  return shortEvent
2✔
106
}
107

108
function convertBidWon(origEvent) {
109
  const shortEvent = {}
4✔
110
  shortEvent.adUnitCode = origEvent.adUnitCode
4✔
111
  shortEvent.bidderCode = origEvent.bidderCode
4✔
112
  shortEvent.mediaType = origEvent.mediaType
4✔
113
  shortEvent.netRevenue = origEvent.netRevenue
4✔
114
  shortEvent.cpm = origEvent.cpm
4✔
115
  shortEvent.size = origEvent.size
4✔
116
  shortEvent.currency = origEvent.currency
4✔
117
  return shortEvent
4✔
118
}
119

120
function handleEvent(eventType, origEvent) {
121
  try {
14✔
122
    origEvent = origEvent ? JSON.parse(JSON.stringify(origEvent)) : {}
14!
123
  } catch (e) {
124
  }
125

126
  let shortEvent
127
  switch (eventType) {
14!
128
    case EVENTS.AUCTION_INIT: {
129
      shortEvent = convertAuctionInit(origEvent)
2✔
130
      break
2✔
131
    }
132
    case EVENTS.BID_REQUESTED: {
133
      shortEvent = convertBidRequested(origEvent)
2✔
134
      break
2✔
135
    }
136
    case EVENTS.BID_TIMEOUT: {
137
      shortEvent = convertBidTimeout(origEvent)
×
138
      break
×
139
    }
140
    case EVENTS.BIDDER_ERROR: {
141
      shortEvent = convertBidderError(origEvent)
×
142
      break
×
143
    }
144
    case EVENTS.AUCTION_END: {
145
      shortEvent = convertAuctionEnd(origEvent)
2✔
146
      break
2✔
147
    }
148
    case EVENTS.BID_WON: {
149
      shortEvent = convertBidWon(origEvent)
4✔
150
      break
4✔
151
    }
152
    default:
153
      return
4✔
154
  }
155

156
  shortEvent.eventType = eventType
10✔
157
  shortEvent.auctionId = origEvent.auctionId
10✔
158
  shortEvent.timestamp = origEvent.timestamp || Date.now()
10✔
159

160
  sendEvent(shortEvent)
10✔
161
}
162

163
function sendEvent(event) {
164
  queue.push(event)
10✔
165

166
  if (event.eventType === EVENTS.AUCTION_END) {
10✔
167
    sendEvents()
2✔
168
  }
169
}
170

171
advRedAnalytics.originEnableAnalytics = advRedAnalytics.enableAnalytics
1✔
172
advRedAnalytics.enableAnalytics = function (config) {
1✔
173
  initOptions = config.options || {}
4!
174
  pwId = generateUUID()
4✔
175
  flushInterval = setInterval(sendEvents, 1000)
4✔
176

177
  advRedAnalytics.originEnableAnalytics(config)
4✔
178
}
179

180
advRedAnalytics.originDisableAnalytics = advRedAnalytics.disableAnalytics
1✔
181
advRedAnalytics.disableAnalytics = function () {
1✔
182
  clearInterval(flushInterval)
4✔
183
  sendEvents()
4✔
184
  advRedAnalytics.originDisableAnalytics()
4✔
185
}
186

187
adapterManager.registerAnalyticsAdapter({
1✔
188
  adapter: advRedAnalytics,
189
  code: 'advRed'
190
})
191

192
advRedAnalytics.getOptions = function () {
1✔
193
  return initOptions
1✔
194
}
195

196
advRedAnalytics.sendEvents = sendEvents
1✔
197

198
export default advRedAnalytics
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc