Created
March 30, 2024 18:02
-
-
Save Kernix13/5bf5506a14dea458a8bbb0885de6ea55 to your computer and use it in GitHub Desktop.
Google Analytics loaded via wp_print_scripts
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
/* | |
DELETE THIS COMMENT BLOCK | |
1. replace 'yourtheme' in yourtheme_google_print_scripts with your theme name | |
- it occurs twice in the code below | |
2. replace the URL below that ends with 'ABC123' with your URL | |
3. replace 'ABC123' argument below in the 'gtag' function | |
4. Paste all of the code to the bottom of your functions.php file in the child theme or custom theme | |
*/ | |
function yourtheme_google_print_scripts() { ?> | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=G-ABC123"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'G-ABC123'); | |
</script> | |
<?php | |
} | |
add_action('wp_print_scripts', 'yourtheme_google_print_scripts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment