Professional Documents
Culture Documents
Installing Saleor
Saleor server and the admin dashboard are located in a single repo ,
and the storefront is in the separate repo. For the purpose of the
tutorial, we need only the server and the admin dashboard. It comes
with very good documentation and detailed installation guide, which
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 1/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
you can find here. Please follow the instructions on installation and
them come back here.
Saleor server and the admin dashboard are located in a single repo
here. It comes with very good documentation and detailed installation
guide, which you can find here. Please follow the installation
instructions and them come back here.
Once, it is installed, let’s populate our store with example products and
orders, as well as the admin account. Run the following command in
your terminal.
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 2/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
Installing Cube.js
Now, as we have Saleor up and running we can install Cube.js to start
adding analytical features to our e-commerce dashboard. The Cube.js
backend is a Node app, which could be run as a separate microservice
or in a serverless mode. Let’s create our Cube.js backend instance.
CUBEJS_DB_TYPE=postgres
CUBEJS_DB_NAME=saleor
CUBEJS_DB_USER=saleor
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 3/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
The next step is to tell Cube.js how to convert raw data in the database
into meaningful analytics insights. This process is sometimes called
data modeling. It is a way to translate business level definitions, such as
customer lifetime value into SQL. In Cube.js it’s called schema and
schema files are located in ‘schema’ folder.
cube(`Orders`, {
sql: `select * from order_order`,
measures: {
count: {
type: `count`
}
},
dimensions: {
created: {
type: `time`,
sql: `created`
}
}
});
Cube.js uses schema to generate a SQL code, which will run in your
database and return a result back. A schema is also used to manage pre-
aggregations and cache, you can learn more about it here.
That is all we need to start our first analytics server. In the project
folder run:
Now, as we have Cube.js server up and running the next step is to add
analytics section to our Saleor admin dashboard.
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 4/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
DashboardPage.displayName = "DashboardPage";
export default DashboardPage;
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 5/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
First, will add new icon component and then edit AppRoot.tsx to add
menu item.
// ...
That’s it! Open admin dashboard in your browser and you should see
the new menu item. Now, let’s add some charts to our Analytics Page.
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 6/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 7/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
return renderChart(resultSet);
}}
/>
</Card>
);
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 8/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
ChartCard.displayName = "ChartCard";
export default ChartCard;
DashboardPage.displayName = "DashboardPage";
export default DashboardPage;
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 9/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
First, let’s add support for other visualizations, such as a pie chart. The
query to Cube.js will remain the same, we just need to support the pie
chart in the renderChart methods. Also, we’ll add support for
currency formatting using numeraljs.
const formatters = {
currency: (val) => numeral(val).format('$0,0'),
date: (val) => moment(val).format("MMM DD"),
undefined: (val) => val
}
const renderLine = (resultSet) => (
<Chart
scale={{ category: { tickCount: 8 } }}
height={CHART_HEIGHT}
data={resultSet.chartPivot()}
forceFit
>
<Axis name="category" label={{ formatter:
formatters.date }} />
{resultSet.seriesNames().map(s => (<Axis name={s.key}
label={{ formatter:
formatters[resultSet.loadResponse.annotation.measures[s.key]
.format] }} />))}
<Tooltip crosshairs={{type : 'y'}} />
{resultSet.seriesNames().map(s => (<Geom type="line"
position={`category*${s.key}`} size={2} />))}
</Chart>
);
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 10/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
ChartCard.displayName = "ChartCard";
export default ChartCard;
cube(`Orders`, {
sql: `select * from order_order`,
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 11/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
measures: {
count: {
type: `count`
},
totalNet: {
sql: `total_net`,
type: `sum`,
format: `currency`
},
averageValue: {
sql: `total_net`,
type: `avg`,
format: `currency`
}
},
dimensions: {
created: {
sql: `created`,
type: `time`
},
status: {
sql: `status`,
type: `string`
}
}
});
We have added two new measures — total sales and average sales. And
one new dimension — status.
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 12/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
const cardContainerStyles = {
display: "grid",
gridColumnGap: "24px",
gridTemplateColumns: "1fr 1fr",
rowGap: "24px"
}
const timeDimensions = [{
dateRange: [
moment().subtract(30, 'days').format("YYYY-MM-DD"),
moment().format("YYYY-MM-DD")
],
dimension: 'Orders.created',
granularity: 'day'
}];
const queries = [
{
query: {
measures: ["Orders.count"],
timeDimensions
},
title: i18n.t("Total Orders"),
visualizationType: 'line',
},
{
query: {
measures: ["Orders.totalNet"],
timeDimensions
},
title: i18n.t("Total Sales"),
visualizationType: 'line'
},
{
query: {
measures: ["Orders.averageValue"],
timeDimensions
},
title: i18n.t("Average Order Value"),
visualizationType: 'line'
},
{
query: {
dimensions: ["Orders.status"],
measures: ["Orders.count"]
},
title: i18n.t("Orders by Status"),
visualizationType: 'pie'
}
];
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 13/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
DashboardPage.displayName = "DashboardPage";
export default DashboardPage;
This will give us a fully working dashboard with four basic metrics. In
the next tutorial, we’ll show you how to add dashboard filters and a
query builder to let users build custom reports.
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 14/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 15/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 16/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 17/18
6/20/2019 Adding an E-Commerce Admin Dashboard to Saleor – Stats and Bots
https://blog.statsbot.co/adding-an-e-commerce-admin-dashboard-to-saleor-da87be14c40e 18/18