Passed
Push — master ( 5b63cb...6ac651 )
by Chris
09:45
created
includes/frontend/seedprod.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,10 +36,10 @@
 block discarded – undo
36 36
 	    require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-gtag-events.php';
37 37
 	    new MonsterInsights_Gtag_Events();
38 38
 
39
-        // Let's run form tracking if we find it
40
-        if ( function_exists( 'monsterinsights_forms_output_after_script' ) ) {
41
-            monsterinsights_forms_output_after_script( array() );
42
-        }
39
+	// Let's run form tracking if we find it
40
+	if ( function_exists( 'monsterinsights_forms_output_after_script' ) ) {
41
+	    monsterinsights_forms_output_after_script( array() );
42
+	}
43 43
     }
44 44
 }
45 45
 add_action( 'seedprod_monsterinsights_output_tracking', 'monsterinsights_seedprod_tracking', 6, 1 );
Please login to merge, or discard this patch.
includes/frontend/tracking/class-tracking-gtag.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function frontend_tracking_options_persistent()
54 54
     {
55
-        return apply_filters('monsterinsights_frontend_tracking_options_persistent_gtag_before_pageview', []);
55
+	return apply_filters('monsterinsights_frontend_tracking_options_persistent_gtag_before_pageview', []);
56 56
     }
57 57
 
