mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 13:01:56 +00:00
fix: updated per @paabloLC request to move Posthog initialization outside of providers.tsx
This commit is contained in:
+4
-11
@@ -7,8 +7,8 @@ import { ThemeProvider as NextThemesProvider } from "next-themes";
|
||||
import { ThemeProviderProps } from "next-themes/dist/types";
|
||||
import posthog from "posthog-js";
|
||||
import { PostHogProvider as PHProvider } from "posthog-js/react";
|
||||
import { useEffect } from "react";
|
||||
import * as React from "react";
|
||||
import { initializePostHog } from "@/lib/analytics";
|
||||
|
||||
export interface ProvidersProps {
|
||||
children: React.ReactNode;
|
||||
@@ -18,16 +18,9 @@ export interface ProvidersProps {
|
||||
export function Providers({ children, themeProps }: ProvidersProps) {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
||||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
autocapture: false,
|
||||
defaults: "2025-05-24",
|
||||
capture_exceptions: true,
|
||||
capture_pageview: false,
|
||||
capture_pageleave: false,
|
||||
});
|
||||
// Initialize PostHog
|
||||
React.useMemo(() => {
|
||||
initializePostHog();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
||||
+22
-1
@@ -1,5 +1,24 @@
|
||||
import posthog from "posthog-js";
|
||||
|
||||
// Initialize PostHog
|
||||
export const initializePostHog = (): void => {
|
||||
if (typeof window === "undefined") return; // Don't initialize on server side
|
||||
|
||||
try {
|
||||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
|
||||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
ui_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
|
||||
autocapture: false,
|
||||
defaults: "2025-05-24",
|
||||
capture_exceptions: true,
|
||||
capture_pageview: false,
|
||||
capture_pageleave: false,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize PostHog:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// Type definitions for tracking payloads
|
||||
export interface UserLoginPayload {
|
||||
email: string;
|
||||
@@ -144,7 +163,9 @@ export const setUserProperties = (properties: Record<string, any>): void => {
|
||||
export const isAnalyticsReady = (): boolean => {
|
||||
try {
|
||||
return (
|
||||
typeof posthog !== "undefined" && posthog._isIdentified !== undefined
|
||||
typeof window !== "undefined" &&
|
||||
typeof posthog !== "undefined" &&
|
||||
posthog.__loaded === true
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user