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 +54 -1 12.7.316.3-a.1 View file →
@@ -5,14 +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 12 require __DIR__ . '/classes/class-jetpack-woocommerce-analytics-trait.php';
13 13 require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-universal.php';
14 14 require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-my-account.php';
15 +require_once __DIR__ . '/classes/class-jetpack-woocommerce-analytics-checkout-flow.php';
15 16
16 17 /**
17 18 * Class Jetpack_WooCommerce_Analytics
18 19 * Instantiate WooCommerce Analytics
@@ -40,8 +41,15 @@
40 41 */
41 42 private static $myaccount = false;
42 43
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 + /**
44 52 * WooCommerce Analytics is only available to Jetpack connected WooCommerce stores with both plugins set to active
45 53 * and WooCommerce version 3.0 or higher
46 54 *
47 55 * @return bool
@@ -76,10 +84,55 @@
76 84 *
77 85 * @return void
78 86 */
79 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 +
80 94 self::$analytics = new Jetpack_WooCommerce_Analytics_Universal();
81 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 + );
82 135 }
83 136
84 137 /**
85 138 * Function to instantiate our class and make it a singleton