jetpack
Last commit date
3rd-party
9 years ago
_inc
1 year ago
bin
9 years ago
css
9 years ago
images
1 year ago
json-endpoints
9 years ago
languages
9 years ago
modules
1 year ago
sal
9 years ago
scss
9 years ago
sync
9 years ago
views
9 years ago
.svnignore
12 years ago
changelog.txt
9 years ago
class.frame-nonce-preview.php
9 years ago
class.jetpack-admin.php
9 years ago
class.jetpack-autoupdate.php
9 years ago
class.jetpack-bbpress-json-api-compat.php
9 years ago
class.jetpack-cli.php
9 years ago
class.jetpack-client-server.php
9 years ago
class.jetpack-client.php
9 years ago
class.jetpack-connection-banner.php
9 years ago
class.jetpack-constants.php
9 years ago
class.jetpack-data.php
9 years ago
class.jetpack-debugger.php
9 years ago
class.jetpack-error.php
10 years ago
class.jetpack-heartbeat.php
9 years ago
class.jetpack-idc.php
9 years ago
class.jetpack-ixr-client.php
10 years ago
class.jetpack-jitm.php
9 years ago
class.jetpack-modules-list-table.php
9 years ago
class.jetpack-network-sites-list-table.php
9 years ago
class.jetpack-network.php
9 years ago
class.jetpack-options.php
9 years ago
class.jetpack-post-images.php
9 years ago
class.jetpack-signature.php
9 years ago
class.jetpack-tracks.php
9 years ago
class.jetpack-twitter-cards.php
9 years ago
class.jetpack-user-agent.php
9 years ago
class.jetpack-xmlrpc-server.php
9 years ago
class.jetpack.php
9 years ago
class.json-api-endpoints.php
3 years ago
class.json-api.php
10 years ago
class.photon.php
9 years ago
composer.json
10 years ago
functions.compat.php
9 years ago
functions.gallery.php
10 years ago
functions.global.php
9 years ago
functions.opengraph.php
9 years ago
functions.photon.php
9 years ago
jetpack.php
1 year ago
json-api-config.php
10 years ago
json-endpoints.php
9 years ago
locales.php
9 years ago
readme.txt
1 year ago
require-lib.php
10 years ago
rest-api.md
9 years ago
uninstall.php
9 years ago
webpack.config.js
9 years ago
wpml-config.xml
10 years ago
class.jetpack-tracks.php
84 lines
| 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 | if ( ! Jetpack::is_active() ) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | // For tracking stuff via js/ajax |
| 17 | add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_tracks_scripts' ) ); |
| 18 | |
| 19 | add_action( 'jetpack_pre_activate_module', array( __CLASS__, 'track_activate_module'), 1, 1 ); |
| 20 | add_action( 'jetpack_pre_deactivate_module', array( __CLASS__, 'track_deactivate_module'), 1, 1 ); |
| 21 | add_action( 'jetpack_user_authorized', array( __CLASS__, 'track_user_linked' ) ); |
| 22 | } |
| 23 | |
| 24 | static function enqueue_tracks_scripts() { |
| 25 | wp_enqueue_script( 'jptracks', plugins_url( '_inc/lib/tracks/tracks-ajax.js', JETPACK__PLUGIN_FILE ), array(), JETPACK__VERSION, true ); |
| 26 | wp_localize_script( 'jptracks', 'jpTracksAJAX', array( |
| 27 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 28 | 'jpTracksAJAX_nonce' => wp_create_nonce( 'jp-tracks-ajax-nonce' ), |
| 29 | ) ); |
| 30 | } |
| 31 | |
| 32 | /* User has linked their account */ |
| 33 | static function track_user_linked() { |
| 34 | $user_id = get_current_user_id(); |
| 35 | $anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true ); |
| 36 | |
| 37 | if ( $anon_id ) { |
| 38 | self::record_user_event( '_aliasUser', array( 'anonId' => $anon_id ) ); |
| 39 | delete_user_meta( $user_id, 'jetpack_tracks_anon_id' ); |
| 40 | if ( ! headers_sent() ) { |
| 41 | setcookie( 'tk_ai', 'expired', time() - 1000 ); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | $wpcom_user_data = Jetpack::get_connected_user_data( $user_id ); |
| 46 | update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] ); |
| 47 | |
| 48 | self::record_user_event( 'wpa_user_linked', array() ); |
| 49 | } |
| 50 | |
| 51 | /* Activated module */ |
| 52 | static function track_activate_module( $module ) { |
| 53 | self::record_user_event( 'wpa_module_activated', array( 'module' => $module ) ); |
| 54 | } |
| 55 | |
| 56 | /* Deactivated module */ |
| 57 | static function track_deactivate_module( $module ) { |
| 58 | self::record_user_event( 'wpa_module_deactivated', array( 'module' => $module ) ); |
| 59 | } |
| 60 | |
| 61 | static function record_user_event( $event_type, $data= array() ) { |
| 62 | |
| 63 | $user = wp_get_current_user(); |
| 64 | $site_url = get_option( 'siteurl' ); |
| 65 | |
| 66 | $data['_via_ua'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; |
| 67 | $data['_via_ip'] = isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : ''; |
| 68 | $data['_lg'] = isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; |
| 69 | $data['blog_url'] = $site_url; |
| 70 | $data['blog_id'] = Jetpack_Options::get_option( 'id' ); |
| 71 | |
| 72 | // Top level events should not be namespaced |
| 73 | if ( '_aliasUser' != $event_type ) { |
| 74 | $event_type = self::$product_name . '_' . $event_type; |
| 75 | } |
| 76 | |
| 77 | $data['jetpack_version'] = defined( 'JETPACK__VERSION' ) ? JETPACK__VERSION : '0'; |
| 78 | |
| 79 | jetpack_tracks_record_event( $user, $event_type, $data ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | add_action( 'init', array( 'JetpackTracking', 'track_jetpack_usage' ) ); |
| 84 |