diff --git a/.env b/.env index 45af9966..48243088 100644 --- a/.env +++ b/.env @@ -72,6 +72,7 @@ OAUTH_BUDDY_CLIENT_SECRET= ###> google analytics ### GA_TRACKING= +GA4_TRACKING= ###< google analytics ### ###> storage ### diff --git a/.env.docker b/.env.docker index c23a221f..74b445db 100644 --- a/.env.docker +++ b/.env.docker @@ -76,6 +76,7 @@ OAUTH_BUDDY_CLIENT_SECRET= ###> google analytics ### GA_TRACKING= +GA4_TRACKING= ###< google analytics ### ###> storage ### diff --git a/ansible/roles/app.deploy/templates/.env.local b/ansible/roles/app.deploy/templates/.env.local index 152a047d..b1f51926 100644 --- a/ansible/roles/app.deploy/templates/.env.local +++ b/ansible/roles/app.deploy/templates/.env.local @@ -24,6 +24,7 @@ OAUTH_BUDDY_CLIENT_SECRET={{ lookup('env', 'REPMAN_OAUTH_BUDDY_CLIENT_SECRET') o TRUSTED_PROXIES={{ lookup('env', 'REPMAN_TRUSTED_PROXIES') or '' }} GA_TRACKING={{ lookup('env', 'REPMAN_GA_TRACKING') or '' }} +GA4_TRACKING={{ lookup('env', 'REPMAN_GA4_TRACKING') or '' }} EWZ_RECAPTCHA_ENABLED={{ lookup('env', 'REPMAN_EWZ_RECAPTCHA_ENABLED') or 'false' }} EWZ_RECAPTCHA_SITE_KEY={{ lookup('env', 'REPMAN_EWZ_RECAPTCHA_SITE_KEY') or 'empty' }} diff --git a/config/packages/twig.yaml b/config/packages/twig.yaml index 2c7cb7f6..bbe1d43e 100644 --- a/config/packages/twig.yaml +++ b/config/packages/twig.yaml @@ -5,4 +5,5 @@ twig: '%kernel.project_dir%/public': public globals: ga_tracking: '%env(resolve:GA_TRACKING)%' + ga4_tracking: '%env(resolve:GA4_TRACKING)%' config: '@Buddy\Repman\Service\Config' diff --git a/templates/base.html.twig b/templates/base.html.twig index 1a7f0ffe..c18e0b31 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -135,6 +135,11 @@ {% endif %} + {% if ga4_tracking is not empty %} + + + {% endif %} + {% block javascripts %}{% endblock %} diff --git a/templates/component/js/ga4.js b/templates/component/js/ga4.js new file mode 100644 index 00000000..dab41d95 --- /dev/null +++ b/templates/component/js/ga4.js @@ -0,0 +1,7 @@ +(function() { + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + + gtag('config', '{{ ga4_tracking }}'); +})();