Skip to content

Commit

Permalink
fix(posthog): wrap posthog init in try catch (#2463)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu authored Jul 10, 2023
1 parent 7905d22 commit fc34f6c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
22 changes: 15 additions & 7 deletions apps/console/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { type ServicePlanType } from '@proofzero/types/account'
import { BadRequestError } from '@proofzero/errors'
import posthog from 'posthog-js'
import { PostHogProvider } from 'posthog-js/react'
import { useHydrated } from 'remix-utils'

export const links: LinksFunction = () => {
return [
Expand Down Expand Up @@ -192,14 +193,21 @@ export default function App() {
}
}, [location, GATag])

// https://posthog.com/docs/libraries/react#posthog-provider
if (typeof window !== 'undefined') {
posthog.init(loaderData.ENV.POSTHOG_API_KEY, {
api_host: POSTHOG_PROXY_HOST,
})
const hydrated = useHydrated()
useEffect(() => {
// https://posthog.com/docs/libraries/react#posthog-provider
if (hydrated) {
try {
posthog.init(loaderData.ENV.POSTHOG_API_KEY, {
api_host: POSTHOG_PROXY_HOST,
})

posthog?.identify(accountURN)
}
posthog?.identify(accountURN)
} catch (ex) {
console.error(ex)
}
}
}, [hydrated])

return (
<html lang="en" className="h-full">
Expand Down
24 changes: 16 additions & 8 deletions apps/passport/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import useTreeshakeHack from '@proofzero/design-system/src/hooks/useTreeshakeHac
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors'
import { ThemeContext } from '@proofzero/design-system/src/contexts/theme'
import { getStarbaseClient } from './platform.server'
import { useHydrated } from 'remix-utils'
export const meta: MetaFunction = () => ({
charset: 'utf-8',
title: 'Passport - Rollup',
Expand Down Expand Up @@ -168,6 +169,8 @@ export default function App() {
const transition = useTransition()
const browserEnv = useLoaderData()

const hydrated = useHydrated()

const GATag = browserEnv.ENV.INTERNAL_GOOGLE_ANALYTICS_TAG

const remixDevPort = browserEnv.ENV.REMIX_DEV_SERVER_WS_PORT
Expand Down Expand Up @@ -217,14 +220,19 @@ export default function App() {
setUEComplete(true)
}, [])

// https://posthog.com/docs/libraries/react#posthog-provider
if (typeof window !== 'undefined') {
posthog.init(browserEnv.ENV.POSTHOG_API_KEY, {
api_host: POSTHOG_PROXY_HOST,
})

posthog?.reset()
}
useEffect(() => {
// https://posthog.com/docs/libraries/react#posthog-provider
if (hydrated) {
try {
posthog.init(browserEnv.ENV.POSTHOG_API_KEY, {
api_host: POSTHOG_PROXY_HOST,
})
posthog?.reset()
} catch (ex) {
console.error(ex)
}
}
}, [hydrated])

return (
<html lang="en">
Expand Down

0 comments on commit fc34f6c

Please sign in to comment.