Refer a Friend using Stripe and Rails in 15 Lines of Code

A referral program on a SaaS product can often be the difference between success and failure. A famous example of this is Dropbox, which aquired four million users in just fifteen months; their referral program likely driving the companies success (which is just about to IPO).

For a one person shop, the trick is to completely automate the program – requiring no work to maintain. That’s what this article covers! In a few short lines of code, we’ll show you how the ProjectPiglet.com referral program was desgined / written, utilizing Ruby on Rails and Stripe.

Our Referral Program

First, it’s important to note there are many ways to design a referral program, ours is as follows:

Get 90 days free subscription ($150 value) in 2 minutes or less!

Here’s how it works:

  1. Refer someone you know providing the following link:
    <link on refer page for ProjectPiglet.com>
  2. They click on the link
  3. They sign up, with their credit card and activate their account.
  4. You immediately receive 90 days free on your subscription (in form of “trial”)

That’s it! Round trip, it should take less than two minutes.

Pretty straight forward and we make it worth the users effort! Now, lets look at implementation.

Rails App Design

Every web application is different, however Ruby on Rails forces a particular way to develop, which in this case is a good thing!

For instance, I can assume you have a “user scaffold”, which also comes with a user model & controller, with that model & contoller we can also make the assumption there is a “create function” in said controller. From there, all you need is stripe setup! For the sake of this post, we have a service wrapper around the stripe on ProjectPiglet.com – so basically we can treat stripe as a model. It’s really nice, and you can see that in our github gist.

That’s it! That’s all the prerequisites we assume – which is essentially: you’re using Rails and using Stripe!

User Registration Workflow

When a new users comes to register you typically want a few pieces of information. For ProjectPiglet.com, we try to keep that to a simple four pieces of information: Name, Email, Password; then you enter your credit card (which we validate). For us that looks like the following:

The question then becomes, how would you want to handle referrals? In our case, it was decided a link will be used for friend referrals and a coupon will be tied back for our “influencer referrals” (i.e. users who get enough people to register, they a cut of the subscription profits).The influencer referral program is not covered in this post.

The link we are looking for should be something like the following:

https://projectpiglet.com/signup?referred_by=<identifier>

Users then simply have to share that link to get the referral(s), the new potential users will be sent to the signup page and the “referred_by” parameter will then be used by rails to link bake to the referrer. In our case, it’ll just be the user id.

Refer a Friend Implementation (Rails & Stripe)

With the design being in place, it’s really as simple as adding a little bit of code to the create function in user_controller.rb class (14 lines of functional code). I personally add it after the credit card and email validation checks:

Note, our payment system service is in this github gist – it’s merely a wrapper around Stripe.

Then, for some Rails magic, we add the foreign key reference to your user.rb model.

This lets your use it as a reference to link back to a particular user (1 line of functional code):

With both of those in place, you’re done! We utilize the stripe “trial” feature to set the date to 90 days further out. This makes it completely automated dead simple to maintain. The only difficult part (if you’d call it that), was ensuring that the trial times are added to the current trial end date (basically the trial time stacks). Without that, the end date would always be just 90 days from the date of code execution (which would upset customers).

Finally, if you’d like to display who referred who, you can use the following partial:

Again, dead simple – in part because we created that referred_by foreign key reference.

Unfortunately, there are some caveats, although they are minimal. For instance, ProjectPiglet.com has users add their credit card at signup. That means, I know with a high probability it’s not a fake user singing up (as we do card validation). This makes it much easier for me to manage any potential users trying to game the system, if your web application doesn’t have that, additional validations should occur.

There’s also the case of shutting down the new account. If a user shuts down account, do you take away the free trial? That’s a question for you, personally I’ve gone both ways.

Regardless, of the caveats above, I hope this helps!

If you’re interested in using ProjectPiglet.com, use the coupon code: pigletblog2018

It’s 25% off for 6 months! Plus, clearly we have a refer a friend program!

New Onboarding Process

In addition to the exciting news about our Refer a Friend Program, we also improved our onboarding.

In this particular case, we’ve stolen a page from the Twitter onboarding process… We noticed we had a 100% convergence rate of customers (from trial to paying), if they were following at least five topics. It appears Twitter made a similar discovery!

As of today, all new users are greated by a selection of topics may want to follow:

These are curated list of topics I personally found to be fairly interesting and representitive as a whole of the category. This should be improved over time, but for the moment each one of those categories follow at least five topics, with some (such as Sicence) following as many as twelve. Users can select as many categories as they’d like.

Further, after that, now all users will be immediately thrown into a tour. Personally, I tend to dislike that option. However, because we are now encouraging the following of topics immediately, the tour link will be less bold and in your face.

Users will only see the large “Click to Begin Guided Tour” if they are not alrady following five topics (aka skipped selection, which we do allow):

If people are interested in following those general categories, you can go to ProjectPiglet.com/onboarding and select them (even if you already have been using the service).

Refer a Friend Program!

Today we’re happy to announce we’ve officially added our referral program!

The details are below!


Refer a Friend

Get 90 days free subscription ($150 value) in 2 minutes or less!

Here’s how it works:

    1. Refer someone you know providing the following link:<link on refer page for ProjectPiglet.com>
    2. They click on the link
    3. They sign up, with their credit card and activate their account.
    4. You immediately receive 90 days free on your subscription (in form of “trial”)

That’s it! Round trip, it should take less than two minutes.

Refer Lots of Friends!

In addition, we also have an Influencer Referral Program, accessible to users who have referred over 10 users. We offer a percentage of profits! This works by providing a coupon code and all users who use that coupon code are associated with you.

We provide a 10% – 50% cut of sales (depending on influence).

If intersted, contact us directly.

** Note: We reserve the right to cancel this program at any time.

March Stats & Invoice Notifications

Greetings!

One thing I’m meticulous about is stats. I try to maximize return to my customers and work hard to ensure my systems are the best possible.

In that regard, one thing I’ve implemented this week – invoice notifications. From here on out, I am notify every customer of how much their payment will be and if they would like to provide feedback (for one month free), they can.

Signup Stats

With that in mind, some quick stats:

  • Of the 40 people who signed up for a trial last month (at $25 – $50 per month), 28 converted to users
  • Of the 28 converted, 15 provided feedback and were provided the next month free
  • Of the 12 who didn’t convert to “paying users”, 4 provided feedback and are still participating
  • That makes a total of 32 people

Those numbers may not sound great to you. However, given I haven’t advertised or otherwise done much of anything besides occassionally mention ProjectPiglet in a comment and let my current users share, that’s pretty exciting. It’s a pretty expensive product for a consumer. What’s getting me more excited, is with the influx of users over the last 6 weeks (~100), my emails stats have stayed consistent.

Email Stats

Last month, we sent 1,718 emails (trade, opinion change, invoice notifications), that’s up from the 767 we sent the prior 30 days.

The good news about that, is although we’ve had an uptake, we’ve maintained the exact same open and click rates between both 30 day segments:

Which I’m reading as, we have a product people want – as those open & click rates are high for the average website. Especially, considering we send an average of 2.2 emails a day for a user with notifications set.

Which brings me to my last point, only 50% (~50 users) are following trends / topics. Of those, if user followed at least five trends / topics, they were 100% likely (thus far) to convert to a full customer. Thus my goal for the next month is to improve the new customer experience to ensure I can improve the following of trends / topics / assets.

Anyway, that’s it for now! Good news!