@useblu/blu-lytics 1.0.1 → 1.0.3

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.
@@ -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,11 +1,11 @@
1
1
  export type EventType = 'customEvent' | 'screenEvent' | 'userIdentification';
2
2
  export type PropertiesType = {
3
- [key: string]: string;
3
+ [key: string]: string | boolean | number | string[] | undefined;
4
4
  };
5
5
  export type UserPropertiesType = {
6
6
  email?: string;
7
7
  name?: string;
8
- [key: string]: string | undefined;
8
+ [key: string]: string | boolean | number | any[] | undefined;
9
9
  };
10
10
  export type EventData = {
11
11
  screen?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"dispatchers.types.d.ts","sourceRoot":"","sources":["../../src/dispatchers/dispatchers.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAC7E,MAAM,MAAM,cAAc,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AACvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,kBAAkB,CAAC;CACrC,CAAC"}
1
+ {"version":3,"file":"dispatchers.types.d.ts","sourceRoot":"","sources":["../../src/dispatchers/dispatchers.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAC7E,MAAM,MAAM,cAAc,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC;CAAE,CAAC;AAClG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,SAAS,CAAC;CAC9D,CAAC;AACF,MAAM,MAAM,SAAS,GAAG;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,cAAc,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,kBAAkB,CAAC;CACrC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dispatchers/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEpF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,cAAe,SAAS,KAAG,IAsBlE,CAAC;AAEF,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"}
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"}
@@ -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 { isValidProvidersList } from '../utils';
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
- if (!isValidProvidersList(providersList)) {
13
- return;
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 (userSelectedEnvironment === 'development') {
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 (userSelectedEnvironment === 'development') {
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 (userSelectedEnvironment === 'development') {
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;AA+F1E;;;;;;;GAOG;AACH,QAAA,IAAI,uBAAuB,EAAE,eAAe,CAAC;AAE7C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,gBACjB,iBAAiB,GAAG,iBAAiB,EAAE;iBAC5B,eAAe;MACtC,IAwCF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,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;AA8F1E;;;;;;;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,9 @@ var fullStoryInitializer = function (environment, apiKey) {
39
39
  */
40
40
  var mixPanelInitializer = function (environment, apiKey) {
41
41
  if (isProduction(environment)) {
42
- mixpanel.init(apiKey, {
43
- track_pageview: true,
44
- persistence: 'localStorage'
45
- });
42
+ localStorage.setItem('_bl_mp', apiKey);
43
+ mixpanel.init(apiKey);
44
+ localStorage.removeItem('_bl_init');
46
45
  }
47
46
  };
48
47
  /**
@@ -115,7 +114,9 @@ export var initializeProviders = function (paramsArray, options) {
115
114
  break;
116
115
  }
117
116
  initializedProviders.push(providerName);
117
+ localStorage.setItem('_bl_providers', JSON.stringify(initializedProviders));
118
118
  };
119
+ localStorage.setItem('_bl_env', environment);
119
120
  userSelectedEnvironment = environment;
120
121
  if (Array.isArray(paramsArray)) {
121
122
  paramsArray.forEach(initialize);
@@ -1 +1 @@
1
- {"version":3,"file":"mixpanel.d.ts","sourceRoot":"","sources":["../../../../src/providers/setups/mixpanel/mixpanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA0CpD,QAAA,MAAM,gBAAgB,EAAE,YAKvB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"mixpanel.d.ts","sourceRoot":"","sources":["../../../../src/providers/setups/mixpanel/mixpanel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA2CpD,QAAA,MAAM,gBAAgB,EAAE,YAKvB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import mixpanel from 'mixpanel-browser';
2
13
  var dispatchUserIdentification = function (id, userProperties) {
3
14
  mixpanel.identify(id);
@@ -21,7 +32,8 @@ var dispatchUserIdentification = function (id, userProperties) {
21
32
  mixpanel.people.set(peopleProperties);
22
33
  };
23
34
  var dispatchCustomEvent = function (event, properties) {
24
- mixpanel.track(event, { properties: properties });
35
+ var rest = __rest(properties, []);
36
+ mixpanel.track(event, rest);
25
37
  };
26
38
  var dispatchScreenEvent = function (screen) {
27
39
  mixpanel.track(screen);
@@ -1,3 +1,14 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import mixpanel from 'mixpanel-browser';
2
13
  import MixPanelProvider from './mixpanel';
3
14
  jest.mock('mixpanel-browser', function () { return ({
@@ -26,9 +37,12 @@ describe('MixPanelProvider', function () {
26
37
  });
27
38
  test('dispatchCustomEvent should call mixpanel.track with event and properties', function () {
28
39
  var event = 'testEvent';
29
- var properties = { key1: 'value1', key2: 'value2' };
40
+ var properties = {
41
+ key1: 'value1', key2: true, key3: 9.9, key4: ['value1', 'value2']
42
+ };
30
43
  MixPanelProvider.customEvent(event, properties);
31
- expect(mixpanel.track).toHaveBeenCalledWith(event, { properties: properties });
44
+ var rest = __rest(properties, []);
45
+ expect(mixpanel.track).toHaveBeenCalledWith(event, rest);
32
46
  });
33
47
  test('dispatchScreenEvent should call mixpanel.track with screen', function () {
34
48
  var screen = 'testScreen';
@@ -1,3 +1,4 @@
1
1
  import { ProviderType } from '../providers/provider.types';
2
2
  export declare const isValidProvidersList: (providersList: ProviderType[]) => boolean;
3
+ export declare const checkIfMixPanelIsInitialized: (provider: string) => void;
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D,eAAO,MAAM,oBAAoB,kBAChB,YAAY,EAAE,KAC5B,OAAmE,CAAC"}
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,IAY/D,CAAC"}
@@ -1,2 +1,14 @@
1
- // eslint-disable-next-line import/prefer-default-export
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
+ localStorage.removeItem('_bl_mp');
11
+ localStorage.setItem('_bl_init', 'init');
12
+ }
13
+ }
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useblu/blu-lytics",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",