Check 30.01 · Multilingual tracking and maintenance

Segment traffic by language and country URL

Add a language and market dimension derived from the URL to GA4 or Matomo, then read each site version's traffic by visitor country and by channel.

Priority
Important
Difficulty
Intermediate
Estimated time
2 to 4 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

Segmenting traffic by language and country URL means being able to answer "how many visits does the German version get, and where do they come from?" without hacking together a filter every time. The method: derive the language and market of each page view from the URL, send them to the analytics tool as dimensions, then cross them with the visitor's country and the acquisition channel. Once the task is done, every report can be broken down by site version in one click.

Why it matters

Analytics tools know nothing about your site's structure. GA4 does offer a "Language" dimension, but it describes the language of the visitor's browser or device, not the site version they are reading. The "Country" dimension describes where the activity comes from, not the market the page targets. A French-speaking expat in Germany reading the French version shows up under "Germany" and under "German" or "French" depending on their browser: neither dimension says they read /fr/.

Without a dedicated dimension, every analysis by language goes through a page path filter, rebuilt by hand, different from one person to the next and impossible to apply cleanly to acquisition or conversion reports. Typical mistakes set in: comparing versions with countries, or counting the traffic of the Swiss German version under "Germany".

Segmentation separates three notions that must never be confused:

Notion What it describes Source
Site version The language and market of the page viewed (/de-ch/ = German, Switzerland) The URL, through your dimension
Visitor country Where the person is The tool's "Country" dimension
Browser language The device's language setting The tool's "Language" dimension

It is the foundation of every other task in this topic: conversions by market, business comparison, detection of underexploited markets.

What it improves

  • Reading performance by market Traffic, engagement and channels for each version, with no manual filter.
  • Spotting inconsistencies A German version viewed mostly from France often points to a hreflang or language selector problem.
  • Reliable comparisons Everyone reads the same definition of "German version".
  • Translation decisions The data feeds the identification of underexploited markets (opens in a new tab).
  • Rankings and AI visibility No direct effect; this is a management tool.

How to check

In GA4, open Reports > Engagement > Pages and screens, then look in the primary dimension selector for a dimension that gives the site version ("Site language", "Content group" or equivalent). Tracking is compliant if:

  1. The dimension exists and every page view carries a value (fr, de, de-ch…), with less than 1% of empty or "(not set)" values over the last seven days.
  2. The sum of views by version equals the report total.
  3. The same breakdown is available in Acquisition > Traffic acquisition, through the "+" button that adds a secondary dimension.

Quick real-time check: open one page of each version, then Reports > Realtime, and check that the expected value appears. In Google Tag Manager, Preview mode shows the variable's value on each page.

How to implement

Before you start

Write down the mapping table between your URLs and your versions. It serves as the reference for every configuration that follows.

URL pattern Site language Market Note
/fr/ fr FR French version, main market
/fr-be/ fr BE Belgian variant
/de/ de DE Germany and Austria
/de-ch/ de CH Prices in Swiss francs
/en/ en INT International English
/ (root) x-default INT Language selection page

For an architecture with country-code domains (example.de, example.it) or subdomains (de.example.com), the mapping is based on the hostname, not the path.

Two decisions to make now:

  • A single analytics property for all versions. One property per language rules out totals and comparisons. With several domains, set up cross-domain tracking (see set up cross-domain tracking if needed (opens in a new tab)).
  • Two dimensions rather than one: site_language (language) and site_market (market). A single combined dimension (de-ch) is enough if you have no regional variants.

What the URL structure changes for measurement

The structure chosen in choose subdirectories, subdomains or country-code domains (opens in a new tab) sets the measurement workload. Subdirectories are the simplest: everything is segmented by path. Each additional host adds a property and a risk of broken sessions.

Tool Subdirectories (example.com/de/) Subdomains (de.example.com) Country-code domains (example.de)
Search Console One Domain property for the total, plus one URL-prefix property per folder (https://example.com/de/) The Domain property covers all subdomains; one URL-prefix property per subdomain (https://de.example.com/) One property per domain, with no shared total: consolidate in a spreadsheet
GA4 One data stream; version read from the path One stream; the Google tag's automatic cookie covers subdomains, and Google also recommends listing them in "Configure your domains" One stream plus cross-domain measurement, otherwise every domain change creates a new user and a new session
Matomo One site; segments or a dimension on the URL One site; setCookieDomain and setDomains on *.example.com One site; setDomains and enableCrossDomainLinking, with each domain added as an alias URL
Version dimension Page path Hostname Hostname

In GA4, cross-domain measurement is set up in Admin > Data streams > [web stream] > Configure tag settings > Configure your domains (see set up cross-domain tracking if needed (opens in a new tab)).

With Google Tag Manager and GA4

This is the most robust method: it reads the URL and requires no change to the site. It also works on JavaScript sites that change page without reloading, because the variable is recalculated on every page view.

  1. In Tag Manager, go to Variables > User-Defined Variables > New, type "RegEx Table", input variable {{Page Path}}.
  2. Add one row per pattern, from the most specific to the most general. For each row, the pattern (left) and the output (right):
^/fr-be(/.*)?$                fr
^/de-ch(/.*)?$                de
^/(fr|de|it|es|en)(/.*)?$     $1
  1. In the advanced settings, uncheck "Full matches only", check "Enable capture groups and replace functionality", and set x-default as the default value. Name the variable Site language.
  2. Create a Market variable the same way (outputs FR, BE, DE, CH, INT). For country-code domains, use a "Lookup Table" variable on {{Page Hostname}}.
  3. Open the GA4 Google tag and, under "Shared event settings", add two parameters sent with every event: site_language = {{Site language}} and site_market = {{Market}}.
  4. Test in Preview mode, then publish the container.
  5. In GA4, go to Admin > Custom definitions > Create custom dimension: name "Site language", scope "Event", event parameter site_language. Repeat for "Market".

Good to know: a custom dimension only applies to data received after it was created; it is not retroactive. For historical data, use a page path filter (see below). The content_group parameter, which GA4 shows without any declaration in the "Content group" dimension, is an alternative if you do not already use it for page types.

With gtag.js, without Tag Manager

If GA4 is installed with the gtag.js code, set the parameters before the config command, in the template shared by every page. The script below reads the URL, which saves you from touching each language template:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}

  var match = location.pathname.match(/^\/(fr-be|de-ch|fr|de|it|es|en)(\/|$)/);
  var siteLanguage = match ? match[1].split('-')[0] : 'x-default';
  var markets = {'fr': 'FR', 'fr-be': 'BE', 'de': 'DE', 'de-ch': 'CH', 'it': 'IT', 'es': 'ES', 'en': 'INT'};
  var siteMarket = match ? markets[match[1]] : 'INT';

  gtag('js', new Date());
  gtag('set', {'site_language': siteLanguage, 'site_market': siteMarket});
  gtag('config', 'G-XXXXXXX');
</script>

Then declare the two custom dimensions in GA4 as in step 7 above.

With Matomo

  1. In Matomo's administration, in the site's Custom Dimensions section: create two dimensions with the "Action" scope, "Site language" and "Market". Note their IDs.
  2. In the tracking code, before trackPageView:
var _paq = window._paq = window._paq || [];
var match = location.pathname.match(/^\/(fr-be|de-ch|fr|de|it|es|en)(\/|$)/);
_paq.push(['setCustomDimension', 1, match ? match[1].split('-')[0] : 'x-default']);
_paq.push(['setCustomDimension', 2, match ? match[1] : 'root']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);

Without a dimension, Matomo segments do most of the job: segment editor, condition "Page URL" contains /de/. They also apply to past data when real-time processing of segments is enabled. The visitor's country depends on the configured geolocation database (GeoLite2 or DB-IP).

WordPress

Versions WordPress 6.4 and later, with Polylang or WPML.

The Tag Manager method works as is if languages are in subdirectories. If the URL is not enough (language by domain, ?lang= parameter), push the current language into the data layer from the child theme, in functions.php, before the container:

add_action('wp_head', function (): void {
    $language = function_exists('pll_current_language')
        ? pll_current_language('slug')
        : apply_filters('wpml_current_language', null);

    if (! $language) {
        return;
    }

    printf(
        '<script>window.dataLayer = window.dataLayer || []; window.dataLayer.push({"site_language": %s});</script>',
        wp_json_encode($language)
    );
}, 1);

In Tag Manager, read it with a "Data Layer Variable" named site_language.

Shopify

Versions Shopify with Shopify Markets, November 2026 interface.

Multilingual Shopify stores serve languages under subfolders (/de, /fr-ch) or domains per market. In a custom pixel (Settings > Customer events > Add custom pixel), the path of each page viewed is available in the event context:

analytics.subscribe('page_viewed', (event) => {
  const path = event.context.document.location.pathname;
  const match = path.match(/^\/([a-z]{2}(-[a-z]{2})?)(\/|$)/);
  const siteLanguage = match ? match[1] : 'default';
  // Send siteLanguage as a parameter of your analytics tool's page_view event.
});

If you use the Google & YouTube app for GA4, the simplest method remains a filter or a group on the page path in GA4, since the default language has no prefix.

