# Using Matomo with Drupal

> Track visitors on your Drupal site with Matomo analytics, using the Matomo module or by adding the tracking code to your theme.

Source: https://helpcenter.ruachost.com/apps/drupal/using-matomo-with-drupal/

**Matomo** (formerly Piwik) is an open‑source analytics platform that provides detailed visitor statistics. Integrating Matomo with Drupal allows you to track traffic, user behavior, and conversions directly from your site. On **ruachost.com**, you can connect Drupal to Matomo either by using a module or by editing your theme.

## Why Use Matomo?

- Privacy‑friendly alternative to Google Analytics.
- Provides detailed traffic reports and visitor insights.
- Helps optimize site performance and content strategy.
- Fully open‑source and self‑hosted for maximum control.

## Methods to Integrate Matomo with Drupal

### Method 1: Use the Matomo Analytics Module

1. Install Matomo on your hosting account (via **Softaculous** or manually).
2. Download the Matomo Analytics module.
3. Log in to Drupal as an administrator.
4. Go to **Extend → Install new module** and upload the `.zip` file.
5. Enable the module under **Extend → List → Statistics → Matomo Analytics**.
6. Go to **Configuration → System → Matomo Analytics**.
7. Enter:

   - **Site ID** → Found in your Matomo dashboard under *Websites → Manage*.
   - **Matomo URL** → e.g., `https://example.com/matomo`.
8. Save configuration.

✅ Matomo is now tracking your Drupal site.

### Method 2: Edit the Drupal Theme Directly

1. Log in to your Matomo account.
2. Go to **Administration → Websites → Tracking Code**.
3. Copy the full JavaScript tracking snippet.
4. On your server, navigate to your Drupal theme directory.
5. Open the `page.html.twig` or template file for your theme.
6. Paste the tracking code before the closing `</body>` tag.
7. Save changes and clear Drupal caches.

✅ Matomo will now track all pages on your site.

## Important Notes

- Modules are easier to manage but add slight overhead.
- Editing the theme is lightweight but requires re‑adding the code if you change themes.
- Always back up your site before making changes.
