Skip to content

Instantly share code, notes, and snippets.

@BruceMcKinnon
Created July 7, 2023 00:20
Show Gist options
  • Save BruceMcKinnon/e552794eb446e0170754a24a9ef1f4ad to your computer and use it in GitHub Desktop.
Save BruceMcKinnon/e552794eb446e0170754a24a9ef1f4ad to your computer and use it in GitHub Desktop.
Add GA to funnctions.php
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