Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, February 18, 2015

Google Analytic tracking script

Google analytic is great way to track your website access and view of different pages.

Question is how to implement analytic in your web project?

To work with this you need Google tracking ID. I represented it as “NNNNN”. In project store it either in web.config or database. Below is script that you need to place it before the end of </body> section of webpage.

<script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'NNNNN']);
    _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>


Please leave your comments or share this script if it’s useful for you.

No comments:

Post a Comment