Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Analytics without a server or localhost?

I have spent quite a lot of time researching ways to use GA on a locally run file, but not using http://localhost:(some_port).

Every method I use never returns any regular data. This is the closest I have got to receiving anything:

<script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-47519364-1']);
            _gaq.push(['_setDomainName', 'none']);
            _gaq.push(['_setAllowLinker', 'true']);
            _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/u/ga_debug.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
        </script>

Anyone got this working in this fashion before?

like image 994
JohnRobertPett Avatar asked Mar 31 '14 12:03

JohnRobertPett


People also ask

Do I need a website to use Google Analytics?

You can learn about both Universal Analytics and Google Analytics 4 without having your own website.

Does Google Analytics count localhost?

Both Global Site Tag - gtag. js and Universal Analytics - analytics. js will detect localhost automatically. You do not need to make any change to the configuration.

Why Cannot use Google Analytics?

Verify that you're tracking the right property and view. If you have access to multiple Google Analytics accounts and properties, there's a chance that you might be using the Google Analytics tracking code from another property, or you may be looking at reports in the wrong account, or for the wrong property and view.


1 Answers

Thanks for enlightening my eyes with the option of the '_debug.js' script. I am using the analytics module and had the same problem. So I used the debug script and got the following error when trying to send an event:

Unallowed document protocol. Aborting hit.

I googled it and found this thread exlaining how to bypass it: https://productforums.google.com/forum/#!topic/analytics/KNz8TimivXo

This was the answer:

ga('create', 'UA-**********-6', {'cookieDomain': 'none'});
ga('set', 'checkProtocolTask', function(){ /* nothing */ });
ga('send', 'pageview');
like image 193
ShlomiTC Avatar answered Oct 16 '22 02:10

ShlomiTC