Laravel

Versions Laravel 11 to 13.

When the language is already resolved by a middleware, expose it in the main layout (resources/views/layouts/app.blade.php), before the Tag Manager code:

<script>
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
        site_language: @json(app()->getLocale()),
        site_market: @json(config('markets.' . request()->segment(1), 'INT')),
    });
</script>

The config/markets.php file holds the mapping table ('de-ch' => 'CH').

Next.js

Versions Next.js 15 and 16 (App Router).

With a [lang] segment in the URL, there is nothing to code: Tag Manager's "RegEx Table" variable on {{Page Path}} is recalculated on every client-side page change, provided page views are triggered by browser history (the "Page changes based on browser history events" option of GA4 enhanced measurement, on by default). Check in Preview mode by navigating from one language to another without reloading.

Reading the data

Once the dimensions are in place:

  1. Traffic by version: Reports > Engagement > Pages and screens, primary dimension "Site language".
  2. Version × visitor country: Explore > Free form, rows "Site language", columns "Country", values "Sessions" and "Active users".
  3. Version × channel: Acquisition > Traffic acquisition, secondary dimension "Site language".
  4. History before the dimension: a comparison with the condition "Page path and screen class" matches regex ^/de(/|$).

Monitoring matrix to fill in every month, fictional example:

Version Sessions Share from the target market Top country outside the market Main channel
/fr/ 41,200 78% (France) Belgium 9% Organic Search
/de/ 12,800 84% (Germany and Austria) Switzerland 7% Organic Search
/de-ch/ 1,900 41% (Switzerland) Germany 52% Organic Search

The last row is a warning sign: the Swiss variant gets mostly German visitors. Check the hreflang annotations (see test same-language variants for different countries (opens in a new tab)).

Common mistakes

  • Taking GA4's "Language" dimension for the site version: it describes the visitor's browser.
  • Confusing visitor country and market: the traffic of /de/ cannot be read through the "Country = Germany" filter.
  • One GA4 property per language: no more totals, no more comparisons, and journeys that break when the visitor switches language.
  • Forgetting the root page and URLs without a prefix: they fall into "(not set)" and skew the breakdown.
  • Putting the general pattern before the specific one in the RegEx Table: /de-ch/ is then classified as de.
  • Expecting historical data from a custom dimension: it only fills in data received after it was created.
  • Ignoring consent: in markets where refusal is common, measured volumes underestimate reality unevenly from one country to another.

Frequently asked questions

Why not use GA4's Language dimension to track each site version?

GA4's Language dimension gives the language of the visitor's browser or device, not the language of the page they are reading. An English speaker reading the French version shows up as English. To track each site version, create a custom dimension derived from the URL, for example site_language, then cross it with the browser language to spot visitors who are not reading the version in their own language.

Do you need one GA4 property per language or per country?

No, a single GA4 property for all versions is better. It allows totals, comparisons between markets and tracking of visitors who switch language during a visit. The split is made through a custom dimension derived from the URL or the hostname. With country-code domains, set up cross-domain tracking so that sessions are not broken between domains.

Does the custom dimension apply to past data?

No. A GA4 custom dimension only applies to events received after it was created, and only if the matching parameter is sent. To analyze historical data by version, use a comparison or a filter on the page path with a regular expression, for example ^/de(/|$), in reports or in an exploration. Both methods give the same results as long as the mapping table is identical.

How do you segment a site on country-code domains such as example.de and example.it?

With country-code domains, the site version is read from the hostname, not the path. In Tag Manager, create a Lookup Table variable on Page Hostname that returns the language and market of each domain, then send them to GA4 as parameters. In reports, the Hostname dimension also gives an initial breakdown with no configuration.

Updated on

Topic checklist (PDF)

And now?

In the “Multilingual tracking and maintenance” topic

  1. Segment traffic by language and country URL
  2. Segment conversions and revenue by market
  3. Track rankings by search engine and country
  4. Track impressions and CTR by version
  5. Track indexing by language
  6. Track backlinks by market
  7. Track AI mentions and citations by language
  8. Track AI traffic and share of voice by market
  9. Compare business performance
  10. Identify underexploited markets and weak translations
  11. Detect missing or outdated translations
  12. Detect changes to the source content
  13. Notify the people responsible for translations
  14. Review AI translations
  15. Automate hreflang and canonical tests
  16. Detect the actual language and untranslated strings
  17. Test cross-language links
  18. Synchronize facts and specifications
  19. Synchronize stock if applicable
  20. Manage market-specific prices
  21. Test all versions after each deployment
  22. Define editorial sign-off for each language
  23. Integrate multilingual tests into CI/CD