PluginProbe
ShareThis Dashboard for Google Analytics / 3.4.1
ShareThis Dashboard for Google Analytics v3.4.1
3.4.1 3.4.0 3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 All 45 releases
googleanalytics / class / class-ga-frontend.php

class-ga-frontend.php in ShareThis Dashboard for Google Analytics 3.4.1, at class/class-ga-frontend.php

81 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * GoogleAnalytics Frontend.
4 *
5 * @package GoogleAnalytics
6 */
7
8 if (!defined('ABSPATH')) exit;
9
10
11 /**
12 * Frontend.
13 */
14 class Ga_Frontend {
15
16 const GA_SHARETHIS_PLATFORM_URL = '//platform-api.sharethis.com/js/sharethis.js#source=googleanalytics-wordpress';
17
18 /**
19 * Platform ShareThis.
20 *
21 * @return void
22 */
23 public static function platform_sharethis() {
24 $url = self::GA_SHARETHIS_PLATFORM_URL . '#product=ga';
25 if ( get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID ) ) {
26 $url = $url . '&property=' . get_option( Ga_Admin::GA_SHARETHIS_PROPERTY_ID );
27 }
28
29 wp_register_script( GA_NAME . '-platform-sharethis', $url, null, null, false ); // phpcs:ignore
30 wp_enqueue_script( GA_NAME . '-platform-sharethis' );
31 }
32
33 /**
34 * Adds frontend actions hooks.
35 */
36 public static function add_actions() {
37 if ( Ga_Helper::are_features_enabled() ) {
38 add_action( 'wp_enqueue_scripts', 'Ga_Frontend::platform_sharethis' );
39 }
40 add_action( 'wp_head', 'Ga_Frontend::insert_ga_script' );
41 }
42
43 /**
44 * Insert GoogleAnalytics script.
45 *
46 * @return void
47 */
48 public static function insert_ga_script() {
49 if ( true === Ga_Helper::can_add_ga_code() || true === Ga_Helper::is_all_feature_disabled() ) {
50 $web_property_id = self::get_web_property_id();
51 $optimize = get_option( 'googleanalytics_optimize_code' );
52 $anonymization = get_option( 'googleanalytics_ip_anonymization' );
53 $debug_mode_on = 'on' === get_option( 'googleanalytics_enable_debug_mode', 'off' );
54
55 if ( Ga_Helper::should_load_ga_javascript( $web_property_id ) ) {
56 $data = array(
57 Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME => $web_property_id,
58 'optimize' => $optimize,
59 'anonymization' => $anonymization,
60 );
61
62 include plugin_dir_path( __FILE__ ) . '../view/ga-code.php';
63 }
64 }
65 }
66
67 /**
68 * Gets and returns Web Property Id.
69 *
70 * @return string Web Property Id
71 */
72 public static function get_web_property_id() {
73 $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME );
74 if ( true === Ga_Helper::is_code_manually_enabled() || true === Ga_Helper::is_all_feature_disabled() ) {
75 $web_property_id = get_option( Ga_Admin::GA_WEB_PROPERTY_ID_MANUALLY_VALUE_OPTION_NAME );
76 }
77
78 return $web_property_id;
79 }
80 }
81