Chuyển đến nội dung
Skillpedia
Phân tích và bảng tính7.6k · #13186

tracking

Skill này làm gì

Skill này giải thích cách ứng dụng gửi sự kiện sử dụng qua một hàm theo dõi duy nhất đến một hoặc nhiều dịch vụ phân tích. Skill dành cho lập trình viên thêm phân tích hoặc kết nối một nhà cung cấp phân tích mới.

Khi nào nên dùng

  • ✓Khi bạn muốn ghi lại một sự kiện, chẳng hạn người dùng lưu một ghi chú mới, trong ứng dụng.
  • ✓Khi bạn thiết lập một dịch vụ phân tích tích hợp sẵn qua biến môi trường.
  • ✓Khi bạn thêm một nhà cung cấp phân tích tùy chỉnh cho một dịch vụ khác.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/tracking/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/tracking/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Theo dõi khi có người lưu một ghi chú mới trong ứng dụng này để tôi thấy nó trong công cụ phân tích của mình.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Ứng dụng gửi mỗi sự kiện qua một hàm theo dõi duy nhất đến mọi nhà cung cấp đã kết nối. Nhà cung cấp được thiết lập từ biến môi trường và gửi theo lô, và một lỗi không bao giờ chặn người dùng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Tracking

Rule

The tracking system provides a single server-side track() call that fans out to all registered providers, plus the browser-side trackEvent() counterpart. Built-in providers auto-register from env vars - set the var and tracking starts. Custom providers can be registered for any analytics backend. Both surfaces are best-effort and never block request handling.

How It Works

  1. At server startup, registerBuiltinProviders() checks env vars and registers any configured providers.
  2. Application code calls track(eventName, properties, source) from actions, plugins, or server routes.
  3. The registry fans out the event to every registered provider. Errors are caught and logged -- a failing provider never crashes the caller.
  4. Built-in providers batch HTTP calls (flush every 10 seconds or 50 events, whichever comes first). Each send times out after 10 seconds.

API

track(name, properties?, source?)

Fire an analytics event. source is either a { userId, anonymousId, sessionId } meta object or an action's ctx passed straight through.

import { track } from "@agent-native/core/tracking";

// From an action — pass ctx; userId comes from ctx.userEmail.
run: async ({ name }, ctx) => {
  track("meal.logged", { mealName: name, calories: 350 }, ctx);
};

// From a plugin or route with no ctx.
track(
  "meal.logged",
  { mealName: "Salad", calories: 350 },
  { userId: "user@example.com" },
);

The caller's browser session comes from the ambient request context (RequestContext.browserSessionId, set from the X-Agent-Native-Session-Id header), so it resolves the same whether the UI called the action or the agent did. Pass sessionId in the meta object to override it — routes that run outside a request context, such as /_agent-native/track, do exactly that. Providers map it to their own session field: $session_id for PostHog (which joins the event to session replay), session_id as a property for Mixpanel and Amplitude, a top-level sessionId for webhooks and Agent-Native Analytics. It is absent for callers with no browser — cron, CLI, MCP, A2A.

identify(userId, traits?)

Identify a user with traits. Forwarded to providers that support it.

import { identify } from "@agent-native/core/tracking";

identify("user@example.com", { plan: "pro", company: "ExampleCo" });

registerTrackingProvider(provider)

Register a custom provider.

import { registerTrackingProvider } from "@agent-native/core/tracking";

registerTrackingProvider({
  name: "my-analytics",
  track(event) {
    // Send event to your backend
  },
  identify(userId, traits) {
    // Optional
  },
  flush() {
    // Optional -- called on graceful shutdown
  },
});

flushTracking()

Flush all providers (call before process exit).

Built-in Providers

Set the env var and the provider auto-registers at startup. No SDK dependencies -- all providers use raw HTTP.

Provider Env vars
PostHog POSTHOG_API_KEY (required), POSTHOG_HOST (optional, defaults to https://us.i.posthog.com), POSTHOG_ERROR_TRACKING=false (optional opt-out)
Mixpanel MIXPANEL_TOKEN
Amplitude AMPLITUDE_API_KEY
Agent-Native Analytics AGENT_NATIVE_ANALYTICS_PUBLIC_KEY (server), AGENT_NATIVE_ANALYTICS_ENDPOINT (optional, defaults to https://analytics.agent-native.com/track)
Webhook TRACKING_WEBHOOK_URL (required), TRACKING_WEBHOOK_AUTH (optional, sent as Authorization header)

Multiple providers can be active simultaneously. All receive every event.

Browser-side trackEvent() also forwards to Agent-Native Analytics when VITE_AGENT_NATIVE_ANALYTICS_PUBLIC_KEY is present. Use VITE_AGENT_NATIVE_ANALYTICS_ENDPOINT to override the default browser endpoint. The built-in Agent-Nat

Câu hỏi thường gặp

Một dịch vụ phân tích lỗi có thể làm hỏng ứng dụng không?

Không. Lỗi được bắt và ghi log, nên các yêu cầu vẫn tiếp tục.

Những dịch vụ nào có sẵn?

Skill nêu PostHog, Mixpanel, Amplitude và một webhook chung.

Sự kiện được gửi thế nào?

Các nhà cung cấp tích hợp gom sự kiện thành lô, gửi mỗi 10 giây hoặc khi đủ 50 sự kiện, tùy điều kiện nào đến trước.

Chi tiết

Mô tả gốc của tác giả

Server-side analytics tracking with pluggable providers. Use when adding analytics events, registering custom tracking providers, or configuring built-in providers (PostHog, Mixpanel, Amplitude, Webhook).

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13186
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự