This is just a convenience wrapper around posthog-js for Next.js
yarn add next-use-posthog
In pages/_app.js
or pages/_app.tsx
import { usePostHog } from 'next-use-posthog'
const App = ({ Component, pageProps }) => {
usePostHog('API_KEY', {
api_host: 'https://app.posthog.com',
})
return <Component {...pageProps} />
}
export default App
import { usePostHog } from 'next-use-posthog'
import { AppProps } from 'next/app'
import { FC } from 'react'
const App: FC<AppProps> = ({ Component, pageProps }) => {
usePostHog('API_KEY', {
api_host: 'https://app.posthog.com',
})
return <Component {...pageProps} />
}
export default App
import { usePostHog } from 'next-use-posthog'
import { AppProps } from 'next/app'
import { FC } from 'react'
const App: FC<AppProps> = ({ Component, pageProps }) => {
usePostHog('API_KEY', {
api_host: 'https://app.posthog.com',
loaded: (posthog) => {
if (process.env.NODE_ENV === 'development') posthog.opt_out_capturing();
},
});
return <Component {...pageProps} />
}
export default App
- React
- Next.js