-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add telemetry for the Event block (#7341)
- Loading branch information
Showing
5 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Give\Tracking\Helpers; | ||
|
||
use Give\DonationForms\Models\DonationForm; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class FormBlocks | ||
{ | ||
/** | ||
* @var DonationForm | ||
* @unreleased | ||
*/ | ||
protected $form; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function __construct(DonationForm $form) | ||
{ | ||
$this->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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Give\Tests\Unit\Tracking\Helpers; | ||
|
||
use Give\DonationForms\Models\DonationForm; | ||
use Give\Donations\Models\Donation; | ||
use Give\Donations\ValueObjects\DonationStatus; | ||
use Give\Framework\Blocks\BlockCollection; | ||
use Give\Framework\Blocks\BlockModel; | ||
use Give\Framework\Database\DB; | ||
use Give\Framework\Support\ValueObjects\Money; | ||
use Give\Revenue\Listeners\UpdateRevenueWhenDonationAmountUpdated; | ||
use Give\Tests\TestCase; | ||
use Give\Tests\TestTraits\RefreshDatabase; | ||
use Give\Tracking\Helpers\FormBlocks; | ||
|
||
/** | ||
* @since 2.20.1 | ||
*/ | ||
class FormBlocksTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testFormHasBlockByName() | ||
{ | ||
$form = DonationForm::factory()->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') | ||
); | ||
} | ||
} | ||
|