Skip to content

Commit

Permalink
automod
Browse files Browse the repository at this point in the history
  • Loading branch information
jtgi committed Mar 7, 2024
1 parent c4c3884 commit b0cb49b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/lib/posthog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { useEffect } from "react";
import { User } from "@prisma/client";
import { posthog } from "posthog-js";

export function usePosthog(props: { user: User | null }) {
export function usePosthog(props: { user: User | null; enabled: boolean }) {
const location = useLocation();
const [clientSetup, setClientSetup] = useState(false);

Check failure on line 8 in app/lib/posthog.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Cannot find name 'useState'.

useEffect(() => {
if (!props.enabled) {
return;
}

if (!clientSetup) {
posthog.init("phc_xSfqRtKRSoH5A9kPcNkI7J2HNakfQ5KRhFiwVujq8WL", {
api_host: "https://app.posthog.com",
Expand All @@ -21,9 +25,11 @@ export function usePosthog(props: { user: User | null }) {
name: props.user.name,
});
}
}, [props.user]);
}, [enabled, props.user]);

Check failure on line 28 in app/lib/posthog.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Cannot find name 'enabled'.

useEffect(() => {
posthog.capture("$pageview");
}, [location]);
if (enabled) {

Check failure on line 31 in app/lib/posthog.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Cannot find name 'enabled'.
posthog.capture("$pageview");
}
}, [enabled, location]);

Check failure on line 34 in app/lib/posthog.tsx

View workflow job for this annotation

GitHub Actions / ʦ TypeScript

Cannot find name 'enabled'.
}
1 change: 1 addition & 0 deletions app/lib/utils.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export function getSharedEnv() {
return {
infuraProjectId: process.env.INFURA_PROJECT_ID!,
postHogApiKey: process.env.POSTHOG_API_KEY!,
nodeEnv: process.env.NODE_ENV!,
hostUrl:
process.env.NODE_ENV === "production"
? process.env.PROD_URL!
Expand Down
2 changes: 1 addition & 1 deletion app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const meta: MetaFunction = () => {
function App() {
const { env, user } = useTypedLoaderData<typeof loader>();

usePosthog({ user });
usePosthog({ user, enabled: env.nodeEnv === "production" });

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

0 comments on commit b0cb49b

Please sign in to comment.