Skip to content

revenue improvements#373

Open
Sahil-Gupta584 wants to merge 2 commits intodatabuddy-analytics:mainfrom
Sahil-Gupta584:main
Open

revenue improvements#373
Sahil-Gupta584 wants to merge 2 commits intodatabuddy-analytics:mainfrom
Sahil-Gupta584:main

Conversation

@Sahil-Gupta584
Copy link
Copy Markdown
Contributor

@Sahil-Gupta584 Sahil-Gupta584 commented Apr 2, 2026

  • updated revenue cards
  • fixed granularity
  • update stripe link for quick access
image

Thinking of adding more payment providers support,
adding revenue bars on traffic trends graph of dashbaord, user can optionally render that. will be cool feat for taking ss

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c89af4f6-b0cf-4cae-ae59-afbf456a2f36

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

@Sahil-Gupta584 is attempting to deploy a commit to the Databuddy OSS Team on Vercel.

A member of the Team first needs to authorize it.

@vercel vercel bot temporarily deployed to Preview – documentation April 2, 2026 17:07 Inactive
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 2, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
documentation Skipped Skipped Apr 2, 2026 5:24pm

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 2, 2026

Greptile Summary

This PR improves the revenue dashboard by adding hourly granularity support, timezone-aware ClickHouse queries, a new "Total Revenue" stat card (replacing the Transactions card), a visitor-based conversion rate card, an improved Stripe webhook link, and dual Y-axes on the revenue chart.

Key changes and issues found:

  • P1 – Debug log in production: console.log({overview,visitors}) at line 742 of revenue-content.tsx was left in and will pollute browser consoles.
  • P1 – Duplicate "revenue" metric: A second "revenue" entry was appended to REVENUE_METRICS in revenue-chart.tsx, resulting in two overlapping Area chart lines and a duplicate legend item.
  • P1 – Conversion rate can exceed 100%: The conversion rate is calculated as total_transactions / visitors, but total_transactions is not deduplicated per customer. A customer making multiple purchases inflates this above 100%. unique_customers / visitors is the correct numerator.
  • P2 – Missing trailing newline: All three changed files are missing a newline at end of file, which is flagged by most linters and formatters.

Confidence Score: 2/5

Not safe to merge — two P1 logic bugs (duplicate chart metric and incorrect conversion rate formula) plus a debug log need to be fixed first.

The duplicate "revenue" metric in REVENUE_METRICS will visually break the chart with two overlapping lines and a duplicate legend entry. The conversion rate will incorrectly show values above 100% for customers with multiple transactions. A debug console.log is also committed to production code. These are straightforward fixes but must be addressed before merging.

revenue-chart.tsx (duplicate metric), revenue-content.tsx (console.log + conversion rate formula)

Important Files Changed

Filename Overview
apps/api/src/query/builders/revenue.ts Rewrites revenue_overview and revenue_time_series builders to support timezone-aware queries and hourly granularity; adds a visitors CTE via CROSS JOIN for the new conversion rate card; adds meta blocks for both; missing trailing newline.
apps/dashboard/app/(main)/websites/[id]/revenue/_components/revenue-chart.tsx Adds hourly date formatting, dual Y-axes (currency vs count), and granularity prop; critically introduces a duplicate "revenue" entry in REVENUE_METRICS that will render two overlapping chart lines.
apps/dashboard/app/(main)/websites/[id]/revenue/_components/revenue-content.tsx Replaces Transactions stat card with Total Revenue, adds a conversion rate card using total_transactions/visitors (can exceed 100%), improves padTimeSeriesData for granularity support, upgrades Stripe webhook link, and leaves a debug console.log in production code.

Sequence Diagram

sequenceDiagram
    participant UI as RevenueContent
    participant API as revenue_overview query
    participant CH as ClickHouse

    UI->>API: fetch(revenue_overview, {websiteId, startDate, endDate, timezone})
    API->>CH: WITH revenue_attributed CTE + visitors CTE
    CH-->>API: {total_revenue, total_transactions, unique_customers, ..., total_visitors}
    API-->>UI: RevenueOverview[]

    UI->>UI: compute visitors = overview.total_visitors
    UI->>UI: compute conversionRate = (total_transactions / visitors) * 100
    Note over UI: Should be unique_customers / visitors

    UI->>API: fetch(revenue_time_series, {websiteId, startDate, endDate, timezone, granularity})
    API->>CH: WITH base_revenue → revenue_agg (hour/day bucket)
    CH-->>API: [{date, revenue, transactions, customers, ...}]
    API-->>UI: RevenueTimeSeries[]

    UI->>UI: padTimeSeriesData(data, start, end, defaults, granularity)
    UI->>UI: map → chartData (revenue, transactions, avg_transaction, customers, refunds)
    UI->>RevenueChart: data={chartData} granularity={dateRange.granularity}
    Note over RevenueChart: revenue key rendered twice (duplicate metric)
Loading

Reviews (1): Last reviewed commit: "revenue improvements" | Re-trigger Greptile

timeField: "created",
customizable: true,
plugins: {
normalizeGeo: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing newline at end of file

All three modified files (revenue.ts, revenue-chart.tsx, revenue-content.tsx) are missing a trailing newline. Most formatters and linters (and git itself) treat this as an error. Please add a newline after the closing };.

@vercel vercel bot temporarily deployed to Preview – documentation April 2, 2026 17:24 Inactive
@sekhar08
Copy link
Copy Markdown
Contributor

sekhar08 commented Apr 2, 2026

Hey Sahil, I noticed you committed directly to your main branch. For future PRs, could you create a feature branch first? Something like git checkout -b revenue-improvements, Then make your commits there and open the PR from that branch to main. This keeps the main branch clean and makes the history easier to manage. Thanks!

@Sahil-Gupta584
Copy link
Copy Markdown
Contributor Author

Sure , will you review this pr?

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.

2 participants