'use client' import { Bar, BarChart, CartesianGrid, LabelList, XAxis, ResponsiveContainer, Tooltip } from 'recharts' import { BarChartIcon } from '@ciphera-net/ui' import type { GoalCountStat } from '@/lib/api/stats' interface ScrollDepthProps { goalCounts: GoalCountStat[] totalPageviews: number } const THRESHOLDS = [25, 50, 75, 100] as const export default function ScrollDepth({ goalCounts, totalPageviews }: ScrollDepthProps) { const scrollCounts = new Map() for (const row of goalCounts) { const match = row.event_name.match(/^scroll_(\d+)$/) if (match) { scrollCounts.set(Number(match[1]), row.count) } } const hasData = scrollCounts.size > 0 && totalPageviews > 0 const chartData = THRESHOLDS.map((threshold) => ({ label: `${threshold}%`, value: totalPageviews > 0 ? Math.round(((scrollCounts.get(threshold) ?? 0) / totalPageviews) * 100) : 0, })) return (

Scroll Depth

% of visitors who scrolled this far

{hasData ? (
[`${value}%`, 'Reached']} /> `${v}%`} />
) : (

No scroll data yet

Scroll depth tracking is automatic — data will appear here once visitors start scrolling on your pages.

)}
) }