@happyvertical/ smrt-ads (欢快的垂直)
S-m-r-t框架的广告投放和跟踪模型. 支持以分级瀑布、IAB广告格式、加权A/B变异测试和不可变事件跟踪为主的广告团体提供.
安装
pnpm add @happyvertical/smrt-ads
使用量
import {
AdDeliveryTier, AdDeliveryTierCollection,
AdGroup, AdGroupCollection,
AdVariation, AdVariationCollection,
AdEvent, AdEventCollection,
AdEventType, PricingModel, AdGroupStatus
} from '@happyvertical/smrt-ads';
// Define delivery tiers (lower priority number = served first)
const tiers = await AdDeliveryTierCollection.create({ db });
const sponsorship = await tiers.create({
name: 'Sponsorship',
priority: 1,
pricingModel: PricingModel.FIXED,
});
const standard = await tiers.create({
name: 'Standard',
priority: 2,
pricingModel: PricingModel.CPM,
});
// Create an ad group with targeting and budget
const groups = await AdGroupCollection.create({ db });
const group = await groups.create({
name: 'Holiday Campaign',
tierId: sponsorship.id,
contractId: 'contract-uuid',
status: AdGroupStatus.ACTIVE,
dailyBudget: 100.00,
totalBudget: 3000.00,
startDate: new Date('2024-06-01'),
endDate: new Date('2024-08-31'),
});
group.setTargeting({ device: 'desktop', geo: 'US' });
group.setZoneIds(['zone-1', 'zone-2']);
await group.save();
// Add variations with weights for A/B testing
// weight=2 is selected 2x more often than weight=1
const variations = await AdVariationCollection.create({ db });
const varA = await variations.create({
groupId: group.id,
name: 'Version A - Blue CTA',
weight: 2,
status: 'active',
});
// Track an immutable event (create-only, no update/delete)
const events = await AdEventCollection.create({ db });
await events.create({
variationId: varA.id,
zoneId: 'zone-uuid',
siteId: 'site-uuid',
eventType: AdEventType.IMPRESSION,
});
一级瀑布
广告通过分级优先排序(下数=高优先排序):
- 赞助 (优先事项1) -- -- 保费安排、固定定价
- 标准 (优先事项2) -- -- 经常方案广告、CPM定价
- 房屋 (优先事项3) -- -- 自我促进倒置广告
在某一层级内,根据相对权重选择变化。 与 weight: 2 被选中的可能性是 weight: 1。 。 。 .
API 密码
模型
| 导出 | 说明 |
|---|---|
AdDeliveryTier | 瀑布交付的优先级(名称、优先级、定价模式) |
AdFormat | IAB标准广告尺寸(宽度,高度,格式) Type:横幅/内地/视频) |
AdGroup | 具有目标选择规则、预算、区域限制和日期范围的运动 |
AdVariation | 具有A/B分布重量的组内创造性变体. 非正常状态 impressions编号 :clicks 计数 |
AdEvent | 不可移动跟踪事件(印象/点击/转换). 只创建 - 没有更新/删除 . cli: false (高数量) |
收款
AdDeliveryTierCollection, (中文(简体) ), AdFormatCollection, (中文(简体) ), AdGroupCollection, (中文(简体) ), AdVariationCollection, (中文(简体) ), AdEventCollection
数字
| 导出 | 数值 |
|---|---|
AdEventType | impression, (中文(简体) ), click, (中文(简体) ), conversion |
AdFormatType | banner, (中文(简体) ), native, (中文(简体) ), video |
AdGroupStatus | draft, (中文(简体) ), active, (中文(简体) ), paused, (中文(简体) ), completed |
AdVariationStatus | draft, (中文(简体) ), active, (中文(简体) ), paused |
PricingModel | fixed, (中文(简体) ), cpm, (中文(简体) ), cpc, (中文(简体) ), cpa |
依赖关系
@happyvertical/smrt-core-- ORM 和代码生成@happyvertical/smrt-tenancy-- 多租户范围界定(关于AdGroup、AdVariation、AdEvent的选择)- 端点 :
@happyvertical/smrt-assets, (中文(简体) ),@happyvertical/smrt-commerce, (中文(简体) ),@happyvertical/smrt-properties, (中文(简体) ),@happyvertical/smrt-tags
贡献者指南
见 AGENTS.md 用于软件包结构、变化、验证、,
和贡献者的指导.