akoha / django-lean
A framework for performing and analyzing split-test experiments in Django applications.
$ hg clone http://bitbucket.org/akoha/django-lean
Welcome
django-lean aims to be a collection of tools for Lean Startups using the Django platform. Currently it provides a framework for implementing split-test experiments in JavaScript, Python, or Django template code along with administrative views for analyzing the results of those experiments.
In the spirit of lean, we have open-sourced this library as quickly as possible, meaning that it might not have all the bells and whistles one might hope for, in particular with regards to setup. Any competent Django/Python developers should have little trouble integrating django-lean with their own projects, but if you would like to see support for your favorite installation mechanism, consider contributing a patch.
Discussion Group
For discussions related to the use or development of django-lean please use our Google group.
Features
django-lean allows you to perform split-test experiments on your users. In brief, this involves exposing 50% of your users to one implementation and 50% to another, then comparing the performance of these two groups with regards to certain metrics.
Experiments Types
django-lean supports two kinds of experiments currently:
- Anonymous Conversion experiments compare the achievement of goals you define (i.e. "register" or "add to cart") amongst two groups of anonymous users.
- Registered Engagement experiments compare a quantitative measure of engagement that you define (i.e., activity, revenue, time on site, ...) amongst two groups of registered users.
There's no real reason why one couldn't measure engagement of anonymous users or conversions of registered users (i.e. "basic to pro") but we didn't need this, so they're not implemented (again, patches welcome!).
Experiment Reports
django-lean provides daily reports of experiment results, including confidence levels.
- For conversion experiments, results and confidence are displayed per conversion goal type (and for 'any' goal). Confidence is calculated using the chi-square method.
- For engagement experiments, confidence is calculated using the Student's t-test method.
Experiment reports are prepared using the update_experiment_reports management command. It's advisable to execute this command from a nightly cron-job.
Bot Exclusion
django-lean attempts to exclude non-human visitors from experiment reports by only recording data for visitors who have JavaScript enabled.
Experiment Management
Experiments may be defined, enabled, disabled, or promoted via the django-admin interface. You may also define experiments in your source tree and have them automatically loaded into the database (see experiments.loader.ExperimentLoader).
Each experiment has a state, which affects whether visitors are enrolled in the experiment, and whether they see the control or test case of the experiment.
disabled: No visitors are enrolled in the experiment. All visitors see the control case of the experiment, even if they were previously enrolled in the test group.enabled: All visitors who encounter the experiment are enrolled randomly in either the test or control group, and see the corresponding case.promoted: No visitors are enrolled in the experiment. All visitors see the test case of the experiment, even if they were previously enrolled in the control group.
New experiments start in the disabled state.
Experiment Implementation
django-lean makes it easy to implement experiments in Python, JavaScript, or Django templates. Here are some examples:
Python
Django Templates
JavaScript
(In your HTML template:)
(In your JavaScript:)
Conversion Tracking
Conversion experiments track the rate of conversion for their test and control groups. It is up to you to define and record the achievement of one or more project specific conversion goals.
Defining Conversion Goals
Conversion goals are defined by placing rows in the experiments_goaltypes table. This table is not currently exposed via django-admin but probably should be (patches welcome!). Alternative ways to populate it include manually via SQL, manually via the Django shell, via your initial_data fixture, or by defining a data migration in your database management tool (we use django-south).
Here is an example of defining a goal type using the Django shell:
Recording Conversions
Once you have defined a conversion goal type, you must record it when it is achieved place. This may be done either programatically, or using a tracking pixel.
Recording Conversions Programatically
Recording Conversions Using a Tracking Pixel
Sometimes a conversion happens somewhere that you don't control (for example, an e-commerce platform). In this case, you can record the conversion by placing a transparent 1x1 pixel on the page that users see after the conversion occurs (i.e., the 'Thank You' page after purchase).
Engagement Tracking
Engagement experiments track an arbitrary engagement value for each user in their test and control groups. It is up to you to define a function that calculates an appropriate engagement value for your users.
Here is an example engagement calculator:
Your engagement calculator must be registered in settings.py as follows:
Dependencies
django-lean has a number of dependencies:
Mox and Beautiful Soup are used exclusively by unit tests. JQuery is used only to execute a single, trivial AJAX request and could easily be removed from the dependency list if one were motivated (patch please!).
You may optionally use South in order to facilitate migrations of the django-lean database schema, but it is not required:
Installation
django-lean has been developed with Django 1.0. Unit Tests run successfully with Django 1.1 but it has not been tried in production. If you successfully run it with another version, please update this documentation.
- Install
django-leanusingeasy_install - Add
experimentstoINSTALLED_APPSinsettings.py - Ensure that
django.core.context_processors.requestis inTEMPLATE_CONTEXT_PROCESSORSinsettings.py - Run
manage.py syncdbto set up thedjango-leantables. - Run
manage.py test experimentsto see if everything is set up correctly. - For every page that will contain an experiment (or in the response after a server-side experiment):
- Ensure that JQuery is included.
- Ensure that
experiments/include/experiments.jsis somehow included (perhaps copy it where your static files go, include it as part of your existing generated JS files, map it fromurls.py, include it directly in a<script/>tag, etc.). - Ensure that
experiments/include/experiment_enrollment.htmlis rendered by your template.
- Install the admin and public url mappings in your site
urls.py - Register your engagement calculator in
settings.py. - Define one or more conversion goal types.
- Add conversion goal recording where appropriate.
- Define, implement, and enable an experiment
- Call
manage.py update_experiment_reportsnightly. - Experiment, learn, repeat!
Installing URL Mappings
The following snippet added to should properly install the needed URL mappings (adjust to meet your needs):
Development
Other Resources
The following links might be of interest to those wanting to learn more about Lean Startup, split testing, and related concepts.
- http://elem.com/~btilly/effective-ab-testing/
- http://www.startuplessonslearned.com/search/label/lean%20startup
- http://www.startuplessonslearned.com/search/label/split-test
- http://www.slideshare.net/erikwright/djangolean-akohas-opensource-ab-experimentation-framework-montreal-python-9
This revision is from 2010-06-20 19:26
