Skip to content

Commit

Permalink
capture submission query string
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwoldatwork authored Jan 13, 2025
2 parents dd7457c + 73e688e commit ffa8635
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def set_form

def submission_params
permitted_fields = @form.questions.collect(&:answer_field)
permitted_fields << %i[language location_code referer hostname page fba_directive]
permitted_fields << %i[language location_code referer hostname page query_string fba_directive]
params.require(:submission).permit(permitted_fields)
end

Expand Down
1 change: 1 addition & 0 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ def hashed_fields_for_export
archived: 'Archived',
flagged: 'Flagged',
page: 'Page',
query_string: 'Query string',
hostname: 'Hostname',
referer: 'Referrer',
created_at: 'Created At',
Expand Down
1 change: 1 addition & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def validate_custom_form
answered_questions.delete('user_agent')
answered_questions.delete('hostname')
answered_questions.delete('page')
answered_questions.delete('query_string')
answered_questions.delete('ip_address')
answered_questions.delete('language')
answered_questions.delete('referer')
Expand Down
1 change: 1 addition & 0 deletions app/serializers/submission_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SubmissionSerializer < ActiveModel::Serializer
:referer,
:hostname,
:page,
:query_string,
:user_agent,
:answer_01,
:answer_02,
Expand Down
8 changes: 8 additions & 0 deletions app/views/admin/submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
<%= sanitize(@submission.page) %>
</td>
</tr>
<tr>
<td>
Query string
</td>
<td>
<%= sanitize(@submission.query_string) %>
</td>
</tr>
<tr>
<td>
Referer
Expand Down
1 change: 1 addition & 0 deletions app/views/components/widget/_fba.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ function FBAform(d, N) {
params["referer"] = d.referrer;
params["hostname"] = N.location.hostname;
params["page"] = N.location.pathname;
params["query_string"] = N.location.search;
params["location_code"] = form.querySelector("#fba_location_code") ? form.querySelector("#fba_location_code").value : null;
params["fba_directive"] = form.querySelector("#fba_directive") ? form.querySelector("#fba_directive").value : null;
params["language"] = "en";
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20250110215441_add_querystring_to_submissions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddQuerystringToSubmissions < ActiveRecord::Migration[7.2]
def change
add_column :submissions, :query_string, :text, default: nil, limit: 2048
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_12_19_001513) do
ActiveRecord::Schema[7.2].define(version: 2025_01_10_215441) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -650,6 +650,7 @@
t.string "hostname"
t.string "tags", default: [], array: true
t.integer "spam_score", default: 0
t.text "query_string"
t.index ["created_at"], name: "index_submissions_on_created_at"
t.index ["flagged"], name: "index_submissions_on_flagged"
t.index ["form_id"], name: "index_submissions_on_form_id"
Expand Down
4 changes: 3 additions & 1 deletion spec/features/touchpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,9 @@

# Asserting against the database/model directly here isn't ideal.
# An alternative is to send location_code back to the client and assert against it
expect(Submission.last.location_code).to eq 'TEST_LOCATION_CODE'
last_submission = Submission.last
expect(last_submission.location_code).to eq('TEST_LOCATION_CODE')
expect(last_submission.query_string).to eq("?location_code=TEST_LOCATION_CODE")
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/models/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
:archived,
:flagged,
:page,
:query_string,
:hostname,
:referer,
:created_at,
Expand Down

0 comments on commit ffa8635

Please sign in to comment.