Socket
Socket
Sign inDemoInstall

yandex-metrika-api

Package Overview
Dependencies
8
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    yandex-metrika-api

Library for easy Metrika API usage


Version published
Weekly downloads
6
increased by500%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

v0.0.1

  • First test version without strong types.

Readme

Source

Yandex Metrika API Library

This library will help you to get data from Yandex Metrika API. It uses mongoose style API to form requests, so if you are using mongo it will be natural to use this library without any issues.

Start

First install lib:

npm i yandex-metrika-api

To initialize it creates new instance of service:

const ym = new YMService('MY_API_TOKEN');

Where MY_API_TOKEN is your auth token for application. You can read more here in English or here in Russian. From this point you are ready to get data from api. Every request starts with get method. After you can use filter to filter results and dimentions to form report.

const { data }: AxiosResponse<IYmResponse & IYmError> = await this.ymService
	.get(dateFrom, dateTo, 'ym:s:visits', 'COUNTER_ID')
	.filter([
		{
			filter: 'ym:s:trafficSourceName',
			operator: '==',
			value: 'Переходы из поисковых систем',
		},
	])
	.dimensions([''])
	.exec();
  • dateFrom (string) - date in format YYYY-MM-DD.
  • dateTo (string) - date in format YYYY-MM-DD.
  • metrics (ymMetrics) - metrics ym:s:visits or ym:s:pageviews or ym:s:users.
  • COUNTER_ID (string) - counter id.

Filter

In filter method you pass array of filters:

[
	{
		filter: 'ym:s:trafficSourceName',
		operator: '==',
		value: 'Переходы из поисковых систем',
	},
	{
		beforeOperator: 'AND',
		filter: 'ym:s:lastSearchPhrase',
		operator: '!~',
		value: 'brandName',
	},
],
  • beforeOperator (ymLogicOperator) - OR or AND. Operator that will connect previous element of array to current. In this example - it will filter with first AND second condition.
  • filter (string) - filter name like ym:s:trafficSourceName or ym:s:lastSearchPhrase or so on. You can read more here.
  • operator (ymOperators) - operator between filter and value (docs).
  • value (string) - value to compare with.

Dimensions

Array of strings in which dimension you want to present results. All dimensions and metrics can be found here.

Keywords

FAQs

Last updated on 19 Nov 2019

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