Skip to Content
Menu

track_notable_bots()

Detect and track notable bot traffic in Google Analytics.

PHP April 27, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Security.php on line 155.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_track_notable_bots"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            function track_notable_bots(){
                $override = apply_filters('pre_track_notable_bots', null);
                if ( isset($override) ){return;}
    
                //Ignore users who have already been checked, or are logged in.
                if ( is_user_logged_in() ){
                    return false;
                }
    
                //Google Page Speed
                if ( strpos($this->super->server['HTTP_USER_AGENT'], 'Google Page Speed') !== false ){
                    if ( $this->url_components('extension') !== 'js' ){
                        global $post;
                    }
                }
    
                //Internet Archive Wayback Machine
                if ( strpos($this->super->server['HTTP_USER_AGENT'], 'archive.org_bot') !== false || strpos($this->super->server['HTTP_USER_AGENT'], 'Wayback Save Page') !== false ){
                    global $post;
                }
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_track_notable_bots', 'my_custom_track_notable_bots'); 
    function my_custom_track_notable_bots(){ 
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_track_notable_bots', '__return_false');