Skip to content

[FSSDK-9605] export and default usage of sendBeaconDispatcher #876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/optimizely-sdk/lib/index.browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016-2017, 2019-2022 Optimizely
* Copyright 2016-2017, 2019-2022, 2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,12 +25,13 @@ import { LocalStoragePendingEventsDispatcher } from '@optimizely/js-sdk-event-pr
import configValidator from './utils/config_validator';
import defaultErrorHandler from './plugins/error_handler';
import defaultEventDispatcher from './plugins/event_dispatcher/index.browser';
import sendBeaconEventDispatcher from './plugins/event_dispatcher/send_beacon_dispatcher';
import * as enums from './utils/enums';
import * as loggerPlugin from './plugins/logger';
import Optimizely from './optimizely';
import eventProcessorConfigValidator from './utils/event_processor_config_validator';
import { createNotificationCenter } from './core/notification_center';
import { default as eventProcessor } from './plugins/event_processor';
import eventProcessor from './plugins/event_processor';
import { OptimizelyDecideOption, Client, Config } from './shared_types';
import { createHttpPollingDatafileManager } from './plugins/datafile_manager/http_polling_datafile_manager';

Expand Down Expand Up @@ -91,6 +92,13 @@ const createInstance = function(config: Config): Client | null {
eventDispatcher = config.eventDispatcher;
}

let closingDispatcher = config.closingEventDispatcher;

if (!config.eventDispatcher && !closingDispatcher && window.navigator && 'sendBeacon' in window.navigator) {
closingDispatcher = sendBeaconEventDispatcher;
}


let eventBatchSize = config.eventBatchSize;
let eventFlushInterval = config.eventFlushInterval;

Expand All @@ -112,6 +120,7 @@ const createInstance = function(config: Config): Client | null {

const eventProcessorConfig = {
dispatcher: eventDispatcher,
closingDispatcher,
flushInterval: eventFlushInterval,
batchSize: eventBatchSize,
maxQueueSize: config.eventMaxQueueSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
Expand Down Expand Up @@ -164,6 +173,7 @@ export {
loggerPlugin as logging,
defaultErrorHandler as errorHandler,
defaultEventDispatcher as eventDispatcher,
sendBeaconEventDispatcher,
enums,
setLogHandler as setLogger,
setLogLevel,
Expand All @@ -176,6 +186,7 @@ export default {
logging: loggerPlugin,
errorHandler: defaultErrorHandler,
eventDispatcher: defaultEventDispatcher,
sendBeaconEventDispatcher,
enums,
setLogger: setLogHandler,
setLogLevel,
Expand Down
4 changes: 3 additions & 1 deletion packages/optimizely-sdk/lib/shared_types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2020-2022, Optimizely
* Copyright 2020-2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -398,6 +398,8 @@ export interface TrackListenerPayload extends ListenerPayload {
errorHandler?: ErrorHandler;
// event dispatcher function
eventDispatcher?: EventDispatcher;
// event dispatcher to use when closing
closingEventDispatcher?: EventDispatcher;
// The object to validate against the schema
jsonSchemaValidator?: {
validate(jsonObject: unknown): boolean,
Expand Down
Loading