Learn how to integrate Google Analytics into your WordPress theme for tracking site performance.
function codebykp_add_google_analytics() {
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_TRACKING_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'YOUR_TRACKING_ID');
</script>
<?php
}
add_action('wp_head', 'codebykp_add_google_analytics');