Matomo (formerly known as Piwik) is a versatile web analytics platform that allows users to gain deep insights into their website’s performance and user behavior. One of the powerful features of Matomo is the ability to generate custom reports and create reporting menus and widgets. In this blog post, we will explore how to create a reporting menu, generate custom reports, and convert them into widgets to display valuable data on your Matomo dashboard.
Generating a Reporting Plugin
Before we dive into creating a reporting menu and reporting widget, we need to clone Matomo from the Git repository. You can download Matomo and get started by following the instructions provided in the Matomo Developer Guide, which can be found at this URL: https://developer.matomo.org/guides/getting-started-part-1.
Once you have downloaded Matomo, you can generate a plugin by following these steps:
Activate the Developer Mode
Enable the developer mode by running the following command
./console development:enable.
Generate a Plugin
Run the command to generate a custom plugin
./console generate:plugin –name=”MyWidgetPlugin”
This will create a folder named plugins/MyWidgetPlugin for your plugin.
Activate the Plugin
Activate the created plugin under “Settings => Plugins” or by using the command
./console plugin:activate MyWidgetPlugin
Creating a Custom Report
Custom reports provide the flexibility to arrange and structure the data in a way that makes sense to you. You can choose the order in which the data is presented, apply filters to segment the information, and even apply advanced analytics techniques to derive deeper insights. See the example,
To create a custom report, follow these steps:
Generate a Controller in the Plugin
Run the command ./console generate:controller to generate a controller for your plugin.
This command will guide you through the process of creating a report. You will be prompted for details such as the plugin name, report name, and report category. You can use an existing plugin name and categories or create new ones.
Adding a Reporting Menu and Widget
To add a menu in the sidebar and convert the report into a widget, follow these steps:
Add Menu Initialization
We can simply use the init() method inside the report/GetMyReportName.php file which is created in the selected plugin during the report-generating command.
Uncomment the subcategoryId line in the report/GetMyReportName.php file under the init method. The menu will be created. When we click on it, the report will be displayed there.
Making the Report a Widget
Creating a widget is a straightforward process. You just need to define the configureWidgets the method within the report class (located at Report/GetMyReportName), and you’re good to go.
public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory)
{
// we have to do it manually since it’s only done automatically if a subcategoryId is specified,
// we do not set a subcategoryId since this report is not supposed to be shown in the UI
If the subcategory for the report is already defined, there is no requirement to include the aforementioned code. However, if the report subcategory has not been implemented, you can add the provided code to transform the report into a dashboard widget. Otherwise, the report will be automatically created without any additional steps. For more details, have a visit to this URL.
Within the custom report, you have the flexibility to arrange and display the values according to your specific requirements. This allows you to curate the report to highlight the most relevant information for your analysis. Ultimately, the outcome is elegantly showcased and presented within the widget, providing a visually compelling and user-friendly interface for accessing and exploring the valuable insights generated by Matomo.
1 Comment
shahzeen – June 8, 2023
very helpful information..