Skip to Content

ga_log_fatal_errors()

Sends fatal PHP errors to Google Analytics as fatal exceptions.

PHP March 24, 2018

Usage

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

Additional Notes

Google Analytics does not have a default exception report. You’ll need to make one or find one in the Gallery. I recommend Ron Whitman’s Exception Report.

This function can’t catch all errors, but it offers a glimpse into many that will prevent visitors from using the website.

JavaScript errors are also logged in the same report.

Source File

Located in /libs/Utilities/Analytics.php on line 212.

No Hooks

This function does not have any filters or actions available. Request one?
PHP
        public function ga_log_fatal_errors(){
            $error = error_get_last();
            if ( isset($error) && $error['type'] === E_ERROR ){
                $message = str_replace(WP_CONTENT_DIR, '', strstr($error['message'], ' in /', true)); //Remove high-level directories to reduce clutter and prevent PII
                $file = str_replace(WP_CONTENT_DIR, '', strstr($error['file'], 'wp-content')); //Remove high-level directories to reduce clutter and prevent PII
                $this->ga_send_exception('(PHP) ' . $message . ' on line ' . $error['line'] . ' in .../' . $file, 1);

                if ( preg_match('/themes\/Nebula-?(main|master|parent|\d+\.\d+)?\//i', $file) && !strpos(strtolower($file), 'scssphp') ){ //If the error is in Nebula parent (and not a Sass compile error) log it for continued improvement of Nebula itself //Remove "master" after a period of time (Maybe January 2021)
                    $this->usage('PHP Fatal Error', array(
                        't' => 'exception',
                        'exd' => '(PHP) ' . $message . ' on line ' . $error['line'] . ' in ' . $file,
                        'exf' => true,
                        'cd12' => (( isset($_SERVER['HTTPS']) )? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
                    ));
                }
            }
        }

Override

This function can not be short-circuited with an override filter. Request one?