1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
Copyright 2006 Aaron D. Campbell (email : [email protected]) |
4
|
|
|
|
5
|
|
|
This program is free software; you can redistribute it and/or modify |
6
|
|
|
it under the terms of the GNU General Public License as published by |
7
|
|
|
the Free Software Foundation; either version 2 of the License, or |
8
|
|
|
(at your option) any later version. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13
|
|
|
GNU General Public License for more details. |
14
|
|
|
|
15
|
|
|
You should have received a copy of the GNU General Public License |
16
|
|
|
along with this program; if not, write to the Free Software |
17
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Jetpack_Google_Analytics is the class that handles ALL of the plugin functionality. |
22
|
|
|
* It helps us avoid name collisions |
23
|
|
|
* http://codex.wordpress.org/Writing_a_Plugin#Avoiding_Function_Name_Collisions |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
27
|
|
|
exit; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
require_once( plugin_basename( 'classes/wp-google-analytics-utils.php' ) ); |
31
|
|
|
require_once( plugin_basename( 'classes/wp-google-analytics-options.php' ) ); |
32
|
|
|
require_once( plugin_basename( 'classes/wp-google-analytics-legacy.php' ) ); |
33
|
|
|
require_once( plugin_basename( 'classes/wp-google-analytics-universal.php' ) ); |
34
|
|
|
|
35
|
|
|
class Jetpack_Google_Analytics { |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Jetpack_Google_Analytics - Static property to hold our singleton instance |
39
|
|
|
*/ |
40
|
|
|
static $instance = false; |
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Static property to hold concrete analytics impl that does the work (universal or legacy) |
44
|
|
|
*/ |
45
|
|
|
static $analytics = false; |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* This is our constructor, which is private to force the use of get_instance() |
49
|
|
|
* |
50
|
|
|
* @return void |
|
|
|
|
51
|
|
|
*/ |
52
|
|
|
private function __construct() { |
53
|
|
|
/** |
54
|
|
|
* Allow for universal analytics (analytics.js) to be used outside of ecommerce contexts |
55
|
|
|
* |
56
|
|
|
* @since 6.1.0 |
57
|
|
|
* |
58
|
|
|
* @param bool Whether universal analytics (analytics.js) should be used (true) or legacy (ga.js) should be used (false) |
59
|
|
|
*/ |
60
|
|
|
$use_universal_analytics = apply_filters( 'jetpack_wga_use_universal_analytics', |
61
|
|
|
Jetpack_Google_Analytics_Options::enhanced_ecommerce_tracking_is_enabled() |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
if ( $use_universal_analytics ) { |
65
|
|
|
$analytics = new Jetpack_Google_Analytics_Universal(); |
|
|
|
|
66
|
|
|
} else { |
67
|
|
|
$analytics = new Jetpack_Google_Analytics_Legacy(); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Function to instantiate our class and make it a singleton |
74
|
|
|
*/ |
75
|
|
|
public static function get_instance() { |
76
|
|
|
if ( ! self::$instance ) { |
77
|
|
|
self::$instance = new self; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return self::$instance; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Bootstrap analytics on the init action. This allows filtering of things like |
86
|
|
|
* jetpack_wga_use_universal_analytics |
87
|
|
|
* |
88
|
|
|
* @since 6.1.0 |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
function jetpack_wga_init() { |
93
|
|
|
global $jetpack_google_analytics; |
94
|
|
|
$jetpack_google_analytics = Jetpack_Google_Analytics::get_instance(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
add_action( 'init', 'jetpack_wga_init' ); |
98
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.