| name | klaviyo-core-workflow-b |
| description | Execute the Klaviyo secondary workflow: event tracking, segments, and campaigns.
Use when you need to track customer events, query or size segments, build and send
email campaigns, or inspect metric-triggered flows through the Klaviyo API.
Trigger with phrases like "klaviyo events", "klaviyo segments", "klaviyo campaigns",
"track klaviyo event", "klaviyo flow trigger".
|
| allowed-tools | Read, Write, Bash(npm:*) |
| version | 1.7.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","klaviyo","email-marketing","cdp"] |
| compatibility | Designed for Claude Code |
Klaviyo Core Workflow B -- Events, Segments & Campaigns
Overview
Secondary workflow: track customer events, query segments, create/send campaigns, and
trigger metric-based flows via the klaviyo-api SDK. This page summarizes the five steps
and their skeletons; the full copy-ready code lives in
references/implementation.md and worked scenarios in
references/examples.md.
Prerequisites
- Completed
klaviyo-core-workflow-a (profiles/lists set up)
- API key scopes:
events:write, segments:read, campaigns:read, campaigns:write, flows:read
klaviyo-api installed and KLAVIYO_PRIVATE_KEY set in the environment
Instructions
Open one session, then use the API class each step needs. Full parameter shapes for every
step are in references/implementation.md.
import { ApiKeySession, EventsApi } from 'klaviyo-api';
const session = new ApiKeySession(process.env.KLAVIYO_PRIVATE_KEY!);
- Step 1 — Track server-side events.
new EventsApi(session).createEvent(...). Include
metric.data.attributes.name (auto-creates the metric), a profile, a value for revenue
attribution, and a uniqueId for deduplication. Custom metrics trigger listening flows.
- Step 2 — Query events and metrics.
MetricsApi.getMetrics() lists event types;
EventsApi.getEvents({ sort: '-datetime', filter: 'equals(metric_id,"...")' }) reads recent events.
- Step 3 — Work with segments.
SegmentsApi.getSegments() lists them,
getSegmentProfiles() reads members, and getSegment({ additionalFieldsSegment: ['profile_count'] })
returns the size — check it before a send.