Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Fix metric undefined (#2589)
RobertJoonasc4b8bf8c3281
diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.jsindex a486c66b2e..425ffeedb2 100644--- a/assets/js/dashboard/stats/graph/visitor-graph.js+++ b/assets/js/dashboard/stats/graph/visitor-graph.js@@ -358,8 +358,8 @@ export default class VisitorGraph extends React.Component {}componentDidUpdate(prevProps, prevState) {- const { metric, topStatData } = this.state;- const { query, site } = this.props+ const { metric } = this.state;+ const { query } = this.propsif (query !== prevProps.query) {if (this.isGraphCollapsed()) {@@ -373,18 +373,22 @@ export default class VisitorGraph extends React.Component {if (metric !== prevState.metric) {this.setState({mainGraphLoadingState: LOADING_STATE.refreshing}, this.fetchGraphData)}+ }++ resetMetric() {+ const { topStatData } = this.state+ const { query, site } = this.propsconst savedMetric = storage.getItem(`metric__${site.domain}`)- const topStatLabels = topStatData && topStatData.top_stats.map(({ name }) => METRIC_MAPPING[name]).filter(name => name)- const prevTopStatLabels = prevState.topStatData && prevState.topStatData.top_stats.map(({ name }) => METRIC_MAPPING[name]).filter(name => name)- if (topStatLabels && `${topStatLabels}` !== `${prevTopStatLabels}`) {- if (query.filters.goal && metric !== 'conversions') {- this.setState({ metric: 'conversions' })- } else if (topStatLabels.includes(savedMetric) && savedMetric !== "") {- this.setState({ metric: savedMetric })- } else {- this.setState({ metric: topStatLabels[0] })- }+ const selectableMetrics = topStatData && topStatData.top_stats.map(({ name }) => METRIC_MAPPING[name]).filter(name => name)+ const canSelectSavedMetric = selectableMetrics && selectableMetrics.includes(savedMetric)++ if (query.filters.goal) {+ this.setState({ metric: 'conversions' })+ } else if (canSelectSavedMetric || savedMetric === "") {+ this.setState({ metric: savedMetric })+ } else {+ this.setState({ metric: 'visitors' })}}@@ -429,7 +433,7 @@ export default class VisitorGraph extends React.Component {fetchTopStatData() {api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/top-stats`, this.props.query).then((res) => {- this.setState({ topStatsLoadingState: LOADING_STATE.loaded, topStatData: res })+ this.setState({ topStatsLoadingState: LOADING_STATE.loaded, topStatData: res }, this.resetMetric)return res})}