React-ga: document is not defined

Created on 1 May 2018  路  4Comments  路  Source: react-ga/react-ga

Hello, I used this library in my react app (server side rendering) and I saw some error in my server when in production, it pointed in "react-ga.js" file, line 891. Error says "document is undefined".

Please help me with this, did I miss something for setup?

Most helpful comment

Hi @kunmura I added if statement like this:

if(typeof window !== 'undefined' && typeof document !== 'undefined') {
// Your ReactGA initialization here..
}

All 4 comments

Update, I fixed the error by checking if document is undefined.

@kenjoe Hello. I am having the same problem.
Please tell me how to check.

Hi @kunmura I added if statement like this:

if(typeof window !== 'undefined' && typeof document !== 'undefined') {
// Your ReactGA initialization here..
}

@kenjoe Thank you so much!! i'll try it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewmclagan picture andrewmclagan  路  3Comments

hlodver picture hlodver  路  4Comments

astroana picture astroana  路  5Comments

olalonde picture olalonde  路  3Comments

199911 picture 199911  路  6Comments