-
Notifications
You must be signed in to change notification settings - Fork 837
chore: fix posthog #2043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: fix posthog #2043
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "lingo.dev": patch | ||
| --- | ||
|
|
||
| fix posthog |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,9 +18,8 @@ function determineDistinctId(email: string | null | undefined): { | |
| const orgId = getOrgId(); | ||
|
|
||
| if (email) { | ||
| const hashedEmail = crypto.createHash("sha256").update(email).digest("hex"); | ||
| return { | ||
| distinct_id: hashedEmail, | ||
| distinct_id: email, | ||
| distinct_id_source: "email", | ||
| org_id: orgId, | ||
| }; | ||
|
|
@@ -72,6 +71,7 @@ export default function trackEvent( | |
| distinct_id: identityInfo.distinct_id, | ||
| properties: { | ||
| ...properties, | ||
| $set: { ...(properties?.$set || {}), ...(email ? { email } : {}) }, | ||
| $lib: "lingo.dev-cli", | ||
| $lib_version: process.env.npm_package_version || "unknown", | ||
| tracking_version: TRACKING_VERSION, | ||
|
|
@@ -112,6 +112,33 @@ export default function trackEvent( | |
| req.write(payload); | ||
| req.end(); | ||
|
|
||
| // TODO: remove after 2026-03-25 — temporary alias to merge old hashed distinct_ids with new raw email | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two-week migration window may be insufficient. The TODO indicates removal after 2026-03-25, which is only ~13 days from now. Users who don't upgrade and run the CLI within this window will never trigger the alias, leaving their old hashed profiles orphaned. Consider extending the window (e.g., 3-6 months) to maximize the number of users who upgrade and get their profiles merged, or plan to keep the alias logic until analytics confirms minimal unmerged profiles. 🤖 Prompt for AI Agents |
||
| if (email) { | ||
| const hashedEmail = crypto.createHash("sha256").update(email).digest("hex"); | ||
| const aliasData = JSON.stringify({ | ||
| api_key: POSTHOG_API_KEY, | ||
| event: "$create_alias", | ||
| distinct_id: email, | ||
| properties: { | ||
| alias: hashedEmail, | ||
| }, | ||
| timestamp: new Date().toISOString(), | ||
| }); | ||
|
|
||
| const aliasReq = https.request({ | ||
| ...options, | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "Content-Length": Buffer.byteLength(aliasData).toString(), | ||
| }, | ||
| }); | ||
| aliasReq.on("timeout", () => aliasReq.destroy()); | ||
| aliasReq.on("error", () => {}); | ||
| aliasReq.write(aliasData); | ||
| aliasReq.end(); | ||
| setTimeout(() => { if (!aliasReq.destroyed) aliasReq.destroy(); }, REQUEST_TIMEOUT_MS); | ||
| } | ||
|
Comment on lines
+115
to
+140
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SDK lacks alias logic — legacy SDK profiles won't merge. The SDK at Consider adding the same alias logic to the SDK module, or confirm that SDK analytics continuity is intentionally being sacrificed. 🤖 Prompt for AI Agents |
||
|
|
||
| setTimeout(() => { | ||
| if (!req.destroyed) { | ||
| req.destroy(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.