home / skills / jeremylongshore / claude-code-plugins-plus-skills / customerio-primary-workflow

This skill helps automate Customer.io primary messaging by identifying users, tracking events, and triggering campaigns across emails, push, SMS, and in-app

npx playbooks add skill jeremylongshore/claude-code-plugins-plus-skills --skill customerio-primary-workflow

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.3 KB
---
name: customerio-primary-workflow
description: |
  Execute Customer.io primary messaging workflow.
  Use when setting up email campaigns, push notifications,
  SMS messaging, or in-app message workflows.
  Trigger with phrases like "customer.io campaign", "customer.io workflow",
  "customer.io email automation", "customer.io messaging".
allowed-tools: Read, Write, Edit, Bash(npm:*), Bash(pip:*), Grep
version: 1.0.0
license: MIT
author: Jeremy Longshore <[email protected]>
---

# Customer.io Primary Workflow

## Overview
Implement Customer.io's primary messaging workflow: identify users, track events, and trigger automated campaigns.

## Prerequisites
- Customer.io SDK configured
- Campaign/workflow created in Customer.io dashboard
- Understanding of your user lifecycle events

## Instructions

### Step 1: Define User Lifecycle Events
```typescript
// events/user-events.ts
export const USER_EVENTS = {
  // Onboarding
  SIGNED_UP: 'signed_up',
  EMAIL_VERIFIED: 'email_verified',
  PROFILE_COMPLETED: 'profile_completed',
  FIRST_LOGIN: 'first_login',

  // Engagement
  FEATURE_USED: 'feature_used',
  CONTENT_VIEWED: 'content_viewed',
  SEARCH_PERFORMED: 'search_performed',

  // Conversion
  TRIAL_STARTED: 'trial_started',
  SUBSCRIPTION_STARTED: 'subscription_started',
  UPGRADE_COMPLETED: 'upgrade_completed',
  PURCHASE_COMPLETED: 'purchase_completed',

  // Churn Risk
  INACTIVE_WARNING: 'inactive_warning',
  SUBSCRIPTION_CANCELLED: 'subscription_cancelled',
  ACCOUNT_DELETED: 'account_deleted',
} as const;

export type UserEvent = typeof USER_EVENTS[keyof typeof USER_EVENTS];
```

### Step 2: Implement Event Tracking Service
```typescript
// services/customerio-service.ts
import { TrackClient, RegionUS } from '@customerio/track';
import { USER_EVENTS, UserEvent } from '../events/user-events';

interface User {
  id: string;
  email: string;
  firstName?: string;
  lastName?: string;
  plan?: string;
}

export class CustomerIOService {
  private client: TrackClient;

  constructor() {
    this.client = new TrackClient(
      process.env.CUSTOMERIO_SITE_ID!,
      process.env.CUSTOMERIO_API_KEY!,
      { region: RegionUS }
    );
  }

  // Called on user signup
  async onSignup(user: User): Promise<void> {
    await this.client.identify(user.id, {
      email: user.email,
      first_name: user.firstName,
      last_name: user.lastName,
      created_at: Math.floor(Date.now() / 1000),
      plan: 'free',
      onboarding_status: 'started'
    });

    await this.track(user.id, USER_EVENTS.SIGNED_UP, {
      signup_source: 'web',
      signup_date: new Date().toISOString()
    });
  }

  // Called when email is verified
  async onEmailVerified(userId: string): Promise<void> {
    await this.updateUser(userId, {
      email_verified: true,
      email_verified_at: Math.floor(Date.now() / 1000)
    });
    await this.track(userId, USER_EVENTS.EMAIL_VERIFIED);
  }

  // Called on subscription change
  async onSubscriptionStarted(userId: string, plan: string): Promise<void> {
    await this.updateUser(userId, {
      plan,
      subscription_started_at: Math.floor(Date.now() / 1000)
    });
    await this.track(userId, USER_EVENTS.SUBSCRIPTION_STARTED, { plan });
  }

  // Generic tracking method
  async track(userId: string, event: UserEvent, data?: Record<string, any>): Promise<void> {
    await this.client.track(userId, {
      name: event,
      data: {
        ...data,
        timestamp: new Date().toISOString()
      }
    });
  }

  // Update user attributes
  async updateUser(userId: string, attributes: Record<string, any>): Promise<void> {
    await this.client.identify(userId, attributes);
  }
}

export const cioService = new CustomerIOService();
```

