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 5 replies, has 2 voices.

Last updated by Bobby 1 week, 2 days ago.

Assigned support staff: Bobby.

Author Posts
August 27, 2019 at 10:22 pm #4469961

jacobC-6

Hi team,

This is a clients site:
hidden link (main site)

This is running WPML. The Dutch version runs under: hidden link

Google Analytics is tracking all requests for example
/about-us (English)
/over-ons (Dutch)
Under the same domain currently.

I cannot anywhere find any suggestions for tracking with WPML, across different domains.

Can you suggest any code to separate out depending on the domain?

Thanks
Jacob

August 28, 2019 at 7:01 am #4471513

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

in order to achieve this some custom work will be required, please review the following thread and let me know your results

=> https://wpml.org/forums/topic/how-to-add-the-google-analytics-for-2-languages-domains/#post-891674

September 2, 2019 at 9:02 pm #4499969

jacobC-6

Hi Bobby,

Thanks for the reply.

I tried this, however, It did not work. When using this code, the NL and UK languages track in the UK domain in GA, and then just the NL in the NL domain in GA.

So the .co.uk domain in GA is showing /about and /over-ons for example
The .nl domain in GA is showing just /over-ons

Thanks

September 3, 2019 at 12:29 pm #4504433

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

unfortunately we are limited when it comes to custom work as it is not supported within the forum but i could take a look at your code and see if everything is setup correctly

if possible please share it with me (you can remove the GA sensitive information before posting)

September 9, 2019 at 7:47 pm #4539979

jacobC-6

Hey Bobby,

Thanks. I have tried the code suggested in the post you linked, unedited, but requests are still tracked incorrectly. Is there any supported/officially suggested way to get this working?

This is my code currently which has the problems as described (UK+NL sent to first tracking code, just NL sent to second)

The GA account has two properties, 1 is the UK domain, 2 is the NL domain

<?php if(ICL_LANGUAGE_CODE=='en'){?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="<em><u>hidden link</u></em>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-127153154-3');
</script>

<?php } elseif(ICL_LANGUAGE_CODE=='nl'){?>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="<em><u>hidden link</u></em>"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-123xxxx-2');
</script>

<?php } ?>

Thanks!
Jacob

September 10, 2019 at 8:03 am #4542729

Bobby
Supporter

Languages: English (English )

Timezone: America/Los_Angeles (GMT-07:00)

Hi There,

there is no official code for this , as it is not a feature provided by WPML.

the code is a simple if elseif statement which uses the WPML Hooks ICL_LANGUAGE_CODE to target each language and then run the specific script

as this is custom work we are limited to the support we can provide

do you by any chance have another script GA provides you with? the original code is using a different looking script, this could be the issue