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