This thread is resolved. Here is a description of the problem and solution.
Problem:
The client is trying to track data for both the primary English domain and the French domain separately in Google Analytics GA4, using a different domain per language in WPML settings.
Solution:
We recommend inserting the Google Analytics code into the site using a custom function with a filter hook to check the current language. Here's a step-by-step guide:
- Add the following code to your theme's
functions.php
file:
add_action( 'wp_head', function(){ $current_language = apply_filters( 'wpml_current_language', null ); ?> <?php if( $current_language == 'fr'){?> <!-- GA code for FR language here --> <?php } elseif( $current_language == 'en'){?> <!-- GA code for EN language here --> <?php } ?> <?php });
- Refer to the documentation for more information on how to get the current language with WPML.
- Check out a similar example in another support ticket.
If this solution doesn't look relevant to your situation, please open a new support ticket and we will be happy to assist you further.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
This topic contains 1 reply, has 2 voices.
Last updated by 9 months, 3 weeks ago.
Assisted by: Long Nguyen.