(eventName: string, props?: Record<string, string | number>)
| 63 | } |
| 64 | |
| 65 | async track(eventName: string, props?: Record<string, string | number>): Promise<boolean> { |
| 66 | if (!this.endpoint) return false |
| 67 | if (!this.getEnabled()) return false |
| 68 | try { |
| 69 | const resp = await fetch(this.endpoint, { |
| 70 | method: 'POST', |
| 71 | headers: { 'Content-Type': 'application/json', 'App-Key': this.appKey }, |
| 72 | body: JSON.stringify({ |
| 73 | timestamp: new Date().toISOString(), |
| 74 | sessionId: this.sessionId, |
| 75 | eventName, |
| 76 | systemProps: { |
| 77 | isDebug: false, |
| 78 | locale: '', |
| 79 | osName: process.platform, |
| 80 | osVersion: '', |
| 81 | engineName: 'Node.js', |
| 82 | engineVersion: process.versions.node, |
| 83 | appVersion: this.appVersion, |
| 84 | sdkVersion: 'chatlab@1', |
| 85 | }, |
| 86 | props, |
| 87 | }), |
| 88 | }) |
| 89 | return resp.ok |
| 90 | } catch (e) { |
| 91 | console.error(`[Analytics] Failed to track ${eventName}:`, e) |
| 92 | return false |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | async trackDailyActive(props?: Record<string, string | number>): Promise<void> { |
| 97 | if (!this.endpoint) return |
no test coverage detected