(user: UserIdentity)
| 15 | } | null; |
| 16 | |
| 17 | function determineDistinctId(user: UserIdentity): { |
| 18 | distinct_id: string; |
| 19 | distinct_id_source: string; |
| 20 | org_id: string | null; |
| 21 | } { |
| 22 | const orgId = getOrgId(); |
| 23 | |
| 24 | if (user) { |
| 25 | return { |
| 26 | distinct_id: user.id, |
| 27 | distinct_id_source: "database_id", |
| 28 | org_id: orgId, |
| 29 | }; |
| 30 | } |
| 31 | |
| 32 | if (orgId) { |
| 33 | return { |
| 34 | distinct_id: orgId, |
| 35 | distinct_id_source: "git_org", |
| 36 | org_id: orgId, |
| 37 | }; |
| 38 | } |
| 39 | |
| 40 | const deviceId = `device-${machineIdSync()}`; |
| 41 | if (process.env.DEBUG === "true") { |
| 42 | console.warn( |
| 43 | "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking.", |
| 44 | ); |
| 45 | } |
| 46 | return { |
| 47 | distinct_id: deviceId, |
| 48 | distinct_id_source: "device", |
| 49 | org_id: null, |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | export default function trackEvent( |
| 54 | user: UserIdentity, |
no test coverage detected