
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-metrika
Advanced tools
Превосходный React/Preact-компонент для работы с Яндекс Метрикой и не только.
<MetrikaCounter /> можно размещать в любом месте на странице, гарантируется что счётчик не будет несколько раз инициализироваться;npm install --save-dev react-metrika
Установка одного счётчика:
import { FC } from 'react';
import { MetrikaCounter } from 'react-metrika';
export const MyPage: FC = () => {
return (
<Header />
<Content>Some text...</Content>
<Footer />
<MetrikaCounter
id={1234567}
options={{
trackHash: true,
webvisor: true
}}
/>
);
}
Установка нескольких счётчиков с одинаковыми настройками:
import { FC } from 'react';
import { MetrikaCounters } from 'react-metrika';
export const MyPage: FC = () => {
const handleClick = () => {
ym(123, 'params', { myParams: { a: 1, b: 2, c: 3 } });
};
return (
<Header />
<Content>
Some text...
<button onClick={handleClick}>Click me!</button>
</Content>
<Footer />
<MetrikaCounters
ids={[123, 234]}
options={{
trackHash: true,
webvisor: true
}}
/>
);
}
import { ym } from 'react-metrika';
// counterId, method, value
ym(123, 'init', { webvisor: true });
// ...
ym(123, 'reachGoal', 'goalName', { params: { a: 1, b: 2, c: 3 }});
В некоторых случаях необходимо максимально быстро загрузить скрипт Метрики, например, в начальной точке инициализации приложения или до отображения интерфейса.
import { loadMetrikaScript } from 'react-metrika';
loadMetrikaScript().then(() => {
console.log('Metrika script is loaded.');
});
// ...
Также можно добавить в <head> страницы предзагрузку скрипта Метрики:
<link rel="preload" href="https://mc.yandex.ru/metrika/tag.js" as="script" />
import { setMetrikaUrl, METRIKA_SCRIPT_URL_COM } from 'react-metrika';
// https://mc.yandex.com/metrika/tag.js
setMetrikaScriptUrl(METRIKA_SCRIPT_URL_COM);
// ...
Для отслеживания изменения урла страницы не забудьте включить опцию счётчика trackHash: true.
<MetrikaCounter
id={1234567}
options={{
trackHash: true, // !!!
webvisor: true
}}
/>
FAQs
Excellent React/Preact component for Yandex Metrika
The npm package react-metrika receives a total of 681 weekly downloads. As such, react-metrika popularity was classified as not popular.
We found that react-metrika demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.