# Matomo Destination

## Destination Info

* Accepts [Page](/docs/segment/connections/spec/page), [Track](/docs/segment/connections/spec/track) calls.
* In Device-mode, refer to it as **Piwik** in the [Integrations object.](/docs/segment/guides/filtering-data/#filtering-with-the-integrations-object)

### Components

* [Browser](https://github.com/segment-integrations/analytics.js-integration-piwik)

## Connection Modes

[Learn more about connection modes.](/docs/segment/connections/destinations/#connection-modes)

### Device-Mode

* web: yes
* mobile: no
* server: no

### Cloud-Mode

* web: no
* mobile: no
* server: no

[Matomo](https://matomo.org/), formerly Piwik, is the leading open source web analytics platform that gives you valuable insights into your website's visitors, your marketing campaigns and much more, so you can optimize your strategy and online experience of your visitors.

Segment's Matomo destination code is open-source and can be viewed on GitHub:

* [Javascript](https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/piwik/lib/index.js).

## Getting started

1. From the Segment web app, click **Catalog**.
2. Search for "Matomo" in the Catalog, select it, and choose which of your sources to connect the destination to. Note the source must be sending events using the Segment JavaScript library Analytics.js.
3. In the destination settings, enter your Site ID. You can find your Site ID in your Matomo snippet.
4. In the destination settings, enter your Server URL. You can find your Server URL in your snippet. Segment automatically appends /matomo.php to the URL.
5. When you enable Matomo in your Segment settings, Segment's CDN is updated within 45 minutes. Once that happens, Segment asynchronously loads `matomo.js` on your page whenever it is loaded. This means you should remove Matomo's snippet from your page.

## Page

If you're not familiar with the Segment Specs, take a look to understand what the [Page method](/docs/segment/connections/spec/page/) does. An example call would look like:

```js
analytics.page();
```

The Page method triggers a call to Matomo's `trackPageView` method.

## Identify

If you're not familiar with the Segment Specs, take a look to understand what the [Identify method](/docs/segment/connections/spec/identify/) does. An example call would look like:

```js
analytics.identify('97980cfea0068');
```

The Identify method triggers a call to Matomo's `setUserId` method and will send the `userId` to Matomo.

## Track

If you're not familiar with the Segment Specs, take a look to understand what the [Track method](/docs/segment/connections/spec/track/) does. An example call would look like:

```js
analytics.track('Logged In');
```

Segement records a Matomo event whenever you make a `track` call.

In the example, these event attributes are sent to Matomo:

| **Event Category** | All       |
| ------------------ | --------- |
| **Event Action**   | Logged In |

See the following Track example, this time with all the available Matomo event parameters:

```js
analytics.track('Created Account', {
  category: 'Account',
  label: 'Premium',
  value: 30
})
```

That call creates a Matomo Event with these attributes:

| **Event Category** | Account   |
| ------------------ | --------- |
| **Event Action**   | Logged In |
| **Event Name**     | Premium   |
| **Event Value**    | 30        |

For **Event Value**, you can name the event property `value` or `revenue`. Segment looks for `value` first, then fall back to `revenue`.

## Best practices

Matomo lets you set [custom variables](http://matomo.org/docs/custom-variables/) with your pageviews and events. With Segment, you can set page-scoped custom variables with any Track call you make with analytics.js.

Since these custom variables must be mapped to an index you define, which can change from call to call, the only way that Segment can support these custom variables with full flexibility is to allow you to pass your map in the `context.Matomo.customVars` dictionary of each call.

To take advantage of this feature, your Track calls should look like this:

> \[!NOTE]
>
> The destination's name is still "piwik" in the JSON for these calls.

```js
analytics.track('event', {
  property: 'property'
}, { integrations: {
  Piwik: {
    customVars: {
      1: ["<variableName>", "<variableValue>"],
      2: ['SubscriptionId', '1234'],
      3: ['PlanName', 'ENTERPRISE']
      }
    }
  }
})
```

### Goals

If you want to flag specific events as Matomo Goals, you can do so by mapping those events in your Segment Source Destinations page under Matomo Settings.

Fill in the event on the left and the Goal ID from Matomo on the right. Then every time the event happens Segment fires Matomo's `trackGoal` method.

## Settings

Segment lets you change these destination settings from the Segment app without having to touch any code.

| Field                 | Description                                                                                                                                                    | Required | Type     |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | -------- |
| Custom Variable Limit | If you have manually changed your Matomo custom variable limit, please enter your new value here. The Matomo default is 5.                                     | No       | number   |
| Goals                 | Matomo only allows for goal ID's, when you \`track('event')\` we need to map \`event\` to a goal ID, enter event names on the left and goal ID's on the right. | No       | text-map |
| Site ID               | You can find your Site ID in your Matomo snippet.                                                                                                              | Yes      | string   |
| Server URL            | You can find your Server URL in your snippet, we will append \`/piwik.php\` to the URL automatically.                                                          | Yes      | string   |
