I have built a React web app and I would like to track the users time spent on my website using Google Analytics.
Currently I am using react-ga
(https://github.com/react-ga/react-ga) as a tool to bind the Google Analytics with React. I have successfully tracked each page with Google Analytics. I can see the traffic sources and overview like this:
Google Analytics Screen shot
However, when I checked the Avg. Time Spent page: Google Analytics Behavior overview. I can not see any data on avg. time spent.
The following is what I have set up in my code, I initialized the ReactGA in my App.js file:
App.js
componentDidMount() {
ReactGA.initialize('UA-xxxxxxx-x')
....
}
And I tracked my pages like this in my Routing.js file where I have all my react routers routes in this file:
Routing.js
componentDidMount() {
this.props.history.listen(location => ReactGA.pageview(location.pathname))
...
}
So far this is all I have set up for react-ga
for Google Analytics.
Do I miss anything for tracking the Avg. time spent on my site?