JavaScript Error Tracking for Laravel


The Laravel service provider includes all of the necessary tools to start tracking JavaScript errors for your Laravel app.

Prerequisites

Installed and configured Laravel service provider.

Configuration

To enable JavaScript tracking library, you have to include the @understandJs blade directive in your main view template or in views from which you would like to track JavaScript errors.

The @understandJs directive output will include all of the necessary configuration to track JavaScript errors:

// the output of the `@understandJs` will be as follows (depending on the service provider version)
<script src="https://cdn.understand.io/understand-js/v1/bundle.min.js" crossorigin="anonymous"></script>
<script>
    Understand.init({
        env: 'production',
        token : 'your-input-token-from-understand-config', 
        context: {
            request_id: '08394443-31d5-4d65-8392-a29d733c498d', // the unique identifier for a request 
            session_id: '7b52009b64fd0a2a49e6d8a939753077792b0554', // the sha1 hashed version of the user session identifier
            user_id: 12, // the user ID
            client_ip: '141.93.46.10' // the user IP
        }
    })
    .catchErrors();
</script>
  • If you prefer not to use the blade directive you can configure JavaScript tracking library manually.
  • If the @understandJs blade directive does not render the HTML/JS as shown above, please make sure you have updated the service provider to the latest version and run php artisan view:cache.

@understandJsConfig directive

In some situations, you may only want to retrieve the configuration. In this case you can use the @understandJsConfig blade directive:

const config = @understandJsConfig;

// override env property
config.env = 'staging';

Understand.init(config);

The same result as a PHP array can be achieved by calling the UnderstandJsProvider::getJsConfig() facade at the Laravel code level.

Framework Integrations

If you are using a particular framework listed below, please click on a link to see how to configure it: