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

Last updated by petrJ-8 2 years ago.

Assigned support staff: Yuri.

Author Posts
September 25, 2017 at 11:34 am

mateuszK-2

Hello,

I have two different domains: PL and DE
I am trying to put other Google Analytics code to each as it is written for example here:
https://wpml.org/forums/topic/we-need-to-use-a-different-analytics-for-more-than-two-languages/
But it doesn't work correct (I have tried in the footer and place for Google Analytics code I have in theme options)

Link to a page where the issue can be seen:
loftdecora.pl (but now it is only one for Polsih website) code because it caused error -screen shot attached)

I have tried to place following code:

if( ICL_LANGUAGES_CODE == 'pl' ) {
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','hidden link','ga');

ga('create', 'UA-62939620-1', 'auto');
ga('send', 'pageview');

</script>
</script>

} else if ( ICL_LANGUAGE_CODE == 'de' ) {
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','hidden link','ga');

ga('create', 'UA-62939620-2', 'auto');
ga('send', 'pageview');

</script>
}

Could you be so kind and help me with this issue.
I send you data to login to my site.

Regards!

September 25, 2017 at 12:43 pm #1382192

Yuri

Hi, it seems that the code you added did not run correctly because it needed to use the PHP tags since it was present in your functions.php file.

I've made a quick modification to the file so you can replace the starting part of your functions.php file from this:

<?php

to this:

<?php

function hook_google_analytics() {

	if( ICL_LANGUAGE_CODE == 'pl' ) {
    ?>
		<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','<em><u>hidden link</u></em>','ga');

		ga('create', 'UA-62939620-1', 'auto');
		ga('send', 'pageview');
		</script>

	<?php

	} else if ( ICL_LANGUAGE_CODE == 'de' ) {
	?>
		<script>
		(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		})(window,document,'script','<em><u>hidden link</u></em>','ga');

		ga('create', 'UA-62939620-2', 'auto');
		ga('send', 'pageview');
		</script>

    <?php
	}
}
add_action('wp_head', 'hook_google_analytics');

Let me know how it goes.

September 25, 2017 at 1:15 pm #1382252

mateuszK-2

It works correctly! Thank you very much for very fast response. I really appreciate your help!

Regards!

October 14, 2018 at 8:02 pm #2815816

petrJ-8

Hello Yuri,

I use you code which is great. But can you help me and with code for 3 domains?

Thank you in advance.