Skip to content
Skillpedia
Analysis & spreadsheets7.6k · #13186

tracking

What it does

This skill explains how an app sends usage events through one tracking function to one or more analytics services. It is for developers adding analytics or connecting a new analytics provider.

When to use it

  • ✓When you want to record an event, such as a user saving a new note, in an app.
  • ✓When you set up a built-in analytics service through environment settings.
  • ✓When you add a custom analytics provider for a different service.

Skill link

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

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/tracking/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Track when someone saves a new note in this app so I can see it in my analytics tool.”

5 new skills a week. 1 minute to read.

How it works

The app sends each event through one tracking function to every connected provider. Providers are set up from environment variables and send in batches, and a failure never blocks the user.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

FAQ

Can a failing analytics service break the app?

No. Errors are caught and logged, so requests keep going.

Which services are built in?

The skill names PostHog, Mixpanel, Amplitude, and a generic webhook.

How are events sent?

Built-in providers batch events, sending every 10 seconds or every 50 events, whichever comes first.

Details

Original description by the author

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

Popularity

GitHub stars
7.6k
Ranking position
#13186
License
MIT
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills