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 g.j.R 3 months, 2 weeks ago.

Assigned support staff: Laura.

Author Posts
June 26, 2019 at 8:14 am

g.j.R

I am trying to:
Add a Google Analytics code to a multi language website. I have a different Tracking code for each domain name but when I enter the complete code, it's showing every Tracking code in the Google Chrome Source window.

Link to a page where the issue can be seen:
hidden link

I expected to see:
Just the Google analytics tracking code for my English page, when I'm on movexx.nl. And when I'm on movexx.com, I'd want to see the google analytics tracking code for my English domain.

Instead, I got:
All the codes showing up in the source window.

This is the code I'm using:

<!-- ANALYTICS TRACKING CODE -->
<?php
   // NL language
    if ( defined( 'ICL_LANGUAGE_CODE' ) && ‘nl’ == ICL_LANGUAGE_CODE ) {
          
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="hidden link"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-21741349-1');
</script>
           
    <?php }
    // DE language
    else if ( defined( 'ICL_LANGUAGE_CODE' ) && 'de' == ICL_LANGUAGE_CODE ) {
          
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="hidden link"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-21741349-4');
</script>
           
    <?php }
    // FR language
    else if ( defined( 'ICL_LANGUAGE_CODE' ) && ‘fr’ == ICL_LANGUAGE_CODE ) {
          
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="hidden link"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-21741349-5');
</script>
          
    <?php }
    // EN language
    else if ( defined( 'ICL_LANGUAGE_CODE' ) && 'en' == ICL_LANGUAGE_CODE ) {
          
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="hidden link"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

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

?>
<!--/ ANALYTICS TRACKING CODE -->

I have added it in WordPress backend -> Divi -> Theme Options -> Integration -> Add code to the <HEAD> of your blog.

I suppose it's not allowing the PHP to work.

June 26, 2019 at 10:39 am
June 27, 2019 at 1:27 pm #4100359

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+02:00)

Hi,

I'm sorry but the chat was closed when you left it. I reopened it as a forum ticket but the credentials were lost so I'd need them again. Could you please provide them?

June 28, 2019 at 5:57 am
June 28, 2019 at 3:10 pm #4108951

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+02:00)

Hi,

not the string is in String Translation and you should be able to translate the language code to have the right code for each language.

Let me know if this helps you or if you need further assistance.

July 1, 2019 at 7:17 am #4115969

g.j.R

Could you tell me the name of that string? Cause divi_integration_head still isn't showing up in the String Translation.

July 1, 2019 at 1:25 pm #4119377

Laura
Supporter

Languages: English (English ) Italian (Italiano ) Portuguese (Brazil) (Português )

Timezone: Europe/Rome (GMT+02:00)

Hi,

the search in String Translation is for searching in the content of the strings, not by name. Search "Google" and you'll find the string.

July 2, 2019 at 9:15 am #4125253

g.j.R

My issue is resolved now. Thank you!