Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在下载PHP脚本中调用跟踪PHP脚本_Php_Html_Analytics_Tracking_Execute - Fatal编程技术网

在下载PHP脚本中调用跟踪PHP脚本

在下载PHP脚本中调用跟踪PHP脚本,php,html,analytics,tracking,execute,Php,Html,Analytics,Tracking,Execute,所以我正试图开发一个供个人使用的网站,到目前为止,我已经有了一个谷歌分析账户和一些基本的基础设施。我想有一个下载功能,我有一个脚本,我设法从这个网站上的另一个问题获得,但是我似乎找不到一个有效的方法来调用下载脚本中的tracking.php。我一直不成功,因为GA将接收请求,但文件将在单独的选项卡上随机下载 以下是我目前使用的下载脚本: <?php $path = $_SERVER['DOCUMENT_ROOT']."/store/files/"; $fullPath = $pat

所以我正试图开发一个供个人使用的网站,到目前为止,我已经有了一个谷歌分析账户和一些基本的基础设施。我想有一个下载功能,我有一个脚本,我设法从这个网站上的另一个问题获得,但是我似乎找不到一个有效的方法来调用下载脚本中的tracking.php。我一直不成功,因为GA将接收请求,但文件将在单独的选项卡上随机下载

以下是我目前使用的下载脚本:

    <?php
$path = $_SERVER['DOCUMENT_ROOT']."/store/files/";
$fullPath = $path.$_GET['id'];


if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
        header("Content-type: application/pdf");
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private");
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;


    }

}

fclose ($fd);
exit;
?>
Google Analytics tracking code tracking.php位于同一目录下另一个单独的php文件中。我尝试过使用exec和include函数,但没有效果


关于我如何纠正这个问题,你有什么想法吗?

你可能会带一些想法来解决这个问题

基本上,不是尝试在下载中跟踪,而是跟踪用户单击的下载链接:

<a href="toyourdownloadscript.php" onClick="_gaq.push(['_trackEvent', 'Downloads', 'Download', 'The name of your download']);">Download</a>

感谢您的回答,但是我仍然无法在GA下填充事件。跟踪片段已放置标记,我在索引上有几个简单的链接,带有事件跟踪,但它们仍然没有反映GA。页面源可在查看源中找到:再次,谢谢!