-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* To use this script, please fill in your Google Analytics ID below | ||
*/ | ||
$GoogleAnalyticsId = 'UA-XXXXX-X'; | ||
|
||
/** | ||
* DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING! | ||
* if ($GoogleAnalyticsId != 'UA-XXXXX-X' && !BE_USER_LOGGED_IN && sha1(session_id() . (!Config::get('disableIpCheck') ? Environment::get('ip') : '') . 'BE_USER_AUTH') != Input::cookie('BE_USER_AUTH')): | ||
*/ | ||
if ('XXXXX' != $GoogleAnalyticsId && !$this->hasAuthenticatedBackendUser()): ?> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
if (localStorage.getItem('contaoPrivacy.enabledAnalytics')) { | ||
// Create the GA4 script element | ||
var ga4Script = document.createElement('script'); | ||
ga4Script.async = true; | ||
ga4Script.src = 'https://www.googletagmanager.com/gtag/js?id=<?= $GoogleAnalyticsId ?>'; | ||
// Append the GA4 script to the placeholder element | ||
document.body.appendChild(ga4Script); | ||
|
||
// Insert the GA4 initialization code | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag() { | ||
dataLayer.push(arguments); | ||
} | ||
gtag('js', new Date()); | ||
gtag('config', '<?= $GoogleAnalyticsId ?>', {'anonymize_ip': true}); | ||
} | ||
}); | ||
</script> | ||
<?php endif; ?> |