Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
WooCommerce_Analytics_Tracker
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 configure
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 bootstrap
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * Wires up the WooCommerce Analytics front-end tracker for Premium Analytics.
4 *
5 * @package automattic/jetpack-premium-analytics
6 */
7
8namespace Automattic\Jetpack\PremiumAnalytics;
9
10use Automattic\Woocommerce_Analytics;
11
12/**
13 * Turns on the modern (ClickHouse + proxy) pipeline and triggers the vendored
14 * WooCommerce Analytics tracker, which self-gates on WooCommerce + connection
15 * and is idempotent.
16 */
17class WooCommerce_Analytics_Tracker {
18
19    /**
20     * Register the tracker bootstrap.
21     */
22    public static function configure() {
23        add_action( 'after_setup_theme', array( __CLASS__, 'bootstrap' ) );
24    }
25
26    /**
27     * Enable the modern pipeline and trigger the tracker.
28     *
29     * On `after_setup_theme` the filters are in place before the package reads
30     * them while localizing `window.wcAnalytics` at `wp_footer`.
31     */
32    public static function bootstrap() {
33        add_filter( 'woocommerce_analytics_clickhouse_enabled', '__return_true' );
34        add_filter( 'woocommerce_analytics_experimental_proxy_tracking_enabled', '__return_true' );
35
36        // Guarded because the package ships with the Jetpack plugin or as a
37        // composer dependency, not with premium-analytics' own source.
38        if ( class_exists( Woocommerce_Analytics::class ) ) {
39            Woocommerce_Analytics::init();
40        }
41    }
42}