|
|
|
|
@ -12,26 +12,39 @@ class ReferrersModal extends React.Component {
|
|
|
|
|
super(props)
|
|
|
|
|
this.state = {
|
|
|
|
|
loading: true,
|
|
|
|
|
query: parseQuery(props.location.search, props.site)
|
|
|
|
|
referrers: [],
|
|
|
|
|
query: parseQuery(props.location.search, props.site),
|
|
|
|
|
page: 1,
|
|
|
|
|
moreResultsAvailable: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
if (this.state.query.filters.goal) {
|
|
|
|
|
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers`, this.state.query, {limit: 100})
|
|
|
|
|
.then((res) => this.setState({loading: false, referrers: res}))
|
|
|
|
|
loadReferrers() {
|
|
|
|
|
const {query, page, referrers} = this.state
|
|
|
|
|
|
|
|
|
|
if (query.filters.goal) {
|
|
|
|
|
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/goal/referrers`, query, {limit: 100, page: page})
|
|
|
|
|
.then((res) => this.setState({loading: false, referrers: referrers.concat(res), moreResultsAvailable: res.length === 100}))
|
|
|
|
|
} else {
|
|
|
|
|
const include = this.showExtra() ? 'bounce_rate,visit_duration' : null
|
|
|
|
|
|
|
|
|
|
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, this.state.query, { limit: 100, include: include, show_noref: true})
|
|
|
|
|
.then((res) => this.setState({loading: false, referrers: res}))
|
|
|
|
|
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/referrers`, query, {limit: 100, page: page, include: include, show_noref: true})
|
|
|
|
|
.then((res) => this.setState({loading: false, referrers: referrers.concat(res), moreResultsAvailable: res.length === 100}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
this.loadReferrers()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showExtra() {
|
|
|
|
|
return this.state.query.period !== 'realtime' && !this.state.query.filters.goal
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMore() {
|
|
|
|
|
this.setState({loading: true, page: this.state.page + 1}, this.loadReferrers.bind(this))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formatBounceRate(page) {
|
|
|
|
|
if (typeof(page.bounce_rate) === 'number') {
|
|
|
|
|
return page.bounce_rate + '%'
|
|
|
|
|
@ -69,33 +82,16 @@ class ReferrersModal extends React.Component {
|
|
|
|
|
return this.state.query.period === 'realtime' ? 'Current visitors' : 'Visitors'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderBody() {
|
|
|
|
|
renderLoading() {
|
|
|
|
|
if (this.state.loading) {
|
|
|
|
|
return <div className="loading my-16 mx-auto"><div></div></div>
|
|
|
|
|
} else if (this.state.moreResultsAvailable) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="loading mt-32 mx-auto"><div></div></div>
|
|
|
|
|
)
|
|
|
|
|
} else if (this.state.referrers) {
|
|
|
|
|
return (
|
|
|
|
|
<React.Fragment>
|
|
|
|
|
<h1 className="text-xl font-bold">Top Sources</h1>
|
|
|
|
|
|
|
|
|
|
<div className="my-4 border-b border-gray-300"></div>
|
|
|
|
|
<main className="modal__content">
|
|
|
|
|
<table className="w-full table-striped table-fixed">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th className="p-2 text-xs tracking-wide font-bold text-gray-500" align="left">Referrer</th>
|
|
|
|
|
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">{this.label()}</th>
|
|
|
|
|
{this.showExtra() && <th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">Bounce rate</th>}
|
|
|
|
|
{this.showExtra() && <th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">Visit duration</th>}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{ this.state.referrers.map(this.renderReferrer.bind(this)) }
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</main>
|
|
|
|
|
</React.Fragment>
|
|
|
|
|
<div className="w-full text-center my-4">
|
|
|
|
|
<button onClick={this.loadMore.bind(this)} type="button" className="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-500 focus:outline-none focus:border-indigo-700 focus:shadow-outline-indigo active:bg-indigo-700 transition ease-in-out duration-150">
|
|
|
|
|
Load more
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -103,7 +99,27 @@ class ReferrersModal extends React.Component {
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Modal site={this.props.site}>
|
|
|
|
|
{ this.renderBody() }
|
|
|
|
|
<h1 className="text-xl font-bold">Top Sources</h1>
|
|
|
|
|
|
|
|
|
|
<div className="my-4 border-b border-gray-300"></div>
|
|
|
|
|
|
|
|
|
|
<main className="modal__content">
|
|
|
|
|
<table className="w-full table-striped table-fixed">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th className="p-2 text-xs tracking-wide font-bold text-gray-500" align="left">Referrer</th>
|
|
|
|
|
<th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">{this.label()}</th>
|
|
|
|
|
{this.showExtra() && <th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">Bounce rate</th>}
|
|
|
|
|
{this.showExtra() && <th className="p-2 w-32 text-xs tracking-wide font-bold text-gray-500" align="right">Visit duration</th>}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{ this.state.referrers.map(this.renderReferrer.bind(this)) }
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
{ this.renderLoading() }
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|