Skip to content

Instantly share code, notes, and snippets.

@adri
Created May 9, 2012 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adri/2644900 to your computer and use it in GitHub Desktop.
Save adri/2644900 to your computer and use it in GitHub Desktop.
abtest example
# 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
@Rendez
Copy link

Rendez commented May 9, 2012

Nice example. Just remember we can't start adding stuff to the mp.com rails app (server). It is used for two simple things, URL matching and fetching the initial resource, and for JS and CSS resource delivering. Nothing else.

@Rendez
Copy link

Rendez commented May 9, 2012

Keep this, we'll keep working on the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment