Your software
My Mautic version is: 2.16.2
My PHP version is: 7.3.17
Your problem
My problem is: As of European Law I need to request consent for cookies before them being set. With a javascript code I was able to disallow mautic cookies after they are set. But on first page load Mautic loads cookies via mtc.js which I like to prevent until the visitor has given consent to set these cookies.
The following line seems to be injected into the pages automatically:
I did not found anything in the template files which is used.
This is about the Mautic internal Landing Pages not any external website where the Mautic Tracking Code must be manually inserted.
Where do I disable the automatic tracking for Mautic Landing Pages?
These errors are showing in the log: No.
Steps I have tried to fix the problem:
Searched numerous files and the internet, but did not found any hint how to disable Mautic landing page tracking.
Such blocking is done by Consent Manager tools (many in the Mautic world use https://tarteaucitron.io/, but there are plenty others, free as well as commercial)
To embed it, simply place the tool’s JavaScript snippet in a “code mode” block in the Landing Page builder.
Best,
Ekke
Subscribe to the Mautic Podcast at www.Mauticast.com - and let me know what topics or interviews you would like to hear! (German version at www.Mauticast.de)
tried the code mode block in the builder now. That is not working at all. The Cookie-Consent Script is not even executed.
I got the tarteaucitron.js working though it deletes the tracking cookies when the visitor denies consent. To do so I took the page html from the database and added the necessary code before entering it back to the database. As soon as everything works as intended, I’ll probably adjust the theme files to have these things included by default.
However, the tracking cookies are still set prior consent. Thus the code lines mentioned earlier still get injected. If there is a way to prevent this, it would solve the whole issue.
delete all Cookies set by Mautic prior Visitor Consent when a Mautic Landing Page is visited.
Set Cookies as per Visitor Consent (by using tarteaucitron.js consent tool)
The Solution:
Create a Cookie called “priorconsent” with value “NoConsentYet” (using javascript)
Check for the above cookie and state, if exits delete all Mautic Cookies and the cookie created under 1)
Set Cookies using tarteaucitron.js and refresh page on every Cookie change.
To 3) to work as I intended I needed to change:
tarteaucitron.js line 31 “reloadThePage”: false, to “reloadThePage”: true,
and needed to add window.location.reload(); to the onclick event for the “OK, accept all” button (lines 314 and 381).
That’s it. Now it works as I like it to work.
To make all this work for all Landing Pages, I’ll going to update the Landing Page Template files according to include the solution above.
I adjusted the base.html.twig files of a Landing Page Theme I like to use, thus it includes all the links and javascripts to make the Cookie Consent work properly.
What I discovered is, that when I load the theme landing page, the body tag onload=“myfunction()” in <body onload="myfunction()"> is removed. Thus I tried a script in the head section with window.onload = myfunction() like <script type="text/javascript"> window.onload = myfunction(); </script>. No surprise, this was removed by Mautic on page load either.
Does anyone has an idea where and how Mautic is removing javascript or html tags on the fly?
BTW, if I add the body onload is not removed by Mautic, if I add it to the related page in the database. But I don’t like to go into the DB all the time.
I’m running the newest version of Mautic 3.2.4 on my own Server.