Bernt Christian Egeland 5 месяцев назад
Родитель
Сommit
f72d0c3ada
2 измененных файлов с 8 добавлено и 7 удалено
  1. 2 1
      src/app/layout.tsx
  2. 6 6
      src/components/posthog-provider.tsx

+ 2 - 1
src/app/layout.tsx

@@ -10,6 +10,7 @@ import { TooltipProvider } from '@/components/ui/tooltip'
 import { PWAServiceWorker } from '@/components/pwa-service-worker'
 import { PostHogProvider } from '@/components/posthog-provider'
 import { isCloudMode } from '@/lib/features'
+import { isDemoMode } from '@/lib/demo'
 import { DemoBanner } from '@/components/demo-banner'
 import './globals.css'
 
@@ -98,7 +99,7 @@ export default async function RootLayout({
       </head>
       <body className={`${geistSans.variable} ${geistMono.variable} font-sans antialiased`}>
         <PostHogProvider
-          isCloud={isCloudMode()}
+          enabled={isCloudMode() || isDemoMode}
           posthogKey={process.env.POSTHOG_KEY}
           posthogHost={process.env.POSTHOG_HOST}
         >

+ 6 - 6
src/components/posthog-provider.tsx

@@ -1,4 +1,4 @@
-// PostHog analytics — only active in cloud mode (TORQVOICE_MODE=cloud).
+// PostHog analytics — active in cloud mode and on the public demo instance.
 // Self-hosted instances never load or initialize PostHog.
 'use client'
 
@@ -7,18 +7,18 @@ import { PostHogProvider as PHProvider } from 'posthog-js/react'
 import { useEffect } from 'react'
 
 export function PostHogProvider({
-  isCloud,
+  enabled,
   posthogKey,
   posthogHost,
   children,
 }: {
-  isCloud: boolean
+  enabled: boolean
   posthogKey?: string
   posthogHost?: string
   children: React.ReactNode
 }) {
   useEffect(() => {
-    if (isCloud && posthogKey) {
+    if (enabled && posthogKey) {
       posthog.init(posthogKey, {
         api_host: posthogHost || 'https://us.i.posthog.com',
         person_profiles: 'identified_only',
@@ -26,9 +26,9 @@ export function PostHogProvider({
         capture_pageleave: true,
       })
     }
-  }, [isCloud, posthogKey, posthogHost])
+  }, [enabled, posthogKey, posthogHost])
 
-  if (!isCloud || !posthogKey) {
+  if (!enabled || !posthogKey) {
     return <>{children}</>
   }