Skip to content

Returning#763

Merged
goldflag merged 5 commits intomasterfrom
returning
Dec 9, 2025
Merged

Returning#763
goldflag merged 5 commits intomasterfrom
returning

Conversation

@goldflag
Copy link
Copy Markdown
Collaborator

@goldflag goldflag commented Dec 9, 2025

Summary by CodeRabbit

  • New Features

    • Added user breakdown toggle to view new vs returning users separately in analytics
    • Extended analytics metrics to include sessions, pages per session, bounce rate, and session duration
    • Enhanced chart visualizations with improved data series rendering and tooltips
  • Improvements

    • Dynamic chart stacking adapts when user breakdown is enabled
    • Refined tooltip display with per-series color coding and contextual information

✏️ Tip: You can customize this high-level summary in your review settings.

…nality

- Adjusted layout in MainSection to enhance alignment and spacing of elements.
- Changed button variant for user split toggle to 'ghost' for better visual consistency.
- Wrapped BucketSelection component in a div for improved styling and layout.
- Introduced a new `useChartData` hook to encapsulate chart data logic, enhancing code reusability.
- Simplified the `Chart` component by delegating data processing to the new hook.
- Cleaned up unnecessary calculations and improved readability of the chart data mapping in `PreviousChart` component.
… visualization

- Reintroduced the 'returning_users' series in the Chart component with updated color settings based on user breakdown.
- Adjusted color settings in PreviousChart to enhance visual consistency across themes.
- Ensured that the series configuration reflects the correct data keys and colors for better clarity in user statistics.
@vercel
Copy link
Copy Markdown

vercel bot commented Dec 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
rybbit Building Building Preview Comment Dec 9, 2025 4:46am

@goldflag goldflag merged commit ce9f7e0 into master Dec 9, 2025
5 of 7 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This PR extends the analytics API to track new vs. returning users and refactors the dashboard chart components to support conditional multi-series visualization. It adds new_users and returning_users fields to the overview API response, implements server-side user segmentation logic, and provides UI controls to toggle between single and multi-series breakdown views.

Changes

Cohort / File(s) Summary
API Type Extensions
client/src/api/analytics/endpoints/overview.ts
Added new_users: number and returning_users: number fields to GetOverviewBucketedResponse items; minor formatting cleanup in fetchOverview and fetchLiveUserCount.
Chart Component Refactoring
client/src/app/[site]/main/components/MainSection/Chart.tsx
Introduced time-bucket utilities (BUCKET_MINUTES_OFFSET, getBucketMinutesOffset); added SERIES_LABELS and SeriesConfig types; created useChartData hook for multi-series data generation with current/previous values; refactored rendering with createStackedLines and createDashedOverlay helpers; replaced inline tooltip with componentized ChartSliceTooltip; updated axis/label formatting for time modes and theme support.
New Chart Tooltip Component
client/src/app/[site]/main/components/MainSection/ChartSliceTooltip.tsx
Introduced new React component rendering contextual tooltips for single-series (value diffs, percentages) and multi-series modes (new vs returning users); exported SeriesConfig, SeriesDataPoint, SeriesData types; implemented formatTooltipValue utility and theme-aware color styling for tooltip rows.
User Breakdown Feature UI
client/src/app/[site]/main/components/MainSection/MainSection.tsx
Added showUserBreakdown state logic; introduced toggle button with icon and tooltip for switching between single/split user views; updated max value calculation to sum new_users and returning_users during breakdown; adjusted layout structure and header controls.
Previous Chart Multi-Series Support
client/src/app/[site]/main/components/MainSection/PreviousChart.tsx
Replaced single-series data with multi-series support driven by showUsersSplit; introduced seriesConfig and colorMap for per-series handling; refactored chartData construction to map series per configuration; added yScale stacking behavior conditional on user breakdown.
Card Component Styling
client/src/components/ui/card.tsx
Added overflow-hidden and pointer-events-none to CardLoader wrapper for improved visual containment and interaction handling.
Store State Extension
client/src/lib/store.ts
Added showUsersSplit boolean flag and setShowUsersSplit setter to Store interface; initialized to false in default state; integrated reset flow.
Server-Side User Segmentation
server/src/api/analytics/getOverviewBucketed.ts
Introduced UserFirstVisits and EventsWithFirstVisit CTEs for per-user first-visit tracking; refactored page-level aggregation to compute new_users and returning_users via uniqExactIf conditions on first_visit_bucket; extended response shape to include sessions, pages_per_session, bounce_rate, session_duration, users, new_users, returning_users.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • server/src/api/analytics/getOverviewBucketed.ts: Review server-side CTEs and new_users/returning_users aggregation logic for SQL correctness and edge cases in first-visit bucket computation.
  • client/src/app/[site]/main/components/MainSection/Chart.tsx: Validate useChartData hook logic, multi-series data mapping, and coordinate transformation between API response shape and chart rendering.
  • client/src/app/[site]/main/components/MainSection/ChartSliceTooltip.tsx: Verify tooltip diff and percentage calculations for both single and multi-series modes, and color/theme resolution logic.
  • Integration across MainSection, Chart, and PreviousChart: Ensure showUserBreakdown state flows correctly and that max value calculations handle summing for breakdown mode without data inconsistencies.

Possibly related PRs

Poem

🐰 A rabbit hops through analytics bright,
Tracking new users and returning folk,
Multi-series charts now paint insight,
With toggles that make dashboards bespoke!
First visits segmented with SQL cheer,
The breakdown view is crystal clear! 📊✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch returning

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between beec0eb and 535082f.

📒 Files selected for processing (8)
  • client/src/api/analytics/endpoints/overview.ts (3 hunks)
  • client/src/app/[site]/main/components/MainSection/Chart.tsx (6 hunks)
  • client/src/app/[site]/main/components/MainSection/ChartSliceTooltip.tsx (1 hunks)
  • client/src/app/[site]/main/components/MainSection/MainSection.tsx (5 hunks)
  • client/src/app/[site]/main/components/MainSection/PreviousChart.tsx (4 hunks)
  • client/src/components/ui/card.tsx (1 hunks)
  • client/src/lib/store.ts (3 hunks)
  • server/src/api/analytics/getOverviewBucketed.ts (4 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant