title: Use Google Analytics to count user visits from an image
body: <p>i have a problem with PHP and Google Analytics. Basically what i want to do is to count a visit when the user access this image from my email <code>&lt;img src='path/to/image' /&gt;</code> from his email client in in <strong>Google Analytics</strong>.</p>
  
  <pre><code>// If is a view then just show an image
  if($mysqlAction == "VIEW")
  {
      // Create a blank image and add some text
      header('Content-Type: image/jpeg');
      readfile('image.jpg');
      ?&gt;
      &lt;script type="text/javascript"&gt;
  
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-35932495-2']);
      _gaq.push(['_trackPageview']);
  
      (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;
      &lt;?php
  }
  </code></pre>
  
  <p>My problem is that after </p>
  
  <pre><code>    // Create a blank image and add some text
      header('Content-Type: image/jpeg');
      readfile('image.jpg');
  </code></pre>
  
  <p>it is useless to put any code, because the output of <code>script.php</code> will be like accessing an <code>image.jpg</code> , but i really need to count views in google analytics.</p>
  
  <p>What i want :</p>
  
  <ol>
  <li>How can i solve this?</li>
  <li>Don't give me an alternative like TrackReports from Sendblaster ... or any similar solution.</li>
  </ol>
  
  <p>My ideas are :</p>
  
  <ol>
  <li>My idea was something with double buffer like first show the analitycs code and then <code>ob_flush()</code> the image</li>
  <li>Fetch with <code>CURL</code> another page or something ...</li>
  <li>Use Analitics for PHP ... </li>
  </ol>
  
  <p>Any solution?</p>