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 |
91.30 | |
0.00% |
0 / 1 |
| get_option | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 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 | // @phan-suppress-next-line PhanPluginDuplicateConditionalNullCoalescing |
| 24 | return isset( $o[ $option_name ] ) ? $o[ $option_name ] : $default; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Get the analytics tracking code. |
| 29 | * |
| 30 | * @return string |
| 31 | */ |
| 32 | public static function get_tracking_code() { |
| 33 | return self::get_option( 'code', '' ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Check if the tracking code is set. |
| 38 | * |
| 39 | * @return bool |
| 40 | */ |
| 41 | public static function has_tracking_code() { |
| 42 | $code = self::get_tracking_code(); |
| 43 | return ! empty( $code ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get the 'anonymize_ip' option used by both legacy and universal analytics. |
| 48 | * |
| 49 | * @return bool |
| 50 | */ |
| 51 | public static function anonymize_ip_is_enabled() { |
| 52 | return (bool) self::get_option( 'anonymize_ip' ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the 'honor_dnt' option used by both legacy and universal analytics. |
| 57 | * |
| 58 | * @return bool |
| 59 | */ |
| 60 | public static function honor_dnt_is_enabled() { |
| 61 | return (bool) static::get_option( 'honor_dnt' ); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get the 'ec_track_purchases' eCommerce option used by both legacy and universal analytics |
| 66 | * |
| 67 | * @return bool |
| 68 | */ |
| 69 | public static function track_purchases_is_enabled() { |
| 70 | return (bool) self::get_option( 'ec_track_purchases' ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get the 'ec_track_add_to_cart' analytics option. |
| 75 | * |
| 76 | * @return bool |
| 77 | */ |
| 78 | public static function track_add_to_cart_is_enabled() { |
| 79 | return (bool) self::get_option( 'ec_track_add_to_cart' ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get the 'enh_ec_tracking' analytics option. |
| 84 | * |
| 85 | * @return bool |
| 86 | */ |
| 87 | public static function enhanced_ecommerce_tracking_is_enabled() { |
| 88 | return (bool) self::get_option( 'enh_ec_tracking' ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the 'enh_ec_track_remove_from_cart' analytics option. |
| 93 | * |
| 94 | * @return bool |
| 95 | */ |
| 96 | public static function track_remove_from_cart_is_enabled() { |
| 97 | return (bool) self::get_option( 'enh_ec_track_remove_from_cart' ); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get the 'enh_ec_track_prod_impression' analytics option. |
| 102 | * |
| 103 | * @return bool |
| 104 | */ |
| 105 | public static function track_product_impressions_is_enabled() { |
| 106 | return (bool) self::get_option( 'enh_ec_track_prod_impression' ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get the 'enh_ec_track_prod_click' analytics option. |
| 111 | * |
| 112 | * @return bool |
| 113 | */ |
| 114 | public static function track_product_clicks_is_enabled() { |
| 115 | return (bool) self::get_option( 'enh_ec_track_prod_click' ); |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get the 'enh_ec_track_prod_detail_view' analytics option. |
| 120 | * |
| 121 | * @return bool |
| 122 | */ |
| 123 | public static function track_product_detail_view_is_enabled() { |
| 124 | return (bool) self::get_option( 'enh_ec_track_prod_detail_view' ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Get the 'enh_ec_track_checkout_started' analytics option. |
| 129 | * |
| 130 | * @return bool |
| 131 | */ |
| 132 | public static function track_checkout_started_is_enabled() { |
| 133 | return (bool) self::get_option( 'enh_ec_track_checkout_started' ); |
| 134 | } |
| 135 | } |