Building a Stripe Analytics Dashboard in Ruby
Track Your Startup Growth
Recently I started building a Stripe analytics dashboard for fun. Here’s how it has evolved from a simple idea, into a personal tool to run locally, and then into a functional Stripe Connect application.
If you’re not familiar with Stripe, it is an awesome tool for payments and subscriptions. And by default, the Stripe dashboard provides a pretty decent look at your monthly payments and subscription data.
However to get in depth analytics on things like your startup’s monthly growth, earnings after refunds, # of new signups by subscription plan, etc, you need to crunch some numbers.
What already exists
A little bit of research will reveal that there is no shortage of analytics tools for Stripe
Still, the idea of building my own anayltics dashboard sounded like a fun technical challenge to beef up my skills a little with my current programming languages.
So I decided to see if I could build a simple, straightforward Stripe analytics dashboard that can analyze my data so I don’t have to track it manually with spreadsheets or something similar.
To start, I initially just focused on building something that would let me view analytics for my own accounts locally.
Getting basic data from Stripe on an account is fairly straightforward, you can read further from their API docs here.
Here’s an example getting a list of charges from your account:
Next I started building an analytics class to process data I’d be getting back from Stripe to start crunching the numbers into core metrics.
For example, here’s a method I’ve been playing with to calculate growth between a current and previous dataset:
In the above example, I’m getting charges from this month and comparing them against charges from last month. Then I can pass all of the totals (charges, refunds, revenue, subscriptions, etc) from those through the above method to get the percentage change to see how this month compares to last month.
After digging a little more through Stripe’s documentation, figuring out how to get the necessary data and crunching it into actionable metrics, a little while later, I had the early stages of a semi functional dashboard put together:
After making some tweaks to the dashboard, the next thing I wanted to do is use Stripe Connect to make my application more than just a personal tool that I can run locally.
Stripe Connect basically allows you to do things like build marketplaces powered on Stripe, manage user accounts, and more crazy awesomeness.
In our case, it will be used to let people connect their accounts to this platform, essentially granting it permission to read and analyze their Stripe charges and subscription data necessary to provide analytics.
I’ll try to outline the steps involved here briefly:
Basically once you register your application in your Stripe account, Stripe will give you a client id that you append as a url parameter some sort of “Connect with Stripe” button in your site:
When the user clicks on your connect button, they get redirected to Stripe where they can confirm that they want to authorize their account in your application.
Once they confirm, Stripe will redirect the user to a url end point that you specify, passing back an authorization code with them. Using that authorization code, you can then make a request to get the unique “stripe_user_id” for that user from Stripe.
Once you have the stripe user id, you can successfully begin to pull data from the users account, authorizing each request with the stripe user id.
Here’s an example snippet from my application that handles the steps just after Stripe returns the initial authorization code:
You can see on line 42 I’m retrieving the “code” parameter from the Stripe response when Stripe redirects the user back to the application.
Then using that, along with the API key from my account the application is built with, I can make a follow up request to get the actual stripe user id that will ultimately be used for requesting things like charge data.
And here’s an example of the earlier method that gets a list of Stripe charges, modified to be used with Stripe Connect:
You can see it’s very similar to the example when it was just for my own personal use, however now we’re passing in an additional “stripe_account” value.
As of right now, I’m saving very little information in the actual web app which I kind of like.
All that gets saved are your account credentials you create for the site, and the stripe user id from Stripe so that users don’t have to re-authorize the Stripe connection every time they want to view the dashboard.
I had a nice working title for this project that I really like, however because it has Stripe in the name I’m pretty sure I can’t use that.
So instead I decided to go with the name tigerlytics.io which I also think is kind of cool (get it? get it? bcuz tiger’s have STRIPES… I’ll see myself out).
I’ve had a lot of fun building this out so far, and there’s still a ton of things to do to improve it.
A few things on the horizon include letting users pass in custom date ranges (which I’m already playing with), fixing up the dashboard for mobile (which is still a little messy at the moment), speed up the number crunching for the dashboard, letting users set goals to compare against, along with several other ideas.