---
title: "How to Install the Drupal Matomo Module"
description: "The Matomo Analytics Drupal module connects your Drupal site to your Matomo Analytics application and eases the process of modifying the tracking code to better suit your needs without advanced..."
url: https://www.inmotionhosting.com/support/edu/drupal/matomo-drupal-module/
date: 2020-12-17
modified: 2023-09-13
author: "InMotion Hosting Contributor"
categories: ["Drupal"]
type: post
lang: en
---

# How to Install the Drupal Matomo Module

The [**Matomo Analytics Drupal module**](https://www.inmotionhosting.com/support/website/analytics/install-matomo-analytics/) connects your Drupal site to your [Matomo Analytics application](https://www.inmotionhosting.com/support/website/analytics/install-matomo-analytics/) and eases the process of modifying the tracking code to better suit your needs without advanced programming experience. The Drupal Matomo module tracking options include:

- Specifying Drupal [blog entries](https://www.inmotionhosting.com/support/edu/drupal/create-entry/) to track
- Ignoring logged in users while working on web design and development tasks
- Tracking clicks for download links
- Respecting [Do-Not-Track (DNT)](https://www.inmotionhosting.com/support/security/why-security-is-important-for-small-businesses/) web browser settings
- And much more

Using the right on-site [web analytics software](https://www.inmotionhosting.com/support/website/analytics/choose-the-best-analytics-tool/) for your needs will prove to be a valuable tool for better understanding how online users interact with your website. This information can assist you with many on-going tasks to refine your branding such as sales funneling initiatives and content marketing ideas.

Below we'll cover how to:

- [Install the Matomo Drupal Integration Module](#install)
- [Configure the Matomo Drupal Module](#config) wp:list /wp:list
  - [General Settings](#general)
  - [Tracking Scope](#track)
  - [Fix the Validation Error](#valid)
  - [Fix the ModSecurity 406 Error](#modsec)
- [Add Additional Matomo Features in Drupal](#add)

Ignite your online presence with cutting-edge [Drupal Website Hosting](https://www.inmotionhosting.com/drupal-hosting). Elevate speed, security, and reliability for a seamless website experience.

## Install the Matomo Drupal Integration Module

1. [Log into Drupal](https://www.inmotionhosting.com/support/edu/drupal/how-to-log-into-the-drupal-admin-dashboard/).
2. Install the Drupal module using the [**Matomo Analytics** download link](https://www.drupal.org/project/matomo).
3. Click **Enable newly added modules**.
4. Under *Statistics*, check the box beside **Matomo Analytics**.
5. At the bottom, select **Install**.

## Configure the Matomo Drupal Module

Below we'll cover the two main module sections - General Settings and Tracking Scope.

### General Settings

These settings create the basic Matomo tracking code to log user interaction.

[![Matomo Drupal module general settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-general-settings-300x114.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-general-settings.png)

1. Click **Configuration** at the top.
2. Under *System*, click **Matomo Analytics**.
3. Type the [Matomo site ID number](https://www.inmotionhosting.com/support/website/analytics/wheres-my-matomo-analytics-site-id/) assigned from your Matomo application.
4. Add your **Matomo HTTP URL**. Use “HTTPS” if your Matomo application forces an SSL connection by default. If not, we recommend [forcing an SSL connection in Matomo](https://www.inmotionhosting.com/support/website/analytics/force-https-matomo-analytics/).
5. Add the **Matomo HTTPS URL**.To accept default tracking code settings, skip to the bottom of the module settings and **Save configuration**. We recommend you continue below.

### Tracking Scope

Here you can configure *how* user behavior is collected.

The default **Domains** selection is “*A single domain*.” If you have subdomains under your Drupal directory, select “*One domain with multiple subdomains*."

[![Matomo Drupal module domains settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-domains.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-domains.png)

The **Pages** tab tracks all pages except the listed ones by default. Alternatively, you can select *The listed pages only* to track specific pages.

[![Matomo Drupal module pages settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-pages-1024x240.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-pages.png)

**Roles** in Drupal aren't tracked by default, which ensures your analytics reports aren't affected by administrative tasks. Select a checkbox to *add tracking for specific roles*. Or select *“Add to every role except the selected ones”* and select user roles to ignore.

[![Matomo Drupal module roles settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-roles-1024x172.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-roles.png)

**Users** are tracked by default but can opt-in or out if permissions are set. **Track User ID** to better track users across multiple devices.

[![Matomo Drupal module users settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-users-1024x165.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-users.png)

The **Page titles hierarchy** feature affects your user experience (UX) in Matomo. The preset option is to *Hide home page from hierarchy*. You can deselect this if you wish. You can also *Show page titles as hierarchy like *[breadcrumbs](https://www.inmotionhosting.com/blog/what-are-website-breadcrumbs/) to show the page [SEO title tags](https://www.inmotionhosting.com/support/website/seo/what-are-meta-tags/).

[![Matomo Drupal module page titles hierarchy settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-page-titles-1024x217.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-page-titles.png)

**Links and downloads** for `mailto` hyperlinks and most commonly used file extensions are tracked by default - docx, mp3, mp4, png, etc. You can add extensions to this text field with regular expressions.

[![Matomo Drupal module links settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-links-1024x266.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-links.png)

**Messages** for statuses, warnings, and errors can be enabled here.

[![Matomo Drupal module messages settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-messages-1024x312.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/drupal-matomo-messages.png)

**Search** queries can be tracked to better understand what users are looking for while on your site.

[![Matomo Drupal module search settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-search.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-search.png)

The Matomo module respects *Universal web tracking opt-out* (Do-Not-Track) by default in the **Privacy** tab. You can also disable cookies from being stored in [web browsers](https://www.inmotionhosting.com/support/website/check-cookies-on-a-webpage-in-web-browsers/).

[![Matomo Drupal module privacy settings](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-privacy-1024x411.png)](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/matomo-drupal-privacy.png)

Developers can create [Custom Variables](https://matomo.org/docs/custom-variables/) and [Custom JavaScript code](https://developer.matomo.org/guides/tracking-javascript-guide) for more customized analytics reporting.

Once you're done configuring your Matomo tracking code, select **Save configuration** at the bottom. At the top you should see “*The configuration options have been saved.*” If not, check out the troubleshooting sections below.

If you've configured your caching settings, you may need to [clear your Drupal cache](https://www.inmotionhosting.com/support/edu/drupal/drupal-performance-optimization/) for the tracking code to take effect immediately.

### Fix the Validation Error

If you get the following error, change the **Matomo HTTP URL **at the top to “https://”:

*The validation of "http://your-matomo.com/matomo.php" failed with an exception "cURL error 7: Failed to connect to your-matomo-site.com port 80: No route to host (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)" (HTTP code 0).*

### Fix the ModSecurity 406 Error

If you get a [406 error](https://www.inmotionhosting.com/support/website/error-numbers/406-error-not-acceptable/) at the top of the page when trying to update settings, and are on a VPS/dedicated server, you'll need to check your [web server error log](https://www.inmotionhosting.com/support/edu/cpanel/cpanel-logs-for-access-apache-email-error-ftp-mysql-whm/) (e.g. `/etc/apache2/error_log`) to figure out which [ModSecurity](https://www.inmotionhosting.com/support/security/what-is-modsecurity-and-why-is-it-important/) rule ID is blocking the request.

If you've installed OWASP ModSecurity Core Rule Set (modsec2-rules-owasp-crs) in EasyApache 4, you may need additional whitelist rules.

1. [Log into SSH](https://www.inmotionhosting.com/support/server/ssh/how-to-login-ssh/) or [WebHost Manager (WHM) Terminal](https://www.inmotionhosting.com/support/edu/whm/how-to-open-a-terminal-connection-in-whm/) as user [root](https://www.inmotionhosting.com/support/amp/obtain-root-access/).
2. Check the web server error log for the ModSec rule. For cPanel and CentOS systems:cat /var/log/apache2/error_log | grep /matomo.php
3. The ModSec error should resemble the following: ` [:error] ModSecurity: Access denied with code 406 (phase 2). ` Note the `file` path, `uri`, and `id` number for later. You can use the `line` indicator to view the actual rule within the ModSec configuration file.
4. There are two ways to resolve this 406 error: disable the rule or whitelist the action. We recommend and will continue with whitelisting the action via URI. To start, edit your ModSec whitelist file in the same directory as the rule file above. In the command below, replace the file path with the file in your error log:nano /etc/apache2/conf.d/imh-modsec/00_whitelist.conf
5. Add the following three lines at the bottom of the file, replacing the URI and rule ID to match your error log.<LocationMatch "/matomo/matomo.php"> SecRuleRemoveById 112233 </LocationMatch>
6. Test your Apache configuration:apachectl -tYou should receive `Syntax OK`.
7. Restart Apache:systemctl restart httpd Debian/Ubuntu: systemctl restart apache2
8. Try to save your tracking code settings in Drupal again.

Afterwards, you can log into Matomo Analytics to view reports.

## Add Additional Matomo Features in Drupal

There are 2 other related Drupal modules you can install for your Matomo setup.

- [Matomo Reports](https://drupal.org/project/Matomo_reports) allows you to see basic analytics within your Drupal dashboard without needing to log into Matomo
- [Matomo Noscript](https://www.drupal.org/project/piwik_noscript) tracks users with JavaScript disabled via browser extensions (e.g. uBlock Origin, AdBlock, and NoScript)
