首页 > 解决方案 > Matomo:在插件 API 中获取 actionDetails

问题描述

我正在尝试创建自定义报告。我希望它显示 CustomDimensions,我可以在 actionDetails 下的 ?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth= 中找到它。

我尝试按照本文中的说明创建报告: https ://developer.matomo.org/guides/custom-reports-extended

但是当我要求“actionDetails”而不是“browserName”时,我没有得到任何结果。

我的功能如下所示:

$data = \Piwik\API\Request::processRequest('Live.getLastVisitsDetails', array(
            'idSite' => $idSite,
            'period' => $period,
            'date' => $date,
            'segment' => $segment,
            'numLastVisitorsToFetch' => 100,
            'minTimestamp' => false,
            'flat' => false,
            'doNotFetchActions' => true
        ));
        $data->applyQueuedFilters();

        // we could create a new instance by using new DataTable(),
        // but we would lose DataTable metadata, which can be useful.
        $result = $data->getEmptyClone($keepFilters = false);

        foreach ($data->getRows() as $visitRow) {
            $actionDetails = $visitRow->getColumn('browserName');
            // try and get the row in the result DataTable for the browser
            $browserRow = $result->getRowFromLabel($actionDetails);

            $test = $visitRow->getColumn('actionDetails');
            var_dump($test);

            // if there is no row for this browser, create it
            if ($browserRow === false) {
                $result->addRowFromSimpleArray(array(
                    'label'     => $actionDetails,
                    'nb_visits' => 1
                ));
            } else { // if there is a row, increment the counter
                $counter = $browserRow->getColumn('nb_visits');
                $browserRow->setColumn('nb_visits', $counter + 1);
            }
        }

        return $result;

var_dump 返回 array(0) { } 虽然我可以在打开 ?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth= 链接时看到数据。

如何获取 actionDetails 数据?

标签: matomo

解决方案


'doNotFetchActions' => true可能已将其设置为 false?这会从结果中删除操作。


推荐阅读