matomo

Matomo: Get actionDetails in Plugin API


I’m trying to create a Custom Report. I want it to display CustomDimensions, that I can find in ?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth= under actionDetails.

I tried to create the report as it is explained in this article: https://developer.matomo.org/guides/custom-reports-extended

But I don’t get any results when I ask for ‘actionDetails’ instead of ‘browserName’.

My function looks like this:

$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;

The var_dump returns array(0) { } although I can see data when I open the ?module=API&method=Live.getLastVisitsDetails&idSite=1&period=day&date=today&format=JSON&token_auth= link.

How can I get the actionDetails data?


Solution

  • You have 'doNotFetchActions' => true maybe set this to false? This removes the actions from the results.