Hi,
I am creating an React App using Next JS for SSR. So when added the ReactGA.initialize event is head tag for _document.js. It is throwing an error for 'window is not defined'.
A quick and prompt solution would be helpful
Can you check that window exists before calling initialize().
if (typeof window !== 'undefined') {
ReactGA.initialize()
}
I have the same problem. but in that case GA will not be initialized and will not work?
You most probably don't want it initializing on the server anyway. It should initialize only when the code is run on the client
Most helpful comment
Can you check that window exists before calling
initialize().