-
Notifications
You must be signed in to change notification settings - Fork 6
fix(analytics): correct hourly presence using user timezone #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(analytics): correct hourly presence using user timezone #20
Conversation
|
Hello @akash-kumar-dev This issue will be fully solved if the browser-extension PR is also merged with this so once the user logs in he can See the usage according to his time zone |
|
Hello @akash-kumar-dev , quick nudge on this PR ...All checks are green. Let me Know if you'd like any changes, or if it's good to merge. Thanks! |
|
I appreciate your work on this. During my research, I came across the idea that handling timezone conversion on the client-side might be a better approach, as our server already uses UTC. This could simplify things, especially if a user has multiple sessions in different regions. It would also keep our server code cleaner by eliminating the need to store timezone data in the database. What are your thoughts on this alternative approach? I appreciate your current solution as well. |
|
Hello @akash-kumar-dev so the thing is right now the live website code which is running that is doing is calculating all the analytics in the backend and sending a time bucket like this which is getting plotted |
|
Also there is a Mistake I did is the getHour function I forgot to update it ....The issue of calling the right query is not solved I have to Fix that so if you want to move forward with this approach let me know I have to make changes to make it work fully as now the getHour function is still in its old version creating the issue I just updated the getHourlyPresence thing. I'll make the changes if we are moving forward with this approach |
|
Another way I can think is to make the calculation on the client side say Send me data from 5:00 Jan 26 UTC to 3:00 Jan 27 UTC so the 24 hour bucket we get is of this time only and we dont have to save the user Timezone but we have to make the calculations that from what to what time we need the analytics as per the user and according to that we have to change the backend code for time calculations I thought to make minimal changes hence I went on with this but well we can think in this direction too |
|
Hi @Suyash-ka-github, great point—you noticed the issue around date boundaries and time range queries for analytics routes correctly. You’re right about that part. What I was trying to say is that this is the standard practice most server-side code follows, and there are established ways they handle this kind of time conflict problem. For analytics routes, we can modify our routes and controllers to accept the timezone in the request body and process the data accordingly. However, we actually have more than just analytics routes—we also have Inbox and Last Seen features. There are already a lot of things standardized in a way that the client side can easily handle. For analytics routes specifically, we need to handle some logic on the server side as well, in line with the previous implementation. Now, what are your thoughts on this? Your suggestion will really help us make a better decision for the implementation. |
|
Ok well @akash-kumar-dev I will for sure think on this and let you know what happens in the real world working software how they are handling it It would be a great opportunity to learn for me too |
fda6a91 to
8c415ce
Compare
|
Hello @akash-kumar-dev I have made the changes .I saw Google analytics has an option to select time zone so Most probably they are saving it but we are going with a different approach that is once the user clicks the Analytics tab the API call is made with the users current time zone so API call is made with say Asia/Kolkata or Asia/Tokyo and as per that in the backend the data is fetched which is in UTC and then Calculated according to the users time zone and then sent to the frontend and displayed. Let me know if there is anything else I can do in it |
|
Hi @Suyash-ka-github, the implementation looks good. I haven't fully reviewed it yet, but the approach seems good. I'm a bit busy with other work at the moment, so I'll merge it after a review on Saturday or Sunday. |
|
If you'd like, you could also open a PR to handle timezones for "Last Seen" and "Inbox". The server currently sends this data in UTC, so it would just require handling the timezone conversion on the frontend. I don't think any server-side changes would be needed for that. What are your thoughts? |
|
@akash-kumar-dev Sure I would love to work on that too and yes there would be no need of Server changes I will raise this issue too |
|
Hello @akash-kumar-dev I just saw that Inbox and Last seen is already working as per the time zone could you specify about exactly what you are talking about |

Description
This PR fixes incorrect hourly analytics caused by UTC-based time grouping by using the authenticated user's timezone for analytics calculations.
Previously, activity occurring during early morning hours (e.g. 4–5 AM IST) was grouped under incorrect hours due to UTC offsets. This change ensures hourly presence analytics are calculated correctly for users across different timezones.
Fixes #19
Type of Change
Checklist
Code Quality
Testing
Database Changes (if applicable)
API Changes (if applicable)
Security
Performance
Testing Evidence
Manual testing was performed locally:
Database Migration Details (if applicable)
API Changes (if applicable)
New Endpoints
Modified Endpoints
timezonefield and stores it for analytics usageDeprecated Endpoints
Screenshots / Evidence (if applicable)
N/A (backend-only change)
Additional Notes
This change ensures analytics are globally correct for users across all timezones without introducing breaking changes. The timezone is stored once during authentication and reused for analytics calculations.
Related PRs
Related to: browseping/browser-extension#26 - This PR sends the user timezone from the browser extension that this server-side change requires. Both PRs should be merged together for complete functionality.