All files / src/analytics posthog.tsx

50% Statements 6/12
0% Branches 0/1
0% Functions 0/2
54.54% Lines 6/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43        33x                     33x     33x 33x       33x                               33x      
import { PostHogConfig } from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { ReactElement } from "react";
 
const options: Partial<PostHogConfig> = {
  api_host: import.meta.env.VITE_POSTHOG_HOST,
  ui_host: import.meta.env.VITE_POSTHOG_UI_HOST,
  session_recording: {
    maskAllInputs: false,
    maskInputOptions: {
      password: true,
    },
  },
};
 
const apiKey: string | null = import.meta.env.VITE_POSTHOG_API_KEY;
 
// If the PostHog API key is set, wrap the application in the PostHogProvider
const startPostHog = apiKey != null;
let postHogStarted = false;
 
// Attempts to start PostHog. Requires the PostHog API key (VITE_POSTHOG_API_KEY) to be set.
// If PostHog is not started, the inner application is returned instead.
const createPostHogApplication = (baseApplication: ReactElement) => {
  Iif (startPostHog) {
    postHogStarted = true;
 
    return (
      <PostHogProvider apiKey={apiKey} options={options}>
        {baseApplication}
      </PostHogProvider>
    );
  }
 
  console.log("PostHog not started: API key not set");
 
  return baseApplication;
};
 
const getPostHogStarted = () => postHogStarted;
 
export { createPostHogApplication, getPostHogStarted };