📈 Conditionally initialize posthog (#586)

This commit is contained in:
Luke Vella 2023-03-20 20:04:39 +00:00 committed by GitHub
parent 4062b572a0
commit d9061d45fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 79 additions and 53 deletions

View file

@ -1,9 +1,10 @@
import clsx from "clsx";
import { useTranslation } from "next-i18next";
import posthog from "posthog-js";
import * as React from "react";
import { Controller, useForm } from "react-hook-form";
import { usePostHog } from "@/utils/posthog";
import { useDayjs } from "../../utils/dayjs";
import { requiredString } from "../../utils/form-validation";
import { trpc } from "../../utils/trpc";
@ -38,10 +39,11 @@ const Discussion: React.FunctionComponent = () => {
trpc: {},
},
);
const posthog = usePostHog();
const addComment = trpc.polls.comments.add.useMutation({
onSuccess: (newComment) => {
posthog.capture("created comment");
posthog?.capture("created comment");
queryClient.polls.comments.list.setData(
{ pollId },
@ -62,7 +64,7 @@ const Discussion: React.FunctionComponent = () => {
);
},
onSuccess: () => {
posthog.capture("deleted comment");
posthog?.capture("deleted comment");
},
});