<f:if condition="{siteTrackingGaId}">
    <div
        data-site-tracking
        data-site-tracking-type="analytics"
        data-site-tracking-mode="{f:if(condition: '{siteTrackingEnableCookieBanner}', then: 'opt-in', else: 'opt-out')}"
        data-site-tracking-analytics.id="{siteTrackingGaId}">
    </div>
</f:if>

<f:if condition="{siteTrackingGTag}">
    <div
        data-site-tracking
        data-site-tracking-type="gtag"
        data-site-tracking-mode="{f:if(condition: '{siteTrackingEnableCookieBanner}', then: 'opt-in', else: 'opt-out')}"
        data-site-tracking-gtag.id="{siteTrackingGTag}">
    </div>
</f:if>

<f:if condition="{siteTrackingGtmId}">
    <div
        data-site-tracking
        data-site-tracking-type="tag-manager"
        data-site-tracking-mode="{f:if(condition: '{siteTrackingEnableCookieBanner}', then: 'opt-in', else: 'opt-out')}"
        data-site-tracking-tag-manager.id="{siteTrackingGtmId}"
        data-site-tracking-tag-manager.persist="(int) {siteTrackingAlwaysLoadTagManager}">
    </div>
</f:if>

<f:if condition="{siteTrackingMatomoHost} && {siteTrackingMatomoSiteId}">
    <div
        data-site-tracking
        data-site-tracking-type="matomo"
        data-site-tracking-mode="{f:if(condition: '{siteTrackingEnableCookieBanner}', then: 'opt-in', else: 'opt-out')}">
    </div>

    <f:comment>
        <!--
            Matomo script is initalized with optUserOut and requireConsent.
            Tracking is enabled after user gives consent via cookie consent.
            More info: https://developer.matomo.org/api-reference
        -->
    </f:comment>
    <![CDATA[
    <script type="text/javascript">
        var _paq = window._paq || [];
        _paq.push(['requireConsent']);
        _paq.push(['optUserOut']);
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
        var u="https://]]>{siteTrackingMatomoHost}<![CDATA[/";
        _paq.push(['setTrackerUrl', u'matomo.php']);
        _paq.push(['setSiteId', ']]>{siteTrackingMatomoSiteId}<![CDATA[']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src='//cdn.matomo.cloud/]]>{siteTrackingMatomoHost}<![CDATA[/matomo.js'; s.parentNode.insertBefore(g,s);
        })();
    </script>
    ]]>
</f:if>
