-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/add posthog envvars to buildtime variables (#232)
* Revert "Revert: Removed posthog" This reverts commit ee8da35. * add posthog env vars to build time environment * added client env vars to health check so that we fail before deploying if client env vars are missing
- Loading branch information
Showing
16 changed files
with
195 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use client' | ||
|
||
import { ReactNode, useEffect } from 'react' | ||
|
||
import { User, Workspace } from '@latitude-data/core/browser' | ||
import { envClient } from '$/envClient' | ||
import posthog from 'posthog-js' | ||
import { PostHogProvider, usePostHog } from 'posthog-js/react' | ||
|
||
if ( | ||
typeof window !== 'undefined' && | ||
envClient.NEXT_PUBLIC_POSTHOG_KEY && | ||
envClient.NEXT_PUBLIC_POSTHOG_HOST | ||
) { | ||
posthog.init(envClient.NEXT_PUBLIC_POSTHOG_KEY, { | ||
api_host: envClient.NEXT_PUBLIC_POSTHOG_HOST, | ||
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well | ||
}) | ||
} | ||
export function CSPostHogProvider({ children }: { children: ReactNode }) { | ||
return <PostHogProvider client={posthog}>{children}</PostHogProvider> | ||
} | ||
|
||
export function IdentifyUser({ | ||
user, | ||
workspace, | ||
children, | ||
}: { | ||
user: User | ||
workspace: Workspace | ||
children: ReactNode | ||
}) { | ||
const posthog = usePostHog() | ||
|
||
useEffect(() => { | ||
if (user) { | ||
posthog?.identify(user.id, { | ||
email: user.email, | ||
}) | ||
posthog?.group('workspace', String(workspace.id)) | ||
} | ||
}, [posthog, user.id, user.email, workspace.id]) | ||
|
||
return children | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createEnv } from '@t3-oss/env-nextjs' | ||
import { z } from 'zod' | ||
|
||
export const envClient = createEnv({ | ||
client: { | ||
NEXT_PUBLIC_POSTHOG_KEY: z.string(), | ||
NEXT_PUBLIC_POSTHOG_HOST: z.string(), | ||
}, | ||
runtimeEnv: { | ||
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY ?? '', | ||
NEXT_PUBLIC_POSTHOG_HOST: process.env.NEXT_PUBLIC_POSTHOG_HOST ?? '', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.