Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| WooCommerce_Analytics_Tracker | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| configure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| bootstrap | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Wires up the WooCommerce Analytics front-end tracker for the WooCommerce section. |
| 4 | * |
| 5 | * @package automattic/jetpack-woocommerce-stats |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\WooCommerceStats; |
| 9 | |
| 10 | use Automattic\Woocommerce_Analytics; |
| 11 | |
| 12 | /** |
| 13 | * Turns on ClickHouse and triggers the vendored WooCommerce Analytics tracker, |
| 14 | * unless the host turns store tracking off. Proxy tracking is the host's to turn on. |
| 15 | * The tracker self-gates on WooCommerce + connection and is idempotent. |
| 16 | */ |
| 17 | class WooCommerce_Analytics_Tracker { |
| 18 | |
| 19 | /** |
| 20 | * Filter a host answers to turn store tracking off, as the Jetpack plugin does while its module is off. |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | const ENABLED_FILTER = 'jetpack_woocommerce_stats_store_tracking_enabled'; |
| 25 | |
| 26 | /** |
| 27 | * Register the tracker bootstrap. |
| 28 | */ |
| 29 | public static function configure() { |
| 30 | add_action( 'after_setup_theme', array( __CLASS__, 'bootstrap' ) ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Turn on ClickHouse and trigger the tracker. |
| 35 | * |
| 36 | * On `after_setup_theme` the filter is in place before the package reads |
| 37 | * it while localizing `window.wcAnalytics` at `wp_footer`. |
| 38 | */ |
| 39 | public static function bootstrap() { |
| 40 | /** |
| 41 | * Filters whether WooCommerce Stats starts WooCommerce Analytics store tracking. |
| 42 | * |
| 43 | * @since $$next-version$$ |
| 44 | * |
| 45 | * @param bool $enabled Whether store tracking is on. Default true. |
| 46 | */ |
| 47 | if ( ! apply_filters( self::ENABLED_FILTER, true ) ) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | add_filter( 'woocommerce_analytics_clickhouse_enabled', '__return_true' ); |
| 52 | |
| 53 | // Guarded because the package ships with the Jetpack plugin or as a |
| 54 | // composer dependency, not with this package's own source. |
| 55 | if ( class_exists( Woocommerce_Analytics::class ) ) { |
| 56 | Woocommerce_Analytics::init(); |
| 57 | } |
| 58 | } |
| 59 | } |