I am trying to add GA to record page hits. I have tried every solution to make it work but no progress.
In index.js
import ReactGA from 'react-ga';
const hist = createBrowserHistory();
ReactGA.initialize('Tracking_Id');
hist.listen(location => {
ReactGA.set({ page: location.pathname }); // Update the user's current page
ReactGA.pageview(location.pathname + location.search); // Record a pageview for the given page
console.log(location.pathname)
});
My Routes are
<Provider store={store}>
<Router history={hist}>
<Route path='/thank-you' component={ThankYou} />
<Route path='/auth' component={AuthLayout} />
<Route exact path='/' component={HomeLayout} />
<Switch>
<PrivateRoute path='/admin' component={AdminLayout} />
</Switch>
</Router>
</Provider>,
Kindly guide me what i am doing wrong.
