| @@ -3,8 +3,9 @@ | ||
| 3 | 3 | namespace Give\Tracking; |
| 4 | 4 | |
| 5 | 5 | use Give\Helpers\Hooks; |
| 6 | 6 | use Give\ServiceProviders\ServiceProvider; |
| 7 | +use Give\Tracking\Events\CampaignsTracking; | |
| 7 | 8 | use Give\Tracking\Events\DonationFormsTracking; |
| 8 | 9 | use Give\Tracking\Events\DonationMetricsTracking; |
| 9 | 10 | use Give\Tracking\Events\EditedDonationFormsTracking; |
| 10 | 11 | use Give\Tracking\Events\GivePluginSettingsTracking; |
| @@ -30,8 +31,10 @@ | ||
| 30 | 31 | } |
| 31 | 32 | |
| 32 | 33 | /** |
| 33 | 34 | * @inheritdoc |
| 35 | + * | |
| 36 | + * @since 3.0.0 Enable tracking if request is made by form builder | |
| 34 | 37 | */ |
| 35 | 38 | public function boot() |
| 36 | 39 | { |
| 37 | 40 | $isTrackingEnabled = Track::isTrackingEnabled(); |
| @@ -39,12 +42,24 @@ | ||
| 39 | 42 | if ($isTrackingEnabled) { |
| 40 | 43 | Hooks::addAction(TrackJobScheduler::CRON_JOB_HOOK_NAME, TrackJob::class, 'send'); |
| 41 | 44 | } |
| 42 | 45 | |
| 46 | + // Enable telemetry for Visual Form Builder | |
| 47 | + add_action('rest_api_init', function () use ($isTrackingEnabled) { | |
| 48 | + $restRoute = $GLOBALS['wp']->query_vars['rest_route'] ?? ''; | |
| 49 | + if (empty($restRoute)) { | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + | |
| 53 | + $isV3FormRoute = strpos($restRoute, 'givewp/v3/form') !== false; | |
| 54 | + if ($isTrackingEnabled && $isV3FormRoute) { | |
| 55 | + $this->enableTracking(); | |
| 56 | + } | |
| 57 | + }); | |
| 58 | + | |
| 43 | 59 | if (is_admin()) { |
| 44 | 60 | if ($isTrackingEnabled) { |
| 45 | - $this->registerTrackEvents(); | |
| 46 | - Hooks::addAction('shutdown', TrackJobScheduler::class, 'schedule', 999); | |
| 61 | + $this->enableTracking(); | |
| 47 | 62 | } |
| 48 | 63 | |
| 49 | 64 | if (Track::checkEnvironment()) { |
| 50 | 65 | Hooks::addFilter('give_get_settings_advanced', AdminSettings::class, 'addSettings'); |
| @@ -72,16 +87,27 @@ | ||
| 72 | 87 | } |
| 73 | 88 | } |
| 74 | 89 | |
| 75 | 90 | /** |
| 91 | + * @since 3.0.0 | |
| 92 | + */ | |
| 93 | + private function enableTracking() | |
| 94 | + { | |
| 95 | + $this->registerTrackEvents(); | |
| 96 | + Hooks::addAction('shutdown', TrackJobScheduler::class, 'schedule', 999); | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 76 | 100 | * Register track events. |
| 77 | 101 | * |
| 78 | 102 | * 'give_send_tracking_data' action hook that will be triggered track routine cron job. |
| 79 | 103 | * |
| 104 | + * @since 3.0.0 Add support for v3 forms | |
| 80 | 105 | * @since 2.10.0 |
| 81 | 106 | */ |
| 82 | 107 | private function registerTrackEvents() |
| 83 | 108 | { |
| 109 | + Hooks::addAction('givewp_form_builder_updated', EditedDonationFormsTracking::class, 'formBuilderUpdatedHookHandler'); | |
| 84 | 110 | Hooks::addAction('save_post_give_forms', EditedDonationFormsTracking::class, 'savePostHookHandler'); |
| 85 | 111 | Hooks::addAction('save_post_give_payment', DonationFormsTracking::class, 'record'); |
| 86 | 112 | Hooks::addAction('save_post_give_payment', DonationMetricsTracking::class, 'record'); |
| 87 | 113 | Hooks::addAction('upgrader_process_complete', ThemeTracking::class, 'themeUpdateTrackingHandler', 10, 2); |
| @@ -88,6 +114,7 @@ | ||
| 88 | 114 | Hooks::addAction('shutdown', WebsiteTracking::class, 'websiteUpdateTrackingHandler'); |
| 89 | 115 | Hooks::addAction('update_option_give_settings', GivePluginSettingsTracking::class, 'record'); |
| 90 | 116 | Hooks::addAction('update_option_active_plugins', PluginsTracking::class, 'record'); |
| 91 | 117 | Hooks::addAction('switch_theme', ThemeTracking::class, 'record'); |
| 118 | + Hooks::addAction('givewp_campaign_updated', CampaignsTracking::class, 'record'); | |
| 92 | 119 | } |
| 93 | 120 | } |