# Integrating Matomo Analytics with BookStack

### Overview

Once Matomo is installed, you must link it to BookStack to begin capturing visitor data, page views, and search trends. This is done by injecting a small JavaScript snippet into the BookStack header.

### 1. Retrieve Tracking Code from Matomo

1. Log in to your **Matomo** dashboard (e.g., http://192.168.0.152:8484).
2. Click the **Gear Icon** (Administration) in the top right.
3. On the left sidebar, navigate to **Websites &gt; Tracking Code**.
4. Ensure the correct website (e.g., "BookStack") is selected in the dropdown.
5. In the **JavaScript Tracking Code** section, copy the entire block of code.

### 2. Apply Code to BookStack

1. Open your **BookStack** instance and log in as an **Administrator**.
2. Go to **Settings** (Gear icon in top navigation).
3. Select **Customization** from the left-hand menu.
4. Find the section labeled **Custom HTML Head Content**.
5. Paste your copied Matomo script directly into the text area.
6. Scroll to the bottom and click **Save Settings**.

```
<!-- Matomo Tracking Script Example -->
<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//YOUR_SERVER_IP:8484/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
```

### 3. Verification

- Open your BookStack homepage in a new tab.
- Navigate to the **Dashboard** in Matomo.
- Check the **Visits in Real-time** widget; your activity should appear within seconds.

*Note: If you use an ad-blocker, you may need to disable it for your local domain to see your own tracking data.*