Advertisement
  1. Code
  2. PHP
Code

Building Your Startup: The Dashboard Foundation

by
Difficulty:IntermediateLength:LongLanguages:
This post is part of a series called Building Your Startup With PHP.
Building Your Startup: Sending Reminders
Building Your Startup: Improving the Mobile Web
Final product image
What You'll Be Creating

This tutorial is part of the Building Your Startup With PHP series on Envato Tuts+. In this series, I'm guiding you through launching a startup from concept to reality using my Meeting Planner app as a real-life example. Every step along the way, I'll release the Meeting Planner code as open-source examples you can learn from. I'll also address startup-related business issues as they arise.

As Meeting Planner nears alpha launch, we need a way to address support requests with users and monitor activity. In other words, we need to build an administrative dashboard with user management and reporting. In discussions with an advisor, we discussed that as I approach potential investors, I'll need to have excellent data detailing user behavior and growth of the service. 

In today's episode, we'll build the foundation for our administrative dashboard and take on and create some of the initial live and historical reporting. For example, we'll know how many people have registered at any time, how many meetings have been scheduled, and what percentage of invited participants like the service enough to go on to organize their own meeting. It's actually been pretty fun to build this stuff and see the data, even if we're pre-launch.

If you haven't tried out Meeting Planner yet (and want to show up in the aggregate data yourself), go ahead and schedule your first meeting. I do participate in the comment threads below, so tell me what you think! You can also reach me on Twitter @reifman. I'm especially interested if you want to suggest new features or topics for future tutorials.

As a reminder, all of the code for Meeting Planner is written in the Yii2 Framework for PHP. If you'd like to learn more about Yii2, check out our parallel series Programming With Yii2.

Building the Foundation of the Dashboard

The Yii Advanced Template

Yii2 offers front and back office websites within its advanced application setup. You can read more about it in my Envato Tuts+ tutorial, How to Program With Yii2: Using the Advanced Application Template. Essentially, the advanced template's front-end site provides people-facing functionality, and the back-end site is made for a service's dashboard and administration site.

In order to activate it, I just needed to set up Apache sites in my MAMP localhost environment and on my production Ubuntu server. For instance, here's the Apache configuration on the production server to load the /backend/web site:

Configuring Our Back-End Site

Next, I built a new layout for the back-end site based on the front-end site, but with different menu options. I decided the home page would redirect to a page of real-time statistics. And the menus would offer links to real-time data, data from yesterday at midnight and historical data. I'll explain a bit more of this as we proceed.

Meeting Planner Dashboard - Menu Layout

Here's the \backend\views\layouts\main.php with the menu:

Building the Initial Reporting

For my initial statistics reporting, I focused on simple real-time data and detailed historical data. For example, real-time data would tell you the number of users and meetings built on the system to date and their status. 

The historical data would tell you the number of users and meetings completed over time as well as other interesting data—especially growth curves that I and prospective investors may care about.

Real-Time Data

The real-time data page needs to show a live snapshot of what's happening on the site. Initially, I wanted to know:

  • How many meetings are there in the system?
  • How many users are there?
  • What's their status?

To accomplish this, I created a back-end DataController.php and Data.php model. I also took a step forward and rather than create raw HTML in my view to display this, I created ActiveDataProviders from my queries and fed them to Yii's grid widgets; the result looks better and is simpler to build and maintain.

This code queries the number of meetings in the system grouped by their status:

This code in /backend/views/data/current.php displays it:

