OMID 分册导航
AdSession 与会话构造
接口本页清单由 scripts/gen-omid-spec.mjs 自 IAB Tech Lab 官方源生成,描述为官方英文原文;采集基线见页尾。 规范收录数据保留英文原文;已提供的中文译文为初稿(draft),打开中英对照可查看原文。
定位与职责
会话客户端的主对象 AdSession:创建、start / finish、曝光与素材加载声明、错误上报、事件注册与元素边界更新;构造所需的 Context / Partner / VerificationScriptResource / OmidVersion 一并列出,并给出 iOS / Android 的同名对象对照。UniversalAdId 与 VastProperties 由 Context 的构造参数与 AdEvents.loaded() 引用,JS 源码已导出(packageExport 到 OmidSessionClient)但官方 JSDoc 站点未发布对应页面,故本册只在参数类型中出现,不单独成表。
- 所属客户端
- 会话客户端
- 端
- JavaScript
- 库版本
- 1.6.10
- 公开成员
- 12
接口面
AdSessionjs · 12
JS 广告会话 API:供集成方(integration partner)参与已有的原生(native)广告会话。它同时负责与 OM SDK JS 服务通信,并处理只能有限访问 OM SDK JS 服务的场景——即跨域 iframe。本 API 常用于以下场景:视频广告会话依赖 HTML5 视频播放器来注入验证脚本资源(verification script resource)和/或发布 OMID 视频事件;展示(display)广告会话依赖独立的 JS 组件来处理曝光事件。ENThe JS ad session API enabling the integration partner to contribute to an existing native ad session. This is also responsible for communicating to the OM SDK JS service and will also handle scenarios with limited access to the OM SDK JS service - i.e. cross-domain iFrames. This API is commonly used in the following scenarios; - video ad session relying on the HTML5 video player for injecting verification script resources and/or publishing OMID video events. - display ad session relying on a separate JS component to handle the impression event.译稿校对中
| 名称 | 签名 | 返回 | 官方描述 |
|---|---|---|---|
| AdSession | new AdSession(context, communication, sessionInterface) | void | (官方未提供描述)
|
| error | error(errorType, message) | void | 通报广告会话上发生了错误。所有验证客户端(verification client)都会通过 'sessionError' 会话观察者事件收到通知。ENNotifies that an error has occurred on the ad session. All verification clients will be notified via the 'sessionError' session observer event.译稿校对中
|
| finish | finish() | void | 若当前存在活跃的广告会话,本方法以 SESSION_FINISH 事件通知所有会话观察者广告会话已结束:广告视图跟踪以及向为本会话注入的验证脚本发送消息随之停止。无活跃会话时调用、或在移动应用环境中调用,本方法无效果。ENIf there is a currently active ad session, this notifies all session observers that the ad session has finished with a SESSION_FINISH event. This ceases ad view tracking and message sending to verification scripts injected for the ad session. This method has no effect if called if there is no active ad session or in a mobile app environment.译稿校对中 |
| getAdSessionId | getAdSessionId() | string | 获取本广告会话的 ID。ENGet the ID of this ad session.译稿校对中 |
| isSupported | isSupported() | boolean | OMID 可用时返回 true,否则返回 false。ENReturns true if OMID is available, false otherwise.译稿校对中 |
| registerAdEvents | registerAdEvents() | void | 登记一个 AdEvents 实例的存在。ENRegisters the existence of an AdEvent instance.译稿校对中 |
| registerMediaEvents | registerMediaEvents() | void | 登记一个 MediaEvents 实例的存在。ENRegisters the existence of an MediaEvents instance.译稿校对中 |
| registerSessionObserver | registerSessionObserver(functionToExecute) | void | 订阅所有会话事件('sessionStart'、'sessionError'、'sessionFinish')。事件处理器会以单个参数被调用,该参数含以下字段:'adSessionId'(string)、'timestamp'(number)、'type'(string)、'data'(object)。ENSubscribes to all session events ('sessionStart', 'sessionError', and 'sessionFinish'). The event handler will be called with a single argument that has the following fields: 'adSessionId': string, 'timestamp': number, 'type': string, 'data': object译稿校对中
|
| setCreativeType | setCreativeType(creativeType) | void | 指定本会话中将渲染的创意类型。要求原生层已将创意类型设为 DEFINED_BY_JAVASCRIPT。ENSpecifies the type of creative to be rendered in this session. Requires that the native layer set the creative type to DEFINED_BY_JAVASCRIPT.译稿校对中
|
| setElementBounds | setElementBounds(elementBounds) | void | 设置 DOM 元素的几何信息,其相对基准为 slotElement 的几何信息,或创意 DOM 元素所在跨域 iframe 的几何信息。ENSet the DOM element's geometry relative to the geometry of either the slotElement or the cross domain iframe the creative's DOM element is in.译稿校对中
|
| setImpressionType | setImpressionType(impressionType) | void | 指定本会话中将被触发的曝光类型。要求原生层已将曝光类型设为 DEFINED_BY_JAVASCRIPT。ENSpecifies the type of impression to be triggered in this session. Requires that the native layer set the impression type to DEFINED_BY_JAVASCRIPT.译稿校对中
|
| start | start() | void | 若当前没有活跃的广告会话,本方法以 SESSION_START 事件通知所有会话观察者会话已开始:广告视图跟踪随之启动,视频事件与广告事件开始可发送给为本会话注入的验证脚本(verification script)。会话已开始后再次调用、或在移动应用环境中调用,本方法无效果。ENIf there is no currently active ad session, this notifies all session observers that an ad session has started with a SESSION_START event. This starts ad view tracking and makes video and ad events available to send to verification scripts injected for this ad session. This method has no effect if called after the ad session has already started or in a mobile app environment.译稿校对中 |
表中已滤除官方源码标注为 friend scoped(不应导出到混淆之外)的成员;曝光与素材加载的公开路径见 AdEvents。
会话构造参数
Contextjs · 11
保存由 JavaScript 层写入广告会话上下文(ad session context)的信息。ENHolds information provided into the ad session context by the JavaScript layer.译稿校对中
| 名称 | 签名 | 返回 | 官方描述 |
|---|---|---|---|
| Context | new Context(partner, verificationScriptResources, contentUrl, customReferenceData, universalAdId) | void | 创建新的广告会话上下文,提供集成方(partner)引用以及应由 OM SDK 服务管理的脚本资源列表。ENCreate a new ad session context providing reference to partner and a list of script resources which should be managed by OM SDK service.译稿校对中
|
| contentUrl | contentUrl: string | string | (官方未提供描述) |
| customReferenceData | customReferenceData: string | string | (官方未提供描述) |
| serviceWindow | serviceWindow: Window | Window | 若非 null,则为服务通信应定向到的 window,覆盖默认的查找算法。ENIf not null, the window to which service communication should be directed, overriding the default search algorithm.译稿校对中 |
| slotElement | slotElement: HTMLElement | HTMLElement | (官方未提供描述) |
| underEvaluation | underEvaluation: boolean | boolean | 本广告会话是否处于评估中(under evaluation),其定义见 Open Measurement License for Web Video, V 1.0 中的“Evaluation Flag”。在应用环境中被忽略。默认值为 false。ENWhether or not this ad session is under evaluation, as defined by "Evaluation Flag" in the Open Measurement License for Web Video, V 1.0. Ignored in app environments. Defaults to false.译稿校对中 |
| universalAdId | universalAdId: UniversalAdId | UniversalAdId | (官方未提供描述) |
| videoElement | videoElement: HTMLVideoElement | HTMLVideoElement | (官方未提供描述) |
| setServiceWindow | setServiceWindow(serviceWindow) | void | 默认情况下,OM SDK 会话客户端库(Session Client Library)假定服务脚本(Service Script)位于库自身被加载的同一 frame 中,或位于 top。调用本方法可覆盖该默认行为,改为让库指向所给的 window。ENBy default, the OM SDK Session Client Library will assume the Service Script is present in the same frame the library is loaded in, or top. Call this method to override this default and point the library to the give window instead.译稿校对中
|
| setSlotElement | setSlotElement(slotElement) | void | 指定 WebView 内的广告创意 HTML 元素。ENSpecifies the ad creative HTML element within the WebView.译稿校对中
|
| setVideoElement | setVideoElement(videoElement) | void | 指定 WebView 内的视频元素。ENSpecifies the video element within the WebView.译稿校对中
|
Partnerjs · 1
保存使用会话客户端的集成方(integration partner)信息。ENHolds information about the integration partner that is using the session client.译稿校对中
| 名称 | 签名 | 返回 | 官方描述 |
|---|---|---|---|
| Partner | new Partner(name, version) | void | 以给定的 name 与 version 创建新的集成方(Partner)实例。ENCreates a new partner instance given a name and a version.译稿校对中
|
VerificationScriptResourcejs · 6
表示一个验证脚本资源(verification script resource):在 VAST 3 及以下版本中来自 VAST 扩展(extension),在 VAST 4 及以上版本中来自 verification 节点。ENRepresents a verification script resource that comes in a VAST extension for VAST versions <= 3 or a verification node for VAST versions >= 4译稿校对中
| 名称 | 签名 | 返回 | 官方描述 |
|---|---|---|---|
| VerificationScriptResource | new VerificationScriptResource(resourceUrl, vendorKey, verificationParameters, accessMode) | void | 创建新的验证脚本资源实例,需提供特定于厂商的验证参数。ENCreates new verification script resource instance which requires vendor specific verification parameters.译稿校对中
|
| accessMode | accessMode: AccessMode | AccessMode | (官方未提供描述) |
| resourceUrl | resourceUrl: string | string | (官方未提供描述) |
| vendorKey | vendorKey: string | (string|undefined) | (官方未提供描述) |
| verificationParameters | verificationParameters: string | (string|undefined) | (官方未提供描述) |
| toJSON | toJSON() | Object | (官方未提供描述) |
OmidVersionjs · 1
表示 OMID 会话客户端(OMID Session Client)的版本。ENRepresents the Version of OMID Session Client.译稿校对中
| 名称 | 签名 | 返回 | 官方描述 |
|---|---|---|---|
| OmidVersion | new OmidVersion(semanticVersion, apiLevel) | void | (官方未提供描述)
|
跨平台命名对照
| 概念 | JavaScript | iOS | Android |
|---|---|---|---|
| ad-session | AdSession | OMIDAdSession | AdSession |
| ad-session-configuration | — | OMIDAdSessionConfiguration | AdSessionConfiguration |
| ad-session-context | — | OMIDAdSessionContext | AdSessionContext |
| context | Context | — | — |
| omid-version | OmidVersion | — | — |
| partner | Partner | OMIDPartner | Partner |
| verification-script-resource | VerificationScriptResource | OMIDVerificationScriptResource | VerificationScriptResource |
- ad-session-configurationJS 无对应类:creativeType/impressionType 由 AdSession.setCreativeType()/setImpressionType() 设置,事件 owner(impressionOwner/mediaEventsOwner)概念在 JS 侧不存在。
- ad-session-context对应 JS 的 Context:JS 把 partner、verificationScriptResources、contentUrl、customReferenceData、universalAdId 与 slot/video element 折叠进 Context 及 AdSession 构造参数,原生侧则拆为 AdSessionContext(iOS 另有 AdSessionConfiguration)。
- contextiOS/Android 无同名类:JS 的 Context 在原生侧被拆分为 AdSessionContext + AdSessionConfiguration(见 ad-session-context / ad-session-configuration 两条)。
- omid-version仅 JS 公开:源码 omid-version.js 顶部有 TODO(OMSDK-715) 注明该类似未使用、下个大版本应移除,但 JSDoc 站点仍发布。
同一概念在三端的类名对照;空缺表示该端不提供对应类。JS 侧把会话配置折进 Context 与构造参数,iOS / Android 侧则拆为独立的配置与上下文类。
常见失效形态
- universal-ad-id
仅 iOS 公开:JS 源码有 UniversalAdId(packageExport 到 OmidSessionClient.UniversalAdId,1.5.5 新增)但官方 JSDoc 站点无对应页面;Android 的 createNativeAdSessionContext(...)/getUniversalAdId() 在签名中引用 UniversalAdId 类型,javadoc 站点亦无该页(实测 404)。
- vast-properties
JS 侧 VastProperties(src/common/vast-properties.js,标 @public 且在 jsdoc.json 的 include 列表内)未被官方 JSDoc 站点发布(VastProperties.html 实测 404),故 js 记 null;AdEvents.loaded(vastProperties) 因此引用了一个站点上没有文档的类型。