Skip to content

Commit

Permalink
Conditionally initialize posthog (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Nov 14, 2024
1 parent bde9cc1 commit 094a5f4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
37 changes: 12 additions & 25 deletions packages/keychain/src/components/Provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,8 @@ import { useConnectionValue } from "hooks/connection";
import { ConnectionProvider } from "./connection";
import { CartridgeAPIProvider } from "@cartridge/utils/api/cartridge";
import { ENDPOINT } from "utils/graphql";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";

if (typeof window !== "undefined") {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: "always",
enable_recording_console_log: true,
loaded: (posthog) => {
if (process.env.NODE_ENV === "development") posthog.debug();
},
});
}
import posthog from "posthog-js";

export function Provider({ children }: PropsWithChildren) {
const preset = useControllerThemePreset();
Expand All @@ -43,19 +32,17 @@ export function Provider({ children }: PropsWithChildren) {
const connection = useConnectionValue();

return (
<PostHogProvider client={posthog}>
<ChakraProvider theme={chakraTheme}>
<CartridgeAPIProvider url={ENDPOINT}>
<QueryClientProvider client={queryClient}>
<ControllerThemeProvider value={controllerTheme}>
<ConnectionProvider value={connection}>
{children}
</ConnectionProvider>
</ControllerThemeProvider>
</QueryClientProvider>
</CartridgeAPIProvider>
</ChakraProvider>
</PostHogProvider>
<ChakraProvider theme={chakraTheme}>
<CartridgeAPIProvider url={ENDPOINT}>
<QueryClientProvider client={queryClient}>
<ControllerThemeProvider value={controllerTheme}>
<ConnectionProvider value={connection}>
<PostHogProvider client={posthog}>{children}</PostHogProvider>
</ConnectionProvider>
</ControllerThemeProvider>
</QueryClientProvider>
</CartridgeAPIProvider>
</ChakraProvider>
);
}

Expand Down
15 changes: 15 additions & 0 deletions packages/keychain/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,26 @@ import { ErrorPage } from "components/ErrorBoundary";
import { Settings } from "components/Settings";
import { Upgrade } from "components/connect/Upgrade";
import { PurchaseCredits } from "components/Funding/PurchaseCredits";
import posthog from "posthog-js";
import { useEffect } from "react";

function Home() {
const { context, controller, setController, error, policies, upgrade } =
useConnection();

useEffect(() => {
if (context?.origin) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: "always",
enable_recording_console_log: true,
loaded: (posthog) => {
if (process.env.NODE_ENV === "development") posthog.debug();
},
});
}
}, [context?.origin]);

if (window.self === window.top || !context?.origin) {
return <></>;
}
Expand Down

0 comments on commit 094a5f4

Please sign in to comment.