Google Analytics - 阻止 HTML/页面渲染

发布于 2024-07-21 07:56:38 字数 390 浏览 6 评论 0原文

我使用了“不会阻止页面下载的更好的 Google Analytics JavaScript”动态加载 Google Analytics,这样就不会阻止 HTML/页面渲染。

但是,我的 HTML 页面偶尔会阻止在 Firefox 3.0 (WinXP) 上呈现,状态消息指出:

正在从 www.google-analytics.com 传输数据

有关如何以不会阻止 HTML/页面渲染的方式加载 Google Analytics JavaScript?

I have used the "Better Google Analytics JavaScript that doesn’t block page downloading" to load Google Analytics dynamically so that it will not block HTML / page rendering.

However, it appears occassionaly that my HTML page will block rendering on the Firefox 3.0 (WinXP) status message states:

"Transferring data from www.google-analytics.com"

Any ideas on how to load the Google Analytics JavaScript in a way in which it will not block HTML/page rending?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

铃予 2024-07-28 07:56:38

您可以使用 Google Analytics [异步加载跟踪代码][1]。 以下代码片段应该有所帮助:

<script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-X']);
    _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>

You could use Google Analytics [asynchronous loading of tracking codes][1]. The following snippet should help:

<script type="text/javascript">

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-X']);
    _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>
绿光 2024-07-28 07:56:38

将 Google Analytics 代码放在 标记之前的最后,就像 Google 推荐的那样?

Put the Google Analytics code as the last thing before the </body> tag, like Google recommends?

野味少女 2024-07-28 07:56:38

您可能会看到这个错误。 在 3.6 之前,FF 有时会错误地指责 google 分析导致页面速度变慢...

https:/ /bugzilla.mozilla.org/show_bug.cgi?id=487638

You may be seeing this bug. Before 3.6, FF sometimes incorrectly blamed google analytics for slowing down the page...

https://bugzilla.mozilla.org/show_bug.cgi?id=487638

请爱~陌生人 2024-07-28 07:56:38

但它位于底部(就在 之前)并延迟它:

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
<script type="text/javascript">
    if (typeof(_gat)=='object')
        setTimeout(function(){
            _gat._getTracker("UA-1234567-8")._trackPageview()}, 1500);
</script>

看看我的解释,了解为什么我认为这是“集成分析的最佳方式”

But it at the bottom (just before the </body>) and delay it:

<script type="text/javascript" src="http://www.google-analytics.com/ga.js"></script>
<script type="text/javascript">
    if (typeof(_gat)=='object')
        setTimeout(function(){
            _gat._getTracker("UA-1234567-8")._trackPageview()}, 1500);
</script>

Have a look at my explanation about why I think this is the "best way to integrate analytics".

踏月而来 2024-07-28 07:56:38

DEFER 属性可能适合您

<script DEFER type="text/javascript" src="http://www.google-analytics.com/ga.js">

<script DEFER type="text/javascript">... tracker code ...</script>

The DEFER attribute may work for you

<script DEFER type="text/javascript" src="http://www.google-analytics.com/ga.js">

<script DEFER type="text/javascript">... tracker code ...</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文