Skip to content

Comments

include MAU, goals & errors into reports#453

Merged
Blaumaus merged 4 commits intoswetrix-revampfrom
new-reports
Dec 14, 2025
Merged

include MAU, goals & errors into reports#453
Blaumaus merged 4 commits intoswetrix-revampfrom
new-reports

Conversation

@Blaumaus
Copy link
Member

@Blaumaus Blaumaus commented Dec 14, 2025

Changes

Community Edition support

  • Your feature is implemented for the Swetrix Community Edition
  • This PR only updates the Cloud (Enterprise) Edition code (e.g. Paddle webhooks, blog, payouts, etc.)

Database migrations

  • Clickhouse / MySQL migrations added for this PR
  • No table schemas changed in this PR

Documentation

  • You have updated the documentation according to your PR
  • This PR did not change any publicly documented endpoints

Summary by CodeRabbit

  • New Features
    • Enhanced project report template with improved layout featuring per-project cards displaying core metrics: Active Users, Unique Visitors, Pageviews, Average Session Duration, and Bounce Rate.
    • Added Goals section showing goal conversions and conversion rates.
    • Added Errors section displaying error statistics.
    • Introduced Top Country display in project reports.
    • Added Tip block and Unsubscribe section to reports.

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

@Blaumaus Blaumaus self-assigned this Dec 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

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

Walkthrough

This PR introduces report generation capabilities for analytics by adding new helper methods to AnalyticsService for fetching summary data in report format, top countries, and error counts; integrating goal-conversion analytics into TaskManagerService; and redesigning the project report email template with per-project cards displaying metrics, goals, and error information.

Changes

Cohort / File(s) Summary
Analytics Service Methods
backend/apps/cloud/src/analytics/analytics.service.ts
Added three new public methods: convertSummaryToReportFormat() converts summary data into report-ready format with pageviews, visitors, and metrics; getTopCountryForReport() queries top country for a time window; getErrorCountForReport() fetches total and unique error counts.
Utilities
backend/apps/cloud/src/common/utils.ts
Added formatDuration() utility to convert seconds (number, null, or undefined) into human-readable duration strings (e.g., "2h 15m", "45s").
Task Manager Integration
backend/apps/cloud/src/task-manager/task-manager.module.ts
Imported GoalModule and added it to module imports.
Task Manager Service
backend/apps/cloud/src/task-manager/task-manager.service.ts
Added GoalService dependency; introduced private helpers buildGoalMatchCondition() and getGoalConversionsForReport() for goal analytics; refactored report data assembly to include top country, error stats, and goal conversions; updated to use new convertSummaryToReportFormat() method.
Report Email Template
backend/apps/cloud/src/common/templates/en/project-report.html
Redesigned template with per-project card layout; added primary metrics grid (Active Users, Unique Visitors, Pageviews) with change indicators; added secondary metrics (Avg. Session Duration, Bounce Rate); introduced conditional Goals and Errors sections; reorganized spacing and separators.

Sequence Diagram

sequenceDiagram
    participant TM as TaskManager<br/>Service
    participant AS as Analytics<br/>Service
    participant GS as Goal<br/>Service
    participant DB as Database
    
    rect rgb(220, 240, 255)
    Note over TM,DB: Report Generation Flow
    end
    
    TM->>AS: convertSummaryToReportFormat(summary)
    AS->>AS: Format metrics + duration
    AS-->>TM: Formatted report data
    
    loop For each project
        TM->>AS: getTopCountryForReport(pid, groupFrom, groupTo)
        AS->>DB: Query analytics by country
        DB-->>AS: Country data
        AS-->>TM: Top country
        
        TM->>AS: getErrorCountForReport(pid, groupFrom, groupTo)
        AS->>DB: Query error analytics
        DB-->>AS: Error counts
        AS-->>TM: Error stats
        
        TM->>GS: getGoalConversionsForReport(goal, pid, groupFrom, groupTo)
        GS->>DB: Query goal conversions
        DB-->>GS: Conversion data
        GS-->>TM: Conversion metrics
    end
    
    TM->>TM: Assemble complete report data
    TM-->>TM: Return enriched project objects
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Task Manager Service: Goal integration logic and refactored report data assembly with multiple new helpers requiring careful review of conversion rate calculations and conditional data inclusion
  • Analytics Service: New database query methods that must correctly aggregate data across time windows
  • Report Template: Significant HTML restructuring with multiple conditional sections and metrics grids that require verification of proper rendering and data binding
  • Integration Points: Verify correct flow between TaskManager, AnalyticsService, and GoalService for complete report generation

