import React from 'react'; import { Link } from 'react-router-dom' import Bar from '../bar' import PropBreakdown from './prop-breakdown' import numberFormatter from '../../util/number-formatter' import * as api from '../../api' import * as url from '../../util/url' import LazyLoader from '../../components/lazy-loader' const MOBILE_UPPER_WIDTH = 767 const DEFAULT_WIDTH = 1080 export default class Conversions extends React.Component { constructor(props) { super(props) this.htmlNode = React.createRef() this.state = { loading: true, viewport: DEFAULT_WIDTH, } this.onVisible = this.onVisible.bind(this) this.handleResize = this.handleResize.bind(this); } componentDidMount() { window.addEventListener('resize', this.handleResize, false); this.handleResize(); } componentWillUnmount() { window.removeEventListener('resize', this.handleResize, false); } handleResize() { this.setState({ viewport: window.innerWidth }); } onVisible() { this.fetchConversions() } componentDidUpdate(prevProps) { if (this.props.query !== prevProps.query) { const height = this.htmlNode.current.element.offsetHeight this.setState({loading: true, goals: null, prevHeight: height}) this.fetchConversions() } } getBarMaxWidth() { const { viewport } = this.state; return viewport > MOBILE_UPPER_WIDTH ? "16rem" : "10rem"; } fetchConversions() { api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/conversions`, this.props.query) .then((res) => this.setState({loading: false, goals: res, prevHeight: null})) } renderGoalText(goalName) { if (this.props.query.period === 'realtime') { return {goalName} } else { return ( {goalName} ) } } renderGoal(goal) { const { viewport } = this.state; const renderProps = this.props.query.filters['goal'] == goal.name && goal.prop_names return (