prebid.js 7.18.0 → 7.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/dist/33acrossBidAdapter.js +1 -1
  2. package/dist/adagioBidAdapter.js +1 -1
  3. package/dist/adbookpspBidAdapter.js +1 -1
  4. package/dist/adfBidAdapter.js +1 -1
  5. package/dist/adgenerationBidAdapter.js +1 -1
  6. package/dist/adqueryIdSystem.js +1 -1
  7. package/dist/adrelevantisBidAdapter.js +1 -1
  8. package/dist/adtrgtmeBidAdapter.js +1 -1
  9. package/dist/adxcgBidAdapter.js +1 -1
  10. package/dist/ajaBidAdapter.js +1 -1
  11. package/dist/amxBidAdapter.js +1 -1
  12. package/dist/amxIdSystem.js +1 -1
  13. package/dist/appierAnalyticsAdapter.js +1 -1
  14. package/dist/appnexusBidAdapter.js +1 -1
  15. package/dist/asoBidAdapter.js +1 -1
  16. package/dist/axonixBidAdapter.js +1 -1
  17. package/dist/{andBeyondMediaBidAdapter.js → beyondmediaBidAdapter.js} +1 -1
  18. package/dist/bidglassBidAdapter.js +1 -1
  19. package/dist/big-richmediaBidAdapter.js +1 -1
  20. package/dist/bridgewellBidAdapter.js +1 -1
  21. package/dist/brightMountainMediaBidAdapter.js +1 -1
  22. package/dist/carodaBidAdapter.js +1 -1
  23. package/dist/cleanioRtdProvider.js +1 -1
  24. package/dist/colossussspBidAdapter.js +1 -1
  25. package/dist/concertBidAdapter.js +1 -1
  26. package/dist/connectadBidAdapter.js +1 -1
  27. package/dist/consumableBidAdapter.js +1 -1
  28. package/dist/conversantAnalyticsAdapter.js +1 -0
  29. package/dist/conversantBidAdapter.js +1 -1
  30. package/dist/craftBidAdapter.js +1 -1
  31. package/dist/criteoBidAdapter.js +1 -1
  32. package/dist/debugging-standalone.js +1 -1
  33. package/dist/debugging.js +1 -1
  34. package/dist/dependencies.json +6 -0
  35. package/dist/dgkeywordRtdProvider.js +1 -1
  36. package/dist/dianomiBidAdapter.js +1 -1
  37. package/dist/dspxBidAdapter.js +1 -1
  38. package/dist/enrichmentFpdModule.js +1 -1
  39. package/dist/eplanningBidAdapter.js +1 -1
  40. package/dist/finativeBidAdapter.js +1 -1
  41. package/dist/fpd.js +1 -0
  42. package/dist/glimpseBidAdapter.js +1 -1
  43. package/dist/gmosspBidAdapter.js +1 -1
  44. package/dist/goldbachBidAdapter.js +1 -1
  45. package/dist/gridBidAdapter.js +1 -1
  46. package/dist/gridNMBidAdapter.js +1 -1
  47. package/dist/gumgumBidAdapter.js +1 -1
  48. package/dist/h12mediaBidAdapter.js +1 -1
  49. package/dist/id5IdSystem.js +1 -1
  50. package/dist/improvedigitalBidAdapter.js +1 -1
  51. package/dist/inmarBidAdapter.js +1 -1
  52. package/dist/insticatorBidAdapter.js +1 -1
  53. package/dist/ixBidAdapter.js +1 -1
  54. package/dist/justpremiumBidAdapter.js +1 -1
  55. package/dist/konduitAnalyticsAdapter.js +1 -1
  56. package/dist/kueezBidAdapter.js +1 -1
  57. package/dist/lassoBidAdapter.js +1 -1
  58. package/dist/lifestreetBidAdapter.js +1 -1
  59. package/dist/liveIntentIdSystem.js +1 -1
  60. package/dist/liveyieldAnalyticsAdapter.js +1 -1
  61. package/dist/logicadBidAdapter.js +1 -1
  62. package/dist/loglyliftBidAdapter.js +1 -1
  63. package/dist/malltvAnalyticsAdapter.js +1 -1
  64. package/dist/marsmediaBidAdapter.js +1 -1
  65. package/dist/mediafuseBidAdapter.js +1 -1
  66. package/dist/mediakeysBidAdapter.js +1 -1
  67. package/dist/mediasquareBidAdapter.js +1 -1
  68. package/dist/mgidBidAdapter.js +1 -1
  69. package/dist/minutemediaBidAdapter.js +1 -1
  70. package/dist/nativoBidAdapter.js +1 -1
  71. package/dist/not-for-prod/prebid.js +123 -121
  72. package/dist/oguryBidAdapter.js +1 -1
  73. package/dist/onetagBidAdapter.js +1 -1
  74. package/dist/ooloAnalyticsAdapter.js +1 -1
  75. package/dist/outbrainBidAdapter.js +1 -1
  76. package/dist/parrableIdSystem.js +1 -1
  77. package/dist/pixfutureBidAdapter.js +1 -1
  78. package/dist/prebid-core.js +1 -1
  79. package/dist/prebidServerBidAdapter.js +1 -1
  80. package/dist/publinkIdSystem.js +1 -1
  81. package/dist/pubmaticBidAdapter.js +1 -1
  82. package/dist/pubwiseAnalyticsAdapter.js +1 -1
  83. package/dist/pxyzBidAdapter.js +1 -1
  84. package/dist/quantcastBidAdapter.js +1 -1
  85. package/dist/readpeakBidAdapter.js +1 -1
  86. package/dist/relaidoBidAdapter.js +1 -1
  87. package/dist/rhythmoneBidAdapter.js +1 -1
  88. package/dist/riseBidAdapter.js +1 -1
  89. package/dist/rubiconAnalyticsAdapter.js +1 -1
  90. package/dist/rubiconBidAdapter.js +1 -1
  91. package/dist/seedingAllianceBidAdapter.js +1 -1
  92. package/dist/seedtagBidAdapter.js +1 -1
  93. package/dist/sharethroughAnalyticsAdapter.js +1 -1
  94. package/dist/sharethroughBidAdapter.js +1 -1
  95. package/dist/shinezBidAdapter.js +1 -1
  96. package/dist/smaatoBidAdapter.js +1 -1
  97. package/dist/smartadserverBidAdapter.js +1 -1
  98. package/dist/smartxBidAdapter.js +1 -1
  99. package/dist/smilewantedBidAdapter.js +1 -1
  100. package/dist/sonobiBidAdapter.js +1 -1
  101. package/dist/sovrnAnalyticsAdapter.js +1 -1
  102. package/dist/sovrnBidAdapter.js +1 -1
  103. package/dist/sspBCBidAdapter.js +1 -1
  104. package/dist/sublimeBidAdapter.js +1 -1
  105. package/dist/synacormediaBidAdapter.js +1 -1
  106. package/dist/taboolaBidAdapter.js +1 -1
  107. package/dist/targetVideoBidAdapter.js +1 -1
  108. package/dist/teadsBidAdapter.js +1 -1
  109. package/dist/trionBidAdapter.js +1 -1
  110. package/dist/tripleliftBidAdapter.js +1 -1
  111. package/dist/ttdBidAdapter.js +1 -1
  112. package/dist/ucfunnelAnalyticsAdapter.js +1 -1
  113. package/dist/underdogmediaBidAdapter.js +1 -1
  114. package/dist/undertoneBidAdapter.js +1 -1
  115. package/dist/vidazooBidAdapter.js +1 -1
  116. package/dist/videobyteBidAdapter.js +1 -1
  117. package/dist/visxBidAdapter.js +1 -1
  118. package/dist/vuukleBidAdapter.js +1 -1
  119. package/dist/widespaceBidAdapter.js +1 -1
  120. package/dist/winrBidAdapter.js +1 -1
  121. package/dist/yahoosspBidAdapter.js +1 -1
  122. package/dist/yandexBidAdapter.js +1 -1
  123. package/dist/yieldmoBidAdapter.js +1 -1
  124. package/dist/yieldoneAnalyticsAdapter.js +1 -1
  125. package/libraries/fpd/sua.js +98 -0
  126. package/modules/adfBidAdapter.js +1 -1
  127. package/modules/adkernelAdnBidAdapter.js +1 -0
  128. package/modules/adqueryIdSystem.js +8 -8
  129. package/modules/adxcgBidAdapter.js +1 -1
  130. package/modules/amxBidAdapter.js +1 -1
  131. package/modules/{andBeyondMediaBidAdapter.js → beyondmediaBidAdapter.js} +0 -0
  132. package/modules/{andBeyondMediaBidAdapter.md → beyondmediaBidAdapter.md} +1 -1
  133. package/modules/cleanioRtdProvider.js +3 -4
  134. package/modules/colossussspBidAdapter.js +2 -1
  135. package/modules/conversantAnalyticsAdapter.js +560 -0
  136. package/modules/conversantAnalyticsAdapter.md +47 -0
  137. package/modules/criteoBidAdapter.js +1 -1
  138. package/modules/debugging/bidInterceptor.js +2 -2
  139. package/modules/debugging/debugging.js +10 -2
  140. package/modules/dgkeywordRtdProvider.js +21 -3
  141. package/modules/dianomiBidAdapter.js +1 -1
  142. package/modules/enrichmentFpdModule.js +33 -14
  143. package/modules/finativeBidAdapter.js +1 -1
  144. package/modules/gridBidAdapter.js +187 -117
  145. package/modules/improvedigitalBidAdapter.js +2 -2
  146. package/modules/ixBidAdapter.js +94 -23
  147. package/modules/liveIntentIdSystem.js +39 -5
  148. package/modules/mediakeysBidAdapter.js +6 -1
  149. package/modules/mediakeysBidAdapter.md +50 -40
  150. package/modules/nativoBidAdapter.js +1 -1
  151. package/modules/prebidServerBidAdapter/index.js +44 -13
  152. package/modules/readpeakBidAdapter.js +1 -1
  153. package/modules/rubiconBidAdapter.js +2 -3
  154. package/modules/seedingAllianceBidAdapter.js +1 -1
  155. package/modules/sharethroughBidAdapter.js +1 -1
  156. package/modules/taboolaBidAdapter.js +1 -1
  157. package/modules/talkadsBidAdapter.js +1 -0
  158. package/modules/truereachBidAdapter.js +1 -0
  159. package/modules/ttdBidAdapter.js +1 -1
  160. package/modules/vuukleBidAdapter.js +34 -3
  161. package/modules/yahoosspBidAdapter.js +3 -1
  162. package/modules/yandexBidAdapter.js +31 -8
  163. package/package.json +2 -2
  164. package/src/adapterManager.js +2 -4
  165. package/src/cpmBucketManager.js +22 -3
  166. package/src/native.js +1 -5
  167. package/src/prebid.js +3 -3
  168. package/test/spec/cpmBucketManager_spec.js +239 -177
  169. package/test/spec/fpd/sua_spec.js +244 -0
  170. package/test/spec/modules/adfBidAdapter_spec.js +2 -3
  171. package/test/spec/modules/adqueryIdSystem_spec.js +0 -2
  172. package/test/spec/modules/adxcgBidAdapter_spec.js +2 -3
  173. package/test/spec/modules/amxBidAdapter_spec.js +3 -2
  174. package/test/spec/modules/{andBeyondMediaBidAdapter_spec.js → beyondmediaBidAdapter_spec.js} +1 -1
  175. package/test/spec/modules/colossussspBidAdapter_spec.js +4 -2
  176. package/test/spec/modules/conversantAnalyticsAdapter_spec.js +963 -0
  177. package/test/spec/modules/debugging_mod_spec.js +9 -0
  178. package/test/spec/modules/dgkeywordRtdProvider_spec.js +83 -1
  179. package/test/spec/modules/dianomiBidAdapter_spec.js +2 -3
  180. package/test/spec/modules/enrichmentFpdModule_spec.js +50 -7
  181. package/test/spec/modules/fpdModule_spec.js +9 -0
  182. package/test/spec/modules/gridBidAdapter_spec.js +87 -31
  183. package/test/spec/modules/ixBidAdapter_spec.js +221 -2
  184. package/test/spec/modules/liveIntentIdMinimalSystem_spec.js +62 -8
  185. package/test/spec/modules/liveIntentIdSystem_spec.js +62 -8
  186. package/test/spec/modules/mediakeysBidAdapter_spec.js +20 -3
  187. package/test/spec/modules/nativoBidAdapter_spec.js +13 -2
  188. package/test/spec/modules/prebidServerBidAdapter_spec.js +159 -4
  189. package/test/spec/modules/seedtagBidAdapter_spec.js +15 -18
  190. package/test/spec/modules/sharethroughBidAdapter_spec.js +2 -1
  191. package/test/spec/modules/taboolaBidAdapter_spec.js +2 -2
  192. package/test/spec/modules/ttdBidAdapter_spec.js +3 -3
  193. package/test/spec/modules/vuukleBidAdapter_spec.js +87 -0
  194. package/test/spec/modules/yahoosspBidAdapter_spec.js +3 -1
  195. package/test/spec/modules/yandexBidAdapter_spec.js +8 -5
  196. package/test/spec/native_spec.js +5 -0
  197. package/test/spec/unit/pbjs_api_spec.js +44 -0
@@ -0,0 +1,560 @@
1
+ import {ajax} from '../src/ajax.js';
2
+ import adapter from '../libraries/analyticsAdapter/AnalyticsAdapter.js';
3
+ import CONSTANTS from '../src/constants.json';
4
+ import {getGlobal} from '../src/prebidGlobal.js';
5
+ import adapterManager from '../src/adapterManager.js';
6
+ import {logInfo, logError, logMessage, deepAccess, isInteger} from '../src/utils.js';
7
+
8
+ const {
9
+ EVENTS: { AUCTION_END, AD_RENDER_FAILED, BID_TIMEOUT, BID_WON }
10
+ } = CONSTANTS;
11
+ const GVLID = 24;
12
+ const ANALYTICS_TYPE = 'endpoint';
13
+
14
+ // for local testing set domain to 127.0.0.1:8290
15
+ const URL = 'https://web.hb.ad.cpe.dotomi.com/cvx/event/prebidanalytics';
16
+ const ANALYTICS_CODE = 'conversant';
17
+
18
+ export const CNVR_CONSTANTS = {
19
+ LOG_PREFIX: 'Conversant analytics adapter: ',
20
+ // Maximum time to keep an item in the cache before it gets purged
21
+ MAX_MILLISECONDS_IN_CACHE: 30000,
22
+ // How often cache cleanup will run
23
+ CACHE_CLEANUP_TIME_IN_MILLIS: 30000,
24
+ // Should be float from 0-1, 0 is turned off, 1 is sample every instance
25
+ DEFAULT_SAMPLE_RATE: 1,
26
+
27
+ // BID STATUS CODES
28
+ WIN: 10,
29
+ BID: 20,
30
+ NO_BID: 30,
31
+ TIMEOUT: 40,
32
+ RENDER_FAILED: 50
33
+ };
34
+
35
+ // Saves passed in options from the bid adapter
36
+ const initOptions = {};
37
+
38
+ // Simple flag to help handle any tear down needed on disable
39
+ let conversantAnalyticsEnabled = false;
40
+
41
+ export const cnvrHelper = {
42
+ // Turns on sampling for an instance of prebid analytics.
43
+ doSample: true,
44
+
45
+ /**
46
+ * Used to hold data for RENDER FAILED events so we can send a payload back that will match our original auction data.
47
+ * Contains the following key/value data:
48
+ * <adId> => {
49
+ * 'bidderCode': <bidderCode>,
50
+ * 'adUnitCode': <adUnitCode>,
51
+ * 'auctionId': <auctionId>,
52
+ * 'timeReceived': Date.now() //For cache cleaning
53
+ * }
54
+ */
55
+ adIdLookup: {},
56
+
57
+ /**
58
+ * Time out events happen before AUCTION END so we can save them in a cache and report them at the same time as the
59
+ * AUCTION END event. Has the following data and key is based off of auctionId, adUnitCode, bidderCode from
60
+ * keyStr = getLookupKey(auctionId, adUnitCode, bidderCode);
61
+ * <keyStr> => {
62
+ * timeReceived: Date.now() //so cache can be purged in case it doesn't get cleaned out at auctionEnd
63
+ * }
64
+ */
65
+ timeoutCache: {},
66
+
67
+ /**
68
+ * Lookup of auction IDs to auction start timestamps
69
+ */
70
+ auctionIdTimestampCache: {}
71
+ };
72
+
73
+ /**
74
+ * Cleanup timer for the adIdLookup and timeoutCache caches. If all works properly then the caches are self-cleaning
75
+ * but in case something goes sideways we poll periodically to cleanup old values to prevent a memory leak
76
+ */
77
+ let cacheCleanupInterval;
78
+
79
+ let conversantAnalytics = Object.assign(
80
+ adapter({URL, ANALYTICS_TYPE}),
81
+ {
82
+ track({eventType, args}) {
83
+ if (cnvrHelper.doSample) {
84
+ logMessage(CNVR_CONSTANTS.LOG_PREFIX + ' track(): ' + eventType, args);
85
+ switch (eventType) {
86
+ case AUCTION_END:
87
+ onAuctionEnd(args);
88
+ break;
89
+ case AD_RENDER_FAILED:
90
+ onAdRenderFailed(args);
91
+ break;
92
+ case BID_WON:
93
+ onBidWon(args);
94
+ break;
95
+ case BID_TIMEOUT:
96
+ onBidTimeout(args);
97
+ break;
98
+ } // END switch
99
+ } else {
100
+ logMessage(CNVR_CONSTANTS.LOG_PREFIX + ' - ' + eventType + ': skipped due to sampling');
101
+ }// END IF(cnvrHelper.doSample)
102
+ } // END track()
103
+ }
104
+ );
105
+
106
+ // ================================================== EVENT HANDLERS ===================================================
107
+ /**
108
+ * We get the list of timeouts before the endAution, cache them temporarily in a global cache and the endAuction event
109
+ * will pick them up. Uses getLookupKey() to create the key to the entry from auctionId, adUnitCode and bidderCode.
110
+ * Saves a single value of timeReceived so we can do cache purging periodically.
111
+ *
112
+ * Current assumption is that the timeout will always be an array even if it is just one object in the array.
113
+ * @param args [{
114
+ "bidId": "80882409358b8a8",
115
+ "bidder": "conversant",
116
+ "adUnitCode": "MedRect",
117
+ "auctionId": "afbd6e0b-e45b-46ab-87bf-c0bac0cb8881"
118
+ }, {
119
+ "bidId": "9da4c107a6f24c8",
120
+ "bidder": "conversant",
121
+ "adUnitCode": "Leaderboard",
122
+ "auctionId": "afbd6e0b-e45b-46ab-87bf-c0bac0cb8881"
123
+ }
124
+ ]
125
+ */
126
+ function onBidTimeout(args) {
127
+ args.forEach(timedOutBid => {
128
+ const timeoutCacheKey = cnvrHelper.getLookupKey(timedOutBid.auctionId, timedOutBid.adUnitCode, timedOutBid.bidder);
129
+ cnvrHelper.timeoutCache[timeoutCacheKey] = {
130
+ timeReceived: Date.now()
131
+ }
132
+ });
133
+ }
134
+
135
+ /**
136
+ * Bid won occurs after auctionEnd so we need to send this separately. We also save an entry in the adIdLookup cache
137
+ * so that if the render fails we can match up important data so we can send a valid RENDER FAILED event back.
138
+ * @param args bidWon args
139
+ */
140
+ function onBidWon(args) {
141
+ const bidderCode = args.bidderCode;
142
+ const adUnitCode = args.adUnitCode;
143
+ const auctionId = args.auctionId;
144
+ let timestamp = args.requestTimestamp ? args.requestTimestamp : Date.now();
145
+
146
+ // Make sure we have all the data we need
147
+ if (!bidderCode || !adUnitCode || !auctionId) {
148
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onBidWon() did not get all the necessary data to process the event.');
149
+ return;
150
+ }
151
+
152
+ if (cnvrHelper.auctionIdTimestampCache[auctionId]) {
153
+ timestamp = cnvrHelper.auctionIdTimestampCache[auctionId].timeReceived; // Don't delete, could be multiple winners/auction, allow cleanup to handle
154
+ }
155
+
156
+ const bidWonPayload = cnvrHelper.createPayload('bid_won', auctionId, timestamp);
157
+
158
+ const adUnitPayload = cnvrHelper.createAdUnit();
159
+ bidWonPayload.adUnits[adUnitCode] = adUnitPayload;
160
+
161
+ const bidPayload = cnvrHelper.createBid(CNVR_CONSTANTS.WIN, args.timeToRespond);
162
+ bidPayload.adSize = cnvrHelper.createAdSize(args.width, args.height);
163
+ bidPayload.cpm = args.cpm;
164
+ bidPayload.originalCpm = args.originalCpm;
165
+ bidPayload.currency = args.currency;
166
+ bidPayload.mediaType = args.mediaType;
167
+ adUnitPayload.bids[bidderCode] = [bidPayload];
168
+
169
+ if (!cnvrHelper.adIdLookup[args.adId]) {
170
+ cnvrHelper.adIdLookup[args.adId] = {
171
+ 'bidderCode': bidderCode,
172
+ 'adUnitCode': adUnitCode,
173
+ 'auctionId': auctionId,
174
+ 'timeReceived': Date.now() // For cache cleaning
175
+ };
176
+ }
177
+
178
+ sendData(bidWonPayload);
179
+ }
180
+
181
+ /**
182
+ * RENDER FAILED occurs after AUCTION END and BID WON, the payload does not have all the data we need so we use
183
+ * adIdLookup to pull data from a BID WON event to populate our payload
184
+ * @param args = {
185
+ * reason: <value>
186
+ * message: <value>
187
+ * adId: <value> --optional
188
+ * bid: {object?} --optional: unsure what this looks like but guessing it is {bidder: <value>, params: {object}}
189
+ * }
190
+ */
191
+ function onAdRenderFailed(args) {
192
+ const adId = args.adId;
193
+ // Make sure we have all the data we need, adId is optional so it's not guaranteed, without that we can't match it up
194
+ // to our adIdLookup data.
195
+ if (!adId || !cnvrHelper.adIdLookup[adId]) {
196
+ logError(CNVR_CONSTANTS.LOG_PREFIX + "onAdRenderFailed(): Unable to process RENDER FAILED because adId is missing or doesn't match a record in our cache.");
197
+ return; // Either no adId to match against a bidWon event, or no data saved from a bidWon event that matches the adId
198
+ }
199
+ const adIdObj = cnvrHelper.adIdLookup[adId];
200
+ const adUnitCode = adIdObj['adUnitCode'];
201
+ const bidderCode = adIdObj['bidderCode'];
202
+ const auctionId = adIdObj['auctionId'];
203
+ delete cnvrHelper.adIdLookup[adId]; // cleanup our cache
204
+
205
+ if (!bidderCode || !adUnitCode || !auctionId) {
206
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onAdRenderFailed(): Unable to process RENDER FAILED because lookup cache did not have all the data we required.');
207
+ return;
208
+ }
209
+
210
+ let timestamp = Date.now();
211
+ if (cnvrHelper.auctionIdTimestampCache[auctionId]) {
212
+ timestamp = cnvrHelper.auctionIdTimestampCache[auctionId].timeReceived; // Don't delete, could be multiple winners/auction, allow cleanup to handle
213
+ }
214
+
215
+ const renderFailedPayload = cnvrHelper.createPayload('render_failed', auctionId, timestamp);
216
+ const adUnitPayload = cnvrHelper.createAdUnit();
217
+ adUnitPayload.bids[bidderCode] = [cnvrHelper.createBid(CNVR_CONSTANTS.RENDER_FAILED, 0)];
218
+ adUnitPayload.bids[bidderCode][0].message = 'REASON: ' + args.reason + '. MESSAGE: ' + args.message;
219
+ renderFailedPayload.adUnits[adUnitCode] = adUnitPayload;
220
+ sendData(renderFailedPayload);
221
+ }
222
+
223
+ /**
224
+ * AUCTION END contains bid and no bid info and all of the auction info we need. This sends the bulk of the information
225
+ * about the auction back to the servers. It will also check the timeoutCache for any matching bids, if any are found
226
+ * then they will be removed from the cache and send back with this payload.
227
+ * @param args AUCTION END payload, fairly large data structure, main objects are 'adUnits[]', 'bidderRequests[]',
228
+ * 'noBids[]', 'bidsReceived[]'... 'winningBids[]' seems to be always blank.
229
+ */
230
+ function onAuctionEnd(args) {
231
+ const auctionId = args.auctionId;
232
+ if (!auctionId) {
233
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onAuctionEnd(): No auctionId in args supplied so unable to process event.');
234
+ return;
235
+ }
236
+
237
+ const auctionTimestamp = args.timestamp ? args.timestamp : Date.now();
238
+ cnvrHelper.auctionIdTimestampCache[auctionId] = { timeReceived: auctionTimestamp };
239
+
240
+ const auctionEndPayload = cnvrHelper.createPayload('auction_end', auctionId, auctionTimestamp);
241
+ // Get bid request information from adUnits
242
+ if (!Array.isArray(args.adUnits)) {
243
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onAuctionEnd(): adUnits not defined in arguments.');
244
+ return;
245
+ }
246
+
247
+ args.adUnits.forEach(adUnit => {
248
+ const cnvrAdUnit = cnvrHelper.createAdUnit();
249
+ // Initialize bids with bidderCode
250
+ adUnit.bids.forEach(bid => {
251
+ cnvrAdUnit.bids[bid.bidder] = []; // support multiple bids from a bidder for different sizes/media types //cnvrHelper.initializeBidDefaults();
252
+
253
+ // Check for cached timeout responses
254
+ const timeoutKey = cnvrHelper.getLookupKey(auctionId, adUnit.code, bid.bidder);
255
+ if (cnvrHelper.timeoutCache[timeoutKey]) {
256
+ cnvrAdUnit.bids[bid.bidder].push(cnvrHelper.createBid(CNVR_CONSTANTS.TIMEOUT, args.timeout));
257
+ delete cnvrHelper.timeoutCache[timeoutKey];
258
+ }
259
+ });
260
+
261
+ // Ad media types for the ad slot
262
+ if (cnvrHelper.keyExistsAndIsObject(adUnit, 'mediaTypes')) {
263
+ Object.entries(adUnit.mediaTypes).forEach(([mediaTypeName]) => {
264
+ cnvrAdUnit.mediaTypes.push(mediaTypeName);
265
+ });
266
+ }
267
+
268
+ // Ad sizes listed under the size key
269
+ if (Array.isArray(adUnit.sizes) && adUnit.sizes.length >= 1) {
270
+ adUnit.sizes.forEach(size => {
271
+ if (!Array.isArray(size) || size.length !== 2) {
272
+ logMessage(CNVR_CONSTANTS.LOG_PREFIX + 'Unknown object while retrieving adUnit sizes.', adUnit);
273
+ return; // skips to next item
274
+ }
275
+ cnvrAdUnit.sizes.push(cnvrHelper.createAdSize(size[0], size[1]));
276
+ });
277
+ }
278
+
279
+ // If the Ad Slot is not unique then ad sizes and media types merge them together
280
+ if (auctionEndPayload.adUnits[adUnit.code]) {
281
+ // Merge ad sizes
282
+ Array.prototype.push.apply(auctionEndPayload.adUnits[adUnit.code].sizes, cnvrAdUnit.sizes);
283
+ // Merge mediaTypes
284
+ Array.prototype.push.apply(auctionEndPayload.adUnits[adUnit.code].mediaTypes, cnvrAdUnit.mediaTypes);
285
+ } else {
286
+ auctionEndPayload.adUnits[adUnit.code] = cnvrAdUnit;
287
+ }
288
+ });
289
+
290
+ if (Array.isArray(args.noBids)) {
291
+ args.noBids.forEach(noBid => {
292
+ const bidPayloadArray = deepAccess(auctionEndPayload, 'adUnits.' + noBid.adUnitCode + '.bids.' + noBid.bidder);
293
+
294
+ if (bidPayloadArray) {
295
+ bidPayloadArray.push(cnvrHelper.createBid(CNVR_CONSTANTS.NO_BID, 0)); // no time to respond info for this, would have to capture event and save it there
296
+ } else {
297
+ logMessage(CNVR_CONSTANTS.LOG_PREFIX + 'Unable to locate bid object via adUnitCode/bidderCode in payload for noBid reply in END_AUCTION', Object.assign({}, noBid));
298
+ }
299
+ });
300
+ } else {
301
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onAuctionEnd(): noBids not defined in arguments.');
302
+ }
303
+
304
+ // Get bid data from bids sent
305
+ if (Array.isArray(args.bidsReceived)) {
306
+ args.bidsReceived.forEach(bid => {
307
+ const bidPayloadArray = deepAccess(auctionEndPayload, 'adUnits.' + bid.adUnitCode + '.bids.' + bid.bidderCode);
308
+ if (bidPayloadArray) {
309
+ const bidPayload = cnvrHelper.createBid(CNVR_CONSTANTS.BID, bid.timeToRespond);
310
+ bidPayload.originalCpm = bid.originalCpm;
311
+ bidPayload.cpm = bid.cpm;
312
+ bidPayload.currency = bid.currency;
313
+ bidPayload.mediaType = bid.mediaType;
314
+ bidPayload.adSize = {
315
+ 'w': bid.width,
316
+ 'h': bid.height
317
+ };
318
+ bidPayloadArray.push(bidPayload);
319
+ } else {
320
+ logMessage(CNVR_CONSTANTS.LOG_PREFIX + 'Unable to locate bid object via adUnitCode/bidderCode in payload for bid reply in END_AUCTION', Object.assign({}, bid));
321
+ }
322
+ });
323
+ } else {
324
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'onAuctionEnd(): bidsReceived not defined in arguments.');
325
+ }
326
+ // We need to remove any duplicate ad sizes from merging ad-slots or overlap in different media types and also
327
+ // media-types from merged ad-slots in twin bids.
328
+ Object.keys(auctionEndPayload.adUnits).forEach(function(adCode) {
329
+ auctionEndPayload.adUnits[adCode].sizes = cnvrHelper.deduplicateArray(auctionEndPayload.adUnits[adCode].sizes);
330
+ auctionEndPayload.adUnits[adCode].mediaTypes = cnvrHelper.deduplicateArray(auctionEndPayload.adUnits[adCode].mediaTypes);
331
+ });
332
+
333
+ sendData(auctionEndPayload);
334
+ }
335
+
336
+ // =============================================== START OF HELPERS ===================================================
337
+
338
+ /**
339
+ * Helper to verify a key exists and is a data type of Object (not a function, or array)
340
+ * @param parent The parent that we want to check the key for
341
+ * @param key The key which we want to check
342
+ * @returns {boolean} True if it's an object and exists, false otherwise (null, array, primitive, function)
343
+ */
344
+ cnvrHelper.keyExistsAndIsObject = function (parent, key) {
345
+ if (!parent.hasOwnProperty(key)) {
346
+ return false;
347
+ }
348
+ return typeof parent[key] === 'object' &&
349
+ !Array.isArray(parent[key]) &&
350
+ parent[key] !== null;
351
+ }
352
+
353
+ /**
354
+ * De-duplicate an array that could contain primitives or objects/associative arrays.
355
+ * A temporary array is used to store a string representation of each object that we look at. If an object matches
356
+ * one found in the temp array then it is ignored.
357
+ * @param array An array
358
+ * @returns {*} A de-duplicated array.
359
+ */
360
+ cnvrHelper.deduplicateArray = function(array) {
361
+ if (!array || !Array.isArray(array)) {
362
+ return array;
363
+ }
364
+
365
+ const tmpArray = [];
366
+ return array.filter(function (tmpObj) {
367
+ if (tmpArray.indexOf(JSON.stringify(tmpObj)) < 0) {
368
+ tmpArray.push(JSON.stringify(tmpObj));
369
+ return tmpObj;
370
+ }
371
+ });
372
+ };
373
+
374
+ /**
375
+ * Generic method to look at each key/value pair of a cache object and looks at the 'timeReceived' key, if more than
376
+ * the max wait time has passed then just delete the key.
377
+ * @param cacheObj one of our cache objects [adIdLookup or timeoutCache]
378
+ * @param currTime the current timestamp at the start of the most recent timer execution.
379
+ */
380
+ cnvrHelper.cleanCache = function(cacheObj, currTime) {
381
+ Object.keys(cacheObj).forEach(key => {
382
+ const timeInCache = currTime - cacheObj[key].timeReceived;
383
+ if (timeInCache >= CNVR_CONSTANTS.MAX_MILLISECONDS_IN_CACHE) {
384
+ delete cacheObj[key];
385
+ }
386
+ });
387
+ };
388
+
389
+ /**
390
+ * Helper to create an object lookup key for our timeoutCache
391
+ * @param auctionId id of the auction
392
+ * @param adUnitCode ad unit code
393
+ * @param bidderCode bidder code
394
+ * @returns string concatenation of all the params into a string key for timeoutCache
395
+ */
396
+ cnvrHelper.getLookupKey = function(auctionId, adUnitCode, bidderCode) {
397
+ return auctionId + '-' + adUnitCode + '-' + bidderCode;
398
+ };
399
+
400
+ /**
401
+ * Creates our root payload object that gets sent back to the server
402
+ * @param payloadType string type of payload (AUCTION_END, BID_WON, RENDER_FAILED)
403
+ * @param auctionId id for the auction
404
+ * @param timestamp timestamp in milliseconds of auction start time.
405
+ * @returns
406
+ * {{
407
+ * requestType: *,
408
+ * adUnits: {},
409
+ * auction: {
410
+ * auctionId: *,
411
+ * preBidVersion: *,
412
+ * sid: *}
413
+ * }} Basic structure of our object that we return to the server.
414
+ */
415
+ cnvrHelper.createPayload = function(payloadType, auctionId, timestamp) {
416
+ return {
417
+ requestType: payloadType,
418
+ globalSampleRate: initOptions.global_sample_rate,
419
+ cnvrSampleRate: initOptions.cnvr_sample_rate,
420
+ auction: {
421
+ auctionId: auctionId,
422
+ preBidVersion: getGlobal().version,
423
+ sid: initOptions.site_id,
424
+ auctionTimestamp: timestamp
425
+ },
426
+ adUnits: {}
427
+ };
428
+ };
429
+
430
+ /**
431
+ * Helper to create an adSize object, if the value passed in is not an int then set it to -1
432
+ * @param width in pixels (must be an int)
433
+ * @param height in peixl (must be an int)
434
+ * @returns {{w: *, h: *}} a fully valid adSize object
435
+ */
436
+ cnvrHelper.createAdSize = function(width, height) {
437
+ if (!isInteger(width)) {
438
+ width = -1;
439
+ }
440
+ if (!isInteger(height)) {
441
+ height = -1;
442
+ }
443
+ return {
444
+ 'w': width,
445
+ 'h': height
446
+ };
447
+ };
448
+
449
+ /**
450
+ * Helper to create the basic structure of our adUnit payload
451
+ * @returns {{sizes: [], bids: {}}} Basic adUnit payload structure as follows
452
+ */
453
+ cnvrHelper.createAdUnit = function() {
454
+ return {
455
+ sizes: [],
456
+ mediaTypes: [],
457
+ bids: {}
458
+ };
459
+ };
460
+
461
+ /**
462
+ * Helper to create a basic bid payload object.
463
+ */
464
+ cnvrHelper.createBid = function (eventCode, timeToRespond) {
465
+ return {
466
+ 'eventCodes': [eventCode],
467
+ 'timeToRespond': timeToRespond
468
+ };
469
+ };
470
+
471
+ /**
472
+ * Helper to get the sampling rates from an object and validate the result.
473
+ * @param parentObj Parent object that has the sampling property
474
+ * @param propNm Name of the sampling property
475
+ * @param defaultSampleRate A default value to apply if there is a problem
476
+ * @returns {number} returns a float number from 0 (always off) to 1 (always on)
477
+ */
478
+ cnvrHelper.getSampleRate = function(parentObj, propNm, defaultSampleRate) {
479
+ let sampleRate = defaultSampleRate;
480
+ if (parentObj && typeof parentObj[propNm] !== 'undefined') {
481
+ sampleRate = parseFloat(parentObj[propNm]);
482
+ if (Number.isNaN(sampleRate) || sampleRate > 1) {
483
+ sampleRate = defaultSampleRate;
484
+ } else if (sampleRate < 0) {
485
+ sampleRate = 0;
486
+ }
487
+ }
488
+ return sampleRate;
489
+ }
490
+
491
+ /**
492
+ * Helper function to send data back to server. Need to make sure we don't trigger a CORS preflight by not adding
493
+ * extra header params.
494
+ * @param payload our JSON payload from either AUCTION END, BID WIN, RENDER FAILED
495
+ */
496
+ function sendData(payload) {
497
+ ajax(URL, function () {}, JSON.stringify(payload), {contentType: 'text/plain'});
498
+ }
499
+
500
+ // =============================== BOILERPLATE FOR PRE-BID ANALYTICS SETUP ============================================
501
+ // save the base class function
502
+ conversantAnalytics.originEnableAnalytics = conversantAnalytics.enableAnalytics;
503
+ conversantAnalytics.originDisableAnalytics = conversantAnalytics.disableAnalytics;
504
+
505
+ // override enableAnalytics so we can get access to the config passed in from the page
506
+ conversantAnalytics.enableAnalytics = function (config) {
507
+ if (!config || !config.options || !config.options.site_id) {
508
+ logError(CNVR_CONSTANTS.LOG_PREFIX + 'siteId is required.');
509
+ return;
510
+ }
511
+
512
+ cacheCleanupInterval = setInterval(
513
+ function() {
514
+ const currTime = Date.now();
515
+ cnvrHelper.cleanCache(cnvrHelper.adIdLookup, currTime);
516
+ cnvrHelper.cleanCache(cnvrHelper.timeoutCache, currTime);
517
+ cnvrHelper.cleanCache(cnvrHelper.auctionIdTimestampCache, currTime);
518
+ },
519
+ CNVR_CONSTANTS.CACHE_CLEANUP_TIME_IN_MILLIS
520
+ );
521
+
522
+ Object.assign(initOptions, config.options);
523
+
524
+ initOptions.global_sample_rate = cnvrHelper.getSampleRate(initOptions, 'sampling', 1);
525
+ initOptions.cnvr_sample_rate = cnvrHelper.getSampleRate(initOptions, 'cnvr_sampling', CNVR_CONSTANTS.DEFAULT_SAMPLE_RATE);
526
+
527
+ logInfo(CNVR_CONSTANTS.LOG_PREFIX + 'Conversant sample rate set to ' + initOptions.cnvr_sample_rate);
528
+ logInfo(CNVR_CONSTANTS.LOG_PREFIX + 'Global sample rate set to ' + initOptions.global_sample_rate);
529
+ // Math.random() pseudo-random number in the range 0 to less than 1 (inclusive of 0, but not 1)
530
+ cnvrHelper.doSample = Math.random() < initOptions.cnvr_sample_rate;
531
+
532
+ conversantAnalyticsEnabled = true;
533
+ conversantAnalytics.originEnableAnalytics(config); // call the base class function
534
+ };
535
+
536
+ /**
537
+ * Cleanup code for any timers and caches.
538
+ */
539
+ conversantAnalytics.disableAnalytics = function () {
540
+ if (!conversantAnalyticsEnabled) {
541
+ return;
542
+ }
543
+
544
+ // Cleanup our caches and disable our timer
545
+ clearInterval(cacheCleanupInterval);
546
+ cnvrHelper.timeoutCache = {};
547
+ cnvrHelper.adIdLookup = {};
548
+ cnvrHelper.auctionIdTimestampCache = {};
549
+
550
+ conversantAnalyticsEnabled = false;
551
+ conversantAnalytics.originDisableAnalytics();
552
+ };
553
+
554
+ adapterManager.registerAnalyticsAdapter({
555
+ adapter: conversantAnalytics,
556
+ code: ANALYTICS_CODE,
557
+ gvlid: GVLID
558
+ });
559
+
560
+ export default conversantAnalytics;
@@ -0,0 +1,47 @@
1
+ # Overview
2
+ - Module Name: Conversant Bidder Adapter
3
+ - Module Type: Analytics Adapter
4
+ - Maintainer: mediapsr@conversantmedia.com
5
+
6
+ ## Description
7
+
8
+ Analytics adapter for Conversant is used to track performance of Prebid auctions. See the usage below for how to
9
+ configure the adapter for your webpage. To enable analytics and gain access to the data publishers will need
10
+ to contact their Conversant representative.
11
+
12
+ ## Setup
13
+
14
+ Before any analytics are recorded for your website you will need to have a Conversant representative turn
15
+ on Prebid analytics for your website.
16
+
17
+ The simplest configuration to add Conversant Prebid analytics to your page is as follows:
18
+
19
+ ```
20
+ pbjs.que.push(function() {
21
+ pbjs.enableAnalytics({
22
+ provider: 'conversant',
23
+ options: {
24
+ site_id: '<YOUR_SITE_ID>'
25
+ }
26
+ })
27
+ });
28
+ ```
29
+
30
+ Additionally the following options are supported:
31
+
32
+ - **sampleRate**: Expects an integer from 0 to 100. By default only 50% (corresponds to a value of 50) of instances are enabled
33
+ for Conversant Prebid Analytics. This field allows the publisher to override that percentage to sample
34
+ at a higher or lower rate. '0' would completely disable sampling and '100' would capture every instance.
35
+
36
+ ### Complete Example
37
+ ```
38
+ pbjs.que.push(function() {
39
+ pbjs.enableAnalytics({
40
+ provider: 'conversant',
41
+ options: {
42
+ site_id: '1234',
43
+ sampleRate: 90
44
+ }
45
+ })
46
+ });
47
+ ```
@@ -27,7 +27,7 @@ const LOG_PREFIX = 'Criteo: ';
27
27
  Unminified source code can be found in the privately shared repo: https://github.com/Prebid-org/prebid-js-external-js-criteo/blob/master/dist/prod.js
