Skip to content

Commit

Permalink
Only load GA in production environment
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
QWp6t committed Aug 7, 2014
1 parent 576d70e commit dc0e838
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,23 @@ function roots_jquery_local_fallback($src, $handle = null) {

/**
* 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 }
Expand Down

0 comments on commit dc0e838

Please sign in to comment.