diff --git a/app/models/spree/app_configuration_decorator.rb b/app/models/spree/app_configuration_decorator.rb
index 5b11a0ee61..a039ddbd45 100644
--- a/app/models/spree/app_configuration_decorator.rb
+++ b/app/models/spree/app_configuration_decorator.rb
@@ -26,6 +26,7 @@ Spree::AppConfiguration.class_eval do
preference :bugherd_api_key, :string, default: nil
preference :matomo_url, :string, default: nil
preference :matomo_site_id, :string, default: nil
+ preference :matomo_tag_manager_url, :string, default: nil
# Invoices & Receipts
preference :enable_invoices?, :boolean, default: true
diff --git a/app/views/admin/matomo_settings/edit.html.haml b/app/views/admin/matomo_settings/edit.html.haml
index 51f553bcff..6a6b447da4 100644
--- a/app/views/admin/matomo_settings/edit.html.haml
+++ b/app/views/admin/matomo_settings/edit.html.haml
@@ -17,7 +17,11 @@
.field
= label_tag(:matomo_site_id, t('.matomo_site_id')) + tag(:br)
= preference_field_tag("preferences[#{:matomo_site_id}]", Spree::Config[:matomo_site_id], type: Spree::Config.preference_type(:matomo_site_id))
-
+
+ %legend= t('.config_instructions_tag_manager_html')
+ .field
+ = label_tag(:matomo_tag_manager_url, t('.matomo_tag_manager_url')) + tag(:br)
+ = preference_field_tag("preferences[#{:matomo_tag_manager_url}]", Spree::Config[:matomo_tag_manager_url], type: Spree::Config.preference_type(:matomo_tag_manager_url))
.form-buttons{"data-hook" => "buttons"}
= button t(:update), 'icon-refresh'
diff --git a/app/views/layouts/_matomo_tag.html.haml b/app/views/layouts/_matomo_tag.html.haml
index aba1b19528..85a4cf47dc 100644
--- a/app/views/layouts/_matomo_tag.html.haml
+++ b/app/views/layouts/_matomo_tag.html.haml
@@ -1,6 +1,15 @@
+
+- if Spree::Config.matomo_tag_manager_url.present?
+ :javascript
+ var _mtm = _mtm || [];
+ _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
+ var u="#{Spree::Config.matomo_tag_manager_url}";
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u; s.parentNode.insertBefore(g,s);
+
- if Spree::Config.matomo_url.present?
:javascript
- var _paq = _paq || [];
+ var _paq = window._paq || [];
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
_paq.push(["setCookieDomain", "*.#{Spree::Config.site_url}"]);
_paq.push(["setDomains", ["*.#{Spree::Config.site_url}"]]);
@@ -8,8 +17,8 @@
_paq.push(['enableLinkTracking']);
(function() {
var u="#{Spree::Config.matomo_url}";
- _paq.push(['setTrackerUrl', u+'piwik.php']);
+ _paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '#{Spree::Config.matomo_site_id}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
- g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 63be6d0844..195253f8e1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -415,8 +415,10 @@ en:
title: "Matomo Settings"
matomo_url: "Matomo URL"
matomo_site_id: "Matomo Site ID"
- info_html: "Matomo is a Web and Mobile Analytics. You can either host Matomo on-premises or use a cloud-hosted service. See matomo.org for more information."
+ matomo_tag_manager_url: "Matomo Tag Manager URL"
+ info_html: "Matomo is a Web and Mobile Analytics application. You can either host Matomo on-premises or use a cloud-hosted service. See matomo.org for more information."
config_instructions_html: "Here you can configure the OFN Matomo integration. The Matomo URL below should point to the Matomo instance where the user tracking information will be sent to; if it is left empty, Matomo user tracking will be disabled. The Site ID field is not mandatory but useful if you are tracking more than one website on a single Matomo instance; it can be found on the Matomo instance console."
+ config_instructions_tag_manager_html: "Setting the Matomo Tag Manager URL enables Matomo Tag Manager. This tool allows you to set up analytics events. The Matomo Tag Manager URL is copied from the Install Code section of Matomo Tag Manager. Ensure you select the right container and environment as these options change the URL."
customers:
index: