# Segment Track

> Segment analytics track call with event, properties, and context.

- Name: `segment-track`
- Categories: analytics
- Detail page: https://open-types.dev/types/segment-track

## Install

```bash
# Types only
npx shadcn add @open-types/segment-track

# Types + Zod v4 validators
npx shadcn add @open-types/segment-track-zod

# Types + real-world examples
npx shadcn add @open-types/segment-track-examples
```

## Types

```typescript
export interface SegmentTrackCall {
  userId?: string;
  anonymousId?: string;
  event: string;
  properties?: Record<string, unknown>;
  context?: Record<string, unknown>;
  timestamp?: string;
  integrations?: Record<string, boolean>;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { SegmentTrackCall } from "../types/segment-track";

export const segmentTrackCallSchema = z.object({
  userId: z.string().optional(),
  anonymousId: z.string().optional(),
  event: z.string().min(1, { error: "Event is required" }),
  properties: z.record(z.string(), z.unknown()).optional(),
  context: z.record(z.string(), z.unknown()).optional(),
  timestamp: z.iso.datetime({ error: "Invalid timestamp" }).optional(),
  integrations: z.record(z.string(), z.boolean()).optional(),
}) satisfies z.ZodType<SegmentTrackCall>;

export type { SegmentTrackCall } from "../types/segment-track";
```

## Examples

```typescript
// Source: https://segment.com/docs/connections/spec/track/
// Captured: 2026-05
import type { SegmentTrackCall } from "../types/segment-track";

const ordered = {
  userId: "97980cfea0067",
  event: "Order Completed",
  properties: {
    order_id: "ord_5051",
    total: 99.99,
    currency: "USD",
    items: [{ sku: "sku_abc", quantity: 1, price: 99.99 }],
  },
  context: {
    library: { name: "analytics.js", version: "5.10.0" },
    page: { path: "/checkout/complete", url: "https://example.com/checkout/complete" },
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
  },
  timestamp: "2026-04-13T18:30:00.000Z",
  integrations: { All: true, "Google Analytics": true, Mixpanel: false },
} as const satisfies SegmentTrackCall;

export const segmentTrackCallExamples = {
  orderCompleted: ordered,
  anonymous: {
    anonymousId: "anon_1234567890",
    event: "Product Viewed",
    properties: { product_id: "sku_abc", name: "Pro Plan" },
  } satisfies SegmentTrackCall,
  signupStarted: {
    anonymousId: "anon_2222222222",
    event: "Signup Started",
    properties: { plan: "free" },
    timestamp: "2026-04-13T18:00:00.000Z",
  } satisfies SegmentTrackCall,
  minimalIdentified: {
    userId: "user_321",
    event: "Page Viewed",
  } satisfies SegmentTrackCall,
  serverSide: {
    userId: "user_777",
    event: "Subscription Renewed",
    properties: { plan: "team", amount: 49 },
    integrations: { All: false, Webhook: true },
  } satisfies SegmentTrackCall,
} as const;
```
