react-matomo
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

react-matomo

install

npm i -D react-matomo

Or using yarn:

yarn add react-matomo

usage

Setup the Provider:

import { MatomoProvider, createInstance } from "react-matomo";

<MatomoProvider
  value={createInstance({
    url: "https://analytics.yoursite.org/",
    siteId: 9,
  })}
>
  <App />
</MatomoProvider>;

Use the hook:

import { useMatomo } from "react-matomo";

const App = () => {
  const { trackPageView } = useMatomo();

  useEffect(() => {
    trackPageView();
  }, []);

  return <div>Content goes here</div>;
};

Track event

import { useMatomo } from "react-matomo";

const App = () => {
  const { trackEvent } = useMatomo();

  return (
    <div>
      <button onClick={() => trackEvent("category", "action")}>Click me</button>
    </div>
  );
};

roadmap

  • [ ] handle custom configuration
  • [x] handle trackEvent
  • [ ] handle trackSiteSearch
  • [ ] handle trackGoal
  • [ ] handle trackLink

Package Sidebar

Install

npm i react-matomo

Weekly Downloads

23

Version

0.0.6

License

ISC

Unpacked Size

23.1 kB

Total Files

30

Last publish

Collaborators

  • madein83