简体   繁体   中英

Javascript, replace a string with a variable value in aspx page for Google Analytics

How do I replace the 'UA-XXXXXXXX-XX' with 'UA-AAAAAAAA-AA' via script code in an ASPX page ? I can assign mGoogle_Id " UA-AAAAAAAA-AA ' from my session variable and that works. But I don't know how to use the variable mGoogleID in the _gaq.push(['_setAccount', 'UA-XXXXXXXX-XX']); line. You would think that just putting the variable mGoogleId would work, but it does not.

    var mGoogleId='<%=Session("Google_Id")%>';

    var _gaq = _gaq || [];

    _gaq.push(['_setAccount', 'UA-XXXXXXXX-XX']);

    _gaq.push(['_setAccount', mGoogleId]); ***************** This Does Not Work *****

    _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);
    })();

您想将mGoogleId推送到您的数组吗?

_gaq.push(['_setAccount', mGoogleId]);

要将变量( mGoogleId )推入数组( _gaq ),请使用以下命令:

_gaq.push(['_setAccount', mGoogleId]);

您已经在那里:

_gaq.push(['_setAccount', '<%=Session("Google_Id")%>']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM