From f8d70506a13c9266467f671f80424a4873ececf4 Mon Sep 17 00:00:00 2001 From: Timmy Crawford Date: Mon, 22 Oct 2018 08:56:02 -0700 Subject: [PATCH] Update/track usage logic (https://github.com/woocommerce/woocommerce-admin/pull/561) * Tracks: Don't track if Jetpack is not present or in dev env. * Check for JETPACK__VERSION instead. * Fix linting errors * Yoda conditions use you must --- plugins/woocommerce-admin/client/lib/tracks.js | 2 +- plugins/woocommerce-admin/lib/client-assets.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/woocommerce-admin/client/lib/tracks.js b/plugins/woocommerce-admin/client/lib/tracks.js index 21d66ea8e9c..f3e1a87a484 100644 --- a/plugins/woocommerce-admin/client/lib/tracks.js +++ b/plugins/woocommerce-admin/client/lib/tracks.js @@ -8,7 +8,7 @@ */ export function recordEvent( eventName, eventProperties ) { - if ( ! wcSettings.trackingEnabled ) { + if ( ! wcSettings.trackingEnabled || 'development' === process.env.NODE_ENV ) { return false; } diff --git a/plugins/woocommerce-admin/lib/client-assets.php b/plugins/woocommerce-admin/lib/client-assets.php index 1b03a600637..8cb2ed6f9a0 100644 --- a/plugins/woocommerce-admin/lib/client-assets.php +++ b/plugins/woocommerce-admin/lib/client-assets.php @@ -23,7 +23,7 @@ function wc_admin_register_script() { wp_register_script( 'wc-components', wc_admin_url( 'dist/components.js' ), - [ 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes' ], + array( 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes' ), filemtime( wc_admin_dir_path( 'dist/components.js' ) ), true ); @@ -31,14 +31,14 @@ function wc_admin_register_script() { wp_register_style( 'wc-components', wc_admin_url( 'dist/css/components.css' ), - [ 'wp-edit-blocks' ], + array( 'wp-edit-blocks' ), filemtime( wc_admin_dir_path( 'dist/css/components.css' ) ) ); wp_register_script( WC_ADMIN_APP, wc_admin_url( $js_entry ), - [ 'wc-components', 'wp-date', 'wp-html-entities', 'wp-keycodes' ], + array( 'wc-components', 'wp-date', 'wp-html-entities', 'wp-keycodes' ), filemtime( wc_admin_dir_path( $js_entry ) ), true ); @@ -46,7 +46,7 @@ function wc_admin_register_script() { wp_register_style( WC_ADMIN_APP, wc_admin_url( $css_entry ), - [ 'wc-components' ], + array( 'wc-components' ), filemtime( wc_admin_dir_path( $css_entry ) ) ); @@ -55,9 +55,9 @@ function wc_admin_register_script() { $content = 'wp.i18n.setLocaleData( ' . json_encode( $locale_data ) . ', "wc-admin" );'; wp_add_inline_script( 'wc-components', $content, 'before' ); - // Add Tracks script to the DOM if tracking is opted in. + // Add Tracks script to the DOM if tracking is opted in, and Jetpack is installed/activated. $tracking_enabled = 'yes' === get_option( 'woocommerce_allow_tracking', 'no' ); - if ( $tracking_enabled ) { + if ( $tracking_enabled && defined( 'JETPACK__VERSION' ) ) { $tracking_script = "var wc_tracking_script = document.createElement( 'script' );\n"; $tracking_script .= "wc_tracking_script.src = '//stats.wp.com/w.js';\n"; // TODO Version/cache buster. $tracking_script .= "wc_tracking_script.type = 'text/javascript';\n";