Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
26.67% |
4 / 15 |
|
23.08% |
3 / 13 |
CRAP | |
0.00% |
0 / 1 |
| Options | |
26.67% |
4 / 15 |
|
23.08% |
3 / 13 |
79.65 | |
0.00% |
0 / 1 |
| get_option | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| get_tracking_code | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| has_tracking_code | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| anonymize_ip_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| honor_dnt_is_enabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| track_purchases_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_add_to_cart_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| enhanced_ecommerce_tracking_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_remove_from_cart_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_product_impressions_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_product_clicks_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_product_detail_view_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| track_checkout_started_is_enabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The class provides a single interface to package options. |
| 4 | * |
| 5 | * @package automattic/jetpack-google-analytics |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Google_Analytics; |
| 9 | |
| 10 | /** |
| 11 | * The class provides a single interface to package options. |
| 12 | */ |
| 13 | class Options { |
| 14 | /** |
| 15 | * Get the Google Analytics tracking ID. |
| 16 | * |
| 17 | * @param string $option_name Nested 'jetpack_wga' option value to retrieve. |
| 18 | * @param mixed $default Default value if $option is not set. |
| 19 | * @return mixed Option value or `$default`. |
| 20 | */ |
| 21 | public static function get_option( $option_name, $default = false ) { |
| 22 | $o = get_option( 'jetpack_wga' ); |
| 23 | return $o[ $option_name ] ?? $default; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get the analytics tracking code. |
| 28 | * |
| 29 | * @return string |
| 30 | */ |
| 31 | public static function get_tracking_code() { |
| 32 | return self::get_option( 'code', '' ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Check if the tracking code is set. |
| 37 | * |
| 38 | * @return bool |
| 39 | */ |
| 40 | public static function has_tracking_code() { |
| 41 | $code = self::get_tracking_code(); |
| 42 | return ! empty( $code ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get the 'anonymize_ip' option used by both legacy and universal analytics. |
| 47 | * |
| 48 | * @return bool |
| 49 | */ |
| 50 | public static function anonymize_ip_is_enabled() { |
| 51 | return (bool) self::get_option( 'anonymize_ip' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Get the 'honor_dnt' option used by both legacy and universal analytics. |
| 56 | * |
| 57 | * @return bool |
| 58 | */ |
| 59 | public static function honor_dnt_is_enabled() { |
| 60 | return (bool) static::get_option( 'honor_dnt' ); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Get the 'ec_track_purchases' eCommerce option used by both legacy and universal analytics |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | public static function track_purchases_is_enabled() { |
| 69 | return (bool) self::get_option( 'ec_track_purchases' ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Get the 'ec_track_add_to_cart' analytics option. |
| 74 | * |
| 75 | * @return bool |
| 76 | */ |
| 77 | public static function track_add_to_cart_is_enabled() { |
| 78 | return (bool) self::get_option( 'ec_track_add_to_cart' ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Get the 'enh_ec_tracking' analytics option. |
| 83 | * |
| 84 | * @return bool |
| 85 | */ |
| 86 | public static function enhanced_ecommerce_tracking_is_enabled() { |
| 87 | return (bool) self::get_option( 'enh_ec_tracking' ); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Get the 'enh_ec_track_remove_from_cart' analytics option. |
| 92 | * |
| 93 | * @return bool |
| 94 | */ |
| 95 | public static function track_remove_from_cart_is_enabled() { |
| 96 | return (bool) self::get_option( 'enh_ec_track_remove_from_cart' ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the 'enh_ec_track_prod_impression' analytics option. |
| 101 | * |
| 102 | * @return bool |
| 103 | */ |
| 104 | public static function track_product_impressions_is_enabled() { |
| 105 | return (bool) self::get_option( 'enh_ec_track_prod_impression' ); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the 'enh_ec_track_prod_click' analytics option. |
| 110 | * |
| 111 | * @return bool |
| 112 | */ |
| 113 | public static function track_product_clicks_is_enabled() { |
| 114 | return (bool) self::get_option( 'enh_ec_track_prod_click' ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Get the 'enh_ec_track_prod_detail_view' analytics option. |
| 119 | * |
| 120 | * @return bool |
| 121 | */ |
| 122 | public static function track_product_detail_view_is_enabled() { |
| 123 | return (bool) self::get_option( 'enh_ec_track_prod_detail_view' ); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Get the 'enh_ec_track_checkout_started' analytics option. |
| 128 | * |
| 129 | * @return bool |
| 130 | */ |
| 131 | public static function track_checkout_started_is_enabled() { |
| 132 | return (bool) self::get_option( 'enh_ec_track_checkout_started' ); |
| 133 | } |
| 134 | } |