Created
July 7, 2023 00:20
-
-
Save BruceMcKinnon/e552794eb446e0170754a24a9ef1f4ad to your computer and use it in GitHub Desktop.
Add GA to funnctions.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
add_action ( 'wp_head', 'rp_add_custom_js' ); | |
function rp_add_custom_js() { | |
$ga_code = 'G-xxxxxxxx'; | |
$script = "<!-- Google tag (gtag.js) --> | |
<script async src='https://www.googletagmanager.com/gtag/js?id=".$ga_code."'></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', '".$ga_code."'); | |
</script>"; | |
echo $script; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment