Skip to content

Commit 5a2d5ec

Browse files
committed
Use nextjs native instrumentation.ts file to initAnalytics, hopefully fixing missing posthog events
1 parent f5f3da7 commit 5a2d5ec

File tree

4 files changed

+21
-35
lines changed

4 files changed

+21
-35
lines changed

web/instrumentation.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { initAnalytics } from '@codebuff/common/analytics'
2+
import { env } from '@codebuff/common/env'
3+
4+
import { logger } from '@/util/logger'
5+
6+
// This special file runs once when the Next.js server starts
7+
// It initializes analytics for all server-side code including API routes
8+
export function register() {
9+
try {
10+
initAnalytics({
11+
logger,
12+
clientEnv: env,
13+
})
14+
} catch (error) {
15+
logger.warn(
16+
{ error },
17+
'Failed to initialize analytics - continuing without analytics',
18+
)
19+
}
20+
}

web/next.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const nextConfig = {
2525
optimizePackageImports: ['@/components/ui'],
2626
},
2727
webpack: (config) => {
28-
config.resolve.fallback = { fs: false, net: false, tls: false }
28+
config.resolve.fallback = { fs: false, net: false, tls: false, path: false }
2929
// Tell Next.js to leave pino and thread-stream unbundled
3030
config.externals.push(
3131
{ 'thread-stream': 'commonjs thread-stream', pino: 'commonjs pino' },

web/src/app/layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import '@/lib/server-init'
21
import '@/styles/globals.css'
32

43
import type { Metadata } from 'next'
5-
import type { PropsWithChildren } from 'react'
64

75
import { CookieConsentCard } from '@/components/CookieConsentCard'
86
import { Footer } from '@/components/footer'

web/src/lib/server-init.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)