58 58
     /**
@@ -71,107 +71,107 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function frontend_tracking_options($type = 'ua', $encoded = false)
73 73
     {
74
-        global $wp_query;
75
-        $options = [];
74
+	global $wp_query;
75
+	$options = [];
76 76
 
77
-        $tracking_ids = monsterinsights_get_tracking_ids();
78
-        if (empty($tracking_ids)) {
79
-            return $encoded ? wp_json_encode($options) : $options;
80
-        }
77
+	$tracking_ids = monsterinsights_get_tracking_ids();
78
+	if (empty($tracking_ids)) {
79
+	    return $encoded ? wp_json_encode($options) : $options;
80
+	}
81 81
 
82
-        $placeholder = '';
82
+	$placeholder = '';
83 83
 
84
-        if ($encoded) {
85
-            $placeholder = '!@#';
86
-        }
84
+	if ($encoded) {
85
+	    $placeholder = '!@#';
86
+	}
87 87
 
88
-        //		$track_user = monsterinsights_track_user();
88
+	//		$track_user = monsterinsights_track_user();
89 89
 //
90
-        //		if ( ! $track_user ) {
91
-        //			$options['create']   = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( 'auto' ) . "'";
92
-        //			$options['forceSSL'] = "'set', 'forceSSL', true";
93
-        //			$options['send']     = "'send','pageview'";
90
+	//		if ( ! $track_user ) {
91
+	//			$options['create']   = "'create', '" . esc_js( $ua_code ) . "', '" . esc_js( 'auto' ) . "'";
92
+	//			$options['forceSSL'] = "'set', 'forceSSL', true";
93
+	//			$options['send']     = "'send','pageview'";
94 94
 //
95
-        //			return $options;
96
-        //		}
97
-
98
-        $cross_domains = monsterinsights_get_option('cross_domains', []);
99
-        $allow_anchor = monsterinsights_get_option('allow_anchor', false);
100
-
101
-        if ($allow_anchor) {
102
-            $options['allow_anchor'] = 'true';
103
-        }
104
-
105
-        if (class_exists('MonsterInsights_AMP')) {
106
-            $options['use_amp_client_id'] = 'true';
107
-        }
108
-
109
-        $options['forceSSL'] = 'true';
110
-
111
-        // Anonymous data.
112
-        if (monsterinsights_get_option('anonymize_ips', false)) {
113
-            $options['anonymize_ip'] = 'true';
114
-        }
115
-
116
-        $options = apply_filters('monsterinsights_frontend_tracking_options_gtag_before_scripts', $options);
117
-
118
-        // Add Enhanced link attribution.
119
-        if (monsterinsights_get_option('link_attribution', false)) {
120
-            $options['link_attribution'] = 'true';
121
-        }
122
-
123
-        // Add cross-domain tracking.
124
-        if (is_array($cross_domains) && !empty($cross_domains)) {
125
-            $linker_domains = [];
126
-            foreach ($cross_domains as $cross_domain) {
127
-                if (!empty($cross_domain['domain'])) {
128
-                    $linker_domains[] = $cross_domain['domain'];
129
-                }
130
-            }
131
-            $options['linker'] = [
132
-                'domains' => $linker_domains,
133
-            ];
134
-        }
135
-
136
-        if (monsterinsights_is_debug_mode()) {
137
-            $options['debug_mode'] = true;
138
-        }
139
-
140
-        $options = apply_filters('monsterinsights_frontend_tracking_options_gtag_before_pageview', $options, $type);
141
-        $options = apply_filters('monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version, $type);
142
-
143
-        if (is_404()) {
144
-            if (monsterinsights_get_option('hash_tracking', false)) {
145
-                $options['page_path'] = "{$placeholder}'/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer{$placeholder}";
146
-            } else {
147
-                $options['page_path'] = "{$placeholder}'/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer{$placeholder}";
148
-            }
149
-        } elseif ($wp_query->is_search) {
150
-            $pushstr = "'/?s=";
151
-            if (0 === (int) $wp_query->found_posts) {
152
-                $options['page_path'] = $pushstr.'no-results:'.rawurlencode($wp_query->query_vars['s'])."&cat=no-results'";
153
-            } elseif (1 === (int) $wp_query->found_posts) {
154
-                $options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=1-result'";
155
-            } elseif ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
156
-                $options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=2-5-results'";
157
-            } else {
158
-                $options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=plus-5-results'";
159
-            }
160
-        } elseif (monsterinsights_get_option('hash_tracking', false)) {
161
-            $options['page_path'] = "{$placeholder}location.pathname + location.search + location.hash{$placeholder}";
162
-        }
163
-
164
-        $options = apply_filters('monsterinsights_frontend_tracking_options_gtag_end', $options, $type);
165
-
166
-        if ($encoded) {
167
-            return str_replace(
168
-                ['"'.$placeholder, $placeholder.'"'],
169
-                '',
170
-                wp_json_encode($options)
171
-            );
172
-        }
173
-
174
-        return $options;
95
+	//			return $options;
96
+	//		}
97
+
98
+	$cross_domains = monsterinsights_get_option('cross_domains', []);
99
+	$allow_anchor = monsterinsights_get_option('allow_anchor', false);
100
+
101
+	if ($allow_anchor) {
102
+	    $options['allow_anchor'] = 'true';
103
+	}
104
+
105
+	if (class_exists('MonsterInsights_AMP')) {
106
+	    $options['use_amp_client_id'] = 'true';
107
+	}
108
+
109
+	$options['forceSSL'] = 'true';
110
+
111
+	// Anonymous data.
112
+	if (monsterinsights_get_option('anonymize_ips', false)) {
113
+	    $options['anonymize_ip'] = 'true';
114
+	}
115
+
116
+	$options = apply_filters('monsterinsights_frontend_tracking_options_gtag_before_scripts', $options);
117
+
118
+	// Add Enhanced link attribution.
119
+	if (monsterinsights_get_option('link_attribution', false)) {
120
+	    $options['link_attribution'] = 'true';
121
+	}
122
+
123
+	// Add cross-domain tracking.
124
+	if (is_array($cross_domains) && !empty($cross_domains)) {
125
+	    $linker_domains = [];
126
+	    foreach ($cross_domains as $cross_domain) {
127
+		if (!empty($cross_domain['domain'])) {
128
+		    $linker_domains[] = $cross_domain['domain'];
129
+		}
130
+	    }
131
+	    $options['linker'] = [
132
+		'domains' => $linker_domains,
133
+	    ];
134
+	}
135
+
136
+	if (monsterinsights_is_debug_mode()) {
137
+	    $options['debug_mode'] = true;
138
+	}
139
+
140
+	$options = apply_filters('monsterinsights_frontend_tracking_options_gtag_before_pageview', $options, $type);
141
+	$options = apply_filters('monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version, $type);
142
+
143
+	if (is_404()) {
144
+	    if (monsterinsights_get_option('hash_tracking', false)) {
145
+		$options['page_path'] = "{$placeholder}'/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer{$placeholder}";
146
+	    } else {
147
+		$options['page_path'] = "{$placeholder}'/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer{$placeholder}";
148
+	    }
149
+	} elseif ($wp_query->is_search) {
150
+	    $pushstr = "'/?s=";
151
+	    if (0 === (int) $wp_query->found_posts) {
152
+		$options['page_path'] = $pushstr.'no-results:'.rawurlencode($wp_query->query_vars['s'])."&cat=no-results'";
153
+	    } elseif (1 === (int) $wp_query->found_posts) {
154
+		$options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=1-result'";
155
+	    } elseif ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
156
+		$options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=2-5-results'";
157
+	    } else {
158
+		$options['page_path'] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=plus-5-results'";
159
+	    }
160
+	} elseif (monsterinsights_get_option('hash_tracking', false)) {
161
+	    $options['page_path'] = "{$placeholder}location.pathname + location.search + location.hash{$placeholder}";
162
+	}
163
+
164
+	$options = apply_filters('monsterinsights_frontend_tracking_options_gtag_end', $options, $type);
165
+
166
+	if ($encoded) {
167
+	    return str_replace(
168
+		['"'.$placeholder, $placeholder.'"'],
169
+		'',
170
+		wp_json_encode($options)
171
+	    );
172
+	}
173
+
174
+	return $options;
175 175
     }
176 176
 
177 177
     /**
@@ -187,36 +187,36 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function frontend_output()
189 189
     {
190
-        $options = $this->frontend_tracking_options('ua', true);
191
-        $options_v4 = $this->frontend_tracking_options('v4', true);
192
-        $persistent = $this->frontend_tracking_options_persistent();
193
-        $connected_type = MonsterInsights()->auth->get_connected_type();
194
-        $v4_id = monsterinsights_get_v4_id_to_output();
195
-        $ua = monsterinsights_get_ua_to_output();
196
-        $main_id = 'ua' === $connected_type ? $ua : $v4_id;
197
-        $src = apply_filters('monsterinsights_frontend_output_gtag_src', '//www.googletagmanager.com/gtag/js?id='.$main_id);
198
-        $compat_mode = apply_filters('monsterinsights_get_option_gtagtracker_compatibility_mode', true);
199
-        $compat = $compat_mode ? 'window.gtag = __gtagTracker;' : '';
200
-        $track_user = monsterinsights_track_user();
201
-        $output = '';
202
-        $reason = '';
203
-        $attr_string = monsterinsights_get_frontend_analytics_script_atts();
204
-        $gtag_async = apply_filters('monsterinsights_frontend_gtag_script_async', true) ? 'async' : '';
205
-        ob_start(); ?>
190
+	$options = $this->frontend_tracking_options('ua', true);
191
+	$options_v4 = $this->frontend_tracking_options('v4', true);
192
+	$persistent = $this->frontend_tracking_options_persistent();
193
+	$connected_type = MonsterInsights()->auth->get_connected_type();
194
+	$v4_id = monsterinsights_get_v4_id_to_output();
195
+	$ua = monsterinsights_get_ua_to_output();
196
+	$main_id = 'ua' === $connected_type ? $ua : $v4_id;
197
+	$src = apply_filters('monsterinsights_frontend_output_gtag_src', '//www.googletagmanager.com/gtag/js?id='.$main_id);
198
+	$compat_mode = apply_filters('monsterinsights_get_option_gtagtracker_compatibility_mode', true);
199
+	$compat = $compat_mode ? 'window.gtag = __gtagTracker;' : '';
200
+	$track_user = monsterinsights_track_user();
201
+	$output = '';
202
+	$reason = '';
203
+	$attr_string = monsterinsights_get_frontend_analytics_script_atts();
204
+	$gtag_async = apply_filters('monsterinsights_frontend_gtag_script_async', true) ? 'async' : '';
205
+	ob_start(); ?>
206 206
 		<!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using Analytics tracking - https://www.monsterinsights.com/ -->
207 207
 		<?php if (!$track_user) {
208
-            if (empty($v4_id) && empty($ua)) {
209
-                $reason = __('Note: MonsterInsights is not currently configured on this site. The site owner needs to authenticate with Google Analytics in the MonsterInsights settings panel.', 'google-analytics-for-wordpress');
210
-                $output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
211
-            } elseif (current_user_can('monsterinsights_save_settings')) {
212
-                $reason = __('Note: MonsterInsights does not track you as a logged-in site administrator to prevent site owners from accidentally skewing their own Google Analytics data.'.PHP_EOL.'If you are testing Google Analytics code, please do so either logged out or in the private browsing/incognito mode of your web browser.', 'google-analytics-for-wordpress');
213
-                $output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
214
-            } else {
215
-                $reason = __('Note: The site owner has disabled Google Analytics tracking for your user role.', 'google-analytics-for-wordpress');
216
-                $output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
217
-            }
218
-            echo $output;
219
-        } ?>
208
+	    if (empty($v4_id) && empty($ua)) {
209
+		$reason = __('Note: MonsterInsights is not currently configured on this site. The site owner needs to authenticate with Google Analytics in the MonsterInsights settings panel.', 'google-analytics-for-wordpress');
210
+		$output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
211
+	    } elseif (current_user_can('monsterinsights_save_settings')) {
212
+		$reason = __('Note: MonsterInsights does not track you as a logged-in site administrator to prevent site owners from accidentally skewing their own Google Analytics data.'.PHP_EOL.'If you are testing Google Analytics code, please do so either logged out or in the private browsing/incognito mode of your web browser.', 'google-analytics-for-wordpress');
213
+		$output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
214
+	    } else {
215
+		$reason = __('Note: The site owner has disabled Google Analytics tracking for your user role.', 'google-analytics-for-wordpress');
216
+		$output .= '<!-- '.esc_html($reason).' -->'.PHP_EOL;
217
+	    }
218
+	    echo $output;
219
+	} ?>
220 220
 		<?php if (!empty($v4_id) || !empty($ua)) { ?>
221 221
 			<script src="<?php echo esc_attr($src); ?>" <?php echo $attr_string; ?> <?php echo esc_attr($gtag_async); ?>></script>
222 222
 			<script<?php echo $attr_string; ?>>
@@ -315,12 +315,12 @@  discard block
 block discarded – undo
315 315
 					__gtagTracker( 'set', {
316 316
 						'developer_id.dZGIzZG' : true,
317 317
 						<?php
318
-                        if (!empty($persistent)) {
319
-                            foreach ($persistent as $key => $value) {
320
-                                echo "'".esc_js($key)."' : '".esc_js($value)."',";
321
-                            }
322
-                        }
323
-                        ?>
318
+			if (!empty($persistent)) {
319
+			    foreach ($persistent as $key => $value) {
320
+				echo "'".esc_js($key)."' : '".esc_js($value)."',";
321
+			    }
322
+			}
323
+			?>
324 324
 					} );
325 325
 					<?php if (!empty($v4_id)) { ?>
326 326
 					__gtagTracker( 'config', '<?php echo esc_js($v4_id); ?>', <?php echo $options_v4; ?> );
@@ -328,15 +328,15 @@  discard block
 block discarded – undo
328 328
 					<?php if (!empty($ua)) { ?>
329 329
 					__gtagTracker( 'config', '<?php echo esc_js($ua); ?>', <?php echo $options; ?> );
330 330
 					<?php
331
-                    }
332
-                    /*
331
+		    }
332
+		    /*
333 333
                      * Extend or enhance the functionality by adding custom code to frontend
334 334
                      * tracking via this hook.
335 335
                      *
336 336
                      * @since 7.15.0
337 337
                      */
338
-                    do_action('monsterinsights_frontend_tracking_gtag_after_pageview');
339
-                    ?>
338
+		    do_action('monsterinsights_frontend_tracking_gtag_after_pageview');
339
+		    ?>
340 340
 					<?php echo esc_js($compat); ?>
341 341
 					<?php if (apply_filters('monsterinsights_tracking_gtag_frontend_gatracker_compatibility', true)) { ?>
342 342
 						(function () {
@@ -467,14 +467,14 @@  discard block
 block discarded – undo
467 467
 		<?php } ?>
468 468
 		<!-- / Google Analytics by MonsterInsights -->
469 469
 		<?php
470
-        $output = ob_get_contents();
471
-        ob_end_clean();
470
+	$output = ob_get_contents();
471
+	ob_end_clean();
472 472
 
473
-        return $output;
473
+	return $output;
474 474
     }
475 475
 
476 476
     public function should_do_optout()
477 477
     {
478
-        return !(defined('MI_NO_TRACKING_OPTOUT') && MI_NO_TRACKING_OPTOUT);
478
+	return !(defined('MI_NO_TRACKING_OPTOUT') && MI_NO_TRACKING_OPTOUT);
479 479
     }
480 480
 }
Please login to merge, or discard this patch.