Ruby on rails 如何在Rails中实现Google Analytics内容实验
谷歌分析内容实验需要使用原始URL和变体URL。在Rails中,这是否意味着我们需要创建新的路由和控制器操作?或者,我们可以根据URL参数使用相同的操作来呈现不同的视图吗?我相信您可以将多个路径路由到相同的操作,如:Ruby on rails 如何在Rails中实现Google Analytics内容实验,ruby-on-rails,google-analytics,content-experiments,Ruby On Rails,Google Analytics,Content Experiments,谷歌分析内容实验需要使用原始URL和变体URL。在Rails中,这是否意味着我们需要创建新的路由和控制器操作?或者,我们可以根据URL参数使用相同的操作来呈现不同的视图吗?我相信您可以将多个路径路由到相同的操作,如: match 'test_ctrl/test_action_1' => 'test_ctrl#test_action', as: :test_action_1 match 'test_ctrl/test_action_2' => 'test_ctrl#test_a
match 'test_ctrl/test_action_1' => 'test_ctrl#test_action', as: :test_action_1
match 'test_ctrl/test_action_2' => 'test_ctrl#test_action', as: :test_action_2
match 'test_ctrl/test_action_3' => 'test_ctrl#test_action', as: :test_action_3
然后,在TestCtrl控制器内,您可以检查请求数据,并根据请求url呈现特定视图,方法是:
def test_action
if request.path_info == 'test_ctrl/test_action_1'
render "/test_action/1"
elsif request.path_info == 'test_ctrl/test_action_2'
render "/test_action/2"
elsif request.path_info == 'test_ctrl/test_action_3'
render "/test_action/3"
end
end
只需在视图/测试动作中创建视图1、2和3/