class-wc-admin-setup-wizard-tracking.php
5 years ago
class-wc-coupon-tracking.php
6 years ago
class-wc-coupons-tracking.php
7 months ago
class-wc-extensions-tracking.php
1 year ago
class-wc-importer-tracking.php
3 years ago
class-wc-order-tracking.php
6 years ago
class-wc-orders-tracking.php
1 year ago
class-wc-product-collection-block-tracking.php
7 months ago
class-wc-products-tracking.php
1 month ago
class-wc-settings-tracking.php
11 months ago
class-wc-status-tracking.php
7 months ago
class-wc-theme-tracking.php
1 year ago
class-wc-coupons-tracking.php
93 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Coupons Tracking |
| 4 | * |
| 5 | * @package WooCommerce\Tracks |
| 6 | */ |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * This class adds actions to track usage of WooCommerce Orders. |
| 12 | */ |
| 13 | class WC_Coupons_Tracking { |
| 14 | /** |
| 15 | * Init tracking. |
| 16 | */ |
| 17 | public function init() { |
| 18 | add_action( 'load-edit.php', array( $this, 'tracks_coupons_events' ), 10 ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Enqueue JS to handle tracking for bulk editing of coupons. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | public function tracks_coupons_bulk_actions() { |
| 27 | $handle = 'wc-tracks-coupons-bulk-actions'; |
| 28 | wp_register_script( $handle, '', array(), WC_VERSION, array( 'in_footer' => true ) ); |
| 29 | wp_enqueue_script( $handle ); |
| 30 | wp_add_inline_script( |
| 31 | $handle, |
| 32 | " |
| 33 | (function() { |
| 34 | 'use strict'; |
| 35 | |
| 36 | function trackBulkAction( selectorId ) { |
| 37 | return function() { |
| 38 | const select = document.getElementById( selectorId ); |
| 39 | const action = select ? select.value : null; |
| 40 | |
| 41 | if ( action && '-1' !== action && window.wcTracks && window.wcTracks.recordEvent ) { |
| 42 | window.wcTracks.recordEvent( 'coupons_view_bulk_action', { action: action } ); |
| 43 | } |
| 44 | }; |
| 45 | } |
| 46 | |
| 47 | const topButton = document.getElementById( 'doaction' ); |
| 48 | const bottomButton = document.getElementById( 'doaction2' ); |
| 49 | |
| 50 | if ( topButton ) { |
| 51 | topButton.addEventListener( 'click', trackBulkAction( 'bulk-action-selector-top' ) ); |
| 52 | } |
| 53 | |
| 54 | if ( bottomButton ) { |
| 55 | bottomButton.addEventListener( 'click', trackBulkAction( 'bulk-action-selector-bottom' ) ); |
| 56 | } |
| 57 | })(); |
| 58 | " |
| 59 | ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Track page view events. |
| 64 | */ |
| 65 | public function tracks_coupons_events() { |
| 66 | if ( isset( $_GET['post_type'] ) && 'shop_coupon' === $_GET['post_type'] ) { |
| 67 | |
| 68 | $this->tracks_coupons_bulk_actions(); |
| 69 | |
| 70 | WC_Tracks::record_event( |
| 71 | 'coupons_view', |
| 72 | array( |
| 73 | 'status' => isset( $_GET['post_status'] ) ? sanitize_text_field( wp_unslash( $_GET['post_status'] ) ) : 'all', |
| 74 | ) |
| 75 | ); |
| 76 | |
| 77 | if ( isset( $_GET['filter_action'] ) && 'Filter' === sanitize_text_field( wp_unslash( $_GET['filter_action'] ) ) && isset( $_GET['coupon_type'] ) ) { |
| 78 | WC_Tracks::record_event( |
| 79 | 'coupons_filter', |
| 80 | array( |
| 81 | 'filter' => 'coupon_type', |
| 82 | 'value' => sanitize_text_field( wp_unslash( $_GET['coupon_type'] ) ), |
| 83 | ) |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | if ( isset( $_GET['s'] ) && 0 < strlen( sanitize_text_field( wp_unslash( $_GET['s'] ) ) ) ) { |
| 88 | WC_Tracks::record_event( 'coupons_search' ); |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 |