Version Description
- Bugfix for caching plugins
Download this release
Release Info
Developer | webkinder |
Plugin | Google Analytics |
Version | 1.7.3 |
Comparing to | |
See all releases |
Code changes from version 1.7.2 to 1.7.3
- Classes/Loader.php +204 -149
- Classes/Plugin.php +56 -55
- readme.txt +8 -4
- wk-ga.php +1 -1
Classes/Loader.php
CHANGED
@@ -2,153 +2,208 @@
|
|
2 |
|
3 |
namespace WebKinder\GoogleAnalytics;
|
4 |
|
5 |
-
class Loader
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
}
|
2 |
|
3 |
namespace WebKinder\GoogleAnalytics;
|
4 |
|
5 |
+
class Loader
|
6 |
+
{
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Returns if the cookie is present
|
10 |
+
*
|
11 |
+
* @since 1.2
|
12 |
+
* @return boolean
|
13 |
+
*
|
14 |
+
*/
|
15 |
+
function render_script()
|
16 |
+
{
|
17 |
+
ob_start();
|
18 |
+
?>
|
19 |
+
<script>
|
20 |
+
function hasWKGoogleAnalyticsCookie() {
|
21 |
+
return (new RegExp('wp_wk_ga_untrack_' + document.location.hostname)).test(document.cookie);
|
22 |
+
}
|
23 |
+
</script>
|
24 |
+
<?php
|
25 |
+
return ob_get_clean();
|
26 |
+
}
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Outputs a js function that allows a cached page to check if the user should be tracked
|
30 |
+
*/
|
31 |
+
public function output_should_track_js_function(){
|
32 |
+
?>
|
33 |
+
<script>
|
34 |
+
function shouldTrack(){
|
35 |
+
var trackLoggedIn = <?php echo (get_option('track_logged_in') ? 'true' : 'false'); ?>;
|
36 |
+
var loggedIn = jQuery("body").hasClass("logged-in");
|
37 |
+
if(!loggedIn){
|
38 |
+
return true;
|
39 |
+
} else if( trackLoggedIn ) {
|
40 |
+
return true;
|
41 |
+
}
|
42 |
+
return false;
|
43 |
+
}
|
44 |
+
</script>
|
45 |
+
<?php
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Outputs the Google Tag Manager script tag if necessary
|
50 |
+
*
|
51 |
+
* @since 1.2
|
52 |
+
*
|
53 |
+
*/
|
54 |
+
function google_tag_manager_script()
|
55 |
+
{
|
56 |
+
ob_start();
|
57 |
+
if (get_option('ga_use_tag_manager')) {
|
58 |
+
$TAG_MANAGER_ID = get_option('ga_tag_manager_id');
|
59 |
+
|
60 |
+
$this->output_should_track_js_function();
|
61 |
+
?>
|
62 |
+
<script>
|
63 |
+
if (!hasWKGoogleAnalyticsCookie() && shouldTrack()) {
|
64 |
+
//Google Tag Manager
|
65 |
+
(function (w, d, s, l, i) {
|
66 |
+
w[l] = w[l] || [];
|
67 |
+
w[l].push({
|
68 |
+
'gtm.start':
|
69 |
+
new Date().getTime(), event: 'gtm.js'
|
70 |
+
});
|
71 |
+
var f = d.getElementsByTagName(s)[0],
|
72 |
+
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
|
73 |
+
j.async = true;
|
74 |
+
j.src =
|
75 |
+
'//www.googletagmanager.com/gtm.js?id=' + i + dl;
|
76 |
+
f.parentNode.insertBefore(j, f);
|
77 |
+
})(window, document, 'script', 'dataLayer', '<?php echo $TAG_MANAGER_ID; ?>');
|
78 |
+
}
|
79 |
+
</script>
|
80 |
+
<?php
|
81 |
+
}
|
82 |
+
return ob_get_clean();
|
83 |
+
}
|
84 |
+
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Outputs the Google Tag Manager noscript tag if necessary
|
88 |
+
*
|
89 |
+
* @since 1.6
|
90 |
+
*
|
91 |
+
*/
|
92 |
+
function google_tag_manager_noscript()
|
93 |
+
{
|
94 |
+
ob_start();
|
95 |
+
if (get_option('ga_use_tag_manager')) {
|
96 |
+
$TAG_MANAGER_ID = get_option('ga_tag_manager_id');
|
97 |
+
?>
|
98 |
+
<noscript>
|
99 |
+
<iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $TAG_MANAGER_ID; ?>"
|
100 |
+
height="0" width="0" style="display:none;visibility:hidden"></iframe>
|
101 |
+
</noscript>
|
102 |
+
|
103 |
+
<?php
|
104 |
+
}
|
105 |
+
return ob_get_clean();
|
106 |
+
}
|
107 |
+
|
108 |
+
|
109 |
+
/**
|
110 |
+
* Outputs the Google Analytics script if necessary
|
111 |
+
*
|
112 |
+
* @since 1.2
|
113 |
+
* @see https://developers.google.com/analytics/devguides/collection/analyticsjs/ip-anonymization
|
114 |
+
*
|
115 |
+
*/
|
116 |
+
function google_analytics_script()
|
117 |
+
{
|
118 |
+
ob_start();
|
119 |
+
if (!get_option('ga_use_tag_manager')) {
|
120 |
+
$GA_TRACKING_CODE = get_option('ga_tracking_code');
|
121 |
+
$ANONYMIZE_IP = (get_option('ga_anonymize_ip') !== false) ? (boolean)get_option('ga_anonymize_ip') : true;
|
122 |
+
$this->output_should_track_js_function();
|
123 |
+
?>
|
124 |
+
<script>
|
125 |
+
if (!hasWKGoogleAnalyticsCookie() && shouldTrack()) {
|
126 |
+
//Google Analytics
|
127 |
+
(function (i, s, o, g, r, a, m) {
|
128 |
+
i['GoogleAnalyticsObject'] = r;
|
129 |
+
i[r] = i[r] || function () {
|
130 |
+
(i[r].q = i[r].q || []).push(arguments)
|
131 |
+
}, i[r].l = 1 * new Date();
|
132 |
+
a = s.createElement(o),
|
133 |
+
m = s.getElementsByTagName(o)[0];
|
134 |
+
a.async = 1;
|
135 |
+
a.src = g;
|
136 |
+
m.parentNode.insertBefore(a, m)
|
137 |
+
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
138 |
+
ga('create', '<?php echo $GA_TRACKING_CODE; ?>', 'auto');
|
139 |
+
|
140 |
+
<?php
|
141 |
+
if( $ANONYMIZE_IP ) :
|
142 |
+
?>
|
143 |
+
ga('set', 'anonymizeIp', true);
|
144 |
+
<?php
|
145 |
+
endif;
|
146 |
+
?>
|
147 |
+
|
148 |
+
ga('send', 'pageview');
|
149 |
+
}
|
150 |
+
</script>
|
151 |
+
<?php
|
152 |
+
}
|
153 |
+
return ob_get_clean();
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Registers frontend scripts
|
158 |
+
*/
|
159 |
+
function register_ga_scripts()
|
160 |
+
{
|
161 |
+
//cookie function
|
162 |
+
echo $this->render_script();
|
163 |
+
|
164 |
+
//Google Analytics script in <head>
|
165 |
+
echo $this->google_tag_manager_script();
|
166 |
+
|
167 |
+
//Google Analytics script in <head>
|
168 |
+
echo $this->google_analytics_script();
|
169 |
+
}
|
170 |
+
|
171 |
+
/**
|
172 |
+
* Registers cookie scripts for opt out shortcode
|
173 |
+
*/
|
174 |
+
function register_public_scripts()
|
175 |
+
{
|
176 |
+
//cookie library
|
177 |
+
wp_register_script('cookie-js', plugins_url(plugin_basename(WK_GOOGLE_ANALYTICS_DIR)) . '/js/js.cookie.js');
|
178 |
+
|
179 |
+
//admin js for cookies
|
180 |
+
wp_register_script('wk-ga-admin-js', plugins_url(plugin_basename(WK_GOOGLE_ANALYTICS_DIR)) . '/js/admin-functions.js', array('jquery', 'cookie-js'));
|
181 |
+
|
182 |
+
//translate JavaScript
|
183 |
+
$translation_array = array(
|
184 |
+
'TrackText' => __('Do not track any visits from this device.', 'wk-google-analytics')
|
185 |
+
);
|
186 |
+
wp_localize_script('wk-ga-admin-js', 'text_content', $translation_array);
|
187 |
+
}
|
188 |
+
|
189 |
+
|
190 |
+
/**
|
191 |
+
* Loads all the admin scripts for settings page
|
192 |
+
*
|
193 |
+
* @since 1.0
|
194 |
+
* @see https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
|
195 |
+
* @see https://github.com/js-cookie/js-cookie
|
196 |
+
*
|
197 |
+
*/
|
198 |
+
function load_admin_styles($hook)
|
199 |
+
{
|
200 |
+
|
201 |
+
if ($hook != "settings_page_google_analytics") {
|
202 |
+
return;
|
203 |
+
}
|
204 |
+
|
205 |
+
//admin styles
|
206 |
+
wp_enqueue_style('custom-admin-styles', plugins_url(plugin_basename(WK_GOOGLE_ANALYTICS_DIR)) . '/css/admin-styles.css');
|
207 |
+
|
208 |
+
}
|
209 |
}
|
Classes/Plugin.php
CHANGED
@@ -2,76 +2,75 @@
|
|
2 |
|
3 |
namespace WebKinder\GoogleAnalytics;
|
4 |
|
5 |
-
class Plugin
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
$this->settings = new Settings();
|
19 |
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
add_action( 'admin_enqueue_scripts', array( $this->loader, 'load_admin_styles' ) );
|
29 |
-
add_action( 'wp_enqueue_scripts', array( $this->loader, 'register_public_scripts' ) );
|
30 |
-
add_action( 'admin_enqueue_scripts', array( $this->loader, 'register_public_scripts' ) );
|
31 |
-
//cookie function
|
32 |
-
add_action( 'wp_head', array( $this->loader, 'render_script') );
|
33 |
-
//Google Analytics script in <head>
|
34 |
-
add_action( 'wp_head', array( $this->loader, 'google_analytics_script') );
|
35 |
-
//Google Tag Manager script in header
|
36 |
-
add_action( 'wp_head', array( $this->loader, 'google_tag_manager_script'));
|
37 |
-
//Google Tag Manager noscript footer
|
38 |
-
add_action( 'wp_footer', array( $this->loader, 'google_tag_manager_noscript'));
|
39 |
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
|
46 |
-
|
47 |
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
|
62 |
-
|
63 |
|
64 |
-
|
65 |
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
function load_textdomain()
|
74 |
-
|
|
|
75 |
}
|
76 |
|
77 |
/**
|
@@ -79,7 +78,8 @@ class Plugin {
|
|
79 |
* @param $content
|
80 |
* @return string
|
81 |
*/
|
82 |
-
function add_privacy_policy_default_text($content)
|
|
|
83 |
$content .= self::get_ga_policy_text();
|
84 |
return $content;
|
85 |
}
|
@@ -88,7 +88,8 @@ class Plugin {
|
|
88 |
* Get the text for GA
|
89 |
* @return string
|
90 |
*/
|
91 |
-
static function get_ga_policy_text()
|
|
|
92 |
ob_start();
|
93 |
include WK_GOOGLE_ANALYTICS_DIR . '/Content/privacy_policy.php';
|
94 |
$content = ob_get_clean();
|
2 |
|
3 |
namespace WebKinder\GoogleAnalytics;
|
4 |
|
5 |
+
class Plugin
|
6 |
+
{
|
7 |
|
8 |
+
public function run()
|
9 |
+
{
|
10 |
+
//i18n
|
11 |
+
add_action('plugins_loaded', array($this, 'load_textdomain'));
|
12 |
|
13 |
+
//opt-out button
|
14 |
+
include_once 'OptOutButton.php';
|
15 |
+
OptOutButton::init();
|
16 |
|
17 |
+
//settings
|
18 |
+
include_once 'Settings.php';
|
19 |
+
$this->settings = new Settings();
|
20 |
|
21 |
+
add_action('admin_init', array($this->settings, 'register_settings'));
|
22 |
+
add_action('admin_menu', array($this->settings, 'settings_page'));
|
|
|
23 |
|
24 |
+
//loader
|
25 |
+
include_once 'Loader.php';
|
26 |
+
$this->loader = new Loader();
|
27 |
|
28 |
+
//cookie handling
|
29 |
+
add_action('admin_enqueue_scripts', array($this->loader, 'load_admin_styles'));
|
30 |
+
add_action('wp_enqueue_scripts', array($this->loader, 'register_public_scripts'));
|
31 |
+
add_action('admin_enqueue_scripts', array($this->loader, 'register_public_scripts'));
|
32 |
|
33 |
+
add_action('wp_head', array($this->loader, 'register_ga_scripts'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
//Google Tag Manager noscript footer
|
36 |
+
add_action('wp_footer', array($this->loader, 'google_tag_manager_noscript'));
|
37 |
|
38 |
+
//additional links to admin plugin page
|
39 |
+
add_filter('plugin_row_meta', array($this, 'additional_admin_information_links'), 10, 2);
|
40 |
+
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'additional_admin_action_links'));
|
41 |
|
42 |
+
add_filter('wp_get_default_privacy_policy_content', array($this, 'add_privacy_policy_default_text'));
|
43 |
+
}
|
44 |
|
45 |
|
46 |
+
/**
|
47 |
+
* Adds custom links to wk-google-analytics on admin plugin screen on the RIGHT
|
48 |
+
*
|
49 |
+
* @since 1.6.2
|
50 |
+
* @see https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_row_meta
|
51 |
+
*
|
52 |
+
*/
|
53 |
+
function additional_admin_information_links($links, $file)
|
54 |
+
{
|
55 |
|
56 |
+
if (dirname($file) == basename(WK_GOOGLE_ANALYTICS_DIR)) {
|
57 |
+
$links[] = '<a href="http://bit.ly/2jnKboN">' . __('Donate to this plugin', 'wk-google-analytics') . '</a>';
|
58 |
+
}
|
59 |
|
60 |
+
return $links;
|
61 |
|
62 |
+
}
|
63 |
|
64 |
|
65 |
+
/**
|
66 |
+
* Sets up the translations in /lang directory
|
67 |
+
*
|
68 |
+
* @since 1.0
|
69 |
+
*
|
70 |
+
*/
|
71 |
+
function load_textdomain()
|
72 |
+
{
|
73 |
+
load_plugin_textdomain('wk-google-analytics', false, basename(plugin_dir_path(__DIR__)) . '/languages');
|
74 |
}
|
75 |
|
76 |
/**
|
78 |
* @param $content
|
79 |
* @return string
|
80 |
*/
|
81 |
+
function add_privacy_policy_default_text($content)
|
82 |
+
{
|
83 |
$content .= self::get_ga_policy_text();
|
84 |
return $content;
|
85 |
}
|
88 |
* Get the text for GA
|
89 |
* @return string
|
90 |
*/
|
91 |
+
static function get_ga_policy_text()
|
92 |
+
{
|
93 |
ob_start();
|
94 |
include WK_GOOGLE_ANALYTICS_DIR . '/Content/privacy_policy.php';
|
95 |
$content = ob_get_clean();
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
=== Google Analytics ===
|
2 |
Contributors: webkinder
|
3 |
Tags: google analytics, tracking code, analytics, anonymization, anonymize, anonymizeIp, cookie, Datenschutz, ga, gaoptout, google, googleanalytics, google tag manager, gtm, Datenschutz, datenschutzkonform, script, snippet
|
4 |
Requires at least: 3.0
|
5 |
-
Requires PHP: 5.
|
6 |
-
Tested up to:
|
7 |
-
Stable tag: 1.7.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -33,6 +33,10 @@ If you have any questions or feature requests, feel free to contact us via suppo
|
|
33 |
|
34 |
== Changelog ==
|
35 |
|
|
|
|
|
|
|
|
|
36 |
= 1.7.2 =
|
37 |
|
38 |
* Automatically deactivate plugin when PHP version is not sufficient.
|
1 |
+
=== Google Analytics and Google Tag Manager===
|
2 |
Contributors: webkinder
|
3 |
Tags: google analytics, tracking code, analytics, anonymization, anonymize, anonymizeIp, cookie, Datenschutz, ga, gaoptout, google, googleanalytics, google tag manager, gtm, Datenschutz, datenschutzkonform, script, snippet
|
4 |
Requires at least: 3.0
|
5 |
+
Requires PHP: 5.6
|
6 |
+
Tested up to: 5.1.0
|
7 |
+
Stable tag: 1.7.3
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
33 |
|
34 |
== Changelog ==
|
35 |
|
36 |
+
= 1.7.3 =
|
37 |
+
|
38 |
+
* Bugfix for caching plugins
|
39 |
+
|
40 |
= 1.7.2 =
|
41 |
|
42 |
* Automatically deactivate plugin when PHP version is not sufficient.
|
wk-ga.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Google Analytics by WebKinder
|
4 |
Plugin URI: https://wordpress.org/plugins/wk-google-analytics/
|
5 |
Description: Google Analytics for WordPress without tracking your own visits
|
6 |
-
Version: 1.7.
|
7 |
Author: WebKinder
|
8 |
Author URI: https://www.webkinder.ch
|
9 |
License: GPL2
|
3 |
Plugin Name: Google Analytics by WebKinder
|
4 |
Plugin URI: https://wordpress.org/plugins/wk-google-analytics/
|
5 |
Description: Google Analytics for WordPress without tracking your own visits
|
6 |
+
Version: 1.7.3
|
7 |
Author: WebKinder
|
8 |
Author URI: https://www.webkinder.ch
|
9 |
License: GPL2
|