Integrate Segment CDP for Customer Data
Segment CDP implementation patterns: Analytics.js, server-side Node.js tracking, typed tracking plans, and destination routing.
Why it matters
Leverage Segment CDP for robust customer data analysis and management. This asset provides expert patterns for client-side and server-side tracking, enabling comprehensive user journey mapping and data governance.
Outcomes
What it gets done
Implement Analytics.js for browser-based event tracking.
Set up server-side tracking with Node.js for backend events and webhooks.
Design and enforce tracking plans using Segment Protocols for data quality.
Configure identity resolution and destination management.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-segment-cdp | bash Overview
Segment CDP
Provides Segment CDP implementation patterns: Analytics.js and server-side tracking, typed tracking plans, identity resolution, and destination routing. Use when implementing Segment tracking, designing a tracking plan, resolving user identity, or routing events to destinations.
What it does
Provides expert implementation patterns for the Segment Customer Data Platform, covering Analytics.js browser tracking, server-side Node.js tracking, typed tracking plans enforced via Protocols, identity resolution, destinations configuration, and data governance.
When to use - and when NOT to
Use this skill when implementing client-side Analytics.js tracking, server-side event tracking for webhooks or backend events, designing a typed tracking plan with required properties, merging anonymous and identified users, routing events to specific destinations, or tracking from edge/serverless environments via the HTTP API. Not a fit for A/B testing integration, data warehouse pipelines, or consent-management setup, which route to dedicated skills.
Inputs and outputs
Client-side patterns use @segment/analytics-next's AnalyticsBrowser, with typed identify/track/page/group helpers and a Next.js usePageTracking hook that fires a page call on route change. Server-side patterns use @segment/analytics-node with batched, non-blocking identify/track calls, a closeAndFlush on shutdown, and a Stripe-webhook example that tracks Order Completed and Subscription Started events with graceful SIGTERM handling.
Tracking-plan design uses Object + Action event naming, a conceptual Protocols YAML schema defining required properties and enums per event, and a TypeScript TrackingEvents interface with a type-safe trackEvent function that catches missing required properties at compile time. Identity resolution covers anonymous tracking, identify() to merge anonymous history into a user profile, group() for B2B company association, and alias() to link a temporary ID to a permanent user ID (one-way, called once at signup) - with a full signup flow example chaining identify, track, and group.
Destinations configuration shows per-destination integrations overrides (e.g., routing revenue events only to GA4/Mixpanel/Amplitude, or PII only to HubSpot/Salesforce/Warehouse while excluding analytics tools) and context enrichment for every event. An HTTP Tracking API section covers direct calls for edge/serverless environments (500KB batch limit, 32KB per event) with a Cloudflare Worker example.
Documents eight sharp edges (anonymous ID persistence, device-mode bypassing Protocols blocking, HTTP API size limits, tracking-before-consent GDPR violations) and nine validation checks covering dynamic event names, inconsistent casing, missing identify before revenue tracking, hardcoded write keys, and oversized property values.
Integrations
Built on @segment/analytics-next (browser), @segment/analytics-node (server), and Segment's raw HTTP Tracking API for edge/serverless use, with destination routing to tools like Google Analytics 4, Mixpanel, Amplitude, HubSpot, and Salesforce, and Protocols for tracking-plan enforcement.
Who it's for
Frontend and backend engineers implementing Segment tracking who need typed, validated event schemas and destination-aware routing rather than untyped analytics.track() calls scattered across the codebase.
export function trackEvent<T extends keyof TrackingEvents>(event: T, properties: TrackingEvents[T]) {
analytics.track(event, properties);
}
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.