npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-use-hotjar

v1.2.5

Published

Adds Hotjar capabilities as custom hooks

Downloads

20,440

Readme

react-use-hotjar

Adds Hotjar capabilities as custom hooks to your project

NPM


| Statements | Branches | Functions | Lines | | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | | Statements | Branches | Functions | Lines |

Table of Contents


Install

npm install --save react-use-hotjar

Usage

  • Initializing Hotjar (use it at the very top of your application)
import * as React from 'react';
import useHotjar from 'react-use-hotjar';

const myCustomLogger = console.info;

const HotjarReadyApp = () => {
  const { initHotjar } = useHotjar();

  React.useEffect(() => {
    initHotjar(1234567, 6, false, myCustomLogger);
  }, [initHotjar]);

  return <App />;
};
  • Identifying Users (Use it wherever user's information is available. Send and object respecting Identify API's rules)
import * as React from 'react';
import useHotjar from 'react-use-hotjar';

const myCustomLogger = console.log;

const MyCustomComponent = () => {
  const { identifyHotjar } = useHotjar();

  const handleUserInfo = (userInfo) => {
    const { id, ...restUserInfo } = userInfo;

    identifyHotjar(id, restUserInfo, myCustomLogger);
  };
};

Examples


Documentation

useHotjar() returns:

  • An object with the following keys:

| key | description | arguments | example | | -------------- | -------------------------- | --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | | readyState | States if Hotjar is ready | N/A | N/A | | initHotjar | Initialize method | (hotjarId: number, hotjarVersion: number, hotjarDebug?: boolean, loggerCallback?: console[method]) | (1933331, 6, false, console.info) | | identifyHotjar | User identify API method | (userId: string, userInfo: object, loggerCallback?: console[method]) | ('abcde-12345-12345', {name:"Olli",surname:"Parno",address:"Streets of Tomorrow"}, console.log) | | stateChange | Relative path state change | (relativePath: string, loggerCallback?: console[method]) | ('route/logged-route/user?registered=true') | | tagRecording | Tag a recording | (tags: string[], loggerCallback?: console[method]) | (['tag1', 'tag2']) |

  • initHotjar()
  1. hotjarId: Your Hotjar application ID ex.: 1933331
  2. hotjarVersion: Hotjar's current version ex.: 6
  3. hotjarDebug: Optional Debug Mode to see hotjar logs in console ex.: true
  4. logCallback: Optional callback for logging whether Hotjar is ready or not
initHotjar: (
  hotjarId: string,
  hotjarVersion: string,
  hotjarDebug?: boolean,
  logCallback?: () => void
) => boolean;
  • identifyHotjar()
  1. userId: Unique user's identification as string
  2. userInfo: User info of key-value pairs (note this must not be so long and deep according to docs) (Please note: The Identify API is only available to Business plan customers.)
  3. logCallback: Optional callback for logging whether Hotjar identified user or not
identifyHotjar: (userId: string, userInfo: object, logCallback?: () => void) =>
  boolean;
  • stateChange()
  1. relativePath: A change in a route specially for SPAs usage. stateChange docs
  2. logCallback: Optional callback for logging whether Hotjar stateChange was called or not
stateChange: (relativePath: string, logCallback?: () => void) => boolean;
  • tagRecording()
  1. tags: List of strings to associate with a recording that can be used for filtering
  2. logCallback: Optional callback for logging whether Hotjar tagRecording was called or not
tagRecording: (tags: string[], logCallback?: () => void) => boolean;

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!


License

react-use-hotjar is MIT licensed.


This hook is created using create-react-hook.