Home›Support›English Support›[Resolved] Tracking code on our forms works on English site BUT NOT translated site
[Resolved] Tracking code on our forms works on English site BUT NOT translated site
This thread is resolved. Here is a description of the problem and solution.
Problem: The client has a tracking form that works on the English version of their website but does not track when the Spanish language is selected. The tracking code in the head tag disappears on the translated Spanish version of the site.
Solution: If you're experiencing a similar issue with tracking code not functioning correctly in all languages on your website, we recommend setting up the tracking code individually for each language. You can use the "wpml_current_language" hook provided by WPML to customize code for different languages. Here's a step-by-step guide:
I am trying to: We have a tracking form that tracks any form on our website. However, we've discovered it will not track the form when the Spanish language is selected.
We have this tracking code in the head tag, which works for the main English site. But this code disappears for the translated Spanish version of the site.
Here's the code that is in on the head tag in English:
<head> tag of the spanish pages:
<script>"use strict";var simplyconvert_hash = '5bde78b7cdb60170c883efdd3ee8cde9';!function() {var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");o.id = "_scloader", o.type = "text/javascript", o.async = !0, o.src = "//simplyconvert.com/app/embed/"+n+"/load.js";var i = document.getElementsByTagName("script")[0];i.parentNode.insertBefore(o, i);}();</script>
Link to a page where the issue can be seen: hidden link
I understand the issue you're having and will try my best to assist you in this matter.
For the tracking code to function correctly in each language on your website, it's necessary to set up the tracking code individually for every language. This approach ensures accurate and language-specific tracking.
WPML provides a useful hook named "wpml_current_language" that allows you to customize code for different languages. To understand how to effectively use this hook, you can refer to the following documentation: https://wpml.org/wpml-hook/wpml_current_language/
With this hook, you can specifically set up the tracking code for the Spanish version of your site. Here’s a sample code snippet:
This code should be added to the functions.php file of your theme.
By implementing this, you should be able to make the tracking code work appropriately for the Spanish language as well. Feel free to let me know if you need further assistance in this matter. I will be happy to assist.
Thank you for the reply. I entered the following code into my Functions.php file, but I code the error:
"Your PHP code changes were not applied due to an error on line 57 of file wp-content/themes/Avada/functions.php. Please fix and try saving again.
syntax error, unexpected token "if" "
Line 57 refers to this line:
if($my_current_lang=='es-ES')
Here's the entire code I entered into my Functions.php file:
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
if($my_current_lang=='es-ES'){
//
<script>"use strict";var simplyconvert_hash = '5bde78b7cdb60170c883efdd3ee8cde9';
!function() {var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.id = "_scloader", o.type = "text/javascript", o.async = !0, o.src = "//simplyconvert.com/app/embed/"+n+"/load.js";
var i = document.getElementsByTagName("script")[0];i.parentNode.insertBefore(o, i);
}();</script>
}
The issue with your PHP code seems to be the placement of JavaScript within the PHP "if" statement. In PHP files, you need to use "echo" to output the JavaScript code. Here's how you can modify your code in the functions.php file to fix the syntax error:
$my_current_lang = apply_filters( 'wpml_current_language', NULL );
if ($my_current_lang == 'es-ES') {
echo '<script>"use strict";var simplyconvert_hash = "5bde78b7cdb60170c883efdd3ee8cde9";
!function() {var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.id = "_scloader", o.type = "text/javascript", o.async = !0, o.src = "//simplyconvert.com/app/embed/"+n+"/load.js";
var i = document.getElementsByTagName("script")[0];i.parentNode.insertBefore(o, i);
}();</script>';
}
Please try and let me know if you need further assistance in this matter. I will be happy to help.
I placed the code you sent above, and while I get no errors, it doesn't work. Here's an image that might help.
The image titled 'Free case evaluation' shows the form on the bottom right hand side of the screen.
The image titled 'Spanish' is our Spanish version of the site, and you'll see the 'Free case evaluation' form is not being shown.
The code for this form must be in the <head> tag. And it is located there for the English page. However, when you click on Spanish, the code is no longer in the head tag area.
Does that shed any more insight into this issue? thank you again... we are really lost with this issue.