title: How to implement script to Rails app?
body: <p>I need to add HotJar code to my app. I did it this way:</p>
  
  <p><strong>views/services/_hotjar.html.erb</strong></p>
  
  <pre><code>&lt;script&gt;
      (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=');
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>views/layouts/application.html.erb</strong></p>
  
  <pre><code>&lt;head&gt;
    .
    .
    &lt;%= render partial: "services/google_analytics" %&gt;
    &lt;%= render partial: "services/hotjar" %&gt;
  &lt;/head&gt;
  </code></pre>
  
  <p>This way HotJar works only at first opened page (I'm not sure about it, but however it doesn't work well). You may see the same thing that I've done with Google Analytic, but it works good, because here is one difference, it renders this code on every page: </p>
  
  <p><strong>views/layouts/application.html.erb</strong></p>
  
  <pre><code>&lt;body&gt;
  .
  .
    &lt;script&gt;
      ga('send', 'pageview', '&lt;%= request.path %&gt;');
    &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I'm sure, this is not right way. But how to do it right?</p>