Skip to content

Commit 969e450

Browse files
Second experiment
This tries implementing a second (concurrent) experiment, which would rely on knowing how often a user clicks an outbound link. That means we need an interstitial redirect in order to conclude the experiment, which happens in the new outbound path. PLEASE NOTE: This isn't working yet, because the redirect is getting caught by Turbo, it seems, and violating CORS policies. As a result, we're just logging the outbound URLs to the console.
1 parent 0001dc3 commit 969e450

7 files changed

Lines changed: 36 additions & 0 deletions

File tree

app/controllers/record_controller.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ class RecordController < ApplicationController
33

44
include RecordHelper
55

6+
# The out method is used for concluding A/B testing experiments that rely on the user following outbound links.
7+
#
8+
# @param url String a URL where the URL will be redirected
9+
def out
10+
if params[:url].present?
11+
ab_finished(:result_format)
12+
13+
redirect_to params[:url], allow_other_host: true
14+
else
15+
redirect_to '/'
16+
end
17+
end
18+
619
def view
720
id = params[:id]
821
index = ENV.fetch('TIMDEX_INDEX', nil)

app/controllers/search_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def results
1515
# if we are loading results, the user submitted the form - so this experiment is finished
1616
ab_finished(:ui_colors)
1717

18+
# Start experimental result format
19+
@fulfillment = ab_test(:result_format, 'link', 'button')
20+
1821
# inject session preference for boolean type if it is present
1922
params[:booleanType] = cookies[:boolean_type] || 'AND'
2023

app/helpers/search_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def format_highlight_label(field_name)
1818

1919
def link_to_result(result)
2020
if result[:source_link].present?
21+
Rails.logger.debug(outbound_path(url: result[:source_link]))
2122
link_to(result[:title], result[:source_link])
2223
else
2324
result[:title]

app/views/record/out.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>This would redirect you.</p>

app/views/search/_result_primo.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<h3 class="record-title">
77
<span class="sr">Title: </span>
88
<% if result[:links]&.find { |link| link['kind'] == 'full record' } %>
9+
<% Rails.logger.debug(outbound_path(url: result[:links].find { |link| link['kind'] == 'full record' }['url'])) %>
910
<%= link_to(result[:title], result[:links].find { |link| link['kind'] == 'full record' }['url']) %>
1011
<% else %>
1112
<%= result[:title] %>

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
get 'lookup', to: 'libkey#lookup'
77

8+
get 'out', to: 'record#out', as: "outbound"
9+
810
get 'record/(:id)',
911
to: 'record#view',
1012
as: 'record',

test/controllers/record_controller_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,19 @@ class RecordControllerTest < ActionDispatch::IntegrationTest
3636
assert_select 'main', /(.*)#{message}(.*)/
3737
end
3838
end
39+
40+
test 'outbound route redirects to home without a URL parameter' do
41+
get '/out'
42+
43+
assert_response :redirect
44+
assert_redirected_to root_url
45+
end
46+
47+
test 'outbound route redirects to a URL if provided' do
48+
target = 'https://example.org'
49+
get "/out?url=#{target}"
50+
51+
assert_response :redirect
52+
assert_redirected_to target
53+
end
3954
end

0 commit comments

Comments
 (0)