diff --git a/assets/js/dashboard/stats/behaviours/conversions.js b/assets/js/dashboard/stats/behaviours/conversions.js index cfe1a0a8b..a183b07c0 100644 --- a/assets/js/dashboard/stats/behaviours/conversions.js +++ b/assets/js/dashboard/stats/behaviours/conversions.js @@ -100,6 +100,10 @@ export default class Conversions extends React.Component { } else if (this.state.goals) { return ( +
+

Goal conversions

+ {this.props.tabs} +
Goal
diff --git a/assets/js/dashboard/stats/behaviours/funnel.js b/assets/js/dashboard/stats/behaviours/funnel.js index b3333bc97..a16f4af41 100644 --- a/assets/js/dashboard/stats/behaviours/funnel.js +++ b/assets/js/dashboard/stats/behaviours/funnel.js @@ -6,8 +6,6 @@ Chart.register(ChartDataLabels); import * as api from '../../api' import LazyLoader from '../../components/lazy-loader' - - export default class Funnel extends React.Component { constructor(props) { super(props) @@ -30,10 +28,14 @@ export default class Funnel extends React.Component { } } - formatDataLabel(visitors) { - const total = this.state.funnel.steps[0].visitors - const percentage = (visitors / total) * 100 - return `${visitors} Visitors (${percentage}%)` + formatDataLabel(visitors, ctx) { + if (ctx.dataset.label === 'Visitors') { + const total = this.state.funnel.steps[0].visitors + const percentage = (visitors / total) * 100 + return `${percentage}%\n${visitors} Visitors` + } else { + return null + } } fetchFunnel() { @@ -46,8 +48,18 @@ export default class Funnel extends React.Component { if (this.chart) { this.chart.destroy() } - const labels = this.state.funnel.steps.map(step => step.label); + const labels = this.state.funnel.steps.map((step, i) => `${i + 1}. ${step.label}`); const stepData = this.state.funnel.steps.map(step => step.visitors) + const dropOffData = this.state.funnel.steps.map((step, i) => { + const thisVisitors = step.visitors + const prevEntry = this.state.funnel.steps[i - 1] + if (prevEntry) { + return prevEntry.visitors - thisVisitors + } else { + return 0 + } + }) + const ctx = document.getElementById('funnel').getContext('2d') var gradient = ctx.createLinearGradient(0, 0, 0, 300); @@ -56,15 +68,22 @@ export default class Funnel extends React.Component { const data = { labels: labels, - datasets: [{ - label: 'Visitors', - data: stepData, - backgroundColor: [gradient], - borderColor: ['rgba(101,116,205)'], - borderWidth: 1, - borderSkipped: false, - borderRadius: 4 - }] + datasets: [ + { + label: 'Visitors', + data: stepData, + backgroundColor: ['rgb(99, 102, 241)'], + borderRadius: 4, + stack: 'Stack 0', + }, + { + label: 'Dropoff', + data: dropOffData, + backgroundColor: ['rgb(224, 231, 255)'], + borderRadius: 4, + stack: 'Stack 0', + } + ], }; const config = { @@ -79,12 +98,19 @@ export default class Funnel extends React.Component { display: false, }, datalabels: { - formatter: this.formatDataLabel.bind(this) + formatter: this.formatDataLabel.bind(this), + anchor: 'end', + backgroundColor: 'rgba(25, 30, 56)', + color: 'rgb(243, 244, 246)', + borderRadius: 4, + font: {size: 14, weight: 'bold'}, + textAlign: 'center', + padding: {top: 4, bottom: 4, right: 8, left: 8} } }, scales: { - y: { display: false, border: { display: false } }, - x: { display: true, border: { display: false }, grid: { drawOnChartArea: false, drawTicks: false }, ticks: { font: { weight: 'bold', size: 14 }, color: 'rgb(75, 85, 99)' } } + y: { display: false}, + x: { position: 'top', display: true, border: { display: false }, grid: {drawBorder: false, display: false}, ticks: {padding: 24, font: { weight: 'bold', size: 14 }, color: 'rgb(17, 24, 39)'}} } }, }; @@ -94,7 +120,7 @@ export default class Funnel extends React.Component { renderInner() { if (this.state.loading) { - return
+ return
} else if (this.state.funnel) { const firstStep = this.state.funnel.steps[0].visitors const lastStep = this.state.funnel.steps[this.state.funnel.steps.length - 1].visitors @@ -102,9 +128,12 @@ export default class Funnel extends React.Component { return ( -

{this.state.funnel.name}

-

{this.state.funnel.steps.length}-step funnel • {conversionRate}% conversion rate

- +
+

{this.state.funnel.name}

+ {this.props.tabs} +
+

{this.state.funnel.steps.length}-step funnel • {conversionRate}% conversion rate

+
) } @@ -112,7 +141,7 @@ export default class Funnel extends React.Component { render() { return ( - + {this.renderInner()} ) diff --git a/assets/js/dashboard/stats/behaviours/index.js b/assets/js/dashboard/stats/behaviours/index.js index 9cfc14208..e082f61da 100644 --- a/assets/js/dashboard/stats/behaviours/index.js +++ b/assets/js/dashboard/stats/behaviours/index.js @@ -63,14 +63,12 @@ export default function Behaviours({ query, site }) { const funnelNames = site.funnels.map(({name}) => name) const selectedFunnel = site.funnels.find(funnel => funnel.name === tab) + const tabs = + return (
-
-

Behaviors

- -
- { tab == 'conversions' && } - { funnelNames.includes(tab) && } + { tab == 'conversions' && } + { funnelNames.includes(tab) && }
) } diff --git a/assets/js/dashboard/stats/graph/visitor-graph.js b/assets/js/dashboard/stats/graph/visitor-graph.js index fddd1ed08..d1874d4fb 100644 --- a/assets/js/dashboard/stats/graph/visitor-graph.js +++ b/assets/js/dashboard/stats/graph/visitor-graph.js @@ -55,6 +55,7 @@ class LineGraph extends React.Component { animation: false, plugins: { legend: { display: false }, + datalabels: { display: false}, tooltip: { enabled: false, mode: 'index',