Skip to content

feat: implement real campaign statistics in AutomationService.getWorkflowStats - #1092

Merged
RUKAYAT-CODER merged 4 commits into
rinafcode:mainfrom
Meet-hybrid:feat/real-workflow-stats
Jul 26, 2026
Merged

feat: implement real campaign statistics in AutomationService.getWorkflowStats#1092
RUKAYAT-CODER merged 4 commits into
rinafcode:mainfrom
Meet-hybrid:feat/real-workflow-stats

Conversation

@Meet-hybrid

@Meet-hybrid Meet-hybrid commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Description
Implement real campaign statistics in AutomationService.getWorkflowStats. The current method returns hardcoded values (emailsSent: 0, openRate: 0, clickRate: 0) alongside two real fields, which misleads marketers into thinking workflows are broken rather than missing instrumentation.

Problem
Email send, open, and click counts are not computed from actual events.

The dashboard shows zero values for active workflows, creating confusion.

There is no distinction between “no data yet” and “zero performance.”

The method still carries a // TODO marker, leaving functionality incomplete.

Solution
Aggregate sends, opens, and clicks per workflow from delivery events captured by email-webhook.controller.ts.

Compute open and click rates as ratios over delivered messages, with division‑by‑zero safeguards.

Return null instead of 0 for statistics that cannot yet be computed, and document this distinction in the response type.

Add an index to support efficient per‑workflow event aggregation.

Remove the TODO and add tests covering workflows with and without recorded events.

Impacted Files
src/email-marketing/automation/automation.service.ts

src/email-marketing/email-webhook.controller.ts

Acceptance Criteria
✅ A workflow that has sent email reports a non‑zero send count.
✅ Open and click rates are computed from real events.
✅ Missing data is reported as null, not 0.
✅ No TODO remains in the method.
✅ Tests confirm correct behavior for workflows with and without events.

Closes #1038

…flowStats

- Add workflowId and metadata (jsonb) columns to EmailEvent entity with composite index
- Extract workflowId from SendGrid custom_args in webhook controller
- Inject EmailEvent repository into AutomationService for per-workflow aggregation
- Compute emailsSent, openRate, and clickRate from recorded delivery events
- Return null for email stats when no instrumentation data exists (not 0)
- Guard division by zero when computing open/click rates
- Pass workflowId in SEND_AUTOMATION_EMAIL and email worker job payloads
- Remove TODO and add JSDoc documenting the null semantics
- Add tests covering workflows with and without recorded events

closes rinafcode#1038
@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 1d3b1c9 into rinafcode:main Jul 26, 2026
1 check 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.

Implement real campaign statistics in AutomationService.getWorkflowStats

2 participants