Completed
Push — remove/wp-admin-publicize-conn... ( d708bd...e84ae6 )
by
unknown
64:00 queued 52:22
created

JetpackTracking::track_deactivate_module()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
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';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $product_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
10
11
	static function track_jetpack_usage() {
12
		if ( ! Jetpack::is_active() ) {
13
			return;
14
		}
15
16
		add_action( 'jetpack_pre_activate_module',   array( __CLASS__, 'track_activate_module'), 1, 1 );
17
		add_action( 'jetpack_pre_deactivate_module', array( __CLASS__, 'track_deactivate_module'), 1, 1 );
18
		add_action( 'jetpack_user_authorized',       array( __CLASS__, 'track_user_linked' ) );
19
	}
20
21
	/* User has linked their account */
22
	static function track_user_linked() {
23
		$user_id = get_current_user_id();
24
		$anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true );
25
26
		if ( $anon_id ) {
27
			self::record_user_event( '_aliasUser', array( 'anonId' => $anon_id ) );
28
			delete_user_meta( $user_id, 'jetpack_tracks_anon_id' );
29
			if ( ! headers_sent() ) {
30
				setcookie( 'tk_ai', 'expired', time() - 1000 );
31
			}
32
		}
33
34
		$wpcom_user_data = Jetpack::get_connected_user_data( $user_id );
35
		update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] );
36
37
		self::record_user_event( 'user_linked', array() );
38
	}
39
40
	/* Activated module */
41
	static function track_activate_module( $module ) {
42
		self::record_user_event( 'module_activated', array( 'module' => $module ) );
43
	}
44
45
	/* Deactivated module */
46
	static function track_deactivate_module( $module ) {
47
		self::record_user_event( 'module_deactivated', array( 'module' => $module ) );
48
	}
49
50
	static function record_user_event( $event_type, $data ) {
51
52
		$user = wp_get_current_user();
53
		$site_url = get_option( 'siteurl' );
54
55
		$data['_via_ua']  = $_SERVER['HTTP_USER_AGENT'];
56
		$data['_via_ip']  = $_SERVER['REMOTE_ADDR'];
57
		$data['_lg']      = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
58
		$data['blog_url'] = $site_url;
59
		$data['blog_id']  = Jetpack_Options::get_option( 'id' );
60
61
		// Top level events should not be namespaced
62
		if ( '_aliasUser' != $event_type ) {
63
			$event_type = self::$product_name . '_' . $event_type;
64
		}
65
66
		$data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : '0';
67
68
		tracks_record_event( $user, $event_type, $data );
69
	}
70
}
71
72
add_action( 'init',  array( 'JetpackTracking', 'track_jetpack_usage' ) );
73