import React from 'react'; import { Link } from 'react-router-dom' import Bar from '../bar' import PropBreakdown from './prop-breakdown' import numberFormatter from '../../number-formatter' import * as api from '../../api' import * as url from '../../url' import LazyLoader from '../../lazy-loader' const MOBILE_UPPER_WIDTH = 767 const DEFAULT_WIDTH = 1080 export default class Conversions extends React.Component { constructor(props) { super(props) 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) { this.setState({loading: true, goals: null}) 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})) } 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 (