If I can still answer this for the next person:
- create a Hotjar account
- if you have not done so already for other reasons before, create a new index.html in your theme/web folder, by copy-pasting the template index-example.html from the deployment/web folder. (see instructions here: https://docs.mendix.com/howto/front-end/customize-styling-new/#custom-web)
- add the Hotjar snippet to the head of the HTML file
- deploy and test that it works on Hotjar.
This has worked for me. No need to put the code snippet on all pages, just the index.html.