'custom_code', 'value' => stripslashes( monsterinsights_get_option( 'custom_code', '' ) ), ); } // Anonymous data if ( monsterinsights_get_option( 'anonymize_ips', false ) ) { $options['anonymize_ips'] = "'set', 'anonymizeIp', true"; } $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_scripts', $options ); // add demographics if ( monsterinsights_get_option( 'demographics', false ) ) { $options['demographics'] = "'require', 'displayfeatures'"; } // Check for Enhanced link attribution if ( monsterinsights_get_option( 'enhanced_link_attribution', false ) ) { $options['enhanced_link_attribution'] = "'require', 'linkid', 'linkid.js'"; } $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_before_pageview', $options ); $options = apply_filters( 'monsterinsights_frontend_tracking_options_before_pageview', $options, $this->name, $this->version ); if ( is_404() ) { if ( monsterinsights_get_option( 'hash_tracking', false ) ) { $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + location.hash + '&from=' + document.referrer"; } else { $options['send'] = "'send','pageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer"; } } else if ( $wp_query->is_search ) { $pushstr = "'send','pageview','/?s="; if ( (int) $wp_query->found_posts === 0 ) { $options['send'] = $pushstr . 'no-results:' . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'"; } else if ( (int) $wp_query->found_posts === 1 ) { $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'"; } else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) { $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'"; } else { $options['send'] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'"; } } else if ( monsterinsights_get_option( 'hash_tracking', false ) ) { $options['send'] = "'send','pageview', location.pathname + location.search + location.hash"; } else { $options['send'] = "'send','pageview'"; } $options = apply_filters( 'monsterinsights_frontend_tracking_options_analytics_end', $options ); return $options; } /** * Get frontend output. * * This function is used to return the Javascript * to output in the head of the page for the given * tracking method. * * @since 6.0.0 * @access public * * @return string Javascript to output. */ public function frontend_output( ) { $options = $this->frontend_tracking_options(); $is_debug_mode = monsterinsights_is_debug_mode(); $src = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics.js' ); if ( current_user_can( 'manage_options' ) && $is_debug_mode ) { $src = apply_filters( 'monsterinsights_frontend_output_analytics_src', '//www.google-analytics.com/analytics_debug.js' ); } $compat = monsterinsights_get_option( 'gatracker_compatibility_mode', false ); $compat = $compat ? 'window.ga = __gaTracker;' : ''; $track_user = monsterinsights_track_user(); $ua = monsterinsights_get_ua(); $output = ''; $reason = ''; $attributes = apply_filters( 'monsterinsights_tracking_analytics_script_attributes', array( 'type' => "text/javascript", 'data-cfasync' => 'false' ) ); $attr_string = ''; if ( ! empty( $attributes ) ) { foreach( $attributes as $attr_name => $attr_value ) { if ( ! empty( $attr_name ) ) { $attr_string .= ' ' . sanitize_key( $attr_name ) . '="' . esc_attr( $attr_value ) . '"'; } else { $attr_string .= ' ' . sanitize_key( $attr_value ); } } } ob_start(); ?> ' . PHP_EOL; } else if ( current_user_can( 'monsterinsights_save_settings' ) ) { $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' ); $output .= '' . PHP_EOL; } else { $reason = __( 'Note: The site owner has disabled Google Analytics tracking for your user role.', 'google-analytics-for-wordpress' ); $output .= '' . PHP_EOL; } echo $output; } ?> > var mi_version = ''; var mi_track_user = ; var mi_no_track_reason = ; should_do_optout() ) { ?> var disableStr = 'ga-disable-'; /* Function to detect opted out users */ function __gaTrackerIsOptedOut() { return document.cookie.indexOf(disableStr + '=true') > -1; } /* Disable tracking if the opt-out cookie exists. */ if ( __gaTrackerIsOptedOut() ) { window[disableStr] = true; } /* Opt-out function */ function __gaTrackerOptout() { document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/'; window[disableStr] = true; } if ( mi_track_user ) { (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','','__gaTracker'); = 1 ) { foreach ( $options as $item ) { if ( ! is_array( $item ) ) { echo ' __gaTracker(' . $item . ");\n"; } else if ( ! empty ( $item['value'] ) ) { echo ' ' . $item['value'] . "\n"; } } } ?> } else { should_do_optout() ) { ?> console.log( "" ); (function() { /* https://developers.google.com/analytics/devguides/collection/analyticsjs/ */ var noopfn = function() { return null; }; var noopnullfn = function() { return null; }; var Tracker = function() { return null; }; var p = Tracker.prototype; p.get = noopfn; p.set = noopfn; p.send = noopfn; var __gaTracker = function() { var len = arguments.length; if ( len === 0 ) { return; } var f = arguments[len-1]; if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) { console.log( ' __gaTracker(' + arguments[0] + " ....) " + mi_no_track_reason ); return; } try { f.hitCallback(); } catch (ex) { } }; __gaTracker.create = function() { return new Tracker(); }; __gaTracker.getByName = noopnullfn; __gaTracker.getAll = function() { return []; }; __gaTracker.remove = noopfn; window['__gaTracker'] = __gaTracker; })(); }