Background of the issue:
I am trying to set up Google Analytics to track multiple languages on a site under development using WPML. I found a related question on the WPML forums.
Symptoms:
The answer to the question on the WPML forums is not visible.
Questions:
Can you provide the information from the WPML forum topic on setting up Google Analytics to track different languages?
Welcome to the WPML support forum. Thanks for contacting us.
While waiting for one of my colleagues to help with this ticket, and based on what you've described, allow me to walk you through some initial debugging steps.
1. Same Google Analytic for all languages
If you're using language folders in your URL structure (e.g., domain.com/en/, domain.com/es/), you can track all website traffic under a single Google Analytics property. Google Analytics allows you to filter or create views based on subdirectories. For example, you can create a filtered view to track only Spanish visitors by targeting /es/.
Refer to the official Analytics documentation on how to set up views.
2. Different Google Analytics accounts
If you prefer to use a separate tracking ID for each language, you can implement a custom solution using the code below:
add_action( 'wp_head', function(){
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
if ( $my_current_lang == 'fr' ){ ?>
<!-- Tracking code for FR language here -->
<?php } elseif ( $my_current_lang == 'en' ){ ?>
<!-- Tracking code for EN language here -->
<?php }
});
If that doesn't answer you question, could you please provide more details about what you're trying to achieve?
Nico
The topic ‘[Closed] Tracking multiple languages with Google Analytics’ is closed to new replies.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.