### Step 3: Integrate with Application
```typescript
// routes/auth.ts
import { cioService } from '../services/customerio-service';

app.post('/signup', async (req, res) => {
  const user = await createUser(req.body);

  // Fire and forget - don't block signup on analytics
  cioService.onSignup({
    id: user.id,
    email: user.email,
    firstName: user.firstName,
    lastName: user.lastName
  }).catch(err => console.error('Customer.io error:', err));

  res.json({ user });
});

app.post('/verify-email', async (req, res) => {
  const userId = await verifyEmailToken(req.body.token);

  cioService.onEmailVerified(userId)
    .catch(err => console.error('Customer.io error:', err));

  res.json({ success: true });
});
```

### Step 4: Create Dashboard Campaign
In Customer.io Dashboard:
1. Go to Campaigns > Create Campaign
2. Select trigger: Event "signed_up"
3. Add workflow steps:
   - Wait 1 day
   - Send welcome email
   - Wait 3 days
   - Branch: if email_verified = false, send reminder
   - Continue nurture sequence

## Output
- User lifecycle event definitions
- Customer.io service integration
- Application route integration
- Campaign workflow triggering

## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| Event not triggering | Wrong event name | Match exact event name in dashboard |
| User not receiving | Missing email attribute | Ensure email is set on identify |
| Duplicate sends | Multiple event fires | Deduplicate or use idempotency |

## Resources
- [Customer.io Campaigns](https://customer.io/docs/campaigns/)
- [Trigger Events](https://customer.io/docs/events/)

## Next Steps
After implementing primary workflow, proceed to `customerio-core-feature` for advanced features.

Overview

This skill executes a Customer.io primary messaging workflow to identify users, track lifecycle events, and trigger automated campaigns. It provides a ready pattern for onboarding, engagement, conversion, and churn-risk events so you can wire application actions to Customer.io campaigns quickly. Use it to send emails, push, SMS, or in-app messages driven by real user events.

How this skill works

The skill defines a set of canonical user events and exposes a Customer.io service that identifies users, updates attributes, and tracks events. Application routes call the service (fire-and-forget recommended) on signup, email verification, subscription changes, and other lifecycle moments. Events in Customer.io dashboard are configured to trigger campaigns and workflow branches using the same event names and attributes.

When to use it

  • When onboarding events should trigger welcome emails and nurture sequences
  • When you need to sync user attributes and send targeted messaging based on plan or verification state
  • When converting trial users to paid plans and measuring conversion events
  • When implementing re-engagement or churn-prevention workflows
  • When adding analytics-driven push, SMS, or in-app messages tied to specific user actions

Best practices

  • Keep event names consistent between code and Customer.io dashboard to avoid missed triggers
  • Identify users with email and created_at, and update attributes before tracking events when possible
  • Use fire-and-forget calls for non-blocking user flows, and log errors for retry or monitoring
  • Include timestamps and source metadata in event data for clearer segmentation and debugging
  • Deduplicate event emission in your app to prevent duplicate sends; consider idempotency where needed

Example use cases

  • Trigger a welcome email 1 day after 'signed_up' and branch if 'email_verified' is false to send a reminder
  • Track 'subscription_started' with plan attribute to kick off billing-related onboarding messages
  • Send churn warnings when 'inactive_warning' or 'subscription_cancelled' events occur
  • Record feature usage events like 'feature_used' for behavior-based in-app messaging
  • Update user profile attributes on changes to enable precise audience segmentation in campaigns

FAQ

What must be configured before using this workflow?

Install and configure the Customer.io SDK with site ID and API key, and create campaigns/triggers in the Customer.io dashboard.

Should I block signup until Customer.io calls succeed?

No. Use fire-and-forget for identify/track calls and surface errors to logs or background retries to avoid slowing user flows.