analytics/assets/js/dashboard/stats/current-visitors.js
Uku Taht 232298d327
Realtime dashboard (#212)
* Auto-updating dashboard with realtime info

* Remove extra route

* Draw list of countries next to the map

* Nice animations

* Do not show bounce rates in realtime modals

* Update countries and devices in realtime

* Remove unused component

* Show total pageviews in the last 30 minutes

* Show proper labels

* Remove unnecessary z-index

* Fix label for main graph

* Fix compiler warnings

* Add tests

* Fix copy pluralizations

* Fix copy in countries modal

* Real-time -> Realtime

* Looser test assertion

* Show last 30 minutes conversions on realtime report

* Remove EventTarget API because it doesn't work on Safari

* Get referrer drilldown from sessions table

* Fix failing tests
2020-07-14 16:52:26 +03:00

39 lines
1.1 KiB
JavaScript

import React from 'react';
import { Link } from 'react-router-dom'
export default class CurrentVisitors extends React.Component {
constructor(props) {
super(props)
this.state = {currentVisitors: null}
}
componentDidMount() {
this.updateCount()
this.props.timer.onTick(this.updateCount.bind(this))
}
updateCount() {
return fetch(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`)
.then( response => {
if (!response.ok) { throw response }
return response.json()
})
.then((res) => this.setState({currentVisitors: res}))
}
render() {
if (this.state.currentVisitors !== null) {
return (
<Link to={`/${encodeURIComponent(this.props.site.domain)}?period=realtime`} className="block text-sm font-bold text-gray-500 mt-1">
<svg className="w-2 mr-2 fill-current text-green-500 inline" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="8"/>
</svg>
{this.state.currentVisitors} current visitors
</Link>
)
} else {
return null
}
}
}