Bernoulli

Python

  1. pip install bernoulli
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. set BERNOULLI_CLIENT_ID Environment Variable to your client ID (on Heroku this is done for you by installing the add-on)
  5. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    
    def get_signup_copy():
        experiments = bernoulli.get_experiments(experiment_ids=['signup'], user_id='s59', user_data={
            'age': 30,
            'gender': 'f',
        })
        chosen_variant_id = experiments[0]['variant']
        if chosen_variant_id == 'free_copy':
            return 'Sign up for free'
        elif chosen_variant_id == 'trial_copy':
            return 'Start your trial'
    
  6. Record when a user completes the flow
    bernoulli.record_goal_attained(experiment_id='signup', user_id='s59')

Django

  1. pip install bernoulli_django
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. In settings.py make sure 'django.core.context_processors.request' is in TEMPLATE_CONTEXT_PROCESSORS. For example
    TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS + ('django.core.context_processors.request',)
  5. Add 'bernoulli_django' to INSTALLED_APPS in settings.py
  6. Set BERNOULLI_CLIENT_ID in settings.py
    BERNOULLI_CLIENT_ID=os.environ.get('BERNOULLI_CLIENT_ID', None)
  7. Modify your template to handle the experiment. For example:
    {% load experiments %}
    {% experiment signup request %}
        {% variant free %}
            <a href="{% url 'free' %}">Sign up for free</a>
        {% endvariant %}
        {% variant trial control %}
            <a href="{% url 'trial' %}">Start your trial</a>
        {% endvariant %}
    {% endexperiment %}
    
  8. Record when the user took an action.
    def free(request):
        record_variant_goal(request, 'signup')

NodeJS

  1. npm install bernoulli
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. set BERNOULLI_CLIENT_ID Environment Variable to your client ID (on Heroku this is done for you by installing the add-on)
  5. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    var bernoulli = require('bernoulli');
    
    var getSignupCopy = function(callback) {
        bernoulli.getExperiments({
            userId: 'user59',
            experimentIds: 'signup'
        }, function(experiments) {
            switch (experiments[0].variant) {
                case 'free':
                    callback('Sign up for free');
                    break;
                case 'trial':
                default:
                    callback('Start your trial');
                    break;
            }
        });
    };
    
  6. Record when a user completes the flow
    bernoulli.goalAttained({
        userId: 'user59',
        experimentId: 'signup'
    }, function(success) { });
    

Ruby

  1. gem install bernoulli-metrics
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. set BERNOULLI_CLIENT_ID Environment Variable to your client ID (on Heroku this is done for you by installing the add-on)
  5. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    require_relative 'lib/bernoulli'
    
    def get_signup_copy
        response = Bernoulli.get_experiments(['signup'], 'user59')
    
        variant = response[0]['variant']
        if variant == 'free_copy'
            'Sign up for free'
        else variant == 'trial_copy'
            'Start your trial'
        end
    end
    
  6. Record when a user completes the flow
    Bernoulli.goal_attained('signup', 'user59')

C#

  1. From the Nuget Package Manager Console: Install-Package Bernoulli
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
    -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
    Opening bernoulli for sharp-mountain-4005…
    
  4. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    
    private string GetSignupCopy()
    {
        string clientId = Environment.GetEnvironmentVariable("BERNOULLI_CLIENT_ID");
        List<Experiment> experiments = Client.GetExperiments(clientId, new List { "signup" }, "user59", null);
        return experiments[0].Variant;
    }
    
  5. Record when a user completes the flow
    
    private void GoalAttained()
    {
        string clientId = Environment.GetEnvironmentVariable("BERNOULLI_CLIENT_ID");
        Client.GoalAttained(clientId, "signup", "user59");
    }
    

