| @@ -20,14 +20,18 @@ | ||
| 20 | 20 | * Hooked to admin_init for proper WordPress lifecycle integration |
| 21 | 21 | * Only loads after WordPress, plugins, and themes are fully loaded |
| 22 | 22 | */ |
| 23 | 23 | function metasync_init_analytics() { |
| 24 | - // Only initialize in admin area (excludes AJAX and REST API requests) | |
| 24 | + // Initialize the consent-gated PostHog dispatcher in every request context | |
| 25 | + // so REST, MCP, cron, and admin events share one central gate. | |
| 26 | + Metasync_PostHog::get_instance(); | |
| 27 | + | |
| 28 | + // GA4's browser integration remains limited to MetaSync admin screens. | |
| 25 | 29 | if (is_admin() && !wp_doing_ajax() && !defined('REST_REQUEST')) { |
| 26 | 30 | Metasync_GA4::get_instance(); |
| 27 | 31 | } |
| 28 | 32 | } |
| 29 | -add_action('admin_init', 'metasync_init_analytics', 10); | |
| 33 | +add_action('init', 'metasync_init_analytics', 1); | |
| 30 | 34 | |
| 31 | 35 | /** |
| 32 | 36 | * Initialize API Backoff System |
| 33 | 37 | * Hooked to init for proper WordPress lifecycle integration |
| @@ -61,8 +65,23 @@ | ||
| 61 | 65 | Metasync_Review_Notice::get_instance(); |
| 62 | 66 | } |
| 63 | 67 | } |
| 64 | 68 | add_action('init', 'metasync_init_review_notice'); |
| 69 | + | |
| 70 | +/** | |
| 71 | + * Initialize Analytics Consent Notice | |
| 72 | + * Asks existing installs to opt in to usage analytics; re-shows every | |
| 73 | + * 10 days while consent stays off. | |
| 74 | + */ | |
| 75 | +function metasync_init_analytics_consent_notice() { | |
| 76 | + if (metasync_is_non_metasync_admin_ajax()) { | |
| 77 | + return; | |
| 78 | + } | |
| 79 | + if (is_admin()) { | |
| 80 | + Metasync_Analytics_Consent_Notice::get_instance(); | |
| 81 | + } | |
| 82 | +} | |
| 83 | +add_action('init', 'metasync_init_analytics_consent_notice'); | |
| 65 | 84 | |
| 66 | 85 | /** |
| 67 | 86 | * Initialize Host Blocking Check |
| 68 | 87 | * Owns the shared GET/POST reachability probe, its post-activation + weekly crons, |