Comparing Cohorts Using Funnels

Cohort analysis is a subset of behavioral analytics that takes data and breaks them into related groups for analysis. These related groups, or cohorts, usually share common characteristics or experiences within a defined timespan. Cohort analysis enables you to see patterns within the defined timespan by slicing the analysis with defined time intervals. Cohort Analysis can help you understand and measure the effectiveness of a feature or application. You can check out our blog on Cohort Analysis.

Here are some common ways to sort users into cohorts:

  • Signup date - compare people who signed up in week 1 vs people who signed up in week 2, 3, 4, etc
  • Referrer - compare users based on how they found you (twitter, blog post, adwords, facebook campaign)
  • App version - compare users based on their app version (e.g. version 1.0, 1.1, 1.2)
  • A/B testing - compare users based on what alternative of your app they are using (e.g. version A or B)

This guide explains how to use two funnels to compare different cohort analyses.

Combining Funnels

A funnel is a flow of events that a user performs on their way to reaching a goal.

The recipe below combines the results of two funnel queries into a single visualization. This allows you to have a side-by-side view of two (or more) funnel queries. The side-by-side comparisons can be seen step-wise and are organized by the interval used in the filter.

In this example you can see the number of users using “iOS” versus “Android” side-by-side all the way through the funnel.

This introductory sample recipe exposes the ability to do a basic cohort analysis with Keen IO.


var client = new Keen({
  projectId: "YOUR_PROJECT_ID",
  readKey: "YOUR_READ_KEY"
});

Keen.ready(function(){

  // first query for device type 1
  var steps_iOS = [
      {
        event_collection: "start",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:iOS
        }]
      },
      {
        event_collection: "occupancy-options",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"iOS"
        }]
      },
      {
        event_collection: "extras",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"iOS"
        }]
      },
      {
        event_collection: "details",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"iOS"
        }]
      },
      {
        event_collection: "finish",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"iOS"
        }]
      }
  ];

  var iOS = new Keen.Query("funnel", {
      steps: steps_iOS
  });

  // second query for device type 2
  var steps_android = [
      {
        event_collection: "start",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:android
        }]
      },
      {
        event_collection: "occupancy-options",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"android"
        }]
      },
      {
        event_collection: "extras",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"android"
        }]
      },
      {
        event_collection: "details",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"android"
        }]
      },
      {
        event_collection: "finish",
        timeframe: "this_14_days",
        actor_property: "session",
        filters: [{
          property_name:"device",
          operator:"eq",
          property_value:"android"
        }]
      }
  ];

  var android = new Keen.Query("funnel", {
      steps: steps_android
  });

  var combinedFunnel = new Keen.Dataviz()
    .el(document.getElementById('funnel2'))
    .chartType('columnchart')
    .chartOptions({
      legend: { position: 'none' },
      orientation: 'horizontal'
    })
    .width(800)
    .prepare(); // start spinner

  client.run([iOS, android], function(err, response) {
      // if (err) throw('Error!');

      var output = {
          result: [],
          steps: steps_iOS
      };

      // Combine results
      Keen.utils.each(response[0].result, function(stepResult, i){
          output.result.push([
              response[0].steps[i].event_collection,
              response[0].result[i],
              response[1].result[i]
          ]);
      });

      // Draw custom data object
      combinedFunnel
        .parseRawData(output)
        .render();

  });

});

The resulting chart looks like this: Blue for “iOS” and Red for “Android”

Comparison Funnel

If you had more than two cohorts or required multiple views, you can adapt the code to allow for as many cohorts as you needed to view side-by-side in each step in the filter.