説明なし

class-wc-extensions-tracking.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * WooCommerce Extensions Tracking
  4. *
  5. * @package WooCommerce\Tracks
  6. */
  7. defined( 'ABSPATH' ) || exit;
  8. /**
  9. * This class adds actions to track usage of the WooCommerce Extensions page.
  10. */
  11. class WC_Extensions_Tracking {
  12. /**
  13. * Init tracking.
  14. */
  15. public function init() {
  16. add_action( 'load-woocommerce_page_wc-addons', array( $this, 'track_extensions_page' ) );
  17. add_action( 'woocommerce_helper_connect_start', array( $this, 'track_helper_connection_start' ) );
  18. add_action( 'woocommerce_helper_denied', array( $this, 'track_helper_connection_cancelled' ) );
  19. add_action( 'woocommerce_helper_connected', array( $this, 'track_helper_connection_complete' ) );
  20. add_action( 'woocommerce_helper_disconnected', array( $this, 'track_helper_disconnected' ) );
  21. add_action( 'woocommerce_helper_subscriptions_refresh', array( $this, 'track_helper_subscriptions_refresh' ) );
  22. add_action( 'woocommerce_addon_installed', array( $this, 'track_addon_install' ), 10, 2 );
  23. }
  24. /**
  25. * Send a Tracks event when an Extensions page is viewed.
  26. */
  27. public function track_extensions_page() {
  28. // phpcs:disable WordPress.Security.NonceVerification.Recommended
  29. $properties = array(
  30. 'section' => empty( $_REQUEST['section'] ) ? '_featured' : wc_clean( wp_unslash( $_REQUEST['section'] ) ),
  31. );
  32. $event = 'extensions_view';
  33. if ( 'helper' === $properties['section'] ) {
  34. $event = 'subscriptions_view';
  35. }
  36. if ( ! empty( $_REQUEST['search'] ) ) {
  37. $event = 'extensions_view_search';
  38. $properties['search_term'] = wc_clean( wp_unslash( $_REQUEST['search'] ) );
  39. }
  40. // phpcs:enable
  41. WC_Tracks::record_event( $event, $properties );
  42. }
  43. /**
  44. * Send a Tracks even when a Helper connection process is initiated.
  45. */
  46. public function track_helper_connection_start() {
  47. WC_Tracks::record_event( 'extensions_subscriptions_connect' );
  48. }
  49. /**
  50. * Send a Tracks even when a Helper connection process is cancelled.
  51. */
  52. public function track_helper_connection_cancelled() {
  53. WC_Tracks::record_event( 'extensions_subscriptions_cancelled' );
  54. }
  55. /**
  56. * Send a Tracks even when a Helper connection process completed successfully.
  57. */
  58. public function track_helper_connection_complete() {
  59. WC_Tracks::record_event( 'extensions_subscriptions_connected' );
  60. }
  61. /**
  62. * Send a Tracks even when a Helper has been disconnected.
  63. */
  64. public function track_helper_disconnected() {
  65. WC_Tracks::record_event( 'extensions_subscriptions_disconnect' );
  66. }
  67. /**
  68. * Send a Tracks even when Helper subscriptions are refreshed.
  69. */
  70. public function track_helper_subscriptions_refresh() {
  71. WC_Tracks::record_event( 'extensions_subscriptions_update' );
  72. }
  73. /**
  74. * Send a Tracks event when addon is installed via the Extensions page.
  75. *
  76. * @param string $addon_id Addon slug.
  77. * @param string $section Extensions tab.
  78. */
  79. public function track_addon_install( $addon_id, $section ) {
  80. $properties = array(
  81. 'context' => 'extensions',
  82. 'section' => $section,
  83. );
  84. if ( 'woocommerce-payments' === $addon_id ) {
  85. WC_Tracks::record_event( 'woocommerce_payments_install', $properties );
  86. }
  87. }
  88. }