It looks like this (the data are small since the site hasn't launched yet!):

Meeting Planner Dashboard - Real Time Meeting Data

Then, I created a few more real-time queries, and the rest of the page looks like:

Meeting Planner Dashboard - Real Time Data People and Places

Regarding the People Active and Via invite columns above, if you invite a person to a meeting, we count them as a User via Invite until they create a password or link their social account. Until then, their only access to Meeting Planner is through your email invitation link and its authentication id.

Obviously, I'll expand the real-time reporting options as the project evolves.

Reporting Historical Data

Generating historical reporting for systemwide activities proved a bit more involved. I decided to create some dependent data-gathering layers.

The bottom layer is a UserData table that summarizes the state of a person's historical account activity up to a specific day at midnight. Essentially, we'll do this nightly.

The top layer is the HistoricalData table that builds its calculations using the UserData table from the night before.

I also needed to write code which built up the two tables from scratch since our service had been a bit active for several months.

I'll guide you through how I did this. The result turned out quite well.

Creating Table Migrations

Here is the table migration for UserData—it contains the data I wanted to calculate nightly to assist the historical calculations:

For example, count_meeting_participant_last30 is how many meetings this person was invited to in the last 30 days. 

Here is the table migration for HistoricalData—almost all of the columns in this table need to be calculated from different layers of data:

In discussion with my advisor, we realized that prospective investors will want to know how people are responding to the site. I created a measurement for a metric called percent_invited_own_meeting, short for the percentage of users invited to their first meeting who liked the service enough to use it to schedule their own meeting in the future. I'll review more about the calculations a bit further below.

The migrations all reside in /console/migrations. Here's what it looks like when you run the database migrations.

Gathering the Reporting Data

Each night after midnight, a background task will calculate the previous night's statistics. Here's the background method:

I set up a cron job to run actionOvernight at 1:15 am daily. Note: When you're focused intently programming on a startup day and night, a cron job is about all the actionOvernight you'll get.

To build up the history of the past, I created a one-time recalc() function. This flushes the tables and builds up each table as if it was happening a day at a time. 

Note: The after time is a workaround to exclude some of the early users who signed up before they could schedule a meeting. I wanted the historical data to reflect a more accurate depiction of recent activity (currently there are a couple hundred older accounts without any activity). I'll likely remove this at a later date.

Calculating the User Data Table

Here's the code that populates the UserData table nightly:

It's mostly just counting totals for users of meetings, places, friends and in some cases within time ranges of the last 30 days. 

Here's the code that detects whether this user chose to schedule a meeting using the service after having been invited:

Calculating the HistoricalData

Here's the code that leverages UserData to populate HistoricalData:

It's summarizing totals and calculating percentages and averages.

Here's what the finished product looks like:

Meeting Planner Dashboard - Final Historical Data

Even though we're seeing the analysis of only pre-alpha usage, the data is intriguing, and the potential usefulness of this appears excellent. And, of course, it will be easy to expand the data collection and analysis using the foundational code I shared with you today.

By the way, the percentage of invited users going on to schedule their own meetings is about 9% (but it's a small dataset).

You're probably wondering if we can chart these columns. I hope to address that in a follow-up tutorial, which always requires interaction with the editorial goddesses. Just FYI, not everyone walks away from those conversations. I'll also ask her to allow me to write about administration features such as disabling users, resending passwords, etc.

Meeting Planner Dashboard - Game of Thrones Melisandre

If you don't hear more from me, know that the Lord of Light has found a use for me.

What's Next?

As mentioned, I'm currently working feverishly to prepare Meeting Planner for alpha release. I am primarily focused on the key improvements and features that will make the alpha release go smoothly.

I'm tracking everything in Asana now, which I'll write about in an upcoming tutorial; it's been incredibly helpful. There are also some interesting new features still on their way. (As a yoga teacher, I think Asana is the worst product name ever. They've basically taken a common term in yoga pronounced āsana or ah-sana and changed the pronunciation to a-sauna — and put that in their introductory videos. It wasn't easy consulting last year talking to client team members about what they put in a sauna and talking to yogis about āsana. But I digress.)

I'm also beginning to focus more on the upcoming investment gathering effort with Meeting Planner. I'm just beginning to experiment with WeFunder based on the implementation of the SEC's new crowdfunding rules. Please consider following our profile. I will also write more about this in a future tutorial.

Again, while you're waiting for more episodes, schedule your first meeting and try out the templates with your friends with Gmail mailboxes. Also, I'd appreciate it if you share your experience below in the comments, and I'm always interested in your suggestions. You can also reach me on Twitter @reifman directly. You can also post them at the Meeting Planner support site.

Watch for upcoming tutorials in the Building Your Startup With PHP series.

Related Links

Advertisement
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.