Google Analytics: Tracking Not Installed though re

2019-08-15 04:56发布

问题:

Bellow is my code. I'm new to GA and I just created a random site to see if I can get things to implement properly (it's a simple Hello World). From all my knowledge and hours of reading forums, books and instructions, this should work. But I am still getting the error message "Tracking Not Installed". However, I am getting real-time data from GA; so I know it is pinging my site properly. Also, can someone look over my Custom Variables to ensure that those are implemented properly? Thank you

<html>
<head>
  <title>Testing Google Analytics Script type B</title>
  <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-15047826-4', 'patientordersets.com');
    ga('send', 'pageview');
</script>
</head>
<body>
    <h1>Hello world B</h1>
    <p id="demo">       
        <script>
        document.getElementById("demo").innerHTML=Date();
        </script>
    </p>

    <script>
        var Data1 = 'blah';
        var Data2 = 'blach';
        var Data3 = 'blanch'        
    </script>

    <script type="text/javascript">
            _gaq.push(
            ['_setAccount', 'UA-15047826-4'],
            ['_setCustomVar', 1, "Data1", Data1, 2],
            ['_setCustomVar', 1, "Data2", Data2, 2],
            ['_setCustomVar', 1, "Data3", Data3, 2],
            ['_trackPageview'],
        );
    </script>

</body>

回答1:

if you just go in the code downloaded by this script:

<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-15047826-4', 'patientordersets.com');
    ga('send', 'pageview');
</script>

you will see that it doesn't refer to a _gaq object. This is old Google code.

Please use:

<script>
    (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>

instead.



回答2:

The code you had used initially is correct and is infact the latest one based on Universal Analytics. You can see that it uses the latest library analytics.js instead of ga.js which is an older one. Google recommends using universal analytics for new implementations and and you will be getting that tracking code when you create a new property in google analytics console

When you set create a new analytics property and add it to a website, immediately the real time reporting will work and this means your setup and tracking code are correct. Infact, real time report is the recommended route to verify if analytics is working. But for other reports to work, it will take few hours and till then you will get the message tracking not installed.

Regarding the usage of custom variables, if you are using the latest code based on analytics.js, then you should be using custom dimensions and metrics . Custom variables are used with the older ga.js library. You can use upto 20 custom dimensions as against 5 custom variables.



回答3:

Custom Variables:

I can't tell about the scope, since this depends on the application, but there is one slot for one variable, so:

        ['_setCustomVar', 1, "Data1", Data1, 2],
        ['_setCustomVar', 1, "Data2", Data2, 2],
        ['_setCustomVar', 1, "Data3", Data3, 2],

won't work. It should be:

        ['_setCustomVar', 1, "Data1", Data1, 2],
        ['_setCustomVar', 2, "Data2", Data2, 2],
        ['_setCustomVar', 3, "Data3", Data3, 2],