我需要将HotJar代码添加到我的应用程序。我就是这么做的:如何实现脚本到Rails应用程序?
的意见/服务/ _hotjar.html.erb
<script>
(function(h,o,t,j,a,r){
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
h._hjSettings={hjid:140457,hjsv:5};
a=o.getElementsByTagName('head')[0];
r=o.createElement('script');r.async=1;
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
a.appendChild(r);
})(window,document,'//static.hotjar.com/c/hotjar-','.js?sv=');
</script>
的意见/布局/ application.html.erb
<head>
.
.
<%= render partial: "services/google_analytics" %>
<%= render partial: "services/hotjar" %>
</head>
这样HotJar作品只有在第一次打开的页面(我不确定,但它不能很好地工作)。您可能会看到,我已经与谷歌分析做同样的事情,但它的作品好,因为这里是一个区别,它呈现在每一页上的代码:
的意见/布局/ application.html.erb
<body>
.
.
<script>
ga('send', 'pageview', '<%= request.path %>');
</script>
</body>
我敢肯定,这是不正确的方式。但如何做到这一点?
是否使用turbolinks? – Vasfed
@Vasfed是的,我做 – nobilik