PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.6.1
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.6.1
1.6.1 1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
← All changes | inc/admin/analytics.php +422 -10 1.2.0 → 1.6.1 View file →
@@ -6,8 +6,11 @@
6 6 */
7 7
8 8 namespace SureDonation\Inc\Admin;
9 9
10 +use SureDonation\Inc\Campaign_Templates\Campaign_Templates;
11 +use SureDonation\Inc\Campaigns\Campaign_Cpt;
12 +use SureDonation\Inc\Emails\Email_Reports;
10 13 use SureDonation\Inc\Helper;
11 14 use SureDonation\Inc\Payments\Offline\Offline_Helper;
12 15 use SureDonation\Inc\Payments\Payment_Helper;
13 16 use SureDonation\Inc\Payments\PayPal\PayPal_Helper;
@@ -28,8 +31,52 @@
28 31 class Analytics {
29 32 use Get_Instance;
30 33
31 34 /**
35 + * Allowlist of React admin-notice / UI analytics events.
36 + *
37 + * Single source of truth for the track-notice-event REST endpoint: the notice
38 + * registrations (Admin::register_react_notices) and the dashboard Quick Access
39 + * item set an event to one of these values, and handle_track_notice_event()
40 + * only records events present here. Add a new event here (and reference it on
41 + * the notice/item) to track it end-to-end.
42 + *
43 + * @var array<string, string>
44 + * @since 1.3.0
45 + */
46 + public const TRACKED_EVENTS = [
47 + 'configure_gateway' => 'configure_gateway_notice_react_cta',
48 + 'webhook' => 'webhook_notice_react_cta',
49 + 'test_mode' => 'test_mode_notice_react_cta',
50 + 'quick_access' => 'quick_access_configure_gateway_react_cta',
51 + // The PayPal settings panel warns when PayPal has told us the connected
52 + // account cannot be paid. The CTA sends the merchant to PayPal to finish
53 + // setup; the dismiss says they saw it and moved on, which is worth
54 + // separating from never having seen it.
55 + 'paypal_account' => 'paypal_account_warning_react_cta',
56 + 'paypal_account_x' => 'paypal_account_warning_react_dismiss',
57 + 'paypal_webhook_x' => 'paypal_webhook_error_react_dismiss',
58 + // The Stripe settings panel warns when Stripe has told us the connected
59 + // account cannot charge cards. The CTA sends the site owner to their
60 + // Stripe dashboard to resolve it; the dismiss says they saw it and moved
61 + // on, which is worth separating from never having seen it.
62 + 'stripe_account' => 'stripe_account_warning_react_cta',
63 + 'stripe_account_x' => 'stripe_account_warning_react_dismiss',
64 + // The form-side capability notices link here with ?sd_notice=, so the
65 + // settings screen records that one of them is what brought the admin
66 + // over. Their own page is a public donation form, which is no place to
67 + // be loading a tracker.
68 + 'stripe_capability' => 'stripe_capability_notice_cta',
69 + // The other three donation-form notices reach the settings screen the
70 + // same way. Their own page is a public donation form, which is no place
71 + // to be loading a tracker, so the CTA carries a marker and the arrival
72 + // is what gets recorded.
73 + 'frontend_test_mode' => 'frontend_test_mode_notice_cta',
74 + 'frontend_gateway_unavailable' => 'frontend_gateway_unavailable_notice_cta',
75 + 'frontend_gateway_setup' => 'frontend_gateway_setup_notice_cta',
76 + ];
77 +
78 + /**
32 79 * BSF_Analytics_Events instance for one-time event tracking.
33 80 *
34 81 * @var \BSF_Analytics_Events|null
35 82 * @since 1.0.0
@@ -60,8 +107,11 @@
60 107 * init priority 10.
61 108 */
62 109 add_action( 'init', [ $this, 'register_entity' ], 0 );
63 110
111 + // REST route the React admin app calls to record notice/UI clicks.
112 + add_action( 'rest_api_init', [ $this, 'register_routes' ] );
113 +
64 114 add_filter( 'bsf_core_stats', [ $this, 'add_suredonation_analytics_data' ] );
65 115
66 116 // Keep analytics sends (and their stat queries) off the frontend.
67 117 add_filter( 'suredonation_tracking_enabled', [ $this, 'restrict_tracking_to_admin' ] );
@@ -68,8 +118,12 @@
68 118
69 119 // Event tracking hooks. Registered outside is_admin() on purpose —
70 120 // onboarding completion and campaign publishes fire during REST requests.
71 121 add_action( 'suredonation_onboarding_user_details_saved', [ $this, 'track_onboarding_completed' ] );
122 + add_action( 'suredonation_campaign_tour_shown', [ $this, 'track_campaign_tour_shown' ] );
123 + add_action( 'suredonation_campaign_tour_outcome', [ $this, 'track_campaign_tour_outcome' ], 10, 2 );
124 + add_action( 'suredonation_campaign_template_picker_opened', [ $this, 'track_campaign_template_picker_opened' ] );
125 + add_action( 'suredonation_campaign_created_from_template', [ $this, 'track_campaign_created_from_template' ] );
72 126 add_action( 'transition_post_status', [ $this, 'track_first_campaign_published' ], 10, 3 );
73 127 add_action( 'current_screen', [ $this, 'track_first_campaign_editor_opened' ] );
74 128 add_action( 'suredonation_privacy_data_exported', [ $this, 'track_privacy_data_exported' ] );
75 129 add_action( 'suredonation_privacy_data_erased', [ $this, 'track_privacy_data_erased' ] );
@@ -169,8 +223,77 @@
169 223 return self::$events;
170 224 }
171 225
172 226 /**
227 + * Register REST routes.
228 + *
229 + * Hooked - rest_api_init
230 + *
231 + * @return void
232 + * @since 1.3.0
233 + */
234 + public function register_routes() {
235 + register_rest_route(
236 + 'suredonation/v1',
237 + '/track-notice-event',
238 + [
239 + 'methods' => \WP_REST_Server::CREATABLE,
240 + 'callback' => [ $this, 'handle_track_notice_event' ],
241 + // A named method rather than a closure: the capability guard in
242 + // tests/unit/inc/test-rest-api.php introspects every write
243 + // route's permission_callback, and a closure is opaque to it.
244 + 'permission_callback' => [ $this, 'check_permissions' ],
245 + 'args' => [
246 + 'event' => [
247 + 'type' => 'string',
248 + 'required' => true,
249 + ],
250 + ],
251 + ]
252 + );
253 + }
254 +
255 + /**
256 + * Whether the current user may record notice events.
257 + *
258 + * Named check_permissions to match the other REST controllers, which is also
259 + * what the write-route capability guard asserts on.
260 + *
261 + * @return bool True when the user can manage options.
262 + * @since 1.4.0
263 + */
264 + public function check_permissions() {
265 + return current_user_can( 'manage_options' );
266 + }
267 +
268 + /**
269 + * Record a React notice/UI interaction event.
270 + *
271 + * Validates the event against an allowlist (so arbitrary events cannot be
272 + * injected) and records it via the shared analytics events, respecting the
273 + * usage-tracking opt-in. Event names are suffixed `_react` to keep them
274 + * distinct from the wp-admin notice events.
275 + *
276 + * @param \WP_REST_Request<array<string, mixed>> $request REST request.
277 + * @return \WP_REST_Response
278 + * @since 1.3.0
279 + */
280 + public function handle_track_notice_event( $request ) {
281 + $event = sanitize_key( (string) $request->get_param( 'event' ) );
282 +
283 + if ( ! in_array( $event, self::TRACKED_EVENTS, true ) ) {
284 + return new \WP_REST_Response( [ 'success' => false ], 400 );
285 + }
286 +
287 + $events = self::events();
288 + if ( null !== $events ) {
289 + $events->track( $event );
290 + }
291 +
292 + return new \WP_REST_Response( [ 'success' => true ], 200 );
293 + }
294 +
295 + /**
173 296 * Callback function to add SureDonation specific analytics data.
174 297 *
175 298 * @param array<string, mixed> $stats_data Existing stats data.
176 299 * @return array<string, mixed>
@@ -187,11 +310,16 @@
187 310 : 'self';
188 311
189 312 $privacy_settings = Privacy_Settings::get_settings();
190 313
314 + $email_reports_settings = Email_Reports::get_settings();
315 +
316 + // Computed once: the headline total below is derived from the same rows.
317 + $template_usage = $this->get_campaign_template_usage();
318 +
191 319 $plugin_data = [
192 - 'free_version' => SUREDONATION_VER,
193 - 'numeric_values' => [
320 + 'free_version' => SUREDONATION_VER,
321 + 'numeric_values' => [
194 322 'total_campaigns' => absint( $campaign_counts->publish ?? 0 ),
195 323 'total_donation_forms' => absint( $form_counts->publish ?? 0 ),
196 324 'total_donations' => $aggregates['total'],
197 325 'completed_donations' => $aggregates['completed'],
@@ -196,11 +324,25 @@
196 324 'total_donations' => $aggregates['total'],
197 325 'completed_donations' => $aggregates['completed'],
198 326 'recurring_donations' => $aggregates['recurring'],
199 327 'total_donors' => $this->get_total_donors(),
328 + 'forms_with_image_block' => $this->get_image_block_form_count(),
200 329 'posts_with_social_sharing_block' => $this->get_social_sharing_block_count(),
330 + 'stripe_accounts_count' => count( Stripe_Helper::get_all_accounts() ),
331 + // Campaigns started from a gallery template — excludes both the
332 + // scratch path and the `general` fallback, so this is the count
333 + // of campaigns that actually adopted a cause template.
334 + 'campaigns_from_template' => array_sum(
335 + array_diff_key(
336 + $template_usage,
337 + [
338 + 'scratch' => 0,
339 + Campaign_Templates::GENERAL => 0,
340 + ]
341 + )
342 + ),
201 343 ],
202 - 'boolean_values' => [
344 + 'boolean_values' => [
203 345 'stripe_enabled' => Stripe_Helper::is_stripe_connected(),
204 346 'paypal_enabled' => PayPal_Helper::is_paypal_connected(),
205 347 'offline_enabled' => Offline_Helper::is_offline_enabled(),
206 348 // True only when the OttoKit plugin is active AND authenticated,
@@ -208,14 +350,20 @@
208 350 'ottokit_connected' => Helper::is_suretriggers_ready(),
209 351 'contact_consent_enabled' => ! empty( $privacy_settings['contact_consent_field'] ),
210 352 'privacy_policy_field_enabled' => ! empty( $privacy_settings['privacy_policy_field'] ),
211 353 'terms_field_enabled' => ! empty( $privacy_settings['terms_conditions_field'] ),
354 + // Scheduled sends only go out in live mode, so read this
355 + // against the payment_mode already on the KPI records to tell
356 + // sites actually receiving a report from sites where it is on
357 + // but paused.
358 + 'email_reports_enabled' => ! empty( $email_reports_settings['enabled'] ),
212 359 ],
213 - 'data_retention_period' => isset( $privacy_settings['minimum_data_retention_period'] ) ? Helper::get_string_value( $privacy_settings['minimum_data_retention_period'] ) : 'none',
214 - 'block_usage' => $this->get_block_usage(),
215 - 'elementor_widget_usage' => $this->get_elementor_widget_usage(),
216 - 'bricks_element_usage' => $this->get_bricks_element_usage(),
217 - 'internal_referer' => $internal_referer,
360 + 'data_retention_period' => isset( $privacy_settings['minimum_data_retention_period'] ) ? Helper::get_string_value( $privacy_settings['minimum_data_retention_period'] ) : 'none',
361 + 'block_usage' => $this->get_block_usage(),
362 + 'campaign_template_usage' => $template_usage,
363 + 'elementor_widget_usage' => $this->get_elementor_widget_usage(),
364 + 'bricks_element_usage' => $this->get_bricks_element_usage(),
365 + 'internal_referer' => $internal_referer,
218 366 ];
219 367
220 368 // Add KPI tracking data.
221 369 $kpi_data = $this->get_kpi_tracking_data();
@@ -287,8 +435,118 @@
287 435 );
288 436 }
289 437
290 438 /**
439 + * Track the first time the campaign guided tour is shown to a user.
440 + *
441 + * Fired from the REST layer on the tour's first render. The events tracker
442 + * dedups by name, so this is recorded once per site regardless of how many
443 + * users see the tour or how often it re-triggers.
444 + *
445 + * @return void
446 + * @since 1.5.0
447 + */
448 + public function track_campaign_tour_shown() {
449 + $events = self::events();
450 + if ( null === $events ) {
451 + return;
452 + }
453 +
454 + $events->track( 'campaign_tour_shown' );
455 + }
456 +
457 + /**
458 + * Track how a campaign guided-tour run ended.
459 + *
460 + * `campaign_tour_shown` tells us the tour was seen; these tell us whether it
461 + * worked. Four outcomes, each recorded under its own event name:
462 + *
463 + * - `completed` — the user reached the final step.
464 + * - `dismissed` — closed part-way; the step key rides along as the
465 + * event value so we can see where runs are abandoned.
466 + * - `opted_out` — ticked "Don't show this again".
467 + * - `manual_started` — replayed deliberately via "Take a tour".
468 + *
469 + * `dismissed` is tracked with $force so the most recent drop-off step wins
470 + * rather than only the first one ever recorded on the site; the others keep
471 + * the default once-per-site semantics.
472 + *
473 + * @param string $outcome How the run ended. Unknown values are ignored.
474 + * @param string $step Step key the run ended on. Only used for `dismissed`.
475 + * @return void
476 + * @since 1.5.0
477 + */
478 + public function track_campaign_tour_outcome( $outcome, $step = '' ) {
479 + $events = self::events();
480 + if ( null === $events ) {
481 + return;
482 + }
483 +
484 + $outcome = Helper::get_string_value( $outcome );
485 + $step = Helper::get_string_value( $step );
486 +
487 + switch ( $outcome ) {
488 + case 'completed':
489 + $events->track( 'campaign_tour_completed' );
490 + break;
491 + case 'dismissed':
492 + // Retrackable: the latest abandonment point is the useful one.
493 + $events->track( 'campaign_tour_dismissed', $step, [], true );
494 + break;
495 + case 'opted_out':
496 + $events->track( 'campaign_tour_opted_out', $step );
497 + break;
498 + case 'manual_started':
499 + $events->track( 'campaign_tour_manual_started' );
500 + break;
501 + }
502 + }
503 +
504 + /**
505 + * Track the first time the campaign template picker is opened.
506 + *
507 + * Deduped, so it answers "did this site ever discover the picker?" — the
508 + * denominator for template adoption, since `campaign_template_usage` in the
509 + * stats payload only counts campaigns that were actually created from one.
510 + *
511 + * @return void
512 + * @since 1.5.0
513 + */
514 + public function track_campaign_template_picker_opened() {
515 + $events = self::events();
516 + if ( null === $events ) {
517 + return;
518 + }
519 +
520 + $events->track( 'campaign_template_picker_opened' );
521 + }
522 +
523 + /**
524 + * Track the first campaign a site creates from a template.
525 + *
526 + * Deduped, so the event value is the template the site reached for *first* —
527 + * the running per-template totals live in `campaign_template_usage` on the
528 + * stats payload, which is recomputed on every send.
529 + *
530 + * @param string $template_id Template the campaign was created from.
531 + * @return void
532 + * @since 1.5.0
533 + */
534 + public function track_campaign_created_from_template( $template_id ) {
535 + $events = self::events();
536 + if ( null === $events ) {
537 + return;
538 + }
539 +
540 + $template_id = Helper::get_string_value( $template_id );
541 + if ( '' === $template_id ) {
542 + return;
543 + }
544 +
545 + $events->track( 'first_campaign_from_template', $template_id );
546 + }
547 +
548 + /**
291 549 * Track first personal-data export that included SureDonation data
292 550 * (adoption event — deduped, sent once).
293 551 *
294 552 * @since 1.2.0
@@ -401,8 +659,9 @@
401 659
402 660 $defaults = [
403 661 'total' => 0,
404 662 'completed' => 0,
663 + 'completed_live' => 0,
405 664 'recurring' => 0,
406 665 'anonymous_completed' => 0,
407 666 'fees_covered_completed' => 0,
408 667 'refunded' => 0,
@@ -412,8 +671,9 @@
412 671 $row = $wpdb->get_row(
413 672 $wpdb->prepare(
414 673 "SELECT COUNT(*) AS total,
415 674 COALESCE(SUM(payment_status = 'completed'),0) AS completed,
675 + COALESCE(SUM(payment_status = 'completed' AND payment_mode = 'live'),0) AS completed_live,
416 676 COALESCE(SUM(subscription_id IS NOT NULL AND subscription_id <> ''),0) AS recurring,
417 677 COALESCE(SUM(is_anonymous = 1 AND payment_status = 'completed'),0) AS anonymous_completed,
418 678 COALESCE(SUM(fees_covered > 0 AND payment_status = 'completed'),0) AS fees_covered_completed,
419 679 COALESCE(SUM(payment_status IN ('refunded','partially_refunded')),0) AS refunded
@@ -469,8 +729,9 @@
469 729 'campaign_goal' => 'suredonation/campaign-goal',
470 730 'campaign_stats' => 'suredonation/campaign-stats',
471 731 'campaign_donations' => 'suredonation/campaign-donations',
472 732 'campaign_donors' => 'suredonation/campaign-donors',
733 + 'campaign_donor_comments' => 'suredonation/campaign-donor-comments',
473 734 'campaign_donate_button' => 'suredonation/campaign-donate-button',
474 735 'campaign_social_sharing' => 'suredonation/campaign-social-sharing',
475 736 'donation_form' => 'suredonation/donation-form',
476 737 ];
@@ -503,8 +764,81 @@
503 764 return $usage;
504 765 }
505 766
506 767 /**
768 + * How many published campaigns were created from each campaign template.
769 + *
770 + * The running answer to "which template gets used, and how often" — a
771 + * snapshot rather than an event, because the stats payload is rebuilt on
772 + * every send while events dedup by name and fire once per site.
773 + *
774 + * Every known template id is seeded to 0 so the payload keeps the same shape
775 + * across sites (same contract as get_block_usage()). Campaigns with no
776 + * template meta — anything created before templates shipped, or via "Start
777 + * from scratch" — land in `scratch`. Ids that are no longer registered are
778 + * dropped rather than passed through, so a stale or hand-edited meta value
779 + * can never widen the payload.
780 + *
781 + * @return array<string, int> Template id => number of published campaigns.
782 + * @since 1.5.0
783 + */
784 + private function get_campaign_template_usage() {
785 + global $wpdb;
786 +
787 + $registry = Campaign_Templates::get_instance();
788 +
789 + // Seed the known ids, plus the two buckets that are not gallery cards:
790 + // `general` (the built-in fallback) and `scratch` (no meta at all).
791 + $usage = [ 'scratch' => 0 ];
792 + foreach ( $registry->get_all() as $template ) {
793 + $id = Helper::get_string_value( $template['id'] ?? '' );
794 + if ( '' !== $id ) {
795 + $usage[ $id ] = 0;
796 + }
797 + }
798 + $usage[ Campaign_Templates::GENERAL ] = 0;
799 +
800 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Single grouped scan at analytics send time only.
801 + $rows = $wpdb->get_results(
802 + $wpdb->prepare(
803 + 'SELECT pm.meta_value AS template_id, COUNT(*) AS total
804 + FROM %i AS p
805 + LEFT JOIN %i AS pm ON pm.post_id = p.ID AND pm.meta_key = %s
806 + WHERE p.post_type = %s AND p.post_status = %s
807 + GROUP BY pm.meta_value',
808 + $wpdb->posts,
809 + $wpdb->postmeta,
810 + Campaign_Cpt::META_TEMPLATE_ID,
811 + SUREDONATION_POST_TYPE,
812 + 'publish'
813 + ),
814 + ARRAY_A
815 + );
816 +
817 + if ( ! is_array( $rows ) ) {
818 + return $usage;
819 + }
820 +
821 + foreach ( $rows as $row ) {
822 + $id = Helper::get_string_value( $row['template_id'] ?? '' );
823 + $total = absint( $row['total'] ?? 0 );
824 +
825 + // No meta (NULL from the LEFT JOIN, or an empty string) => scratch.
826 + if ( '' === $id ) {
827 + $usage['scratch'] += $total;
828 + continue;
829 + }
830 +
831 + // Only report ids we still recognise.
832 + if ( array_key_exists( $id, $usage ) ) {
833 + $usage[ $id ] += $total;
834 + }
835 + }
836 +
837 + return $usage;
838 + }
839 +
840 + /**
507 841 * How many published posts use each SureDonation Elementor widget.
508 842 *
509 843 * The Elementor counterpart of get_block_usage(): widgets live in the
510 844 * _elementor_data postmeta (JSON with a quoted "widgetType"), not in the
@@ -521,8 +855,9 @@
521 855 'campaign_goal' => 'suredonation-campaign-goal',
522 856 'campaign_stats' => 'suredonation-campaign-stats',
523 857 'campaign_donations' => 'suredonation-campaign-donations',
524 858 'campaign_donors' => 'suredonation-campaign-donors',
859 + 'campaign_donor_comments' => 'suredonation-campaign-donor-comments',
525 860 'campaign_donate_button' => 'suredonation-campaign-donate-button',
526 861 'campaign_social_sharing' => 'suredonation-campaign-social-sharing',
527 862 'donation_form' => 'suredonation-donation-form',
528 863 ];
@@ -575,8 +910,9 @@
575 910 'campaign_goal' => 'suredonation-campaign-goal',
576 911 'campaign_stats' => 'suredonation-campaign-stats',
577 912 'campaign_donations' => 'suredonation-campaign-donations',
578 913 'campaign_donors' => 'suredonation-campaign-donors',
914 + 'campaign_donor_comments' => 'suredonation-campaign-donor-comments',
579 915 'campaign_donate_button' => 'suredonation-campaign-donate-button',
580 916 'campaign_social_sharing' => 'suredonation-campaign-social-sharing',
581 917 'donation_form' => 'suredonation-donation-form',
582 918 ];
@@ -641,8 +977,38 @@
641 977 return absint( $count );
642 978 }
643 979
644 980 /**
981 + * How many published donation forms use the Image block.
982 + *
983 + * A privacy-preserving adoption count (no content leaves the site), run only
984 + * at analytics send time. The trailing space is the delimiter the block
985 + * serializer always emits after the block name, so a future
986 + * "image-x" block can't prefix-match.
987 + *
988 + * @return int Number of published donation forms containing the block.
989 + * @since 1.3.0
990 + */
991 + private function get_image_block_form_count() {
992 + global $wpdb;
993 +
994 + $like = '%' . $wpdb->esc_like( '<!-- wp:suredonation/image ' ) . '%';
995 +
996 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Single aggregate COUNT run only at analytics send time.
997 + $count = $wpdb->get_var(
998 + $wpdb->prepare(
999 + 'SELECT COUNT(ID) FROM %i WHERE post_type = %s AND post_status = %s AND post_content LIKE %s',
1000 + $wpdb->posts,
1001 + 'suredonation_form',
1002 + 'publish',
1003 + $like
1004 + )
1005 + );
1006 +
1007 + return absint( $count );
1008 + }
1009 +
1010 + /**
645 1011 * Get KPI tracking data for the last 2 full days (excluding today).
646 1012 *
647 1013 * Single grouped query; raw revenue never enters the payload — only
648 1014 * the donation count and a coarse revenue tier per day.
@@ -782,8 +1148,28 @@
782 1148 if ( Stripe_Helper::is_stripe_connected() ) {
783 1149 $events->track( 'stripe_connected', $mode );
784 1150 }
785 1151
1152 + // stripe_card_capability_blocked: connected but Stripe will not let the
1153 + // account charge cards, so the card form is hidden and donations are
1154 + // being lost or diverted. Detected here rather than where the notices
1155 + // render: this is site state, not a page event, and the render path is
1156 + // a public request that should not be paying for analytics.
1157 + $blocked_accounts = 0;
1158 + foreach ( array_keys( Stripe_Helper::get_all_accounts() ) as $blocked_candidate ) {
1159 + if ( Stripe_Helper::is_card_capability_blocked( (string) $blocked_candidate, $mode ) ) {
1160 + ++$blocked_accounts;
1161 + }
1162 + }
1163 +
1164 + if ( $blocked_accounts > 0 ) {
1165 + $events->track(
1166 + 'stripe_card_capability_blocked',
1167 + $mode,
1168 + [ 'blocked_accounts' => $blocked_accounts ]
1169 + );
1170 + }
1171 +
786 1172 // paypal_connected: detect connection state.
787 1173 if ( PayPal_Helper::is_paypal_connected() ) {
788 1174 $events->track( 'paypal_connected', $mode );
789 1175 }
@@ -806,8 +1192,25 @@
806 1192 'days_since_install' => (string) $days_since_install,
807 1193 'payment_mode' => $mode,
808 1194 ]
809 1195 );
1196 +
1197 + // first_live_donation_received: first completed LIVE donation. A
1198 + // separate event with its own dedup key — first_donation_received
1199 + // almost always fires on a test donation (sites start in test
1200 + // mode) and the name-only dedup then suppresses it forever, so
1201 + // the live milestone would otherwise never be visible. Gated on
1202 + // the donation rows' own payment_mode, not the mode at detection
1203 + // time, so a later mode switch can't skew the signal.
1204 + if ( $aggregates['completed_live'] > 0 ) {
1205 + $events->track(
1206 + 'first_live_donation_received',
1207 + Payment_Helper::get_currency(),
1208 + [
1209 + 'days_since_install' => (string) $days_since_install,
1210 + ]
1211 + );
1212 + }
810 1213 }
811 1214
812 1215 // anonymous_donation_submitted: at least one completed anonymous donation.
813 1216 if ( $aggregates['anonymous_completed'] > 0 ) {
@@ -823,10 +1226,19 @@
823 1226 if ( $aggregates['refunded'] > 0 ) {
824 1227 $events->track( 'first_refund_processed' );
825 1228 }
826 1229
827 - // webhook_configured: a Stripe webhook secret is stored for the current mode.
828 - if ( '' !== Stripe_Helper::get_webhook_secret() ) {
1230 + // webhook_configured: a Stripe webhook secret is stored for the current
1231 + // mode on any connected account (multi-account aware — reading only the
1232 + // default account would false-negative on sites using a non-default one).
1233 + $webhook_configured = false;
1234 + foreach ( array_keys( Stripe_Helper::get_all_accounts() ) as $wh_account_id ) {
1235 + if ( '' !== Stripe_Helper::get_webhook_secret( $mode, (string) $wh_account_id ) ) {
1236 + $webhook_configured = true;
1237 + break;
1238 + }
1239 + }
1240 + if ( $webhook_configured ) {
829 1241 $events->track( 'webhook_configured', $mode );
830 1242 }
831 1243 }
832 1244 }