📈 Improvements to posthog analytics data (#1189)

This commit is contained in:
Luke Vella 2024-07-03 12:09:58 +01:00 committed by GitHub
parent 278713d57f
commit 587e11de17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 93 additions and 80 deletions

View file

@ -174,9 +174,32 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
signOut: "/logout",
error: "/auth/error",
},
events: {
signIn({ user, account }) {
posthog?.capture({
distinctId: user.id,
event: "login",
properties: {
method: account?.provider,
$set: {
name: user.name,
email: user.email,
timeZone: user.timeZone,
locale: user.locale,
},
},
});
},
signOut({ session }) {
posthog?.capture({
distinctId: session.user.id,
event: "logout",
});
},
},
callbacks: {
async signIn({ user, email, account, profile }) {
const distinctId = user.email ?? user.id;
async signIn({ user, email, profile }) {
const distinctId = user.id;
// prevent sign in if email is not verified
if (
profile &&
@ -221,22 +244,6 @@ const getAuthOptions = (...args: GetServerSessionParams) =>
if (session && session.user.email === null) {
await mergeGuestsIntoUser(user.id, [session.user.id]);
}
posthog?.identify({
distinctId,
properties: {
name: user.name,
email: user.email,
},
});
posthog?.capture({
distinctId,
event: "login",
properties: {
method: account?.provider,
},
});
}
return true;