posthog-core-workflow-a
Implement PostHog product analytics: event capture, user identification, group analytics, and property management using posthog-js and posthog-node. Trigger: "posthog analytics", "capture events", "track users posthog", "posthog identify", "posthog group analytics", "product analytics".
What this skill does
# PostHog Core Workflow A — Product Analytics
## Overview
Primary PostHog workflow covering event capture, user identification, group analytics, and person properties. This is the foundation for all PostHog analytics: capturing what users do, linking events to identified users, and grouping users by company/team for B2B analytics.
## Prerequisites
- Completed `posthog-install-auth` setup
- `posthog-js` (browser) and/or `posthog-node` (server) installed
- Project API key (`phc_...`) configured
## Instructions
### Step 1: Define Event Taxonomy
```typescript
// src/analytics/events.ts
// Define all events as typed constants for consistency
export const EVENTS = {
// User lifecycle
USER_SIGNED_UP: 'user_signed_up',
USER_LOGGED_IN: 'user_logged_in',
USER_ONBOARDING_COMPLETED: 'user_onboarding_completed',
// Core product actions
FEATURE_USED: 'feature_used',
ITEM_CREATED: 'item_created',
ITEM_UPDATED: 'item_updated',
ITEM_DELETED: 'item_deleted',
SEARCH_PERFORMED: 'search_performed',
EXPORT_COMPLETED: 'export_completed',
// Revenue events
SUBSCRIPTION_STARTED: 'subscription_started',
SUBSCRIPTION_UPGRADED: 'subscription_upgraded',
SUBSCRIPTION_CANCELED: 'subscription_canceled',
PAYMENT_COMPLETED: 'payment_completed',
} as const;
// Standard property schema for consistency across events
interface BaseProperties {
source?: 'web' | 'mobile' | 'api' | 'webhook';
plan_tier?: 'free' | 'pro' | 'enterprise';
duration_ms?: number;
}
```
### Step 2: Capture Events (Browser)
```typescript
import posthog from 'posthog-js';
import { EVENTS } from './events';
// Custom event with properties
posthog.capture(EVENTS.ITEM_CREATED, {
item_type: 'document',
source: 'web',
plan_tier: 'pro',
});
// Timed event (measure duration)
const start = performance.now();
await doExpensiveOperation();
posthog.capture(EVENTS.EXPORT_COMPLETED, {
format: 'csv',
row_count: 1500,
duration_ms: Math.round(performance.now() - start),
});
// Pageview with custom properties (if capture_pageview: false)
posthog.capture('$pageview', {
page_title: document.title,
referrer: document.referrer,
});
```
### Step 3: Identify Users and Set Properties
```typescript
// After user logs in — links anonymous events to this user
posthog.identify('user-456', {
// $set properties (persist, overwrite on change)
email: '[email protected]',
name: 'Jane Smith',
plan: 'enterprise',
signup_date: '2025-06-15',
});
// Update properties later without re-identifying
posthog.people.set({
last_active: new Date().toISOString(),
total_items: 42,
});
// Set properties only if not already set ($set_once)
posthog.people.set_once({
first_seen: new Date().toISOString(),
original_referrer: document.referrer,
});
// Unset properties
posthog.people.unset(['deprecated_field']);
// Reset on logout (clears distinct_id, starts new anonymous session)
posthog.reset();
```
### Step 4: Group Analytics (B2B Company Tracking)
```typescript
// Associate user with a company group
posthog.group('company', 'company-789', {
name: 'Acme Corp',
industry: 'SaaS',
plan: 'enterprise',
employee_count: 150,
arr: 250000,
});
// Events now automatically include company context
posthog.capture(EVENTS.FEATURE_USED, {
feature_name: 'bulk-export',
});
// This event is attributed to both user-456 AND company-789
// Multiple group types
posthog.group('team', 'team-alpha', { name: 'Alpha Team' });
```
### Step 5: Server-Side Event Capture (posthog-node)
```typescript
import { PostHog } from 'posthog-node';
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
host: 'https://us.i.posthog.com',
});
// Server-side capture (e.g., in API route or webhook handler)
function trackServerEvent(userId: string, event: string, properties?: Record<string, any>) {
posthog.capture({
distinctId: userId,
event,
properties: {
...properties,
source: 'api',
},
});
}
// Identify with server-side properties
posthog.identify({
distinctId: 'user-456',
properties: {
subscription_status: 'active',
mrr: 99,
},
});
// Group identify from server
posthog.groupIdentify({
groupType: 'company',
groupKey: 'company-789',
properties: {
plan: 'enterprise',
total_seats: 50,
},
});
// CRITICAL: Flush in serverless/edge functions
await posthog.flush();
```
### Step 6: Create Annotations for Context
```bash
set -euo pipefail
# Mark a deployment or product change in PostHog
curl -X POST "https://app.posthog.com/api/projects/$POSTHOG_PROJECT_ID/annotations/" \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"content": "v2.5.0 deployed — new checkout flow",
"date_marker": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'",
"scope": "project"
}'
```
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Events not appearing | `posthog.init` not called | Ensure init runs before any capture |
| Anonymous/identified split | Different `distinct_id` across platforms | Use consistent user ID from your auth system |
| Group data missing | `posthog.group()` not called | Call `group()` before capture for group attribution |
| Server events lost | No `flush()` in serverless | Always call `await posthog.flush()` before response |
| Properties not updating | Using `$set_once` for mutable data | Use `posthog.people.set()` for values that change |
## Output
- Typed event taxonomy for consistent tracking
- Browser event capture with user identification
- B2B group analytics linking users to companies
- Server-side event capture with proper flushing
- Annotations marking deployments and product changes
## Resources
- [Capture Events](https://posthog.com/docs/product-analytics/capture-events)
- [Identifying Users](https://posthog.com/docs/product-analytics/identify)
- [Group Analytics](https://posthog.com/docs/product-analytics/group-analytics)
- [Annotations API](https://posthog.com/docs/api/annotations)
## Next Steps
For feature flags and experiments, see `posthog-core-workflow-b`.
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.