Skip to content

Commit

Permalink
Merge pull request #612 from nationalarchives/feature/feedback-link-q…
Browse files Browse the repository at this point in the history
…uery-params

Add more tracking parameters to feedback survey link
  • Loading branch information
jacksonj04 authored Mar 28, 2023
2 parents e754392 + 52fc5ee commit 413d49e
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 14 deletions.
40 changes: 40 additions & 0 deletions config/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import urlencode

from django.utils.cache import patch_cache_control


Expand All @@ -19,3 +21,41 @@ def __call__(self, request):
# the view is called.

return response


class FeedbackLinkMiddleware:

BASE_FEEDBACK_URL: str = (
"https://corexmsnp4n42lf2kht3.qualtrics.com/jfe/form/SV_0lyyYAzfv9bGcyW"
)

def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
# We don't manipulate the response here
return self.get_response(request)

def process_template_response(self, request, response):
params = {
"full_url": request.build_absolute_uri(),
}

if "query" in response.context_data["context"]:
params["search_term"] = response.context_data["context"]["query"]

if "feedback_survey_type" in response.context_data:
params["type"] = response.context_data["feedback_survey_type"]

if "feedback_survey_judgment_uri" in response.context_data:
params["judgment_uri"] = response.context_data[
"feedback_survey_judgment_uri"
]

if "feedback_survey_court" in response.context_data:
params["court"] = response.context_data["feedback_survey_court"]

response.context_data["feedback_survey_link"] = (
self.BASE_FEEDBACK_URL + "?" + urlencode(params)
)
return response
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"django.middleware.common.BrokenLinkEmailsMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"rollbar.contrib.django.middleware.RollbarNotifierMiddleware",
"config.middleware.FeedbackLinkMiddleware",
]

# STATIC
Expand Down
32 changes: 32 additions & 0 deletions config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,41 @@ class TransactionalLicenceFormView(TemplateViewWithContext):
template_name = "pages/transactional_licence.html"
page_title = "transactionallicenceform.title"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "license"
return context


class AccessibilityStatement(TemplateViewWithContext):
template_name = "pages/accessibility_statement.html"
page_title = "accessibilitystatement.title"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "support"
return context


class OpenJusticeLicenceView(TemplateViewWithContext):
template_name = "pages/open_justice_licence.html"
page_title = "openjusticelicence.title"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "license"
return context


class TermsOfUseView(TemplateViewWithContext):
template_name = "pages/terms_of_use.html"
page_title = "terms.title"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "support"
return context


class StructuredSearchView(TemplateViewWithContext):
template_name = "pages/structured_search.html"
Expand All @@ -41,12 +61,18 @@ class StructuredSearchView(TemplateViewWithContext):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["context"]["courts"] = courts.get_selectable()
context["feedback_survey_type"] = "structured_search"
return context


class NoResultsView(TemplateViewWithContext):
template_name = "pages/no_results.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "search"
return context


class CheckView(TemplateViewWithContext):
template_name = "pages/check.html"
Expand All @@ -58,8 +84,14 @@ class WhatToExpectView(TemplateViewWithContext):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["context"]["courts"] = courts.get_listable_groups()
context["feedback_survey_type"] = "support"
return context


class HowToUseThisService(TemplateViewWithContext):
template_name = "pages/how_to_use_this_service.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["feedback_survey_type"] = "support"
return context
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ <h2>{% translate "service.improved" %}</h2>
draggable="false"
rel="noreferrer noopener"
class="sub-footer__cta-button"
href="{% translate "survey.link" %}">{% translate "survey.link.text" %}</a>
href="{{ feedback_survey_link }}">{% translate "survey.link.text" %}</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This is a new service – your
<a target="_blank"
rel="noreferrer noopener"
href="{% translate "survey.link" %}">feedback</a>
href="{{ feedback_survey_link }}">feedback</a>
will help us to improve it.
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h3>Alpha service</h3>
years.
</p>
<p>
<a href="{% translate "survey.link" %}">Your feedback will help us develop the service</a>
<a href="{{ feedback_survey_link }}">Your feedback will help us develop the service</a>
</p>
<h3>Our legal basis for archiving and publishing case law</h3>
<p>
Expand Down
9 changes: 8 additions & 1 deletion judgments/views/advanced_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,11 @@ def advanced_search(request):
except MarklogicResourceNotFoundError:
raise Http404("Search failed") # TODO: This should be something else!
template = loader.get_template("judgment/results.html")
return TemplateResponse(request, template, context={"context": context})
return TemplateResponse(
request,
template,
context={
"context": context,
"feedback_survey_type": "structured_search",
},
)
10 changes: 9 additions & 1 deletion judgments/views/browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ def browse(request, court=None, subdivision=None, year=None):
except MarklogicResourceNotFoundError:
raise Http404("Search failed") # TODO: This should be something else!
template = loader.get_template("judgment/results.html")
return TemplateResponse(request, template, context={"context": context})
return TemplateResponse(
request,
template,
context={
"context": context,
"feedback_survey_type": "browse",
"feedback_survey_court": court_query,
},
)
10 changes: 9 additions & 1 deletion judgments/views/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ def detail(request, judgment_uri):
raise Http404("Judgment was not found")

template = loader.get_template("judgment/detail.html")
return TemplateResponse(request, template, context={"context": context})
return TemplateResponse(
request,
template,
context={
"context": context,
"feedback_survey_type": "judgment",
"feedback_survey_judgment_uri": judgment_uri,
},
)


def detail_xml(_request, judgment_uri):
Expand Down
1 change: 1 addition & 0 deletions judgments/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def index(request):
"context": context,
"courts": all_courts.get_listable_courts(),
"tribunals": all_courts.get_listable_tribunals(),
"feedback_survey_type": "home",
},
)
9 changes: 8 additions & 1 deletion judgments/views/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ def results(request):
except MarklogicAPIError:
raise Http404("Search error") # TODO: This should be something else!
template = loader.get_template("judgment/results.html")
return TemplateResponse(request, template, context={"context": context})
return TemplateResponse(
request,
template,
context={
"context": context,
"feedback_survey_type": "search",
},
)
8 changes: 1 addition & 7 deletions locale/en_GB/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-23 15:23+0000\n"
"POT-Creation-Date: 2023-03-27 19:55+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -123,12 +123,6 @@ msgstr "Privacy"
msgid "service.improved"
msgstr "How can this service be improved?"

#: ds_judgements_public_ui/templates/includes/how_can_this_service_be_improved.html
#: ds_judgements_public_ui/templates/includes/phase_banner.html
#: ds_judgements_public_ui/templates/pages/what_to_expect.html
msgid "survey.link"
msgstr "https://corexmsnp4n42lf2kht3.qualtrics.com/jfe/form/SV_0lyyYAzfv9bGcyW"

#: ds_judgements_public_ui/templates/includes/how_can_this_service_be_improved.html
msgid "survey.link.text"
msgstr "Fill out our short survey"
Expand Down

0 comments on commit 413d49e

Please sign in to comment.