Skip to content

Commit 0022b40

Browse files
committed
refactor: additional data now can be modified by filter hook
1 parent 10dbde1 commit 0022b40

File tree

4 files changed

+32
-30
lines changed

4 files changed

+32
-30
lines changed

readme.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function initialize_telemetry_client() {
2222
TelemetryConfig::setTitle($slug);
2323
TelemetryConfig::setPrefix($prefix);
2424
TelemetryConfig::setVersion($version);
25+
TelemetryConfig::setServerBaseUrl( 'https://api.example.com/' );
2526

2627
// initialize tracking and reporting
2728
Telemetry::report()->init();
@@ -41,12 +42,6 @@ All the configuration should be done in the `initialize_telemetry_client()` func
4142

4243
### # Telemetry Client Config
4344

44-
Set custom server URL
45-
46-
```php
47-
TelemetryConfig::setServerBaseUrl( 'https://example.com' );
48-
```
49-
5045
Set custom terms URL
5146

5247
```php
@@ -59,7 +54,7 @@ Set custom privacy policy URL
5954
TelemetryConfig::setPolicyUrl( 'https://example.com/privacy' );
6055
```
6156

62-
### # Tracking Report Config
57+
### # Tracking Report Modify
6358

6459
Add plugin information in tracking data
6560

@@ -69,14 +64,32 @@ TelemetryConfig::report()
6964
->init();
7065
```
7166

72-
Add extra information in tracking data
67+
Add additional data in tracking data
7368

7469
```php
75-
TelemetryConfig::report()
76-
->addExtraInfo([
77-
'my_plugin_logs' => Log::get(),
78-
])
79-
->init();
70+
$plugin_prefix = 'my_plugin_prefix_';
71+
72+
add_filter($plugin_prefix . 'tracking_additional_data', function($additional_data) {
73+
74+
// example: add custom data
75+
$additional_data['my_custom_data'] = 'My Custom Data';
76+
77+
return $additional_data;
78+
});
79+
```
80+
81+
Filter tracking data before sending
82+
83+
```php
84+
$plugin_prefix = 'my_plugin_prefix_';
85+
86+
add_filter($plugin_prefix . 'tracking_data', function($tracking_data) {
87+
88+
// example: remove some data
89+
unset($tracking_data['some_data']);
90+
91+
return $tracking_data;
92+
});
8093
```
8194

8295
### # Deactivate Feedback Config

src/Telemetry/Report/Report.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
class Report
99
{
10-
private $extraInfo = [];
11-
1210
private $addPluginData = false;
1311

1412
public function init()
@@ -27,13 +25,6 @@ public function addPluginData()
2725
return $this;
2826
}
2927

30-
public function addExtraInfo($data = [])
31-
{
32-
$this->extraInfo = $data;
33-
34-
return $this;
35-
}
36-
3728
public function initCommonHooks()
3829
{
3930
if (!$this->isTrackingNoticeDismissed()) {
@@ -210,15 +201,13 @@ public function getTrackingData()
210201
$data['plugins'] = $reportInfo->getPluginInfo($allPlugins['activePlugins'], TelemetryConfig::getSlug());
211202
}
212203

213-
if (\is_array($this->extraInfo) && !empty($this->extraInfo)) {
214-
$data['extra'] = $this->extraInfo;
215-
}
216-
217204
if (get_option(TelemetryConfig::getPrefix() . 'tracking_skipped')) {
218205
delete_option(TelemetryConfig::getPrefix() . 'tracking_skipped');
219206
$data['previously_skipped'] = true;
220207
}
221208

209+
$data['additional_data'] = apply_filters(TelemetryConfig::getPrefix() . 'tracker_additional_data', []);
210+
222211
return apply_filters(TelemetryConfig::getPrefix() . 'tracker_data', $data);
223212
}
224213

src/Telemetry/Telemetry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function sendReport($route, $data, $blocking = false)
4646
$apiUrl = trailingslashit(TelemetryConfig::getServerBaseUrl()) . $route;
4747

4848
$headers = [
49-
'host-user' => 'BitApps/' . md5(esc_url(home_url())),
49+
'host-user' => md5(esc_url(home_url())),
5050
'Content-Type' => 'application/json',
5151
];
5252

src/Telemetry/TelemetryConfig.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ class TelemetryConfig
1212

1313
private static $version;
1414

15-
private static $termsUrl = 'https://bitapps.pro/terms';
15+
private static $termsUrl = '';
1616

17-
private static $policyUrl = 'https://bitapps.pro/privacy-policy';
17+
private static $policyUrl = '';
1818

19-
private static $serverBaseUrl = 'https://wp-api.bitapps.pro/public/';
19+
private static $serverBaseUrl = '';
2020

2121
public static function setTitle($title)
2222
{

0 commit comments

Comments
 (0)