diff --git a/assets/js/dashboard/historical.js b/assets/js/dashboard/historical.js index 524bcbab5..688bc4b0a 100644 --- a/assets/js/dashboard/historical.js +++ b/assets/js/dashboard/historical.js @@ -9,7 +9,7 @@ import Sources from './stats/sources' import Pages from './stats/pages' import Locations from './stats/locations'; import Devices from './stats/devices' -import Conversions from './stats/conversions' +import Funnel from './stats/funnel' import ComparisonInput from './comparison-input' import { withPinnedHeader } from './pinned-header-hoc'; @@ -20,7 +20,7 @@ function Historical(props) { if (props.site.hasGoals) { return (
- +
) } diff --git a/assets/js/dashboard/stats/funnel.js b/assets/js/dashboard/stats/funnel.js new file mode 100644 index 000000000..000998a09 --- /dev/null +++ b/assets/js/dashboard/stats/funnel.js @@ -0,0 +1,97 @@ +import React from 'react'; +import Chart from 'chart.js/auto'; + +import * as api from '../api' +import LazyLoader from '../components/lazy-loader' + +const FUNNEL_ID = 1 + + +export default class Funnel extends React.Component { + constructor(props) { + super(props) + this.state = {loading: true} + this.onVisible = this.onVisible.bind(this) + this.fetchFunnel = this.fetchFunnel.bind(this) + } + + onVisible() { + this.fetchFunnel() + } + + componentDidUpdate(prevProps) { + if (this.props.query !== prevProps.query) { + this.fetchFunnel() + } + } + + + 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) + } + + initialiseChart() { + const ctx = document.getElementById('funnel').getContext('2d') + + var gradient = ctx.createLinearGradient(0, 0, 0, 300); + gradient.addColorStop(1, 'rgba(101,116,205, 0.3)'); + 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'], + datasets: [{ + label: 'My First Dataset', + data: [100, 80, 20, 4, 1], + backgroundColor: [gradient], + borderColor: ['rgba(101,116,205)'], + borderWidth: 1, + borderRadius: 8 + }] + }; + + const config = { + type: 'bar', + 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)'}} + } + }, + }; + + new Chart(ctx, config); + } + + renderInner() { + if (this.state.loading) { + return
+ } else if (this.state.funnel) { + return ( + +

Signup funnel

+ +
+ ) + } + } + + render() { + return ( + + { this.renderInner() } + + ) + } +}