Possibly Related PRs

  • feat: Feature flags #450: Modifies AnalyticsService with changes to session recording and aggregated output fields (profileId/isIdentified), overlapping in the analytics service codebase with this PR's new reporting methods.

Poem

🐰 A report card in the making,
With goals and errors, data shaking,
Countries tallied, durations bright,
Per-project metrics, what a sight!
Analytics blooming, templates new,
Hop along, the reports break through!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description addresses most required sections with specific checkboxes marked appropriately, but the 'Changes' section lacks detail—it only references an issue link rather than describing what was actually implemented. Expand the 'Changes' section to explicitly describe the implementation details beyond the issue link, such as the new methods added, template updates, and specific features introduced.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding MAU (Monthly Active Users), goals, and errors into reports, which aligns with the modifications to analytics service methods and report template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@Blaumaus
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
backend/apps/cloud/src/common/templates/en/project-report.html (1)

73-76: Email-client rendering risk (Outlook) with rounded cards / margins.
Outlook often ignores border-radius and margin on tables—acceptable, but ensure it still reads well without them.

backend/apps/cloud/src/analytics/analytics.service.ts (1)

1522-1574: Prefer a typed “report DTO” instead of any for the email/template contract.
This reduces accidental undefined in templates (e.g., percChangeUsers, avgDuration).

backend/apps/cloud/src/task-manager/task-manager.service.ts (1)

334-393: Avoid 2 ClickHouse queries per goal (N projects × M goals × recipients).
At minimum, fetch totalSessions once per project+window and reuse for all goals; ideally batch goal conversions per project.

Also applies to: 469-509, 593-633

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4a1cd and 18b135f.

📒 Files selected for processing (5)
  • backend/apps/cloud/src/analytics/analytics.service.ts (2 hunks)
  • backend/apps/cloud/src/common/templates/en/project-report.html (2 hunks)
  • backend/apps/cloud/src/common/utils.ts (1 hunks)
  • backend/apps/cloud/src/task-manager/task-manager.module.ts (2 hunks)
  • backend/apps/cloud/src/task-manager/task-manager.service.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
backend/apps/cloud/src/analytics/analytics.service.ts (2)
backend/apps/cloud/src/analytics/interfaces/index.ts (1)
  • IOverall (169-171)
backend/apps/cloud/src/common/utils.ts (2)
  • calculateRelativePercentage (148-162)
  • formatDuration (330-356)
backend/apps/cloud/src/task-manager/task-manager.service.ts (2)
web/app/api/index.ts (1)
  • Goal (1232-1242)
backend/apps/cloud/src/common/utils.ts (1)
  • getRandomTip (83-85)
🔇 Additional comments (3)
backend/apps/cloud/src/common/templates/en/project-report.html (1)

87-94: “Top country” likely shows ISO code, not a human label.
Template prints {{topCountry}}; current backend appears to pass cc (e.g., “US”). If you want “United States”, map before templating.

backend/apps/cloud/src/analytics/analytics.service.ts (1)

1576-1631: Time-range consistency: these helpers assume caller passes the same window as summary metrics.
Given email reports compute summary via period but extra queries take explicit groupFrom/groupTo, it’s easy to drift (timezone / inclusivity).

backend/apps/cloud/src/task-manager/task-manager.module.ts (1)

17-34: No circular module dependency detected. GoalModule does not import TaskManagerModule or any module that imports it, so the forwardRef wrapper is not necessary. The one-way dependency from TaskManagerModule to GoalModule is safe.

Likely an incorrect or invalid review comment.

@Blaumaus Blaumaus merged commit 959c67f into swetrix-revamp Dec 14, 2025
2 checks passed
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