Created
May 9, 2012 14:29
-
-
Save adri/2644900 to your computer and use it in GitHub Desktop.
abtest example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This would be returned from a abtest-server and | |
# executed in mp.com on application load | |
# This code could be generated by a little webinterface or just be hardcoded for now | |
# singleton/static class | |
class Ab1GuestHeader extends MovieExplorer.AbTest | |
@name = "AB1: Guest Header" | |
@condition = MovieExplorer.user? | |
@variations = [ | |
"Control: Text" | |
"V1: Facepile" | |
"V2: Headline" | |
"V3: Headline + Learn more" | |
] | |
@goals = | |
'service_provider_click': {'.login-provider a', 'click'}, | |
'learn_more': {'.learn-more-button', 'click'} | |
@running = true | |
# This would be on mp.com in the frontend code | |
class MovieExplorer.AbTest | |
initialize: -> | |
# set used group | |
@group = switch @variations.length | |
when 2 then MovieExplorer.sessionController.groupHalf # A/B test | |
when 3 then MovieExplorer.sessionController.groupThird # A/B/C test | |
when 4 then MovieExplorer.sessionController.groupQuarter # A/B/C/D test | |
else false # throw error | |
@current_variation == null | |
generate_template: -> | |
# returns template code for eazy coding | |
# {{abtest "AB1: Guest Header" "Control: Text"}} | |
# ... display code for control | |
# {{abtest "AB1: Guest Header" "V1: Facepile"}} | |
# ... display code for variation 1 | |
# {{abtest "AB1: Guest Header" "V2: Headline"}} | |
# ... display code for variation 2 | |
# {{abtest "AB1: Guest Header" "V3: Headline + Learn more"}} | |
# ... display code for variation 3 | |
# {{else}} | |
# ... display something if ab test is not running | |
# {{end}} | |
helper_abtest: (variation) -> | |
return false until @running | |
until @current_variation? | |
@current_variation = @variations[@group] | |
@mxTrack 'abtest:show', name: @name, group: @current_variation | |
return @current_variation == variation | |
helper_else: () -> | |
return true until @running | |
helper_end: () -> | |
# bind goal events | |
$(event[0]).bind(event[1], track(goal)) for goal, event in @goals | |
track: (goal) -> | |
return () -> | |
@mxTrack 'abtest:goal', name: @name, group: @current_variation, goal: goal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep this, we'll keep working on the idea.