2022-06-16 14:01:47 +02:00
|
|
|
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileNames
|
2019-11-15 23:26:29 +01:00
|
|
|
/**
|
2022-06-16 14:01:47 +02:00
|
|
|
* Jetpack_Google_Analytics_Options provides a single interface to module options
|
|
|
|
|
*
|
|
|
|
|
* @author allendav
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
|
|
|
|
|
/**
|
2022-06-16 14:01:47 +02:00
|
|
|
* Bail if accessed directly
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Jetpack_Google_Analytics_Options main class.
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
class Jetpack_Google_Analytics_Options {
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the Google Analytics tracking ID.
|
|
|
|
|
*
|
|
|
|
|
* @param string $option_name Nested 'jetpack_wga' option value to retrieve.
|
|
|
|
|
* @param mixed $default Default value if $option is not set.
|
|
|
|
|
* @return mixed Option value or `$default`.
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function get_option( $option_name, $default = false ) {
|
|
|
|
|
$o = get_option( 'jetpack_wga' );
|
|
|
|
|
return isset( $o[ $option_name ] ) ? $o[ $option_name ] : $default;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the analytics tracking code.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function get_tracking_code() {
|
|
|
|
|
return self::get_option( 'code', '' );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Check if the tracking code is set.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function has_tracking_code() {
|
|
|
|
|
$code = self::get_tracking_code();
|
|
|
|
|
return ! empty( $code );
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'anonymize_ip' option used by both legacy and universal analytics.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function anonymize_ip_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'anonymize_ip' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'ec_track_purchases' eCommerce option used by both legacy and universal analytics
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_purchases_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'ec_track_purchases' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'ec_track_add_to_cart' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_add_to_cart_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'ec_track_add_to_cart' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_tracking' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function enhanced_ecommerce_tracking_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_tracking' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_track_remove_from_cart' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_remove_from_cart_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_track_remove_from_cart' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_track_prod_impression' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_product_impressions_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_track_prod_impression' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_track_prod_click' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_product_clicks_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_track_prod_click' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_track_prod_detail_view' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_product_detail_view_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_track_prod_detail_view' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 14:01:47 +02:00
|
|
|
/**
|
|
|
|
|
* Get the 'enh_ec_track_checkout_started' analytics option.
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-11-15 23:26:29 +01:00
|
|
|
public static function track_checkout_started_is_enabled() {
|
2022-06-16 14:01:47 +02:00
|
|
|
return (bool) self::get_option( 'enh_ec_track_checkout_started' );
|
2019-11-15 23:26:29 +01:00
|
|
|
}
|
|
|
|
|
}
|