MCPcopy Create free account
hub / github.com/CapSoftware/Cap / identifyUser

Function identifyUser

apps/desktop/src/utils/analytics.ts:56–86  ·  view source on GitHub ↗
(
	userId: string,
	properties?: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

54}
55
56export function identifyUser(
57 userId: string,
58 properties?: Record<string, unknown>,
59) {
60 if (!key || !host) {
61 console.warn("Cannot identify user - missing key or host");
62 return;
63 }
64
65 try {
66 const currentId = posthog.get_distinct_id();
67 const anonymousId = localStorage.getItem("anonymous_id");
68
69 if (currentId !== userId) {
70 if (anonymousId && currentId === anonymousId) {
71 console.log(`Aliasing user ${userId} from anonymous ID ${anonymousId}`);
72 posthog.alias(userId, anonymousId);
73 }
74 posthog.identify(userId);
75 if (properties) {
76 posthog.people.set(properties);
77 }
78 localStorage.removeItem("anonymous_id");
79 console.log(`User identified: ${userId}`);
80 } else {
81 console.log(`User already identified as ${userId}`);
82 }
83 } catch (error) {
84 console.error("Error identifying user:", error);
85 }
86}
87
88export function trackEvent(
89 eventName: string,

Callers 1

processAuthDataFunction · 0.90

Calls 2

getItemMethod · 0.80
removeItemMethod · 0.80

Tested by

no test coverage detected