title: Google Analytics server-side tracking
body: <p>Google Analytics, by just placing its sourcecode on my website, automatically tracks everything I used to need (pageviews, unique visitors).</p>
  
  <p>But now, I need to track events, and the only way to do this is to do it server-side. Each time any users does an specific action i need to track, the server posts data to google to track the information, as explained here:</p>
  
  <p><a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event" rel="nofollow">https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event</a></p>
  
  <p>And it does works amazingly perfect, but, since I realiced, I am now receiving a LOT of visits from Spain, doubling the visits from USA. And before I implemented the event tracking, Spain wasn't even part of the top 10 countries.</p>
  
  <p>Today I have realiced that my servers are in Spain, and that may be causing the issue.</p>
  
  <p>How can I track the event, without making it count as a pageview?</p>
  
  <pre><code>$url = 'http://www.google-analytics.com/collect';
  $data = array('v' =&gt; '1', 'tid' =&gt; 'UA-HIDDEN-1', 'cid' =&gt; $_SERVER["REMOTE_ADDR"], 'ni' =&gt; '1', 't' =&gt; 'event', 'ec' =&gt; '', 'ea' =&gt; 'JUMP', 'el' =&gt; '');
  $options = array(
      'http' =&gt; array(
          'header'  =&gt; "Content-type: application/x-www-form-urlencoded\r\n",
          'method'  =&gt; 'POST',
          'content' =&gt; http_build_query($data),
      ),
  );
  $context  = stream_context_create($options);
  $result = file_get_contents($url, false, $context);
  </code></pre>
  
  <p>Thank you very much!!</p>