@pagopa/selfcare-common-frontend 1.3.0 → 1.3.1

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/CHANGELOG.md CHANGED
@@ -4,8 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v1.3.1](https://github.com/pagopa/selfcare-common-frontend/compare/v1.3.0...v1.3.1)
8
+
9
+ - analyticsService will accept a callback [`#18`](https://github.com/pagopa/selfcare-common-frontend/pull/18)
10
+
7
11
  #### [v1.3.0](https://github.com/pagopa/selfcare-common-frontend/compare/v1.2.3...v1.3.0)
8
12
 
13
+ > 4 February 2022
14
+
9
15
  - SELC-145 e SELC-144 [`#17`](https://github.com/pagopa/selfcare-common-frontend/pull/17)
10
16
  - SELC-144 analytcsService through mixPanel [`#16`](https://github.com/pagopa/selfcare-common-frontend/pull/16)
11
17
  - SELC-145 e SELC-144 (#17) [`#145`](https://pagopa.atlassian.net/browse/145) [`#144`](https://pagopa.atlassian.net/browse/144) [`#145`](https://pagopa.atlassian.net/browse/145)
package/README.md CHANGED
@@ -269,6 +269,11 @@ This feature can be configured with the following keys of the [CONFIG](#Configur
269
269
  | ADDITIONAL_PROPERTIES | {[key: string]: string} | An object containing a fixed set of properties to send every time, overridden if the actual event will report the same properties | {} |
270
270
  | ADDITIONAL_PROPERTIES_IMPORTANT | {[key: string]: string} | As ADDITIONAL_PROPERTIES, but these properties will take the precedence overriding events conflicting properties | {} |
271
271
 
272
+ In order track an event (once the initAnalytics method has been invoked) you have to call the trackEvent(event_name: string, properties?: any, callback?: () => void)=> void method where:
273
+ * event_name: the name of the event
274
+ * properties: the additional payload sent with the event
275
+ * callback: an action taken when the track has completed (If the action taken immediately after the track is an exit action from the application, it's better to use this callback to perform the exit, in order to give to mixPanel the time to send the event)
276
+
272
277
  ## Consent management
273
278
  This feature allows the automatic enabling of the [analytics feature](#analytics) only when the user accept to send that data.
274
279
 
package/build.info CHANGED
@@ -1,2 +1,2 @@
1
- 20220204.1 - selfcare-common-frontend.deploy(19176)
2
- tags/v1.3.0^0 28b9f7a08d60a63d2224568a4180ab7b3c1fbcb7
1
+ 20220207.1 - selfcare-common-frontend.deploy(19531)
2
+ remotes/origin/SELC-144-track-events 0606cfa74d6adbdd06cb25b128ea601cb3daf5f3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagopa/selfcare-common-frontend",
3
3
  "description": "Shared React components for the pagopa selfcare project",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/pagopa/selfcare-common-frontend",
7
7
  "author": "https://www.pagopa.gov.it",
@@ -1,7 +1,12 @@
1
1
  import { AppError } from '../redux/slices/appStateSlice';
2
2
  /** To call in order to start the analytics service, otherwise no event will be sent */
3
3
  export declare const initAnalytics: () => void;
4
- /** To notify an event through the analytics tool */
5
- export declare const trackEvent: (event_name: string, properties?: any) => void;
6
4
  /** To notify an error through the analytics tool */
7
5
  export declare const trackAppError: (error: AppError) => void;
6
+ /**
7
+ * To notify an event through the analytics tool:
8
+ * @property event_name: the name of the event
9
+ * @property properties: the additional payload sent with the event
10
+ * @property callback: an action taken when the track has completed (If the action taken immediately after the track is an exit action from the application, it's better to use this callback to perform the exit, in order to give to mixPanel the time to send the event)
11
+ */
12
+ export declare const trackEvent: (event_name: string, properties?: any, callback?: (() => void) | undefined) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.trackAppError = exports.trackEvent = exports.initAnalytics = void 0;
3
+ exports.trackEvent = exports.trackAppError = exports.initAnalytics = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const mixpanel_browser_1 = (0, tslib_1.__importDefault)(require("mixpanel-browser"));
6
6
  const env_1 = require("../config/env");
@@ -26,38 +26,70 @@ const initAnalytics = () => {
26
26
  }
27
27
  };
28
28
  exports.initAnalytics = initAnalytics;
29
- /** To notify an event through the analytics tool */
30
- const trackEvent = (event_name, properties) => {
29
+ /** To notify an error through the analytics tool */
30
+ const trackAppError = (error) => {
31
+ if (env_1.CONFIG.ANALYTCS.ENABLE && init) {
32
+ (0, exports.trackEvent)('GENERIC_ERROR', error);
33
+ }
34
+ else {
35
+ console.error(error);
36
+ }
37
+ };
38
+ exports.trackAppError = trackAppError;
39
+ /**
40
+ * To notify an event through the analytics tool:
41
+ * @property event_name: the name of the event
42
+ * @property properties: the additional payload sent with the event
43
+ * @property callback: an action taken when the track has completed (If the action taken immediately after the track is an exit action from the application, it's better to use this callback to perform the exit, in order to give to mixPanel the time to send the event)
44
+ */
45
+ const trackEvent = (event_name, properties, callback) => {
31
46
  if (env_1.CONFIG.ANALYTCS.ENABLE && init) {
32
47
  if (env_1.CONFIG.ANALYTCS.MOCK) {
33
48
  // eslint-disable-next-line no-console
34
49
  console.log(event_name, properties);
50
+ if (callback) {
51
+ callback();
52
+ }
35
53
  }
36
54
  else {
55
+ trackEventThroughAnalyticTool(event_name, properties, callback);
56
+ }
57
+ }
58
+ else {
59
+ if (callback) {
60
+ callback();
61
+ }
62
+ }
63
+ };
64
+ exports.trackEvent = trackEvent;
65
+ const trackEventThroughAnalyticTool = (event_name, properties, callback) => {
66
+ // eslint-disable-next-line functional/no-let
67
+ let called = false;
68
+ const wrappedCallback = callback
69
+ ? () => {
37
70
  try {
38
- mixpanel_browser_1.default.track(event_name, {
39
- ...env_1.CONFIG.ANALYTCS.ADDITIONAL_PROPERTIES,
40
- ...properties,
41
- ...env_1.CONFIG.ANALYTCS.ADDITIONAL_PROPERTIES_IMPORTANT,
42
- });
71
+ called = true;
72
+ callback();
43
73
  }
44
74
  catch (reason) {
45
- console.error('Something gone wrong while sending data to mixpanel:', reason);
46
- // eslint-disable-next-line no-console
47
- console.log(event_name, properties);
75
+ console.error(`Something gone wrong while calling trackEvent ${event_name} callback`, reason);
48
76
  }
49
77
  }
78
+ : undefined;
79
+ try {
80
+ mixpanel_browser_1.default.track(event_name, {
81
+ ...env_1.CONFIG.ANALYTCS.ADDITIONAL_PROPERTIES,
82
+ ...properties,
83
+ ...env_1.CONFIG.ANALYTCS.ADDITIONAL_PROPERTIES_IMPORTANT,
84
+ }, wrappedCallback ? { send_immediately: true } : undefined, wrappedCallback);
50
85
  }
51
- };
52
- exports.trackEvent = trackEvent;
53
- /** To notify an error through the analytics tool */
54
- const trackAppError = (error) => {
55
- if (env_1.CONFIG.ANALYTCS.ENABLE && init) {
56
- (0, exports.trackEvent)('GENERIC_ERROR', error);
57
- }
58
- else {
59
- console.error(error);
86
+ catch (reason) {
87
+ console.error('Something gone wrong while sending data to mixpanel:', reason);
88
+ // eslint-disable-next-line no-console
89
+ console.log(event_name, properties);
90
+ if (wrappedCallback && !called) {
91
+ wrappedCallback();
92
+ }
60
93
  }
61
94
  };
62
- exports.trackAppError = trackAppError;
63
95
  //# sourceMappingURL=analyticsService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"analyticsService.js","sourceRoot":"","sources":["../../src/lib/services/analyticsService.ts"],"names":[],"mappings":";;;;AAAA,qFAAwC;AACxC,uCAAuC;AAGvC,6CAA6C;AAC7C,IAAI,IAAI,GAAG,KAAK,CAAC;AAEjB,uFAAuF;AAChF,MAAM,aAAa,GAAG,GAAS,EAAE;IACtC,IAAI,YAAM,CAAC,QAAQ,CAAC,MAAM,EAAE;QAC1B,IAAI,GAAG,IAAI,CAAC;QACZ,IAAI,YAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;YACxB,sCAAsC;YACtC,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;SACrD;aAAM;YACL,0BAAQ,CAAC,IAAI,CAAC,YAAM,CAAC,QAAQ,CAAC,KAAK,EAAE;gBACnC,QAAQ,EAAE,YAAM,CAAC,QAAQ,CAAC,QAAQ;gBAClC,WAAW,EAAE,YAAM,CAAC,QAAQ,CAAC,WAAwC;gB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