File tree Expand file tree Collapse file tree 3 files changed +53
-44
lines changed
Expand file tree Collapse file tree 3 files changed +53
-44
lines changed Original file line number Diff line number Diff line change 1- import { Analytics } from '@vercel/analytics/next'
21import type { Metadata , Viewport } from 'next'
32import { PublicEnvScript } from 'next-runtime-env'
43import { BrandedLayout } from '@/components/branded-layout'
54import { generateThemeCSS } from '@/lib/branding/inject-theme'
65import { generateBrandedMetadata , generateStructuredData } from '@/lib/branding/metadata'
7- import { isHosted } from '@/lib/environment'
86import { createLogger } from '@/lib/logs/console/logger'
7+ import { PostHogProvider } from '@/lib/posthog/provider'
98import '@/app/globals.css'
109
1110import { SessionProvider } from '@/lib/session/session-context'
@@ -55,7 +54,6 @@ export const viewport: Viewport = {
5554 ] ,
5655}
5756
58- // Generate dynamic metadata based on brand configuration
5957export const metadata : Metadata = generateBrandedMetadata ( )
6058
6159export default function RootLayout ( { children } : { children : React . ReactNode } ) {
@@ -91,19 +89,16 @@ export default function RootLayout({ children }: { children: React.ReactNode })
9189 < PublicEnvScript />
9290 </ head >
9391 < body suppressHydrationWarning >
94- < ThemeProvider >
95- < SessionProvider >
96- < BrandedLayout >
97- < ZoomPrevention />
98- { children }
99- { isHosted && (
100- < >
101- < Analytics />
102- </ >
103- ) }
104- </ BrandedLayout >
105- </ SessionProvider >
106- </ ThemeProvider >
92+ < PostHogProvider >
93+ < ThemeProvider >
94+ < SessionProvider >
95+ < BrandedLayout >
96+ < ZoomPrevention />
97+ { children }
98+ </ BrandedLayout >
99+ </ SessionProvider >
100+ </ ThemeProvider >
101+ </ PostHogProvider >
107102 </ body >
108103 </ html >
109104 )
Original file line number Diff line number Diff line change 55 * It respects the user's telemetry preferences stored in localStorage.
66 *
77 */
8- import posthog from 'posthog-js'
9- import { env , getEnv , isTruthy } from './lib/env'
10-
11- // Initialize PostHog only if explicitly enabled
12- if ( isTruthy ( getEnv ( 'NEXT_PUBLIC_POSTHOG_ENABLED' ) ) && getEnv ( 'NEXT_PUBLIC_POSTHOG_KEY' ) ) {
13- posthog . init ( getEnv ( 'NEXT_PUBLIC_POSTHOG_KEY' ) ! , {
14- api_host : '/ingest' ,
15- ui_host : 'https://us.posthog.com' ,
16- person_profiles : 'identified_only' ,
17- capture_pageview : true ,
18- capture_pageleave : true ,
19- capture_performance : true ,
20- session_recording : {
21- maskAllInputs : false ,
22- maskInputOptions : {
23- password : true ,
24- email : false ,
25- } ,
26- recordCrossOriginIframes : false ,
27- recordHeaders : true ,
28- recordBody : true ,
29- } ,
30- autocapture : true ,
31- capture_dead_clicks : true ,
32- persistence : 'localStorage+cookie' ,
33- enable_heatmaps : true ,
34- } )
35- }
8+ import { env } from './lib/env'
369
3710if ( typeof window !== 'undefined' ) {
3811 const TELEMETRY_STATUS_KEY = 'simstudio-telemetry-status'
Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useEffect } from 'react'
4+ import posthog from 'posthog-js'
5+ import { PostHogProvider as PHProvider } from 'posthog-js/react'
6+ import { getEnv , isTruthy } from '../env'
7+
8+ export function PostHogProvider ( { children } : { children : React . ReactNode } ) {
9+ useEffect ( ( ) => {
10+ const posthogEnabled = getEnv ( 'NEXT_PUBLIC_POSTHOG_ENABLED' )
11+ const posthogKey = getEnv ( 'NEXT_PUBLIC_POSTHOG_KEY' )
12+
13+ if ( isTruthy ( posthogEnabled ) && posthogKey && ! posthog . __loaded ) {
14+ posthog . init ( posthogKey , {
15+ api_host : '/ingest' ,
16+ ui_host : 'https://us.posthog.com' ,
17+ defaults : '2025-05-24' ,
18+ person_profiles : 'identified_only' ,
19+ capture_pageview : true ,
20+ capture_pageleave : true ,
21+ capture_performance : true ,
22+ session_recording : {
23+ maskAllInputs : false ,
24+ maskInputOptions : {
25+ password : true ,
26+ email : false ,
27+ } ,
28+ recordCrossOriginIframes : false ,
29+ recordHeaders : true ,
30+ recordBody : true ,
31+ } ,
32+ autocapture : true ,
33+ capture_dead_clicks : true ,
34+ persistence : 'localStorage+cookie' ,
35+ enable_heatmaps : true ,
36+ } )
37+ }
38+ } , [ ] )
39+
40+ return < PHProvider client = { posthog } > { children } </ PHProvider >
41+ }
You can’t perform that action at this time.
0 commit comments