在没有服务器或本地主机的情况下使用Google Analytics?

Joh*_*ett 7 google-analytics

我花了很多时间研究在本地运行的文件上使用GA的方法,但没有使用http://localhost:(some_port).

我使用的每个方法都不会返回任何常规数据.这是我最接近的东西:

<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>
Run Code Online (Sandbox Code Playgroud)

以前有人以这种方式工作吗?

Shl*_*iTC 13

感谢您通过"_debug.js"脚本选项启发我的眼睛.我正在使用分析模块并遇到同样的问题.所以我使用调试脚本,并在尝试发送事件时收到以下错误:

Unallowed document protocol. Aborting hit.

我搜索了它,发现这个主题如何绕过它:https://productforums.google.com/forum/#! topic/analytics/KNz8TimivXo

这就是答案:

ga('create', 'UA-**********-6', {'cookieDomain': 'none'});
ga('set', 'checkProtocolTask', function(){ /* nothing */ });
ga('send', 'pageview');
Run Code Online (Sandbox Code Playgroud)

  • 另外,您可以将`checkProtocolTask​​`设置为`null`,而不是使用noop函数。 (2认同)