Skip to content

Commit efa19cf

Browse files
committed
chore: readme updated & unnecessary tracking data fetch removed
1 parent fd352a3 commit efa19cf

File tree

2 files changed

+74
-48
lines changed

2 files changed

+74
-48
lines changed

readme.md

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ composer require bitapps/wp-telemetry
1717
Initialize the telemetry client in your plugin's bootstrap file.
1818

1919
```php
20-
function initialize_telemetry_client() {
20+
function initialize_telemetry_client()
21+
{
2122
TelemetryConfig::setSlug($title);
2223
TelemetryConfig::setTitle($slug);
2324
TelemetryConfig::setPrefix($prefix);
2425
TelemetryConfig::setVersion($version);
25-
TelemetryConfig::setServerBaseUrl( 'https://api.example.com/' );
2626

27-
TelemetryConfig::setTermsUrl( 'https://example.com/terms' ); // optional
28-
TelemetryConfig::setPolicyUrl( 'https://example.com/privacy' ); // optional
27+
TelemetryConfig::setServerBaseUrl( 'https://api.example.com/' );
28+
TelemetryConfig::setTermsUrl( 'https://example.com/terms/' ); // (optional)
29+
TelemetryConfig::setPolicyUrl( 'https://example.com/privacy/' ); // (optional)
2930

3031
// initialize tracking and reporting
3132
Telemetry::report()->init();
@@ -37,80 +38,102 @@ function initialize_telemetry_client() {
3738
initialize_telemetry_client();
3839
```
3940

40-
You are good to go! The telemetry client will start sending data to the default server.
41+
**You are good to go! 👍️**
42+
43+
The telemetry client will start sending data to your configured api base url.
4144

4245
## Configuration
4346

44-
All the configuration should be done in the `initialize_telemetry_client()` function.
47+
### # Activate/Deactivate Telemetry Tracking
4548

46-
### # Tracking Report Modify
49+
You can add a setting in your plugin settings page to allow users to opt-in or opt-out of telemetry tracking. You can use the following methods to change the opt-in/opt-out status.
4750

48-
Add plugin information in tracking data
51+
**⚡️ Opt In :**
4952

5053
```php
51-
TelemetryConfig::report()
52-
->addPluginData()
53-
->init();
54+
Telemetry::report()->trackingOptIn();
5455
```
5556

56-
**Filter Hook to Add Additional Data :**
57+
**⚡️ Opt Out :**
58+
59+
```php
60+
Telemetry::report()->trackingOptOut();
61+
```
62+
63+
### # Tracking Report Modify
64+
65+
**⚡️ Filter Hook to Add Additional Data :**
5766

5867
This filter allows adding additional data to track information used by the plugin. You can modify the `additional_data` array to include any custom data needed.
5968

6069
```php
61-
$plugin_prefix = 'my_plugin_prefix_';
70+
apply_filters($plugin_prefix . 'telemetry_additional_data', $additional_data);
71+
```
6272

