Conditions | 17 |
Paths | 144 |
Total Lines | 138 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
175 | public function frontend_output( ) { |
||
176 | $options = $this->frontend_tracking_options(); |
||
177 | $src = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics.js' ); |
||
178 | $compat = monsterinsights_get_option( 'gatracker_compatibility_mode', false ); |
||
179 | $compat = $compat ? 'window.ga = __gaTracker;' : ''; |
||
180 | $track_user = monsterinsights_track_user(); |
||
181 | $ua = monsterinsights_get_ua(); |
||
182 | $output = ''; |
||
183 | $reason = ''; |
||
184 | $attributes = apply_filters( 'monsterinsights_tracking_analytics_script_attributes', array( 'type' => "text/javascript", 'data-cfasync' => 'false' ) ); |
||
185 | $attr_string = ''; |
||
186 | if ( ! empty( $attributes ) ) { |
||
187 | foreach( $attributes as $attr_name => $attr_value ) { |
||
188 | if ( ! empty( $attr_name ) ) { |
||
189 | $attr_string .= ' ' . sanitize_key( $attr_name ) . '="' . esc_attr( $attr_value ) . '"'; |
||
190 | } else { |
||
191 | $attr_string .= ' ' . sanitize_key( $attr_value ); |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | ob_start(); |
||
196 | ?> |
||
197 | <!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using Analytics tracking - https://www.monsterinsights.com/ --> |
||
198 | <?php if ( ! $track_user ) { |
||
199 | if ( empty( $ua ) ) { |
||
200 | $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' ); |
||
201 | $output .= '<!-- ' . esc_html( $reason ) . ' -->' . PHP_EOL; |
||
202 | } else if ( current_user_can( 'monsterinsights_save_settings' ) ) { |
||
203 | $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' ); |
||
204 | $output .= '<!-- ' . esc_html( $reason ) . ' -->' . PHP_EOL; |
||
205 | } else { |
||
206 | $reason = __( 'Note: The site owner has disabled Google Analytics tracking for your user role.', 'google-analytics-for-wordpress' ); |
||
207 | $output .= '<!-- ' . esc_html( $reason ) . ' -->' . PHP_EOL; |
||
208 | } |
||
209 | echo $output; |
||
210 | } ?> |
||
211 | <?php if ( $ua ) { ?> |
||
212 | <script<?php echo $attr_string;?>> |
||
213 | var mi_version = '<?php echo MONSTERINSIGHTS_VERSION; ?>'; |
||
214 | var mi_track_user = <?php echo ( $track_user ? 'true' : 'false' ); ?>; |
||
215 | var mi_no_track_reason = <?php echo ( $reason ? "'" . esc_js( $reason) . "'": "''" ); ?>; |
||
216 | <?php do_action( 'monsterinsights_tracking_analytics_frontend_output_after_mi_track_user' ); ?> |
||
217 | |||
218 | <?php if ( $this->should_do_optout() ) { ?> |
||
219 | var disableStr = 'ga-disable-<?php echo monsterinsights_get_ua(); ?>'; |
||
220 | |||
221 | /* Function to detect opted out users */ |
||
222 | function __gaTrackerIsOptedOut() { |
||
223 | return document.cookie.indexOf(disableStr + '=true') > -1; |
||
224 | } |
||
225 | |||
226 | /* Disable tracking if the opt-out cookie exists. */ |
||
227 | if ( __gaTrackerIsOptedOut() ) { |
||
228 | window[disableStr] = true; |
||
229 | } |
||
230 | |||
231 | /* Opt-out function */ |
||
232 | function __gaTrackerOptout() { |
||
233 | document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; |
||
234 | window[disableStr] = true; |
||
235 | } |
||
236 | <?php } ?> |
||
237 | |||
238 | if ( mi_track_user ) { |
||
239 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
||
240 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
||
241 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
||
242 | })(window,document,'script','<?php echo $src; ?>','__gaTracker'); |
||
243 | |||
244 | <?php |
||
245 | echo $compat; |
||
246 | |||
247 | if ( count( $options ) >= 1 ) { |
||
248 | foreach ( $options as $item ) { |
||
249 | if ( ! is_array( $item ) ) { |
||
250 | echo ' __gaTracker(' . $item . ");\n"; |
||
251 | } else if ( ! empty ( $item['value'] ) ) { |
||
252 | echo ' ' . $item['value'] . "\n"; |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | ?> |
||
257 | } else { |
||
258 | <?php if ( $this->should_do_optout() ) { ?> |
||
259 | console.log( "<?php echo esc_js( $reason );?>" ); |
||
260 | (function() { |
||
261 | /* https://developers.google.com/analytics/devguides/collection/analyticsjs/ */ |
||
262 | var noopfn = function() { |
||
263 | return null; |
||
264 | }; |
||
265 | var noopnullfn = function() { |
||
266 | return null; |
||
267 | }; |
||
268 | var Tracker = function() { |
||
269 | return null; |
||
270 | }; |
||
271 | var p = Tracker.prototype; |
||
272 | p.get = noopfn; |
||
273 | p.set = noopfn; |
||
274 | p.send = noopfn; |
||
275 | var __gaTracker = function() { |
||
276 | var len = arguments.length; |
||
277 | if ( len === 0 ) { |
||
278 | return; |
||
279 | } |
||
280 | var f = arguments[len-1]; |
||
281 | if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) { |
||
282 | console.log( '<?php echo esc_js( __("Not running function", "google-analytics-for-wordpress" ) );?> __gaTracker(' + arguments[0] + " ....) <?php echo esc_js( __( "because you are not being tracked.", 'google-analytics-for-wordpress' ) );?> " + mi_no_track_reason ); |
||
283 | return; |
||
284 | } |
||
285 | try { |
||
286 | f.hitCallback(); |
||
287 | } catch (ex) { |
||
288 | |||
289 | } |
||
290 | }; |
||
291 | __gaTracker.create = function() { |
||
292 | return new Tracker(); |
||
293 | }; |
||
294 | __gaTracker.getByName = noopnullfn; |
||
295 | __gaTracker.getAll = function() { |
||
296 | return []; |
||
297 | }; |
||
298 | __gaTracker.remove = noopfn; |
||
299 | window['__gaTracker'] = __gaTracker; |
||
300 | <?php echo $compat; ?> |
||
301 | })(); |
||
302 | <?php } ?> |
||
303 | } |
||
304 | </script> |
||
305 | <?php } else { ?> |
||
306 | <!-- No UA code set --> |
||
307 | <?php } ?> |
||
308 | <!-- / Google Analytics by MonsterInsights --> |
||
309 | <?php |
||
310 | $output = ob_get_contents(); |
||
311 | ob_end_clean(); |
||
312 | return $output; |
||
313 | } |
||
319 |