How to add javascript code in side head tag in application

When I am writing the below code in then following code comes as plain text in browser. I also tried to add the following javascript code in js file then plain text not coming in browser but below code is not working.
Please suggest.

<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>

Not sure WHERE you write the code (it was filtered it seems, try three backticks “`” for block code (more than one line) or one single one for inline text.

Your theme has probably a template file for headers. Depending on how your theme is built it’s something called header.html in the layouts/partials/ folder. It’s probably a good idea to contact the developer of your theme. If it’s a good one you already have a README.md file in the theme that describes how to add this type of code.