1
1
/**
2
- * Copyright 2016-2017, 2019-2022 Optimizely
2
+ * Copyright 2016-2017, 2019-2022, 2023 Optimizely
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -25,12 +25,13 @@ import { LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-pr
25
25
import configValidator from './utils/config_validator' ;
26
26
import defaultErrorHandler from './plugins/error_handler' ;
27
27
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser' ;
28
+ import sendBeaconEventDispatcher from './plugins/event_dispatcher/send_beacon_dispatcher' ;
28
29
import * as enums from './utils/enums' ;
29
30
import * as loggerPlugin from './plugins/logger' ;
30
31
import Optimizely from './optimizely' ;
31
32
import eventProcessorConfigValidator from './utils/event_processor_config_validator' ;
32
33
import { createNotificationCenter } from './core/notification_center' ;
33
- import { default as eventProcessor } from './plugins/event_processor' ;
34
+ import eventProcessor from './plugins/event_processor' ;
34
35
import { OptimizelyDecideOption , Client , Config } from './shared_types' ;
35
36
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager' ;
36
37
@@ -91,6 +92,13 @@ const createInstance = function(config: Config): Client | null {
91
92
eventDispatcher = config . eventDispatcher ;
92
93
}
93
94
95
+ let closingDispatcher = config . closingEventDispatcher ;
96
+
97
+ if ( ! config . eventDispatcher && ! closingDispatcher && window . navigator && 'sendBeacon' in window . navigator ) {
98
+ closingDispatcher = sendBeaconEventDispatcher ;
99
+ }
100
+
101
+
94
102
let eventBatchSize = config . eventBatchSize ;
95
103
let eventFlushInterval = config . eventFlushInterval ;
96
104
@@ -112,6 +120,7 @@ const createInstance = function(config: Config): Client | null {
112
120
113
121
const eventProcessorConfig = {
114
122
dispatcher : eventDispatcher ,
123
+ closingDispatcher,
115
124
flushInterval : eventFlushInterval ,
116
125
batchSize : eventBatchSize ,
117
126
maxQueueSize : config . eventMaxQueueSize || DEFAULT_EVENT_MAX_QUEUE_SIZE ,
@@ -164,6 +173,7 @@ export {
164
173
loggerPlugin as logging ,
165
174
defaultErrorHandler as errorHandler ,
166
175
defaultEventDispatcher as eventDispatcher ,
176
+ sendBeaconEventDispatcher ,
167
177
enums ,
168
178
setLogHandler as setLogger ,
169
179
setLogLevel ,
@@ -176,6 +186,7 @@ export default {
176
186
logging : loggerPlugin ,
177
187
errorHandler : defaultErrorHandler ,
178
188
eventDispatcher : defaultEventDispatcher ,
189
+ sendBeaconEventDispatcher,
179
190
enums,
180
191
setLogger : setLogHandler ,
181
192
setLogLevel,
0 commit comments