Skip to content

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

Open
iamdharmesh wants to merge 13 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 13 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 👍

@ankitguptaindia
Copy link
Copy Markdown
Collaborator

QA Status: Needs Feedback ❓

Hi @iamdharmesh,

Thanks for working on this—overall, it works as per the defined scope. I have a few questions and observations related to the chart data and UI:

  1. Data refresh interval:
    Is there any specific time interval for updating the chart data?
    Currently, I have 3 subscribers in the Mailchimp list, but the chart is showing only 1. Is there a delay or sync interval for reflecting updated data in WordPress?
image image
  1. Unsubscribes count delay:
    Similarly, the “Unsubscribes” count also seems to take time to update in the chart. Could you confirm if this is expected or we can improve this to show real time data?

  1. UI issue – text clipping:
    Text like “days” is getting cut off due to a fixed height.
    If height: 36px; is removed and set to auto, the UI appears correct. Can we adjust this to prevent character clipping (e.g., for letters like “y”)?
image
  1. Icon color consistency:
    Can we align the colors for the “Subscribers” and “Unsubscribers” icons for better visual consistency?
image

Next Step: Moving back to In-Progress for feedback.

@iamdharmesh
Copy link
Copy Markdown
Collaborator Author

iamdharmesh commented Apr 30, 2026

Thanks for testing this @ankitguptaindia.

  1. Data refresh interval:
    Is there any specific time interval for updating the chart data?

Yes, we are using transient caching which expires after every 15 mins. So, you will get updated data in 15 mins.

  1. UI issue – text clipping:

Done. Thanks.

  1. Icon color consistency:

Done. Thanks

@ankitguptaindia
Copy link
Copy Markdown
Collaborator

QA Status: Approved ✅

Test Summary

  • Feature: “Subscriber Change Over Time” analytics section (diverging bar chart + totals doughnut) on Mailchimp > Analytics.
  • Status: Passed. Functionality works as expected in testing, and QA feedback has been addressed.

Test Scenarios and Results

1. Basic rendering

  • Opened Mailchimp > Analytics.
  • Verified the “Subscriber Change Over Time” card renders with: title, date subtitle, bar chart, doughnut chart, legend, totals, and loading/empty/error states.
  • Result: Pass. UI elements display correctly and use the mailchimp text domain. ✅

2. List and date filters

  • Changed list selector and presets: 7 / 30 / 90 / 180 / 365 days and custom ranges.
  • Verified charts refresh on mailchimp-analytics-refresh, bucket logic (daily ≤30d, weekly 31–90d, monthly 91d–1y), and labels match the aggregation rule.
  • Result: Pass. Bucketing and label behavior match the described technical details. ✅

3. 180‑day data limitation

  • Selected a date range >180 days.
  • Verified that only ~180 days of data is shown, and the limitation notice appears.
  • Result: Pass. Mailchimp API window constraint is clearly communicated in the UI. ✅

4. Loading, error, and empty states

  • Observed the loading state while data is fetched via admin-ajax.php.
  • Simulated failure (e.g., disconnected account) and verified that a page is not appearing.
  • Tested a list with no recent activity and confirmed the empty state is shown.
  • Result: Pass. All states behave as expected. ✅

5. Data freshness and caching

  • Verified updated subscriber and unsubscribe counts appear after cache expiry (expected delay up to 15 minutes).
  • Result: Pass. Behavior aligns with the documented 15‑minute refresh interval, and QA’s question on delayed counts is explained by this cache.

6. UI/UX fixes from QA feedback

From QA feedback by @ankitguptaindia, the following items were raised and addressed:

  • Text clipping (“days” truncated due to fixed height):
    • Fix applied (removal/adjustment of height: 36px; to prevent character clipping).
    • Result: Pass. No clipping observed after the fix. ✅
  • Icon color consistency between “Subscribers” and “Unsubscribers”:
    • Colors updated for consistent visual appearance.
    • Result: Pass. Icons now use aligned colors. ✅
  • Chart color adjustment:
    • Commit “Chart color fix” ensures diverging bar and doughnut colors follow the intended palette.
    • Result: Pass. Colors are consistent and distinguishable. ✅

QA feedback on these points is marked as Done by the author in the latest comment.

6. Cross‑browser and responsive

  • Checked the new card layout and charts for responsiveness and basic cross‑browser behaviour.
  • Result: Pass. Layout remains usable and visually consistent at common breakpoints. ✅

Known/Expected Behaviours

  • Data is not strictly real‑time due to the 15‑minute transient cache; subscribers and unsubscribers will update after cache expiry. This is expected behaviour, as confirmed by the author.

Final QA Status

  • Overall Result: Passed.
  • QA feedback: Addressed (data freshness clarified; UI clipping fixed; icon and chart colors updated).
  • Recommendation: Ready to proceed with the merge.
Screenshot 2026-04-30 at 9 16 30 PM

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

4 participants