@hyvor/design 1.1.22 → 1.1.23

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.
@@ -8,8 +8,8 @@ declare class Track {
8
8
  private op;
9
9
  private isProductionDomain;
10
10
  init({ forceTrack, openPanelApiUrl, openPanelClientId, context }?: InitOptions): void;
11
- private checkOp;
12
11
  ready(): boolean;
12
+ private warnNoOp;
13
13
  context(properties: Record<string, any>): void;
14
14
  event(name: string, properties?: Record<string, any>): void;
15
15
  identify(profileId: string, props: {
@@ -21,38 +21,52 @@ class Track {
21
21
  this.op.setGlobalProperties(context);
22
22
  }
23
23
  }
24
- checkOp() {
25
- if (!this.op) {
26
- throw new Error('OpenPanel is not initialized. Call track.init() first.');
27
- }
28
- }
29
24
  ready() {
30
25
  return this.op !== undefined;
31
26
  }
27
+ warnNoOp(message) {
28
+ console.warn(`[Track] Ignoring action: ${message} - OpenPanel is not initialized. Call track.init() first.`);
29
+ }
32
30
  // set global context
33
31
  context(properties) {
34
- this.checkOp();
35
- this.op.setGlobalProperties(properties);
32
+ if (this.op) {
33
+ this.op.setGlobalProperties(properties);
34
+ }
35
+ else {
36
+ this.warnNoOp('set context');
37
+ }
36
38
  }
37
39
  // log an event
38
40
  event(name, properties) {
39
- this.checkOp();
40
- this.op.track(name, properties);
41
+ if (this.op) {
42
+ this.op.track(name, properties);
43
+ }
44
+ else {
45
+ this.warnNoOp(`log event "${name}"`);
46
+ }
41
47
  }
42
48
  // identify user
43
49
  identify(profileId, props) {
44
- this.checkOp();
45
- this.op.identify({
46
- profileId: profileId,
47
- firstName: props.name,
48
- avatar: props.avatar,
49
- properties: props.properties
50
- });
50
+ if (this.op) {
51
+ this.op.identify({
52
+ profileId: profileId,
53
+ firstName: props.name,
54
+ avatar: props.avatar,
55
+ properties: props.properties
56
+ });
57
+ }
58
+ else {
59
+ this.warnNoOp(`identify user "${profileId}"`);
60
+ }
51
61
  }
52
62
  // log out user (clear identity)
53
63
  logout() {
54
- this.checkOp();
55
- this.op.clear();
64
+ if (this.op) {
65
+ this.op.clear();
66
+ }
67
+ else {
68
+ this.warnNoOp('logout user');
69
+ }
56
70
  }
57
71
  }
58
72
  const track = new Track();
package/package.json CHANGED
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "access": "public"
64
64
  },
65
- "version": "1.1.22"
65
+ "version": "1.1.23"
66
66
  }