Skip to content

Commit 6816e23

Browse files
authored
Merge pull request #626 from citizensadvice/CP-864-integrate-cookies-engine
Chore: Integrate cookie preferences engine [CP-864]
2 parents ca183a6 + 1a9f484 commit 6816e23

15 files changed

Lines changed: 213 additions & 15 deletions

.github/resources/preview-overrides.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ envVars:
2222
RAILS_ENV: production
2323
USE_TEST_SUPPLIERS: ${{ vars.USE_TEST_SUPPLIERS }}
2424
FF_SMALL_SUPPLIER_STARS: ${{ vars.FF_SMALL_SUPPLIER_STARS }}
25+
FF_NEW_COOKIE_MANAGEMENT: ${{ vars.FF_NEW_COOKIE_MANAGEMENT }}

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ gem "citizens_advice_components",
4141
tag: "v8.1.0",
4242
glob: "engine/*.gemspec"
4343

44+
gem "citizens_advice_cookie_preferences",
45+
github: "citizensadvice/cookie-preferences"
46+
4447
# The citizens_advice_components gem uses view component but we also use this to write
4548
# our app components so explicitly name it as an application dependency.
4649
gem "view_component", "~> 4.0"

Gemfile.lock

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ GIT
1919
rubocop-rspec (~> 3.5)
2020
rubocop-rspec_rails (~> 2.31)
2121

22+
GIT
23+
remote: https://github.com/citizensadvice/cookie-preferences.git
24+
revision: 287a515c578be03c6951fe3545e0ad2858224b2d
25+
specs:
26+
citizens_advice_cookie_preferences (0.1.0)
27+
citizens_advice_components (> 8.0.0)
28+
meta-tags
29+
rails (>= 7.1.0)
30+
view_component (>= 2.0.0, < 5.0)
31+
2232
GIT
2333
remote: https://github.com/citizensadvice/design-system.git
2434
revision: c3cb623bf7eeac13c5573d7594032bc10f611021
@@ -136,7 +146,7 @@ GEM
136146
climate_control (1.2.0)
137147
coderay (1.1.3)
138148
concurrent-ruby (1.3.5)
139-
connection_pool (2.5.3)
149+
connection_pool (2.5.4)
140150
crack (1.0.0)
141151
bigdecimal
142152
rexml
@@ -293,7 +303,7 @@ GEM
293303
uri
294304
net-http-persistent (4.0.6)
295305
connection_pool (~> 2.2, >= 2.2.4)
296-
net-imap (0.5.9)
306+
net-imap (0.5.10)
297307
date
298308
net-protocol
299309
net-pop (0.1.2)
@@ -534,6 +544,7 @@ DEPENDENCIES
534544
capybara_accessible_selectors!
535545
citizens-advice-style!
536546
citizens_advice_components!
547+
citizens_advice_cookie_preferences!
537548
climate_control
538549
cssbundling-rails
539550
cucumber-rails

app/assets/stylesheets/appliance-calculator.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
@import "appliance-calculator/components/usages_table";
77
@import "appliance-calculator/components/most-expensive-appliance";
88
@import "appliance-calculator/components/last_added_appliance";
9+
@import 'citizens_advice_cookie_preferences/components/cookie-banner';
10+
@import 'citizens_advice_cookie_preferences/components/cookie-preferences';

app/assets/stylesheets/energy-csr-table.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
@import "./reset";
33
@import "./fonts";
44
@import "./components";
5+
@import 'citizens_advice_cookie_preferences/components/cookie-banner';
6+
@import 'citizens_advice_cookie_preferences/components/cookie-preferences';

app/controllers/application_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class ApplicationController < ActionController::Base
44
include SwiftypeMeta
55
include DataLayer
6+
include CitizensAdviceCookiePreferences::Helpers
67

78
def internal_server_error
89
render template: "errors/500", status: :internal_server_error

app/controllers/concerns/data_layer.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ def custom_data_layer_properties
1919
end
2020

2121
def default_data_layer_properties
22-
{
22+
properties = {
2323
platform: "content-platform",
2424
siteType: "Public Website",
2525
# language confusingly represents the current country: England, Wales etc.
2626
# but needs to have this name to match up with Episerver page data.
2727
language: (helpers.current_country || "england").to_s.capitalize
2828
}
29+
30+
if Feature.enabled?("FF_NEW_COOKIE_MANAGEMENT") && allow_analytics_cookies?
31+
properties.merge({ analyticsCookiesAccepted: "True" })
32+
else
33+
properties
34+
end
2935
end
3036
end

app/lib/feature.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
# Tiny class for checking if a feature is enabled
66
class Feature
77
def self.enabled?(flag_name)
8-
# Use ActiveModel's boolean type which recognises the strings 'false'/'0'/'' as false values
8+
# Setting "false" in the cdk returns "False", which isn't classed a falsey value by ActiveModel::Type::Boolean,
9+
# so we need to explicitly return false in these cases
10+
return false if ENV.fetch(flag_name, nil) == "False"
11+
12+
# Use ActiveModel's boolean type which recognises the strings 'false'/'0' etc as false values
913
ActiveModel::Type::Boolean.new.cast(ENV.fetch(flag_name, nil))
1014
end
1115
end

app/views/layouts/application.html.haml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
%body{ class: ("cas" if scotland?) }
2424
= render "shared/google_tag_manager_no_script"
2525
= render "shared/half_star_svg"
26+
- if Feature.enabled?("FF_NEW_COOKIE_MANAGEMENT") && !cookies_preference_page?
27+
= render CitizensAdviceCookiePreferences::CookieBanner.new
2628
2729
.wrapper
2830
= render HeaderComponent.new
@@ -48,3 +50,6 @@
4850
columns: public_website_footer_nav_links)
4951
5052
= javascript_include_tag digested_js_file_name("application.js"), defer: true
53+
54+
- if Feature.enabled?("FF_NEW_COOKIE_MANAGEMENT")
55+
= javascript_include_tag "citizens_advice_cookie_preferences/application", nonce: true
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-# haml-lint:disable InlineStyles
2-
%noscript
3-
%iframe{ src: "https://www.googletagmanager.com/ns.html?id=GTM-T5MB575",
4-
height: "0", width: "0", style: "display:none;visibility:hidden" }
2+
- if !Feature.enabled?("FF_NEW_COOKIE_MANAGEMENT") || allow_analytics_cookies?
3+
%noscript
4+
%iframe{ src: "https://www.googletagmanager.com/ns.html?id=GTM-T5MB575",
5+
height: "0", width: "0", style: "display:none;visibility:hidden" }

0 commit comments

Comments
 (0)