diff --git a/app/controllers/cookies_controller.rb b/app/controllers/cookies_controller.rb new file mode 100644 index 000000000..4809d099e --- /dev/null +++ b/app/controllers/cookies_controller.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class CookiesController < ApplicationController + before_action :set_cookie_form, only: :show + + def show; end + + def update + analytics_consent = params[:cookies_form][:analytics_consent] + if %w[on off].include?(analytics_consent) + cookies[:accept_analytics_cookies] = { value: analytics_consent, expires: 1.year.from_now } + end + + respond_to do |format| + format.html do + set_cookie_form + flash[:notice] = "You’ve set your cookie preferences." + + redirect_to cookies_path + end + end + end + +private + + def set_cookie_form + @cookies_form = CookiesForm.new(accept_analytics_cookies: cookies[:accept_analytics_cookies]) + end +end diff --git a/app/models/cookies_form.rb b/app/models/cookies_form.rb new file mode 100644 index 000000000..02618e4b5 --- /dev/null +++ b/app/models/cookies_form.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +class CookiesForm + include ActiveModel::Model + + attr_accessor :accept_analytics_cookies + + def consent_options + [ + OpenStruct.new(id: "on", name: "Yes"), + OpenStruct.new(id: "off", name: "No"), + ] + end +end diff --git a/app/views/cookies/show.html.erb b/app/views/cookies/show.html.erb new file mode 100644 index 000000000..8b954f884 --- /dev/null +++ b/app/views/cookies/show.html.erb @@ -0,0 +1,81 @@ +<% content_for :title, "Cookies" %> + +
+
+

Cookies

+

Cookies are small files saved on your phone, tablet or computer when you visit a website.

+

We use cookies to make the Manage training for early career teachers service (the service) work and collect information about how you use our service.

+ +

Essential cookies

+

Essential cookies keep your information secure while you use the service. We do not need to ask permission to use them.

+ + + + + + + + + + + + + + + + + + + + + + +
Essential cookies
NamePurposeExpires
_data_collector_sessionUsed to keep you signed in2 weeks
accept_analytics_cookiesSaves your cookie consent settings1 year
+ +

Analytics cookies (optional)

+

With your permission, we use Google Analytics to collect data about how you use the service. This information helps us to improve our service.

+

Google is not allowed to use or share our analytics data with anyone.

+

Google Analytics stores anonymised information about:

+ + + + + + + + + + + + + + + + + + + + + + + + +
Google Analytics cookies
NamePurposeExpires
_gaChecks if you’ve visited the service before. This helps us count how many people visit our site.2 years
_gidChecks if you’ve visited the service before. This helps us count how many people visit our site.24 hours
+ + <%= form_for @cookies_form, url: cookies_path, method: :put do |f| %> + <%= f.govuk_collection_radio_buttons( + :accept_analytics_cookies, + @cookies_form.consent_options, + :id, + :name, + inline: true, + legend: { text: "Do you want to accept analytics cookies?" }, + ) %> + <%= f.govuk_submit "Save cookie settings" %> + <% end %> +
+
diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index 7694b5ca8..660b0d221 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -40,6 +40,9 @@ +