Skip to content

feat: add campaign performance benchmarking analytics and recommendat…#451

Open
Mohitmhatre32 wants to merge 2 commits into
Kuldeeep18:mainfrom
Mohitmhatre32:feature/lo-069-benchmarking-analytics
Open

feat: add campaign performance benchmarking analytics and recommendat…#451
Mohitmhatre32 wants to merge 2 commits into
Kuldeeep18:mainfrom
Mohitmhatre32:feature/lo-069-benchmarking-analytics

Conversation

@Mohitmhatre32

@Mohitmhatre32 Mohitmhatre32 commented Jun 24, 2026

Copy link
Copy Markdown

Pull Request

🔗 Related Issue

Closes #406

📝 Summary of Changes

  • Backend (backend/campaigns/views.py):
    • Enhanced DashboardAnalyticsView response payload to return standard industry benchmarks (open_rate: 20.0 and reply_rate: 5.0) within a new benchmarks dictionary structure.
  • Backend Tests (backend/campaigns/tests.py):
    • Added test assertions to CampaignWorkflowTests to verify tenant data isolation and that the benchmark values are correctly returned.
  • Frontend Dashboard (frontend/analytics.html):
    • Added a new glassmorphism-styled Performance Insights & Recommendations section below the KPI grid.
    • Dynamically renders comparison cards for Open Rate and Reply Rate against industry benchmarks:
      • If campaign rates fall below benchmarks, a warning card using native --paused-bg / --paused-fg colors displays actionable advice (personalizing subject lines, using dynamic fields like {{first_name}}, shortening copy, refining Call-to-Actions).
      • If metrics meet or exceed benchmarks, an encouraging success card using --active-bg / --active-fg is shown.
    • Overhauled the Campaign Performance chart:
      • Switched from displaying raw counts to displaying rate percentages (Open Rate % and Reply Rate %) to make benchmarking comparisons meaningful.
      • Overlayed dashed horizontal benchmark comparison lines on the chart (red for 20% Open Rate and purple for 5% Reply Rate).
      • Updated tooltips and Y-axis to format data as percentages.

🏷️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor
  • 📝 Documentation update
  • 🎨 UI / Style change
  • 🔧 Chore

🧪 Testing

Steps to test:

  1. Start the Django backend local development server:
    python manage.py runserver
  2. Start the local HTTP server inside the frontend directory:
    python -m http.server 8080
  3. Run the backend analytics test suite using the virtual environment python:
    python manage.py test campaigns.tests.CampaignWorkflowTests.test_dashboard_analytics_isolates_data_by_tenant campaigns.tests.CampaignWorkflowTests.test_dashboard_analytics_requires_authentication
  4. Log into the local instance and navigate to the Analytics Console (/analytics.html). Verify that the Performance Insights & Recommendations card loads correctly, displays proper comparative values (e.g. 0% vs 20%), has readable contrast, and that the Campaign Performance chart displays open/reply rate bars alongside dashed benchmark reference lines.

📸 Screenshots (if applicable)

(Please attach screenshots of the Analytics dashboard here)
image
image

✅ Checklist

  • No merge conflicts
  • Changes follow the project guidelines
  • Documentation updated (if applicable)
  • Related issue linked
  • Changes tested locally (if applicable)

Summary by CodeRabbit

  • New Features
    • Added a “Performance Insights & Recommendations” panel to the Analytics page.
    • Introduced benchmark-based guidance for open and reply rates, with recommendations shown when performance is below target.
    • Updated the campaign performance chart to display open rate (%) and reply rate (%) with benchmark reference lines.
  • Bug Fixes
    • Dashboard analytics responses now consistently include benchmark metrics, keeping insights synchronized across views.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The dashboard analytics API now returns benchmark rates for open and reply performance. The analytics page renders benchmark recommendations, updates them on time-range changes, and charts open and reply rates with benchmark overlays. Tests cover the new benchmark data under tenant isolation.

Changes

Campaign Performance Benchmarking Analytics

Layer / File(s) Summary
Backend benchmark payload and tenant-isolation tests
backend/campaigns/views.py, backend/campaigns/tests.py
DashboardAnalyticsView.get appends a benchmarks object with constant open_rate: 20.0 and reply_rate: 5.0 to its response. The tenant-isolation test asserts this field is present with correct values for both tenants.
Insights panel and benchmark recommendations
frontend/analytics.html
Adds a hidden “Performance Insights & Recommendations” panel, extends analytics defaults with benchmark fallback values, and introduces updateBenchmarkInsights() to compare current open and reply rates against benchmark thresholds and render recommendation cards. The time-range change handler calls the insights update after reload.
Campaign Performance chart rates and benchmark overlays
frontend/analytics.html
renderCampaignPerformanceChart() switches the Campaign Performance chart from raw counts to open-rate and reply-rate percentages, adds dashed benchmark lines for both metrics, and updates tooltip and axis labeling to display percentages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hop hop, the benchmarks are in sight,
Open and reply rates now compare just right.
Charts go dashed, and insights glow,
Helping campaign stats tell what they know.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: campaign performance benchmarking analytics and recommendations.
Linked Issues check ✅ Passed The backend adds benchmark values and the frontend shows benchmark lines plus recommendations, matching issue #406.
Out of Scope Changes check ✅ Passed The added frontend and backend changes stay within campaign analytics benchmarking and recommendation scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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

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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/analytics.html`:
- Around line 518-525: The Y-axis in the chart config still displays raw numeric
ticks, so update the existing y scale configuration to format tick labels as
percentages as well. Add a tick callback within the chart options around the
y-axis setup in the analytics chart so the axis labeling matches the
percentage-based tooltip and the “Percentage (%)” title.
- Around line 279-369: The benchmark insights in updateBenchmarkInsights
currently treat missing volume as zero, so empty campaigns render false “below
benchmark” warnings. Add a guard in updateBenchmarkInsights that checks
emails_sent (or equivalent sent volume) before building openHTML and replyHTML,
and when it is 0 or absent, either hide benchmark-insights-section or render a
neutral empty state instead of the warning cards.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d0ca5f50-b3b7-4146-9b2d-85935ecbb285

📥 Commits

Reviewing files that changed from the base of the PR and between 4a33158 and ae5a060.

📒 Files selected for processing (4)
  • .gitignore
  • backend/campaigns/tests.py
  • backend/campaigns/views.py
  • frontend/analytics.html

Comment thread frontend/analytics.html
Comment thread frontend/analytics.html
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.

LO-069 [Advanced]: Campaign Performance Benchmarking Analytics

1 participant