Below is a sample code that can be used to integrate Hotjar with Cookie Consent. Make sure you insert your hjid and the correct url of your Cookie Consent javascript.
<script language="javascript"> var hjLoaded = false; var loadHotjar = function() { if (!hjLoaded) { (function(h,o,t,j,a,r){ h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)}; h._hjSettings={hjid:xxxxxx,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='); hjLoaded = true; } } </script> <script src="https://cookie.consent.is/cc/xxxxxxx.js"></script> <script type="text/javascript"> window.addEventListener("load", function() { window.cookieconsent.initialise({ // Called when the widget has been initialized and rendered. // When using geolocation this method is always called when loading a page. onInitialise: function(status) { if (this.hasConsented('analytics')) { console.log('onInitialise: analytics'); loadHotjar(); } }, // Called when user allows a category // The category parameter contains the name of the category // being allowed. onAllow: function(category) { if (category == 'analytics') { console.log('onAllow: analytics'); loadHotjar(); } } }) }); </script>