controller
5 years ago
core
5 years ago
Ga_Admin.php
4 years ago
Ga_Autoloader.php
4 years ago
Ga_Frontend.php
5 years ago
Ga_Helper.php
4 years ago
Ga_Hook.php
4 years ago
Ga_Notice.php
6 years ago
Ga_Sharethis.php
6 years ago
Ga_Stats.php
4 years ago
Ga_Template.php
4 years ago
Ga_Frontend.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | class Ga_Frontend { |
| 4 | |
| 5 | const GA_SHARETHIS_PLATFORM_URL = '//platform-api.sharethis.com/js/sharethis.js'; |
| 6 | |
| 7 | public static function platform_sharethis() { |
| 8 | $url = self::GA_SHARETHIS_PLATFORM_URL . '#product=ga'; |
| 9 | if ( get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ) ) { |
| 10 | $url = $url . '&property=' . get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ); |
| 11 | } |
| 12 | wp_register_script( GA_NAME . '-platform-sharethis', $url, null, null, false ); |
| 13 | wp_enqueue_script( GA_NAME . '-platform-sharethis' ); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Adds frontend actions hooks. |
| 18 | */ |
| 19 | public static function add_actions() { |
| 20 | if ( Ga_Helper::are_features_enabled() ) { |
| 21 | add_action( 'wp_enqueue_scripts', 'Ga_Frontend::platform_sharethis' ); |
| 22 | } |
| 23 | add_action( 'wp_head', 'Ga_Frontend::insert_ga_script' ); |
| 24 | } |
| 25 | |
| 26 | public static function insert_ga_script() { |
| 27 | if ( Ga_Helper::can_add_ga_code() || Ga_Helper::is_all_feature_disabled() ) { |
| 28 | $web_property_id = Ga_Frontend::get_web_property_id(); |
| 29 | $optimize = get_option( 'googleanalytics_optimize_code' ); |
| 30 | $anonymization = get_option( 'googleanalytics_ip_anonymization' ); |
| 31 | |
| 32 | if ( Ga_Helper::should_load_ga_javascript( $web_property_id ) ) { |
| 33 | $data = array( |
| 34 | Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME => $web_property_id, |
| 35 | 'optimize' => $optimize, |
| 36 | 'anonymization' => $anonymization, |
| 37 | ); |
| 38 | |
| 39 | include plugin_dir_path( __FILE__ ) . '../view/ga_code.php'; |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Gets and returns Web Property Id. |
| 46 | * |
| 47 | * @return string Web Property Id |
| 48 | */ |
| 49 | public static function get_web_property_id() { |
| 50 | $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME ); |
| 51 | if ( Ga_Helper::is_code_manually_enabled() || Ga_Helper::is_all_feature_disabled() ) { |
| 52 | $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_MANUALLY_VALUE_OPTION_NAME ); |
| 53 | } |
| 54 | |
| 55 | return $web_property_id; |
| 56 | } |
| 57 | |
| 58 | } |
| 59 |