diff --git a/assets/js/dashboard/stats/funnel.js b/assets/js/dashboard/stats/funnel.js
index 000998a09..beb3c58d9 100644
--- a/assets/js/dashboard/stats/funnel.js
+++ b/assets/js/dashboard/stats/funnel.js
@@ -10,7 +10,7 @@ const FUNNEL_ID = 1
export default class Funnel extends React.Component {
constructor(props) {
super(props)
- this.state = {loading: true}
+ this.state = { loading: true }
this.onVisible = this.onVisible.bind(this)
this.fetchFunnel = this.fetchFunnel.bind(this)
}
@@ -25,14 +25,17 @@ export default class Funnel extends React.Component {
}
}
-
fetchFunnel() {
api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/funnels/${FUNNEL_ID}`, this.props.query)
- .then((res) => this.setState({loading: false, funnel: res}))
- .then(this.initialiseChart)
+ .then((res) => this.setState({ loading: false, funnel: res }))
+ .then(this.initialiseChart.bind(this))
}
initialiseChart() {
+ console.info(this.state.funnel);
+
+ const labels = this.state.funnel.steps.map(step => step.label);
+ const stepData = this.state.funnel.steps.map(step => step.visitors);
const ctx = document.getElementById('funnel').getContext('2d')
var gradient = ctx.createLinearGradient(0, 0, 0, 300);
@@ -40,10 +43,10 @@ export default class Funnel extends React.Component {
gradient.addColorStop(0, 'rgba(101,116,205, 0)');
const data = {
- labels: ['1. Visit /blog/**', '2. Visit /register', '3. Signup', '4. Go to moon', '5. Turn it up to 11'],
+ labels: labels,
datasets: [{
label: 'My First Dataset',
- data: [100, 80, 20, 4, 1],
+ data: stepData,
backgroundColor: [gradient],
borderColor: ['rgba(101,116,205)'],
borderWidth: 1,
@@ -56,17 +59,14 @@ export default class Funnel extends React.Component {
data: data,
options: {
responsive: true,
- layout: {
- padding: {left: 0, right: 0}
- },
plugins: {
legend: {
display: false,
},
},
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, 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)' } }
}
},
};
@@ -80,7 +80,7 @@ export default class Funnel extends React.Component {
} else if (this.state.funnel) {
return (
- Signup funnel
+ {this.state.funnel.name}
)
@@ -89,8 +89,8 @@ export default class Funnel extends React.Component {
render() {
return (
-
- { this.renderInner() }
+
+ {this.renderInner()}
)
}
diff --git a/lib/plausible_web/controllers/api/funnels_controller.ex b/lib/plausible_web/controllers/api/funnels_controller.ex
index c256ae5f6..402543685 100644
--- a/lib/plausible_web/controllers/api/funnels_controller.ex
+++ b/lib/plausible_web/controllers/api/funnels_controller.ex
@@ -3,6 +3,7 @@ defmodule PlausibleWeb.Api.FunnelsController do
def show(conn, _params) do
json(conn, %{
+ name: "Signup Funnel",
conversion_rate: "38%",
steps: [
%{