Using LogRocket with server-side rendering

If you are using LogRocket with a server-side rendering framework like next.js be sure that you initialize LogRocket (and any plugins you are using) on the client and not on the server.

Example with next.js

// you can import these packages anywhere
const LogRocket = require('logrocket');
const setupLogRocketReact = require('logrocket-react');

// only initialize when in the browser
if (typeof window !== 'undefined') {
  LogRocket.init('app/id');
  // plugins should also only be initialized when in the browser
  setupLogRocketReact(LogRocket);
}

Other options

If the framework you are using does not have an API for determining whether or not you are running on the browser, you can also use React's componentDidMount lifecycle method, preferable on the main app component.

Plugin Compatibility

The LogRocket React (which allows you to filter user clicks on specific components) does not work with server-side rendering due to the way that React's event system works. We are currently looking for ways to support this use case.