[Simple Analytics] Audience Overview KPI block#209
[Simple Analytics] Audience Overview KPI block#209alaca wants to merge 11 commits intofeature/form-performance-chartfrom
Conversation
There was a problem hiding this comment.
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.
| /** | ||
| * 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 ); | ||
| } |
| /** | ||
| * Audience Overview KPI block | ||
| */ | ||
| (function audienceOverviewModule() { | ||
| const section = document.querySelector('[data-section="audience-overview"]'); | ||
| if (!section) { | ||
| return; | ||
| } |
iamdharmesh
left a comment
There was a problem hiding this comment.
Thanks for the PR @alaca. Added some feedback to check, Copilot has added some feedback as well. could you please check once?
| 1, | ||
| array( 'stats.member_count' ) |
| /** | ||
| * Audience Overview KPI block | ||
| */ | ||
| (function audienceOverviewModule() { | ||
| const section = document.querySelector('[data-section="audience-overview"]'); | ||
| if (!section) { | ||
| return; | ||
| } |
iamdharmesh
left a comment
There was a problem hiding this comment.
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.
Description of the Change
This PR adds the Audience Overview KPI block.
How to test the Change
Go to: WP Admin -> MailChimp -> Analytics
Changelog Entry
Credits
Props @alaca
Checklist: