| 1 |
<?php |
| 2 |
/** |
| 3 |
* Telemetry: Telemetry activation and event registration |
| 4 |
* |
| 5 |
* @package Parsely\Telemetry |
| 6 |
* @since 3.12.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
use Parsely\Telemetry\Telemetry_System; |
| 12 |
use Parsely\Telemetry\Tracks; |
| 13 |
|
| 14 |
require_once __DIR__ . '/class-telemetry-system.php'; |
| 15 |
|
| 16 |
// If in a VIP environment, prevent logging duplicate Tracks events. |
| 17 |
if ( defined( 'VIP_GO_APP_ENVIRONMENT' ) ) { |
| 18 |
add_filter( 'wp_parsely_enable_telemetry_backend', '__return_false' ); |
| 19 |
} |
| 20 |
|
| 21 |
add_action( |
| 22 |
'init', |
| 23 |
function (): void { |
| 24 |
// Initialize the JS tracking. It will handle if telemetry is enabled or not by itself. |
| 25 |
Telemetry_System::init_js_tracking(); |
| 26 |
|
| 27 |
// Bail if wp-admin telemetry is not allowed. |
| 28 |
if ( false === Telemetry_System::is_wpadmin_telemetry_allowed() ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
require_once __DIR__ . '/Events/recommended-widget.php'; |
| 33 |
require_once __DIR__ . '/Events/settings.php'; |
| 34 |
require_once __DIR__ . '/Tracks/class-tracks-event.php'; |
| 35 |
require_once __DIR__ . '/Tracks/class-tracks-pixel.php'; |
| 36 |
require_once __DIR__ . '/Tracks/class-tracks.php'; |
| 37 |
|
| 38 |
$tracks = new Tracks(); |
| 39 |
|
| 40 |
$tracks->register_events( |
| 41 |
// Recommended Widget events. |
| 42 |
array( |
| 43 |
'action_hook' => 'delete_widget', |
| 44 |
'callable' => 'Parsely\Telemetry\record_widget_deleted', |
| 45 |
'accepted_args' => 3, |
| 46 |
), |
| 47 |
array( |
| 48 |
'action_hook' => 'widget_update_callback', |
| 49 |
'callable' => 'Parsely\Telemetry\record_widget_updated', |
| 50 |
'accepted_args' => 4, |
| 51 |
), |
| 52 |
// Setting events. |
| 53 |
array( |
| 54 |
'action_hook' => 'load-parse-ly_page_parsely-settings', |
| 55 |
'callable' => 'Parsely\Telemetry\record_settings_page_loaded', |
| 56 |
), |
| 57 |
array( |
| 58 |
'action_hook' => 'update_option_parsely', |
| 59 |
'callable' => 'Parsely\Telemetry\record_parsely_option_updated', |
| 60 |
'accepted_args' => 2, |
| 61 |
) |
| 62 |
); |
| 63 |
|
| 64 |
$tracks->run(); |
| 65 |
} |
| 66 |
); |
| 67 |
|
| 68 |
// Attempt to enable the Pendo JavaScript library. It's up to the Pendo class to |
| 69 |
// decide whether the library will be enabled. |
| 70 |
if ( class_exists( '\Automattic\VIP\Telemetry\Pendo' ) ) { |
| 71 |
add_action( |
| 72 |
'admin_init', |
| 73 |
// @phpstan-ignore argument.type |
| 74 |
array( \Automattic\VIP\Telemetry\Pendo::class, 'enable_javascript_library' ) |
| 75 |
); |
| 76 |
} |
| 77 |
|