PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/woocommerce-analytics/class-jetpack-woocommerce-analytics.php +65 -6 12.5.2 → 16.3-a.1 View file →
@@ -5,12 +5,15 @@
5 5 * @package automattic/jetpack
6 6 */
7 7
8 8 if ( ! defined( 'ABSPATH' ) ) {
9 - exit;
9 + exit( 0 );
10 10 }
11 11
12 +require __DIR__ . '/classes/class-jetpack-woocommerce-analytics-trait.php';
12 13 require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-universal.php';
14 +require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-my-account.php';
15 +require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-checkout-flow.php';
13 16
14 17 /**
15 18 * Class Jetpack_WooCommerce_Analytics
16 19 * Instantiate WooCommerce Analytics
@@ -26,13 +29,27 @@
26 29
27 30 /**
28 31 * Instance of the Universal functions
29 32 *
30 - * @var Static property to hold concrete analytics impl that does the work (universal or legacy)
33 + * @var Static property to hold concrete analytics implementation that does the work (universal or legacy)
31 34 */
32 35 private static $analytics = false;
33 36
34 37 /**
38 + * Instance of the My account functions
39 + *
40 + * @var Static property to hold concrete analytics implementation that does the work.
41 + */
42 + private static $myaccount = false;
43 +
44 + /**
45 + * Instance of the Checkout Flow functions
46 + *
47 + * @var Static property to hold concrete analytics implementation that does the work.
48 + */
49 + private static $views = false;
50 +
51 + /**
35 52 * WooCommerce Analytics is only available to Jetpack connected WooCommerce stores with both plugins set to active
36 53 * and WooCommerce version 3.0 or higher
37 54 *
38 55 * @return bool
@@ -49,12 +66,8 @@
49 66 // Tracking only Site pages.
50 67 if ( is_admin() ) {
51 68 return false;
52 69 }
53 - // Don't track site admins.
54 - if ( is_user_logged_in() && in_array( 'administrator', wp_get_current_user()->roles, true ) ) {
55 - return false;
56 - }
57 70 // Make sure Jetpack is installed and connected.
58 71 if ( ! Jetpack::is_connection_ready() ) {
59 72 return false;
60 73 }
@@ -71,9 +84,55 @@
71 84 *
72 85 * @return void
73 86 */
74 87 private function __construct() {
88 + // loading _wca.
89 + add_action( 'wp_head', array( $this, 'wp_head_top' ), 1 );
90 +
91 + // loading s.js.
92 + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_tracking_script' ) );
93 +
75 94 self::$analytics = new Jetpack_WooCommerce_Analytics_Universal();
95 + self::$myaccount = new Jetpack_WooCommerce_Analytics_My_Account();
96 + if ( class_exists( 'Automattic\WooCommerce\Blocks\Package' ) && version_compare( Automattic\WooCommerce\Blocks\Package::get_version(), '11.6.2', '>=' ) ) {
97 + self::$views = new Jetpack_WooCommerce_Analytics_Checkout_Flow();
98 + }
99 + }
100 +
101 + /**
102 + * Make _wca available to queue events
103 + */
104 + public function wp_head_top() {
105 + if ( is_cart() || is_checkout() || is_checkout_pay_page() || is_order_received_page() || is_add_payment_method_page() ) {
106 + echo '<script>window._wca_prevent_referrer = true;</script>' . "\r\n";
107 + }
108 + echo '<script>window._wca = window._wca || [];</script>' . "\r\n";
109 + }
110 +
111 + /**
112 + * Place script to call s.js, Store Analytics.
113 + */
114 + public function enqueue_tracking_script() {
115 + // No store activity to track on 404 pages.
116 + if ( is_404() ) {
117 + return;
118 + }
119 +
120 + $url = sprintf(
121 + 'https://stats.wp.com/s-%d.js',
122 + gmdate( 'YW' )
123 + );
124 +
125 + wp_enqueue_script(
126 + 'woocommerce-analytics',
127 + $url,
128 + array(),
129 + null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- The version is set in the URL.
130 + array(
131 + 'in_footer' => false,
132 + 'strategy' => 'defer',
133 + )
134 + );
76 135 }
77 136
78 137 /**
79 138 * Function to instantiate our class and make it a singleton