Javascript not working (how to add hotjar)

When we add this code on head section of application then its not working.

Please suggest how to add hotjar in our website.
Thanks.

<script type="application/javascript">
    (function(h,o,t,j,a,r){
    h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
    h._hjSettings={hjid:1505758,hjsv:6};
    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,'https://static.hotjar.com/c/hotjar-','.js?sv=&#39;);
    </script>

Looks like there’s a small typo. There’s a missing quote around the param on the last line.

This should work, or copy it from HotJar again:

  <script>
      (function(h,o,t,j,a,r){
          h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
          h._hjSettings={hjid:1505758,hjsv:6};
          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,'https://static.hotjar.com/c/hotjar-','.js?sv=');
  </script>

See the example on HotJar’s admin:

If you want to make sure it will only load on production wrap it in: {{ if hugo.IsProduction }} HOTJAR CODE {{ end }}.

And if you want to preconnect:

  <link rel="preconnect" href="https://script.hotjar.com/" crossorigin>
  <link rel="preconnect" href="https://vars.hotjar.com" crossorigin>
  <link rel="preconnect" href="https://vc.hotjar.io" crossorigin>
  <link rel="preconnect" href="https://in.hotjar.com" crossorigin>

Good to know.
Thanks, its working.

Great!

Would you please mark it as “Solution” so this thread will automatically close?

image

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.