diff --git a/apps/sim/app/layout.tsx b/apps/sim/app/layout.tsx index 50bbd857b3..f7363002a9 100644 --- a/apps/sim/app/layout.tsx +++ b/apps/sim/app/layout.tsx @@ -1,11 +1,10 @@ -import { Analytics } from '@vercel/analytics/next' import type { Metadata, Viewport } from 'next' import { PublicEnvScript } from 'next-runtime-env' import { BrandedLayout } from '@/components/branded-layout' import { generateThemeCSS } from '@/lib/branding/inject-theme' import { generateBrandedMetadata, generateStructuredData } from '@/lib/branding/metadata' -import { isHosted } from '@/lib/environment' import { createLogger } from '@/lib/logs/console/logger' +import { PostHogProvider } from '@/lib/posthog/provider' import '@/app/globals.css' import { SessionProvider } from '@/lib/session/session-context' @@ -55,7 +54,6 @@ export const viewport: Viewport = { ], } -// Generate dynamic metadata based on brand configuration export const metadata: Metadata = generateBrandedMetadata() export default function RootLayout({ children }: { children: React.ReactNode }) { @@ -91,19 +89,16 @@ export default function RootLayout({ children }: { children: React.ReactNode }) - - - - - {children} - {isHosted && ( - <> - - - )} - - - + + + + + + {children} + + + + ) diff --git a/apps/sim/instrumentation-client.ts b/apps/sim/instrumentation-client.ts index 6ba4db89b3..584abb63f5 100644 --- a/apps/sim/instrumentation-client.ts +++ b/apps/sim/instrumentation-client.ts @@ -5,34 +5,7 @@ * It respects the user's telemetry preferences stored in localStorage. * */ -import posthog from 'posthog-js' -import { env, getEnv, isTruthy } from './lib/env' - -// Initialize PostHog only if explicitly enabled -if (isTruthy(getEnv('NEXT_PUBLIC_POSTHOG_ENABLED')) && getEnv('NEXT_PUBLIC_POSTHOG_KEY')) { - posthog.init(getEnv('NEXT_PUBLIC_POSTHOG_KEY')!, { - api_host: '/ingest', - ui_host: 'https://us.posthog.com', - person_profiles: 'identified_only', - capture_pageview: true, - capture_pageleave: true, - capture_performance: true, - session_recording: { - maskAllInputs: false, - maskInputOptions: { - password: true, - email: false, - }, - recordCrossOriginIframes: false, - recordHeaders: true, - recordBody: true, - }, - autocapture: true, - capture_dead_clicks: true, - persistence: 'localStorage+cookie', - enable_heatmaps: true, - }) -} +import { env } from './lib/env' if (typeof window !== 'undefined') { const TELEMETRY_STATUS_KEY = 'simstudio-telemetry-status' diff --git a/apps/sim/lib/posthog/provider.tsx b/apps/sim/lib/posthog/provider.tsx new file mode 100644 index 0000000000..a016dfd546 --- /dev/null +++ b/apps/sim/lib/posthog/provider.tsx @@ -0,0 +1,41 @@ +'use client' + +import { useEffect } from 'react' +import posthog from 'posthog-js' +import { PostHogProvider as PHProvider } from 'posthog-js/react' +import { getEnv, isTruthy } from '../env' + +export function PostHogProvider({ children }: { children: React.ReactNode }) { + useEffect(() => { + const posthogEnabled = getEnv('NEXT_PUBLIC_POSTHOG_ENABLED') + const posthogKey = getEnv('NEXT_PUBLIC_POSTHOG_KEY') + + if (isTruthy(posthogEnabled) && posthogKey && !posthog.__loaded) { + posthog.init(posthogKey, { + api_host: '/ingest', + ui_host: 'https://us.posthog.com', + defaults: '2025-05-24', + person_profiles: 'identified_only', + capture_pageview: true, + capture_pageleave: true, + capture_performance: true, + session_recording: { + maskAllInputs: false, + maskInputOptions: { + password: true, + email: false, + }, + recordCrossOriginIframes: false, + recordHeaders: true, + recordBody: true, + }, + autocapture: true, + capture_dead_clicks: true, + persistence: 'localStorage+cookie', + enable_heatmaps: true, + }) + } + }, []) + + return {children} +}