add posthog integration (#7)

* add possibility to track events with posthog by setting environment variables POSTHOG_API_KEY and POSTHOG_API_HOST
This commit is contained in:
Matthias Nannt
2022-07-22 16:15:39 +02:00
committed by GitHub
parent cb6b76c3e2
commit 277bd014ae
13 changed files with 372 additions and 259 deletions

View File

@@ -6,6 +6,7 @@ import { Fragment, useState } from "react";
import { BsPlus } from "react-icons/bs";
import { createForm } from "../../lib/forms";
import { createNoCodeForm } from "../../lib/noCodeForm";
import { trackPosthogEvent } from "../../lib/posthog";
import { classNames } from "../../lib/utils";
import StandardButton from "../StandardButton";
@@ -47,6 +48,7 @@ export default function NewFormModal({
if (form.formType === "NOCODE") {
await createNoCodeForm(form.id);
}
trackPosthogEvent("newForm", { formType: form.formType });
router.push(`/forms/${form.id}/form`);
};

View File

@@ -1,5 +1,6 @@
import { SnoopElement, SnoopForm, SnoopPage } from "@snoopforms/react";
import { useMemo } from "react";
import { trackPosthogEvent } from "../../lib/posthog";
import Loading from "../Loading";
export default function App({ id = "", formId, blocks, localOnly = false }) {
@@ -41,6 +42,9 @@ export default function App({ id = "", formId, blocks, localOnly = false }) {
formId={formId}
localOnly={localOnly}
className="w-full max-w-3xl mx-auto space-y-6"
onSubmit={() => {
trackPosthogEvent("submitForm", { formId });
}}
>
{pages.map((page) => (
<SnoopPage key={page.id} name={page.id}>

View File

@@ -1,6 +1,7 @@
import { signIn, useSession } from "next-auth/react";
import Head from "next/head";
import { useEffect, useState } from "react";
import { usePosthog } from "../../lib/posthog";
import { classNames } from "../../lib/utils";
import Loading from "../Loading";
import MenuBreadcrumbs from "./MenuBreadcrumbs";
@@ -40,6 +41,8 @@ export default function BaseLayoutAuthorized({
}
}, [session, status]);
usePosthog(session?.user?.email);
if (status === "loading" || loading) {
return <Loading />;
}

View File

@@ -0,0 +1,14 @@
import Head from "next/head";
import { usePosthog } from "../../lib/posthog";
export default function BaseLayoutUnauthorized({ title, children }) {
usePosthog(null, true);
return (
<>
<Head>
<title>{title}</title>
</Head>
{children}
</>
);
}