| 1 |
<?php |
| 2 |
/** |
| 3 |
* Analytics. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Admin; |
| 9 |
|
| 10 |
use const WCPOS\WooCommercePOS\PLUGIN_NAME; |
| 11 |
use const WCPOS\WooCommercePOS\PLUGIN_URL; |
| 12 |
use const WCPOS\WooCommercePOS\TRANSLATION_VERSION; |
| 13 |
use const WCPOS\WooCommercePOS\VERSION; |
| 14 |
|
| 15 |
/** |
| 16 |
* Analytics class. |
| 17 |
*/ |
| 18 |
class Analytics { |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructor. |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 25 |
add_action( 'admin_head', array( $this, 'analytics_css' ) ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Add CSS to the admin head |
| 30 |
*/ |
| 31 |
public function analytics_css() { |
| 32 |
echo '<style>.woocommerce-pos-upgrade-notice { margin: 0 0 24px 0; }</style>'; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Enqueue analytics assets. |
| 37 |
*/ |
| 38 |
public function enqueue_assets() { |
| 39 |
$is_development = isset( $_ENV['DEVELOPMENT'] ) |
| 40 |
&& wp_validate_boolean( sanitize_text_field( wp_unslash( $_ENV['DEVELOPMENT'] ) ) ); |
| 41 |
$dir = $is_development ? 'build' : 'assets'; |
| 42 |
|
| 43 |
// Inject translation version for i18next. |
| 44 |
wp_add_inline_script( |
| 45 |
'wp-hooks', |
| 46 |
'window.wcpos = window.wcpos || {}; window.wcpos.translationVersion = "' . esc_js( TRANSLATION_VERSION ) . '";', |
| 47 |
'before' |
| 48 |
); |
| 49 |
|
| 50 |
wp_enqueue_script( |
| 51 |
PLUGIN_NAME . '-analytics', |
| 52 |
PLUGIN_URL . $dir . '/js/analytics.js', |
| 53 |
array( |
| 54 |
'wp-hooks', |
| 55 |
'wc-components', |
| 56 |
), |
| 57 |
VERSION, |
| 58 |
true |
| 59 |
); |
| 60 |
|
| 61 |
wp_add_inline_script( PLUGIN_NAME . '-analytics', Menu::get_posthog_inline_script(), 'before' ); |
| 62 |
} |
| 63 |
} |
| 64 |
|