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!

Code hardening

Blue Mouse3c65051d09de
diff --git a/backend/apps/cloud/src/analytics/analytics.controller.ts b/backend/apps/cloud/src/analytics/analytics.controller.ts
index 62336fa09..2b8b5c323 100644
--- a/backend/apps/cloud/src/analytics/analytics.controller.ts
+++ b/backend/apps/cloud/src/analytics/analytics.controller.ts
@@ -459,10 +459,14 @@ export class AnalyticsController {
)
})(),
(async () => {
- stepDetails = await this.analyticsService.getFunnelStepDetails(
- pagesArr,
- params,
- )
+ try {
+ stepDetails = await this.analyticsService.getFunnelStepDetails(
+ pagesArr,
+ params,
+ )
+ } catch (e) {
+ this.logger.error(e, 'GET /analytics/funnel - getFunnelStepDetails')
+ }
})(),
]
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 8a6b72743..39964e33d 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -183,6 +183,10 @@ export const isValidDate = (date: string, format = 'YYYY-MM-DD'): boolean => {
return false
}
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(date)) {
+ return dayjs(date).isValid()
+ }
+
return dayjs(date, format).format(format) === date
}
diff --git a/backend/apps/community/src/analytics/analytics.controller.ts b/backend/apps/community/src/analytics/analytics.controller.ts
index 8de4bab52..337e76791 100644
--- a/backend/apps/community/src/analytics/analytics.controller.ts
+++ b/backend/apps/community/src/analytics/analytics.controller.ts
@@ -447,10 +447,14 @@ export class AnalyticsController {
)
})(),
(async () => {
- stepDetails = await this.analyticsService.getFunnelStepDetails(
- pagesArr,
- params,
- )
+ try {
+ stepDetails = await this.analyticsService.getFunnelStepDetails(
+ pagesArr,
+ params,
+ )
+ } catch (e) {
+ this.logger.error(e, 'GET /analytics/funnel - getFunnelStepDetails')
+ }
})(),
]
diff --git a/backend/apps/community/src/analytics/analytics.service.ts b/backend/apps/community/src/analytics/analytics.service.ts
index 069bb4af7..894a72616 100644
--- a/backend/apps/community/src/analytics/analytics.service.ts
+++ b/backend/apps/community/src/analytics/analytics.service.ts
@@ -176,6 +176,10 @@ export const isValidDate = (date: string, format = 'YYYY-MM-DD'): boolean => {
return false
}
+ if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(date)) {
+ return dayjs(date).isValid()
+ }
+
return dayjs(date, format).format(format) === date
}
diff --git a/web/app/pages/Project/View/ViewProject.helpers.tsx b/web/app/pages/Project/View/ViewProject.helpers.tsx
index cd1126f42..fa81d03a9 100644
--- a/web/app/pages/Project/View/ViewProject.helpers.tsx
+++ b/web/app/pages/Project/View/ViewProject.helpers.tsx
@@ -722,8 +722,6 @@ const getSettings = (
}
}
: undefined,
- onover: undefined,
- onout: undefined,
types: {
unique: chartType === chartTypes.line ? area() : bar(),
uniqueCompare: chartType === chartTypes.line ? line() : bar(),
@@ -1140,14 +1138,35 @@ const getSettings = (
const target = e.target as SVGRectElement
if (!target?.classList?.contains('bb-event-rect')) return
- const rects =
- eventRectsGroup.querySelectorAll('.bb-event-rect')
- const index = Array.from(rects).indexOf(target)
- if (index === -1) return
+ const groupRect = eventRectsGroup.getBoundingClientRect()
+ const mouseX = e.clientX - groupRect.left
+ const mouseY = e.clientY - groupRect.top
- const xs = chartInstance.data.xs()
- const xValues = Object.values(xs)[0] as Date[] | undefined
- if (!xValues || index >= xValues.length) return
+ const circles = svg.querySelectorAll('.bb-circle')
+ let closestCircle: Element | null = null
+ let minDistance = Infinity
+
+ circles.forEach((c: Element) => {
+ const cx = parseFloat(c.getAttribute('cx') || '0')
+ const cy = parseFloat(c.getAttribute('cy') || '0')
+ const distance = Math.hypot(cx - mouseX, cy - mouseY)
+
+ if (distance < minDistance) {
+ minDistance = distance
+ closestCircle = c
+ }
+ })
+
+ if (!closestCircle) return
+ const circle = closestCircle as Element
+
+ const classAttr = circle.getAttribute('class') || ''
+ const indexMatch = classAttr.match(/bb-circle-(\d+)/)
+ if (!indexMatch) return
+ const index = parseInt(indexMatch[1], 10)
+
+ const xValues = columns[0].slice(1) as Date[]
+ if (index >= xValues.length) return
onDataPointClick({ x: xValues[index], index })
})
diff --git a/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx b/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
index d7de2ee38..08bd70fd7 100644
--- a/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
+++ b/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
@@ -1,4 +1,4 @@
-import { XIcon, UsersIcon } from '@phosphor-icons/react'
+import { XIcon, UsersIcon, WarningCircleIcon } from '@phosphor-icons/react'
import _map from 'lodash/map'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
@@ -36,11 +36,19 @@ async function fetchSessionsPage(
signal,
})
- if (!response.ok) return null
+ if (!response.ok) {
+ throw new Error(`Request failed with status ${response.status}`)
+ }
const result = (await response.json()) as {
data: SessionsResponse | null
+ error: string | null
+ }
+
+ if (result.error) {
+ throw new Error(result.error)
}
+
return result.data
}
@@ -74,13 +82,18 @@ export const SessionsDrawer = ({
const [hasMore, setHasMore] = useState(true)
const [initialLoading, setInitialLoading] = useState(true)
const [loadingMore, setLoadingMore] = useState(false)
+ const [error, setError] = useState<string | null>(null)
const sentinelRef = useRef<HTMLDivElement>(null)
const scrollContainerRef = useRef<HTMLDivElement>(null)
const loadingRef = useRef(false)
const abortControllerRef = useRef<AbortController | null>(null)
const loadSessions = useCallback(
- async (currentSkip: number, append: boolean, signal?: AbortSignal) => {
+ async (
+ currentSkip: number,
+ append: boolean,
+ signal?: AbortSignal,
+ ): Promise<boolean> => {
let result: SessionsResponse | null = null
try {
@@ -97,11 +110,19 @@ export const SessionsDrawer = ({
},
signal,
)
- } catch {
- return
+ } catch (e) {
+ if (signal?.aborted) return false
+ setError(
+ e instanceof Error
+ ? e.message
+ : t('apiNotifications.somethingWentWrong'),
+ )
+ return false
}
- if (signal?.aborted) return
+ if (signal?.aborted) return false
+
+ setError(null)
if (result) {
const newSessions = result.sessions ?? []
@@ -112,8 +133,10 @@ export const SessionsDrawer = ({
}
setHasMore(newSessions.length >= SESSIONS_TAKE)
}
+
+ return true
},
- [projectId, from, to, timezone, stableFilters],
+ [projectId, from, to, timezone, stableFilters, t],
)
useEffect(() => {
@@ -127,6 +150,7 @@ export const SessionsDrawer = ({
setSessions([])
setSkip(0)
setHasMore(true)
+ setError(null)
// Delay fetching slightly to allow the drawer animation to run smoothly without layout shifts
const timer = setTimeout(() => {
@@ -150,8 +174,14 @@ export const SessionsDrawer = ({
try {
const nextSkip = skip + SESSIONS_TAKE
- setSkip(nextSkip)
- await loadSessions(nextSkip, true, abortControllerRef.current?.signal)
+ const success = await loadSessions(
+ nextSkip,
+ true,
+ abortControllerRef.current?.signal,
+ )
+ if (success) {
+ setSkip(nextSkip)
+ }
} finally {
loadingRef.current = false
setLoadingMore(false)
@@ -224,6 +254,16 @@ export const SessionsDrawer = ({
<div className='flex items-center justify-center py-16'>
<Loader />
</div>
+ ) : error && sessions.length === 0 ? (
+ <div className='flex flex-col items-center justify-center py-16 text-center'>
+ <WarningCircleIcon
+ className='size-10 text-red-400 dark:text-red-500'
+ weight='duotone'
+ />
+ <span className='mt-3 text-sm text-gray-500 dark:text-gray-400'>
+ {error}
+ </span>
+ </div>
) : sessions.length === 0 ? (
<div className='flex flex-col items-center justify-center py-16 text-center'>
<UsersIcon
diff --git a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
index bd7f75817..161649efa 100644
--- a/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
+++ b/web/app/pages/Project/tabs/Traffic/TrafficView.tsx
@@ -341,6 +341,7 @@ const TrafficViewInner = ({
const handleDataPointClick = useCallback(
(d: { x: Date; index: number }) => {
+ console.log('handleDataPointClick:', d)
const date = dayjs(d.x).tz(timezone)
let from: string
let to: string
diff --git a/web/app/routes/api.analytics.ts b/web/app/routes/api.analytics.ts
index e46a187cb..a11b55750 100644
--- a/web/app/routes/api.analytics.ts
+++ b/web/app/routes/api.analytics.ts
@@ -75,21 +75,17 @@ import { getProjectPasswordCookie } from '~/utils/session.server'
function formatDateForBackend(dateStr: string | undefined): string | undefined {
if (!dateStr) return undefined
- // If already in YYYY-MM-DD format, return as-is
if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) {
return dateStr
}
- // Convert ISO 8601 or other formats to YYYY-MM-DD
+ // Preserve full ISO 8601 timestamps so the backend can use precise time bounds
const date = new Date(dateStr)
- if (Number.isNaN(date.getTime())) {
+ if (!Number.isNaN(date.getTime())) {
return dateStr
}
- const yyyy = date.getUTCFullYear()
- const mm = String(date.getUTCMonth() + 1).padStart(2, '0')
- const dd = String(date.getUTCDate()).padStart(2, '0')
- return `${yyyy}-${mm}-${dd}`
+ return dateStr
}
interface ProxyRequest {