计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
klaviyo-core-workflow-b【效率与协作】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", "kla…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
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:
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.
klaviyo-core-workflow-a (profiles/lists set up)events:write, segments:read, campaigns:read, campaigns:write, flows:readklaviyo-api installed and KLAVIYO_PRIVATE_KEY set in the environmentOpen 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!);
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.MetricsApi.getMetrics() lists event types;
EventsApi.getEvents({ sort: '-datetime', filter: 'equals(metric_id,"...")' }) reads recent events.SegmentsApi.getSegments() lists them,
getSegmentProfiles() reads members, and getSegment({ additionalFieldsSegment: ['profile_count'] })
returns the size — check it before a send.audiences.included/excluded), assign the template to the campaign message,
then create the campaign-send-job. Sending before the template is assigned returns a 400.FlowsApi.getFlows() lists flows;
getFlowFlowActions({ id }) returns each flow's steps and their status.body.data array of records with id and
attributes (name, status, profileCount, etc.).id; the send job queues the campaign, and Klaviyo
reports delivery back in the app's campaign analytics.| Event name | Typical trigger | Flow type |
|---|---|---|
Placed Order | Purchase completed | Post-purchase / cross-sell |
Started Checkout | Cart created | Abandoned cart |
Viewed Product | Product page visit | Browse abandonment |
Ordered Product | Per-item tracking | Product review request |
Fulfilled Order | Shipment sent | Shipping confirmation |
Cancelled Order | Order cancelled | Win-back |
Subscribed to List | Email/SMS signup | Welcome series |
Custom Event | Any API event | Custom automation |
| Error | Status | Cause | Solution |
|---|---|---|---|
| Invalid metric name | 400 | Empty or null metric | Always include metric.data.attributes.name |
| Segment not found | 404 | Wrong segment ID | List segments with getSegments() |
| Campaign send failed | 400 | Missing template/audience | Assign template and set audience first |
| Duplicate event | N/A | Same uniqueId | Deduplication built-in; safe to retry |
Concrete, runnable scenarios are collected in references/examples.md:
Started Checkout event for a flow to pick up.profileCount and refuse to send to an empty audience.A minimal event track:
import { EventsApi, EventEnum, ProfileEnum } from 'klaviyo-api';
const eventsApi = new EventsApi(session);
await eventsApi.createEvent({
data: {
type: EventEnum.Event,
attributes: {
metric: { data: { type: 'metric', attributes: { name: 'Placed Order' } } },
profile: { data: { type: ProfileEnum.Profile, attributes: { email: 'customer@example.com' } } },
value: 99.97,
time: new Date().toISOString(),
uniqueId: 'ORD-12345',
},
},
});
klaviyo-common-errors skill.