MCPcopy
hub / github.com/lingodotdev/lingo.dev / getDistinctId

Function getDistinctId

packages/compiler/src/utils/observability.ts:59–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57}
58
59async function getDistinctId(): Promise<{
60 distinct_id: string;
61 distinct_id_source: string;
62 org_id: string | null;
63}> {
64 const orgId = getOrgId();
65 const email = await tryGetEmail();
66
67 if (email) {
68 const hashedEmail = crypto.createHash("sha256").update(email).digest("hex");
69 return {
70 distinct_id: hashedEmail,
71 distinct_id_source: "email",
72 org_id: orgId,
73 };
74 }
75
76 if (orgId) {
77 return {
78 distinct_id: orgId,
79 distinct_id_source: "git_org",
80 org_id: orgId,
81 };
82 }
83
84 const deviceId = `device-${await machineIdLib.machineId()}`;
85 if (process.env.DEBUG === "true") {
86 console.warn(
87 "[Tracking] Using device ID fallback. Consider using git repository for consistent tracking.",
88 );
89 }
90 return {
91 distinct_id: deviceId,
92 distinct_id_source: "device",
93 org_id: null,
94 };
95}
96
97async function tryGetEmail(): Promise<string | null> {
98 const rc = getRc();

Callers 1

trackEventFunction · 0.70

Calls 4

getOrgIdFunction · 0.90
warnMethod · 0.80
tryGetEmailFunction · 0.70
updateMethod · 0.65

Tested by

no test coverage detected