Answer the question
In order to leave comments, you need to log in
How to add analytics script in React?
How to add a view script in React so that it works on every page? Or is it necessary to execute it in ComponentDidMount?
Answer the question
In order to leave comments, you need to log in
Analytics are usually added to HTML.
You can use a specialized library, for ga this is react-ga .
If you need to log page transitions, then using the example of react-router and react-ga, you can do, for example, like this:
const history = createBrowserHistory();
history.listen(location => {
ReactGA.pageview(location.pathname + location.search);
});
const root = (
<Router history={history}>
<App />
</Router>
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question