Açıklama Yok

class-wc-coupons-tracking.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * WooCommerce Coupons Tracking
  4. *
  5. * @package WooCommerce\Tracks
  6. */
  7. defined( 'ABSPATH' ) || exit;
  8. /**
  9. * This class adds actions to track usage of WooCommerce Orders.
  10. */
  11. class WC_Coupons_Tracking {
  12. /**
  13. * Init tracking.
  14. */
  15. public function init() {
  16. add_action( 'load-edit.php', array( $this, 'tracks_coupons_events' ), 10 );
  17. }
  18. /**
  19. * Add a listener on the "Apply" button to track bulk actions.
  20. */
  21. public function tracks_coupons_bulk_actions() {
  22. wc_enqueue_js(
  23. "
  24. function onApplyBulkActions( event ) {
  25. var id = event.data.id;
  26. var action = $( '#' + id ).val();
  27. if ( action && '-1' !== action ) {
  28. window.wcTracks.recordEvent( 'coupons_view_bulk_action', {
  29. action: action
  30. } );
  31. }
  32. }
  33. $( '#doaction' ).on( 'click', { id: 'bulk-action-selector-top' }, onApplyBulkActions );
  34. $( '#doaction2' ).on( 'click', { id: 'bulk-action-selector-bottom' }, onApplyBulkActions );
  35. "
  36. );
  37. }
  38. /**
  39. * Track page view events.
  40. */
  41. public function tracks_coupons_events() {
  42. if ( isset( $_GET['post_type'] ) && 'shop_coupon' === $_GET['post_type'] ) {
  43. $this->tracks_coupons_bulk_actions();
  44. WC_Tracks::record_event(
  45. 'coupons_view',
  46. array(
  47. 'status' => isset( $_GET['post_status'] ) ? sanitize_text_field( wp_unslash( $_GET['post_status'] ) ) : 'all',
  48. )
  49. );
  50. if ( isset( $_GET['filter_action'] ) && 'Filter' === sanitize_text_field( wp_unslash( $_GET['filter_action'] ) ) && isset( $_GET['coupon_type'] ) ) {
  51. WC_Tracks::record_event(
  52. 'coupons_filter',
  53. array(
  54. 'filter' => 'coupon_type',
  55. 'value' => sanitize_text_field( wp_unslash( $_GET['coupon_type'] ) ),
  56. )
  57. );
  58. }
  59. if ( isset( $_GET['s'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) ) {
  60. WC_Tracks::record_event( 'coupons_search' );
  61. }
  62. }
  63. }
  64. }