import React from 'react'; import { Link } from 'react-router-dom' import Bar from '../bar' import MoreLink from '../more-link' import PropBreakdown from './prop-breakdown' import numberFormatter from '../../number-formatter' import * as api from '../../api' 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() { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/conversions`, this.props.query) .then((res) => this.setState({loading: false, goals: res})) } renderGoalText(goalName) { if (this.props.query.period === 'realtime') { return {goalName} } else { const query = new URLSearchParams(window.location.search) query.set('goal', goalName) return ( { goalName } ) } } renderGoal(goal) { const renderProps = this.props.query.filters['goal'] == goal.name && goal.prop_names return (
{this.renderGoalText(goal.name)}
{numberFormatter(goal.count)} {numberFormatter(goal.total_count)} {goal.conversion_rate}%
{ renderProps && }
) } render() { if (this.state.loading) { return (
) } else if (this.state.goals) { return (

{this.props.title || "Goal Conversions"}

Goal
Uniques Total CR
{ this.state.goals.map(this.renderGoal.bind(this)) }
) } } }