1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Nosara Tracks for Jetpack |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
require_once( dirname( __FILE__ ) . '/_inc/lib/tracks/client.php' ); |
7
|
|
|
|
8
|
|
|
class JetpackTracking { |
9
|
|
|
static $product_name = 'jetpack'; |
|
|
|
|
10
|
|
|
|
11
|
|
|
static function track_jetpack_usage() { |
12
|
|
|
add_action( 'jetpack_activate_module', array( __CLASS__, 'track_activate_module'), 1, 1 ); |
13
|
|
|
add_action( 'jetpack_pre_deactivate_module', array( __CLASS__, 'track_deactivate_module'), 1, 1 ); |
14
|
|
|
add_action( 'jetpack_user_authorized', array( __CLASS__, 'track_user_linked' ) ); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/* User has linked their account */ |
18
|
|
|
static function track_user_linked() { |
19
|
|
|
self::record_user_event( 'user_linked', array() ); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/* Activated module */ |
23
|
|
|
static function track_activate_module( $module ) { |
24
|
|
|
self::record_user_event( 'module_activated', array( 'module' => $module ) ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/* Deactivated module */ |
28
|
|
|
static function track_deactivate_module( $module ) { |
29
|
|
|
self::record_user_event( 'module_deactivated', array( 'module' => $module ) ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
static function record_user_event( $event_type, $data ) { |
33
|
|
|
|
34
|
|
|
$user = wp_get_current_user(); |
35
|
|
|
$site_url = get_option( 'siteurl' ); |
36
|
|
|
|
37
|
|
|
$data['_via_ua'] = $_SERVER['HTTP_USER_AGENT']; |
38
|
|
|
$data['_via_ip'] = $_SERVER['REMOTE_ADDR']; |
39
|
|
|
$data['_lg'] = $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
40
|
|
|
$data['blog_url'] = $site_url; |
41
|
|
|
|
42
|
|
|
$data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : "0"; |
43
|
|
|
|
44
|
|
|
$response = tracks_record_event( $user, self::$product_name.'_'.$event_type, $data ); |
45
|
|
|
|
46
|
|
|
if ( is_wp_error( $response ) ) { |
47
|
|
|
error_log( "There was an error: ".$response->get_error_message() ); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
add_action( 'init', array( 'JetpackTracking', 'track_jetpack_usage' ) ); |
53
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.