*

Recent

Author Topic: Adding Google Analytics to php  (Read 5372 times)

emil

  • Newbie
  • *
  • Posts: 26
  • Force: +0/-0
Adding Google Analytics to php
« on: March 26, 2010, 04:23:38 PM »
Following up on a conversation from yesterday with Kurt and Adam, whom i thank again for the great support. I tried this myself and it works.

For any PHP pages, put the following code in a file (for example, analyticstracking.php) and upload it to your site. Then, add the following line to each template page before the </body> tag: <?php include_once("analyticstracking.php") ?>

<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">
try {
var pageTracker = _gat._getTracker("youranalyticsid");
pageTracker._trackPageview();
} catch(err) {}</script>