Skip to content

Commit 894d5f8

Browse files
committed
改变ga的加载方式,提高网站载入速度。
ga相关的代码可以改成这样,实现异步加载。把app.cofee中的 “ #= require google_analytics”注释掉。试试看。具 体 可以参考这个帖子:http://www.jb51.net/article/23436.htm
1 parent 132e7c4 commit 894d5f8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/views/layouts/application.html.erb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@
106106
</script>
107107
<%= yield :scripts %>
108108
<script>
109-
ga('create', '<%= Setting.google_analytics_key %>', 'auto');
110-
ga('require', 'displayfeatures');
111-
ga('send', 'pageview');
109+
$.getScript("https://www.google-analytics.com/analytics.js",function(){
110+
try {
111+
var pageTracker = _gat._getTracker('<%= Setting.google_analytics_key %>');
112+
pageTracker._trackPageview();
113+
} catch(e) {}
114+
});
112115
</script>
113116
<div class="zoom-overlay"></div>
114117
</body>

0 commit comments

Comments
 (0)