How to use Matomo with Drupal

This article describes how to integrate Drupal with the open-source Matomo (formerly Piwik) analytics platform.

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.

The following sections describe how to do both of these methods.

Before you can use Matomo with Drupal, you must first install the Matomo application files. There are two ways to do this:

  • If your hosting account includes Softaculous, you can use it to install Matomo.
  • If your hosting account does not include Softaculous, or if you want to install the newest version, you can install Matomo manually.
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:

  1. Use your web browser to visit https://www.drupal.org/project/matomo.
  2. Download the .zip file for your Drupal version to your local computer.
  3. Log in to your Drupal site as the administrator.
  4. On the top menu bar, click Manage, and then click Extend.
  5. Click Install new module.
  6. Click Browse, select the .zip file on your local computer, and then click Install. Drupal installs the module.
  7. 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:

  1. Log in to your Drupal site as the administrator.
  2. On the top menu bar, click Manage, and then click Configuration.
  3. Under SYSTEM, click Matomo Analytics. The Matomo Analytics configuration page appears.
  4. Under GENERAL SETTINGS, in the Matomo site ID text box, type the Matomo ID number for your site.
    To obtain the Matomo ID number for your site, follow these steps:
    1. Log in to Matomo.
    2. On the top right of the page, click the Administration ( Matomo - Administration settings icon ) icon.
    3. In the left sidebar, click Websites, and then click Manage.
    4. Under Manage Measurables, locate your site and its ID number.
  5. 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.
  6. 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.
  7. In the Tracking scope section, you can configure additional settings to customize your site's tracking behavior.
  8. 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:

  1. Log in to your Matomo account as the administrator:
    • On the top right of the page, click the Administration ( Matomo - Administration settings icon ) 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 <!—Matomo—> tag and the ending <!—End Matomo Code—> tag.
  2. Using SSH or the cPanel File Manager, navigate to the Drupal theme directory.

    This location varies based on:

    • Where you installed Drupal.
    • Which version of Drupal you are running.

    If you are unsure, check the Drupal documentation.

  3. Use your preferred text editor to open the page template file for the theme.

    This file varies based on:

    • Which theme you are using.
    • Which version of Drupal you are running.

    If you are unsure, check the Drupal documentation.

  4. Paste the tracking code snippet that you obtained in step 1.
  5. 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.

More Information

For more information about Matomo, please visit https://matomo.org.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.