- Issue created by @ultimike
With the Klaro! consent management module β gaining traction (as it is part of Drupal CMS,) it would be swell if this module supported integration with it out-of-the-box.
I think this will have to be an "Enable Klaro! integration" checkbox configuration option in this module so that when selected, the mautic_base_url
script tag is properly output. When using Klaro, script tags with 3rd-party src values must utilize slightly different attributes. For example, instead of the current:
<script async src="https://your-mautic-site.com/mtc.js">
When using Klaro, this must be:
To achieve this on my site, I added the following patch which modifies the mautic.js file:
diff --git a/js/mautic.js b/js/mautic.js
index 45e677a2a7..7fd2f465d0 100644
--- a/js/mautic.js
+++ b/s/mautic.js
@@ -1,5 +1,13 @@
(function(w,d,t,drupalSettings,n,a,m){w['MauticTrackingObject']=n;
w[n]=w[n]||function(){(w[n].q=w[n].q||[]).push(arguments)},a=d.createElement(t),
-m=d.getElementsByTagName(t)[0];a.async=1;a.src=drupalSettings.mautic.base_url;m.parentNode.insertBefore(a,m)
+m=d.getElementsByTagName(t)[0];
+//a.async=1;
+//a.src=drupalSettings.mautic.base_url;
+a.defer = 1;
+a.dataset.src = drupalSettings.mautic.base_url;
+a.dataset.type = "text/javascript";
+a.type = "text/plain";
+a.dataset.name = "unknown_app";
+m.parentNode.insertBefore(a,m)
})(window,document,'script',drupalSettings,'mt');
mt('send', 'pageview');
In addition, since I have a Mautic form on my site, I needed to modify the code provided by Mautic in my html.html.twig template file with the following:
//script.type = 'text/javascript';
//script.src = 'https://your-mautic-site.com/media/js/mautic-form.js';
script.defer = 1;
script.dataset.src = 'https://your-mautic-site.com/media/js/mautic-form.js';
script.dataset.type = "text/javascript";
script.type = "text/plain";
script.dataset.name = "unknown_app";
With these two changes, Klaro can properly handle the Mautic javascript files.
-mike
Active
1.0
Code