Google Analytics - Version 1.6.2

Version Description

  • Refactored settings page for cleaner settings fields
  • Added direct settings link from plugin overview screen
  • Tested up to WordPress 4.7.2
Download this release

Release Info

Developer webkinder
Plugin Icon 128x128 Google Analytics
Version 1.6.2
Comparing to
See all releases

Code changes from version 1.6.1 to 1.6.2

Files changed (2) hide show
  1. readme.txt +7 -3
  2. wk-ga.php +434 -193
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === Google Analytics ===
2
  Contributors: webkinder
3
- Donate link: http://bit.ly/2jnKboN
4
  Tags: google analytics, tracking code, analytics, anonymization, anonymize, anonymizeIp, cookie, Datenschutz, ga, gaoptout, google, googleanalytics, google tag manager, gtm, Datenschutz, datenschutzkonform, script, snippet
5
  Requires at least: 3.0
6
- Tested up to: 4.7
7
- Stable tag: 1.6.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -36,6 +35,11 @@ If you have any questions or feature requests, feel free to contact us via suppo
36
 
37
  == Changelog ==
38
 
 
 
 
 
 
39
  = 1.6.1 =
40
  * 'Test your tracking code now' linking to the correct language
41
 
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
+ Tested up to: 4.9
6
+ Stable tag: 1.6.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
35
 
36
  == Changelog ==
37
 
38
+ = 1.6.2 =
39
+ * Refactored settings page for cleaner settings fields
40
+ * Added direct settings link from plugin overview screen
41
+ * Tested up to WordPress 4.7.2
42
+
43
  = 1.6.1 =
44
  * 'Test your tracking code now' linking to the correct language
45
 
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.6.1
7
  Author: WebKinder
8
  Author URI: http://www.webkinder.ch
9
  License: GPL2
@@ -13,177 +13,426 @@ Text Domain: wk-ga
13
  */
14
 
15
  class wk_ga {
16
- public function __construct() {
17
 
18
- //Lifecycle hooks
19
- register_activation_hook( __FILE__, array( $this, "activation" ) );
20
- register_deactivation_hook( __FILE__, array( $this, "deactivation" ) );
21
 
22
- //i18n
23
- add_action('plugins_loaded', array( $this, "load_textdomain") );
24
 
25
- //Settings
26
- add_action( 'admin_init', array( $this, "register_settings" ) );
27
- add_action( 'admin_menu', array( $this, "settings_page" ) );
28
 
29
- //Cookie Handling
30
- add_action( 'admin_enqueue_scripts', array( $this, "load_admin_scripts" ) );
31
 
32
- //Cookie function
33
- add_action( 'wp_head', array( $this, 'render_script') );
34
 
35
- //Google Analytics script in <head>
36
- add_action( 'wp_head', array( $this, 'google_analytics_script') );
37
 
38
- //Google Tag Manager script in header
39
- add_action( 'wp_head', array( $this, 'google_tag_manager_script'));
40
 
41
- //Google Tag Manager noscript footer
42
- add_action( 'wp_footer', array( $this, 'google_tag_manager_noscript'));
43
- }
44
 
45
- /*
46
- * Should Track Visit
47
- */
48
- function should_track_visit() {
49
- return ( !is_user_logged_in() || get_option('track_logged_in') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
 
52
- /*
53
- * Render Script
54
- */
55
- function render_script() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  ?>
57
  <script>
58
- function hasWKGoogleAnalyticsCookie() {
59
- return (new RegExp('wp_wk_ga_untrack_' + document.location.hostname) ).test(document.cookie);
60
- }
 
 
 
 
 
61
  </script>
62
  <?php
63
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- /*
66
- * Tag Manager Script Tag
67
- */
68
- function google_tag_manager_script() {
69
- if( $this->should_track_visit() && get_option('ga_use_tag_manager') ) {
70
- $TAG_MANAGER_ID = get_option('ga_tag_manager_id');
71
- ?>
72
- <script>
73
- if( !hasWKGoogleAnalyticsCookie() ) {
74
- //Google Tag Manager
75
- (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
76
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
77
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
78
- '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
79
- })(window,document,'script','dataLayer','<?php echo $TAG_MANAGER_ID; ?>');
80
- }
81
- </script>
82
- <?php
83
- }
84
- }
85
-
86
- /*
87
- * Tag Manager Script Tag
88
- */
89
- function google_tag_manager_noscript() {
90
- if( $this->should_track_visit() && get_option('ga_use_tag_manager') ) {
91
- $TAG_MANAGER_ID = get_option('ga_tag_manager_id');
92
- ?>
93
- <noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $TAG_MANAGER_ID; ?>"
94
- height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
95
 
96
- <?php
97
- }
98
- }
 
 
 
 
 
99
 
100
- /*
101
- * Google Analytics Script Tag
102
- */
103
- function google_analytics_script() {
104
- if( $this->should_track_visit() && ! get_option('ga_use_tag_manager') ) {
105
- $GA_TRACKING_CODE = get_option('ga_tracking_code');
106
- $ANONYMIZE_IP = get_option('ga_anonymize_ip');
107
- ?>
108
- <script>
109
- if( !hasWKGoogleAnalyticsCookie() ) {
110
- //Google Analytics
111
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
112
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
113
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
114
- })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
115
- ga('create', '<?php echo $GA_TRACKING_CODE; ?>', 'auto');
116
  <?php
117
  if( $ANONYMIZE_IP ) :
118
  ?>
119
- //anonymize IP
120
  ga('set', 'anonymizeIp', true);
121
  <?php
122
  endif;
123
  ?>
124
- ga('send', 'pageview');
125
- }
126
- </script>
127
- <?php
128
  }
 
 
 
129
  }
