@@ -18,9 +18,8 @@ function determineDistinctId(email: string | null | undefined): {
1818 const orgId = getOrgId ( ) ;
1919
2020 if ( email ) {
21- const hashedEmail = crypto . createHash ( "sha256" ) . update ( email ) . digest ( "hex" ) ;
2221 return {
23- distinct_id : hashedEmail ,
22+ distinct_id : email ,
2423 distinct_id_source : "email" ,
2524 org_id : orgId ,
2625 } ;
@@ -72,6 +71,7 @@ export default function trackEvent(
7271 distinct_id : identityInfo . distinct_id ,
7372 properties : {
7473 ...properties ,
74+ $set : { ...( properties ?. $set || { } ) , ...( email ? { email } : { } ) } ,
7575 $lib : "lingo.dev-cli" ,
7676 $lib_version : process . env . npm_package_version || "unknown" ,
7777 tracking_version : TRACKING_VERSION ,
@@ -112,6 +112,33 @@ export default function trackEvent(
112112 req . write ( payload ) ;
113113 req . end ( ) ;
114114
115+ // TODO: remove after 2026-03-25 — temporary alias to merge old hashed distinct_ids with new raw email
116+ if ( email ) {
117+ const hashedEmail = crypto . createHash ( "sha256" ) . update ( email ) . digest ( "hex" ) ;
118+ const aliasData = JSON . stringify ( {
119+ api_key : POSTHOG_API_KEY ,
120+ event : "$create_alias" ,
121+ distinct_id : email ,
122+ properties : {
123+ alias : hashedEmail ,
124+ } ,
125+ timestamp : new Date ( ) . toISOString ( ) ,
126+ } ) ;
127+
128+ const aliasReq = https . request ( {
129+ ...options ,
130+ headers : {
131+ "Content-Type" : "application/json" ,
132+ "Content-Length" : Buffer . byteLength ( aliasData ) . toString ( ) ,
133+ } ,
134+ } ) ;
135+ aliasReq . on ( "timeout" , ( ) => aliasReq . destroy ( ) ) ;
136+ aliasReq . on ( "error" , ( ) => { } ) ;
137+ aliasReq . write ( aliasData ) ;
138+ aliasReq . end ( ) ;
139+ setTimeout ( ( ) => { if ( ! aliasReq . destroyed ) aliasReq . destroy ( ) ; } , REQUEST_TIMEOUT_MS ) ;
140+ }
141+
115142 setTimeout ( ( ) => {
116143 if ( ! req . destroyed ) {
117144 req . destroy ( ) ;
0 commit comments