VAST/VPAID视频广告协议完全解析
视频广告是eCPM最高的广告形式,其技术核心是VAST(Video Ad Serving Template)协议。掌握VAST,你才能真正搞懂视频广告从服务端到客户端的完整流程。
一、VAST协议是什么?
VAST是IAB制定的视频广告通用标准,定义了广告服务器如何向播放器传递视频广告信息的XML格式。
# VAST 4.0 XML结构示例
OpenClaw
品牌推广30秒视频
00:00:30
二、Python解析VAST XML
import xml.etree.ElementTree as ET
import requests
def parse_vast(vast_url):
"""解析VAST XML,提取关键信息"""
resp = requests.get(vast_url, timeout=3)
root = ET.fromstring(resp.text)
ns = '' # VAST 4.0不用命名空间
result = {}
# 提取曝光监测URL
impression = root.find('.//Impression')
result['impression_url'] = impression.text.strip() if impression is not None else None
# 提取媒体文件(按码率降序)
media_files = []
for mf in root.findall('.//MediaFile'):
media_files.append({
'url': mf.text.strip(),
'type': mf.get('type'),
'bitrate': int(mf.get('bitrate', 0)),
'width': int(mf.get('width', 0)),
})
result['media_files'] = sorted(media_files, key=lambda x: x['bitrate'], reverse=True)
# 提取跟踪事件
result['tracking'] = {}
for t in root.findall('.//Tracking'):
event = t.get('event')
result['tracking'][event] = t.text.strip()
# 提取可跳过时间
linear = root.find('.//Linear')
result['skip_offset'] = linear.get('skipoffset') if linear is not None else None
return result
三、激励视频的完整播放流程
# 激励视频播放状态机
#
# IDLE
# │ load()
# ▼
# LOADING ──失败──► ERROR → 通知用户无广告
# │ 成功
# ▼
# READY
# │ show()
# ▼
# PLAYING
# │
# ├─ 用户点击跳过 ──► SKIPPED → 不发放奖励
# │
# └─ 完整播放(30s) ──► COMPLETED → 发放奖励
#
# 关键: 奖励必须在COMPLETED后发放,不能提前
class RewardedVideoController:
def __init__(self, unit_id, on_reward):
self.unit_id = unit_id
self.on_reward = on_reward # 发放奖励的回调
self.ad_completed = False
def on_video_complete(self):
self.ad_completed = True
# 上报完播事件
requests.get(self.tracking_urls.get('complete'))
def on_ad_closed(self):
if self.ad_completed:
self.on_reward() # 发放奖励
else:
print('用户跳过,不发奖励')
四、VAST 4.0新特性:互动广告与验证
| 特性 | VAST 3.0 | VAST 4.0 | 说明 |
|---|---|---|---|
| 互动广告 | 通过VPAID | 内置InteractiveCreative | 减少安全风险 |
| 第三方验证 | 无标准 | Verification节点 | 防作弊验证脚本 |
| 多语言素材 | 不支持 | AdServingId | 统一素材追踪 |
| 背景视频 | 不支持 | UniversalAdId | 跨平台素材复用 |
总结:VAST是视频广告的通用语言,掌握它你就能对接任何视频广告系统。激励视频的核心是完播奖励机制——必须服务端验证完播事件再发放奖励,客户端发放容易被作弊。
