Skip to content

[Simple Analytics] Subscriber Change Over Time Chart & Mailchimp API Integration#206

Open
iamdharmesh wants to merge 11 commits intofeature/data-layer-and-form-event-trackingfrom
feature/200
Open

[Simple Analytics] Subscriber Change Over Time Chart & Mailchimp API Integration#206
iamdharmesh wants to merge 11 commits intofeature/data-layer-and-form-event-trackingfrom
feature/200

Conversation

@iamdharmesh
Copy link
Copy Markdown
Collaborator

Description of the Change

The PR adds a Subscriber change over time section on the Analytics admin page, a diverging bar chart (new subscribers vs unsubscribes) and a totals doughnut with net change, driven by the Mailchimp Marketing API lists/{list_id}/activity endpoint. The section loads on the existing mailchimp-analytics-refresh event so it stays independent from KPIs and Form Performance section failures in this request do not block other analytics UI.

Screenshot 2026-04-20 at 1 09 50 PM

Technical Details:

Backend:

  • New Mailchimp_Subscriber_Activity class (includes/class-mailchimp-subscriber-activity.php): admin AJAX action mailchimp_sf_get_subscriber_activity, capability check (MCSF_CAP_THRESHOLD), nonce (mailchimp_sf_analytics_admin_nonce), and validated list_id / date_from / date_to (Y-m-d).
  • Fetches raw activity (180-day API window), normalizes to daily series, then filters to the requested range intersected with the last 180 days (site timezone). Returns limited: true when the selected span exceeds what Mailchimp can supply so the UI can show an info notice.
  • Bucket interval follows the plan: daily (≤30d), weekly ISO Mon–Sun (31–90d), monthly (91d–1y).
  • Transient cache (15 minutes) on successful raw responses only; key scoped by list (mailchimp_sf_subscriber_activity_ + hash) so one cache entry serves many date-range requests.
  • Registered and init()’d from mailchimp.php next to existing analytics classes.

Frontend:

  • includes/admin/templates/analytics.php: new card markup for the section (title, date subtitle, notice, chart + totals, loading/error/empty states). Strings use the mailchimp text domain.
  • assets/js/analytics.js: subscribes to filter refresh, POSTs to admin-ajax.php, renders Chart.js bar (diverging: positive new subs, negative unsubs) and doughnut for range totals; handles empty, error, and limited-range notice.
  • assets/css/analytics.scss (and built dist/ assets via npm run build): layout (chart + totals column), legend, notice/error/loading states, responsive behavior.

Closes #200

How to test the Change

  1. Go to Mailchimp > Analytics.
  2. Ensure the "Subscriber Change Over Time" graph is displayed, including both bar and doughnut charts.
  3. Verify that changing the list and date presets (e.g., 7 / 30 / 90 / 180 / 365 / custom) refreshes the graph, and that buckets and labels match the aggregation rules.
  4. Select a longer date range (>180 days) and confirm that a limitation notice is shown and only ~180 days of data are displayed in the bars.
  5. Ensure the section shows the correct loading state.
  6. Confirm that an appropriate error message is displayed in case of API failure (e.g., disconnected account or invalid credentials).
  7. Check responsiveness and cross-browser compatibility.

Changelog Entry

Added - Subscriber Change Over Time chart to the Analytics page.

Credits

Props @iamdharmesh @builtbytay April Domingo Cameron Campbell

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@iamdharmesh iamdharmesh self-assigned this Apr 20, 2026
@iamdharmesh iamdharmesh added this to the 2.1.0 milestone Apr 20, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new “Subscriber change over time” analytics section (bar + doughnut charts) backed by a new admin AJAX endpoint that fetches Mailchimp list activity and aggregates it for charting.

Changes:

  • Register a new backend data provider (Mailchimp_Subscriber_Activity) and hook an admin AJAX action for subscriber activity.
  • Add new Analytics admin template markup for the subscriber activity card (states, charts, totals).
  • Extend the analytics JS/CSS to fetch and render the diverging bar chart + totals doughnut, and update styling via SCSS.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
mailchimp.php Boots the new subscriber activity provider class.
includes/class-mailchimp-subscriber-activity.php New AJAX endpoint + caching + date-range filtering/aggregation for Mailchimp activity data.
includes/admin/templates/analytics.php Adds subscriber activity section markup; adjusts deep link button styling.
assets/js/analytics.js Adds subscriber activity module (Chart.js rendering) and introduces WP i18n usage.
assets/css/analytics.scss New SCSS-based styling for analytics page and subscriber activity card.
assets/css/analytics.css Removes the previously committed compiled CSS source file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/class-mailchimp-subscriber-activity.php
Comment thread includes/admin/templates/analytics.php
Comment thread assets/js/analytics.js
Comment thread includes/admin/templates/analytics.php Outdated
@iamdharmesh iamdharmesh requested a review from Copilot April 20, 2026 08:34
@iamdharmesh iamdharmesh marked this pull request as ready for review April 20, 2026 08:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread includes/class-mailchimp-subscriber-activity.php
Comment thread includes/class-mailchimp-analytics.php Outdated
@iamdharmesh iamdharmesh requested a review from alaca April 20, 2026 08:42
Copy link
Copy Markdown
Collaborator

@alaca alaca left a comment

Choose a reason for hiding this comment

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

Looks good 👍

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.

[Simple Analytics] Subscriber Change Over Time Chart & Mailchimp API Integration

3 participants