まず、私はphpの初心者です。この方法を使用して作業しているサイトの pdf 追跡を設定したいと考えています: http://www.lunametrics.com/blog/2013/06/04/tracking-pdfs-google-analytics-server-side/
コードを実装しましたが、エラーが発生します
解析エラー: 構文エラー、予期しない T_STRING、9 行目の /home/ngjge/public_html/download.php の T_CONSTANT_ENCAPSED_STRING または '(' が必要です
どんな助けや指針も大歓迎です...
download.php ページの私の php コードは次のとおりです。
?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->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->fromUtma($_COOKIE['__utma']);
//$visitor->setScreenResolution('1480x1200');
// Assemble Session information
$session = new GoogleAnalytics\Session();
$session->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->setTitle($filename);
$page->setReferrer($_SERVER['HTTP_REFERER']);
// Track page view
$tracker->trackPageview($page, $session, $visitor);
// Create the URL for the PDF
$protocol = ((!empty($_SERVER['HTTPS']) && $_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;
?>