Google Analytics in Blade

You can have this function by 3 ways:

1. Under Blade > Custom Codes

Please add the Google Tracking Code in the Blade > Custom Codes > Code (Head). For example:

<script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

 ga('create', 'UA-XXXXXXXX-X', 'auto');
 ga('send', 'pageview');

</script>

 

google analytics in blade theme

2. Via Theme Options (JS Code)

Please add the JS tracking code under Appearance > Theme Options > CSS/JS Code – JS Code and replace the UA-XXXXXXXX-X with your tracking id:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', 'auto');
ga('send', 'pageview');

 

3. Via Child Theme

Please add a function to your functions.php of your Child Theme and replace UA-XXXXXXXX-X with your tracking id :

/**
 * Prints Tracking code for analytics e.g: Google Analytics
 */
add_action('wp_head', 'grve_blade_child_print_tracking_code');
function grve_blade_child_print_tracking_code() {
?>
<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    ga('create', 'UA-XXXXXXXX-X', 'auto');
    ga('send', 'pageview');
</script>
<?php
}