1
votes

Following the documentation found here: https://developers.google.com/analytics/devguides/collection/gajs/

I have made a simplest case in an empty html file as such:

<script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXX-2']);
    _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>

When I load the page in Chrome with the Google Tag Assistant plugin it says "No HTTP Response Detected" and I all I see in the Developer Tools network tab is the html file load and the ga.js script being downloaded from google. I get the same result in IE, but when I use Firefox I can see the it trying to get __utm.gif from Google which is how I understand that it should work.

I see no errors in the console, why wouldn't this work in IE and Chrome?

Here is the entire html:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>GA Test</title>
        <script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-X-2']);
            _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>
    </head>
    <body>
        <p>Testing GA</p>
    </body>
</html>
2
Are you able to share your site? - nyuen
It's not on a live site yet, I'll add the entirety of the html to the question though if it helps. - jhunter
When you test this are you testing on localhost or an IP such as 127.0.0.1? If so GA might not work. You should test this from a FQDN. Try setting up a fake hostname for your dev machine such as testsite.com - Eduardo

2 Answers

3
votes

May be this happens, if you are using tracking code at the locale HTML file(as you said, that website is not live yet).

So,

  1. This tracking code will work, when you publish it to live domain;
  2. May be if you add string _gaq.push(['_setDomainName', 'none']); before string _gaq.push(['_trackPageview']); in your locale HTML, it will work for you and will send HTTP-response.
0
votes

I actually would recommend that before you implement this tracking, that you go ahead and upgrade to Universal Analytics. The e-commerce tracking should be easier to set up and with classic analytics already being depreciated, this seems to be the step that would be best for you. This link shows a bit on how much easier it can be.

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce