title: analytics tracking with php website
body: <p>I have recently changed my website format to php (rather than html), i.e. I have renamed all of my HTML pages with a .php extension and fixed the links with my .htaccess file.  </p>
  
  <p>I need to track my new php pages with Google analytics, so I created a separate php file containing Google's javascript snippet. I placed it at the root of my website and linked each of my php tags to it with this code after the <code>&lt;body&gt;</code> tag:</p>
  
  <pre><code>&lt;?php include_once("analyticstracking.php") ?&gt;
  </code></pre>
  
  <p>My problem is that this only appears to be working with my index.php page. All my other pages cannot find <code>analyticstracking.php</code> (in Dreamweaver it says "'analyticstracking.php' is not on the local disk. Get")</p>
  
  <p>If I change the link (by adding "/") to: </p>
  
  <pre><code>&lt;?php include_once("/analyticstracking.php") ?&gt;
  </code></pre>
  
  <p>then all my pages can locate the file but google analytics doesn't appear to track my activity.</p>
  
  <p>I am using "Analytics - Real Time" to test this.</p>
  
  <p>Here is my url www.brp-architects.com. 
  (Currently using </p>
  
  <pre><code>&lt;?php include_once("/analyticstracking.php") ?&gt;
  </code></pre>
  
  <p>as this code, with the "/", allows all my pages to locate my tracking code php file).</p>
  
  <p>The whole reason I am doing this is so I can use a snippet of PHP code to retrieve my website visitor's IP addresses by getting behind the proxy servers ip:</p>
  
  <pre><code>&lt;?
  if (getenv(HTTP_X_FORWARDED_FOR)) {
      $ip_address = getenv(HTTP_X_FORWARDED_FOR);
  } else {
      $ip_address = getenv(REMOTE_ADDR);
  }
  </code></pre>
  
  <p>?></p>
  
  <p>
  Thanks for your responses!</p>
  
  <p>Here is my tracking snippet from the analyticstracking.php file:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-5434990-2']);
    _gaq.push(['_trackPageview']);
    setTimeout('_gaq.push([\'_trackEvent\', \'NoBounce\', \'Over 30 seconds\'])',30000);
  
  (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The link to my tracking code is directly under the opening body tag:</p>
  
  <pre><code>&lt;?php include_once("/analyticstracking.php") ?&gt;
  </code></pre>