# yandex-metrika-react

> Yandex Metrika component for React

Latest version **1.0.2** (published 2022-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install yandex-metrika-react
pnpm add yandex-metrika-react
yarn add yandex-metrika-react
bun add yandex-metrika-react
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-01-27 |
| First published | 2022-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Artem Lipovoy |
| Maintainers | artemquel |
| Keywords | yandex, metrika, react, ym, component |

## Links

- npm: https://www.npmjs.com/package/yandex-metrika-react
- Repository: https://github.com/artemquel/yandex-metrika-react
- Homepage: https://github.com/artemquel/yandex-metrika-react#readme
- Issues: https://github.com/artemquel/yandex-metrika-react/issues
- npm.io page: https://npm.io/package/yandex-metrika-react

## Dependencies (1)

- [react-helmet](https://npm.io/package/react-helmet.md) ^6.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2022-01-27
- 1.0.1 — 2022-01-27
- 1.0.0 — 2022-01-27
- 0.0.3 — 2022-01-27
- 0.0.2 — 2022-01-26
- 0.0.1 — 2022-01-26

## README

yandex-metrika-react
======================

Adds a wrapper component that allows you to use Yandex Metrika and exposes `ym` tracking function as hook

Features:
- Uses context API to store `ym` call stack
- Requests via hook calls only after metrika initialization, until that moment they are stored in the call stack

Usage:

Use the component to wrap your application at the top level (for example in `index.js` for create-react-app)
```javascript
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import {YandexMetrika} from "yandex-metrika-react"

ReactDOM.render(
    <YandexMetrika
        counterId={XXXX}
        options={{
          clickmap: true,
          trackLinks: true,
          accurateTrackBounce: true,
          webvisor: true,
          triggerEvent: true,
        }}
    >
      <App />
    </YandexMetrika>, document.getElementById("root")
)
```

To call tracker function in your component:
```javascript
...
const ym = useMetrika()
ym("reachGoal","MyAwesomeGoal", {param: 1})
...
```
The hook syntax is equivalent to the `ym` tracking function syntax, except for passing the counter ID

The property of `YandexMetrika` component is equal to metrika initialize params (as described in [Yandex.Metrika documentation](https://yandex.ru/support/metrica/code/counter-initialize.html))

---
_Source: https://npm.io/package/yandex-metrika-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
