It is not absolutely necessary to send the data via the data layer.
Depending on the WPML setting, you can read the language from the URL. Or from a cookie called “wp-wpml_current_language”.
To do this, you can create a variable in GTM that reads the data.
For example, custom JavaScript can be used as a variable configuration.
For example, we have the following URL structure
- /en/… => EN
- /fr/… => FR
- /… => DE (original language in WordPress, does not have its own folder on our wpml setup.)
The following JS is a GTM variable and checks if the URL path starts with one of the active WPML language codes. If yes, then it will be returned. On the other hand, the original language DE is returned.
function() {
var path = window.location.pathname;
var allowed = ['de','en','fr'];
var parts = path.split('/');
var firstFolder = parts[1];
if(!allowed.includes(firstFolder))
return 'de';
return firstFolder;
}
Maybe this will help. You may have to search around on Google to find out how to write the appropriate JS for your GTM variable and how to debug its value with the GTM preview.