ASP.NET MVC

  1. From the Nuget Package Manager Console: Install-Package BernoulliMVC
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. Add namespace to Web.config
    <system.web>
        <pages>
            <namespaces>
                <add names=pace="BernoulliMVC.Extensions" />
            </namespaces>
        </pages>
    </system.web>
  5. Add Bernoulli Client ID to appSettings in Web.config (On AppHarbor this is taken care for you)
    <appSettings>
        <add key="BernoulliClientID" value="MY_KEY_GOES_HERE" />
    </appSettings>
  6. Add an experiment to a razor template:
    @using BernoulliMVC.Extensions;
    @using (var experiment = Html.GetExperiment("signup", "user59"))
    {
        if (experiment.IsVariant("free"))
        {
            <h1>Free Trial</h1>
        }
        else if (experiment.IsVariant("trial", true))
        {
            <h1>Signup Now</h1>
        }
    }
  7. Record when a user completes the flow
    
        private void GoalAttained()
        {
            string clientId = WebConfigurationManager.AppSettings["BernoulliClientID"];
            Bernoulli.Client.GoalAttained(clientId, "signup", "user59");
        }
    

Javascript

  1. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  2. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  3. <script src="//d8ojhlj1t3aps.cloudfront.net/bernoulli.min.js"></script>
  4. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    bernoulli.getExperiments({
        clientId: BERNOULLI_CLIENT_ID,
        experimentIds: 'signup',
        userId: 'user59'
    }, function(experiments) {
        console.log(experiments);
    });
    
  5. Record when a user completes the flow
    bernoulli.goalAttained({
        clientId: 1,
        experimentId: 'signup',
        userId: 'user59'
    }, function(success) {
        console.log(success);
    });
    

Java

  1. Add the dependency to your pom.xml file:
    <dependency>
        <groupId>io.bernoulli</groupId>
        <artifactId>bernoulli</artifactId>
        <version>0.5</version>
    </dependency>
    
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    import io.bernoulli.bernoulli.Client;
    public String GetSignupCopy() {
        List<Experiment> experiments = null;
        List<String> experimentIds = new ArrayList();
            experimentIds.add("signup_copy");
        try {
            experiments = Client.GetExperiments(BERNOULLI_CLIENT_ID, experimentIds, "user59", null);
        } catch (BernoulliException ex) {
            return "Start your trial";
        }
    
        Experiment experiment = (Experiment)experiments.get(0);
        if (experiment.Variant == "free") {
            return "Sign up for free";
        } else {
            return "Start your trial";
        }
    }
    
  5. Record when a user completes the flow
    public void RecordGoal() {
        try {
            Client.GoalAttained(BERNOULLI_CLIENT_ID, "signup_copy", "user59");
        } catch (BernoulliException ex) {
            return;
        }
    }
    
    

iOS

  1. Install CocoaPod (coming soon)
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    NSArray *experimentIds = [NSArray arrayWithObject:@"signup_copy"];
    [Bernoulli getExperimentsForIds:experimentIds clientId:@"BERNOULLI_CLIENT_ID" userId:@"user59" userData:nil success:^(NSArray *experiments) {
        id experiment = [experiments objectAtIndex:0];
        id variant = [experiment objectForKey:@"variant"];
        if (variant == "free") {
            // Show free message
        } else if (variant == "trial") {
            // Show trial message
        }
    } error:^(NSString *message) {
        // Handle Fallback
        return;
    }];
    
  5. Record when a user completes the flow
    [Bernoulli goalAttainedForId:@"signup_copy" clientId:@"BERNOULLI_CLIENT_ID" userId:@"user59" callback:^(BOOL success) {
        return;
    }]
    

PHP

  1. Install via composer by adding "bernoulli/bernoulli": "dev-master" to your composer.json file and running:
    $ composer update
  2. Install Heroku add-on
    $ heroku addons:add bernoulli
        -----> Adding bernoulli to sharp-mountain-4005... done, v18 (free)
    
  3. Design an experiment
    $ heroku addons:open bernoulli
        Opening bernoulli for sharp-mountain-4005…
    
  4. Fetch the experiment data for this user - a variant can automatically be chosen. Pass along any segmentation data to further target your experiment.
    function GetSignupCopy($userId) {
        $experiments = Bernoulli\Client::GetExperiments(['signup_copy'], $userId, [], "BERNOULLI_CLIENT_ID");
        if ($experiments[0]['variant'] == "free") {
            return "Signup for free";
        } else {
            return "Start your trial";
        }
    }
    
  5. Record when a user completes the flow
    
    function RecordGoalAttained($userId) {
        Bernoulli\Cient::GoalAttained('signup_copy', $userId, "BERNOULLI_CLIENT_ID");
    }
    
Email: contact@bernoulli.io
contact@bernoulli.io | Privacy | Terms of service