如何使用 google-analytics 和 php 跟踪下载页面?

2021-12-29 00:00:00 redirect php google-analytics

我在 php 中有一个下载页面,在执行一些检查后返回一个文件,但不显示任何 html:

I have a download page in php that after performing some checks returns a file, without displaying any html:

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=xyz.exe');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize(LOCAL_FILE));
readfile(LOCAL_FILE);

现在我想用 google-analytics 跟踪这个页面.在不显示 html 的情况下实现这一目标的最佳方法是什么?

Now I'd like to track this page with google-analytics. What's the best way to achieve this without displaying html?

推荐答案

试试这个:http://www.acleon.co.uk/posts/galvanize-google-analytics-without-the-javascript/

它叫做Galvanize"(不知道是谁想到的).您可以在此处下载该类.

Its called 'Galvanize' (Don't know who thought that one up). You can download the class here.

显然开发人员仍然支持它,因为他两天前刚刚评论了一个错误修复.

Apparently the developer is still supporting it too, as he just commented about a bug fix 2 days ago.

相关文章