gatsby-plugin-hotjar icon indicating copy to clipboard operation
gatsby-plugin-hotjar copied to clipboard

Here this hotjar script should added inside body tag instead of head. If it should add inside the head tag that will be better. :)

Open jamalumusic opened this issue 4 years ago • 3 comments

https://github.com/pavloko/gatsby-plugin-hotjar/blob/08e92c8001b51ed20b42a6091cac0710c032719d/src/gatsby-ssr.js#L9

jamalumusic avatar Jul 15 '21 12:07 jamalumusic

@jamalumusic so it's been a while since I've made that decision, so can you provide more context for why you'd rather have it in the head? My considerations for placing it at the end of the body were the following. Hotjar records user session and in any scenario the full page would need to be loaded to capture the session. This is different from, for example, Google Analytics script, which we want to start loading as soon as possible to capture users who would leave the page without waiting for it to load.

pavloko avatar Jul 15 '21 12:07 pavloko

@pavloko Is that possible to add setHeadComponents function. Your library was very helpful, but in my case I need to add that script in head tag

jamalumusic avatar Jul 15 '21 13:07 jamalumusic

@jamalumusic can you explain the context around why you need it to be in the head tag? A change like this will effect all users of the library, so we need to make sure it satisfies everybody.

pavloko avatar Jul 15 '21 13:07 pavloko

Following up with this, adding to the head is what hotjar recommends

Share the code with your developer, or in your site's code paste the copied Tracking Code between the

tag. Hotjar works most accurately if the Hotjar Tracking Code is inside the Head tag ( ) of every page you want to track.

or at least add a flag to toggle between putting it in head/body.

elistone avatar Aug 22 '24 12:08 elistone

Thank to @elistone this has been implemented and the new version is now publish on the NPM: https://www.npmjs.com/package/gatsby-plugin-hotjar/v/1.2.1

pavloko avatar Sep 12 '24 11:09 pavloko