title: tracking pdfs with php-ga and Google Analytics Not Working Right.
body: <p>First off, I am total newbie to php.
   I am wanting to set up pdf tracking for a site I am working on using this method:
  <a href="http://www.lunametrics.com/blog/2013/06/04/tracking-pdfs-google-analytics-server-side/" rel="nofollow">http://www.lunametrics.com/blog/2013/06/04/tracking-pdfs-google-analytics-server-side/</a> </p>
  
  <p>I have implemented the code, but am getting a error </p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/ngjge/public_html/download.php on line 9</p>
  </blockquote>
  
  <p>Any help or pointers would be greatly appreciated...</p>
  
  <p>My php code for the download.php page is:</p>
  
  <pre><code>?php
  
  // Set header MIME-Type for PDF
  header("Content-type: application/pdf");
  
  // Google Analytics Server Side
  $GA_ACCOUNT = "UA-8496414-14"; // replace with your GA-ID
  include "autoload.php";
  use UnitedPrototype\GoogleAnalytics;
  
  // Initilize GA Tracker
  $tracker = new GoogleAnalytics\Tracker($GA_ACCOUNT, 'goodandevilbook.com');
  
  // Assemble Visitor information
  $visitor = new GoogleAnalytics\Visitor();
  $visitor-&gt;setIpAddress($_SERVER['REMOTE_ADDR']);
  $visitor-&gt;setUserAgent($_SERVER['HTTP_USER_AGENT']);
  $visitor-&gt;fromUtma($_COOKIE['__utma']);
  //$visitor-&gt;setScreenResolution('1480x1200');
  
  // Assemble Session information
  $session = new GoogleAnalytics\Session();
  $session-&gt;fromUtmb($_COOKIE['__utmb']);
  
  // Get filename from the previous request
  $filename = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH);
  //$filetype = preg_replace("/.+\.(.+)/i","$1",$filename);
  
  // Assemble Page information
  $page = new GoogleAnalytics\Page($filename);
  $page-&gt;setTitle($filename);
  $page-&gt;setReferrer($_SERVER['HTTP_REFERER']);
  
  // Track page view
  $tracker-&gt;trackPageview($page, $session, $visitor);
  
  // Create the URL for the PDF
  $protocol = ((!empty($_SERVER['HTTPS']) &amp;&amp; $_SERVER['HTTPS'] != 'off') ||       $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
  $url  = $protocol.$_SERVER['HTTP_HOST'].$filename;
  
  // Fetch the PDF (cURL it)
  $ch = curl_init($url);
  // This creates a user-agent string that we set .htaccess to ignore (preventing an endless ##loop)
  curl_setopt($ch, CURLOPT_USERAGENT, "LunaMetrics123");
  $data = curl_exec($ch);
  curl_close($ch);
  
  // For good measure
  exit;
  ?&gt;
  </code></pre>