@useblu/blu-lytics 1.0.1 → 1.0.2
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/lib/dispatchers/dispatchers.spec.js +5 -0
- package/lib/dispatchers/index.d.ts.map +1 -1
- package/lib/dispatchers/index.js +27 -23
- package/lib/initializers/index.d.ts.map +1 -1
- package/lib/initializers/index.js +5 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.d.ts.map +1 -1
- package/lib/utils/index.js +15 -1
- package/package.json +1 -1
|
@@ -18,6 +18,11 @@ describe('Event dispatching functions', function () {
|
|
|
18
18
|
afterEach(function () {
|
|
19
19
|
jest.clearAllMocks();
|
|
20
20
|
});
|
|
21
|
+
var localStorageKey = '_bl_providers';
|
|
22
|
+
var providers = ['Sentry', 'MixPanel'];
|
|
23
|
+
beforeEach(function () {
|
|
24
|
+
localStorage.setItem(localStorageKey, JSON.stringify([providers]));
|
|
25
|
+
});
|
|
21
26
|
it('should be dispatch sendScreenEvent', function () {
|
|
22
27
|
var consoleLogSpy = jest.spyOn(console, 'log');
|
|
23
28
|
sendScreenEvent('TestScreen');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dispatchers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dispatchers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGpF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,cAAe,SAAS,KAAG,IA2BlE,CAAC;AAIF,QAAA,MAAM,eAAe,WAAY,MAAM,KAAG,IAMzC,CAAC;AAEF,QAAA,MAAM,eAAe,UAAW,MAAM,cAAc,cAAc,KAAG,IAQpE,CAAC;AAEF,QAAA,MAAM,sBAAsB,OACtB,MAAM,kBACM,kBAAkB,KACjC,IAQF,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAE,CAAC"}
|
package/lib/dispatchers/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
-
import { userSelectedEnvironment } from '../initializers';
|
|
3
2
|
import { providersList } from '../providers';
|
|
4
|
-
import {
|
|
3
|
+
import { checkIfMixPanelIsInitialized } from '../utils';
|
|
5
4
|
/**
|
|
6
5
|
* Dispatches the specified event data to all configured providers.
|
|
7
6
|
*
|
|
@@ -9,28 +8,33 @@ import { isValidProvidersList } from '../utils';
|
|
|
9
8
|
* @returns {void}
|
|
10
9
|
*/
|
|
11
10
|
export var dispatchEventToAllProviders = function (eventData) {
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
var localStorageProvidersList = JSON.parse(localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem('_bl_providers'));
|
|
12
|
+
var providersFiltered = localStorageProvidersList
|
|
13
|
+
? providersList.filter(function (item) { return localStorageProvidersList.includes(item.name); })
|
|
14
|
+
: providersList;
|
|
15
|
+
if (providersFiltered.length > 0) {
|
|
16
|
+
providersFiltered.forEach(function (provider) {
|
|
17
|
+
checkIfMixPanelIsInitialized(provider.name);
|
|
18
|
+
var actions = {
|
|
19
|
+
screenEvent: function () { return provider.screenEvent
|
|
20
|
+
&& eventData.screen
|
|
21
|
+
&& provider.screenEvent(eventData.screen); },
|
|
22
|
+
customEvent: function () { return provider.customEvent
|
|
23
|
+
&& eventData.event
|
|
24
|
+
&& eventData.properties
|
|
25
|
+
&& provider.customEvent(eventData.event, eventData.properties); },
|
|
26
|
+
userIdentification: function () { return provider.userIdentification
|
|
27
|
+
&& eventData.id
|
|
28
|
+
&& eventData.userProperties
|
|
29
|
+
&& provider.userIdentification(eventData.id, eventData.userProperties); }
|
|
30
|
+
};
|
|
31
|
+
Object.values(actions).forEach(function (action) { return action(); });
|
|
32
|
+
});
|
|
14
33
|
}
|
|
15
|
-
providersList.forEach(function (provider) {
|
|
16
|
-
var actions = {
|
|
17
|
-
screenEvent: function () { return provider.screenEvent
|
|
18
|
-
&& eventData.screen
|
|
19
|
-
&& provider.screenEvent(eventData.screen); },
|
|
20
|
-
customEvent: function () { return provider.customEvent
|
|
21
|
-
&& eventData.event
|
|
22
|
-
&& eventData.properties
|
|
23
|
-
&& provider.customEvent(eventData.event, eventData.properties); },
|
|
24
|
-
userIdentification: function () { return provider.userIdentification
|
|
25
|
-
&& eventData.id
|
|
26
|
-
&& eventData.userProperties
|
|
27
|
-
&& provider.userIdentification(eventData.id, eventData.userProperties); }
|
|
28
|
-
};
|
|
29
|
-
Object.values(actions).forEach(function (action) { return action(); });
|
|
30
|
-
});
|
|
31
34
|
};
|
|
35
|
+
var currentEnvironment = localStorage.getItem('_bl_env') || 'development';
|
|
32
36
|
var sendScreenEvent = function (screen) {
|
|
33
|
-
if (
|
|
37
|
+
if (currentEnvironment === 'development') {
|
|
34
38
|
console.log("[blu-lytics]: Screen event: ".concat(screen));
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
@@ -38,7 +42,7 @@ var sendScreenEvent = function (screen) {
|
|
|
38
42
|
}
|
|
39
43
|
};
|
|
40
44
|
var sendCustomEvent = function (event, properties) {
|
|
41
|
-
if (
|
|
45
|
+
if (currentEnvironment === 'development') {
|
|
42
46
|
console.log("[blu-lytics]: Custom event: ".concat(event, " - ").concat(JSON.stringify(properties)));
|
|
43
47
|
}
|
|
44
48
|
else {
|
|
@@ -46,7 +50,7 @@ var sendCustomEvent = function (event, properties) {
|
|
|
46
50
|
}
|
|
47
51
|
};
|
|
48
52
|
var sendUserIdentification = function (id, userProperties) {
|
|
49
|
-
if (
|
|
53
|
+
if (currentEnvironment === 'development') {
|
|
50
54
|
console.log("[blu-lytics]: User identification: ".concat(id, " - ").concat(JSON.stringify(userProperties)));
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initializers/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initializers/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAgG1E;;;;;;;GAOG;AACH,QAAA,IAAI,uBAAuB,EAAE,eAAe,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,gBACjB,iBAAiB,GAAG,iBAAiB,EAAE;iBAC5B,eAAe;MACtC,IA0CF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -39,10 +39,11 @@ var fullStoryInitializer = function (environment, apiKey) {
|
|
|
39
39
|
*/
|
|
40
40
|
var mixPanelInitializer = function (environment, apiKey) {
|
|
41
41
|
if (isProduction(environment)) {
|
|
42
|
+
localStorage.setItem('_bl_mp', apiKey);
|
|
42
43
|
mixpanel.init(apiKey, {
|
|
43
|
-
track_pageview: true
|
|
44
|
-
persistence: 'localStorage'
|
|
44
|
+
track_pageview: true
|
|
45
45
|
});
|
|
46
|
+
localStorage.removeItem('_bl_init');
|
|
46
47
|
}
|
|
47
48
|
};
|
|
48
49
|
/**
|
|
@@ -115,7 +116,9 @@ export var initializeProviders = function (paramsArray, options) {
|
|
|
115
116
|
break;
|
|
116
117
|
}
|
|
117
118
|
initializedProviders.push(providerName);
|
|
119
|
+
localStorage.setItem('_bl_providers', JSON.stringify(initializedProviders));
|
|
118
120
|
};
|
|
121
|
+
localStorage.setItem('_bl_env', environment);
|
|
119
122
|
userSelectedEnvironment = environment;
|
|
120
123
|
if (Array.isArray(paramsArray)) {
|
|
121
124
|
paramsArray.forEach(initialize);
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D,eAAO,MAAM,oBAAoB,kBAChB,YAAY,EAAE,KAC5B,OAAmE,CAAC;AAEvE,eAAO,MAAM,4BAA4B,aAAc,MAAM,KAAG,IAc/D,CAAC"}
|
package/lib/utils/index.js
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import mixpanel from 'mixpanel-browser';
|
|
2
2
|
export var isValidProvidersList = function (providersList) { return Array.isArray(providersList) && providersList.length > 0; };
|
|
3
|
+
export var checkIfMixPanelIsInitialized = function (provider) {
|
|
4
|
+
var isMixPanelProvider = provider === 'MixPanel';
|
|
5
|
+
if (isMixPanelProvider) {
|
|
6
|
+
var apiKey = localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem('_bl_mp');
|
|
7
|
+
var wasInitialized = localStorage.getItem('_bl_init');
|
|
8
|
+
if (!wasInitialized) {
|
|
9
|
+
mixpanel.init(apiKey, {
|
|
10
|
+
track_pageview: true
|
|
11
|
+
});
|
|
12
|
+
localStorage.removeItem('_bl_mp');
|
|
13
|
+
localStorage.setItem('_bl_init', 'init');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|