2019-11-19 07:30:42 +03:00
|
|
|
import React from "react";
|
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
|
|
|
|
import Modal from './modal'
|
|
|
|
import * as api from '../../api'
|
|
|
|
import numberFormatter from '../../number-formatter'
|
|
|
|
import {parseQuery} from '../../query'
|
|
|
|
|
|
|
|
class PagesModal extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2020-01-15 11:57:47 +03:00
|
|
|
this.state = {
|
|
|
|
loading: true,
|
|
|
|
query: parseQuery(props.location.search, props.site)
|
|
|
|
}
|
2019-11-19 07:30:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-01-15 11:57:47 +03:00
|
|
|
const include = this.showBounceRate() ? 'bounce_rate' : null
|
2019-11-19 07:30:42 +03:00
|
|
|
|
2020-01-15 11:57:47 +03:00
|
|
|
api.get(`/api/stats/${this.props.site.domain}/pages`, this.state.query, {limit: 100, include: include})
|
2019-11-19 07:30:42 +03:00
|
|
|
.then((res) => this.setState({loading: false, pages: res}))
|
|
|
|
}
|
|
|
|
|
2020-01-15 11:57:47 +03:00
|
|
|
showBounceRate() {
|
|
|
|
return !this.state.query.filters.goal
|
|
|
|
}
|
|
|
|
|
2020-01-06 16:51:43 +03:00
|
|
|
formatBounceRate(page) {
|
|
|
|
if (page.bounce_rate) {
|
|
|
|
return page.bounce_rate + '%'
|
|
|
|
} else {
|
|
|
|
return '-'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 07:30:42 +03:00
|
|
|
renderPage(page) {
|
|
|
|
return (
|
2020-01-06 16:51:43 +03:00
|
|
|
<tr className="text-sm" key={page.name}>
|
|
|
|
<td className="p-2 truncate">{page.name}</td>
|
|
|
|
<td className="p-2 w-32 font-medium" align="right">{numberFormatter(page.count)}</td>
|
2020-01-15 11:57:47 +03:00
|
|
|
{this.showBounceRate() && <td className="p-2 w-32 font-medium" align="right">{this.formatBounceRate(page)}</td> }
|
2020-01-06 16:51:43 +03:00
|
|
|
</tr>
|
2019-11-19 07:30:42 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBody() {
|
|
|
|
if (this.state.loading) {
|
|
|
|
return (
|
|
|
|
<div className="loading my-32 mx-auto"><div></div></div>
|
|
|
|
)
|
|
|
|
} else if (this.state.pages) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<header className="modal__header">
|
|
|
|
<h1>Top pages</h1>
|
|
|
|
</header>
|
|
|
|
|
|
|
|
<div className="my-4 border-b border-grey-light"></div>
|
|
|
|
<main className="modal__content">
|
2020-01-06 16:51:43 +03:00
|
|
|
<table className="w-full table-striped table-fixed">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="p-2 text-xs tracking-wide font-bold text-grey-dark" align="left">Page url</th>
|
|
|
|
<th className="p-2 w-32 text-xs tracking-wide font-bold text-grey-dark" align="right">Pageviews</th>
|
2020-01-15 11:57:47 +03:00
|
|
|
{this.showBounceRate() && <th className="p-2 w-32 text-xs tracking-wide font-bold text-grey-dark" align="right">Bounce rate</th>}
|
2020-01-06 16:51:43 +03:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{ this.state.pages.map(this.renderPage.bind(this)) }
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2019-11-19 07:30:42 +03:00
|
|
|
</main>
|
|
|
|
</React.Fragment>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Modal site={this.props.site}>
|
|
|
|
{ this.renderBody() }
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(PagesModal)
|