# ks.reportScene

更新时间:2025-07-03 18:03:15

该功能用于游戏启动阶段的自定义场景数据上报,助力厂商快速定位问题根源。

快手安卓版本>=13.5.40,iOS版本>=13.5.40,低版本需做兼容处理。

请求 object

字段名 类型 默认值 必填 描述
sceneId number 场景ID
costTime number 0 此场景的耗时,单位 ms
dimension object 自定义维度数据,key在「小程序管理后台」获取。只支持能够通过JSON.stringify序列化的对象,且序列化后长度不超过1024个字符
metric object 自定义指标数据,key在「小程序管理后台」获取。只支持能够通过JSON.stringify序列化的对象,且序列化后长度不超过1024个字符
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

回调成功

字段名 类型 描述
errMsg string "reportScene:ok"
data object 开发者上报的原始数据

回调失败

字段名 类型 描述
errNo int 异常错误码
errMsg string 错误信息

错误码

code msg 描述
20001 params.${key} should be ${expect_type}, but got ${actual_value}​ 参数数据类型校验,请根据「参数说明」检查对应字段传参情况
20001 report sceneId:${scene_id} repeatedly​ 同一个场景 ID 重复上报,游戏每次启动只可以上报一次​
20001 params.dimension.${key} needs to be a string type and a non-empty string​ dimension 中每个字段需要为非空字符串​
20001 params.metric.${key} needs to be a numeric value of type string​ metric 中每个字段需要为非空字符串且可以 parse 为非 NaN 数字​
20001 params.${key} cannot exceed 1024 characters​ dimension / metric 字段 stringify 后字符串长度不可超过 1024​
20001 failed to serialize params.${} by JSON.stringify​ dimension / metric 对象 stringify 失败​
20001 invalid sceneId:${scene_id} 场景id不合法
-20001 unknown error 系统内部异常

example

ks.reportScene({
    sceneId: 7001,
    costTime: 1000,
    dimension: {
        d1: "value"
    },
    metric: {
        m1: "1000"
    },
    success: (res) => {
        console.log("reportScene success");
        // 上报成功回调逻辑
    },
    fail: (res) => {
        console.log("reportScene fail: ", res);
        // 上报失败回调逻辑
    },
});
Copyright ©2025, All Rights Reserved