• 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':'http://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: http://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: http://seotrafico.com/getUrlParameters.html

    This problem has been reproduced on 2 different web servers (both running on nginx though).

    Thanks for your help!

    https://wordpress.org/plugins/google-analyticator/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Antoine Brunel

    (@antoinet)

    In response to the moderator note, the characters I mention do not appear when I post on the forum. (ASCII characters maybe or an encoding problem, for example & amp). They appear in view-source in Chrome, and in an HTML editor:

    <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':'http://www')+'.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();</script>

    Thread Starter Antoine Brunel

    (@antoinet)

    To be even more specific in my question:
    Why does the same javascript code work when introduced on a static HTML page but crash when introduced in Google Analyticator “before tracker initialization textbox”?

    Thread Starter Antoine Brunel

    (@antoinet)

    So why is Google analyticator textbox adding HTML characters?
    That is the question …

    Thread Starter Antoine Brunel

    (@antoinet)

    I’m sorry to say that I don’t see much support for this plugin.
    I think I’ll try Google Analytics for WordPress…

    [Moderator Note: No bumping, thank you.]

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘before tracking init: Wrong characters’ is closed to new replies.