2019-11-19 07:30:42 +03:00
|
|
|
import React from 'react';
|
2019-11-20 08:48:27 +03:00
|
|
|
import { Link } from 'react-router-dom'
|
2019-11-19 07:30:42 +03:00
|
|
|
|
2020-10-28 12:09:04 +03:00
|
|
|
import Bar from '../bar'
|
|
|
|
import MoreLink from '../more-link'
|
2020-10-30 11:49:41 +03:00
|
|
|
import PropBreakdown from './prop-breakdown'
|
2020-10-28 12:09:04 +03:00
|
|
|
import numberFormatter from '../../number-formatter'
|
|
|
|
import * as api from '../../api'
|
2019-11-19 07:30:42 +03:00
|
|
|
|
|
|
|
export default class Conversions extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {loading: true}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.fetchConversions()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (this.props.query !== prevProps.query) {
|
|
|
|
this.setState({loading: true, goals: null})
|
|
|
|
this.fetchConversions()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchConversions() {
|
2020-02-04 16:44:13 +03:00
|
|
|
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/conversions`, this.props.query)
|
2019-11-19 07:30:42 +03:00
|
|
|
.then((res) => this.setState({loading: false, goals: res}))
|
|
|
|
}
|
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
renderGoalText(goalName) {
|
2020-10-20 11:24:20 +03:00
|
|
|
if (this.props.query.period === 'realtime') {
|
2020-07-14 16:52:26 +03:00
|
|
|
return <span className="block px-2" style={{marginTop: '-26px'}}>{goalName}</span>
|
|
|
|
} else {
|
|
|
|
const query = new URLSearchParams(window.location.search)
|
|
|
|
query.set('goal', goalName)
|
2019-11-20 08:48:27 +03:00
|
|
|
|
2020-07-14 16:52:26 +03:00
|
|
|
return (
|
2020-10-28 12:09:04 +03:00
|
|
|
<Link to={{search: query.toString()}} style={{marginTop: '-26px'}} className="hover:underline block px-2">
|
2020-07-14 16:52:26 +03:00
|
|
|
{ goalName }
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderGoal(goal) {
|
2020-10-30 11:49:41 +03:00
|
|
|
const renderProps = this.props.query.filters['goal'] == goal.name && goal.prop_names
|
2020-10-28 12:09:04 +03:00
|
|
|
|
2019-11-19 07:30:42 +03:00
|
|
|
return (
|
2020-10-28 12:09:04 +03:00
|
|
|
<div className="my-2 text-sm" key={goal.name}>
|
|
|
|
<div className="flex items-center justify-between my-2">
|
2020-10-29 16:33:37 +03:00
|
|
|
<div className="w-full h-8 relative" style={{maxWidth: 'calc(100% - 10rem)'}}>
|
2020-10-28 12:09:04 +03:00
|
|
|
<Bar count={goal.count} all={this.state.goals} bg="bg-red-50" />
|
|
|
|
{this.renderGoalText(goal.name)}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span className="font-medium inline-block w-20 text-right">{numberFormatter(goal.count)}</span>
|
2020-10-29 16:33:37 +03:00
|
|
|
<span className="font-medium inline-block w-20 text-right">{numberFormatter(goal.total_count)}</span>
|
2020-10-28 12:09:04 +03:00
|
|
|
</div>
|
2020-08-20 14:57:49 +03:00
|
|
|
</div>
|
2020-10-30 11:49:41 +03:00
|
|
|
{ renderProps && <PropBreakdown site={this.props.site} query={this.props.query} goal={goal} /> }
|
2020-02-10 16:17:00 +03:00
|
|
|
</div>
|
2019-11-19 07:30:42 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.loading) {
|
|
|
|
return (
|
2020-04-23 10:58:04 +03:00
|
|
|
<div className="w-full bg-white shadow-xl rounded p-4" style={{height: '94px'}}>
|
|
|
|
<div className="loading my-2 mx-auto"><div></div></div>
|
2019-11-19 07:30:42 +03:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
} else if (this.state.goals) {
|
|
|
|
return (
|
2020-02-10 16:17:00 +03:00
|
|
|
<div className="w-full bg-white shadow-xl rounded p-4">
|
2020-07-14 16:52:26 +03:00
|
|
|
<h3 className="font-bold">{this.props.title || "Goal Conversions"}</h3>
|
2020-03-26 16:43:55 +03:00
|
|
|
<div className="flex items-center mt-3 mb-2 justify-between text-gray-500 text-xs font-bold tracking-wide">
|
2020-02-10 16:17:00 +03:00
|
|
|
<span>Goal</span>
|
2020-08-20 14:57:49 +03:00
|
|
|
<div className="text-right">
|
|
|
|
<span className="inline-block w-20">Uniques</span>
|
2020-10-29 16:33:37 +03:00
|
|
|
<span className="inline-block w-20">Total</span>
|
2020-08-20 14:57:49 +03:00
|
|
|
</div>
|
2019-11-19 07:30:42 +03:00
|
|
|
</div>
|
|
|
|
|
2020-02-10 16:17:00 +03:00
|
|
|
{ this.state.goals.map(this.renderGoal.bind(this)) }
|
2019-11-19 07:30:42 +03:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|