Getting Started With Analytics and Marketing Automation for Ruby Apps

Have you gotten your MVP out the door? Congrats! Now are you wondering what your users are doing and how well it’s working? It’s time for analytics and marketing automation!

This post will go through an opinionated minimum viable marketing automation stack in Ruby. The goal is to take an existing funnel, instrument it with events, track how it’s going, and then use email automation to improve conversion rates.

We’ll take a school course application process as an example where the user logs in with a social account (Facebook, Twitter, etc) and then goes through a multi step application.

Technology Choices

If you haven’t already installed Google Analytics. It’ll work out of the box and get you started on understanding who is using your site.

Next, we’ll install and configure Segment’s Ruby library. We choose to use Segment because it acts as a uniform interface to dozens of helpful automation tools. This post will use only Mixpanel but Segment has many options to play with later (all without having to update your code).

We’ll identify and track when a user signs up so we can attach events to this user later on. Below is an exmaple of implementing these methods on our User model, which we would call when we create the user after signing in.

# user.rb

def initial_identify
      created_at: self.created_at,
      completed_application: false

def track_registration
    event: "UserCreated",
    properties: { email:, timestamp: }

Now that we are sending events upon sign up, we’ll want to configure Segment to push events to Mixpanel. We’ll make this change via Segment’s UI.

Understand and Instrument Your Funnel

We now have the barebones data flowing into our analytics system and our next step is to instrument our funnel so we can see how well users progress through each step. Our application process that we are using as an example looks like the following flow:

  1. User is created (here’s where we tracked UserCreated above)
  2. Fills out some biographic data
  3. Uploads a resume
  4. Takes a quiz to judge fit for the program
  5. Submits the final application after making any changes to answers

We want to take each of these steps and track when a user completes each step. In this way, we can know which steps are difficult for users and focus our efforts on improving them. We’ll implement this tracking with the following code in our ApplicationController and then use it in each endpoint where a user completes a step

# ApplicationController

def track_event(event, properties = {})
  properties.merge!({timestamp:, email:})

    event: event,
    properties: properties

And when we use it, it would like look:


Segment has some great recommendations on event naming. Check our their docs.

Analyze Funnel Issues

Now that we are pushing each of our funnel events to Segment (and through to Mixpanel) we can build our funnel in Mixpanel and begin looking at steps where users drop off. If there is a glaring step where users are dropping off, spend time researching why and fix it. Once you have improved each step, it’s time for some marketing automation to bring back abandoned users.

An Example Mixpanel Funnel

Setup Automation to Fix Funnel Issues

It’s important to say again; do what you can to improve your funnel before throwing automation at it. Once we’ve done that, let’s use Mixpanel’s messages product to send targeted emails to users who meet certain criteria. Example of criteria for us could be a user that meets the following criteria:

When a user meets all these criteria, we’ll send them an email. The magic of Mixpanel is that these emails (and their openings) are also events upon which we can build funnels. Our next step is to build another funnel to track how our email campaign works.

From there, it’s observing the data and tweaking, tweaking, tweaking as our funnel improves.

Want to go deeper?