GithubHelp home page GithubHelp logo

Comments (6)

fritzmg avatar fritzmg commented on June 12, 2024 1

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.

doishub avatar doishub commented on June 12, 2024 1

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.

doishub avatar doishub commented on June 12, 2024

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.

fritzmg avatar fritzmg commented on June 12, 2024

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.

fritzmg avatar fritzmg commented on June 12, 2024

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.

doishub avatar doishub commented on June 12, 2024

Both features were implemented in version 1.7.0.

from contao-cookiebar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.