Skip to content

Commit a59c5a9

Browse files
committed
compute variations stats from sent instead of delivered
1 parent bd46349 commit a59c5a9

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

internal/domain/broadcast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,12 @@ func (r *GetTestResultsRequest) FromURLParams(values url.Values) error {
805805
type VariationResult struct {
806806
TemplateID string `json:"template_id"`
807807
TemplateName string `json:"template_name"`
808-
Recipients int `json:"recipients"`
809-
Delivered int `json:"delivered"`
808+
Recipients int `json:"recipients"` // Total sent emails (used as denominator for rate calculations)
809+
Delivered int `json:"delivered"` // Total delivered emails (ESP-dependent, may not be available)
810810
Opens int `json:"opens"`
811811
Clicks int `json:"clicks"`
812-
OpenRate float64 `json:"open_rate"`
813-
ClickRate float64 `json:"click_rate"`
812+
OpenRate float64 `json:"open_rate"` // Opens / Recipients
813+
ClickRate float64 `json:"click_rate"` // Clicks / Recipients
814814
}
815815

816816
// TestResultsResponse represents the response for A/B test results

internal/service/broadcast_service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -966,15 +966,15 @@ func (s *BroadcastService) GetTestResults(ctx context.Context, workspaceID, broa
966966
// Calculate rates (avoid division by zero)
967967
openRate := 0.0
968968
clickRate := 0.0
969-
if stats.TotalDelivered > 0 {
970-
openRate = float64(stats.TotalOpened) / float64(stats.TotalDelivered)
971-
clickRate = float64(stats.TotalClicked) / float64(stats.TotalDelivered)
969+
if stats.TotalSent > 0 {
970+
openRate = float64(stats.TotalOpened) / float64(stats.TotalSent)
971+
clickRate = float64(stats.TotalClicked) / float64(stats.TotalSent)
972972
}
973973

974974
variationResults[variation.TemplateID] = &domain.VariationResult{
975975
TemplateID: variation.TemplateID,
976976
TemplateName: "Template " + variation.TemplateID, // Could fetch actual template name
977-
Recipients: stats.TotalSent,
977+
Recipients: stats.TotalSent, // Use sent as recipients to match rate calculation denominator
978978
Delivered: stats.TotalDelivered,
979979
Opens: stats.TotalOpened,
980980
Clicks: stats.TotalClicked,

0 commit comments

Comments
 (0)