title: Insert Google Analytics in php (Am I doing it the right way?)
body: <p>I'm trying to load Google Analytics on every file using php.
  This is not a site, these are some affiliate links structure with javascript redirectiib, so I decided to implement GA tracking code on them. They basically work like this:</p>
  
  <p>The root folder is <code>affiliatestuff</code>, and it has:<br/>
  <code>googleanalytics123.php</code> (File which contains the GA javascript), it doesn't have any php inside, just the GA code.<br/>
  <code>index.thml</code>: Blank HTML file.<br/><br/>
  Inside the root folder there is a subfolder named <code>affiliate01</code>: Inside this folder, there is a <code>index.php</code> with the following code (Please not that in the following code I've changed a few stuff for security reasons):</p>
  
  <p>Begin <code>index.php</code></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
  &lt;?php
  include_once ('http:// my site/go/googleanalytics123.php');
  ?&gt;
  
  &lt;script type="text/javascript"&gt; function recordOutboundLink(link, category, action) { try { var myTracker=_gat._getTrackerByName(); _gaq.push(['myTracker._trackEvent', category , action ]); setTimeout('document.location = "' + link.href + '"', 100) }catch(err){} } &lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;&lt;a href="../trafficapp"&gt;trafficapp&lt;/a&gt;
  
  recordOutboundLink(this, 'Go to Australia', 'http:// my affiliate link /191719/18040');
  setTimeout(function(){window.location='http:// my affiliate link/191719/18040';}, 500); // working with a 500ms timeout to make sure the tracking is done correctly
  
  &lt;/script&gt;&lt;/head&gt;
  &lt;title&gt;Live and work in Australia&lt;/title&gt;
  &lt;body&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>That last file is supposed to redirect the user to the affiliate product's page, it is working, what I'd like to know is if I'm getting the googleanalytics123.php the right way.</p>
  
  <p>There is the code of the googleanalytics123.php</p>
  
  <pre><code>&lt;script&gt;
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
    ga('create', 'UA-xxxxxxxx-x', 'auto');
    ga('send', 'pageview');
  
  &lt;/script&gt;
  </code></pre>
  
  <p>It's just that inside the script, no php at all. Please not that I've changed the UA on purpose.</p>
  
  <p>So am I doing it the right way? I managed to track the google analytics file, but not the affiliates folder.</p>