#Help with tracking user session

10 messages · Page 1 of 1 (latest)

floral rampart
#

I'm working on a project with next.js and prisma (PostgreSQL), for authentication I use (NEXTAUTH),

I just want to know how to track a user's session (Its duration - start and end time each time he enters site)

and this is because i want to calculate the DAU (Daily active users), and other purposes, if anybody gives me ideas i'd be so thankful.

thanks in advance.

rancid mulchBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

modern thunder
# floral rampart I'm working on a project with next.js and prisma (PostgreSQL), for authenticatio...

you can add custom parameters to your next-auth session. When you create the session get the current time and put that current time inside the session. Thats your startTime. Now you can check inside your middleware the session, get the value and compare it with the current time. Like that you got a "endTime" (not really, but you get the point). If you substract it from each other you can get the duration.

At the end you have: startTime, endTime and duration

floral rampart
#

but i will struggle with advanced cases, for example. what if the user logs into the website, then his PC sleeps ? it won't never end, i should then specify what is the endtime (browser closed - logout - network disconnection, etc...)

modern thunder
floral rampart
#

its actaully JWT,

please do you have ressources that can help me ? i didnt find this on documentation.

modern thunder
raven helm
#

@floral rampart I would recommend you to integrate analytics tools like GA, Log Rocket or MixPanel ...

near cliff
modern thunder
#

@floral rampart solved? Please mark solution: