2
0

📈 (posthog) Send user last login event

This commit is contained in:
Baptiste Arnaud
2024-03-04 10:04:48 +01:00
parent 8846cdbf6b
commit 434b06767d
3 changed files with 22 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import got from 'got'
import { env } from '@typebot.io/env'
import * as Sentry from '@sentry/nextjs'
import { getIp } from '@typebot.io/lib/getIp'
import { trackEvents } from '@typebot.io/lib/telemetry/trackEvents'
const providers: Provider[] = []
@ -218,11 +219,18 @@ const updateLastActivityDate = async (user: User) => {
first.getMonth() === second.getMonth() &&
first.getDate() === second.getDate()
if (!datesAreOnSameDay(user.lastActivityAt, new Date()))
if (!datesAreOnSameDay(user.lastActivityAt, new Date())) {
await prisma.user.updateMany({
where: { id: user.id },
data: { lastActivityAt: new Date() },
})
await trackEvents([
{
name: 'User logged in',
userId: user.id,
},
])
}
}
const getUserGroups = async (account: Account): Promise<string[]> => {