segment
БесплатноБез исполняемых скриптовНе проверенSegment is a customer data platform (CDP) that collects events from your website, apps and servers once and routes them to analytics, marketing and warehouse…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Segment
Overview
Segment is a customer data platform: your code sends events to Segment through one API, and Segment forwards them to every destination you enable (Mixpanel, Amplitude, BigQuery, Intercom and so on). Destinations are switched on and off in the Segment app without code changes. Each source (website, server, mobile app) has its own write key. Libraries checked here (npm, October 2026): @segment/analytics-next 1.84.3 for browsers and @segment/analytics-node 3.1.0 for servers (Node.js 20+). Segment's docs site blocks automated fetching, so UI paths and plan limits are not covered here; read them in the app.
Instructions
Install
npm install @segment/analytics-next # browser / React
npm install @segment/analytics-node # server
Segment can also generate a script snippet for a JavaScript source. Prefer that generated snippet over copying one from memory, since it carries the current version and your write key. With the npm package no snippet is needed.
Browser
// lib/analytics.ts
import { AnalyticsBrowser } from "@segment/analytics-next";
export const analytics = AnalyticsBrowser.load({
writeKey: process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY!,
});
AnalyticsBrowser.load is called once. If you need consent first, create new AnalyticsBrowser() and call .load({ writeKey }) after the user agrees; calls made earlier are buffered. Browser calls take positional arguments: analytics.identify("usr_8f2c1", { plan: "pro" }), analytics.track("Plan Selected", { plan: "pro" }), analytics.page("Pricing").
Server (Node.js)
import { Analytics } from "@segment/analytics-node";
const analytics = new Analytics({ writeKey: process.env.SEGMENT_WRITE_KEY! });
analytics.identify({
userId: "usr_8f2c1",
traits: { email: "[email protected]", name: "Maria Kovacs", plan: "pro" },
});
analytics.track({
userId: "usr_8f2c1",
event: "Order Completed",
properties: {
orderId: "ord_456",
total: 99.99,
currency: "USD",
products: [{ id: "prod_1", name: "Standing desk mat", price: 49.99, quantity: 2 }],
},
});
analytics.group({ userId: "usr_8f2c1", groupId: "org_789", traits: { name: "Northwind", plan: "enterprise" } });
analytics.page({ userId: "usr_8f2c1", name: "Pricing" });
analytics.alias({ userId: "usr_8f2c1", previousId: "anon_abc" });
await analytics.closeAndFlush(); // before a script, Lambda or shutdown handler exits
Server calls take one object and need userId or anonymousId (at least one). Events are batched: the client sends after 15 events or 10 seconds by default (flushAt, flushInterval), so a short-lived process that exits without closeAndFlush() loses events. Other settings: host, path, maxRetries, httpRequestTimeout, disable: true (all calls become no-ops; useful in tests).
React
import { useEffect } from "react";
import { analytics } from "@/lib/analytics";
export function PricingPage() {
useEffect(() => { analytics.page("Pricing"); }, []);
return <button onClick={() => analytics.track("Plan Selected", { plan: "pro", price: 49 })}>Choose Pro</button>;
}
In single-page apps you must call page() on route changes yourself.
Examples
Example 1: Track signups and purchases for a SaaS product
User request: "Track signups, feature usage and purchases and send them to Mixpanel, BigQuery and Intercom."
Install the browser and server packages, create one JavaScript source and one Node.js source in Segment, and put their write keys in NEXT_PUBLIC_SEGMENT_WRITE_KEY and SEGMENT_WRITE_KEY. Call identify on signup and login, track("Signed Up") from the server after the account is created, and track("Order Completed", {...}) from the payment webhook handler. Then connect the three destinations in the Segment app; no further code is needed. Confirm in the Segment app that events arrive at the source.
Example 2: Replace several analytics SDKs with Segment
User request: "We load Mixpanel, Amplitude and GA4 separately. Consolidate into one."
List the events the three SDKs send today, map them to one set of "Object Action" names, replace the SDK calls with analytics.track, and enable each tool as a Segment destination. Run old and new in parallel for a week and compare counts before removing the old SDKs.
Guidelines
- Call
identifyas soon as you know the user; latertrackcalls with thatuserIdattach to the profile. - Name events "Object Action" in past tense ("Order Completed") and keep names stable; write a tracking plan before instrumenting.
- User attributes (email, plan) go in
traits; event data (order total, product ids) goes inproperties. - Send revenue and subscription events from the server; send UI events from the browser.
- Do not send passwords, payment card numbers or health data as traits or properties. Gate loading on user consent where the law requires it.
- The write key ident
Установить segment в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл segment?
Segment is a customer data platform (CDP) that collects events from your website, apps and servers once and routes them to analytics, marketing and warehouse destinations. Use when someone asks to "track user events across tools", "set up Segment", "send events to Mixpanel, Amplitude or BigQuery", "unify analytics", or needs identify, track, page, group and alias calls in JavaScript, Node.js or React.
Как установить скилл segment?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл segment запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic