1.5.5 • Published 4 months ago

@usermaven/react v1.5.5

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Official Usermaven SDK for React

General

This package is a wrapper around @usermaven/sdk-js, with added functionality related to React.

Installation

To use Usermaven SDK, install npm package

npm install @usermaven/react

Import and configure Usermaven SDK Provider

//...
import { createClient, UsermavenProvider } from "@usermaven/react";

// initialize Usermaven core
const usermavenClient = createClient({
  tracking_host: "__USERMAVEN_HOST__",
  key: "__API_KET__",
  // See Usermaven SDK parameters section for more options
});

// wrap our app with Usermaven provider
ReactDOM.render(
  <React.StrictMode>
    <UsermavenProvider client={usermavenClient}>
      <App />
    </UsermavenProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

See parameters list for createClient() call.

Usage

import { useUsermaven } from "@usermaven/react";

const App = () => {
  const {id, track, trackPageView} = useUsermaven(); // import methods from useUsermaven hook

  useEffect(() => {
    id({id: '__USER_ID__', email: '__USER_EMAIL__'}); // identify current user for all track events
    trackPageView() // send page_view event
  }, [])
  
  const onClick = (btnName: string) => {
    track('btn_click', {btn: btnName}); // send btn_click event with button name payload on click
  }
  
  return (
    <button onClick="() => onClick('test_btn')">Test button</button>
  )
}

\ To enable automatic pageview tracking, add usePageView() hook. This hook will send pageview each time user loads a new page (including internal SPA pages). This hook relies on React Router and requires react-router (>=5.x) package to be present

const App = () => {
  usePageView() //this hook will send pageview track event on router change

  return (
    <Routes>
      <Route path="/" element={<Main />} />
      <Route path="page" element={<Page />} />
    </Routes>
  );
}

\ If you need to pre-configure usermaven event - for example, identify a user, it's possible to do via before callback:

usePageView({before: (usermaven) => usermaven.id({id: '__USER_ID__', email: '__USER_EMAIL__'})})

Hooks

useUsermaven

Returns object with id, track, trackPageView, rawTrack, set, unset and interceptAnalytics methods of Usermaven SDK.

usePageView

Can be used only with react-router. Sends pageview event on every route change.

1.5.5

4 months ago

1.5.4

4 months ago

1.5.4-rc.96

4 months ago

1.5.3-rc.95

4 months ago

1.5.3

6 months ago

1.5.2-rc.92

6 months ago

1.4.3-rc.88

6 months ago

1.4.3-rc.89

6 months ago

1.5.2

6 months ago

1.5.1

6 months ago

1.4.1-rc.86

6 months ago

1.4.1-rc.69

6 months ago

1.5.0-rc.90

6 months ago

1.4.1-rc.84

6 months ago

1.5.1-rc.91

6 months ago

1.4.1-rc.70

6 months ago

1.4.1-rc.72

6 months ago

1.4.2-rc.87

6 months ago

1.4.1-rc.71

6 months ago

1.4.1-rc.66

6 months ago

1.4.1-rc.64

7 months ago

1.4.1-rc.63

8 months ago

1.4.4

8 months ago

1.4.3

8 months ago

1.4.2

8 months ago

1.4.1

8 months ago

1.4.1-rc.62

8 months ago

1.4.1-rc.61

8 months ago

1.4.1-rc.60

8 months ago

1.4.1-rc.59

9 months ago

1.4.1-rc.58

9 months ago

1.4.0

1 year ago

1.3.3

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.2.8

1 year ago

1.3.0

1 year ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago