fix: properly initialize CMP, GTM and data layer for tracking

This commit is contained in:
Björn Fromme
2026-01-27 21:25:03 +01:00
parent 6365e4b24c
commit 93eb08c610
12 changed files with 87 additions and 37 deletions
+5 -12
View File
@@ -1,12 +1,5 @@
<script>
window.dataLayer = window.dataLayer || [];
var consent = (window.CookieFirst && window.CookieFirst.consent) || { advertising: false };
if (consent.advertising) {
dataLayer.push({
'event':'VirtualPageview',
'virtualPageURL': '{{ url }}',
'virtualPageTitle': '{{ title }}',
'userInfo': '{{ is_granted('ROLE_USER') ? 'mitglied' : 'gast' }}'
});
}
</script>
<div {{ stimulus_controller('data-layer', {
'url': url,
'title': title,
'userInfo': is_granted('ROLE_USER') ? 'mitglied' : 'gast'
}) }}></div>
+2
View File
@@ -9,6 +9,7 @@
<link rel="icon" href="{{ asset('build/favicon/icon.svg') }}" type="image/svg+xml">
<link rel="apple-touch-icon" href="{{ asset('build/favicon/apple-touch-icon.png') }}">
{% if cmp_url() is not empty %}
<script>window.dataLayer = window.dataLayer || [];</script>
<script src="{{ cmp_url() }}"></script>
<script type="text/plain" data-cookiefirst-category="necessary">
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
@@ -27,5 +28,6 @@
</head>
<body class="bg-white text-gray-700 font-sans antialiased {{ booking_theme() }}"{% if not oauth2 %} hx-boost="true"{% endif %}>
{% block body %}{% endblock %}
{% block data_layer %}{% endblock %}
</body>
</html>
@@ -95,10 +95,6 @@
</div>
</div>
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt0_login_oder_gast',
'title': 'Login oder Gast'
} %}
{% endblock %}
{% block footer %}
@@ -112,3 +108,10 @@
</button>
</div>
{% endblock %}
{% block data_layer %}
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt0_login_oder_gast',
'title': 'Login oder Gast'
} %}
{% endblock %}
@@ -101,6 +101,9 @@
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{% block data_layer %}
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt1_zimmerauswahl',
'title': 'Zimmerauswahl'
@@ -75,6 +75,9 @@
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{% block data_layer %}
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt2_teilnehmende_leistungen',
'title': 'Teilnehmende und Leistungen'
@@ -85,6 +85,9 @@
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{% block data_layer %}
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt3_zahlungsart',
'title': 'Zahlungsart'
@@ -567,6 +567,9 @@
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{% block data_layer %}
{% include '_partials/_tracking.html.twig' with {
'url': '/trichter_Z1/schritt4_uerbersicht_bestaetigung',
'title': 'Übersicht und Bestätigung'
@@ -55,6 +55,9 @@
</div>
</div>
{% endblock %}
{% block data_layer %}
{% if bookingTotal is not null and travelName is not null %}
<script>
window.dataLayer = window.dataLayer || [];