Skip to content

Commit

Permalink
disable posthog on localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
mishushakov committed Aug 28, 2024
1 parent 75a55be commit 596a658
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import { CSPostHogProvider } from './providers'
import { PostHogProvider } from './providers'
import './globals.css'

const inter = Inter({ subsets: ['latin'] })
Expand All @@ -17,11 +17,11 @@ export default function RootLayout({
}>) {
return (
<html lang="en">
<CSPostHogProvider>
<PostHogProvider>
<body className={inter.className}>
{children}
</body>
</CSPostHogProvider>
</PostHogProvider>
</html>
)
}
15 changes: 0 additions & 15 deletions app/providers.js

This file was deleted.

21 changes: 21 additions & 0 deletions app/providers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// app/providers.js
'use client'
import posthog from 'posthog-js'
import { PostHogProvider as PostHogProviderJS } from 'posthog-js/react'

if (typeof window !== 'undefined' && process.env.NEXT_PUBLIC_ENABLE_POSTHOG) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY ?? '', {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: 'identified_only'
})
}

export function PostHogProvider({ children }: { children: React.ReactNode }) {
return process.env.NEXT_PUBLIC_ENABLE_POSTHOG ? (
<PostHogProviderJS client={posthog}>
{children}
</PostHogProviderJS>
) : (
children
)
}

0 comments on commit 596a658

Please sign in to comment.