Added matomo opt out iframe to cookies policy page

This commit is contained in:
luisramos0
2018-09-02 14:59:58 +01:00
parent 3f5c799166
commit 409f084bd4
6 changed files with 119 additions and 19 deletions

View File

@@ -16,6 +16,11 @@
}
}
iframe {
border: 0;
width: 100%;
}
&.fade {
-ms-transform: translate(0, 0) !important;
-webkit-transform: translate(0, 0) !important;

View File

@@ -5,4 +5,17 @@ module CookiesPolicyHelper
cookie_desc: cookie_desc,
cookie_domain: cookie_domain }
end
def matomo_iframe_src
Spree::Config.matomo_url\
"/index.php?module=CoreAdminHome&action=optOut"\
"&language=#{locale_language}"\
"&backgroundColor=&fontColor=222222&fontSize=16px&fontFamily=%22Roboto%22%2C%20Arial%2C%20sans-serif"
end
# removes country from locale if needed
# for example, both locales en and en_GB return language en
def locale_language
I18n.locale[0..1]
end
end

View File

@@ -69,6 +69,12 @@
= render_cookie_entry( "_pk_hsr, _pk_cvar, _pk_id and _pk_ses", t( "legal.cookies_policy.cookie_matomo_heatmap_desc" ) )
= render_cookie_entry( "piwik_ignore, _pk_cvar, _pk_id and _pk_ses", t( "legal.cookies_policy.cookie_matomo_ignore_desc" ) )
- if Spree::Config.cookies_policy_matomo_section && Spree::Config.matomo_url.present?
%p
= t 'legal.cookies_policy.statistics_cookies_matomo_optout'
%p
%iframe{ src: matomo_iframe_src }
%h2
= t 'legal.cookies_policy.disabling_cookies_header'
%p

View File

@@ -1299,6 +1299,7 @@ en:
statistics_cookies_desc: "The following are not strictly necessary, but help to provide you with the best user experience by allowing us to analyse user behaviour, identify which features you use most, or dont use, understand user experience issues, etc."
statistics_cookies_analytics_desc_html: "To collect and analyse platform usage data, we use Google Analytics, as it was the default service connected with Spree (the e-commerce open source software that we built on) but our vision is to switch to <a href='https://matomo.org/' target='_blank'>Matomo</a> (ex Piwik, open source analytics tool that is GDPR compliant and protects your privacy) as soon as we can."
statistics_cookies_matomo_desc_html: "To collect and analyse platform usage data, we use <a href='https://matomo.org/' target='_blank'>Matomo</a> (ex Piwik), an open source analytics tool that is GDPR compliant and protects your privacy."
statistics_cookies_matomo_optout: "Do you want to opt-out of Matomo analytics? We dont collect any personal data, and Matomo helps us to improve our service, but we respect your choice :-)"
cookie_analytics_utma_desc: "Used to distinguish users and sessions. The cookie is created when the javascript library executes and no existing __utma cookies exists. The cookie is updated every time data is sent to Google Analytics."
cookie_analytics_utmt_desc: "Used to throttle request rate."
cookie_analytics_utmb_desc: "Used to determine new sessions/visits. The cookie is created when the javascript library executes and no existing __utmb cookies exists. The cookie is updated every time data is sent to Google Analytics."

View File

@@ -10,7 +10,7 @@ feature "Cookies", js: true do
Spree::Config[:cookies_consent_banner_toggle] = original_banner_toggle
end
describe "in the homepage" do
context "in the homepage" do
before do
Spree::Config[:cookies_consent_banner_toggle] = true
visit_root_path_and_wait
@@ -46,7 +46,7 @@ feature "Cookies", js: true do
end
end
describe "in product listing page" do
context "in product listing page" do
before do
Spree::Config[:cookies_consent_banner_toggle] = true
end
@@ -57,7 +57,7 @@ feature "Cookies", js: true do
end
end
describe "disabled in the settings" do
context "disabled in the settings" do
scenario "it is not showing" do
Spree::Config[:cookies_consent_banner_toggle] = false
visit root_path
@@ -70,38 +70,59 @@ feature "Cookies", js: true do
# keeps config unchanged
around do |example|
original_config_value = Spree::Config[:cookies_policy_matomo_section]
original_matomo_config = Spree::Config[:cookies_policy_matomo_section]
original_matomo_url_config = Spree::Config[:matomo_url]
example.run
Spree::Config[:cookies_policy_matomo_section] = original_config_value
Spree::Config[:cookies_policy_matomo_section] = original_matomo_config
Spree::Config[:matomo_url] = original_matomo_url_config
end
scenario "showing session_id cookies description with correct instance domain" do
scenario "shows session_id cookies description with correct instance domain" do
visit '/#/policies/cookies'
expect(page).to have_content('_session_id')
.and have_content('127.0.0.1')
end
describe "with Matomo section configured" do
scenario "shows Matomo cookies details" do
context "without Matomo section configured" do
scenario "does not show Matomo cookies details and does not show Matomo optout text" do
Spree::Config[:cookies_policy_matomo_section] = false
visit_cookies_policy_page
expect(page).to have_no_content matomo_description_text
expect(page).to have_no_content matomo_opt_out_iframe
end
end
context "with Matomo section configured" do
before do
Spree::Config[:cookies_policy_matomo_section] = true
visit '/#/policies/cookies'
end
scenario "shows Matomo cookies details" do
visit_cookies_policy_page
expect(page).to have_content matomo_description_text
end
end
describe "without Matomo section configured" do
scenario "does not show Matomo cookies details" do
Spree::Config[:cookies_policy_matomo_section] = false
visit '/#/policies/cookies'
expect(page).to have_no_content matomo_description_text
context "with Matomo integration enabled" do
scenario "shows Matomo optout iframe" do
Spree::Config[:matomo_url] = "https://0000.innocraft.cloud/"
visit_cookies_policy_page
expect(page).to have_content matomo_opt_out_iframe
expect(page).to have_selector("iframe")
end
end
context "with Matomo integration disabled" do
scenario "does not show Matomo iframe" do
Spree::Config[:cookies_policy_matomo_section] = true
Spree::Config[:matomo_url] = ""
visit_cookies_policy_page
expect(page).to have_no_content matomo_opt_out_iframe
expect(page).to have_no_selector("iframe")
end
end
end
end
def matomo_description_text
I18n.t('legal.cookies_policy.cookie_matomo_basics_desc')
end
def expect_visible_cookies_policy_page
expect(page).to have_content I18n.t('legal.cookies_policy.header')
end
@@ -142,4 +163,16 @@ feature "Cookies", js: true do
find("a.close-reveal-modal").click
sleep 2
end
def visit_cookies_policy_page
visit '/#/policies/cookies'
end
def matomo_description_text
I18n.t('legal.cookies_policy.cookie_matomo_basics_desc')
end
def matomo_opt_out_iframe
I18n.t('legal.cookies_policy.statistics_cookies_matomo_optout')
end
end

View File

@@ -0,0 +1,42 @@
require 'spec_helper'
describe CookiesPolicyHelper, type: :helper do
# keeps global state unchanged
around do |example|
original_locale = I18n.locale
original_matomo_url = Spree::Config.matomo_url
example.run
Spree::Config.matomo_url = original_matomo_url
I18n.locale = original_locale
end
describe "matomo optout iframe src" do
scenario "includes matomo URL" do
Spree::Config.matomo_url = "http://matomo.org/"
expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url
end
scenario "is not nil, when matomo url is nil" do
Spree::Config.matomo_url = nil
expect(helper.matomo_iframe_src).to_not eq nil
end
end
describe "language from locale" do
scenario "when locale is the language" do
I18n.locale = "en"
expect(helper.locale_language).to eq "en"
end
scenario "is empty when locale is empty" do
I18n.locale = ""
expect(helper.locale_language).to be_empty
end
scenario "is only the language, when locale includes country" do
I18n.locale = "en_GB"
expect(helper.locale_language).to eq "en"
end
end
end