diff --git a/src/Tracking/Helpers/FormBlocks.php b/src/Tracking/Helpers/FormBlocks.php new file mode 100644 index 0000000000..2ae7c9b4c4 --- /dev/null +++ b/src/Tracking/Helpers/FormBlocks.php @@ -0,0 +1,41 @@ +form = $form; + } + + /** + * @unreleased + */ + public static function formId($formId): self + { + return new self(DonationForm::find($formId)); + } + + /** + * @unreleased + */ + public function hasBlock(string $blockName): bool + { + return (bool) $this->form->blocks->findByName($blockName); + } +} diff --git a/src/Tracking/README.md b/src/Tracking/README.md new file mode 100644 index 0000000000..21db0f4888 --- /dev/null +++ b/src/Tracking/README.md @@ -0,0 +1,21 @@ +# Anonymous Usage Tracking + +When a site is opted in to anonymous usage tracking, GiveWP uses various hooks to collect data about how the plugin and related donation forms are configured. + +Each grouping of usage data is collected on a corresponding hook in the WordPress request cycle. + +During [shutdown](https://developer.wordpress.org/reference/hooks/shutdown/) any registered changes are offloaded to a background task using the [WordPress cron](https://developer.wordpress.org/plugins/cron/) system. + +## Sending new tracking data + +The data that is collected should belong to one of a few groups: + +1. Environment configuration data +2. Plugin configuration data +3. Donation Form configuration data + +Each of the groups has one or more related events with a corresponding hook and `TrackingData` class, which can be referenced in [TrackingServiceProvider](TrackingServiceProvider.php). + +To add new tracking data, identify the appropriate event and the related `TrackingData`. + +The returned array of data will be sent to the appropriate endpoint according the the [EventType](Enum/EventType.php) of the event. diff --git a/src/Tracking/TrackingData/DonationFormsData.php b/src/Tracking/TrackingData/DonationFormsData.php index 4d2b188e71..8f71859be0 100644 --- a/src/Tracking/TrackingData/DonationFormsData.php +++ b/src/Tracking/TrackingData/DonationFormsData.php @@ -9,6 +9,7 @@ use Give\Helpers\Form\Utils; use Give\Tracking\Contracts\TrackData; use Give\Tracking\Helpers\DonationStatuses; +use Give\Tracking\Helpers\FormBlocks; use Give\Tracking\Repositories\TrackEvents; /** @@ -60,6 +61,7 @@ public function get() /** * Get forms data. * + * @unreleased Add check for event block. * @since 3.0.0 Add support for v3 forms * @since 2.10.0 * @return array @@ -81,6 +83,7 @@ protected function getData() 'form_template' => $this->getFormTemplate($formId), 'donor_count' => $this->formDonorCounts[$formId], 'revenue' => $this->formRevenues[$formId], + 'event_block' => (int) FormBlocks::formId($formId)->hasBlock('givewp/event-tickets'), ]; $this->addAddonsInformation($temp, $formId); $data[] = $temp; diff --git a/src/Tracking/TrackingData/GivePluginSettingsData.php b/src/Tracking/TrackingData/GivePluginSettingsData.php index bab5c3f517..4b5b6a9686 100644 --- a/src/Tracking/TrackingData/GivePluginSettingsData.php +++ b/src/Tracking/TrackingData/GivePluginSettingsData.php @@ -2,6 +2,7 @@ namespace Give\Tracking\TrackingData; +use Give\BetaFeatures\Facades\FeatureFlag; use Give\Tracking\Contracts\TrackData; use Give\Tracking\Repositories\Settings; @@ -29,6 +30,7 @@ public function get() /** * Returns plugin global settings. * + * @unreleased Add check for Event Tickets beta feature. * @since 2.10.0 * @return array */ @@ -64,6 +66,11 @@ private function getGlobalSettings() $data['active_payment_gateways'] = $this->getGatewaysLabels(); + /** + * @unreleased Add check for Event Tickets beta feature. + */ + $data['is_event_tickets'] = FeatureFlag::eventTickets(); + return $data; } diff --git a/tests/Unit/Tracking/Helpers/FormBlocksTest.php b/tests/Unit/Tracking/Helpers/FormBlocksTest.php new file mode 100644 index 0000000000..a0ceab820b --- /dev/null +++ b/tests/Unit/Tracking/Helpers/FormBlocksTest.php @@ -0,0 +1,44 @@ +create(); + $form->blocks->insertAfter('givewp/donor-name', new BlockModel('test/form-block-1')); + $form->save(); + + $this->assertTrue( + FormBlocks::formId($form->id)->hasBlock('test/form-block-1') + ); + } + + public function testFormDoesNotHaveBlockByName() + { + $form = DonationForm::factory()->create(); + + $this->assertFalse( + FormBlocks::formId($form->id)->hasBlock('test/form-block-1') + ); + } +} +