|
| 1 | +/** |
| 2 | + * Telemetry in FlowTestAI is just an anonymous visit counter (triggered once per day). |
| 3 | + * The only details shared are: |
| 4 | + * - OS (ex: mac, windows, linux) |
| 5 | + * - Version (ex: 1.3.0) |
| 6 | + * We don't track usage analytics / micro-interactions / crash logs / anything else. |
| 7 | + */ |
| 8 | + |
| 9 | +import { useEffect } from 'react'; |
| 10 | +import { v4 as uuidv4 } from 'uuid'; |
| 11 | +// import getConfig from 'next/config'; |
| 12 | +import { PostHog } from 'posthog-node'; |
| 13 | + |
| 14 | +const posthogApiKey = 'phc_NWEriNXcUcZ1QB3GDBHrM3NDzZj69P1npzZ9PY2A5tW'; |
| 15 | +let posthogClient = null; |
| 16 | + |
| 17 | +const getPosthogClient = () => { |
| 18 | + if (posthogClient) { |
| 19 | + return posthogClient; |
| 20 | + } |
| 21 | + |
| 22 | + posthogClient = new PostHog(posthogApiKey); |
| 23 | + return posthogClient; |
| 24 | +}; |
| 25 | + |
| 26 | +const getAnonymousId = () => { |
| 27 | + let id = localStorage.getItem('flowtestai.anonymousId'); |
| 28 | + |
| 29 | + if (!id || !id.length || id.length !== 21) { |
| 30 | + id = uuidv4(); |
| 31 | + localStorage.setItem('flowtestai.anonymousId', id); |
| 32 | + } |
| 33 | + |
| 34 | + return id; |
| 35 | +}; |
| 36 | + |
| 37 | +const trackStart = () => { |
| 38 | + const { ipcRenderer } = window; |
| 39 | + const id = getAnonymousId(); |
| 40 | + const client = getPosthogClient(); |
| 41 | + client.capture({ |
| 42 | + distinctId: id, |
| 43 | + event: 'start', |
| 44 | + properties: { |
| 45 | + os: ipcRenderer.isMacOs() ? 'darwin' : 'win32', |
| 46 | + version: '1.2.0', |
| 47 | + }, |
| 48 | + }); |
| 49 | +}; |
| 50 | + |
| 51 | +const useTelemetry = () => { |
| 52 | + useEffect(() => { |
| 53 | + trackStart(); |
| 54 | + setInterval(trackStart, 24 * 60 * 60 * 1000); |
| 55 | + }, []); |
| 56 | +}; |
| 57 | + |
| 58 | +export default useTelemetry; |
0 commit comments