mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-31 23:19:15 +02:00
📈 Capture logout event + merge set and identify calls (#1211)
Signed-off-by: Luke Vella <me@lukevella.com>
This commit is contained in:
parent
c126cbdda1
commit
ba3008b3f2
3 changed files with 29 additions and 16 deletions
|
@ -1,14 +1,29 @@
|
||||||
|
"use client";
|
||||||
import { Button, ButtonProps } from "@rallly/ui/button";
|
import { Button, ButtonProps } from "@rallly/ui/button";
|
||||||
|
import { signOut } from "next-auth/react";
|
||||||
|
|
||||||
|
import { usePostHog } from "@/utils/posthog";
|
||||||
|
|
||||||
export function LogoutButton({
|
export function LogoutButton({
|
||||||
children,
|
children,
|
||||||
|
onClick,
|
||||||
...rest
|
...rest
|
||||||
}: React.PropsWithChildren<ButtonProps>) {
|
}: React.PropsWithChildren<ButtonProps>) {
|
||||||
|
const posthog = usePostHog();
|
||||||
return (
|
return (
|
||||||
<form action="/auth/logout" method="POST">
|
<Button
|
||||||
<Button {...rest} type="submit">
|
{...rest}
|
||||||
{children}
|
onClick={async (e) => {
|
||||||
</Button>
|
onClick?.(e);
|
||||||
</form>
|
posthog?.capture("logout");
|
||||||
|
posthog?.reset();
|
||||||
|
signOut({
|
||||||
|
redirect: true,
|
||||||
|
callbackUrl: "/login",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</Button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { PostHogProvider as Provider, usePostHog } from "posthog-js/react";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useMount } from "react-use";
|
import { useMount } from "react-use";
|
||||||
|
|
||||||
|
import { useTranslation } from "@/app/i18n/client";
|
||||||
import { useUser } from "@/components/user-provider";
|
import { useUser } from "@/components/user-provider";
|
||||||
import { env } from "@/env";
|
import { env } from "@/env";
|
||||||
|
|
||||||
|
@ -48,14 +49,18 @@ function usePostHogPageView() {
|
||||||
|
|
||||||
export function PostHogProvider(props: PostHogProviderProps) {
|
export function PostHogProvider(props: PostHogProviderProps) {
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
usePostHogPageView();
|
usePostHogPageView();
|
||||||
|
|
||||||
useMount(() => {
|
useMount(() => {
|
||||||
if (user.email) {
|
if (user.email) {
|
||||||
posthog.identify(user.id);
|
posthog.identify(user.id, {
|
||||||
posthog.people.set({
|
email: user.email,
|
||||||
$email: user.email,
|
name: user.name,
|
||||||
$name: user.name,
|
tier: user.tier,
|
||||||
|
timeZone: user.timeZone,
|
||||||
|
locale: i18n.language,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -174,7 +174,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
||||||
providers: providers,
|
providers: providers,
|
||||||
pages: {
|
pages: {
|
||||||
signIn: "/login",
|
signIn: "/login",
|
||||||
signOut: "/logout",
|
|
||||||
error: "/auth/error",
|
error: "/auth/error",
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
|
@ -193,12 +192,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
signOut({ session }) {
|
|
||||||
posthog?.capture({
|
|
||||||
distinctId: session.user.id,
|
|
||||||
event: "logout",
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
callbacks: {
|
callbacks: {
|
||||||
async signIn({ user, email, profile }) {
|
async signIn({ user, email, profile }) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue