<?php
// script configuration
$GoogleAnalyticsId = $GLOBALS['TL_CONFIG']['googleAnalytics'];
// script activation check
// if ($GoogleAnalyticsId):
if ($GoogleAnalyticsId && !BE_USER_LOGGED_IN && !$this->hasAuthenticatedBackendUser()):
?>
<!-- contao: ga -->
<script async src="https://www.googletagmanager.com/gtag/js?id=<?= $GoogleAnalyticsId ?>"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '<?= $GoogleAnalyticsId ?>');
</script>
<?php endif; ?>