/var/www/html/wp-content/plugins/woocommerce/includes/tracks/events/class-wc-coupons-tracking.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
 * WooCommerce Coupons Tracking
 *
 * @package WooCommerce\Tracks
 */

defined'ABSPATH' ) || exit;

/**
 * This class adds actions to track usage of WooCommerce Orders.
 */
class WC_Coupons_Tracking {
    
/**
     * Init tracking.
     */
    
public function init() {
        
add_action'load-edit.php', array( $this'tracks_coupons_events' ), 10 );
    }

    
/**
     * Add a listener on the "Apply" button to track bulk actions.
     */
    
public function tracks_coupons_bulk_actions() {
        
wc_enqueue_js(
            
"
            function onApplyBulkActions( event ) {
                var id = event.data.id;
                var action = $( '#' + id ).val();
                
                if ( action && '-1' !== action ) {
                    window.wcTracks.recordEvent( 'coupons_view_bulk_action', {
                        action: action
                    } );
                }
            }
            $( '#doaction' ).on( 'click', { id: 'bulk-action-selector-top' }, onApplyBulkActions );
            $( '#doaction2' ).on( 'click', { id: 'bulk-action-selector-bottom' }, onApplyBulkActions );
        "
        
);
    }

    
/**
     * Track page view events.
     */
    
public function tracks_coupons_events() {
        if ( isset( 
$_GET['post_type'] ) && 'shop_coupon' === $_GET['post_type'] ) {

            
$this->tracks_coupons_bulk_actions();

            
WC_Tracks::record_event(
                
'coupons_view',
                array(
                    
'status' => isset( $_GET['post_status'] ) ? sanitize_text_fieldwp_unslash$_GET['post_status'] ) ) : 'all',
                )
            );

            if ( isset( 
$_GET['filter_action'] ) && 'Filter' === sanitize_text_fieldwp_unslash$_GET['filter_action'] ) ) && isset( $_GET['coupon_type'] ) ) {
                
WC_Tracks::record_event(
                    
'coupons_filter',
                    array(
                        
'filter' => 'coupon_type',
                        
'value'  => sanitize_text_fieldwp_unslash$_GET['coupon_type'] ) ),
                    )
                );
            }

            if ( isset( 
$_GET['s'] ) && strlensanitize_text_fieldwp_unslash$_GET['s'] ) ) ) ) {
                
WC_Tracks::record_event'coupons_search' );
            }
        }
    }
}