class-tracker.php
1.26 KB
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
<?php
/**
* Class Tracker
*
* @package WooCommerce\Payments
*/
namespace WCPay;
defined( 'ABSPATH' ) || exit; // block direct access.
/**
* An API for adding track events that will get unloaded
* at a later stage and pushed to WP.com.
*/
class Tracker {
/**
* A key value array event_name => properties.
*
* @var array $admin_events
*/
protected static $admin_events = [];
/**
* Record an event in Tracks
*
* This only sends track events for admin logged in users. This is a limitation of the
* WC_Tracks and related classes.
*
* The event name will be prefixed before sending it see Core_Tracks_Wrapper.
*
* @param string $event_name The name of the event.
* @param array $properties Custom properties to send with the event.
*/
public static function track_admin( $event_name, $properties = [] ) {
self::$admin_events[ $event_name ] = $properties;
}
/**
* Remove a track event.
*
* @param string $event_name The name of the event that should be removed.
*/
public static function remove_admin_event( $event_name ) {
if ( isset( self::$admin_events ) ) {
unset( self::$admin_events[ $event_name ] );
}
}
/**
* Remove a track event.
*/
public static function get_admin_events() {
return self::$admin_events;
}
}