Triggering event with react-ga returns "Command ignored. Unknown target: undefined"

Viewed 467

I get this error:

Command ignored. Unknown target: undefined

...when trying to trigger an event like this

ReactGA.event({
  category: 'Navigation',
  action: 'Clicked main CTA',
})

What does that mean?

I have initialised it like this:

ReactGA.initialize(process.env.REACT_APP_UA_ID, {
  debug: true,
})

And pageviews work:

ReactGA.pageview(window.location.pathname + window.location.search)
1 Answers

Prior to firing ReactGA.pageview(), try firing ReactGA.set(). Initializing GA when your app loads should look along the lines of this;

ReactGA.initialize({ 'ID', {
  debug: true,
  }
})

ReactGA.set({ page: window.location.pathname + window.location.search });
ReactGA.pageview(window.location.pathname + window.location.search);
Related