Last active
December 26, 2021 21:52
-
-
Save drikusroor/37584fc94f9677123a64bbe2460c7d76 to your computer and use it in GitHub Desktop.
Insert a Google Analytics sitetag in Wordpress using a constant defined in wp-config.php
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
<?php | |
if (defined('GOOGLE_ANALYTICS_KEY')) { | |
?> | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=<?php echo GOOGLE_ANALYTICS_KEY; ?>"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag() { | |
dataLayer.push(arguments); | |
} | |
gtag('js', new Date()); | |
gtag('config', '<?php echo GOOGLE_ANALYTICS_KEY; ?>'); | |
</script> | |
<?php | |
} // if (defined('GOOGLE_ANALYTICS_KEY')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment