Skip to content

MADEiN83/react-matomo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  • handle trackEvent
  • handle trackSiteSearch
  • handle trackGoal
  • handle trackLink

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published