Skip to content

TypeScript 事件上报接口

根据上报的事件类型数据,会反应在系统的统计数据中。

请求参数列表

参数名类型说明
requestAppReportRequest设置具体接口请求参数,请参见 事件上报

返回值列表

返回值名类型说明
resultAppReportResponse接口返回值,当 err 为nil 时有效,具体接口返回参数,请参见 事件上报

单元测试代码位置

示例代码

您可以使用以下代码上报的事件类型数据。

typescript
import Client, { AppReportRequest } from '@toolsetlink/upgradelink-api-typescript';

// 测试事件上报信息
async function testPostAppReport() {
    try {
        // 初始化客户端
        const config = new Config({
            accessKey:  'mui2W50H1j-OC4xD6PgQag',
            accessSecret: 'PEbdHFGC0uO_Pch7XWBQTMsFRxKPQAM2565eP8LJ3gc',
        });
        const client = new Client(config);

        // 构造请求参数

        /* app_start 应用-启动事件 */
        // const request = new AppReportRequest({
        //     eventType: Enums.EVENT_TYPE_APP_START,
        //     appKey: 'LOYlLXNy7wV3ySuh0XgtSg',
        //     devModelKey: '',
        //     devKey: '',
        //     versionCode: 1,
        //     timestamp: Tools.timeRFC3339(),
        //     eventData: {
        //         launchTime: Tools.timeRFC3339(),
        //     }
        // });

        /* app_upgrade_download 应用升级-下载事件 */
        // const request = new AppReportRequest({
        //     eventType: Enums.EVENT_TYPE_APP_UPGRADE_DOWNLOAD,
        //     appKey: 'LOYlLXNy7wV3ySuh0XgtSg',
        //     devModelKey: '',
        //     devKey: '',
        //     versionCode: 1,
        //     timestamp: Tools.timeRFC3339(),
        //     eventData: {
        //         code: Enums.EVENT_TYPE_CODE_SUCCESS,
        //         downloadVersionCode: 10,
        //     }
        // });

        /* app_upgrade_install 应用升级-升级事件 */
        const request = new AppReportRequest({
            eventType: Enums.EVENT_TYPE_APP_UPGRADE_UPGRADE,
            appKey: 'LOYlLXNy7wV3ySuh0XgtSg',
            devModelKey: '',
            devKey: '',
            versionCode: 1,
            timestamp: Tools.timeRFC3339(),
            eventData: {
                code: Enums.EVENT_TYPE_CODE_SUCCESS,
                upgradeVersionCode: 10,
            }
        });

        // 发起请求
        const response = await client.AppReport(request);

        // 打印响应结果
        console.log('\n事件上报信息响应:');
        console.log(`code: ${response.code}`);
        console.log(`msg: ${response.msg}`);
    } catch (error) {
        console.error('\n事件上报信息失败:', error);
    }
}