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
|
* Google Analytics snippet from HTML5 Boilerplate
|
||||||
|
*
|
||||||
|
* Cookie domain is 'auto' configured. See: http://goo.gl/VUCHKM
|
||||||
*/
|
*/
|
||||||
function roots_google_analytics() { ?>
|
function roots_google_analytics() { ?>
|
||||||
<script>
|
<script>
|
||||||
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
|
<?php if(WP_ENV==='production') :?>
|
||||||
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
|
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
|
||||||
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
|
||||||
e.src='//www.google-analytics.com/analytics.js';
|
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
|
||||||
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
|
e.src='//www.google-analytics.com/analytics.js';
|
||||||
ga('create','<?php echo GOOGLE_ANALYTICS_ID; ?>');ga('send','pageview');
|
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>
|
</script>
|
||||||
|
|
||||||
<?php }
|
<?php }
|
||||||
|
|||||||
Reference in New Issue
Block a user