130
-
131
- /*
132
- * Load Text Domain
133
- */
 
 
 
 
134
  function load_textdomain() {
135
  load_plugin_textdomain( 'wk-ga', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
136
  }
137
 
138
- /*
139
- * Plugin Activation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  */
141
- public function activation() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- }
144
 
145
- /*
146
- * Plugin Deactivation
147
- */
148
- public function deactivation() {
 
 
 
 
149
 
150
- }
151
 
152
- /*
153
- * Register Settings
154
- */
155
- public function register_settings() {
156
- register_setting(
157
- 'wk_ga_google_analytics',
158
- 'ga_tracking_code'
159
- );
160
-
161
- register_setting(
162
- 'wk_ga_google_analytics',
163
- 'track_logged_in'
164
- );
165
-
166
- register_setting(
167
- 'wk_ga_google_analytics',
168
- 'ga_anonymize_ip'
169
- );
170
-
171
- register_setting(
172
- 'wk_ga_google_analytics',
173
- 'ga_use_tag_manager'
174
- );
175
-
176
- register_setting(
177
- 'wk_ga_google_analytics',
178
- 'ga_tag_manager_id'
179
- );
180
 
181
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
 
183
- /*
184
- *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  */
186
- public function load_admin_scripts( $hook ) {
187
  if( $hook != "settings_page_google_analytics" ) {
188
  return;
189
  }
@@ -206,70 +455,62 @@ class wk_ga {
206
 
207
  }
208
 
209
- /*
210
- * Settings Page
211
- */
212
- public function settings_page() {
213
- add_options_page(
214
- 'Google Analytics',
215
- 'Google Analytics',
216
- 'manage_options',
217
- 'google_analytics',
218
- array( $this, "settings_content" )
219
- );
220
- }
221
-
222
- public function settings_content() {
 
 
 
 
 
 
 
 
 
 
223
 
224
  if ( ! isset( $_REQUEST['settings-updated'] ) )
225
- $_REQUEST['settings-updated'] = false;
226
  ?>
227
- <div class="wrap">
228
- <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
229
-
230
- <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
231
- <div class="updated fade"><p><strong><a target="_blank" href="https://support.google.com/analytics/answer/1008083"><?php _e( 'Test your tracking code now!', 'wk-ga' ); ?></a></strong></p>
232
- </div>
233
- <?php endif; ?>
234
-
235
- <p><?php _e('Enter your Google Analytics tracking code below. You can also use Google Tag Manager instead by checking the relevant setting.', 'wk-ga'); ?>
236
- </p>
237
- <div class="wk-left-part">
238
- <form id="wk-google-analytics-settings" method="post" action="options.php">
239
- <?php settings_fields( 'wk_ga_google_analytics' ); ?>
240
- <?php do_settings_sections('wk_ga_google_analytics'); ?>
241
-
242
- <div class="use-google-analytics">
243
- <label><?php _e('GA Tracking Code', 'wk-ga'); ?></label>
244
- <input type="text" name="ga_tracking_code" placeholder="UA-XXXXXXXX-X" value="<?php echo esc_attr( get_option( "ga_tracking_code" ) ); ?>" />
245
- </div>
246
- <div class="use-google-analytics">
247
- <label><?php _e("Anonymize IP's", 'wk-ga'); ?></label>
248
- <input type="checkbox" name="ga_anonymize_ip" value="1" <?php checked( get_option( "ga_anonymize_ip") ); ?> />
249
- </div>
250
- <div>
251
- <label><?php _e('Track logged in users', 'wk-ga'); ?></label>
252
- <input type="checkbox" name="track_logged_in" value="1" <?php checked( get_option( "track_logged_in" ) ); ?> />
253
- </div>
254
- <div>
255
- <label><?php _e("Use Google Tag Manager instead", 'wk-ga'); ?></label>
256
- <input id="use-google-tag-manager" type="checkbox" name="ga_use_tag_manager" value="1" <?php checked( get_option( "ga_use_tag_manager") ); ?> />
257
- </div>
258
- <div class="use-google-tag-manager">
259
- <label><?php _e("Google Tag Manager ID", 'wk-ga'); ?></label>
260
- <input type="text" name="ga_tag_manager_id" placeholder="GTM-XXXXXX" value="<?php echo esc_attr( get_option( "ga_tag_manager_id" ) ); ?>" />
261
- </div>
262
- <div id="track-device"></div>
263
- <?php submit_button(); ?>
264
- </form>
265
- </div>
266
- <div class="wk-right-part">
267
- <?php include_once( __DIR__ . "/includes/mailchimp-form.php" ); ?>
268
- </div>
269
- </div>
270
-
271
- <?php
272
- }
273
 
274
  }
275
 
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.6.2
7
  Author: WebKinder
8
  Author URI: http://www.webkinder.ch
9
  License: GPL2
13
  */
14
 
15
  class wk_ga {
16
+ public function __construct() {
17
 
18
+ //lifecycle hooks
19
+ register_activation_hook( __FILE__, array( $this, 'activation' ) );
20
+ register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
21
 
22
+ //i18n
23
+ add_action('plugins_loaded', array( $this, 'load_textdomain') );
24
 
25
+ //settings
26
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
27
+ add_action( 'admin_menu', array( $this, 'settings_page' ) );
28
 
29
+ //cookie handling
30
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_scripts' ) );
31
 
32
+ //cookie function
33
+ add_action( 'wp_head', array( $this, 'render_script') );
34
 
35
+ //Google Analytics script in <head>
36
+ add_action( 'wp_head', array( $this, 'google_analytics_script') );
37
 
38
+ //Google Tag Manager script in header
39
+ add_action( 'wp_head', array( $this, 'google_tag_manager_script'));
40
 
41
+ //Google Tag Manager noscript footer
42
+ add_action( 'wp_footer', array( $this, 'google_tag_manager_noscript'));
 
43
 
44
+ //additional links to admin plugin page
45
+ add_filter( 'plugin_row_meta', array( $this, 'additional_admin_information_links' ), 10, 2);
46
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'additional_admin_action_links' ) );
47
+
48
+ }
49
+
50
+ /**
51
+ * Adds custom links to wk-google-analytics on admin plugin screen on the RIGHT
52
+ *
53
+ * @since 1.6.2
54
+ * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_row_meta
55
+ *
56
+ */
57
+ function additional_admin_information_links( $links, $file ) {
58
+
59
+ $base = plugin_basename(__FILE__);
60
+
61
+ if ($file == $base) {
62
+ $links[] = '<a href="http://bit.ly/2jnKboN">' . __('Donate to this plugin', 'wk-ga') . '</a>';
63
  }
64
 
65
+ return $links;
66
+
67
+ }
68
+
69
+ /**
70
+ * Adds custom links to wk-google-analytics on admin plugin screen on the LEFT
71
+ *
72
+ * @since 1.6.2
73
+ * @see https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
74
+ *
75
+ */
76
+ function additional_admin_action_links( $links ) {
77
+
78
+ return array_merge( array('settings' => '<a href="' . admin_url( '/options-general.php?page=google_analytics' ) . '">' . __( 'Settings', 'wk-ga' ) . '</a>'), $links );
79
+
80
+ }
81
+
82
+ /**
83
+ * Returns whether the current request should be tracked or not
84
+ *
85
+ * @since 1.2
86
+ * @return boolean
87
+ *
88
+ */
89
+ function should_track_visit() {
90
+ return ( !is_user_logged_in() || get_option('track_logged_in') );
91
+ }
92
+
93
+ /**
94
+ * Returns if the cookie is present
95
+ *
96
+ * @since 1.2
97
+ * @return boolean
98
+ *
99
+ */
100
+ function render_script() {
101
+ ?>
102
+ <script>
103
+ function hasWKGoogleAnalyticsCookie() {
104
+ return (new RegExp('wp_wk_ga_untrack_' + document.location.hostname) ).test(document.cookie);
105
+ }
106
+ </script>
107
+ <?php
108
+ }
109
+
110
+ /**
111
+ * Outputs the Google Tag Manager script tag if necessary
112
+ *
113
+ * @since 1.2
114
+ *
115
+ */
116
+ function google_tag_manager_script() {
117
+ if( $this->should_track_visit() && get_option('ga_use_tag_manager') ) {
118
+ $TAG_MANAGER_ID = get_option('ga_tag_manager_id');
119
  ?>
120
  <script>
121
+ if( !hasWKGoogleAnalyticsCookie() ) {
122
+ //Google Tag Manager
123
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
124
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
125
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
126
+ '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
127
+ })(window,document,'script','dataLayer','<?php echo $TAG_MANAGER_ID; ?>');
128
+ }
129
  </script>
130
  <?php
131
  }
132
+ }
133
+
134
+ /**
135
+ * Outputs the Google Tag Manager noscript tag if necessary
136
+ *
137
+ * @since 1.6
138
+ *
139
+ */
140
+ function google_tag_manager_noscript() {
141
+ if( $this->should_track_visit() && get_option('ga_use_tag_manager') ) {
142
+ $TAG_MANAGER_ID = get_option('ga_tag_manager_id');
143
+ ?>
144
+ <noscript><iframe src="//www.googletagmanager.com/ns.html?id=<?php echo $TAG_MANAGER_ID; ?>"
145
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
146
 
147
+ <?php
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Outputs the Google Analytics script if necessary
153
+ *
154
+ * @since 1.2
155
+ * @see https://developers.google.com/analytics/devguides/collection/analyticsjs/ip-anonymization
156
+ *
157
+ */
158
+ function google_analytics_script() {
159
+ if( $this->should_track_visit() && ! get_option('ga_use_tag_manager') ) {
160
+ $GA_TRACKING_CODE = get_option('ga_tracking_code');
161
+ $ANONYMIZE_IP = get_option('ga_anonymize_ip');
162
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
+ <script>
165
+ if( !hasWKGoogleAnalyticsCookie() ) {
166
+ //Google Analytics
167
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
168
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
169
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
170
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
171
+ ga('create', '<?php echo $GA_TRACKING_CODE; ?>', 'auto');
172
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  <?php
174
  if( $ANONYMIZE_IP ) :
175
  ?>
 
176
  ga('set', 'anonymizeIp', true);
177
  <?php
178
  endif;
179
  ?>
180
+
181
+ ga('send', 'pageview');
 
 
182
  }
183
+ </script>
184
+
185
+ <?php
186
  }
187
+ }
188
+
189
+ /**
190
+ * Sets up the translations in /lang directory
191
+ *
192
+ * @since 1.0
193
+ *
194
+ */
195
  function load_textdomain() {
196
  load_plugin_textdomain( 'wk-ga', false, dirname( plugin_basename(__FILE__) ) . '/lang/' );
197
  }
198
 
199
+ /**
200
+ * Placeholder function for plugin activation
201
+ *
202
+ * @since 1.0
203
+ *
204
+ */
205
+ function activation() {
206
+
207
+ }
208
+
209
+ /**
210
+ * Placeholder function for plugin deactivation
211
+ *
212
+ * @since 1.0
213
+ *
214
+ */
215
+ function deactivation() {
216
+
217
+ }
218
+
219
+ /**
220
+ * Registers all the settings separately
221
+ *
222
+ * @since 1.0
223
+ * @see https://codex.wordpress.org/Function_Reference/register_setting
224
+ * @see https://codex.wordpress.org/Function_Reference/add_settings_section
225
+ * @see https://codex.wordpress.org/Function_Reference/add_settings_field
226
+ *
227
+ */
228
+ function register_settings() {
229
+
230
+ add_settings_section(
231
+ 'google_analytics',
232
+ __('Google Analytics', 'wk-ga'),
233
+ array( $this, 'settings_header'),
234
+ 'google_analytics'
235
+ );
236
+
237
+ /**
238
+ * @since 1.0
239
+ */
240
+ register_setting(
241
+ 'wk_ga_google_analytics',
242
+ 'ga_tracking_code'
243
+ );
244
+
245
+ add_settings_field(
246
+ 'ga_tracking_code',
247
+ __('GA Tracking Code', 'wk-ga'),
248
+ array( $this, 'tracking_code_field' ),
249
+ 'google_analytics',
250
+ 'google_analytics'
251
+ );
252
+
253
+ /**
254
+ * @since 1.0
255
  */
256
+ register_setting(
257
+ 'wk_ga_google_analytics',
258
+ 'track_logged_in'
259
+ );
260
+
261
+ add_settings_field(
262
+ 'ga_anonymize_ip',
263
+ __('Anonymize IP"s', 'wk-ga'),
264
+ array( $this, 'anonymize_ip_field' ),
265
+ 'google_analytics',
266
+ 'google_analytics'
267
+ );
268
+
269
+ /**
270
+ * @since 1.1
271
+ */
272
+ register_setting(
273
+ 'wk_ga_google_analytics',
274
+ 'ga_anonymize_ip'
275
+ );
276
+
277
+ add_settings_field(
278
+ 'track_logged_in',
279
+ __('Track logged in users', 'wk-ga'),
280
+ array( $this, 'track_logged_in_field' ),
281
+ 'google_analytics',
282
+ 'google_analytics'
283
+ );
284
+
285
+ /**
286
+ * @since 1.2
287
+ */
288
+ register_setting(
289
+ 'wk_ga_google_analytics',
290
+ 'ga_use_tag_manager'
291
+ );
292
+
293
+ add_settings_field(
294
+ 'ga_use_tag_manager',
295
+ __('Use Google Tag Manager instead', 'wk-ga'),
296
+ array( $this, 'use_tag_manager_field' ),
297
+ 'google_analytics',
298
+ 'google_analytics'
299
+ );
300
+
301
+ /**
302
+ * @since 1.2
303
+ */
304
+ register_setting(
305
+ 'wk_ga_google_analytics',
306
+ 'ga_tag_manager_id'
307
+ );
308
+
309
+ add_settings_field(
310
+ 'ga_tag_manager_id',
311
+ __('Google Tag Manager ID', 'wk-ga'),
312
+ array( $this, 'tag_manager_id_field' ),
313
+ 'google_analytics',
314
+ 'google_analytics'
315
+ );
316
 
317
+ }
318
 
319
+ /**
320
+ * Renders the header text for the settings page
321
+ *
322
+ * @since 1.6.2
323
+ *
324
+ */
325
+ function settings_header() {
326
+ ?>
327
 
328
+ <p><?php _e('Enter your Google Analytics tracking code below. You can also use Google Tag Manager instead by checking the relevant setting.', 'wk-ga'); ?></p>
329
 
330
+ <?php
331
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
 
333
+ /**
334
+ * Renders text input for the Google Analytics tracking code
335
+ *
336
+ * @since 1.6.2
337
+ *
338
+ */
339
+ function tracking_code_field() {
340
+
341
+ $field = 'ga_tracking_code';
342
+ $value = esc_attr( get_option( $field ) );
343
+
344
+ ?>
345
+
346
+ <input type="text" name="<?php echo $field; ?>" placeholder="UA-XXXXXXXX-X" value="<?php echo $value; ?>" />
347
+
348
+ <?php
349
+ }
350
+
351
+ /**
352
+ * Renders checkbox for the anonymize IP's option
353
+ *
354
+ * @since 1.6.2
355
+ *
356
+ */
357
+ function anonymize_ip_field() {
358
+
359
+ $field = 'ga_anonymize_ip';
360
+ $value = get_option( $field );
361
+
362
+ ?>
363
+
364
+ <input type="checkbox" name="<?php echo $field; ?>" value="1" <?php checked( $value ); ?> />
365
+
366
+ <?php
367
+
368
+ }
369
+
370
+ /**
371
+ * Renders checkbox for the track logged in users option
372
+ *
373
+ * @since 1.6.2
374
+ *
375
+ */
376
+ function track_logged_in_field() {
377
+
378
+ $field = 'track_logged_in';
379
+ $value = get_option( $field );
380
+
381
+ ?>
382
+
383
+ <input type="checkbox" name="<?php echo $field; ?>" value="1" <?php checked( $value ); ?> />
384
+
385
+ <?php
386
+
387
+ }
388
 
389
+ /**
390
+ * Renders checkbox for the use tag manager option
391
+ *
392
+ * @since 1.6.2
393
+ *
394
+ */
395
+ function use_tag_manager_field() {
396
+
397
+ $field = 'ga_use_tag_manager';
398
+ $value = get_option( $field );
399
+
400
+ ?>
401
+
402
+ <input type="checkbox" name="<?php echo $field; ?>" value="1" <?php checked( $value ); ?> />
403
+
404
+ <?php
405
+
406
+ }
407
+
408
+ /**
409
+ * Renders text field for the Google Tag Manager ID
410
+ *
411
+ * @since 1.6.2
412
+ *
413
+ */
414
+ function tag_manager_id_field() {
415
+
416
+ $field = 'ga_tag_manager_id';
417
+ $value = esc_attr( get_option( $field ) );
418
+
419
+ ?>
420
+
421
+ <input type="text" name="<?php echo $field; ?>" placeholder="GTM-XXXXXX" value="<?php echo $value; ?>" />
422
+
423
+ <?php
424
+
425
+ }
426
+
427
+ /**
428
+ * Loads all the admin scripts for settings page
429
+ *
430
+ * @since 1.0
431
+ * @see https://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
432
+ * @see https://github.com/js-cookie/js-cookie
433
+ *
434
  */
435
+ function load_admin_scripts( $hook ) {
436
  if( $hook != "settings_page_google_analytics" ) {
437
  return;
438
  }
455
 
456
  }
457
 
458
+ /**
459
+ * Add an options page under 'Settings'
460
+ *
461
+ * @since 1.0
462
+ * @see https://codex.wordpress.org/Function_Reference/add_options_page
463
+ *
464
+ */
465
+ function settings_page() {
466
+ add_options_page(
467
+ 'Google Analytics',
468
+ 'Google Analytics',
469
+ 'manage_options',
470
+ 'google_analytics',
471
+ array( $this, "settings_content" )
472
+ );
473
+ }
474
+
475
+ /**
476
+ * Ouputs the markup for the options page
477
+ *
478
+ * @since 1.0
479
+ *
480
+ */
481
+ function settings_content() {
482
 
483
  if ( ! isset( $_REQUEST['settings-updated'] ) )
484
+ $_REQUEST['settings-updated'] = false;
485
  ?>
486
+
487
+ <div class="wrap">
488
+ <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
489
+
490
+ <?php if ( false !== $_REQUEST['settings-updated'] ) : ?>
491
+ <div class="updated fade">
492
+ <p>
493
+ <strong><a target="_blank" href="https://support.google.com/analytics/answer/1008083"><?php _e( 'Test your tracking code now!', 'wk-ga' ); ?></a></strong>
494
+ </p>
495
+ </div>
496
+ <?php endif; ?>
497
+
498
+ <div class="wk-left-part">
499
+ <form id="wk-google-analytics-settings" method="post" action="options.php">
500
+ <?php settings_fields( 'wk_ga_google_analytics' ); ?>
501
+ <?php do_settings_sections('google_analytics'); ?>
502
+ <div id="track-device"></div>
503
+ <?php submit_button(); ?>
504
+ </form>
505
+ </div>
506
+ <div class="wk-right-part">
507
+ <?php include_once( __DIR__ . "/includes/mailchimp-form.php" ); ?>
508
+ </div>
509
+ </div>
510
+
511
+ <?php
512
+
513
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
514
 
515
  }
516