Skip to content

Conversation

@bmarini
Copy link
Contributor

@bmarini bmarini commented Jun 23, 2013

This adds two new attributes to Split.configuration,
on_trial_choose and on_trial_complete.

Set these attributes to a method name available in the
same context as the ab_test method. These methods should
accept one argument, a Trial instance.

For example:

Split.configuration.on_trial_choose = :log_choice

# application_controller.rb
def log_choice(trial)
  logger.info "experiment=%s alternative=%s user=%s" %
    [ trial.experiment.name, trial.alternative, current_user.id ]
end

The motivation for this is I want to store a user event when a user participates in an experiment, and when a user reaches an experiment's goal. I want to store this info somewhere besides redis, and do cohort analysis later on, where cohorts would be users who participated in a particular experiment alternative. Let me know what you think. I'm pretty new to this gem so there may be a cleaner way to do this that I'm missing.

This adds two new attributes to Split.configuration,
on_trial_choose and on_trial_complete.

Set these attributes to a method name available in the
same context as the ab_test method. These methods should
accept one argument, a Trial instance.

For example:

    Split.configuration.on_trial_choose = :log_choice

    # application_controller.rb
    def log_choice(trial)
      logger.info "experiment=%s alternative=%s user=%s" %
        [ trial.experiment.name, trial.alternative, current_user.id ]
    end
@coveralls
Copy link

Coverage Status

Coverage decreased (-0%) when pulling bb0c78e on bmarini:trial-hooks into ddbfbcd on andrew:master.

@andrew
Copy link
Member

andrew commented Jul 2, 2013

Looks great, can you add some documentation to the readme about the options?

@bmarini
Copy link
Contributor Author

bmarini commented Jul 2, 2013

Yeah, absolutely.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0c54792 on bmarini:trial-hooks into ddbfbcd on andrew:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 0c54792 on bmarini:trial-hooks into ddbfbcd on andrew:master.

@andrew
Copy link
Member

andrew commented Jul 2, 2013

Sweet, thanks!

🤘

andrew added a commit that referenced this pull request Jul 2, 2013
Add hooks for Trial#choose! and Trial#complete!
@andrew andrew merged commit a05b86f into splitrb:master Jul 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants