@useblu/blu-lytics 1.0.0 → 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.
@@ -18,19 +18,24 @@ 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');
24
- expect(consoleLogSpy).toHaveBeenCalledWith('[BLUEFIN]: Screen event: TestScreen');
29
+ expect(consoleLogSpy).toHaveBeenCalledWith('[blu-lytics]: Screen event: TestScreen');
25
30
  });
26
31
  it('should be dispatch sendCustomEvent', function () {
27
32
  var consoleLogSpy = jest.spyOn(console, 'log');
28
33
  sendCustomEvent('TestEvent', { prop1: 'value1' });
29
- expect(consoleLogSpy).toHaveBeenCalledWith('[BLUEFIN]: Custom event: TestEvent - {"prop1":"value1"}');
34
+ expect(consoleLogSpy).toHaveBeenCalledWith('[blu-lytics]: Custom event: TestEvent - {"prop1":"value1"}');
30
35
  });
31
36
  it('should be dispatch sendUserIdentification', function () {
32
37
  var consoleLogSpy = jest.spyOn(console, 'log');
33
38
  sendUserIdentification('123', { name: 'Name' });
34
- expect(consoleLogSpy).toHaveBeenCalledWith('[BLUEFIN]: User identification: 123 - {"name":"Name"}');
39
+ expect(consoleLogSpy).toHaveBeenCalledWith('[blu-lytics]: User identification: 123 - {"name":"Name"}');
35
40
  });
36
41
  });
@@ -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,45 +8,50 @@ 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') {
34
- console.log("[BLUEFIN]: Screen event: ".concat(screen));
37
+ if (currentEnvironment === 'development') {
38
+ console.log("[blu-lytics]: Screen event: ".concat(screen));
35
39
  }
36
40
  else {
37
41
  dispatchEventToAllProviders({ screen: screen });
38
42
  }
39
43
  };
40
44
  var sendCustomEvent = function (event, properties) {
41
- if (userSelectedEnvironment === 'development') {
42
- console.log("[BLUEFIN]: Custom event: ".concat(event, " - ").concat(JSON.stringify(properties)));
45
+ if (currentEnvironment === 'development') {
46
+ console.log("[blu-lytics]: Custom event: ".concat(event, " - ").concat(JSON.stringify(properties)));
43
47
  }
44
48
  else {
45
49
  dispatchEventToAllProviders({ event: event, properties: properties });
46
50
  }
47
51
  };
48
52
  var sendUserIdentification = function (id, userProperties) {
49
- if (userSelectedEnvironment === 'development') {
50
- console.log("[BLUEFIN]: User identification: ".concat(id, " - ").concat(JSON.stringify(userProperties)));
53
+ if (currentEnvironment === 'development') {
54
+ console.log("[blu-lytics]: User identification: ".concat(id, " - ").concat(JSON.stringify(userProperties)));
51
55
  }
52
56
  else {
53
57
  dispatchEventToAllProviders({ id: id, userProperties: userProperties });
@@ -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;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);
@@ -124,7 +127,7 @@ export var initializeProviders = function (paramsArray, options) {
124
127
  initialize(paramsArray);
125
128
  }
126
129
  if (initializedProviders.length > 0) {
127
- console.log('[Bluefin] Initialized providers:', initializedProviders);
130
+ console.log('[blu-lytics] Initialized providers:', initializedProviders);
128
131
  }
129
132
  };
130
133
  export { userSelectedEnvironment };
@@ -15,7 +15,7 @@ describe('Initializers', function () {
15
15
  var logSpy = jest.spyOn(console, 'log').mockImplementation(function () { });
16
16
  initializeProviders(paramsArray, { environment: 'production' });
17
17
  expect(userSelectedEnvironment).toBe('production');
18
- expect(logSpy).toHaveBeenCalledWith('[Bluefin] Initialized providers:', expect.arrayContaining(['Mixpanel', 'Sentry']));
18
+ expect(logSpy).toHaveBeenCalledWith('[blu-lytics] Initialized providers:', expect.arrayContaining(['Mixpanel', 'Sentry']));
19
19
  logSpy.mockRestore();
20
20
  });
21
21
  it('should throw an error when initializing Sentry with an invalid tracesSampleRate', function () {
@@ -1,6 +1,6 @@
1
1
  import { clarity } from 'react-microsoft-clarity';
2
2
  var dispatchUserIdentification = function (id, userProperties) {
3
- clarity.identify(id, { userProperties: userProperties });
3
+ clarity.identify(id, { userProperties: 'id' });
4
4
  };
5
5
  var dispatchCustomEvent = function (event, properties) {
6
6
  clarity.setTag(event, 'customEvent');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=clarity.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clarity.spec.d.ts","sourceRoot":"","sources":["../../../../src/providers/setups/clarity/clarity.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ import { clarity } from 'react-microsoft-clarity';
2
+ import ClarityProvider from './clarity';
3
+ jest.mock('react-microsoft-clarity', function () { return ({
4
+ clarity: {
5
+ identify: jest.fn(),
6
+ setTag: jest.fn()
7
+ }
8
+ }); });
9
+ describe('ClarityProvider', function () {
10
+ it('dispatchUserIdentification should call clarity.identify with correct arguments', function () {
11
+ var userId = 'user123';
12
+ ClarityProvider.userIdentification(userId, { userProperties: 'id' });
13
+ expect(clarity.identify).toHaveBeenCalledWith(userId, { userProperties: 'id' });
14
+ });
15
+ it('dispatchCustomEvent should call clarity.setTag with correct arguments', function () {
16
+ var eventName = 'clickEvent';
17
+ var properties = { key: 'value' };
18
+ ClarityProvider.customEvent(eventName, properties);
19
+ expect(clarity.setTag).toHaveBeenCalledWith(eventName, 'customEvent');
20
+ });
21
+ it('dispatchScreenEvent should call clarity.setTag with correct arguments', function () {
22
+ var screenName = 'HomeScreen';
23
+ ClarityProvider.screenEvent(screenName);
24
+ expect(clarity.setTag).toHaveBeenCalledWith(screenName, 'screen');
25
+ });
26
+ });
@@ -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,IAc/D,CAAC"}
@@ -1,2 +1,16 @@
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
+ track_pageview: true
11
+ });
12
+ localStorage.removeItem('_bl_mp');
13
+ localStorage.setItem('_bl_init', 'init');
14
+ }
15
+ }
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@useblu/blu-lytics",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",