hzdg / react-google-analytics

Google analytics component
Other
111 stars 9 forks source link

TypeError: Cannot read property 'script' of undefined #9

Closed gHashTag closed 4 years ago

gHashTag commented 6 years ago

Why do I have this error?

  4 | React = require('react');
  5 | 
> 6 | script = React.DOM.script;
  7 | 
  8 | if (typeof window !== "undefined" && window !== null) {
  9 |   if (window.GoogleAnalyticsObject == null) {
import ga from 'react-google-analytics'

const GAInitiailizer = ga.Initializer
  componentDidMount(){
    ga('create', 'UA-XXX', 'auto')
    ga('send', 'pageview')
  }
klikstermkd commented 4 years ago

Because you are using a newer version of React where React.DOM is a separate package, and that's why it fails.