63-
add_filter($plugin_prefix . 'telemetry_additional_data', function($additional_data) {
73+
**Usage**
6474

65-
// example: add custom data
66-
$additional_data['my_custom_data'] = 'My Custom Data';
75+
```php
76+
add_filter($plugin_prefix . 'telemetry_additional_data', 'customize_additional_data', 10, 1);
6777

78+
function customize_additional_data($additional_data)
79+
{
80+
// Do your stuffs here
6881
return $additional_data;
69-
});
82+
}
7083
```
7184

72-
**Filter Hook To Modify Telemetry Data :**
85+
**⚡️ Filter Hook To Modify Telemetry Data :**
7386

7487
This filter allows modification of the telemetry data array before it is sent.
7588

7689
```php
77-
$plugin_prefix = 'my_plugin_prefix_';
78-
79-
add_filter($plugin_prefix . 'telemetry_data', function($telemetry_data) {
90+
apply_filters($plugin_prefix . 'telemetry_data', $telemetry_data);
91+
```
8092

81-
// example: remove some data
82-
unset($telemetry_data['some_data']);
93+
**Usage**
8394

84-
// example: add custom data
85-
$telemetry_data['my_custom_data'] = 'My Custom Data';
95+
```php
96+
add_filter($plugin_prefix . 'telemetry_data', 'customize_telemetry_data', 10, 1);
8697

98+
function customize_telemetry_data($telemetry_data)
99+
{
100+
// Do your stuffs here
87101
return $telemetry_data;
88-
});
102+
}
89103
```
90104

91-
### # Deactivate Feedback Config
105+
**⚡️ Add plugin information in tracking data**
92106

93-
You can customize the feedback survey by adding questions using `add_filter()`
107+
```php
108+
TelemetryConfig::report()
109+
->addPluginData()
110+
->init();
111+
```
112+
113+
### # Deactivation Feedback Survey
114+
115+
**⚡️ Filter Hook to Add Deactivate Reasons :**
94116

95-
- **title** - The title of the question
96-
- **placeholder** - The input placeholder of the question (optional)
117+
This filter allows adding additional deactivate reasons to the feedback survey. You can modify the `deactivate_reasons` array to include any custom reasons needed.
97118

98119
```php
99-
$prefix = 'my_plugin_prefix_';
120+
apply_filters($plugin_prefix . 'deactivate_reasons', $deactivate_reasons);
121+
```
100122

101-
add_filter($prefix . 'deactivate_reasons', function ($default_reasons) {
123+
**Usage**
102124

103-
$default_reasons['my_custom_reason'] = [
104-
'title' => 'My Custom Reason',
105-
'placeholder' => 'Please specify the reason',
106-
]
125+
```php
107126

108-
$default_reasons['my_custom_reason_2'] = [
109-
'title' => 'My Custom Reason 2',
110-
'placeholder' => '',
111-
]
127+
add_filter($plugin_prefix . 'deactivate_reasons', 'add_deactivate_reasons', 10, 1);
112128

113-
return $default_reasons;
114-
});
129+
function add_deactivate_reasons($deactivate_reasons)
130+
{
131+
// example of adding a custom deactivate reason
132+
$deactivate_reasons[] = [
133+
'title' => 'What could we have done to improve your experience?',
134+
'placeholder' => 'Please provide your feedback here',
135+
];
115136

137+
return $deactivate_reasons;
138+
}
116139
```

src/Telemetry/Report/Report.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,19 @@ public function handleTrackingOptInOptOut()
8383
return;
8484
}
8585

86-
if (isset($_GET[TelemetryConfig::getPrefix() . 'tracking_opt_in']) && $_GET[TelemetryConfig::getPrefix() . 'tracking_opt_in'] === 'true') {
86+
$optInKey = TelemetryConfig::getPrefix() . 'tracking_opt_in';
87+
88+
if (isset($_GET[$optInKey]) && $_GET[$optInKey] === 'true') {
8789
$this->trackingOptIn();
88-
wp_safe_redirect(remove_query_arg(TelemetryConfig::getPrefix() . 'tracking_opt_in'));
90+
wp_safe_redirect(remove_query_arg($optInKey));
8991
exit;
9092
}
9193

92-
if (isset($_GET[TelemetryConfig::getPrefix() . 'tracking_opt_out'], $_GET[TelemetryConfig::getPrefix() . 'tracking_opt_out']) && $_GET[TelemetryConfig::getPrefix() . 'tracking_opt_out'] === 'true') {
94+
$optOutKey = TelemetryConfig::getPrefix() . 'tracking_opt_out';
95+
96+
if (isset($_GET[$optOutKey]) && $_GET[$optOutKey] === 'true') {
9397
$this->trackingOptOut();
94-
wp_safe_redirect(remove_query_arg(TelemetryConfig::getPrefix() . 'tracking_opt_out'));
98+
wp_safe_redirect(remove_query_arg($optOutKey));
9599
exit;
96100
}
97101
}
@@ -105,7 +109,7 @@ public function trackingOptIn()
105109
$this->scheduleEvent();
106110
$this->sendTrackingReport();
107111

108-
do_action(TelemetryConfig::getPrefix() . 'tracking_opt_in', $this->getTrackingData());
112+
do_action(TelemetryConfig::getPrefix() . 'tracking_opt_in');
109113
}
110114

111115
public function trackingOptOut()
@@ -114,7 +118,6 @@ public function trackingOptOut()
114118
update_option(TelemetryConfig::getPrefix() . 'tracking_notice_dismissed', true);
115119

116120
$this->trackingSkippedRequest();
117-
118121
$this->clearScheduleEvent();
119122

120123
do_action(TelemetryConfig::getPrefix() . 'tracking_opt_out');

0 commit comments

Comments
 (0)