Skip to content

Commit

Permalink
📈 Track login events in posthog (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella authored Oct 24, 2023
1 parent 4f1389c commit f771f6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion apps/web/src/components/auth/auth-forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ export const LoginForm: React.FunctionComponent<{
name: s.user.name,
});
}
posthog?.capture("login");
posthog?.capture("login", {
method: "verification-code"
});
router.push(callbackUrl);
}
}}
Expand Down
24 changes: 22 additions & 2 deletions apps/web/src/pages/auth/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Skeleton } from "@/components/skeleton";
import { Trans } from "@/components/trans";
import { UserAvatar } from "@/components/user";
import { NextPageWithLayout } from "@/types";
import { usePostHog } from "@/utils/posthog";
import { trpc } from "@/utils/trpc/client";
import { getServerSideTranslations } from "@/utils/with-page-translations";

Expand All @@ -29,13 +30,32 @@ type PageProps = { magicLink: string; email: string };

const Page: NextPageWithLayout<PageProps> = ({ magicLink, email }) => {
const session = useSession();
const posthog = usePostHog();
const trpcUtils = trpc.useUtils();
const magicLinkFetch = useMutation({
mutationFn: async () => {
const res = await fetch(magicLink);
return res;
},
onSuccess: (data) => {
session.update();
onSuccess: async (data) => {
if (!data.url.includes("auth/error")) {
// if login was successful, update the session
const updatedSession = await session.update();
if (updatedSession) {
// identify the user in posthog
posthog?.identify(updatedSession.user.id, {
email: updatedSession.user.email,
name: updatedSession.user.name,
});

posthog?.capture("login", {
method: "magic-link",
});

await trpcUtils.invalidate();
}
}

router.push(data.url);
},
});
Expand Down

1 comment on commit f771f6a

@vercel
Copy link

@vercel vercel bot commented on f771f6a Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

app – ./

rallly-vert.vercel.app
app-rallly.vercel.app
app-git-main-rallly.vercel.app
app.rallly.co

Please sign in to comment.