Commit 4bcd079d authored by Alishan Ladhani's avatar Alishan Ladhani

Add default setting for matomo_disable_cookies

parent d566a31e
<!-- Matomo --> <!-- Matomo -->
- matomo_disable_cookies = extra_config.has_key?('matomo_disable_cookies') && extra_config.matomo_disable_cookies
= javascript_tag do = javascript_tag do
:plain :plain
var _paq = window._paq = window._paq || []; var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']); _paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']); _paq.push(['enableLinkTracking']);
#{matomo_disable_cookies ? '_paq.push(["disableCookies"])' : ""}; #{extra_config.matomo_disable_cookies ? '_paq.push(["disableCookies"])' : ""};
(function() { (function() {
var u="//#{extra_config.matomo_url}/"; var u="//#{extra_config.matomo_url}/";
_paq.push(['setTrackerUrl', u+'matomo.php']); _paq.push(['setTrackerUrl', u+'matomo.php']);
......
...@@ -819,6 +819,7 @@ Settings.forti_token_cloud['enabled'] = false if Settings.forti_token_cloud['ena ...@@ -819,6 +819,7 @@ Settings.forti_token_cloud['enabled'] = false if Settings.forti_token_cloud['ena
Settings['extra'] ||= Settingslogic.new({}) Settings['extra'] ||= Settingslogic.new({})
Settings.extra['matomo_site_id'] ||= Settings.extra['piwik_site_id'] if Settings.extra['piwik_site_id'].present? Settings.extra['matomo_site_id'] ||= Settings.extra['piwik_site_id'] if Settings.extra['piwik_site_id'].present?
Settings.extra['matomo_url'] ||= Settings.extra['piwik_url'] if Settings.extra['piwik_url'].present? Settings.extra['matomo_url'] ||= Settings.extra['piwik_url'] if Settings.extra['piwik_url'].present?
Settings.extra['matomo_disable_cookies'] = false if Settings.extra['matomo_disable_cookies'].nil?
# #
# Rack::Attack settings # Rack::Attack settings
......
...@@ -92,7 +92,8 @@ RSpec.describe 'layouts/_head' do ...@@ -92,7 +92,8 @@ RSpec.describe 'layouts/_head' do
before do before do
stub_config(extra: { stub_config(extra: {
matomo_url: matomo_host, matomo_url: matomo_host,
matomo_site_id: 12345 matomo_site_id: 12345,
matomo_disable_cookies: false
}) })
end end
...@@ -101,10 +102,10 @@ RSpec.describe 'layouts/_head' do ...@@ -101,10 +102,10 @@ RSpec.describe 'layouts/_head' do
expect(rendered).to match(/<script.*>.*var u="\/\/#{matomo_host}\/".*<\/script>/m) expect(rendered).to match(/<script.*>.*var u="\/\/#{matomo_host}\/".*<\/script>/m)
expect(rendered).to match(%r(<noscript>.*<img src="//#{matomo_host}/matomo.php.*</noscript>)) expect(rendered).to match(%r(<noscript>.*<img src="//#{matomo_host}/matomo.php.*</noscript>))
expect(rendered).not_to include('_paq.push(["disableCookies"])')
end end
context 'matomo_disable_cookies' do context 'when matomo_disable_cookies is true' do
context 'when true' do
before do before do
stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: true }) stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: true })
end end
...@@ -115,31 +116,6 @@ RSpec.describe 'layouts/_head' do ...@@ -115,31 +116,6 @@ RSpec.describe 'layouts/_head' do
expect(rendered).to include('_paq.push(["disableCookies"])') expect(rendered).to include('_paq.push(["disableCookies"])')
end end
end end
context 'when false' do
before do
stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345, matomo_disable_cookies: false })
end
it 'does not disable cookies' do
render
expect(rendered).not_to include('_paq.push(["disableCookies"])')
end
end
context 'when absent' do
before do
stub_config(extra: { matomo_url: matomo_host, matomo_site_id: 12345 })
end
it 'does not disable cookies' do
render
expect(rendered).not_to include('_paq.push(["disableCookies"])')
end
end
end
end end
def stub_helper_with_safe_string(method) def stub_helper_with_safe_string(method)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment