简体   繁体   中英

Should I add the google analytics snippets in every html page in my web application?

I am trying to enable Google Analytics to my web application.

Do I need to add the "JavaScript tracking snippet" like below in my every html pages within my web application ?

Or would it be enough to add this snippet only in the landing page please ?

<!-- Google analytics code starts -->
<script>
    (function(i, s, o, g, r, a, m) {
        i['GoogleAnalyticsObject'] = r;
        i[r] = i[r] || function() {
            (i[r].q = i[r].q || []).push(arguments)
        }, i[r].l = 1 * new Date();
        a = s.createElement(o), m = s.getElementsByTagName(o)[0];
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m)
    })(window, document, 'script',
            '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', 'UA-12345678-1', 'myweb.com');
    ga('send', 'pageview');
</script>
<!-- Google analytics code ends -->

Basically Google Analytics Snippets should be showed on every page in browser. If you add you Google Analytics Snippets in header, it will appear on automatically appear on every page where you call header. If you not include header on some pages then on those pages you should add it separately.

I hope this will help you.

If you are using some kind of template engine then just put it in the default, or do as the gentleman said above and put it in the header or footer. You just need to put it in something that is ubiquitous. Like the footer. You could tell us a little more about your app and we may be able to give more specific advice.

You need to add that snippet in every page for your site. You could add some event track or something like this on specific pages, but always you will need that snippet.

You should be add the snippet in the recommended script area, before </body>

Add that snippet to whatever page you want tracked into GA, but 99.99% of the time you would want it on every page so that you have continuity in your sessions and so that referrals are maintained. But since you are in the process of adding the GA snippet to your site, why not consider adding GTM instead so that you can more easily set up page and event tracking? Basically adding GTM future-proofs your site so that you rarely have to touch your site code again.

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