Skip to content

[Simple Analytics] Audience Overview KPI block#209

Open
alaca wants to merge 11 commits intofeature/form-performance-chartfrom
feature/audience-overview
Open

[Simple Analytics] Audience Overview KPI block#209
alaca wants to merge 11 commits intofeature/form-performance-chartfrom
feature/audience-overview

Conversation

@alaca
Copy link
Copy Markdown
Collaborator

@alaca alaca commented Apr 28, 2026

Description of the Change

This PR adds the Audience Overview KPI block.

image

How to test the Change

Go to: WP Admin -> MailChimp -> Analytics

Changelog Entry

Added - Audience Overview KPI block on the Analytics admin page, showing Total subscribers (via Mailchimp API), Form views, New submissions, and Conversion rate for the selected list and date range.

Credits

Props @alaca

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.

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 an “Audience Overview” KPI card to the Mailchimp → Analytics admin page, combining Mailchimp list subscriber totals with local form analytics totals for the selected list and date range.

Changes:

  • Adds a new admin-only AJAX endpoint/data provider (Mailchimp_Audience_Overview) to return KPI totals (subscribers, views, submissions, conversion rate).
  • Refactors conversion_rate() into the shared analytics bucketing trait for reuse.
  • Adds the KPI card UI + client-side fetching/rendering logic and styles.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
mailchimp.php Boots the new Audience Overview data provider during plugin init.
includes/trait-mailchimp-analytics-bucketing.php Adds shared conversion_rate() helper for multiple analytics providers.
includes/class-mailchimp-form-performance.php Removes local conversion_rate() implementation in favor of the shared trait method.
includes/class-mailchimp-audience-overview.php New AJAX handler + cached Mailchimp API fetch for total subscribers, plus local totals aggregation.
includes/admin/templates/analytics.php Adds Audience Overview KPI card markup (metrics + error banner).
assets/js/analytics.js Adds a new module to fetch/render the Audience Overview KPIs and handle loading/error/retry.
assets/css/analytics.scss Adds styling for the Audience Overview KPI card and its error banner.

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

Comment thread includes/class-mailchimp-audience-overview.php Outdated
Comment on lines +100 to +113
/**
* Submissions ÷ views
*
* @param int $submissions Submission count.
* @param int $views View count.
* @return float
*/
protected function conversion_rate( int $submissions, int $views ): float {
if ( $views <= 0 ) {
return 0.0;
}
$rate = ( $submissions / $views ) * 100;
return round( min( 100.0, $rate ), 2 );
}
Comment thread assets/js/analytics.js
Comment on lines +1165 to +1172
/**
* Audience Overview KPI block
*/
(function audienceOverviewModule() {
const section = document.querySelector('[data-section="audience-overview"]');
if (!section) {
return;
}
Comment thread assets/js/analytics.js Outdated
Comment thread includes/class-mailchimp-audience-overview.php Outdated
Copy link
Copy Markdown
Collaborator

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @alaca. Added some feedback to check, Copilot has added some feedback as well. could you please check once?

Comment thread includes/class-mailchimp-audience-overview.php Outdated
Comment thread assets/js/analytics.js Outdated
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 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +101 to +102
1,
array( 'stats.member_count' )
Comment thread assets/js/analytics.js
Comment on lines +1188 to +1195
/**
* Audience Overview KPI block
*/
(function audienceOverviewModule() {
const section = document.querySelector('[data-section="audience-overview"]');
if (!section) {
return;
}
Copy link
Copy Markdown
Collaborator

@iamdharmesh iamdharmesh left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @alaca. The code changes looks good to me.

However, there are some open copilot items mostly regarding update doc comment and E2E tests, could you please check once? As those are not a blocker I am approving the PR.

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.

4 participants