Need help with script for User ID for Matomo 4.1.1

Hello .
Maybe someone can help me - I’m somehow overwhelmed :upside_down_face:

I would like to receive the stats for users with an individual ID during tracking.

Procedure:
Tracking start from login.
After a successful login the tracking should start,
The user can therefore be identified with a unique ID (email address).
The time should be recorded how long he looks around / stays on all sides.
Tracking should stop after logging out or closing the browser window.

If the user logs in the next day, the time should also be recorded for the new day and added to the time of the previous day at the end.
At the end of the month I would like to know how long each user has been on the pages to create an evaluation (hours, minutes, etc.)

Maybe someone has a solution?
I think I put the script together completely wrong (see below in the attachment)

Many Thanks

-----------------------------------------