@@ -14,6 +14,8 @@ const bidWon = CONSTANTS.EVENTS.BID_WON;
14
14
const bidTimeout = CONSTANTS . EVENTS . BID_TIMEOUT ;
15
15
const ua = navigator . userAgent ;
16
16
17
+ var _sampled = true ;
18
+
17
19
let adomikAdapter = Object . assign ( adapter ( { } ) ,
18
20
{
19
21
// Track every event needed
@@ -81,6 +83,7 @@ adomikAdapter.sendTypedEvent = function() {
81
83
uid : adomikAdapter . currentContext . uid ,
82
84
ahbaid : adomikAdapter . currentContext . id ,
83
85
hostname : window . location . hostname ,
86
+ sampling : adomikAdapter . currentContext . sampling ,
84
87
eventsByPlacementCode : groupedTypedEvents . map ( function ( typedEventsByType ) {
85
88
let sizes = [ ] ;
86
89
const eventKeys = [ 'request' , 'response' , 'winner' ] ;
@@ -203,19 +206,28 @@ adomikAdapter.adapterEnableAnalytics = adomikAdapter.enableAnalytics;
203
206
204
207
adomikAdapter . enableAnalytics = function ( config ) {
205
208
adomikAdapter . currentContext = { } ;
206
-
207
209
const initOptions = config . options ;
208
- if ( initOptions ) {
209
- adomikAdapter . currentContext = {
210
- uid : initOptions . id ,
211
- url : initOptions . url ,
212
- testId : initOptions . testId ,
213
- testValue : initOptions . testValue ,
214
- id : '' ,
215
- timeouted : false ,
210
+
211
+ _sampled = typeof config === 'undefined' ||
212
+ typeof config . sampling === 'undefined' ||
213
+ Math . random ( ) < parseFloat ( config . sampling ) ;
214
+
215
+ if ( _sampled ) {
216
+ if ( initOptions ) {
217
+ adomikAdapter . currentContext = {
218
+ uid : initOptions . id ,
219
+ url : initOptions . url ,
220
+ testId : initOptions . testId ,
221
+ testValue : initOptions . testValue ,
222
+ id : '' ,
223
+ timeouted : false ,
224
+ sampling : config . sampling
225
+ }
226
+ logInfo ( 'Adomik Analytics enabled with config' , initOptions ) ;
227
+ adomikAdapter . adapterEnableAnalytics ( config ) ;
216
228
}
217
- logInfo ( 'Adomik Analytics enabled with config' , initOptions ) ;
218
- adomikAdapter . adapterEnableAnalytics ( config ) ;
229
+ } else {
230
+ logInfo ( 'Adomik Analytics ignored for sampling' , config . sampling ) ;
219
231
}
220
232
} ;
221
233
0 commit comments