Last active
October 6, 2018 22:06
-
-
Save dannydover/164f5d5abebb513d3a1b8a03568408b8 to your computer and use it in GitHub Desktop.
Add Google Analytics (gtag.js) Tracking to top of <head> in Wordpress via Theme functions.php
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 | |
| // Google Analytics Tracking Code Snippet | |
| add_action( 'wp_head', 'google_analytics_tracking', 1 ); | |
| function google_analytics_tracking( $priority ) { | |
| ?> | |
| <!-- Global site tag (gtag.js) - Google Analytics --> | |
| <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX-X"></script> | |
| <script> | |
| window.dataLayer = window.dataLayer || []; | |
| function gtag(){dataLayer.push(arguments);} | |
| gtag('js', new Date()); | |
| gtag('config', 'UA-XXXXXXX-X'); | |
| </script> | |
| <?php | |
| }; | |
| ?> | |
| // REMEMBER TO UPDATE UA CODE "UA-XXXXXXX-X" IN BOTH PLACES IN GIST ABOVE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment