@dashgram/react 1.0.2 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnD,eAAO,MAAM,eAAe,4CAAmD,CAAA;AAK/E,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAKD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,UAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,KAAK,EACL,QAAQ,EACR,OAAO,EACR,EAAE,qBAAqB,2CAmEvB"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqD,MAAM,OAAO,CAAA;AAEzE,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAKnD,eAAO,MAAM,eAAe,4CAAmD,CAAA;AAK/E,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAKD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,SAAS,EACT,UAAc,EACd,MAAM,EACN,SAAS,EACT,aAAa,EACb,KAAK,EACL,QAAQ,EACR,OAAO,EACR,EAAE,qBAAqB,2CAuHvB"}
package/dist/provider.js CHANGED
@@ -10,6 +10,9 @@ export function DashgramProvider({ children, projectId, trackLevel = 2, apiUrl,
10
10
  if (initRef.current) {
11
11
  return;
12
12
  }
13
+ if (!projectId) {
14
+ return;
15
+ }
13
16
  initRef.current = true;
14
17
  try {
15
18
  DashgramMini.init({
@@ -26,27 +29,63 @@ export function DashgramProvider({ children, projectId, trackLevel = 2, apiUrl,
26
29
  }
27
30
  catch (error) {
28
31
  console.error("Dashgram: Failed to initialize", error);
32
+ setIsInitialized(false);
33
+ initRef.current = false;
29
34
  }
30
35
  return () => {
31
- DashgramMini.shutdown();
36
+ if (initRef.current) {
37
+ try {
38
+ DashgramMini.shutdown();
39
+ }
40
+ catch (error) {
41
+ }
42
+ initRef.current = false;
43
+ setIsInitialized(false);
44
+ }
32
45
  };
33
- }, [projectId, trackLevel, apiUrl, batchSize, flushInterval, debug, disabled, onError]);
46
+ }, [projectId, trackLevel, apiUrl, batchSize, flushInterval, debug, disabled]);
34
47
  const value = {
35
48
  track: (event, properties) => {
36
- if (isInitialized) {
49
+ if (!isInitialized) {
50
+ if (debug) {
51
+ console.warn("Dashgram: Track called before initialization", { event, properties });
52
+ }
53
+ return;
54
+ }
55
+ try {
37
56
  DashgramMini.track(event, properties);
38
57
  }
58
+ catch (error) {
59
+ if (debug) {
60
+ console.warn("Dashgram: Track failed", error);
61
+ }
62
+ setIsInitialized(false);
63
+ }
39
64
  },
40
65
  isInitialized,
41
66
  flush: async () => {
42
67
  if (isInitialized) {
43
- await DashgramMini.flush();
68
+ try {
69
+ await DashgramMini.flush();
70
+ }
71
+ catch (error) {
72
+ if (debug) {
73
+ console.warn("Dashgram: Flush failed", error);
74
+ }
75
+ }
44
76
  }
45
77
  },
46
78
  setTrackLevel: level => {
47
79
  if (isInitialized) {
48
- DashgramMini.setTrackLevel(level);
49
- setCurrentTrackLevel(level);
80
+ try {
81
+ DashgramMini.setTrackLevel(level);
82
+ setCurrentTrackLevel(level);
83
+ }
84
+ catch (error) {
85
+ if (debug) {
86
+ console.warn("Dashgram: SetTrackLevel failed", error);
87
+ }
88
+ }
50
89
  }
51
90
  },
52
91
  getTrackLevel: () => {
@@ -54,9 +93,16 @@ export function DashgramProvider({ children, projectId, trackLevel = 2, apiUrl,
54
93
  },
55
94
  shutdown: () => {
56
95
  if (isInitialized) {
57
- DashgramMini.shutdown();
58
- setIsInitialized(false);
59
- initRef.current = false;
96
+ try {
97
+ DashgramMini.shutdown();
98
+ setIsInitialized(false);
99
+ initRef.current = false;
100
+ }
101
+ catch (error) {
102
+ if (debug) {
103
+ console.warn("Dashgram: Shutdown failed", error);
104
+ }
105
+ }
60
106
  }
61
107
  }
62
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashgram/react",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "React wrapper for Dashgram Analytics SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",