before tracking init: Wrong characters
-
Hello,
In “Additional tracking code ( before tracker initialization )”, I write the following code, (from a notepad that removes all the formatting just in case):
function getUrlParameters(parameter,decode){var currLocation=window.location.search;var paramList=currLocation.split("?")[1];if(!paramList){return false;} var parameters=paramList.split("&");var returnBool=true;for(var i=0;i<parameters.length;i++){param=parameters[i].split("=");if(param[0]==parameter){return(decode)?decodeURIComponent(param[1]):param[1];returnBool=true;} else{returnBool=false;}} if(!returnBool){return false;}} var source=getUrlParameters('utm_source',true);var medium=getUrlParameters('utm_medium',true);_gaq.push(['_setCustomVar',2,'Fuente-medio',source+'-'+medium,1]);
However, what appears in the source code in a browser is different, with strange characters:
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-16677640-3']);_gaq.push(['_addDevId','i9k95']);function getUrlParameters(parameter,decode){var currLocation=window.location.search;var paramList=currLocation.split('?')[1];if(!paramList){return false;} var parameters=paramList.split('&');var returnBool=true;for(var i=0;i<parameters.length;i++){param=parameters[i].split('=');if(param[0]==parameter){return(decode)?decodeURIComponent(param[1]):param[1];returnBool=true;} else{returnBool=false;}} if(!returnBool){return false;}} var source=getUrlParameters('utm_source',true);var medium=getUrlParameters('utm_medium',true);_gaq.push(['_setCustomVar',2,'Fuente-medio',source+'-'+medium,1]);_gaq.push(['_trackPageview']);(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;ga.src=('https:'==document.location.protocol?'https://ssl':'https://www')+'.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();</script>
[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
That causes a javascript crash, you can see that here: https://seotrafico.com/
And it is not a server problem since the strange characters do not appear on a static page, and the code runs flawlessly without crashing: https://seotrafico.com/getUrlParameters.html
This problem has been reproduced on 2 different web servers (both running on nginx though).
Thanks for your help!
- The topic ‘before tracking init: Wrong characters’ is closed to new replies.