Created
July 10, 2021 00:02
-
-
Save stacklast/8c15515f2893115d841b38d20b814e67 to your computer and use it in GitHub Desktop.
[WordPress] - Add Google Analytics | Global site tag (gtag.js) - Google Analytics
This file contains hidden or 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 | |
| // Add Google Analytics | |
| add_action( 'wp_head', 'my_own_analytics', 20 ); | |
| function my_own_analytics() { ?> | |
| <!-- Global site tag (gtag.js) - Google Analytics --> | |
| <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script> | |
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'UA-XXXXXXXXX-X'); | |
| </script> | |
| <?php | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment