Last active
September 9, 2019 16:02
-
-
Save deeman/f8d621559c9d7067229f20f5a3b8b221 to your computer and use it in GitHub Desktop.
Google Analytics tracking via Child Theme
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
<!-- Example with code --> | |
<!-- Hook--> | |
add_action( 'wp_head', 'ga_google_analytics', 10 ); | |
function da_google_analytics() { ?> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxxx-x"> | |
</script> | |
<script> | |
// Paste your Google Analytics tracking script here | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', 'UA-xxxxxxxxx-x'); | |
// Tracking Script - End | |
</script> | |
<?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
add_action('wp_head', 'wpb_add_googleanalytics'); | |
function ga_add_googleanalytics() { ?> | |
// Paste your Google Analytics code here | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment