From: Tom Hughes Date: Mon, 1 Aug 2022 19:40:25 +0000 (+0100) Subject: Rename piwik to matomo and merge configuration into settings X-Git-Tag: live~1099 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/e9f62a8c30832e0533dce0ccd691b6c89e98ae30 Rename piwik to matomo and merge configuration into settings --- diff --git a/.gitignore b/.gitignore index 73316769e..75e9eb59e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ .vagrant app/assets/javascripts/i18n config/environments/*.local.yml -config/piwik.yml config/settings.local.yml config/settings/*.local.yml coverage diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d5b16bbfb..aea9e01a4 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,7 +13,7 @@ //= require leaflet.locationfilter //= require i18n //= require oauth -//= require piwik +//= require matomo //= require richtext //= require qs/dist/qs //= require bs-custom-file-input diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index f0b96f59f..6d379ca8c 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -212,13 +212,13 @@ $(document).ready(function () { } }); - if (OSM.PIWIK) { + if (OSM.MATOMO) { map.on("layeradd", function (e) { if (e.layer.options) { - var goal = OSM.PIWIK.goals[e.layer.options.keyid]; + var goal = OSM.MATOMO.goals[e.layer.options.keyid]; if (goal) { - $("body").trigger("piwikgoal", goal); + $("body").trigger("matomogoal", goal); } } }); diff --git a/app/assets/javascripts/matomo.js b/app/assets/javascripts/matomo.js new file mode 100644 index 000000000..34af54ce7 --- /dev/null +++ b/app/assets/javascripts/matomo.js @@ -0,0 +1,32 @@ +if (OSM.MATOMO) { + $(document).ready(function () { + var base = document.location.protocol + "//" + OSM.MATOMO.location + "/"; + var matomoTracker; + + var matomoLoader = $.ajax({ + url: base + "matomo.js", + dataType: "script", + cache: true, + success: function () { + matomoTracker = Matomo.getTracker(base + "matomo.php", OSM.MATOMO.site); + + if (OSM.user) { + matomoTracker.setUserId(OSM.user.toString()); + } + + matomoTracker.trackPageView(); + matomoTracker.enableLinkTracking(); + + $("meta[name=matomo-goal]").each(function () { + matomoTracker.trackGoal($(this).attr("content")); + }); + } + }); + + $("body").on("matomogoal", function (e, goal) { + matomoLoader.done(function () { + matomoTracker.trackGoal(goal); + }); + }); + }); +} diff --git a/app/assets/javascripts/osm.js.erb b/app/assets/javascripts/osm.js.erb index 3e2e7c866..f82516632 100644 --- a/app/assets/javascripts/osm.js.erb +++ b/app/assets/javascripts/osm.js.erb @@ -3,8 +3,8 @@ //= require qs/dist/qs OSM = { -<% if defined?(PIWIK) %> - PIWIK: <%= PIWIK.to_json %>, +<% if defined?(Settings.matomo) %> + MATOMO: <%= Settings.matomo.to_json %>, <% end %> MAX_REQUEST_AREA: <%= Settings.max_request_area.to_json %>, diff --git a/app/assets/javascripts/piwik.js b/app/assets/javascripts/piwik.js deleted file mode 100644 index 5353a99ac..000000000 --- a/app/assets/javascripts/piwik.js +++ /dev/null @@ -1,32 +0,0 @@ -if (OSM.PIWIK) { - $(document).ready(function () { - var base = document.location.protocol + "//" + OSM.PIWIK.location + "/"; - var piwikTracker; - - var piwikLoader = $.ajax({ - url: base + "piwik.js", - dataType: "script", - cache: true, - success: function () { - piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK.site); - - if (OSM.user) { - piwikTracker.setUserId(OSM.user.toString()); - } - - piwikTracker.trackPageView(); - piwikTracker.enableLinkTracking(); - - $("meta[name=piwik-goal]").each(function () { - piwikTracker.trackGoal($(this).attr("content")); - }); - } - }); - - $("body").on("piwikgoal", function (e, goal) { - piwikLoader.done(function () { - piwikTracker.trackGoal(goal); - }); - }); - }); -} diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6215403c9..933cec53d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -83,7 +83,7 @@ class UsersController < ApplicationController end if current_user.save - flash[:piwik_goal] = PIWIK["goals"]["signup"] if defined?(PIWIK) + flash[:matomo_goal] = Settings.matomo["goals"]["signup"] if defined?(Settings.matomo) referer = welcome_path diff --git a/app/views/layouts/_meta.html.erb b/app/views/layouts/_meta.html.erb index 2052b1d64..3517673ac 100644 --- a/app/views/layouts/_meta.html.erb +++ b/app/views/layouts/_meta.html.erb @@ -20,6 +20,6 @@ <%= tag.link :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") %> <%= tag.meta :name => "description", :content => "OpenStreetMap is the free wiki world map." %> <%= opengraph_tags(@title) %> -<% if flash[:piwik_goal] -%> -<%= tag.meta :name => "piwik-goal", :content => flash[:piwik_goal] %> +<% if flash[:matomo_goal] -%> +<%= tag.meta :name => "matomo-goal", :content => flash[:matomo_goal] %> <% end -%> diff --git a/app/views/layouts/site.html.erb b/app/views/layouts/site.html.erb index ca59f5763..7c921658d 100644 --- a/app/views/layouts/site.html.erb +++ b/app/views/layouts/site.html.erb @@ -4,8 +4,8 @@ <%= render :partial => "layouts/header" %> <%= render :partial => "layouts/content" %> - <% if defined?(PIWIK) -%> - + <% if defined?(Settings.matomo) -%> + <% end -%> diff --git a/config/eslint.json b/config/eslint.json index 22ecdd3db..3b878d48a 100644 --- a/config/eslint.json +++ b/config/eslint.json @@ -11,7 +11,7 @@ "I18n": "readonly", "L": "readonly", "OSM": "writable", - "Piwik": "readonly", + "Matomo": "readonly", "Qs": "readonly", "updateLinks": "readonly" }, diff --git a/config/initializers/piwik.rb b/config/initializers/piwik.rb deleted file mode 100644 index 1b9fa73c1..000000000 --- a/config/initializers/piwik.rb +++ /dev/null @@ -1,5 +0,0 @@ -require "yaml" - -if File.exist?(piwik_file = File.expand_path("../piwik.yml", __dir__)) - PIWIK = YAML.load_file(piwik_file) -end diff --git a/config/initializers/secure_headers.rb b/config/initializers/secure_headers.rb index 97952f7cb..53ab76808 100644 --- a/config/initializers/secure_headers.rb +++ b/config/initializers/secure_headers.rb @@ -18,9 +18,9 @@ csp_policy = { :report_uri => [] } -csp_policy[:connect_src] << PIWIK["location"] if defined?(PIWIK) -csp_policy[:img_src] << PIWIK["location"] if defined?(PIWIK) -csp_policy[:script_src] << PIWIK["location"] if defined?(PIWIK) +csp_policy[:connect_src] << Settings.matomo["location"] if defined?(Settings.matomo) +csp_policy[:img_src] << Settings.matomo["location"] if defined?(Settings.matomo) +csp_policy[:script_src] << Settings.matomo["location"] if defined?(Settings.matomo) csp_policy[:img_src] << Settings.avatar_storage_url if Settings.key?(:avatar_storage_url) csp_policy[:img_src] << Settings.trace_image_storage_url if Settings.key?(:trace_image_storage_url) diff --git a/config/settings.yml b/config/settings.yml index 0e73d2b02..9ff8a653b 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -138,3 +138,5 @@ smtp_tls_verify_mode: "none" smtp_authentication: null smtp_user_name: null smtp_password: null +# Matomo settings for analytics +#matomo: