wpdesk / wp-wpdesk-tracker
Requires
- php: >=7.1 || ^8
- psr/log: ^1 || ^2
- wpdesk/wp-builder: ^2.0
- wpdesk/wp-notice: ^3.1
- wpdesk/wp-view: ^2
Requires (Dev)
- 10up/wp_mock: ^1
- phpunit/phpunit: ^7 || ^8 || ^9
- wpdesk/phpstan-rules: ^1
- wpdesk/wp-code-sniffer: ^1
- dev-master
- 3.7.1
- 3.7.0
- 3.6.1
- 3.6.0
- 3.6.0-beta.2
- 3.6.0-beta.1
- 3.5.12
- 3.5.10
- 3.5.9
- 3.5.8
- 3.5.7
- 3.5.6
- 3.5.5
- 3.5.4
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.2.0-beta4
- 3.2.0-beta3
- 3.2.0-beta2
- 3.2.0-beta1
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 2.4.0-beta1
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0
- dev-use-psr-log
- dev-feat/plugin-links
- dev-fix/ditch-localized-names
- dev-source
- dev-rephrase-links
- dev-notice
- dev-improvements
- dev-style
- dev-composer
- dev-wc-settings
- dev-fix/deprecated_functions
- dev-php-compatibility
- dev-remove-suhosin-detection
- dev-fix/escaping
- dev-feature/content-filter
- dev-feature/deactivation-dialog
- dev-feature/init
This package is auto-updated.
Last update: 2024-12-12 07:01:39 UTC
README
A WordPress library containing interfaces, abstracts and implementations to be used for plugins' usage tracking.
[[TOC]]
Requirements
PHP 7.0 or later.
Installation via Composer
In order to install the bindings via Composer run the following command:
composer require wpdesk/wp-wpdesk-tracker
Usage
The library features multiple purposes:
- provides a framework for collecting website usage data,
- prepares a common set of data to be sent to the tracker server,
- exposes UI elements for user to interact with the tracker (enable/disable telemetry)
Extending collected data
If you want to include custom data exposed by your plugin, you can easily add it to the usage data payload. There are two ways to register additional data:
- via
wpdesk_tracker_data
filter, - by registering class implementing
WPDesk_Tracker_Data_Provider
interface
Exposing to users
As usage tracking is disabled by default, a key point is to encourage users to enable it. This library exposes some common UI interfaces, which serves the purpose of enabling the telemetry:
- admin notice, encouraging user to enable usage tracking,
- a box with information about tracking and actionable buttons
/**
* Assuming usage with wp-builder library.
*/
use WPDesk\Tracker\OptInOptOut;
use WPDesk\Tracker\OptInPage;
use WPDesk\PluginBuilder\Plugin\AbstractPlugin;
class Plugin extends AbstractPlugin {
public function hooks(): void {
$tracker_ui = new OptInOptOut(
$this->plugin_info->get_plugin_file_name(),
$this->plugin_info->get_plugin_slug(),
'https://wpdesk.net',
$this->plugin_info->get_plugin_name()
);
$tracker_ui->create_objects();
$tracker_ui->hooks();
}
public function settings_page(): void {
echo "<h1>Settings page</h1>";
(new OptInPage(
$this->plugin_info->get_plugin_file_name(),
$this->plugin_info->get_plugin_slug()
))->output();
}
}
Replacing the default sender
By default, the library sends usage data to wpdesk.org server. You can replace it with your desired endpoint, by swapping WPDesk_Tracker_Sender
implementation.
class MySender implements WPDesk_Tracker_Sender {
public function send_payload(array $payload){
// implement send_payload method.
}
}
$plugin_slug = 'my-example-plugin';
add_filter( 'wpdesk/tracker/sender/' . $plugin_slug, 'replace_sender' );
function replace_sender() {
return new MySender();
}
Technical details
The library enables usage tracking globally for all library consumers. This means, if you have two separate plugins using the library, the data will be send only once.
After enabling, data collection is performed periodically, once a week.