Add Google Analytics to WordPress Theme functions.php
function init_analytics() { | |
$analytics = '<script type="text/javascript"> | |
var _gaq = _gaq || []; | |
_gaq.push([\'_setAccount\', \'UA-XXXXXXXX-X\']); | |
_gaq.push([\'_trackPageview\']); | |
(function() { | |
var ga = document.createElement(\'script\'); ga.type = \'text/javascript\'; ga.async = true; | |
ga.src = (\'https:\' == document.location.protocol ? \'https://\' : \'http://\') + \'stats.g.doubleclick.net/dc.js\'; | |
var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
</script>'; | |
echo "\n" . $analytics; | |
} | |
if (!is_admin()) { | |
//load front-end options here. | |
if(!current_user_can( 'manage_options' ) ) { | |
add_action('wp_footer', 'init_analytics', 35); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment