Background of the issue:
My website is already set up with GA4, and I'm able to see traffic data. However, there's no traffic data showing for the translation site. For instance, there's no traffic for this URL: hidden link. I need to know if I need to configure GA4 within WPML to track traffic on all translated pages and how to set this up.
Symptoms:
No traffic data showing for the translation site.
Questions:
Do I need to configure GA4 within WPML to track traffic on all translated pages?
How can I set up GA4 to track traffic on all translated pages?
Thank you for contacting WPML Support, I will gladly help you.
Can you please share WPML support debug information from your site?
* To provide the debug information:
- Login to your site and go to WPML -> Support, click on the “debug information” link at the bottom of the page.
- Once on the “debug information” page, select the entire text box content and copy it.
- Go back to our support forum, find the debug information box, and paste it.
So our GA tracking is done through Google Tag manager. If you go to the home page of our website and view the source code, and search for 'GTM-5WPKNFG' you will see the tag is there.
If however, you go to one of our Chinese pages, example URL being:
hidden link
And view the source code, you cannot find the GTM-5WPKNFG when doing a search. So it is not being loaded by WPML 🙁
I would rather not have to install another plugin just to get the Tag to load on WPML pages, so instead do you have a code snippet I could add which specifically hooks into WPML URLs? I ask as I have WPCodeBox on the site which is what I use to manage all my custom code snippets, so I would rather store this in there if possible.
I look forward to hearing back from you - thanks for your help
We will do our best to point you in the right direction, but please note that custom coding is beyond the scope of this support forum, we recommend that you check our contractors.
That being said, you could try the following code and check if the issue persits:
function insert_gtm_code() {
// Replace this with your actual GTM container ID
$gtm_container_id = 'GTM-5WPKNFG';
// Define the GTM code snippet
$gtm_code = "
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'<em><u>hidden link</u></em>);
})(window,document,'script','dataLayer','{$gtm_container_id}');</script>
<!-- End Google Tag Manager -->
";
// Only output GTM code if it's not already present
if ( ! strpos( wp_get_http_referer(), $gtm_container_id ) ) {
echo $gtm_code;
}
}
add_action('wp_head', 'insert_gtm_code', 1);
* Please ensure you have a full backup of your website before making any changes to your website.
Thank you for understanding and I hope you find this information helpful.
Let me know if you have any more questions.
Kind regards,
Marsel
The topic ‘[Closed] How to setup GA4 on WPML?’ is closed to new replies.