Google Analytics location?

Where do I put the code for Google Analytics?

In one place in the documentation it sounds like you can put it in a PHP include file and include it anywhere. But in another place in the documentation it sounds like it has to be between the < head > < /head > tags?

I have a PHP include file called “footer.php” that is on every page and I was hoping to just drop it in there. But I know that my IDE complains about the < script > tags being outside of the < head > tags and so it got me to doubting this approach.

When running locally there is no need to call the JavaScript Analysis :smile:

// preferably the first file loaded

// Define Locahost platform
defined('LOCALHOST') ?: define('LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME']);

<?php // footer.php

if( ! LOCALHOST ): 
   include '/assets/js/google-analytics.js'; // without <script> </script>
   include '/assets/js/google-plusone.js'; // without <script> </script>
 endif;

I always include Google Analytics code at the bottom of the website right before the </html> tag

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.