Skip to content

feat: emails.metrics() for account-level email metrics - #1042

Merged
dielduarte merged 7 commits into
preview-headless-dashboardfrom
emails-metrics
Aug 5, 2026
Merged

feat: emails.metrics() for account-level email metrics#1042
dielduarte merged 7 commits into
preview-headless-dashboardfrom
emails-metrics

Conversation

@dielduarte

@dielduarte dielduarte commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds emails.metrics() to retrieve account-level email metrics: counts and rates for sent, delivered, opened, clicked, bounced, etc., optionally broken down by period and/or domain.
  • Supports startDate/endDate range, timezone, granularity (hourly/daily/weekly), a metrics allowlist, dimensions breakdown, and filter.domainId.
  • totals and each data row are typed as a partial record over the possible metric keys, since the set of metrics present depends on what was requested.

Based on resend-docs#1686.

Test plan

  • emails.spec.ts covers metrics() with no options, with date range/metrics/dimensions/filter, and an error response
  • Full emails.spec.ts suite passes (27 tests)

Summary by cubic

Adds resend.emails.metrics() to fetch account-level email metrics with date range, timezone, granularity, breakdowns, filters, and flexible sorting (by date or any metric). Returns typed totals and optional rows; response echoes resolved sort_by/sort_order.

  • New Features

    • New resend.emails.metrics(options?) for /emails/metrics.
    • Options: startDate/endDate, timezone, granularity (hourly|daily|weekly), metrics, dimensions (period|domain|email), filter.domainId, filter.emailId, sortBy (date or any metric, including engagement and rate), sortOrder (asc|desc).
  • Bug Fixes

    • sortBy: 'date' works when dimensions includes period (alone or with domain/email).
    • Query builder omits empty metrics/dimensions, serializes timezone/granularity, and is simplified; get-metrics types exported from emails/interfaces.

Written for commit 5873b0e. Summary will update on new commits.

Review in cubic

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/resend@1042

commit: 5873b0e

@cubic-dev-ai cubic-dev-ai 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.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/emails/interfaces/get-metrics.interface.ts
Comment thread src/emails/emails.spec.ts
Comment thread src/emails/emails.spec.ts

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 1 file (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 3 unresolved issues from previous reviews.

Re-trigger cubic

dielduarte added a commit that referenced this pull request Aug 3, 2026
Also cover timezone/granularity serialization in the metrics options
test, per cubic review on #1042.

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.

Re-trigger cubic

@dielduarte
dielduarte marked this pull request as ready for review August 3, 2026 16:42
@dielduarte
dielduarte requested a review from a team as a code owner August 3, 2026 16:42
@dielduarte
dielduarte requested review from cassiozen and removed request for a team August 3, 2026 16:42
@github-actions github-actions Bot added the linear-synced PR has been synced to Linear label Aug 4, 2026

@cubic-dev-ai cubic-dev-ai 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.

0 issues found across 3 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: This adds a new public SDK method and exported request/response types for a new API endpoint, expanding the package's public contract surface. A human should approve the added method, parameter mapping, and types before release.

Re-trigger cubic

@klotty klotty left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Adds a new API wrapper method that delegates to the backend endpoint; no existing behavior changed, no operational or security tradeoff visible in the diff.

Re-trigger cubic

dielduarte added a commit that referenced this pull request Aug 5, 2026
Also cover timezone/granularity serialization in the metrics options
test, per cubic review on #1042.
@dielduarte
dielduarte force-pushed the preview-headless-dashboard branch from 10e0dc9 to e50c36b Compare August 5, 2026 17:18
dielduarte added a commit that referenced this pull request Aug 5, 2026
Also cover timezone/granularity serialization in the metrics options
test, per cubic review on #1042.
@dielduarte
dielduarte force-pushed the preview-headless-dashboard branch from e50c36b to afc19ce Compare August 5, 2026 17:29
Seven near-identical if-blocks reduced to one key/value map filtered
in a single loop.
Also cover timezone/granularity serialization in the metrics options
test, per cubic review on #1042.
…cs()

Mirrors the domain dimension/filter. Keeps the SDK in sync with the
emails/metrics endpoint's new per-email breakdown.
- sortBy: 'date' for a period breakdown, or a count/derived metric
  (received, delivered, ..., sent) for a domain-only or email-only
  breakdown.
- sortOrder: 'asc' | 'desc', defaults to 'asc' for a period breakdown
  and 'desc' otherwise.
- Response now echoes the resolved sort_by/sort_order.
- Also omit empty metrics/dimensions arrays from the query string,
  same fix as segments.metrics().

Based on resend-monorepo#7814.
Corrects the doc comment and adds a test: sortBy='date' requires
dimensions to include 'period', not be exactly ['period'] — it also
works for a period+domain or period+email breakdown.

Based on the latest resend-monorepo#7814 commit that fixed this same
gap server-side.
…rived

The API now supports sorting a domain/email breakdown by engagement
metrics (unique_opened, unique_clicked) and rate metrics (open_rate,
bounce_rate, etc.), not just the count/derived ones. Widens
EmailMetricsSortBy from the narrower SortableEmailMetric subset to
EmailMetric directly, since every metric is sortable now - some via the
Tinybird pipe, some client-side, but that's an API implementation detail
the SDK type doesn't need to encode.
@dielduarte
dielduarte merged commit c884b70 into preview-headless-dashboard Aug 5, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge linear-synced PR has been synced to Linear

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants