Light Ya.Metrika for sites


Keywords
light, yandex, yandex-metrika, metrika, lightweight, typescript
License
MIT
Install
npm install lyam@1.2.0

Documentation

Лёгкая Π―.ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠ°

NPM version NPM Downloads install size

ΠœΠΎΡ‚ΠΈΠ²Π°Ρ†ΠΈΡ

Π‘ΠΊΡ€ΠΈΠΏΡ‚ ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ Π·Π°Π½ΠΈΠΌΠ°Π΅Ρ‚ Π±ΠΎΠ»Π΅Π΅ 350 ΠšΠ‘ (90 ΠšΠ‘ Π² GZIP), для Π»Ρ‘Π³ΠΊΠΈΡ… страниц ΠΈ Π½Π΅Π±ΠΎΠ»ΡŒΡˆΠΈΡ… ΠΏΠ°ΠΊΠ΅Ρ‚ΠΎΠ² ΠΎΠ½ Π³Ρ€ΠΎΠΌΠΎΠ·Π΄ΠΊΠΈΠΉ.

ΠŸΡ€Π΅ΠΈΠΌΡƒΡ‰Π΅ΡΡ‚Π²Π°

  • Π‘Π²Π΅Ρ€Ρ…ΠΌΠ°Π»Ρ‹ΠΉ Ρ€Π°Π·ΠΌΠ΅Ρ€ ΠΊΠΎΠ΄Π°.
  • Код ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π°Π΅Ρ‚ΡΡ Π² основной Π±Π°Π½Π΄Π» ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°, Π½Π΅Ρ‚ Π΄ΠΎΠΏΠΎΠ»Π½ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ запроса Π½Π° Π·Π°Π³Ρ€ΡƒΠ·ΠΊΡƒ скрипта ΠΈ парсинга ΠΊΠΎΠ΄Π° ΠœΠ΅Ρ‚Ρ€ΠΈΠΊΠΈ.
  • ИспользованиС Π² serviceWorker’С, элСктрон-прилоТСниях ΠΈ Ρ‚.Π΄.

ИспользованиС

import { hit } from 'lyam';

const counterId = '12345';

// Если Π½Π΅ ΡƒΠΊΠ°Π·Π°Π½Ρ‹ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹, Ρ‚ΠΎ адрСс страницы бСрётся ΠΈΠ· location.href,
// Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ страницы ΠΈΠ· document.title ΠΈ
// Ρ€Π΅Ρ„Π΅Ρ€Π΅Ρ€ ΠΈΠ· document.referrer.
hit(counterId);

Π‘ΠΎ всСми ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ:

import { hit } from 'lyam';

const counterId = '12345';
const userVars = { myParam: 123 };

hit(counterId, {
  referrer: 'https://anothersite.ru',
  title: 'My document title',
  url: 'https://mysite.ru'
}, userVars);

ΠžΡ‚ΠΏΡ€Π°Π²ΠΊΠ° Ρ†Π΅Π»ΠΈ

import { hit, reachGoal } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

reachGoal(counterId, 'MY_GOAL_NAME');

ΠžΡ‚ΠΏΡ€Π°Π²ΠΊΠ° Ρ†Π΅Π»ΠΈ с ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Π°ΠΌΠΈ Π²ΠΈΠ·ΠΈΡ‚Π°

import { hit, reachGoal } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

const userVars = { myParam: 123 };
reachGoal(counterId, 'MY_GOAL_NAME', userVars);

Π’Π½Π΅ΡˆΠ½ΡΡ ссылка

import { hit, extLink } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

extLink(counterId, 'https://externalsite.ru');

Π—Π°Π³Ρ€ΡƒΠ·ΠΊΠ° Ρ„Π°ΠΉΠ»Π°

import { hit, file } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

file(counterId, 'https://mysite.ru/file.zip');

НС ΠΎΡ‚ΠΊΠ°Π·

import { hit, notBounce } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

setTimeout(() => {
    notBounce(counterId);
}, 15000); // 15 сСк.

ΠŸΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ Π²ΠΈΠ·ΠΈΡ‚Π°

import { hit, params } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

params(counterId, { myParam: 123 });

ΠŸΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΈΠ΅ ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹

import { hit, userParams } from 'lyam';

const counterId = '12345';
hit(counterId);

// ...

userParams(counterId, { myParam: 1, UserID: 12345 });

CSP

Content-Security-Policy:
  ...
  img-src https://mc.yandex.ru;
  connect-src https://mc.yandex.ru;
  ...

MIT