title: Google Analytics tracking events within php
body: <p>I want to track events via google analytics for items loading on the page. Basically if a banner image shows on a page I want to track the impression via an event using google analytics. So for example:</p>
  
  <pre><code>pageTracker._trackEvent('BannerImages','Impression','Banner Ad Name Here');
  </code></pre>
  
  <p>Where would I put this? Here is the php code:</p>
  
  <pre><code>$query = $dbconn-&gt;query("SELECT * FROM banner_images LIMIT 5");
  
  foreach($query AS $banner_result)
  {
  
  echo '&lt;div&gt;' .$banner_result-&gt;location .'&lt;/div&gt;';
  
  }
  </code></pre>
  
  <p>Would I echo out the pageTracker code after each value is echoed out for $banner_result->location like so?</p>
  
  <pre><code>echo '&lt;div&gt;' .$banner_result-&gt;location .'&lt;div&gt;' ."\n" .'&lt;script&gt;pageTracker._trackEvent('BannerImages','Impression','Banner Ad Name Here');&lt;/script&gt;';
  </code></pre>
  
  <p>The google tracking code is in the footer.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Looks like I have to add it after the tracking code initializes.</p>