在我的网站上,可以下载pdf。
到这里为止,一切都很好。
现在,我想跟踪pdf下载。这可以通过使用pdf链接中的Google Analytics(分析)事件来完成:
<a onclick="var that=this;_gaq.push(['_trackEvent','Download','PDF',this.href]);setTimeout(function(){location.href=that.href;},400);return false;" href="pdfs/my-file.pdf">Download my file</a>
问题是,如果somebady将从搜索引擎(而不是直接从网站)下载pdf,将不会被跟踪。
您是否知道适当的跟踪方法?
渲染pdf时,是否应该在服务器端实现某些功能,从而触发GA事件?
先感谢您。
请您参考如下方法:
这是我刚刚找到的一种解决方案:
php-ga Google Analytics for PHP
使用php-ga,可以在服务器端模拟综合浏览量。因此,现在对我来说,当有人下载pdf时,我也称呼此代码:
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-5824718-6', 'mdpi.com');
// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->setScreenResolution('1024x768');
// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();
// Get filename from the previous request
$filename = parse_url(urldecode($_SERVER['REQUEST_URI']), PHP_URL_PATH);
// Assemble Page information
$page = new GoogleAnalytics\Page($filename);
$page->setTitle($filename);
// Track page view
$tracker->trackPageview($page, $session, $visitor);
$this->downloadFile($file, 'application/pdf');
我必须解决的唯一问题是如何过滤机器人(机器人)...