MCPcopy Create free account
hub / github.com/datapane/datapane / setupPostHog

Function setupPostHog

web-components/shared/dp-track.ts:32–53  ·  view source on GitHub ↗
(
    apiKey: string,
    userId?: string,
    groupId?: string,
)

Source from the content-addressed store, hash-verified

30}
31
32export const setupPostHog = async (
33 apiKey: string,
34 userId?: string,
35 groupId?: string,
36): Promise<void> => {
37 try {
38 await mutex.lock(LOCK_NAME);
39 posthog.init(apiKey, {
40 api_host: API_HOST,
41 loaded: async (posthog: any) => {
42 /* We need to do this to use elsewhere in more dynamic ways, outside the scope of this file */
43 window.posthog = posthog;
44 userId && posthog.identify(userId);
45 groupId && posthog.group("company", groupId);
46 await mutex.release(LOCK_NAME);
47 },
48 });
49 } catch (e) {
50 console.error("Posthog setup error", e);
51 await mutex.release(LOCK_NAME);
52 }
53};
54
55/**
56 * async safely get the global posthog instance, sleeping until ready

Callers

nothing calls this directly

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected