diff --git a/app/assets/javascripts/analytics.js b/app/assets/javascripts/analytics.js new file mode 100644 index 00000000..6ac74ae4 --- /dev/null +++ b/app/assets/javascripts/analytics.js @@ -0,0 +1,23 @@ +//= require govuk_publishing_components/analytics + +var linkedDomains = ['www.gov.uk'] + +$(document).ready(function() { + if (typeof window.GOVUK.analyticsInit !== 'undefined') { + window.GOVUK.analyticsInit(linkedDomains) + + $('.js-cookie-consent .govuk-radios__input').on('click', function() { + var response = $(this).val() + + if (response === 'yes') { + window.GOVUK.approveAllCookieTypes() + window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 }) + window.GOVUK.analyticsInit(linkedDomains) + } + + else { + window.GOVUK.deleteCookie('cookies_policy') + } + }) + } +}) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 0beb937d..c11bcb31 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -4,3 +4,5 @@ //= require govuk_publishing_components/components/checkboxes //= require govuk_publishing_components/components/error-summary //= require govuk_publishing_components/components/radio + +//= require ./analytics diff --git a/app/views/devise/registrations/your_information.html.erb b/app/views/devise/registrations/your_information.html.erb index 1a04643e..3c18f0a1 100644 --- a/app/views/devise/registrations/your_information.html.erb +++ b/app/views/devise/registrations/your_information.html.erb @@ -19,24 +19,26 @@ <%= form_with(url: new_user_registration_your_information_path(registration_state_id: @registration_state_id), method: :post) do %> - <%= render "govuk_publishing_components/components/radio", { - name: "cookie_consent", - heading: t("devise.registrations.your_information.fields.cookie_consent.heading"), - heading_size: "s", - error_message: devise_error_items(:cookie_consent, @resource_error_messages), - items: [ - { - value: "yes", - text: t("devise.registrations.your_information.fields.cookie_consent.yes"), - checked: @consents.fetch(:cookie_consent_decision, nil) == "yes" - }, - { - value: "no", - text: t("devise.registrations.your_information.fields.cookie_consent.no"), - checked: @consents.fetch(:cookie_consent_decision, nil) == "no" - } - ] - } %> + <%= render "govuk_publishing_components/components/radio", { name: "feedback_consent", diff --git a/spec/feature/registration_from_another_application_spec.rb b/spec/feature/registration_from_another_application_spec.rb index 443e79c8..d4c327cb 100644 --- a/spec/feature/registration_from_another_application_spec.rb +++ b/spec/feature/registration_from_another_application_spec.rb @@ -166,8 +166,8 @@ def start_journey end def i_consent_my_information_being_used - within(".govuk-form-group:first-of-type") { choose "Yes" } - within(".govuk-form-group:last-of-type") { choose "Yes" } + find(:css, "input[name='cookie_consent'][value='yes']").set(true) + find(:css, "input[name='feedback_consent'][value='yes']").set(true) click_on I18n.t("devise.registrations.your_information.fields.submit.label") end diff --git a/spec/feature/registration_spec.rb b/spec/feature/registration_spec.rb index 369747b3..8f4d4590 100644 --- a/spec/feature/registration_spec.rb +++ b/spec/feature/registration_spec.rb @@ -244,8 +244,8 @@ def enter_incorrect_mfa end def provide_consent - within(".govuk-form-group:first-of-type") { choose "Yes" } - within(".govuk-form-group:last-of-type") { choose "No" } + find(:css, "input[name='cookie_consent'][value='yes']").set(true) + find(:css, "input[name='feedback_consent'][value='no']").set(true) click_on I18n.t("devise.registrations.your_information.fields.submit.label") end end