feat: implement real campaign statistics in AutomationService.getWorkflowStats - #1092
Merged
RUKAYAT-CODER merged 4 commits intoJul 26, 2026
Merged
Conversation
…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
Contributor
|
Thank you for contributing to the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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