PhoenixKit.Emails.Metrics (phoenix_kit v1.6.15)

View Source

Local metrics and analytics for PhoenixKit email tracking.

This module provides comprehensive metrics collection and analysis capabilities for email performance, deliverability, and engagement tracking using the local database.

Features

  • Engagement Analysis: Open rates, click rates, and engagement trends
  • Geographic Analytics: Performance by region and country
  • Provider Analysis: Deliverability by email provider (Gmail, Outlook, etc.)
  • Campaign Performance: Top performing campaigns and templates
  • Real-time Dashboards: Data for live monitoring dashboards
  • Time Series Data: Historical trends and patterns

Usage Examples

# Get engagement metrics
engagement = PhoenixKit.Emails.Metrics.get_engagement_metrics(:last_7_days)

# Get geographic distribution
geo = PhoenixKit.Emails.Metrics.get_geographic_metrics(:last_30_days)

# Get dashboard data
dashboard = PhoenixKit.Emails.Metrics.get_dashboard_data(:last_30_days)

Summary

Functions

Gets comprehensive dashboard data combining multiple metric sources.

Gets engagement metrics with trend analysis.

Gets geographic distribution of email engagement.

Checks metrics against thresholds and returns alerts.

Functions

get_dashboard_data(period \\ :last_7_days)

Gets comprehensive dashboard data combining multiple metric sources.

Returns data optimized for dashboard visualization with time series, percentages, trends, and alerts.

Examples

iex> PhoenixKit.Emails.Metrics.get_dashboard_data(:last_7_days)
%{
  overview: %{
    total_sent: 5000,
    delivery_rate: 98.2,
    bounce_rate: 1.8,
    open_rate: 24.5,
    click_rate: 4.2
  },
  time_series: [...],
  alerts: [...],
  top_performers: [...]
}

get_engagement_metrics(period \\ :last_7_days)

Gets engagement metrics with trend analysis.

Examples

iex> PhoenixKit.Emails.Metrics.get_engagement_metrics(:last_7_days)
%{
  open_rate: 24.5,
  click_rate: 4.2,
  engagement_score: 28.7,
  trend: :improving,
  daily_breakdown: [...]
}

get_geographic_metrics(event_type, period \\ :last_30_days)

Gets geographic distribution of email engagement.

Examples

iex> PhoenixKit.Emails.Metrics.get_geographic_metrics("open", :last_30_days)
%{
  "US" => %{count: 500, percentage: 45.5},
  "CA" => %{count: 200, percentage: 18.2},
  "UK" => %{count: 150, percentage: 13.6}
}

get_metric_alerts(period \\ :last_24_hours)

Checks metrics against thresholds and returns alerts.

Examples

iex> PhoenixKit.Emails.Metrics.get_metric_alerts(:last_24_hours)
[
  %{type: :high_bounce_rate, severity: :warning, value: 5.2, threshold: 5.0},
  %{type: :low_open_rate, severity: :info, value: 15.1, threshold: 20.0}
]