跳转到主要内容

用例

探索流媒体蓝图支持的常见场景:

Video Platforms

按视频带宽消耗和流媒体质量向客户计费。

Music Streaming

按订阅层级跟踪每位用户的音频流媒体使用情况。

Live Events

监控直播消耗并按带宽使用量收费。

Real-Time Data

跟踪物联网及遥测应用的实时数据传输。
非常适合视频/音频流媒体平台、直播服务和实时数据应用。

快速开始

跟踪客户消耗的流媒体字节:
1

Install the SDK

npm install @dodopayments/ingestion-blueprints
2

Get Your API Keys

3

Create a Meter

在你的 Dodo Payments Dashboard 中创建一个计量器:
  • Event Name: stream_consumption(或你偏好的名称)
  • Aggregation Type: sum 以跟踪总流式传输字节数
  • Over Property: bytes 以根据带宽使用量计费
4

Track Stream Usage

import { Ingestion, trackStreamBytes } from '@dodopayments/ingestion-blueprints';

const ingestion = new Ingestion({
  apiKey: process.env.DODO_PAYMENTS_API_KEY,
  environment: 'test_mode',
  eventName: 'stream_consumption'
});

// Track video stream consumption
await trackStreamBytes(ingestion, {
  customerId: 'customer_123',
  bytes: 10485760, // 10MB
  metadata: {
    stream_type: 'video',
  }
});

配置

数据摄取配置

apiKey
string
必填
来自仪表板的 Dodo Payments API 密钥。
environment
string
必填
环境模式:test_modelive_mode
eventName
string
必填
与计量器配置匹配的事件名称。

跟踪流媒体字节选项

customerId
string
必填
用于计费归属的客户 ID。
bytes
number
流中消耗的字节数。按基于带宽的计费,这是必需的。
metadata
object
有关流的可选元数据,如流类型、质量、sessionId 等。

最佳实践

按块跟踪:对于长流,按块跟踪消耗,而不是等待整个流完成。
准确的字节计数:如果按总带宽计费,请确保字节计数包含所有开销(头部、协议开销)。