Comments (6)
In the mean time, for anyone trying to achieve this:
<!-- templates/matomo_nocookies.html5 -->
var _paq = window._paq = window._paq || [];
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="<?= $this->url ?>";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', <?= $this->id ?>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
// src/EventListener/MatomoNoCookiesListener.php
namespace App\EventListener;
use Contao\BackendTemplate;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Oveleon\ContaoCookiebar\CookieHandler;
/**
* @Hook("compileCookieType")
*/
class MatomoNoCookiesListener
{
public const TYPE = 'matomoNoCookies';
public function __invoke(string $type, CookieHandler $handler): void
{
if ($this->isRecursion || self::TYPE !== $type) {
return;
}
$url = str_replace(['http:', 'https:'], '', $handler->vendorUrl);
$url = '/' === substr($url, -1) ? $url : $url.'/';
$url = '//' === substr($url, 0, 2) ? $url : '//'.$url;
$template = new BackendTemplate('matomo_nocookies');
$template->url = $url;
$template->id = $handler->vendorId;
$handler->addScript(
$template->parse(),
true,
CookieHandler::POS_HEAD
);
}
}
Note: I had to use BackendTemplate
in order to avoid an infinite recursion due the usage of the parseFrontendTemplate
hook within the extension.
// contao/dca/tl_cookie.php
use App\EventListener\MatomoNoCookiesListener;
use Contao\CoreBundle\DataContainer\PaletteManipulator;
$GLOBALS['TL_DCA']['tl_cookie']['fields']['type']['options'][] = MatomoNoCookiesListener::TYPE;
$GLOBALS['TL_DCA']['tl_cookie']['palettes'][MatomoNoCookiesListener::TYPE] = $GLOBALS['TL_DCA']['tl_cookie']['palettes']['matomo'];
PaletteManipulator::create()
->removeField('token')
->removeField('showTokens')
->removeField('expireTime')
->removeField('showExpireTime')
->applyToPalette(MatomoNoCookiesListener::TYPE, 'tl_cookie')
;
// contao/languages/en/tl_cookie.php
use App\EventListener\MatomoNoCookiesListener;
$GLOBALS['TL_LANG']['tl_cookie'][MatomoNoCookiesListener::TYPE] = ['Matomo (no cookies)', 'Integrate Matomo without Cookies.'];
$GLOBALS['TL_LANG']['tl_cookie'][MatomoNoCookiesListener::TYPE.'_vendorId'] = &$GLOBALS['TL_LANG']['tl_cookie']['matomo_vendorId'];
$GLOBALS['TL_LANG']['tl_cookie'][MatomoNoCookiesListener::TYPE.'_vendorUrl'] = &$GLOBALS['TL_LANG']['tl_cookie']['matomo_vendorUrl'];
from contao-cookiebar.
I can't find a plugin at the moment where an adjustment would be necessary, but I would not want to exclude this. ๐
Maybe I adapt the cookie type "Matomo" as discussed above, but add another cookie type for the use of templates like analytics_*
. This way the extension could work in all directions and you could decide to use a prepared cookie type or integrate your own code via a template.
from contao-cookiebar.
Hello Fritz,
thanks for the nice feedback! ๐
Maybe we can proceed for this case similarly as we already do in the cookie type "Google Analytics". Here there is also the possibility to extend the configuration with a script block. So the following settings for Matomo could be maintained directly in the backend:
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
Furthermore, the cookie token would no longer be defined as mandatory.
Do you think we can get by with that, or should we allow the integration of our own script templates? In the end, this would already be possible via the cookie type "Custom (Script)".
WDYT?
from contao-cookiebar.
In the end, this would already be possible via the cookie type "Custom (Script)".
Yeah, may be I thought too complicated while implementing it ๐
Maybe we can proceed for this case similarly as we already do in the cookie type "Google Analytics". Here there is also the possibility to extend the configuration with a script block. So the following settings for Matomo could be maintained directly in the backend:
May be, yeah. Though if you use plugins, then you'd still need the custom script.
// hm or not, I thought they would need to be anabled in the tracking script as well
from contao-cookiebar.
Maybe I adapt the cookie type "Matomo" as discussed above, but add another cookie type for the use of templates like
analytics_*
. This way the extension could work in all directions and you could decide to use a prepared cookie type or integrate your own code via a template.
Sounds good, I think ๐
from contao-cookiebar.
Both features were implemented in version 1.7.0
.
from contao-cookiebar.
Related Issues (20)
- 5.x-dev Google Analytics not working HOT 3
- Starten unterbinden bei Bots wie Google HOT 4
- Feature request : Content-blocking-only-mode HOT 7
- Videos werden nicht mehr angezeigtโฆ HOT 7
- No Menu Entry after Installation HOT 2
- Add new Google Consent Mode options
- Add a message when consent-log is activated/deactivated HOT 1
- Unknown option within language of the essential cookie group HOT 1
- Add an insert tag to open cookie bar HOT 3
- Cookiebar unter Contao 5.3 LTS Fehlermeldung HOT 3
- 2.0-RC1: Extended swiper.html.twig template is ignored if cookiebar is activated HOT 6
- Contao 5.3 CSP Support HOT 8
- Export large data from tl_cookie_log HOT 2
- Debug Mode not working: Attempt to read property "rootId" on null (2.0.0-RC2) HOT 12
- Soft hypen insert-tag stopped working in 2.0.0 HOT 1
- 5.3.1: error message when updating extensions with the contao manager HOT 2
- Problem with Contao 5.2 HOT 1
- Contao 5.3? Twig? Consent-Mode? Google Ads? HOT 4
- Einbindung Trustami Widget HOT 3
- Cookiebar Ausrichtung - fehlende CSS-Klasse oder CSS unvollstรคndig? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contao-cookiebar.