@happyvertical/ smrt- 市场营销
跨频道运动模型、不可改变的性能快照、计算 s-m-r-t的可重用Svelte营销表面.
pnpm add @happyvertical/smrt-marketing
import {
BudgetPacingService,
CampaignChannelCollection,
CampaignCollection,
MetricIngestionService,
} from '@happyvertical/smrt-marketing';
const campaigns = await CampaignCollection.create({ db });
const channels = await CampaignChannelCollection.create({ db });
const campaign = await campaigns.create({
tenantId,
customerId,
campaignKey: 'summer-demand-2026',
name: 'Summer demand 2026',
objective: 'demand_generation',
budgetCents: 200_000,
currency: 'CAD',
});
if (!campaign.id) throw new Error('Campaign did not persist');
const adGroup = await channels.create({
tenantId,
campaignId: campaign.id,
channelKind: 'ad_group',
channelRef: 'ad-group-42',
allocatedBudgetCents: 150_000,
});
if (!adGroup.id) throw new Error('Campaign channel did not persist');
const ingestion = await MetricIngestionService.create({ db });
await ingestion.ingest({
tenantId,
campaignId: campaign.id,
campaignChannelId: adGroup.id,
periodStart: new Date('2026-07-01T00:00:00Z'),
periodEnd: new Date('2026-07-01T23:59:59Z'),
spendCents: 12_500,
impressions: 25_000,
clicks: 800,
conversions: 35,
leads: 20,
source: 'ad-platform',
// Unique per tenant: (tenant_id, dedupe_key). A replay by the same owner
// returns the original snapshot unchanged.
dedupeKey: 'summer-demand-2026:ad-group-42:2026-07-01',
});
// Channel-scoped evidence is accepted only when the channel belongs to the
// supplied campaign. Reporting periods are required valid date-like values.
const pacing = await BudgetPacingService.create({ db });
console.log(await pacing.getCampaignPacing(campaign.id));
客户范围运动读取
Campaign.customerId 是本地的UUID关系
@happyvertical/smrt-commerce:Customer运动及其客户必须
完全相同的租户, 顾客范围阅读要求租户
明确(null 选择全球/全球范围)。 相关运动储蓄
验证并持续一项交易;客户范围为验证和
在一个交易中查询。 客户失踪和交叉租户失败
CampaignCustomerScopeError 但不透露发生什么情况.
const firstPage = await campaigns.listByCustomer(tenantId, customerId, {
limit: 50,
});
const secondPage = firstPage.nextCursor
? await campaigns.listByCustomer(tenantId, customerId, {
limit: 50,
after: firstPage.nextCursor,
})
: null;
const summaries = await campaigns.summarizeByCustomers(tenantId, customerIds);
// [{ customerId, totalCount, activeCount, latestStartAt }]
const reporting = await campaigns.listReportingByCustomer(
tenantId,
customerId,
{
limit: 50,
after: firstPage.nextCursor ?? undefined,
at: new Date('2026-08-15T00:00:00Z'),
},
);
// reporting.items keeps the same newest-first page order. Every item contains:
// { campaign, channelCount, channelMix, metricTotals, pacing }
页数、报告页数和摘要批次上限为100个项目并拒绝
更大的投入。 贴子是最新的第一 startAt,然后UUID;运动
没有开始时间 遵循预定的运动. listReportingByCustomer()
验证客户范围并在一次交易中读取页面,然后执行
一个被分组的频道读取,一个被分组的不可改变证据读取,无论
页面大小. metricTotals 使用与
BudgetPacingService:每个具体时期,一次竞选活动将取代其
频道快照, 而频道只保留时段 . pacing 因此为
等值为 getCampaignPacing() 没有每个阵营的回调或懒惰
负载。 摘要解析同样使用受约束的分组查询,而不是
装入租户活动或每个客户发出一个查询.
移动基于元数据的协会
- 应用生成的添加无效本地- UUID 的图案迁移
campaigns.customer_id编辑(tenant_id, customer_id, start_at, id)指数. - 在操作员拥有的数据迁移中 提取旧的元数据客户代号,
证实它存在于商业中 并且完全一样
tenant_id,则 写入customer_id。停止查找缺失、畸形或不匹配的值. - 通过
listByCustomer()或者说summarizeByCustomers(),然后更新消费者使用这些API. - 校验后删除旧的元数据密钥 。 市场从来没有读过 兼容性回落,所以没有全租户的JSON或原始SQL路径 保持同步.
从 @happyvertical/smrt-marketing/svelte。 。 。 .
它们具有展示性,并接受平面视图模型;消费者仍留在
控制取取和变异.
见 一般事务人员(其他职等) 寿命周期、证据和包件边界 变化无常.