Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix session drilldown timezone bucket alignment

Blue Mouse5f70b27b26de
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index 81c553176..bd2dea069 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -729,7 +729,11 @@ const getSettings = (
onclick: onDataPointClick
? (d: any) => {
if (d?.x) {
- onDataPointClick({ x: d.x, index: d.index })
+ onDataPointClick({
+ x: d.x,
+ index: d.index,
+ xValue: chart.x?.[d.index],
+ })
}
}
: undefined,
@@ -1102,6 +1106,7 @@ const getSettings = (
chartInstance,
columns,
onDataPointClick,
+ chart.x,
)
} catch {
// ignore
@@ -1560,7 +1565,11 @@ const getSettingsError = (
onclick: onDataPointClick
? (d: any) => {
if (d?.x) {
- onDataPointClick({ x: d.x, index: d.index })
+ onDataPointClick({
+ x: d.x,
+ index: d.index,
+ xValue: chart.x?.[d.index],
+ })
}
}
: undefined,
@@ -1686,7 +1695,7 @@ const getSettingsError = (
},
onrendered: onDataPointClick
? function (this: any) {
- attachDataPointClickHandlers(this, columns, onDataPointClick)
+ attachDataPointClickHandlers(this, columns, onDataPointClick, chart.x)
}
: undefined,
}
@@ -2006,7 +2015,11 @@ const getSettingsPerf = (
onclick: onDataPointClick
? (d: any) => {
if (d?.x) {
- onDataPointClick({ x: d.x, index: d.index })
+ onDataPointClick({
+ x: d.x,
+ index: d.index,
+ xValue: chart.x?.[d.index],
+ })
}
}
: undefined,
@@ -2286,7 +2299,7 @@ const getSettingsPerf = (
},
onrendered: onDataPointClick
? function (this: any) {
- attachDataPointClickHandlers(this, columns, onDataPointClick)
+ attachDataPointClickHandlers(this, columns, onDataPointClick, chart.x)
}
: undefined,
zoom:
diff --git a/web/app/pages/Project/View/utils/chartPoint.ts b/web/app/pages/Project/View/utils/chartPoint.ts
index 302fcb9f9..e7a29ad06 100644
--- a/web/app/pages/Project/View/utils/chartPoint.ts
+++ b/web/app/pages/Project/View/utils/chartPoint.ts
@@ -5,7 +5,13 @@ import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
dayjs.extend(timezonePlugin)
-export type ChartDataPointClick = (d: { x: Date; index: number }) => void
+export type ChartDataPoint = {
+ x: Date
+ index: number
+ xValue?: string
+}
+
+export type ChartDataPointClick = (d: ChartDataPoint) => void
type EventRectsGroup = SVGElement & {
__clickHandlers?: {
@@ -42,6 +48,7 @@ export const attachDataPointClickHandlers = (
chartInstance: any,
columns: any[],
onDataPointClick?: ChartDataPointClick,
+ chartXValues?: string[],
) => {
if (!chartInstance?.$) return
@@ -116,7 +123,11 @@ export const attachDataPointClickHandlers = (
const xValues = columns[0]?.slice(1) as Date[] | undefined
if (!xValues || index >= xValues.length) return
- onDataPointClick({ x: xValues[index], index })
+ onDataPointClick({
+ x: xValues[index],
+ index,
+ xValue: chartXValues?.[index],
+ })
}
eventRectsGroup.addEventListener('mousemove', handleMouseMove)
@@ -131,16 +142,33 @@ export const attachDataPointClickHandlers = (
export const getChartPointWindow = ({
x,
+ xValue,
timeBucket,
timezone,
timeFormat,
}: {
x: Date
+ xValue?: string
timeBucket: string
timezone: string
timeFormat: string
}) => {
- const date = dayjs(x).tz(timezone)
+ const chartDate = dayjs(x)
+ let wallTime = chartDate.format('YYYY-MM-DD HH:mm:ss')
+
+ if (xValue) {
+ wallTime = xValue
+ }
+
+ if (timeBucket === 'year') {
+ wallTime = `${wallTime.slice(0, 4)}-01-01 00:00:00`
+ } else if (timeBucket === 'month') {
+ wallTime = `${wallTime.slice(0, 7)}-01 00:00:00`
+ } else if (timeBucket === 'day') {
+ wallTime = `${wallTime.slice(0, 10)} 00:00:00`
+ }
+
+ const date = dayjs.tz(wallTime, timezone)
switch (timeBucket) {
case 'minute':
diff --git a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx b/web/app/pages/Project/tabs/Errors/ErrorsView.tsx
index 27a66b6de..1913c8190 100644
--- a/web/app/pages/Project/tabs/Errors/ErrorsView.tsx
+++ b/web/app/pages/Project/tabs/Errors/ErrorsView.tsx
@@ -195,7 +195,11 @@ const getErrorTrendsChartSettings = (
onclick: onDataPointClick
? (d: any) => {
if (d?.x) {
- onDataPointClick({ x: d.x, index: d.index })
+ onDataPointClick({
+ x: d.x,
+ index: d.index,
+ xValue: chartData.x?.[d.index],
+ })
}
}
: undefined,
@@ -306,7 +310,12 @@ const getErrorTrendsChartSettings = (
},
onrendered: onDataPointClick
? function (this: any) {
- attachDataPointClickHandlers(this, columns, onDataPointClick)
+ attachDataPointClickHandlers(
+ this,
+ columns,
+ onDataPointClick,
+ chartData.x,
+ )
}
: undefined,
}
@@ -854,10 +863,11 @@ const ErrorsViewInner = ({ deferredData }: ErrorsViewInnerProps) => {
}, [t, errorOptions])
const handleOverviewDataPointClick = useCallback(
- (d: { x: Date; index: number }) => {
+ (d: { x: Date; index: number; xValue?: string }) => {
setSessionsDrawer(
getChartPointWindow({
x: d.x,
+ xValue: d.xValue,
timeBucket,
timezone,
timeFormat,
@@ -868,12 +878,13 @@ const ErrorsViewInner = ({ deferredData }: ErrorsViewInnerProps) => {
)
const handleActiveErrorDataPointClick = useCallback(
- (d: { x: Date; index: number }) => {
+ (d: { x: Date; index: number; xValue?: string }) => {
if (!activeError?.details.eid) return
setSessionsDrawer({
...getChartPointWindow({
x: d.x,
+ xValue: d.xValue,
timeBucket: activeError.timeBucket || timeBucket,
timezone,
timeFormat,
diff --git a/web/app/pages/Project/tabs/Goals/GoalsView.tsx b/web/app/pages/Project/tabs/Goals/GoalsView.tsx
index c11e2e2a7..efca5471d 100644
--- a/web/app/pages/Project/tabs/Goals/GoalsView.tsx
+++ b/web/app/pages/Project/tabs/Goals/GoalsView.tsx
@@ -61,6 +61,7 @@ import { SessionsDrawer } from '~/pages/Project/tabs/Traffic/SessionsDrawer'
import {
attachDataPointClickHandlers,
getChartPointWindow,
+ type ChartDataPoint,
type ChartDataPointClick,
} from '~/pages/Project/View/utils/chartPoint'
import { useCurrentProject } from '~/providers/CurrentProjectProvider'
@@ -303,7 +304,11 @@ const getGoalChartSettings = (
onclick: onDataPointClick
? (d: any) => {
if (d?.x) {
- onDataPointClick({ x: d.x, index: d.index })
+ onDataPointClick({
+ x: d.x,
+ index: d.index,
+ xValue: chartData.x?.[d.index],
+ })
}
}
: undefined,
@@ -426,7 +431,12 @@ const getGoalChartSettings = (
},
onrendered: onDataPointClick
? function (this: any) {
- attachDataPointClickHandlers(this, columns, onDataPointClick)
+ attachDataPointClickHandlers(
+ this,
+ columns,
+ onDataPointClick,
+ chartData.x,
+ )
}
: undefined,
}
@@ -444,7 +454,7 @@ interface GoalRowProps {
onDelete: (id: string) => void
onEdit: (id: string) => void
onToggleExpand: (id: string) => void
- onChartDataPointClick: (goalId: string, d: { x: Date; index: number }) => void
+ onChartDataPointClick: (goalId: string, d: ChartDataPoint) => void
}
const GoalRow = ({
@@ -1001,10 +1011,11 @@ const GoalsViewInner = ({
}
const handleChartDataPointClick = useCallback(
- (goalId: string, d: { x: Date; index: number }) => {
+ (goalId: string, d: { x: Date; index: number; xValue?: string }) => {
setSessionsDrawer({
...getChartPointWindow({
x: d.x,
+ xValue: d.xValue,
timeBucket,
timezone,
timeFormat,
diff --git a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
index 46b052c75..4491a9948 100644
--- a/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
+++ b/web/app/pages/Project/tabs/Performance/PerformanceView.tsx
@@ -270,10 +270,11 @@ const PerformanceViewInner = ({
}, [deferredData.perfOverallCompareStats, id])
const handleDataPointClick = useCallback(
- (d: { x: Date; index: number }) => {
+ (d: { x: Date; index: number; xValue?: string }) => {
setSessionsDrawer(
getChartPointWindow({
x: d.x,
+ xValue: d.xValue,
timeBucket,
timezone,
timeFormat,
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx b/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
index 85d9f6b07..aaef310b1 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficChart.tsx
@@ -3,6 +3,7 @@ import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { Annotation } from '~/lib/models/Project'
+import type { ChartDataPointClick } from '~/pages/Project/View/utils/chartPoint'
import { MainChart } from '../../View/components/MainChart'
import { getSettings } from '../../View/ViewProject.helpers'
@@ -24,7 +25,7 @@ interface TrafficChartProps {
annotations?: Annotation[]
period?: string
timezone?: string
- onDataPointClick?: (d: { x: Date; index: number }) => void
+ onDataPointClick?: ChartDataPointClick
}
export const TrafficChart = ({
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index 018d0a358..5d63f2a57 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -341,10 +341,11 @@ const TrafficViewInner = ({
} | null>(null)
const handleDataPointClick = useCallback(
- (d: { x: Date; index: number }) => {
+ (d: { x: Date; index: number; xValue?: string }) => {
setSessionsDrawer(
getChartPointWindow({
x: d.x,
+ xValue: d.xValue,
timeBucket,
timezone,
timeFormat,