28
28
  */
29
29
  const FAST_BID_VERSION_PLACEHOLDER = '%FAST_BID_VERSION%';
30
- export const FAST_BID_VERSION_CURRENT = 123;
30
+ export const FAST_BID_VERSION_CURRENT = 130;
31
31
  const FAST_BID_VERSION_LATEST = 'latest';
32
32
  const FAST_BID_VERSION_NONE = 'none';
33
33
  const PUBLISHER_TAG_URL_TEMPLATE = 'https://static.criteo.net/js/ld/publishertag.prebid' + FAST_BID_VERSION_PLACEHOLDER + '.js';
@@ -126,7 +126,7 @@ Object.assign(BidInterceptor.prototype, {
126
126
  Object.entries(ref).forEach(([key, val]) => {
127
127
  if (typeof val === 'function') {
128
128
  result[key] = val(...args);
129
- } else if (typeof val === 'object') {
129
+ } else if (val != null && typeof val === 'object') {
130
130
  result[key] = replFn({args, ref: val})
131
131
  } else {
132
132
  result[key] = val;
@@ -138,7 +138,7 @@ Object.assign(BidInterceptor.prototype, {
138
138
  return (bid, ...args) => {
139
139
  const response = this.responseDefaults(bid);
140
140
  mergeDeep(response, replFn({args: [bid, ...args]}));
141
- if (!response.ad) {
141
+ if (!response.hasOwnProperty('ad') && !response.hasOwnProperty('adUrl')) {
142
142
  response.ad = this.defaultAd(bid, response);
143
143
  }
144
144
  response.isDebug = true;
@@ -49,9 +49,17 @@ function saveDebuggingConfig(debugConfig, {sessionStorage = window.sessionStorag
49
49
  }
50
50
  }
51
51
 
52
- export function getConfig(debugging, {sessionStorage = window.sessionStorage, DEBUG_KEY, config, hook, logger} = {}) {
52
+ export function getConfig(debugging, {getStorage = () => window.sessionStorage, DEBUG_KEY, config, hook, logger} = {}) {
53
53
  if (debugging == null) return;
54
- saveDebuggingConfig(debugging, {sessionStorage, DEBUG_KEY});
54
+ let sessionStorage;
55
+ try {
56
+ sessionStorage = getStorage();
57
+ } catch (e) {
58
+ logger.logError(`sessionStorage is not available: debugging configuration will not persist on page reload`, e);
59
+ }
60
+ if (sessionStorage != null) {
61
+ saveDebuggingConfig(debugging, {sessionStorage, DEBUG_KEY});
62
+ }
55
63
  if (!debugging.enabled) {
56
64
  disableDebugging({hook, logger});
57
65
  } else {