Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

mixpanel

БесплатноБез исполняемых скриптовНе проверен

Mixpanel is a product analytics service for tracking events, building funnels and retention reports, and segmenting users. Use when a user asks to add…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Mixpanel

Overview

Mixpanel stores events (track) and user or group profiles (people.set, group profiles). Three credentials exist and are easy to mix up:

  • Project token: public, goes in browser code and in the server SDKs' init; it can only send data.
  • Service account (username, secret, project id): private; required for /import, the Export API and the Query API.
  • Data residency: EU projects must send to api-eu.mixpanel.com (browser: api_host: 'https://api-eu.mixpanel.com') and query eu.mixpanel.com; US is the default. Sending to the wrong region silently loses data.

Instructions

Step 1: Browser SDK

npm install mixpanel-browser
// lib/mixpanel.ts
import mixpanel from 'mixpanel-browser'

export function initMixpanel() {
  mixpanel.init(process.env.NEXT_PUBLIC_MIXPANEL_TOKEN!, {
    debug: process.env.NODE_ENV === 'development',
    api_host: 'https://api-eu.mixpanel.com',   // remove for US projects
    track_pageview: 'url-with-path',
    persistence: 'localStorage',
    // batch_requests (true), batch_size (50) and batch_flush_interval_ms (5000) are already the defaults
  })
}

Call initMixpanel() once on the client (for example in a useEffect in the root layout), never during server rendering.

// lib/mixpanel-events.ts
import mixpanel from 'mixpanel-browser'

export function identifyUser(userId: string, traits: { email: string; name: string; plan: string }) {
  mixpanel.identify(userId)   // call on login/signup; anonymous activity before it is merged into this user
  mixpanel.people.set({ $email: traits.email, $name: traits.name, plan: traits.plan })
}

export function trackPurchase(plan: string, amount: number, currency: string) {
  mixpanel.track('Purchase', { plan, amount, currency })
}

export function resetUser() {
  mixpanel.reset()            // on logout
}

mixpanel.people.track_charge() is deprecated and does nothing in current versions; record revenue as an event property (as above) and chart it in Mixpanel.

Step 2: Server SDK, Node.js

npm install mixpanel
// lib/mixpanel-server.ts
import Mixpanel from 'mixpanel'

const mixpanel = Mixpanel.init(process.env.MIXPANEL_TOKEN!, {
  host: 'api-eu.mixpanel.com',   // omit for US
})

export function trackSubscription(userId: string, plan: string, mrr: number) {
  mixpanel.track('Subscription Started', { distinct_id: userId, plan, mrr, currency: 'usd' })
  mixpanel.people.set(userId, { plan, mrr })
}

Historical or backfilled events go through /import, which needs service account credentials:

const { ServiceAccountCredentials } = Mixpanel
const credentials = new ServiceAccountCredentials(
  process.env.MIXPANEL_SA_USER!, process.env.MIXPANEL_SA_SECRET!, process.env.MIXPANEL_PROJECT_ID!)
const importer = Mixpanel.init(process.env.MIXPANEL_TOKEN!, { credentials })
importer.import('Purchase', new Date('2026-09-01T10:00:00Z'),
  { distinct_id: 'u_1042', amount: 49, $insert_id: 'ord-1001' })

Step 3: Server SDK, Python

pip install mixpanel
import os
from mixpanel import Mixpanel, Consumer, ServiceAccountCredentials

credentials = ServiceAccountCredentials(
    username=os.environ["MIXPANEL_SA_USER"],
    secret=os.environ["MIXPANEL_SA_SECRET"],
    project_id=os.environ["MIXPANEL_PROJECT_ID"],
)
# EU projects: pass api_host. The credentials are used for import_data.
mp = Mixpanel(os.environ["MIXPANEL_TOKEN"],
              consumer=Consumer(api_host="api-eu.mixpanel.com", credentials=credentials))

mp.track("u_1042", "Sign Up", {"method": "google"})
mp.people_set("u_1042", {"$email": "[email protected]", "plan": "pro"})
mp.group_set("company", "northwind", {"$name": "Northwind Traders", "seats": 50})
# Past event: api_key is deprecated, pass None; timestamp is UTC seconds. Use $insert_id so retries do not duplicate.
mp.import_data(None, "u_1042", "Purchase", 1788256800, {"amount": 49, "$insert_id": "ord-1001"})

The Python calls were run against a local stub server: track posts to /track, people_set to /engage, group_set to /groups, and import_data to /import?project_id=... with Basic auth.

Step 4: Group analytics (B2B)

Enable the group key (for example company) in Mixpanel project settings first.

import mixpanel from 'mixpanel-browser'

export function setUserCompany(companyId: string, companyName: string) {
  mixpanel.set_group('company', companyId)
  mixpanel.get_group('company', companyId).set({ $name: companyName, plan: 'enterprise' })
}

export function trackCompanyEvent(companyId: string, event: string, properties = {}) {
  mixpanel.track_with_groups(event, properties, { company: companyId })
}

Step 5: Query and Export APIs

Authenticate with the service account (HTTP Basic) and pass project_id. The Insights endpoint only reads a saved report (bookmark_id is required), so for ad-hoc counts use Segmentation, an

Полный SKILL.md на GitHub

Установить mixpanel в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл mixpanel?

Mixpanel is a product analytics service for tracking events, building funnels and retention reports, and segmenting users. Use when a user asks to add Mixpanel tracking to a web app, send server-side events from Node.js or Python, identify users, set up company-level group analytics, import historical events, or pull data out with the Query and Export APIs.

Как установить скилл mixpanel?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл mixpanel запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить mixpanel с