There are two methods that can be used to track individual Page URLs in a Multilingual website or in sites that have multiple language versions. Each method below is made with the assumption that your website is split into different languages using a path, for example English is
example.com/en, other languages are tracked in their own path, for example German could be tracked as
Option 1. Generate a custom page URL and track it as a Custom Dimension.
Create your Custom Dimension with an « Action » scope and take note of the ID
// first we declare the regex we want to use to search and replace later const regex = /\/en\/|\/jp\/|\/de\//gm; // then we declare the current URL of the web page var current_url = window.location.href; // we then replace the language folder using the regex, // for example /en/ will become / in the custom_url variable var custom_url = current_url.replace(regex, '/'); // this custom_url is then tracked as the Custom Dimension to Matomo, // replace X with your Custom Dimension ID _paq.push(['setCustomDimension', X, custom_url]);
You will need to ensure that you track the Canonical URL to the correct Custom Dimension of « Action » scope in your Matomo.
- You can then additionally track the language folder as another custom dimension to still have this information easily tracked in Matomo (This can be helpful to get overall statistics for each language version of your website). This can be done using regex in the Custom Dimensions « Extract Value » using for example
/(en|jp|de)as the regular expression:
We will then have two Custom Dimensions being tracked in Matomo:
A. The Canonical URL
B. The language for each pageview on your website
Option 2. Extract the URL path and track it as a Custom Dimension without the language path
This can be done by using multiple « Extract value » conditions in the Custom Dimension, for example:
This would set the value of the Custom Dimension to anything that follows the language folder. For example for the page /en/my-page, the custom dimension will become /my-page.
See our User Guide for Custom Dimensions for more information