@splitsoftware/splitio-commons 1.5.0 → 1.5.1-rc.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.
- package/CHANGES.txt +4 -0
- package/cjs/integrations/ga/GaToSplit.js +12 -11
- package/cjs/listeners/browser.js +35 -15
- package/esm/integrations/ga/GaToSplit.js +12 -11
- package/esm/listeners/browser.js +35 -15
- package/package.json +1 -1
- package/src/integrations/ga/GaToSplit.ts +14 -8
- package/src/integrations/ga/autoRequire.js +33 -0
- package/src/integrations/ga/types.ts +13 -2
- package/src/listeners/browser.ts +34 -14
- package/src/logger/.DS_Store +0 -0
- package/types/integrations/ga/GaToSplitPlugin.d.ts +3 -0
- package/types/integrations/ga/SplitToGaPlugin.d.ts +4 -0
- package/types/integrations/ga/autoRequire.d.ts +4 -0
- package/types/integrations/ga/types.d.ts +13 -2
- package/types/listeners/browser.d.ts +6 -6
- package/types/logger/browser/{DebugLogger.d.ts → debugLogger.d.ts} +0 -0
- package/types/logger/browser/{ErrorLogger.d.ts → errorLogger.d.ts} +0 -0
- package/types/logger/browser/{InfoLogger.d.ts → infoLogger.d.ts} +0 -0
- package/types/logger/browser/{WarnLogger.d.ts → warnLogger.d.ts} +0 -0
- package/types/logger/codes.d.ts +2 -0
- package/types/logger/codesConstants.d.ts +117 -0
- package/types/logger/codesConstantsBrowser.d.ts +2 -0
- package/types/logger/codesConstantsNode.d.ts +14 -0
- package/types/logger/codesDebug.d.ts +1 -0
- package/types/logger/codesDebugBrowser.d.ts +1 -0
- package/types/logger/codesDebugNode.d.ts +1 -0
- package/types/logger/codesError.d.ts +1 -0
- package/types/logger/codesErrorNode.d.ts +1 -0
- package/types/logger/codesInfo.d.ts +1 -0
- package/types/logger/codesWarn.d.ts +1 -0
- package/types/logger/codesWarnNode.d.ts +1 -0
- package/types/logger/debugLogger.d.ts +2 -0
- package/types/logger/errorLogger.d.ts +2 -0
- package/types/logger/infoLogger.d.ts +2 -0
- package/types/logger/messages/debugBrowser.d.ts +1 -0
- package/types/logger/messages/debugNode.d.ts +1 -0
- package/types/logger/messages/errorNode.d.ts +1 -0
- package/types/logger/messages/warnNode.d.ts +1 -0
- package/types/logger/noopLogger.d.ts +2 -0
- package/types/logger/warnLogger.d.ts +2 -0
- package/types/sdkFactory/userConsentProps.d.ts +6 -0
- package/types/sdkManager/sdkManagerMethod.d.ts +6 -0
- package/types/storages/getRegisteredSegments.d.ts +10 -0
- package/types/storages/inMemory/index.d.ts +10 -0
- package/types/storages/parseSegments.d.ts +6 -0
- package/types/sync/polling/syncTasks/splitsSyncTask.copy.d.ts +35 -0
- package/types/sync/polling/syncTasks/splitsSyncTask.morelikeoriginal.d.ts +35 -0
- package/types/sync/streaming/AuthClient/indexV1.d.ts +12 -0
- package/types/sync/streaming/AuthClient/indexV2.d.ts +8 -0
- package/types/sync/streaming/UpdateWorkers/constants.d.ts +3 -0
- package/types/sync/streaming/pushManagerCS.d.ts +1 -0
- package/types/sync/streaming/pushManagerNoUsers.d.ts +13 -0
- package/types/sync/streaming/pushManagerSS.d.ts +1 -0
- package/types/sync/submitters/telemetrySyncTask.d.ts +0 -0
- package/types/sync/syncManagerFromFile.d.ts +2 -0
- package/types/sync/syncManagerFromObject.d.ts +2 -0
- package/types/sync/syncManagerOffline.d.ts +9 -0
- package/types/trackers/telemetryRecorder.d.ts +0 -0
- package/types/utils/EventEmitter.d.ts +4 -0
- package/types/utils/consent.d.ts +2 -0
- package/types/utils/lang/errors.d.ts +10 -0
- package/types/utils/murmur3/commons.d.ts +12 -0
- package/types/utils/settingsValidation/buildMetadata.d.ts +3 -0
- package/types/utils/settingsValidation/localhost/index.d.ts +9 -0
- package/types/utils/settingsValidation/logger.d.ts +11 -0
- package/types/utils/settingsValidation/runtime/browser.d.ts +2 -0
- package/types/utils/settingsValidation/runtime/node.d.ts +2 -0
- package/types/utils/settingsValidation/userConsent.d.ts +5 -0
- package/types/utils/timeTracker/index.d.ts +1 -70
package/CHANGES.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
1.6.0 (July 7, 2022)
|
|
2
|
+
- Added `autoRequire` configuration option to the Google Analytics to Split integration (See https://help.split.io/hc/en-us/articles/360040838752#set-up-with-gtm-and-gtag.js).
|
|
3
|
+
- Updated browser listener to push remaining impressions and events on 'visibilitychange' and 'pagehide' DOM events, instead of 'unload', which is not reliable in mobile and modern Web browsers (See https://developer.chrome.com/blog/page-lifecycle-api/#legacy-lifecycle-apis-to-avoid).
|
|
4
|
+
|
|
1
5
|
1.5.0 (June 29, 2022)
|
|
2
6
|
- Added a new config option to control the tasks that listen or poll for updates on feature flags and segments, via the new config sync.enabled . Running online Split will always pull the most recent updates upon initialization, this only affects updates fetching on a running instance. Useful when a consistent session experience is a must or to save resources when updates are not being used.
|
|
3
7
|
- Updated telemetry logic to track the anonymous config for user consent flag set to declined or unknown.
|
|
@@ -10,23 +10,24 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
10
10
|
/**
|
|
11
11
|
* Provides a plugin to use with analytics.js, accounting for the possibility
|
|
12
12
|
* that the global command queue has been renamed or not yet defined.
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
13
|
+
* @param window Reference to global object.
|
|
14
|
+
* @param pluginName The plugin name identifier.
|
|
15
|
+
* @param pluginConstructor The plugin constructor function.
|
|
16
|
+
* @param log Logger instance.
|
|
17
|
+
* @param autoRequire If true, log error when auto-require script is not detected
|
|
15
18
|
*/
|
|
16
|
-
function providePlugin(pluginName, pluginConstructor) {
|
|
19
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
17
20
|
// get reference to global command queue. Init it if not defined yet.
|
|
18
|
-
// @ts-expect-error
|
|
19
21
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
20
22
|
window[gaAlias] = window[gaAlias] || function () {
|
|
21
|
-
|
|
22
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
23
|
-
args[_i] = arguments[_i];
|
|
24
|
-
}
|
|
25
|
-
(window[gaAlias].q = window[gaAlias].q || []).push(args);
|
|
23
|
+
(window[gaAlias].q = window[gaAlias].q || []).push(arguments);
|
|
26
24
|
};
|
|
27
25
|
// provides the plugin for use with analytics.js.
|
|
28
|
-
// @ts-expect-error
|
|
29
26
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
27
|
+
if (autoRequire && (!window[gaAlias].q || window[gaAlias].q.push === [].push)) {
|
|
28
|
+
// Expecting spy on ga.q push method but not found
|
|
29
|
+
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run.');
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
32
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
32
33
|
var defaultMapping = {
|
|
@@ -246,6 +247,6 @@ function GaToSplit(sdkOptions, params) {
|
|
|
246
247
|
return SplitTracker;
|
|
247
248
|
}());
|
|
248
249
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
249
|
-
providePlugin('splitTracker', SplitTracker);
|
|
250
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire);
|
|
250
251
|
}
|
|
251
252
|
exports.GaToSplit = GaToSplit;
|
package/cjs/listeners/browser.js
CHANGED
|
@@ -8,11 +8,12 @@ var objectAssign_1 = require("../utils/lang/objectAssign");
|
|
|
8
8
|
var constants_2 = require("../logger/constants");
|
|
9
9
|
var consent_1 = require("../consent");
|
|
10
10
|
var telemetrySubmitter_1 = require("../sync/submitters/telemetrySubmitter");
|
|
11
|
-
|
|
12
|
-
var
|
|
11
|
+
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
12
|
+
var PAGEHIDE_EVENT = 'pagehide';
|
|
13
|
+
var UNLOAD_EVENT = 'unload';
|
|
13
14
|
var EVENT_NAME = 'for unload page event.';
|
|
14
15
|
/**
|
|
15
|
-
* We'll listen for
|
|
16
|
+
* We'll listen for events over the window object.
|
|
16
17
|
*/
|
|
17
18
|
var BrowserSignalListener = /** @class */ (function () {
|
|
18
19
|
function BrowserSignalListener(syncManager, settings, storage, serviceApi) {
|
|
@@ -21,33 +22,50 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
21
22
|
this.storage = storage;
|
|
22
23
|
this.serviceApi = serviceApi;
|
|
23
24
|
this.flushData = this.flushData.bind(this);
|
|
25
|
+
this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
|
|
26
|
+
this.stopSync = this.stopSync.bind(this);
|
|
24
27
|
this.fromImpressionsCollector = impressionsSubmitter_1.fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
|
|
25
28
|
}
|
|
26
29
|
/**
|
|
27
30
|
* start method.
|
|
28
|
-
* Called when SplitFactory is initialized.
|
|
29
|
-
* We add a handler on unload events. The handler flushes remaining impressions and events to the backend.
|
|
31
|
+
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
30
32
|
*/
|
|
31
33
|
BrowserSignalListener.prototype.start = function () {
|
|
34
|
+
this.settings.log.debug(constants_2.CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
35
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
36
|
+
// Flush data whenever the page is hidden or unloaded.
|
|
37
|
+
document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
38
|
+
}
|
|
32
39
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
// Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
|
|
41
|
+
// If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
|
|
42
|
+
window.addEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
43
|
+
// Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
|
|
44
|
+
window.addEventListener(UNLOAD_EVENT, this.stopSync);
|
|
35
45
|
}
|
|
36
46
|
};
|
|
37
47
|
/**
|
|
38
48
|
* stop method.
|
|
39
|
-
* Called when client is destroyed.
|
|
40
|
-
* We need to remove the handler for unload events, since it can break if called when Split context was destroyed.
|
|
49
|
+
* Called when client is destroyed, it removes event listeners.
|
|
41
50
|
*/
|
|
42
51
|
BrowserSignalListener.prototype.stop = function () {
|
|
52
|
+
this.settings.log.debug(constants_2.CLEANUP_DEREGISTERING, [EVENT_NAME]);
|
|
53
|
+
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
54
|
+
document.removeEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
55
|
+
}
|
|
43
56
|
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
44
|
-
|
|
45
|
-
window.removeEventListener(
|
|
57
|
+
window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
58
|
+
window.removeEventListener(UNLOAD_EVENT, this.stopSync);
|
|
46
59
|
}
|
|
47
60
|
};
|
|
61
|
+
BrowserSignalListener.prototype.stopSync = function () {
|
|
62
|
+
// Close streaming connection
|
|
63
|
+
if (this.syncManager && this.syncManager.pushManager)
|
|
64
|
+
this.syncManager.pushManager.stop();
|
|
65
|
+
};
|
|
48
66
|
/**
|
|
49
67
|
* flushData method.
|
|
50
|
-
* Called when
|
|
68
|
+
* Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
|
|
51
69
|
* using beacon API if possible, or falling back to regular post transport.
|
|
52
70
|
*/
|
|
53
71
|
BrowserSignalListener.prototype.flushData = function () {
|
|
@@ -71,9 +89,11 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
71
89
|
var telemetryCacheAdapter = (0, telemetrySubmitter_1.telemetryCacheStatsAdapter)(this.storage.telemetry, this.storage.splits, this.storage.segments);
|
|
72
90
|
this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
|
|
73
91
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
};
|
|
93
|
+
BrowserSignalListener.prototype.flushDataIfHidden = function () {
|
|
94
|
+
// Precondition: document defined
|
|
95
|
+
if (document.visibilityState === 'hidden')
|
|
96
|
+
this.flushData(); // On a 'visibilitychange' event, flush data if state is hidden
|
|
77
97
|
};
|
|
78
98
|
BrowserSignalListener.prototype._flushData = function (url, cache, postService, fromCacheToPayload, extraMetadata) {
|
|
79
99
|
// if there is data in cache, send it to backend
|
|
@@ -7,23 +7,24 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
7
7
|
/**
|
|
8
8
|
* Provides a plugin to use with analytics.js, accounting for the possibility
|
|
9
9
|
* that the global command queue has been renamed or not yet defined.
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
10
|
+
* @param window Reference to global object.
|
|
11
|
+
* @param pluginName The plugin name identifier.
|
|
12
|
+
* @param pluginConstructor The plugin constructor function.
|
|
13
|
+
* @param log Logger instance.
|
|
14
|
+
* @param autoRequire If true, log error when auto-require script is not detected
|
|
12
15
|
*/
|
|
13
|
-
function providePlugin(pluginName, pluginConstructor) {
|
|
16
|
+
function providePlugin(window, pluginName, pluginConstructor, log, autoRequire) {
|
|
14
17
|
// get reference to global command queue. Init it if not defined yet.
|
|
15
|
-
// @ts-expect-error
|
|
16
18
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
17
19
|
window[gaAlias] = window[gaAlias] || function () {
|
|
18
|
-
|
|
19
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
20
|
-
args[_i] = arguments[_i];
|
|
21
|
-
}
|
|
22
|
-
(window[gaAlias].q = window[gaAlias].q || []).push(args);
|
|
20
|
+
(window[gaAlias].q = window[gaAlias].q || []).push(arguments);
|
|
23
21
|
};
|
|
24
22
|
// provides the plugin for use with analytics.js.
|
|
25
|
-
// @ts-expect-error
|
|
26
23
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
24
|
+
if (autoRequire && (!window[gaAlias].q || window[gaAlias].q.push === [].push)) {
|
|
25
|
+
// Expecting spy on ga.q push method but not found
|
|
26
|
+
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run.');
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
29
30
|
var defaultMapping = {
|
|
@@ -240,5 +241,5 @@ export function GaToSplit(sdkOptions, params) {
|
|
|
240
241
|
return SplitTracker;
|
|
241
242
|
}());
|
|
242
243
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
243
|
-
providePlugin('splitTracker', SplitTracker);
|
|
244
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire);
|
|
244
245
|
}
|
package/esm/listeners/browser.js
CHANGED
|
@@ -5,11 +5,12 @@ import { objectAssign } from '../utils/lang/objectAssign';
|
|
|
5
5
|
import { CLEANUP_REGISTERING, CLEANUP_DEREGISTERING } from '../logger/constants';
|
|
6
6
|
import { isConsentGranted } from '../consent';
|
|
7
7
|
import { telemetryCacheStatsAdapter } from '../sync/submitters/telemetrySubmitter';
|
|
8
|
-
|
|
9
|
-
var
|
|
8
|
+
var VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
9
|
+
var PAGEHIDE_EVENT = 'pagehide';
|
|
10
|
+
var UNLOAD_EVENT = 'unload';
|
|
10
11
|
var EVENT_NAME = 'for unload page event.';
|
|
11
12
|
/**
|
|
12
|
-
* We'll listen for
|
|
13
|
+
* We'll listen for events over the window object.
|
|
13
14
|
*/
|
|
14
15
|
var BrowserSignalListener = /** @class */ (function () {
|
|
15
16
|
function BrowserSignalListener(syncManager, settings, storage, serviceApi) {
|
|
@@ -18,33 +19,50 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
18
19
|
this.storage = storage;
|
|
19
20
|
this.serviceApi = serviceApi;
|
|
20
21
|
this.flushData = this.flushData.bind(this);
|
|
22
|
+
this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
|
|
23
|
+
this.stopSync = this.stopSync.bind(this);
|
|
21
24
|
this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
|
|
22
25
|
}
|
|
23
26
|
/**
|
|
24
27
|
* start method.
|
|
25
|
-
* Called when SplitFactory is initialized.
|
|
26
|
-
* We add a handler on unload events. The handler flushes remaining impressions and events to the backend.
|
|
28
|
+
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
27
29
|
*/
|
|
28
30
|
BrowserSignalListener.prototype.start = function () {
|
|
31
|
+
this.settings.log.debug(CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
32
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
33
|
+
// Flush data whenever the page is hidden or unloaded.
|
|
34
|
+
document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
35
|
+
}
|
|
29
36
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
// Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
|
|
38
|
+
// If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
|
|
39
|
+
window.addEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
40
|
+
// Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
|
|
41
|
+
window.addEventListener(UNLOAD_EVENT, this.stopSync);
|
|
32
42
|
}
|
|
33
43
|
};
|
|
34
44
|
/**
|
|
35
45
|
* stop method.
|
|
36
|
-
* Called when client is destroyed.
|
|
37
|
-
* We need to remove the handler for unload events, since it can break if called when Split context was destroyed.
|
|
46
|
+
* Called when client is destroyed, it removes event listeners.
|
|
38
47
|
*/
|
|
39
48
|
BrowserSignalListener.prototype.stop = function () {
|
|
49
|
+
this.settings.log.debug(CLEANUP_DEREGISTERING, [EVENT_NAME]);
|
|
50
|
+
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
51
|
+
document.removeEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
52
|
+
}
|
|
40
53
|
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
41
|
-
|
|
42
|
-
window.removeEventListener(
|
|
54
|
+
window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
55
|
+
window.removeEventListener(UNLOAD_EVENT, this.stopSync);
|
|
43
56
|
}
|
|
44
57
|
};
|
|
58
|
+
BrowserSignalListener.prototype.stopSync = function () {
|
|
59
|
+
// Close streaming connection
|
|
60
|
+
if (this.syncManager && this.syncManager.pushManager)
|
|
61
|
+
this.syncManager.pushManager.stop();
|
|
62
|
+
};
|
|
45
63
|
/**
|
|
46
64
|
* flushData method.
|
|
47
|
-
* Called when
|
|
65
|
+
* Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
|
|
48
66
|
* using beacon API if possible, or falling back to regular post transport.
|
|
49
67
|
*/
|
|
50
68
|
BrowserSignalListener.prototype.flushData = function () {
|
|
@@ -68,9 +86,11 @@ var BrowserSignalListener = /** @class */ (function () {
|
|
|
68
86
|
var telemetryCacheAdapter = telemetryCacheStatsAdapter(this.storage.telemetry, this.storage.splits, this.storage.segments);
|
|
69
87
|
this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
|
|
70
88
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
};
|
|
90
|
+
BrowserSignalListener.prototype.flushDataIfHidden = function () {
|
|
91
|
+
// Precondition: document defined
|
|
92
|
+
if (document.visibilityState === 'hidden')
|
|
93
|
+
this.flushData(); // On a 'visibilitychange' event, flush data if state is hidden
|
|
74
94
|
};
|
|
75
95
|
BrowserSignalListener.prototype._flushData = function (url, cache, postService, fromCacheToPayload, extraMetadata) {
|
|
76
96
|
// if there is data in cache, send it to backend
|
package/package.json
CHANGED
|
@@ -19,20 +19,26 @@ const logNameMapper = 'ga-to-split:mapper';
|
|
|
19
19
|
/**
|
|
20
20
|
* Provides a plugin to use with analytics.js, accounting for the possibility
|
|
21
21
|
* that the global command queue has been renamed or not yet defined.
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
22
|
+
* @param window Reference to global object.
|
|
23
|
+
* @param pluginName The plugin name identifier.
|
|
24
|
+
* @param pluginConstructor The plugin constructor function.
|
|
25
|
+
* @param log Logger instance.
|
|
26
|
+
* @param autoRequire If true, log error when auto-require script is not detected
|
|
24
27
|
*/
|
|
25
|
-
function providePlugin(pluginName: string, pluginConstructor: Function) {
|
|
28
|
+
function providePlugin(window: any, pluginName: string, pluginConstructor: Function, log: ILogger, autoRequire?: boolean) {
|
|
26
29
|
// get reference to global command queue. Init it if not defined yet.
|
|
27
|
-
// @ts-expect-error
|
|
28
30
|
const gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
29
|
-
window[gaAlias] = window[gaAlias] || function (
|
|
30
|
-
(window[gaAlias].q = window[gaAlias].q || []).push(
|
|
31
|
+
window[gaAlias] = window[gaAlias] || function () {
|
|
32
|
+
(window[gaAlias].q = window[gaAlias].q || []).push(arguments);
|
|
31
33
|
};
|
|
32
34
|
|
|
33
35
|
// provides the plugin for use with analytics.js.
|
|
34
|
-
// @ts-expect-error
|
|
35
36
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
37
|
+
|
|
38
|
+
if (autoRequire && (!window[gaAlias].q || window[gaAlias].q.push === [].push)) {
|
|
39
|
+
// Expecting spy on ga.q push method but not found
|
|
40
|
+
log.error(logPrefix + 'integration is configured to autorequire the splitTracker plugin, but the necessary script does not seem to have run.');
|
|
41
|
+
}
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
@@ -284,5 +290,5 @@ export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIn
|
|
|
284
290
|
}
|
|
285
291
|
|
|
286
292
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
287
|
-
providePlugin('splitTracker', SplitTracker);
|
|
293
|
+
providePlugin(window, 'splitTracker', SplitTracker, log, sdkOptions.autoRequire);
|
|
288
294
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
/**
|
|
3
|
+
* Auto-require script to use with GoogleAnalyticsToSplit integration
|
|
4
|
+
*/
|
|
5
|
+
(function (i, r, s) {
|
|
6
|
+
i[s] = i[s] || r;
|
|
7
|
+
i[r] = i[r] || function () { i[r].q.push(arguments); };
|
|
8
|
+
i[r].q = i[r].q || [];
|
|
9
|
+
|
|
10
|
+
var ts = {}; // Tracker names
|
|
11
|
+
function name(arg) { return typeof arg === 'object' && typeof arg.name === 'string' && arg.name; }
|
|
12
|
+
|
|
13
|
+
function processCommand(v) { // Queue a `require` command if v is a `create` command
|
|
14
|
+
if (v && v[0] === 'create') {
|
|
15
|
+
var t = name(v[1]) || name(v[2]) || name(v[3]) || (typeof v[3] === 'string' ? v[3] : undefined); // Get tracker name
|
|
16
|
+
|
|
17
|
+
if (!ts[t]) {
|
|
18
|
+
ts[t] = true;
|
|
19
|
+
i[r]((t ? t + '.' : '') + 'require', 'splitTracker'); // Auto-require
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
i[r].q.forEach(processCommand); // Process already queued commands
|
|
25
|
+
|
|
26
|
+
var o = i[r].q.push;
|
|
27
|
+
i[r].q.push = function (v) { // Spy new queued commands
|
|
28
|
+
var result = o.apply(this, arguments);
|
|
29
|
+
processCommand(v);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
})(window, 'ga', 'GoogleAnalyticsObject');
|
|
@@ -53,13 +53,24 @@ export interface GoogleAnalyticsToSplitOptions {
|
|
|
53
53
|
* If not provided, events are sent using the key and traffic type provided at SDK config
|
|
54
54
|
*/
|
|
55
55
|
identities?: Identity[],
|
|
56
|
+
/**
|
|
57
|
+
* Optional flag to log an error if the `auto-require` script is not detected.
|
|
58
|
+
* The auto-require script automatically requires the `splitTracker` plugin for created trackers,
|
|
59
|
+
* and should be placed right after your Google Analytics, Google Tag Manager or gtag.js script tag.
|
|
60
|
+
*
|
|
61
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#set-up-with-gtm-and-gtag.js}
|
|
62
|
+
*
|
|
63
|
+
* @property {boolean} autoRequire
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
autoRequire?: boolean,
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
/**
|
|
59
70
|
* Enable 'Google Analytics to Split' integration, to track Google Analytics hits as Split events.
|
|
60
71
|
* Used by the browser variant of the isomorphic JS SDK.
|
|
61
72
|
*
|
|
62
|
-
* @see {@link https://help.split.io/hc/en-us/articles/
|
|
73
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#google-analytics-to-split}
|
|
63
74
|
*/
|
|
64
75
|
export interface IGoogleAnalyticsToSplitConfig extends GoogleAnalyticsToSplitOptions {
|
|
65
76
|
type: 'GOOGLE_ANALYTICS_TO_SPLIT'
|
|
@@ -129,7 +140,7 @@ export interface SplitToGoogleAnalyticsOptions {
|
|
|
129
140
|
* Enable 'Split to Google Analytics' integration, to track Split impressions and events as Google Analytics hits.
|
|
130
141
|
* Used by the browser variant of the isomorphic JS SDK.
|
|
131
142
|
*
|
|
132
|
-
* @see {@link https://help.split.io/hc/en-us/articles/
|
|
143
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#split-to-google-analytics}
|
|
133
144
|
*/
|
|
134
145
|
export interface ISplitToGoogleAnalyticsConfig extends SplitToGoogleAnalyticsOptions {
|
|
135
146
|
type: 'SPLIT_TO_GOOGLE_ANALYTICS'
|
package/src/listeners/browser.ts
CHANGED
|
@@ -14,12 +14,13 @@ import { ISyncManager } from '../sync/types';
|
|
|
14
14
|
import { isConsentGranted } from '../consent';
|
|
15
15
|
import { telemetryCacheStatsAdapter } from '../sync/submitters/telemetrySubmitter';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
const VISIBILITYCHANGE_EVENT = 'visibilitychange';
|
|
18
|
+
const PAGEHIDE_EVENT = 'pagehide';
|
|
19
|
+
const UNLOAD_EVENT = 'unload';
|
|
19
20
|
const EVENT_NAME = 'for unload page event.';
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
|
-
* We'll listen for
|
|
23
|
+
* We'll listen for events over the window object.
|
|
23
24
|
*/
|
|
24
25
|
export class BrowserSignalListener implements ISignalListener {
|
|
25
26
|
|
|
@@ -32,36 +33,53 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
32
33
|
private serviceApi: ISplitApi,
|
|
33
34
|
) {
|
|
34
35
|
this.flushData = this.flushData.bind(this);
|
|
36
|
+
this.flushDataIfHidden = this.flushDataIfHidden.bind(this);
|
|
37
|
+
this.stopSync = this.stopSync.bind(this);
|
|
35
38
|
this.fromImpressionsCollector = fromImpressionsCollector.bind(undefined, settings.core.labelsEnabled);
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* start method.
|
|
40
|
-
* Called when SplitFactory is initialized.
|
|
41
|
-
* We add a handler on unload events. The handler flushes remaining impressions and events to the backend.
|
|
43
|
+
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
42
44
|
*/
|
|
43
45
|
start() {
|
|
46
|
+
this.settings.log.debug(CLEANUP_REGISTERING, [EVENT_NAME]);
|
|
47
|
+
if (typeof document !== 'undefined' && document.addEventListener) {
|
|
48
|
+
// Flush data whenever the page is hidden or unloaded.
|
|
49
|
+
document.addEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
50
|
+
}
|
|
44
51
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
// Some browsers like Safari does not fire the `visibilitychange` event when the page is being unloaded. So we also flush data in the `pagehide` event.
|
|
53
|
+
// If both events are triggered, the last one will find the storage empty, so no duplicated data will be submitted.
|
|
54
|
+
window.addEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
55
|
+
// Stop streaming on 'unload' event. Used instead of 'beforeunload', because 'unload' is not a cancelable event, so no other listeners can stop the event from occurring.
|
|
56
|
+
window.addEventListener(UNLOAD_EVENT, this.stopSync);
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
/**
|
|
51
61
|
* stop method.
|
|
52
|
-
* Called when client is destroyed.
|
|
53
|
-
* We need to remove the handler for unload events, since it can break if called when Split context was destroyed.
|
|
62
|
+
* Called when client is destroyed, it removes event listeners.
|
|
54
63
|
*/
|
|
55
64
|
stop() {
|
|
65
|
+
this.settings.log.debug(CLEANUP_DEREGISTERING, [EVENT_NAME]);
|
|
66
|
+
if (typeof document !== 'undefined' && document.removeEventListener) {
|
|
67
|
+
document.removeEventListener(VISIBILITYCHANGE_EVENT, this.flushDataIfHidden);
|
|
68
|
+
}
|
|
56
69
|
if (typeof window !== 'undefined' && window.removeEventListener) {
|
|
57
|
-
|
|
58
|
-
window.removeEventListener(
|
|
70
|
+
window.removeEventListener(PAGEHIDE_EVENT, this.flushData);
|
|
71
|
+
window.removeEventListener(UNLOAD_EVENT, this.stopSync);
|
|
59
72
|
}
|
|
60
73
|
}
|
|
61
74
|
|
|
75
|
+
stopSync() {
|
|
76
|
+
// Close streaming connection
|
|
77
|
+
if (this.syncManager && this.syncManager.pushManager) this.syncManager.pushManager.stop();
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
/**
|
|
63
81
|
* flushData method.
|
|
64
|
-
* Called when
|
|
82
|
+
* Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
|
|
65
83
|
* using beacon API if possible, or falling back to regular post transport.
|
|
66
84
|
*/
|
|
67
85
|
flushData() {
|
|
@@ -86,9 +104,11 @@ export class BrowserSignalListener implements ISignalListener {
|
|
|
86
104
|
const telemetryCacheAdapter = telemetryCacheStatsAdapter(this.storage.telemetry, this.storage.splits, this.storage.segments);
|
|
87
105
|
this._flushData(telemetryUrl + '/v1/metrics/usage/beacon', telemetryCacheAdapter, this.serviceApi.postMetricsUsage);
|
|
88
106
|
}
|
|
107
|
+
}
|
|
89
108
|
|
|
90
|
-
|
|
91
|
-
|
|
109
|
+
flushDataIfHidden() {
|
|
110
|
+
// Precondition: document defined
|
|
111
|
+
if (document.visibilityState === 'hidden') this.flushData(); // On a 'visibilitychange' event, flush data if state is hidden
|
|
92
112
|
}
|
|
93
113
|
|
|
94
114
|
private _flushData<T>(url: string, cache: IRecorderCacheProducerSync<T>, postService: (body: string) => Promise<IResponse>, fromCacheToPayload?: (cacheData: T) => any, extraMetadata?: {}) {
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IIntegrationFactoryParams } from '../types';
|
|
2
|
+
import SplitToGa from './SplitToGa';
|
|
3
|
+
import { SplitToGoogleAnalyticsOptions } from './types';
|
|
4
|
+
export declare function SplitToGoogleAnalytics(options?: SplitToGoogleAnalyticsOptions): (params: IIntegrationFactoryParams) => SplitToGa;
|
|
@@ -52,12 +52,23 @@ export interface GoogleAnalyticsToSplitOptions {
|
|
|
52
52
|
* If not provided, events are sent using the key and traffic type provided at SDK config
|
|
53
53
|
*/
|
|
54
54
|
identities?: Identity[];
|
|
55
|
+
/**
|
|
56
|
+
* Optional flag to log an error if the `auto-require` script is not detected.
|
|
57
|
+
* The auto-require script automatically requires the `splitTracker` plugin for created trackers,
|
|
58
|
+
* and should be placed right after your Google Analytics, Google Tag Manager or gtag.js script tag.
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#set-up-with-gtm-and-gtag.js}
|
|
61
|
+
*
|
|
62
|
+
* @property {boolean} autoRequire
|
|
63
|
+
* @default false
|
|
64
|
+
*/
|
|
65
|
+
autoRequire?: boolean;
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
57
68
|
* Enable 'Google Analytics to Split' integration, to track Google Analytics hits as Split events.
|
|
58
69
|
* Used by the browser variant of the isomorphic JS SDK.
|
|
59
70
|
*
|
|
60
|
-
* @see {@link https://help.split.io/hc/en-us/articles/
|
|
71
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#google-analytics-to-split}
|
|
61
72
|
*/
|
|
62
73
|
export interface IGoogleAnalyticsToSplitConfig extends GoogleAnalyticsToSplitOptions {
|
|
63
74
|
type: 'GOOGLE_ANALYTICS_TO_SPLIT';
|
|
@@ -125,7 +136,7 @@ export interface SplitToGoogleAnalyticsOptions {
|
|
|
125
136
|
* Enable 'Split to Google Analytics' integration, to track Split impressions and events as Google Analytics hits.
|
|
126
137
|
* Used by the browser variant of the isomorphic JS SDK.
|
|
127
138
|
*
|
|
128
|
-
* @see {@link https://help.split.io/hc/en-us/articles/
|
|
139
|
+
* @see {@link https://help.split.io/hc/en-us/articles/360040838752#split-to-google-analytics}
|
|
129
140
|
*/
|
|
130
141
|
export interface ISplitToGoogleAnalyticsConfig extends SplitToGoogleAnalyticsOptions {
|
|
131
142
|
type: 'SPLIT_TO_GOOGLE_ANALYTICS';
|
|
@@ -4,7 +4,7 @@ import { ISplitApi } from '../services/types';
|
|
|
4
4
|
import { ISettings } from '../types';
|
|
5
5
|
import { ISyncManager } from '../sync/types';
|
|
6
6
|
/**
|
|
7
|
-
* We'll listen for
|
|
7
|
+
* We'll listen for events over the window object.
|
|
8
8
|
*/
|
|
9
9
|
export declare class BrowserSignalListener implements ISignalListener {
|
|
10
10
|
private syncManager;
|
|
@@ -15,22 +15,22 @@ export declare class BrowserSignalListener implements ISignalListener {
|
|
|
15
15
|
constructor(syncManager: ISyncManager | undefined, settings: ISettings, storage: IStorageSync, serviceApi: ISplitApi);
|
|
16
16
|
/**
|
|
17
17
|
* start method.
|
|
18
|
-
* Called when SplitFactory is initialized.
|
|
19
|
-
* We add a handler on unload events. The handler flushes remaining impressions and events to the backend.
|
|
18
|
+
* Called when SplitFactory is initialized, it adds event listeners to close streaming and flush impressions and events.
|
|
20
19
|
*/
|
|
21
20
|
start(): void;
|
|
22
21
|
/**
|
|
23
22
|
* stop method.
|
|
24
|
-
* Called when client is destroyed.
|
|
25
|
-
* We need to remove the handler for unload events, since it can break if called when Split context was destroyed.
|
|
23
|
+
* Called when client is destroyed, it removes event listeners.
|
|
26
24
|
*/
|
|
27
25
|
stop(): void;
|
|
26
|
+
stopSync(): void;
|
|
28
27
|
/**
|
|
29
28
|
* flushData method.
|
|
30
|
-
* Called when
|
|
29
|
+
* Called when pagehide event is triggered. It flushed remaining impressions and events to the backend,
|
|
31
30
|
* using beacon API if possible, or falling back to regular post transport.
|
|
32
31
|
*/
|
|
33
32
|
flushData(): void;
|
|
33
|
+
flushDataIfHidden(): void;
|
|
34
34
|
private _flushData;
|
|
35
35
|
/**
|
|
36
36
|
* _sendBeacon method.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export declare const DEBUG_0 = 0;
|
|
2
|
+
export declare const DEBUG_1 = 1;
|
|
3
|
+
export declare const DEBUG_2 = 2;
|
|
4
|
+
export declare const DEBUG_3 = 3;
|
|
5
|
+
export declare const DEBUG_4 = 4;
|
|
6
|
+
export declare const DEBUG_5 = 5;
|
|
7
|
+
export declare const DEBUG_6 = 6;
|
|
8
|
+
export declare const DEBUG_7 = 7;
|
|
9
|
+
export declare const DEBUG_8 = 8;
|
|
10
|
+
export declare const DEBUG_9 = 9;
|
|
11
|
+
export declare const DEBUG_10 = 10;
|
|
12
|
+
export declare const DEBUG_11 = 11;
|
|
13
|
+
export declare const DEBUG_12 = 12;
|
|
14
|
+
export declare const DEBUG_13 = 13;
|
|
15
|
+
export declare const DEBUG_14 = 14;
|
|
16
|
+
export declare const DEBUG_15 = 15;
|
|
17
|
+
export declare const DEBUG_16 = 16;
|
|
18
|
+
export declare const DEBUG_17 = 17;
|
|
19
|
+
export declare const DEBUG_18 = 18;
|
|
20
|
+
export declare const DEBUG_19 = 19;
|
|
21
|
+
export declare const DEBUG_20 = 20;
|
|
22
|
+
export declare const DEBUG_21 = 21;
|
|
23
|
+
export declare const DEBUG_22 = 22;
|
|
24
|
+
export declare const DEBUG_23 = 23;
|
|
25
|
+
export declare const DEBUG_24 = 24;
|
|
26
|
+
export declare const DEBUG_25 = 25;
|
|
27
|
+
export declare const DEBUG_31 = 31;
|
|
28
|
+
export declare const DEBUG_32 = 32;
|
|
29
|
+
export declare const DEBUG_33 = 33;
|
|
30
|
+
export declare const DEBUG_36 = 36;
|
|
31
|
+
export declare const DEBUG_42 = 42;
|
|
32
|
+
export declare const DEBUG_43 = 43;
|
|
33
|
+
export declare const DEBUG_44 = 44;
|
|
34
|
+
export declare const DEBUG_45 = 45;
|
|
35
|
+
export declare const DEBUG_46 = 46;
|
|
36
|
+
export declare const DEBUG_47 = 47;
|
|
37
|
+
export declare const DEBUG_48 = 48;
|
|
38
|
+
export declare const DEBUG_49 = 49;
|
|
39
|
+
export declare const DEBUG_50 = 50;
|
|
40
|
+
export declare const DEBUG_51 = 51;
|
|
41
|
+
export declare const INFO_0 = 100;
|
|
42
|
+
export declare const INFO_1 = 101;
|
|
43
|
+
export declare const INFO_2 = 102;
|
|
44
|
+
export declare const INFO_3 = 103;
|
|
45
|
+
export declare const INFO_4 = 104;
|
|
46
|
+
export declare const INFO_5 = 105;
|
|
47
|
+
export declare const INFO_6 = 106;
|
|
48
|
+
export declare const INFO_7 = 107;
|
|
49
|
+
export declare const INFO_8 = 108;
|
|
50
|
+
export declare const INFO_9 = 109;
|
|
51
|
+
export declare const INFO_10 = 110;
|
|
52
|
+
export declare const INFO_11 = 111;
|
|
53
|
+
export declare const INFO_12 = 112;
|
|
54
|
+
export declare const INFO_13 = 113;
|
|
55
|
+
export declare const INFO_14 = 114;
|
|
56
|
+
export declare const INFO_15 = 115;
|
|
57
|
+
export declare const INFO_16 = 116;
|
|
58
|
+
export declare const INFO_17 = 117;
|
|
59
|
+
export declare const INFO_18 = 118;
|
|
60
|
+
export declare const INFO_19 = 119;
|
|
61
|
+
export declare const INFO_20 = 120;
|
|
62
|
+
export declare const INFO_21 = 121;
|
|
63
|
+
export declare const WARN_0 = 200;
|
|
64
|
+
export declare const WARN_1 = 201;
|
|
65
|
+
export declare const WARN_2 = 202;
|
|
66
|
+
export declare const WARN_4 = 204;
|
|
67
|
+
export declare const WARN_5 = 205;
|
|
68
|
+
export declare const WARN_6 = 206;
|
|
69
|
+
export declare const WARN_7 = 207;
|
|
70
|
+
export declare const WARN_8 = 208;
|
|
71
|
+
export declare const WARN_9 = 209;
|
|
72
|
+
export declare const WARN_10 = 210;
|
|
73
|
+
export declare const WARN_11 = 211;
|
|
74
|
+
export declare const WARN_12 = 212;
|
|
75
|
+
export declare const WARN_13 = 213;
|
|
76
|
+
export declare const WARN_14 = 214;
|
|
77
|
+
export declare const WARN_15 = 215;
|
|
78
|
+
export declare const WARN_17 = 217;
|
|
79
|
+
export declare const WARN_18 = 218;
|
|
80
|
+
export declare const WARN_19 = 219;
|
|
81
|
+
export declare const WARN_20 = 220;
|
|
82
|
+
export declare const WARN_21 = 221;
|
|
83
|
+
export declare const WARN_22 = 222;
|
|
84
|
+
export declare const WARN_23 = 223;
|
|
85
|
+
export declare const WARN_24 = 224;
|
|
86
|
+
export declare const WARN_25 = 225;
|
|
87
|
+
export declare const ERROR_0 = 300;
|
|
88
|
+
export declare const ERROR_2 = 302;
|
|
89
|
+
export declare const ERROR_3 = 303;
|
|
90
|
+
export declare const ERROR_4 = 304;
|
|
91
|
+
export declare const ERROR_5 = 305;
|
|
92
|
+
export declare const ERROR_7 = 307;
|
|
93
|
+
export declare const ERROR_9 = 309;
|
|
94
|
+
export declare const ERROR_10 = 310;
|
|
95
|
+
export declare const ERROR_11 = 311;
|
|
96
|
+
export declare const ERROR_12 = 312;
|
|
97
|
+
export declare const ERROR_13 = 313;
|
|
98
|
+
export declare const ERROR_14 = 314;
|
|
99
|
+
export declare const ERROR_15 = 315;
|
|
100
|
+
export declare const ERROR_16 = 316;
|
|
101
|
+
export declare const ERROR_17 = 317;
|
|
102
|
+
export declare const ERROR_18 = 318;
|
|
103
|
+
export declare const ERROR_19 = 319;
|
|
104
|
+
export declare const ERROR_20 = 320;
|
|
105
|
+
export declare const ERROR_21 = 321;
|
|
106
|
+
export declare const ERROR_22 = 322;
|
|
107
|
+
export declare const ERROR_23 = 323;
|
|
108
|
+
export declare const ERROR_24 = 324;
|
|
109
|
+
export declare const ERROR_25 = 325;
|
|
110
|
+
export declare const ERROR_26 = 326;
|
|
111
|
+
export declare const ERROR_32 = 332;
|
|
112
|
+
export declare const ERROR_33 = 333;
|
|
113
|
+
export declare const ERROR_34 = 334;
|
|
114
|
+
export declare const ERROR_35 = 335;
|
|
115
|
+
export declare const ERROR_36 = 336;
|
|
116
|
+
export declare const ERROR_37 = 337;
|
|
117
|
+
export declare const ERROR_38 = 338;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const DEBUG_28 = 28;
|
|
2
|
+
export declare const DEBUG_29 = 29;
|
|
3
|
+
export declare const DEBUG_30 = 30;
|
|
4
|
+
export declare const ERROR_1 = 301;
|
|
5
|
+
export declare const DEBUG_39 = 39;
|
|
6
|
+
export declare const DEBUG_40 = 40;
|
|
7
|
+
export declare const DEBUG_41 = 41;
|
|
8
|
+
export declare const ERROR_8 = 308;
|
|
9
|
+
export declare const DEBUG_34 = 34;
|
|
10
|
+
export declare const DEBUG_35 = 35;
|
|
11
|
+
export declare const ERROR_6 = 306;
|
|
12
|
+
export declare const WARN_3 = 203;
|
|
13
|
+
export declare const DEBUG_37 = 37;
|
|
14
|
+
export declare const DEBUG_38 = 38;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesDebug: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesDebugBrowser: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesDebugNode: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesError: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesErrorNode: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesInfo: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesWarn: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesWarnNode: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesDebugBrowser: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesDebugNode: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesErrorNode: [number, string][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const codesWarnNode: [number, string][];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ISyncManager } from '../sync/types';
|
|
2
|
+
import { ISettings } from '../types';
|
|
3
|
+
export declare function userConsentProps(settings: ISettings, syncManager?: ISyncManager): {
|
|
4
|
+
setUserConsent(consent: unknown): boolean;
|
|
5
|
+
getUserConsent(): import("../types").ConsentStatus | undefined;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ISdkClientFactoryParams } from '../sdkClient/types';
|
|
2
|
+
import { SplitIO } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory of client method for server-side SDKs (ISDK and IAsyncSDK)
|
|
5
|
+
*/
|
|
6
|
+
export declare function sdkManagerMethodFactory(params: ISdkClientFactoryParams): () => SplitIO.IManager | SplitIO.IAsyncManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ISplit } from '../dtos/types';
|
|
2
|
+
/**
|
|
3
|
+
* Collect segments from a raw split definition.
|
|
4
|
+
* Exported for testing purposes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function _parseSegments({ conditions }: ISplit): import("../utils/lang/sets").ISet<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Computes the set of segments used by splits.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getRegisteredSegments(splitDefs: string[]): string[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IStorageFactoryParams, IStorageSync } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* InMemory storage factory for standalone server-side SplitFactory
|
|
4
|
+
*
|
|
5
|
+
* @param params parameters required by EventsCacheSync
|
|
6
|
+
*/
|
|
7
|
+
export declare function InMemoryStorageFactory(params: IStorageFactoryParams): IStorageSync;
|
|
8
|
+
export declare namespace InMemoryStorageFactory {
|
|
9
|
+
var type: import("../types").StorageType;
|
|
10
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ISet } from '../../../utils/lang/sets';
|
|
2
|
+
import { ISegmentsCacheSync, ISplitsCacheSync, IStorageSync } from '../../../storages/types';
|
|
3
|
+
import { ISplitChangesFetcher } from '../fetchers/types';
|
|
4
|
+
import { ISplit } from '../../../dtos/types';
|
|
5
|
+
import { IReadinessManager, ISplitsEventEmitter } from '../../../readiness/types';
|
|
6
|
+
import { ISplitsSyncTask } from '../types';
|
|
7
|
+
import { IFetchSplitChanges } from '../../../services/types';
|
|
8
|
+
import { ISettings } from '../../../types';
|
|
9
|
+
declare type ISplitChangesUpdater = (noCache?: boolean) => Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Collect segments from a raw split definition.
|
|
12
|
+
* Exported for testing purposes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseSegments({ conditions }: ISplit): ISet<string>;
|
|
15
|
+
interface ISplitMutations {
|
|
16
|
+
added: [string, string][];
|
|
17
|
+
removed: string[];
|
|
18
|
+
segments: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Given the list of splits from /splitChanges endpoint, it returns the mutations,
|
|
22
|
+
* i.e., an object with added splits, removed splits and used segments.
|
|
23
|
+
* Exported for testing purposes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeSplitsMutation(entries: ISplit[]): ISplitMutations;
|
|
26
|
+
/**
|
|
27
|
+
* factory of SplitChanges updater (a.k.a, SplitsSyncTask), a task that:
|
|
28
|
+
* - fetches split changes using `splitChangesFetcher`
|
|
29
|
+
* - updates `splitsCache`
|
|
30
|
+
* - uses `splitsEventEmitter` to emit events related to split data updates
|
|
31
|
+
* Exported for testing purposes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function splitChangesUpdaterFactory(splitChangesFetcher: ISplitChangesFetcher, splitsCache: ISplitsCacheSync, segmentsCache: ISegmentsCacheSync, splitsEventEmitter: ISplitsEventEmitter, requestTimeoutBeforeReady: number, retriesOnFailureBeforeReady: number): ISplitChangesUpdater;
|
|
34
|
+
export default function splitsSyncTaskFactory(fetchSplitChanges: IFetchSplitChanges, storage: IStorageSync, readiness: IReadinessManager, settings: ISettings): ISplitsSyncTask;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ISet } from '../../../utils/lang/sets';
|
|
2
|
+
import { ISegmentsCacheSync, ISplitsCacheSync, IStorageSync } from '../../../storages/types';
|
|
3
|
+
import { ISplitChangesFetcher } from '../fetchers/types';
|
|
4
|
+
import { ISplit } from '../../../dtos/types';
|
|
5
|
+
import { IReadinessManager, ISplitsEventEmitter } from '../../../readiness/types';
|
|
6
|
+
import { ISplitsSyncTask } from '../types';
|
|
7
|
+
import { IFetchSplitChanges } from '../../../services/types';
|
|
8
|
+
import { ISettings } from '../../../types';
|
|
9
|
+
declare type ISplitChangesUpdater = (noCache?: boolean) => Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Collect segments from a raw split definition.
|
|
12
|
+
* Exported for testing purposes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseSegments({ conditions }: ISplit): ISet<string>;
|
|
15
|
+
interface ISplitMutations {
|
|
16
|
+
added: [string, string][];
|
|
17
|
+
removed: string[];
|
|
18
|
+
segments: string[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Given the list of splits from /splitChanges endpoint, it returns the mutations,
|
|
22
|
+
* i.e., an object with added splits, removed splits and used segments.
|
|
23
|
+
* Exported for testing purposes.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeSplitsMutation(entries: ISplit[]): ISplitMutations;
|
|
26
|
+
/**
|
|
27
|
+
* factory of SplitChanges updater (a.k.a, SplitsSyncTask), a task that:
|
|
28
|
+
* - fetches split changes using `splitChangesFetcher`
|
|
29
|
+
* - updates `splitsCache`
|
|
30
|
+
* - uses `splitsEventEmitter` to emit events related to split data updates
|
|
31
|
+
* Exported for testing purposes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function splitChangesUpdaterFactory(splitChangesFetcher: ISplitChangesFetcher, splitsCache: ISplitsCacheSync, segmentsCache: ISegmentsCacheSync, splitsEventEmitter: ISplitsEventEmitter, requestTimeoutBeforeReady: number, retriesOnFailureBeforeReady: number): ISplitChangesUpdater;
|
|
34
|
+
export default function splitsSyncTaskFactory(fetchSplitChanges: IFetchSplitChanges, storage: IStorageSync, readiness: IReadinessManager, settings: ISettings): ISplitsSyncTask;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IFetchAuth } from '../../../services/types';
|
|
2
|
+
import { IAuthenticate } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory of authentication function.
|
|
5
|
+
*
|
|
6
|
+
* @param fetchAuth `SplitAPI.fetchAuth` endpoint
|
|
7
|
+
*/
|
|
8
|
+
export declare function authenticateFactory(fetchAuth: IFetchAuth): IAuthenticate;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the hash of a given user key
|
|
11
|
+
*/
|
|
12
|
+
export declare function hashUserKey(userKey: string): string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IFetchAuthV2 } from '../../../services/types';
|
|
2
|
+
import { IAuthenticateV2 } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Factory of authentication function.
|
|
5
|
+
*
|
|
6
|
+
* @param fetchAuth `SplitAPI.fetchAuth` endpoint
|
|
7
|
+
*/
|
|
8
|
+
export declare function authenticateFactory(fetchAuthV2: IFetchAuthV2): IAuthenticateV2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pushManagerCSFactory: (params: import("../types").ISyncManagerFactoryParams, pollingManager: import("../polling/types").IPollingManager) => import("./types").IPushManager | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IPushManagerCS } from './types';
|
|
2
|
+
import { IStorageSync } from '../../storages/types';
|
|
3
|
+
import { IReadinessManager } from '../../readiness/types';
|
|
4
|
+
import { IPollingManager } from '../polling/types';
|
|
5
|
+
import { IFetchAuthV2 } from '../../services/types';
|
|
6
|
+
import { ISettings } from '../../types';
|
|
7
|
+
import { IPlatform } from '../../sdkFactory/types';
|
|
8
|
+
/**
|
|
9
|
+
* PushManager factory:
|
|
10
|
+
* - for server-side if key is not provided in settings.
|
|
11
|
+
* - for client-side, with support for multiple clients, if key is provided in settings
|
|
12
|
+
*/
|
|
13
|
+
export default function pushManagerFactory(pollingManager: IPollingManager, storage: IStorageSync, readiness: IReadinessManager, fetchAuthV2: IFetchAuthV2, platform: IPlatform, settings: ISettings): IPushManagerCS | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pushManagerSSFactory: (params: import("../types").ISyncManagerFactoryParams, pollingManager: import("../polling/types").IPollingManager) => import("./types").IPushManager | undefined;
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ISyncManagerCS, ISyncManagerFactoryParams } from './types';
|
|
2
|
+
import { ISplitsParser } from './offline/splitsParser/types';
|
|
3
|
+
/**
|
|
4
|
+
* Offline SyncManager factory.
|
|
5
|
+
* Can be used for server-side API, and client-side API with or without multiple clients.
|
|
6
|
+
*
|
|
7
|
+
* @param splitsParser e.g., `splitsParserFromFile`, `splitsParserFromSettings`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function syncManagerOfflineFactory(splitsParserFactory: () => ISplitsParser): (params: ISyncManagerFactoryParams) => ISyncManagerCS;
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class SplitError extends Error {
|
|
2
|
+
constructor(msg?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class SplitTimeoutError extends SplitError {
|
|
5
|
+
constructor(msg?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class SplitNetworkError extends SplitError {
|
|
8
|
+
statusCode?: number;
|
|
9
|
+
constructor(msg?: string, code?: number);
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function UTF16ToUTF8(key: string): string | undefined;
|
|
2
|
+
/*!
|
|
3
|
+
* +----------------------------------------------------------------------------------+
|
|
4
|
+
* | murmurHash3.js v3.0.0 (http://github.com/karanlyons/murmurHash3.js) |
|
|
5
|
+
* | A TypeScript/JavaScript implementation of MurmurHash3's hashing algorithms. |
|
|
6
|
+
* |----------------------------------------------------------------------------------|
|
|
7
|
+
* | Copyright (c) 2012-2020 Karan Lyons. Freely distributable under the MIT license. |
|
|
8
|
+
* +----------------------------------------------------------------------------------+
|
|
9
|
+
*/
|
|
10
|
+
export declare function x86Multiply(m: number, n: number): number;
|
|
11
|
+
export declare function x86Rotl(m: number, n: number): number;
|
|
12
|
+
export declare function x86Fmix(h: number): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ISettings } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* This function validates `settings.storage` object
|
|
4
|
+
*
|
|
5
|
+
* @param {any} settings config object provided by the user to initialize the sdk
|
|
6
|
+
*
|
|
7
|
+
* @returns {Object} valid storage factory. It might be the default `InMemoryStorageCSFactory` if the provided storage is invalid.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateLocalhost(settings: ISettings): import("../../../types").SplitIO.LocalhostFactory | undefined;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ILogger } from '../../logger/types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates the `log` (logger) property at config.
|
|
4
|
+
*
|
|
5
|
+
* @param settings user config object
|
|
6
|
+
* @returns the provided logger or a no-op logger if no one is provided
|
|
7
|
+
* @throws throws an error if a logger was provided but is invalid
|
|
8
|
+
*/
|
|
9
|
+
export default function logger(settings: {
|
|
10
|
+
log: unknown;
|
|
11
|
+
}): ILogger;
|
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IResponse } from '../../services/types';
|
|
3
|
-
interface MetricsCollector {
|
|
4
|
-
countException(): void;
|
|
5
|
-
count(status: number): void;
|
|
6
|
-
latency(ms: number): void;
|
|
7
|
-
ready(ms: number): void;
|
|
8
|
-
getTreatment(ms: number): void;
|
|
9
|
-
getTreatments(ms: number): void;
|
|
10
|
-
getTreatmentWithConfig(ms: number): void;
|
|
11
|
-
getTreatmentsWithConfig(ms: number): void;
|
|
12
|
-
[method: string]: (ms: number) => void;
|
|
13
|
-
}
|
|
14
|
-
export declare const TrackerAPI: {
|
|
15
|
-
/**
|
|
16
|
-
* "Private" method, used to attach count/countException and stop callbacks to a promise.
|
|
17
|
-
*
|
|
18
|
-
* @param {ILogger} log - Logger.
|
|
19
|
-
* @param {Promise} promise - The promise we want to attach the callbacks.
|
|
20
|
-
* @param {string} task - The name of the task.
|
|
21
|
-
* @param {number | string} modifier - (optional) The modifier for the task, if any.
|
|
22
|
-
*/
|
|
23
|
-
__attachToPromise(log: ILogger, promise: Promise<IResponse>, task: string, collector: false | MetricsCollector, modifier?: string | number | undefined): Promise<IResponse>;
|
|
24
|
-
/**
|
|
25
|
-
* Starts tracking the time for a given task. All tasks tracked are considered "unique" because
|
|
26
|
-
* there may be multiple SDK instances tracking a "generic" task, making any task non-generic.
|
|
27
|
-
*
|
|
28
|
-
* @param {ILogger} log - Logger.
|
|
29
|
-
* @param {string} task - The task we are starting.
|
|
30
|
-
* @param {Object} collectors - The collectors map.
|
|
31
|
-
* @param {Promise} promise - (optional) The promise we are tracking.
|
|
32
|
-
* @return {Function | Promise} The stop function for this specific task or the promise received with the callbacks registered.
|
|
33
|
-
*/
|
|
34
|
-
start(log: ILogger, task: string, collectors?: Record<string, MetricsCollector> | undefined, promise?: Promise<IResponse> | undefined, now?: (() => number) | undefined): Promise<IResponse> | (() => number);
|
|
35
|
-
/**
|
|
36
|
-
* Setup the collector for a task that reports metrics.
|
|
37
|
-
*
|
|
38
|
-
* @param {string} task - The task name
|
|
39
|
-
* @param {number | string} taskUniqueId - The unique identifier for this task
|
|
40
|
-
* @param {Object} collectors - The collectors map.
|
|
41
|
-
*/
|
|
42
|
-
setCollectorForTask(task: string, taskUniqueId: number | string, collectors: Record<string, MetricsCollector>): void;
|
|
43
|
-
/**
|
|
44
|
-
* Stops the tracking of a given task.
|
|
45
|
-
*
|
|
46
|
-
* @param {ILogger} log - Logger.
|
|
47
|
-
* @param {string} task - The task we are starting.
|
|
48
|
-
* @param {number | string} modifier - (optional) The modifier for that specific task.
|
|
49
|
-
*/
|
|
50
|
-
stop(log: ILogger, task: string, modifier?: string | number | undefined): number | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* The constants shortcut for the task names.
|
|
53
|
-
*/
|
|
54
|
-
TaskNames: {
|
|
55
|
-
SDK_READY: string;
|
|
56
|
-
SDK_GET_TREATMENT: string;
|
|
57
|
-
SDK_GET_TREATMENTS: string;
|
|
58
|
-
SDK_GET_TREATMENT_WITH_CONFIG: string;
|
|
59
|
-
SDK_GET_TREATMENTS_WITH_CONFIG: string;
|
|
60
|
-
SPLITS_READY: string;
|
|
61
|
-
SEGMENTS_READY: string;
|
|
62
|
-
METRICS_PUSH: string;
|
|
63
|
-
IMPRESSIONS_PUSH: string;
|
|
64
|
-
EVENTS_PUSH: string;
|
|
65
|
-
MY_SEGMENTS_FETCH: string;
|
|
66
|
-
SEGMENTS_FETCH: string;
|
|
67
|
-
SPLITS_FETCH: string;
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export {};
|
|
1
|
+
export declare function timeTracker(now: () => number): () => () => number;
|