mcpField
Y
yandex-metrica

yandex-metrica

github.com/elsvvData & databases1104 installsUpdated 36w ago
Repository

About yandex-metrica

yandex-metrica is a scripting skill for accessing the Yandex Metrica API, aimed at teams reviewing web analytics and managing counters. It supports aggregate reports, goal lookups, and raw visit or hit log exports.

Key features

  1. 01Check the connection and list counters
  2. 02Inspect counter details and goals
  3. 03Query reports with presets or custom dimensions
  4. 04Apply filters and date ranges
  5. 05Export raw visit or hit logs
  6. 06Save reports as CSV

Use cases

  1. 01Review website visits and user counts
  2. 02Analyze traffic sources and top pages
  3. 03Check counter goals and completions
  4. 04Export visit logs for a date range

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/elsvv/yandex-metrica-skill --skill yandex-metrica

After installing, type/yandex-metricain Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

README.md
.gitignore
cache/
.gitkeep
config/
.env.example
README.md
references/
api-reference.md
scripts/
check_connection.sh
counters.sh
common.sh
get_token.sh
goals.sh
logs.sh
stats.sh

Details

From the project README

yandex-metrica

Yandex Metrica API — web analytics: counters, reports, goals, logs export.

Config

Requires YANDEX_METRICA_TOKEN in config/.env. See config/README.md for token setup (OAuth, permissions: metrika:read, metrika:write).

Quick Start

IMPORTANT: Always run scripts with bash prefix and absolute paths from the skill directory. Scripts use bash-specific features and will not work if sourced from zsh. Do NOT source scripts/common.sh directly — use the wrapper scripts below.

# 1. Setup token
bash scripts/get_token.sh --client-id YOUR_CLIENT_ID

# 2. Check connection
bash scripts/check_connection.sh

# 3. List counters
bash scripts/counters.sh --action list

# 4. Get traffic stats
bash scripts/stats.sh --counter 12345678 --preset traffic

# 5. Export raw logs
bash scripts/logs.sh --action create --counter 12345678 --date1 2025-01-01 --date2 2025-01-31

API Overview

Base URL: https://api-metrika.yandex.net

Auth header: Authorization: OAuth TOKEN

APIPurposeBase Path
ManagementCounters, goals, filters, grants, segments/management/v1/
ReportingAggregated stats, dimensions, metrics/stat/v1/
LogsRaw visit/hit data export/management/v1/counter/{id}/logrequests

Scripts

check_connection.sh

Verify API token and list available counters.

bash scripts/check_connection.sh
counters.sh

Manage counters: list, get details, get full info with goals/filters.

bash scripts/counters.sh --action list
bash scripts/counters.sh --action list --search "mysite.com"
bash scripts/counters.sh --action info --counter 12345678
stats.sh

Pull reporting data with presets or custom metrics/dimensions.

# Traffic overview
bash scripts/stats.sh --counter 12345678 --preset traffic

# Traffic sources breakdown
bash scripts/stats.sh --counter 12345678 --preset sources

# Top pages
bash scripts/stats.sh --counter 12345678 --preset content

# Custom report with filters
bash scripts/stats.sh --counter 12345678 \
  --metrics "ym:s:visits,ym:s:users,ym:s:bounceRate" \
  --dimensions "ym:s:lastTrafficSource" \
  --filters "ym:s:trafficSource=='organic'" \
  --date1 2025-01-01 --date2 2025-01-31

# Time-series report
bash scripts/stats.sh --counter 12345678 --type bytime \
  --metrics "ym:s:visits" --date1 2025-01-01 --date2 2025-01-31

# Export to CSV
bash scripts/stats.sh --counter 12345678 --preset sources --csv report.csv
ParamDefaultDescription
--counterenv varCounter ID (required)
--metricsvisits,pageviews,usersComma-separated metrics
--dimensions—Comma-separated dimensions
--date130 days agoStart date YYYY-MM-DD
--date2todayEnd date YYYY-MM-DD
--filters—Filter expression
--sort—Sort field (prefix - for desc)
--limit100Max rows
--preset—traffic, sources, geo, content, technology
--typedatadata, bytime, drilldown, comparison
--csv—Export to CSV file
goals.sh

List and get goals for a counter.

bash scripts/goals.sh --action list --counter 12345678
bash scripts/goals.sh --action get --counter 12345678 --goal-id 999
logs.sh

Raw data export via Logs API.

# Check if export is possible
bash scripts/logs.sh --action evaluate --counter 12345678 \
  --date1 2025-01-01 --date2 2025-01-31

# Create log request
bash scripts/logs.sh --action create --counter 12345678 \
  --source visits --date1 2025-01-01 --date2 2025-01-31

# Check status
bash scripts/logs.sh --action status --counter 12345678 --request-id 777

# Download when ready
bash scripts/logs.sh --action download --counter 12345678 \
  --request-id 777 --output ./exports

# Clean up server-side
bash scripts/logs.sh --action clean --counter 12345678 --request-id 777

# List all log requests
bash scripts/logs.sh --action list --counter 12345678

Key Metrics Quick Reference

MetricDescription
ym:s:visitsSessions
ym:s:usersUnique visitors
ym:s:pageviewsTotal pageviews
ym:s:bounceRateBounce rate %
ym:s:avgVisitDurationSecondsAvg session duration
ym:s:newUsersNew visitors
ym:s:goal<ID>reachesGoal completions
ym:s:goal<ID>conversionRateGoal conversion rate
ym:s:ecommerceRevenueE-commerce revenue

Key Dimensions Quick Reference

DimensionDescription
ym:s:trafficSourceTraffic source type
ym:s:lastTrafficSourceLast traffic source
ym:s:<attr>UTMSourceUTM source
ym:s:<attr>UTMMediumUTM medium
ym:s:startURLLanding page
ym:s:regionCountryCountry
ym:s:regionCityCity
ym:s:browserBrowser
ym:s:deviceCategoryDevice type
ym:s:operatingSystemOS

<attr> = attribution model: last, first, lastsign, etc.

Filter Syntax

ym:s:trafficSource=='organic'           # equals
ym:s:trafficSource!='organic'           # not equals
ym:s:trafficSource=.('organic','direct') # in list
ym:s:pageViews>5                        # greater than
ym:s:startURL=@'product'               # contains
ym:s:startURL=~'.*product.*'           # regex
ym:s:trafficSource=='organic' AND ym:s:isRobot=='No'  # combine

Rate Limits

LimitValue
General API30 req/sec per IP
Logs API10 req/sec per IP
Parallel requests3 per user
Daily limit5,000 req/day
Reports API200 req/5 min

Detailed Reference

For comprehensive API documentation including all endpoints, field lists, curl examples, and advanced features, see: references/api-reference.md

Covers: Management API (counters, goals, filters, operations, grants, labels, segments, user params), Reporting API (data, bytime, drilldown, comparison, presets, full metrics/dimensions), Logs API (visits/hits fields).

Comments

Markdown supported