Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Apply production-ready Customer.io SDK patterns. Use when implementing typed clients, retry logic, event batching, or singleton management for customerio-node. Trigger: "customer.io best practices", "customer.io patterns", "production customer.io", "customer.io architecture", "customer.io singleton".
.claude/skills/jeremylongshore-customerio-sdk-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 39% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 69% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 59% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 84% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 66% | 0% |
Production-ready patterns for customerio-node: type-safe wrappers with enum-constrained events, retry with exponential backoff, event batching for high-volume scenarios, and singleton lifecycle management.
customerio-node installedtypescript// lib/customerio-typed.ts import { TrackClient, RegionUS, RegionEU } from "customerio-node"; // Define your event taxonomy as a union type type CioEvent = | { name: "signed_up"; data: { method: string; source?: string } } | { name: "plan_changed"; data: { from: string; to: string; mrr: number } } | { name: "feature_used"; data: { feature: string; duration_ms?: number } } | { name: "checkout_completed"; data: { order_id: string; total: number; items: number } } | { name: "subscription_cancelled"; data: { reason: string; feedback?: string } }; // Define user attributes with strict types interface CioUserAttributes { email: string; first_name?: string; last_name?: string; plan?: "free" | "starter" | "pro" | "enterprise"; company?: string; created_at?: number; // Unix seconds last_seen_at?: number; // Unix seconds [key: string]: unknown; // Allow additional attributes } export class TypedCioClient { private client: TrackClient; constructor(siteId: string, apiKey: string, region: "us" | "eu" = "us") { this.client = new TrackClient(siteId, apiKey, { region: region === "eu" ? RegionEU : RegionUS, }); } async identify(userId: string, attributes: CioUserAttributes): Promise<void> { await this.client.identify(userId, { ...attributes, last_seen_at: Math.floor(Date.now() / 1000), }); } async track(userId: string, event: CioEvent): Promise<void> { await this.client.track(userId, { name: event.name, data: { ...event.data, tracked_at: Math.floor(Date.now() / 1000) }, }); } async suppress(userId: string): Promise<void> { await this.client.suppress(userId); } async destroy(userId: string): Promise<void> { await this.client.destroy(userId); } }
typescript// lib/customerio-retry.ts interface RetryOptions { maxRetries: number; baseDelayMs: number; maxDelayMs: number; jitterFactor: number; // 0 to 1 } const DEFAULT_RETRY: RetryOptions = { maxRetries: 3, baseDelayMs: 1000, maxDelayMs: 30000, jitterFactor: 0.3, }; async function withRetry<T>( fn: () => Promise<T>, opts: RetryOptions = DEFAULT_RETRY ): Promise<T> { let lastError: Error | undefined; for (let attempt = 0; attempt <= opts.maxRetries; attempt++) { try { return await fn(); } catch (err: any) { lastError = err; const statusCode = err.statusCode ?? err.status; // Don't retry client errors (except 429 rate limit) if (statusCode >= 400 && statusCode < 500 && statusCode !== 429) { throw err; } if (attempt === opts.maxRetries) break; // Exponential backoff with jitter const delay = Math.min( opts.baseDelayMs * Math.pow(2, attempt), opts.maxDelayMs ); const jitter = delay * opts.jitterFactor * Math.random(); await new Promise((r) => setTimeout(r, delay + jitter)); } } throw lastError; } // Usage with Customer.io client import { TrackClient, RegionUS } from "customerio-node"; const cio = new TrackClient( process.env.CUSTOMERIO_SITE_ID!, process.env.CUSTOMERIO_TRACK_API_KEY!, { region: RegionUS } ); // Wrap any operation with retry await withRetry(() => cio.identify("user-123", { email: "user@example.com" }) ); await withRetry(() => cio.track("user-123", { name: "page_viewed", data: { url: "/pricing" } }) );
typescript// lib/customerio-batch.ts import { TrackClient, RegionUS } from "customerio-node"; interface QueuedEvent { userId: string; name: string; data?: Record<string, any>; } export class CioBatchTracker { private queue: QueuedEvent[] = []; private timer: NodeJS.Timeout | null = null; private client: TrackClient; constructor( private readonly batchSize: number = 50, private readonly flushIntervalMs: number = 5000 ) { this.client = new TrackClient( process.env.CUSTOMERIO_SITE_ID!, process.env.CUSTOMERIO_TRACK_API_KEY!, { region: RegionUS } ); this.startTimer(); } enqueue(userId: string, name: string, data?: Record<string, any>): void { this.queue.push({ userId, name, data }); if (this.queue.length >= this.batchSize) { this.flush(); } } async flush(): Promise<void> { if (this.queue.length === 0) return; const batch = this.queue.splice(0, this.batchSize); const concurrency = 10; for (let i = 0; i < batch.length; i += concurrency) { const chunk = batch.slice(i, i + concurrency); await Promise.allSettled( chunk.map((event) => this.client.track(event.userId, { name: event.name, data: event.data, }) ) ); } } private startTimer(): void { this.timer = setInterval(() => this.flush(), this.flushIntervalMs); } async shutdown(): Promise<void> { if (this.timer) clearInterval(this.timer); await this.flush(); } } // Usage const tracker = new CioBatchTracker(50, 5000); // Non-blocking — events are queued and flushed automatically tracker.enqueue("user-1", "page_viewed", { url: "/home" }); tracker.enqueue("user-2", "button_clicked", { button: "cta" }); // On process exit process.on("SIGTERM", async () => { await tracker.shutdown(); process.exit(0); });
typescript// lib/customerio-singleton.ts import { TrackClient, APIClient, RegionUS, RegionEU } from "customerio-node"; class CioClientFactory { private static trackInstance: TrackClient | null = null; private static appInstance: APIClient | null = null; static getTrackClient(): TrackClient { if (!this.trackInstance) { const siteId = process.env.CUSTOMERIO_SITE_ID; const apiKey = process.env.CUSTOMERIO_TRACK_API_KEY; if (!siteId || !apiKey) { throw new Error( "Missing CUSTOMERIO_SITE_ID or CUSTOMERIO_TRACK_API_KEY. " + "Set these in your environment or .env file." ); } const region = process.env.CUSTOMERIO_REGION === "eu" ? RegionEU : RegionUS; this.trackInstance = new TrackClient(siteId, apiKey, { region }); } return this.trackInstance; } static getAppClient(): APIClient { if (!this.appInstance) { const appKey = process.env.CUSTOMERIO_APP_API_KEY; if (!appKey) { throw new Error( "Missing CUSTOMERIO_APP_API_KEY. " + "Set this in your environment or .env file." ); } const region = process.env.CUSTOMERIO_REGION === "eu" ? RegionEU : RegionUS; this.appInstance = new APIClient(appKey, { region }); } return this.appInstance; } /** Reset for testing */ static reset(): void { this.trackInstance = null; this.appInstance = null; } } // Usage — same instance everywhere const cio = CioClientFactory.getTrackClient(); const api = CioClientFactory.getAppClient();
| Pattern | When to Use | Key Benefit | |---------|------------|-------------| | Typed Client | Always | Compile-time safety on events + attributes | | Retry + Backoff | Production API calls | Handles transient 5xx and 429 errors | | Batch Queue | High-volume tracking (>100 events/sec) | Reduces connection overhead, respects rate limits | | Singleton Factory | Multi-module apps | Prevents connection leaks, validates config once |
| Error | Cause | Solution | |-------|-------|----------| | Type mismatch | Wrong event data shape | Use TypeScript union types for events | | Queue memory growth | Events produced faster than flushed | Lower batchSize, increase flush frequency | | Retry exhausted (3x) | Persistent API failure | Check credentials, Customer.io status page | | Singleton null credentials | Env vars not loaded | Ensure dotenv loads before client creation |
After implementing patterns, proceed to customerio-primary-workflow for messaging workflows.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 18,057 | 12,756 | -29% | 1 | 1 | 0% | 4,082 | 5,664 | +39% | 0 | 0 | — |
case-02 | fail→fail | 15,352 | 16,475 | +7% | 1 | 1 | 0% | 3,356 | 6,239 | +86% | 0 | 0 | — |
case-03 | fail→fail | 18,967 | 17,707 | -7% | 1 | 1 | 0% | 4,169 | 6,555 | +57% | 0 | 0 | — |
case-04 | pass→pass | 8,020 | 11,361 | +42% | 1 | 1 | 0% | 1,659 | 4,854 | +193% | 0 | 0 | — |
case-05 | pass→pass | 11,573 | 13,739 | +19% | 1 | 1 | 0% | 2,550 | 5,295 | +108% | 0 | 0 | — |
case-06 | pass→pass | 8,655 | 6,320 | -27% | 1 | 1 | 0% | 1,651 | 3,930 | +138% | 0 | 0 | — |
case-07 | pass→pass | 14,993 | 8,303 | -45% | 1 | 1 | 0% | 3,059 | 4,274 | +40% | 0 | 0 | — |
case-08 | pass→pass | 13,231 | 13,672 | +3% | 1 | 1 | 0% | 2,663 | 5,352 | +101% | 0 | 0 | — |
case-09 | fail→pass | 10,952 | 5,355 | -51% | 1 | 1 | 0% | 2,093 | 3,544 | +69% | 0 | 0 | — |
case-10 | fail→pass | 13,017 | 6,667 | -49% | 1 | 1 | 0% | 2,423 | 3,846 | +59% | 0 | 0 | — |
case-11 | fail→fail | 13,012 | 8,715 | -33% | 1 | 1 | 0% | 2,312 | 3,966 | +72% | 0 | 0 | — |
case-12 | fail→pass | 13,071 | 7,734 | -41% | 1 | 1 | 0% | 2,144 | 3,953 | +84% | 0 | 0 | — |
case-13 | fail→pass | 13,131 | 9,215 | -30% | 1 | 1 | 0% | 2,727 | 4,540 | +66% | 0 | 0 | — |
case-14 | fail→pass | 13,518 | 5,597 | -59% | 1 | 1 | 0% | 2,502 | 3,614 | +44% | 0 | 0 | — |
case-15 | pass→pass | 9,354 | 6,596 | -29% | 1 | 1 | 0% | 1,699 | 3,923 | +131% | 0 | 0 | — |
case-16 | pass→pass | 14,509 | 10,828 | -25% | 1 | 1 | 0% | 2,933 | 4,748 | +62% | 0 | 0 | — |
case-17 | fail→pass | 9,012 | 1,847 | -80% | 1 | 1 | 0% | 1,660 | 2,833 | +71% | 0 | 0 | — |
case-18 | fail→pass | 9,848 | 5,662 | -43% | 1 | 1 | 0% | 1,724 | 3,651 | +112% | 0 | 0 | — |
case-19 | fail→pass | 15,118 | 10,042 | -34% | 1 | 1 | 0% | 2,943 | 4,433 | +51% | 0 | 0 | — |
case-20 | pass→pass | 12,497 | 5,747 | -54% | 1 | 1 | 0% | 2,366 | 3,623 | +53% | 0 | 0 | — |
case-21 | pass→pass | 7,495 | 3,426 | -54% | 1 | 1 | 0% | 1,544 | 3,144 | +104% | 0 | 0 | — |
case-22 | pass→pass | 11,485 | 8,278 | -28% | 1 | 1 | 0% | 2,104 | 3,841 | +83% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +41 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.