问题
I've got a number of different views that need to share the same experiment (ie footer and header partial need to both show 'nav_a' or 'nav_b' option).
I had hoped that simply having the same named experiment would make this work but it seems to not (ie sometimes the header has 'a' and the footer has 'b', vice versa or the same a on both).
How could I best achieve this?
As a secondary question, part of my 'experiment' is knowing which view was more successful on getting users to click on a video link; in my app I'm saving such clicks as a 'visit' model; is there anyway the visit_controller could know which test - a or b - was being run so I could save it to my visit model? That way I could get a count of which visit model had 'experiment 1 option a' vs 'experiment 2 option b' etc.
I'd be happy with something as simple as a global variable to know which to save; unsure how to initiate the ab_test in split in that way though.
UPDATE:
This is the example code of the current pages:
/layout/header.html.erb with a line like:
<%= ab_test('test_test', 'This is Header Test A', 'This is Header Test B') %>
And /layout/footer.html erb has
<%= ab_test('test_test', 'This is Footer Test A', 'This is Footer Test B') %>
but they're not consistently drawing the same option. Also unsure how to best implement the 'helper_method' as described in the docs here: https://github.com/andrew/split#views
UPDATE #2
I just attempted changing the code in the layouts/header.html.erb and layouts/footer.html.erb to this:
<%= render partial: ab_test("test_test", "layouts/test_a", "layouts/test_b") %>
When I left both of these other layouts pulling in the SAME partial (ie _test_a.html.erb) they both were in sync and displayed what was expected.
However when I changed layouts/footer.html.erb to render this partial:
<%= render partial: ab_test("test_test", "layouts/test_footer_a", "layouts/test_footer_b") %>
They were NO LONGER IN SYNC and would randomly show a different partial -- ie first A+footer B, then header b and footer b, header a + footer b, etc -- all in the same session.
回答1:
I think I figured out how best to deal with this myself.
In ApplicationController create a helper method ie (made this simple to test it out):
helper_method :home_display_test
def home_display_test
@home_display = ab_test("home_display_test", 'original', 'new')
return @home_display
end
Then in my views I could load in different partials such as:
or
I think this is working pretty solidly; I could even request which test version it is in another controller to save the data in the click...
回答2:
One AB test should have one set of alternatives which are defined in a configuration file or in the first call to ab_test()
try doing like this:
<head>
<%- if ab_test('layout_test', 'original', 'new') == 'origional' %>
<title>Old Title</title>
<%- else %>
<title>New Title</title>
<%- end %>
</head>
<body>
<%- if ab_test('layout_test', 'original', 'new') == 'origional' %>
<%= render partial: 'layout/original'%>
<%- else %>
<%= render partial: 'layout/new'%>
<%- end %>
</body>
should work like a charm!
来源:https://stackoverflow.com/questions/24251236/rails-a-b-testing-with-split-multiple-views-sharing-same-experiment-helper-met