Move CustomDimensions into another Plugin

Hello,

I’ve written a Plugin, which generates a new reporting tab in my menu. Now I want to display the Customdimensions in my new reporting tab and not in the Actions-tab. I guess I have to change the code of the Customdimensions-plugin or change something in the matomo database.

Did someone have a similar issue and could help me with my problem?

Best Regards,

T.N.

Hi.

I guess with “new reporting tab” you mean a new main category in the sidebar menu.
If I understand correctly the category placement of the CustomDimensions is done here:

Changing the categoryId from ‘General_Actions’ to your ID should do the trick. Alternatively you could write your own plugin that gets the data from one or more dimensions and displays it where and how you like…

@bfi-dev
Yes thats exactly what I’am meaning.
Unfortunatly I’ve allready tried your suggestion and it doesn’t work, even if I restart apache. The Customdimensions are still in the Generel_Actions Tab, their names are just not displayed correctly anymore.

Try setting the categoryId here as well:


Setting it in both places works on my local installation.

This is a quick and dirty hack, though. In the long run it might be better if your plugin creates an own report with the data from the CustomDimension, like:
$data = Request::processRequest('CustomDimensions.getCustomDimension', [...]);

1 Like

Thank you very much, that did it. I wil try to improve my plugin though, that it creates the reports itself.

namespace Piwik\Plugins\MyPlugin;

class MyPlugin extends \Piwik\Plugin
{
        public function registerEvents()
    {
        return array(
            'after' => true,
            'CustomDimensions.addSubcategories' => 'addSubcategories'
        );
    }

        public function addSubcategories(&$subcategories)
    {
        }
}

that’s my code so far, but I’m not quite sure what to write in the addSubcategories function. As I#m afraid that the error would also occur if I write my previous code which I had in CustomDimnesions here.

This is the code i use:

class MyPlugin extends \Piwik\Plugin
{
  public function registerEvents()
  {
    return [
      'Report.filterReports' => 'modifyReports'
    ];
  }

  public function modifyReports(array &$reports)
  {
    foreach ($reports as $idx => $report) {
      if ($report instanceof GetCustomDimension) {
        $rep = new \ReflectionClass('\Piwik\Plugin\Report');
        $catId = $rep->getProperty('categoryId');
        $catId->setAccessible(true);
        $catId->setValue($report, 'MyCategory');
        $subId = $rep->getProperty('subcategoryId');
        $subId->setAccessible(true);
        $subId->setValue($report, $report->menuTitle);
      }
    }
  }

}

Basically you can set a category and subcategory for every custom dimension here (for subcategory I use the report title). The reflection stuff is only needed because the report properties are protected.