Jump to content
TNG Community
Tracelines

Quick Guide: Implement Google Analytics Using meta.php

Recommended Posts

Tracelines

Quick Guide: Implement Google Analytics Using meta.php

[Last updated: 05-28-2015]

Any corrections/modifications welcome.  Hope this might help someone.

Create a Google Analytics [GA] account and add your url to obtain your customized GA tracking code.

Create a file (preferably using Notepad++ or another html editor) and name it“analyticsTracking.php” and paste the GA tracking code into it.  It should look something like this:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "
https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

<script type="text/javascript">
var pageTracker = _gat._getTracker("INSERT YOUR ID HERE");
pageTracker._trackPageview();
</script> <?php
// End Analytics tracking code
?>

Place “analyticsTracking.php” file in the same directory as “meta.php”.

Give “analyticsTracking.php” the following permissions: 644 (i.e. -rw-rw-r--)

Edit “meta.php”, by adding the following line:


<?php include_once("analyticstracking.php") ?>

Your meta.php should end up looking like this:

<?php
    global $cms;
?>
<?php include_once("analyticstracking.php") ?>

 

 

 

Share this post


Link to post
Share on other sites
Arnaud

This is a great article. Thanks.

Just mind that there is one small "error" in it, for users  running the TNG software on a server with a case-sensitive operating-system (= probably the majority of users):

The suggested filename for the script has an upper-case T in the name "analyticsTracking.php", whereas the call in the meta.php file does  only have lower-case characters. On webservers running linux this is causing a problem, because this OS is case-sensitive. So, either change the filename to analyticstracking.php, or use an upper-case T in the call from meta.php.

Regards,
Arnaud

 

Share this post


Link to post
Share on other sites
jgrubbs

Just curious, is there a reason why we need to put the Google Analytics code into it's own php file to call as a include in the meta.php vs. just putting the Google Analytics code into the meta.php?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×