@splitsoftware/splitio-commons 1.3.2-rc.6 → 1.4.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 +1 -1
- package/cjs/integrations/ga/GaToSplit.js +34 -3
- package/cjs/utils/settingsValidation/index.js +3 -10
- package/esm/integrations/ga/GaToSplit.js +32 -2
- package/esm/utils/settingsValidation/index.js +4 -11
- package/package.json +1 -1
- package/src/integrations/ga/GaToSplit.ts +38 -2
- package/src/integrations/ga/types.ts +7 -0
- package/src/utils/lang/index.ts +1 -1
- package/src/utils/settingsValidation/index.ts +3 -10
- package/types/integrations/ga/GaToSplit.d.ts +1 -0
- package/types/integrations/ga/types.d.ts +7 -0
- package/types/utils/lang/index.d.ts +1 -1
package/CHANGES.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
1.4.0 (May
|
|
1
|
+
1.4.0 (May 24, 2022)
|
|
2
2
|
- Added `scheduler.telemetryRefreshRate` property to SDK configuration, and deprecated `scheduler.metricsRefreshRate` property.
|
|
3
3
|
- Updated SDK telemetry storage, metrics and updater to be more effective and send less often.
|
|
4
4
|
- Bugfixing - Updated default values for `scheduler.impressionsRefreshRate` config parameter: 300s for OPTIMIZED impression mode and 60s for DEBUG impression mode.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GaToSplit = exports.fixEventTypeId = exports.validateEventData = exports.validateIdentities = exports.defaultPrefix = exports.defaultMapper = void 0;
|
|
3
|
+
exports.autoRequireScript = exports.GaToSplit = exports.fixEventTypeId = exports.validateEventData = exports.validateIdentities = exports.defaultPrefix = exports.defaultMapper = void 0;
|
|
4
4
|
/* eslint-disable no-undef */
|
|
5
5
|
var objectAssign_1 = require("../../utils/lang/objectAssign");
|
|
6
6
|
var lang_1 = require("../../utils/lang");
|
|
@@ -12,8 +12,9 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
12
12
|
* that the global command queue has been renamed or not yet defined.
|
|
13
13
|
* @param {string} pluginName The plugin name identifier.
|
|
14
14
|
* @param {Function} pluginConstructor The plugin constructor function.
|
|
15
|
+
* @param {boolean} autoRequire Whether the integration should automatically queue a 'require' command for each 'create' command.
|
|
15
16
|
*/
|
|
16
|
-
function providePlugin(pluginName, pluginConstructor) {
|
|
17
|
+
function providePlugin(pluginName, pluginConstructor, autoRequire) {
|
|
17
18
|
// get reference to global command queue. Init it if not defined yet.
|
|
18
19
|
// @ts-expect-error
|
|
19
20
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
@@ -27,6 +28,8 @@ function providePlugin(pluginName, pluginConstructor) {
|
|
|
27
28
|
// provides the plugin for use with analytics.js.
|
|
28
29
|
// @ts-expect-error
|
|
29
30
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
31
|
+
if (autoRequire)
|
|
32
|
+
autoRequireScript();
|
|
30
33
|
}
|
|
31
34
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
32
35
|
var defaultMapping = {
|
|
@@ -246,6 +249,34 @@ function GaToSplit(sdkOptions, params) {
|
|
|
246
249
|
return SplitTracker;
|
|
247
250
|
}());
|
|
248
251
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
249
|
-
providePlugin('splitTracker', SplitTracker);
|
|
252
|
+
providePlugin('splitTracker', SplitTracker, sdkOptions.autoRequire);
|
|
250
253
|
}
|
|
251
254
|
exports.GaToSplit = GaToSplit;
|
|
255
|
+
function autoRequireScript() {
|
|
256
|
+
(function (i, r) {
|
|
257
|
+
i['GoogleAnalyticsObject'] = r;
|
|
258
|
+
i[r] = i[r] || function () { i[r].q.push(arguments); };
|
|
259
|
+
i[r].q = i[r].q || [];
|
|
260
|
+
var ts = {}; // Tracker names
|
|
261
|
+
var o = i[r].q.push; // Reference to Array.prototype.push
|
|
262
|
+
i[r].q.push = function () {
|
|
263
|
+
var result = o.apply(this, arguments);
|
|
264
|
+
var v = arguments[0];
|
|
265
|
+
if (v && v[0] === 'create') {
|
|
266
|
+
var t = typeof v[2] === 'object' && typeof v[2].name === 'string' ?
|
|
267
|
+
v[2].name : // `ga('create', 'UA-ID', { name: 'trackerName', ... })`
|
|
268
|
+
typeof v[3] === 'object' && typeof v[3].name === 'string' ?
|
|
269
|
+
v[3].name : // `ga('create', 'UA-ID', 'auto', { name: 'trackerName', ... })`
|
|
270
|
+
typeof v[3] === 'string' ?
|
|
271
|
+
v[3] : // `ga('create', 'UA-ID', 'auto', 'trackerName')`
|
|
272
|
+
undefined; // No name tracker, `ga('create', 'UA-ID', 'auto')`
|
|
273
|
+
if (!ts[t]) {
|
|
274
|
+
ts[t] = true;
|
|
275
|
+
i[r](t ? t + '.require' : 'require', 'splitTracker'); // Auto-require
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
};
|
|
280
|
+
})(window, 'ga');
|
|
281
|
+
}
|
|
282
|
+
exports.autoRequireScript = autoRequireScript;
|
|
@@ -112,16 +112,9 @@ function settingsValidation(config, validationParams) {
|
|
|
112
112
|
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
|
|
113
113
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
114
114
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
scheduler.impressionsRefreshRate =
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
122
|
-
if (withDefaults.sync.impressionsMode === constants_1.DEBUG)
|
|
123
|
-
scheduler.impressionsRefreshRate = 60;
|
|
124
|
-
}
|
|
115
|
+
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
116
|
+
if ((0, lang_1.get)(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === constants_1.DEBUG)
|
|
117
|
+
scheduler.impressionsRefreshRate = 60;
|
|
125
118
|
scheduler.impressionsRefreshRate = fromSecondsToMillis(scheduler.impressionsRefreshRate);
|
|
126
119
|
// Log deprecation for old telemetry param
|
|
127
120
|
if (scheduler.metricsRefreshRate)
|
|
@@ -9,8 +9,9 @@ var logNameMapper = 'ga-to-split:mapper';
|
|
|
9
9
|
* that the global command queue has been renamed or not yet defined.
|
|
10
10
|
* @param {string} pluginName The plugin name identifier.
|
|
11
11
|
* @param {Function} pluginConstructor The plugin constructor function.
|
|
12
|
+
* @param {boolean} autoRequire Whether the integration should automatically queue a 'require' command for each 'create' command.
|
|
12
13
|
*/
|
|
13
|
-
function providePlugin(pluginName, pluginConstructor) {
|
|
14
|
+
function providePlugin(pluginName, pluginConstructor, autoRequire) {
|
|
14
15
|
// get reference to global command queue. Init it if not defined yet.
|
|
15
16
|
// @ts-expect-error
|
|
16
17
|
var gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
@@ -24,6 +25,8 @@ function providePlugin(pluginName, pluginConstructor) {
|
|
|
24
25
|
// provides the plugin for use with analytics.js.
|
|
25
26
|
// @ts-expect-error
|
|
26
27
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
28
|
+
if (autoRequire)
|
|
29
|
+
autoRequireScript();
|
|
27
30
|
}
|
|
28
31
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
29
32
|
var defaultMapping = {
|
|
@@ -240,5 +243,32 @@ export function GaToSplit(sdkOptions, params) {
|
|
|
240
243
|
return SplitTracker;
|
|
241
244
|
}());
|
|
242
245
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
243
|
-
providePlugin('splitTracker', SplitTracker);
|
|
246
|
+
providePlugin('splitTracker', SplitTracker, sdkOptions.autoRequire);
|
|
247
|
+
}
|
|
248
|
+
export function autoRequireScript() {
|
|
249
|
+
(function (i, r) {
|
|
250
|
+
i['GoogleAnalyticsObject'] = r;
|
|
251
|
+
i[r] = i[r] || function () { i[r].q.push(arguments); };
|
|
252
|
+
i[r].q = i[r].q || [];
|
|
253
|
+
var ts = {}; // Tracker names
|
|
254
|
+
var o = i[r].q.push; // Reference to Array.prototype.push
|
|
255
|
+
i[r].q.push = function () {
|
|
256
|
+
var result = o.apply(this, arguments);
|
|
257
|
+
var v = arguments[0];
|
|
258
|
+
if (v && v[0] === 'create') {
|
|
259
|
+
var t = typeof v[2] === 'object' && typeof v[2].name === 'string' ?
|
|
260
|
+
v[2].name : // `ga('create', 'UA-ID', { name: 'trackerName', ... })`
|
|
261
|
+
typeof v[3] === 'object' && typeof v[3].name === 'string' ?
|
|
262
|
+
v[3].name : // `ga('create', 'UA-ID', 'auto', { name: 'trackerName', ... })`
|
|
263
|
+
typeof v[3] === 'string' ?
|
|
264
|
+
v[3] : // `ga('create', 'UA-ID', 'auto', 'trackerName')`
|
|
265
|
+
undefined; // No name tracker, `ga('create', 'UA-ID', 'auto')`
|
|
266
|
+
if (!ts[t]) {
|
|
267
|
+
ts[t] = true;
|
|
268
|
+
i[r](t ? t + '.require' : 'require', 'splitTracker'); // Auto-require
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
272
|
+
};
|
|
273
|
+
})(window, 'ga');
|
|
244
274
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { merge } from '../lang';
|
|
1
|
+
import { merge, get } from '../lang';
|
|
2
2
|
import { mode } from './mode';
|
|
3
3
|
import { validateSplitFilters } from './splitFilters';
|
|
4
4
|
import { STANDALONE_MODE, OPTIMIZED, LOCALHOST_MODE, DEBUG } from '../constants';
|
|
@@ -109,16 +109,9 @@ export function settingsValidation(config, validationParams) {
|
|
|
109
109
|
scheduler.offlineRefreshRate = fromSecondsToMillis(scheduler.offlineRefreshRate);
|
|
110
110
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
111
111
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
scheduler.impressionsRefreshRate =
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
119
|
-
if (withDefaults.sync.impressionsMode === DEBUG)
|
|
120
|
-
scheduler.impressionsRefreshRate = 60;
|
|
121
|
-
}
|
|
112
|
+
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
113
|
+
if (get(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === DEBUG)
|
|
114
|
+
scheduler.impressionsRefreshRate = 60;
|
|
122
115
|
scheduler.impressionsRefreshRate = fromSecondsToMillis(scheduler.impressionsRefreshRate);
|
|
123
116
|
// Log deprecation for old telemetry param
|
|
124
117
|
if (scheduler.metricsRefreshRate)
|
package/package.json
CHANGED
|
@@ -21,8 +21,9 @@ const logNameMapper = 'ga-to-split:mapper';
|
|
|
21
21
|
* that the global command queue has been renamed or not yet defined.
|
|
22
22
|
* @param {string} pluginName The plugin name identifier.
|
|
23
23
|
* @param {Function} pluginConstructor The plugin constructor function.
|
|
24
|
+
* @param {boolean} autoRequire Whether the integration should automatically queue a 'require' command for each 'create' command.
|
|
24
25
|
*/
|
|
25
|
-
function providePlugin(pluginName: string, pluginConstructor: Function) {
|
|
26
|
+
function providePlugin(pluginName: string, pluginConstructor: Function, autoRequire?: boolean) {
|
|
26
27
|
// get reference to global command queue. Init it if not defined yet.
|
|
27
28
|
// @ts-expect-error
|
|
28
29
|
const gaAlias = window.GoogleAnalyticsObject || 'ga';
|
|
@@ -33,6 +34,8 @@ function providePlugin(pluginName: string, pluginConstructor: Function) {
|
|
|
33
34
|
// provides the plugin for use with analytics.js.
|
|
34
35
|
// @ts-expect-error
|
|
35
36
|
window[gaAlias]('provide', pluginName, pluginConstructor);
|
|
37
|
+
|
|
38
|
+
if (autoRequire) autoRequireScript();
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
// Default mapping: object used for building the default mapper from hits to Split events
|
|
@@ -284,5 +287,38 @@ export function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIn
|
|
|
284
287
|
}
|
|
285
288
|
|
|
286
289
|
// Register the plugin, even if config is invalid, since, if not provided, it will block `ga` command queue.
|
|
287
|
-
providePlugin('splitTracker', SplitTracker);
|
|
290
|
+
providePlugin('splitTracker', SplitTracker, sdkOptions.autoRequire);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function autoRequireScript() {
|
|
294
|
+
(function (i: any, r: any) {
|
|
295
|
+
i['GoogleAnalyticsObject'] = r;
|
|
296
|
+
i[r] = i[r] || function () { i[r].q.push(arguments); };
|
|
297
|
+
i[r].q = i[r].q || [];
|
|
298
|
+
|
|
299
|
+
var ts: any = {}; // Tracker names
|
|
300
|
+
var o = i[r].q.push; // Reference to Array.prototype.push
|
|
301
|
+
i[r].q.push = function () {
|
|
302
|
+
var result = o.apply(this, arguments);
|
|
303
|
+
|
|
304
|
+
var v = arguments[0];
|
|
305
|
+
if (v && v[0] === 'create') {
|
|
306
|
+
var t = typeof v[2] === 'object' && typeof v[2].name === 'string' ?
|
|
307
|
+
v[2].name : // `ga('create', 'UA-ID', { name: 'trackerName', ... })`
|
|
308
|
+
typeof v[3] === 'object' && typeof v[3].name === 'string' ?
|
|
309
|
+
v[3].name : // `ga('create', 'UA-ID', 'auto', { name: 'trackerName', ... })`
|
|
310
|
+
typeof v[3] === 'string' ?
|
|
311
|
+
v[3] : // `ga('create', 'UA-ID', 'auto', 'trackerName')`
|
|
312
|
+
undefined; // No name tracker, `ga('create', 'UA-ID', 'auto')`
|
|
313
|
+
|
|
314
|
+
if (!ts[t]) {
|
|
315
|
+
ts[t] = true;
|
|
316
|
+
i[r](t ? t + '.require' : 'require', 'splitTracker'); // Auto-require
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return result;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
})(window, 'ga');
|
|
288
324
|
}
|
|
@@ -53,6 +53,13 @@ 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 automatically require the `splitTracker` plugin for all created trackers.
|
|
58
|
+
* If true, it will spy on the ga command queue, and run `ga('[trackerName].require', 'splitTracker');` for each 'create' command.
|
|
59
|
+
* @property {boolean} autoRequire
|
|
60
|
+
* @default false
|
|
61
|
+
*/
|
|
62
|
+
autoRequire?: boolean,
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
/**
|
package/src/utils/lang/index.ts
CHANGED
|
@@ -71,7 +71,7 @@ export function forOwn<T>(obj: { [key: string]: T }, iteratee: (value: T, key: s
|
|
|
71
71
|
* Safely retrieve the specified prop from obj. If we can't retrieve
|
|
72
72
|
* that property value, we return the default value.
|
|
73
73
|
*/
|
|
74
|
-
export function get(obj: any, prop: any, val
|
|
74
|
+
export function get(obj: any, prop: any, val?: any): any {
|
|
75
75
|
let res = val;
|
|
76
76
|
|
|
77
77
|
try { // No risks nor lots of checks.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { merge } from '../lang';
|
|
1
|
+
import { merge, get } from '../lang';
|
|
2
2
|
import { mode } from './mode';
|
|
3
3
|
import { validateSplitFilters } from './splitFilters';
|
|
4
4
|
import { STANDALONE_MODE, OPTIMIZED, LOCALHOST_MODE, DEBUG } from '../constants';
|
|
@@ -131,15 +131,8 @@ export function settingsValidation(config: unknown, validationParams: ISettingsV
|
|
|
131
131
|
scheduler.eventsPushRate = fromSecondsToMillis(scheduler.eventsPushRate);
|
|
132
132
|
scheduler.telemetryRefreshRate = fromSecondsToMillis(validateMinValue('telemetryRefreshRate', scheduler.telemetryRefreshRate, 60));
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
scheduler.impressionsRefreshRate = validateMinValue('impressionsRefreshRate', scheduler.impressionsRefreshRate,
|
|
137
|
-
withDefaults.sync.impressionsMode === DEBUG ? 1 : 60 // Min is 1 sec for DEBUG and 60 secs for OPTIMIZED
|
|
138
|
-
);
|
|
139
|
-
} else {
|
|
140
|
-
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
141
|
-
if (withDefaults.sync.impressionsMode === DEBUG) scheduler.impressionsRefreshRate = 60;
|
|
142
|
-
}
|
|
134
|
+
// Default impressionsRefreshRate for DEBUG mode is 60 secs
|
|
135
|
+
if (get(config, 'scheduler.impressionsRefreshRate') === undefined && withDefaults.sync.impressionsMode === DEBUG) scheduler.impressionsRefreshRate = 60;
|
|
143
136
|
scheduler.impressionsRefreshRate = fromSecondsToMillis(scheduler.impressionsRefreshRate);
|
|
144
137
|
|
|
145
138
|
// Log deprecation for old telemetry param
|
|
@@ -38,3 +38,4 @@ export declare function fixEventTypeId(log: ILogger, eventTypeId: any): any;
|
|
|
38
38
|
* @param {object} log factory logger
|
|
39
39
|
*/
|
|
40
40
|
export declare function GaToSplit(sdkOptions: GoogleAnalyticsToSplitOptions, params: IIntegrationFactoryParams): void;
|
|
41
|
+
export declare function autoRequireScript(): void;
|
|
@@ -52,6 +52,13 @@ 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 automatically require the `splitTracker` plugin for all created trackers.
|
|
57
|
+
* If true, it will spy on the ga command queue, and run `ga('[trackerName].require', 'splitTracker');` for each 'create' command.
|
|
58
|
+
* @property {boolean} autoRequire
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
autoRequire?: boolean;
|
|
55
62
|
}
|
|
56
63
|
/**
|
|
57
64
|
* Enable 'Google Analytics to Split' integration, to track Google Analytics hits as Split events.
|
|
@@ -28,7 +28,7 @@ export declare function forOwn<T>(obj: {
|
|
|
28
28
|
* Safely retrieve the specified prop from obj. If we can't retrieve
|
|
29
29
|
* that property value, we return the default value.
|
|
30
30
|
*/
|
|
31
|
-
export declare function get(obj: any, prop: any, val
|
|
31
|
+
export declare function get(obj: any, prop: any, val?: any): any;
|
|
32
32
|
/**
|
|
33
33
|
* Parses an array into a map of different arrays, grouping by the specified prop value.
|
|
34
34
|
*/
|