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?
You can learn about both Universal Analytics and Google Analytics 4 without having your own website.
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.
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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With