Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass _ga client id to external signon services
Browse files Browse the repository at this point in the history
On pages such as https://www.gov.uk/log-in-file-self-assessment-tax-return/sign-in/prove-identity
we redirect users to services such as tax.service.gov.uk
to complete their sign in.

This will pass the _ga cookie as a _ga param as part of
cross-domain tracking, so that we can measure user journeys
across domains.

This will only pass the _ga param to other .gov.uk services.
Currently these are:
tax.service.gov.uk
www.signin.service.gov.uk
www.ruralpayments.service.gov.uk

Further work is required on the signin.service.gov.uk to
make use of the _ga param and ensure it is included in
redirects.

Trello: https://trello.com/c/ORdXWurC/101
William Franklin committed Sep 12, 2019
1 parent 38dc142 commit 2ed6c11
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/controllers/content_items_controller.rb
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ def service_sign_in_options
return
end

redirect_to selected[:url]
redirect_to service_url(selected[:url])
end
end

@@ -126,6 +126,16 @@ def set_expiry
public: @content_item.cache_control_public?)
end

def service_url(original_url)
return original_url if cookies[:_ga].nil?

ga_param = cookies[:_ga].gsub('GA', '')
url = URI.parse(original_url)
new_query_ar = URI.decode_www_form(url.query || '') << ["_ga", ga_param]
url.query = URI.encode_www_form(new_query_ar)
url.to_s
end

def with_locale
I18n.with_locale(@content_item.locale || I18n.default_locale) { yield }
end
20 changes: 20 additions & 0 deletions test/controllers/service_sign_in_content_item_controller_test.rb
Original file line number Diff line number Diff line change
@@ -100,6 +100,26 @@ class ContentItemsControllerTest < ActionController::TestCase
assert_template :service_sign_in
end

test "includes _ga as a query param when redirecting if set as a cookie" do
content_item = govuk_content_schema_example("service_sign_in", "service_sign_in")
link = 'https://www.horse.service.gov.uk/account?horse=brown&grand-national-winner=yes'
content_item['details']['choose_sign_in']['options'][0]['url'] = link
content_store_has_item(content_item['base_path'], content_item)

cookies[:_ga] = "GA1.1111111.1111111.111111111"
path = "#{path_for(content_item)}/#{content_item['details']['choose_sign_in']['slug']}"

option = content_item['details']['choose_sign_in']['options'][0]
value = option['text'].parameterize

stub_request(:get, %r{#{path}}).to_return(status: 200, body: content_item.to_json, headers: {})

post :service_sign_in_options, params: { path: path, option: value }

assert_response :redirect
assert_redirected_to "https://www.horse.service.gov.uk/account?horse=brown&grand-national-winner=yes&_ga=1.1111111.1111111.111111111"
end

def path_for(content_item, locale = nil)
base_path = content_item['base_path'].sub(/^\//, '')
base_path.gsub!(/\.#{locale}$/, '') if locale

0 comments on commit 2ed6c11

Please sign in to comment.