Only load GA in production environment
Loads Google Analytics when `WP_ENV` is 'production' Otherwise it passes `ga()` arguments as an array to `console.log()` Also sets cookie domain to be auto configured.
This commit is contained in:
@@ -79,15 +79,23 @@ add_action('wp_head', 'roots_jquery_local_fallback');
|
||||
|
||||
/**
|
||||
* Google Analytics snippet from HTML5 Boilerplate
|
||||
*
|
||||
* Cookie domain is 'auto' configured. See: http://goo.gl/VUCHKM
|
||||
*/
|
||||
function roots_google_analytics() { ?>
|
||||
<script>
|
||||
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
|
||||
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
|
||||
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
||||
e.src='//www.google-analytics.com/analytics.js';
|
||||
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
|
||||
ga('create','<?php echo GOOGLE_ANALYTICS_ID; ?>');ga('send','pageview');
|
||||
<?php if(WP_ENV==='production') :?>
|
||||
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
|
||||
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
|
||||
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
||||
e.src='//www.google-analytics.com/analytics.js';
|
||||
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
|
||||
<?php else: ?>
|
||||
function ga() {
|
||||
console.log("GoogleAnalytics: " + [].slice.call(arguments));
|
||||
}
|
||||
<?php endif; ?>
|
||||
ga('create','<?php echo GOOGLE_ANALYTICS_ID; ?>','auto');ga('send','pageview');
|
||||
</script>
|
||||
|
||||
<?php }
|
||||
|
||||
Reference in New Issue
Block a user