Using Matomo with Drupal
Matomo gathers detailed statistics about visitor traffic to your site. You can integrate Matomo with Drupal using either of the following methods:- Installing and configuring a Drupal module.
- Editing the Drupal theme directly.
Method #1: Use a module
There are several modules available for Drupal that provide Matomo integration, but Matomo’s own site recommends Matomo Analytics. This section describes how to install and configure this plugin.Installing Matomo Analytics
To install the Matomo Analytics module on your Drupal site, follow these steps:- Use your web browser to visit https://www.drupal.org/project/matomo.
- Download the .zip file for your Drupal version to your local computer.
- Log in to your Drupal site as the administrator.
- On the top menu bar, click Manage, and then click Extend.
- Click Install new module.
- Click Browse, select the .zip file on your local computer, and then click Install. Drupal installs the module.
- Click Enable newly added modules. The module is now installed and activated.
Configuring Matomo Analytics
After you install the Matomo Analytics module, you must configure it to work with your Matomo installation. To do this, follow these steps:- Log in to your Drupal site as the administrator.
- On the top menu bar, click Manage, and then click Configuration.
- Under SYSTEM, click Matomo Analytics. The Matomo Analytics configuration page appears.
-
Under GENERAL SETTINGS, in the Matomo site ID text box, type the Matomo ID number for your site.
👍 Tip To obtain the Matomo ID number for your site, follow these steps:
- Log in to Matomo.
-
On the top right of the page, click the Administration (
) icon.
- In the left sidebar, click Websites, and then click Manage.
- Under Manage Measurables, locate your site and its ID number.
- In the Matomo HTTP URL text box, type the full URL to your Matomo installation. For example, if your domain name is example.com, and you installed Matomo in the matomo subdirectory, the full URL is http://example.com/matomo.
- If you have an SSL certificate for your site, in the Matomo HTTPS URL text box, type the full secure URL to your Matomo installation. For example, if your domain name is example.com, and you installed Matomo in the matomo subdirectory, the full secure URL is https://example.com/matomo.
- In the Tracking scope section, you can configure additional settings to customize your site’s tracking behavior.
- Click Save configuration. Matomo is now enabled for Drupal.
Method #2: Edit the theme
Modules are convenient, but they also carry processing overhead with them that may affect site performance. If you prefer not to use a module, you can edit the Drupal theme directly to enable Matomo. To enable Matomo by editing the theme, follow these steps:-
Log in to your Matomo account as the administrator:
-
On the top right of the page, click the Administration (
) icon.
- In the left sidebar, click Websites, and then click Tracking Code.
- Under JavaScript Tracking Code, copy the entire text in the tracking code box, including the starting {/Matomooo/} tag and the ending {/End Matomo Codeee/} tag.
-
On the top right of the page, click the Administration (
-
Using SSH or the cPanel File Manager, navigate to the Drupal theme directory.
📘 Note This location varies based on:
- Where you installed Drupal.
- Which version of Drupal you are running.
-
Use your preferred text editor to open the page template file for the theme.
📘 Note This file varies based on:
- Which theme you are using.
- Which version of Drupal you are running.
- Paste the tracking code snippet that you obtained in step 1.
- Save your changes to the theme file. Matomo is now enabled for all pages on your Drupal site. To view site statistics, log in to your Matomo account.