URL Language Matcher
GTM variable for multilingual websites: Extracts localization data from URLs and converts it to ISO 639-1 language codes.
A light, flexible, and reliable Google Tag Manager variable template designed to extract and standardize ISO 639-1 language codes from URLs.
Whether your website uses language codes in the URL path (/de/ or /de-de/), subdomain (de.example.com), top-level domain (example.de), or query parameters (?lang=de), this template seamlessly normalizes inputs into consistent 2-letter language codes for your analytics and tracking tags.
Key Features
- Flexible Pattern Matching: Accepts standard 2-letter ISO codes (
de,en) as well as BCP 47 locale codes (de-DE,en-US,de_CH). - Multi-Source Detection:** Extract language values from 4 different URL sources:
- Path: Parses early path segments (e.g., /en-us/about).
- Subdomain: Evaluates first-level subdomains (e.g., fr.domain.com).
- TLD: Evaluates country-code top-level domains (e.g., domain.de).
- Query Parameter: Reads values from specific URL parameters (e.g., ?lang=es).
- Clean 2-Letter Output: Returns strict 2-letter ISO 639-1 language codes (de, en, fr) for unified data layer and analytics reporting.
- Customizable Fallback: Define a default language code when no URL pattern matches.
Configuration Guide
Detection Method
Select where the template should look for language patterns in the current URL:
Path(Default)SubdomainTLDQuery
Parameter Name
(Only applicable when Detection Method is set to Query)
Specify the key of the URL parameter to inspect (e.g., lang, locale, hl).
Language Mapping Table
Map incoming URL patterns to your desired 2-letter language code outputs.
| Pattern | Language Code | Matching Example |
|---|---|---|
en-us | en | Matches /en-us/ path, en-us. subdomain, or ?lang=en-us |
de-de | de | Matches /de-de/ path, de-de. subdomain, or ?lang=de-de |
fr | fr | Matches /fr/ path, fr. subdomain, .fr TLD, or ?lang=fr |
Default Language Code
Set a fallback 2-letter ISO 639-1 code (e.g., en) returned whenever no rule in the mapping table matches the URL.