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

3.1.0 • Public • Published

Лёгкая Я.Метрика

NPM version NPM Downloads Known Vulnerabilities Bundlephobia 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

Package Sidebar

Install

npm i lyam

Weekly Downloads

161

Version

3.1.0

License

MIT

Unpacked Size

25.7 kB

Total Files

13

Last publish

Collaborators

  • hcodes