Socket
Socket
Sign inDemoInstall

yandex-metrika

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

yandex-metrika

Библиотека для работы с API Яндекс.Метрики


Version published
Maintainers
1
Weekly downloads
2
decreased by-60%

Weekly downloads

Readme

Source

yandex-metrika

Библиотека для API Яндекс.Метрики Для работы с данной библиотекой вам необходимо иметь OAuth-токен приложения Яндекс.Метрики. Для того, чтобы создать приложение:

  • перейдите по этой ссылке и добавьте в правах пункт Яндекс.Метрика.
  • Получите OAuth токен по инструкции, описанной [здесь] (https://tech.yandex.ru/oauth/doc/dg/concepts/ya-oauth-intro-docpage/)

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

const YMetrikaRequest = require( 'yandex-metrika' ),
  oauth_token = 'OAuth токен',
  counterId = 3123123, // id счётчика
  api = new YMetrikaRequest( oauth_token );

/* 
  получить информацию о счтчике по id
  GET /management/v1/counter/{counterId}
*/
api.get( `/management/v1/counter/${counterId}` )
.then( data => {
  console.log( data );
});

// аналогично
api.request( `/management/v1/counter/${counterId}`, 'GET' )
.then( data => {
  console.log( data );
});

/* 
  Создать новую цель
  POST https://api-metrika.yandex.ru/management/v1/counter/{counterId}/goals
*/

api.post( `https://api-metrika.yandex.ru/management/v1/counter/${counterId}/goals`, {
  name: 'Пробыл на сайте N минут',
  type: 'action',
  conditions: [
    {
      type: "exact",
      url: "goal_slug"
    }
  ]
})
.then( data => {
  console.log( data );
});

Описание методов

/**
 * Формирует GET, POST, PUT, DELETE запросы соответственно
 * @param  {String} url     Адрес запроса на сервере, начиная с /
 * @param  {Object} data    Данные для запроса (не включая token)
 * @param  {Object} headers Заголовки запроса
 * @return {Promise}         Обещание ответа
 */
api.get( url, data = {}, headers = {})
api.post( url, data = {}, headers = {})
api.put( url, data = {}, headers = {})
api.delete( url, data = {}, headers = {})

// формирует свободный запрос
api.request( url, method = 'GET', data = {}, headers = {})

Возможные ошибки

  • После 2 запросов последующие могут не работать

TODO

Сделать тесты

Keywords

FAQs

Last updated on 26 May 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc