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