Files
posthog.com/gatsby-browser.tsx
Cory Watilo 15c925b43d version bump (#12254)
Co-authored-by: Cory Watilo <corywatilo@gmail.com>
Co-authored-by: Eli Kinsey <eli@ekinsey.dev>
Co-authored-by: Lucas Faria <12522524+lucasheriques@users.noreply.github.com>
Co-authored-by: Ben White <ben@posthog.com>
Co-authored-by: Juraj Majerik <juro.majerik@gmail.com>
Co-authored-by: Rafael Audibert <32079912+rafaeelaudibert@users.noreply.github.com>
2025-09-10 16:33:30 +00:00

46 lines
1.4 KiB
TypeScript

import React from 'react'
import { initKea, wrapElement } from './kea'
import './src/styles/global.css'
import { Provider as ToastProvider } from './src/context/Toast'
import { RouteUpdateArgs } from 'gatsby'
import { UserProvider } from './src/hooks/useUser'
import Wrapper from './src/components/Wrapper'
import { Provider } from './src/context/App'
initKea(false)
export const wrapRootElement = ({ element }) => (
<ToastProvider>
<UserProvider>{wrapElement({ element })}</UserProvider>
</ToastProvider>
)
export const onRouteUpdate = ({ location, prevLocation }: RouteUpdateArgs) => {
// This is checked and set on initial load in the body script set in gatsby-ssr.js
// Checking for prevLocation prevents this from happening twice
if (typeof window !== 'undefined' && prevLocation) {
var theme = (window as any).__theme
document.body.className = theme
}
if (window?.posthog) {
if (prevLocation) {
window.posthog.capture('$pageleave', {
$host: prevLocation.host,
$pathname: prevLocation.pathname,
$current_url: prevLocation.href,
})
}
window?.posthog?.capture('$pageview')
}
}
export const wrapPageElement = ({ element, props: { location } }) => {
return (
<Provider element={element} location={location}>
<Wrapper />
</Provider>
)
}