interface.uts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /**
  2. * 接口调用成功回调
  3. */
  4. export type ReportSuccess = {
  5. /**
  6. * 成功的详细信息
  7. */
  8. errMsg : string
  9. }
  10. /**
  11. * 错误码
  12. */
  13. export type ReportErrorCode =
  14. /**
  15. * 应用已集成uni统计,但未关联服务空间,请在uniCloud目录右键关联服务空间
  16. */
  17. 61000 |
  18. /**
  19. * 统计服务尚未初始化,需在`main.uts`中引入统计插件
  20. */
  21. 61001 |
  22. /**
  23. * name参数是uni-app-launch时, options 参数未填写
  24. */
  25. 61002 |
  26. /**
  27. * name参数未填写
  28. */
  29. 61003 |
  30. /**
  31. * name参数类型错误,应为`String`类型
  32. */
  33. 61004 |
  34. /**
  35. * name参数长度超限,最大不超过255
  36. */
  37. 61005 |
  38. /**
  39. * options参数错误,应为String或Object类型
  40. */
  41. 61006 |
  42. /**
  43. * options参数为String类型时,长度超限,最大不超过255
  44. */
  45. 61007 |
  46. /**
  47. * name参数为title时,options参数类型错误,应为String
  48. */
  49. 61008
  50. /**
  51. * 错误回调
  52. */
  53. export interface ReportError extends IUniError {
  54. /**
  55. * 错误码
  56. */
  57. errCode : ReportErrorCode
  58. }
  59. /**
  60. * 接口调用失败回调
  61. */
  62. export type ReportFail = ReportError
  63. /**
  64. * 接口调用成功回调
  65. */
  66. export type ReportSuccessCallback = (res : ReportSuccess) => void
  67. /**
  68. * 接口调用失败回调
  69. */
  70. export type ReportFailCallback = (err : ReportFail) => void
  71. /**
  72. * 接口调用结束回调(调用成功、失败都会执行)
  73. */
  74. export type ReportCompleteCallback = (res : any) => void
  75. /**
  76. * Report 参数定义
  77. */
  78. export type ReportOptions = {
  79. /**
  80. * 自定义事件名称,内置名称不允许覆盖,可选值:
  81. * `uni-app-launch`:应用启动,options 参数必填,值为 onLaunch 返回值
  82. * `uni-app-show`:应用进入前台
  83. * `uni-app-hide`:应用进入后台
  84. * `uni-app-error`:应用发生错误,options 参数必填,值为错误信息,类型为String
  85. * `title`:标题采集
  86. * `自定义name`:用户自定义
  87. */
  88. name : string
  89. /**
  90. * 额外参数
  91. */
  92. options ?: any | null
  93. /**
  94. * 接口调用成功的回调函数
  95. */
  96. success ?: ReportSuccessCallback | null,
  97. /**
  98. * 接口调用失败的回调函数
  99. */
  100. fail ?: ReportFailCallback | null,
  101. /**
  102. * 接口调用结束的回调函数(调用成功、失败都会执行)
  103. */
  104. complete ?: ReportCompleteCallback | null
  105. }
  106. /**
  107. * 自定义事件信息
  108. * @param {ReportOptions} options
  109. *
  110. * @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
  111. * @since 4.25
  112. */
  113. export type Report = (options : ReportOptions) => void
  114. export interface Uni {
  115. /**
  116. * 统计自定义事件
  117. * @description uni统计自定义上报方法。
  118. * @param {ReportOptions} options 自定义事件参数
  119. * @uniPlatform {
  120. * "app": {
  121. * "android": {
  122. * "unixVer": "4.33"
  123. * },
  124. * "ios": {
  125. * "unixVer": "4.33"
  126. * }
  127. * },
  128. * "web": {
  129. * "unixVer": "4.33"
  130. * },
  131. * "mp-weixin": {
  132. * "unixVer": "4.41"
  133. * }
  134. * }
  135. * @example
  136. * ```typescript
  137. * uni.report({
  138. * name:'uni-app-launch',
  139. * success(res) {
  140. * console.log(res);
  141. * },
  142. * fail(err) {
  143. * console.log(err);
  144. * }
  145. * })
  146. * ```
  147. * @remark
  148. * - 该接口需要同步调用
  149. */
  150. report(options : ReportOptions) : void;
  151. }
  152. // 统计插件参数类型
  153. export type UniStatOptions = {
  154. /**
  155. * 是否开启debug模式
  156. * @defaultValue false
  157. */
  158. debug ?: boolean
  159. /**
  160. * 前端数据上报周期 ,单位s
  161. * @defaultValue 10
  162. */
  163. reportInterval ?: number
  164. /* 多服务空间配置 */
  165. uniCloud ?: UniCloudInitOptions
  166. /* 采集项配置 */
  167. collectItems ?: UniStatCollectItemsOptions
  168. }
  169. export type UniStatCollectItemsOptions = {
  170. /**
  171. * 是否开启推送PushClientID的采集
  172. * @defaultValue false
  173. */
  174. uniPushClientID ?: boolean
  175. /**
  176. * 是否开启页面数据采集
  177. * @defaultValue true
  178. */
  179. uniStatPageLog ?: boolean
  180. }
  181. /**
  182. * 应用参数扩展
  183. */
  184. export type OnLaunchOptionsWithCst = {
  185. /** 页面路径 */
  186. path ?: string
  187. /** 上报时机,参看 ReprotCstType */
  188. cst ?: number
  189. /** 场景值 */
  190. scene ?: number
  191. /** 参数 */
  192. query ?: string
  193. };
  194. /**
  195. * 停留时长
  196. */
  197. export type ResidenceTimeReturn = {
  198. /** 停留时长 */
  199. residenceTime : number
  200. /** 是否超时 */
  201. overtime : boolean
  202. }
  203. /**
  204. * 路由
  205. */
  206. export type RouteParams = {
  207. path : string
  208. fullpath : string
  209. }
  210. /**
  211. * 页面标题
  212. */
  213. export type TitleConfigParams = {
  214. /** pages.json 中的标题 */
  215. config : string
  216. /** setNavigationBarTitle 获取的标题*/
  217. page : string
  218. /** 自定义上报的标题 */
  219. report : string
  220. /** 统计数据类型 */
  221. lt : string
  222. }
  223. /**
  224. * 页面参数
  225. */
  226. export type PageParams = {
  227. /** 当前页面的完整 url,包含参数在内。最多255字符 */
  228. url ?: string
  229. /** pages.json 中定义的页面的 title,获取不到时,可以不传 */
  230. ttpj ?: string
  231. /** 通过接口 uni.setnavigationbartitle 设置的 title,获取不到时,可以不传 */
  232. ttn ?: string
  233. /** 通过 uni.report 上报的页面的 title,获取不到时,可以不传 */
  234. ttc ?: string
  235. /** title 组件中设置的 title,获取不到时,可以不传 */
  236. ttct ?: string
  237. /** 上个页面的完整 url */
  238. urlref : string
  239. /** 上个页面停留时间,单位为秒,不足1秒按1秒计。 url */
  240. urlref_ts : number
  241. /** 上个页面的标题 */
  242. urlref_tt ?: string
  243. }
  244. /**
  245. * 上传 unicloud 参数
  246. */
  247. export type RequestData = {
  248. /** 统计 SDK 版本号 */
  249. usv : string
  250. /** 发送请求时的时间戮 */
  251. t : number
  252. /** 组合数据 */
  253. requests : string
  254. }
  255. /**
  256. * 用户自定义服务空间配置信息
  257. */
  258. export type CustomUnicloudConfig = {
  259. /** 服务空间id */
  260. spaceId : string,
  261. /** 云厂商 */
  262. provider : string,
  263. /** clientSecret */
  264. clientSecret ?: string
  265. /** secretKey */
  266. secretKey ?: string
  267. /** secretId */
  268. secretId ?: string
  269. }
  270. /**
  271. * 事件类型
  272. */
  273. export type EventParams = {
  274. /** 事件名字*/
  275. key : string
  276. /** 事件内容 */
  277. value ?: string
  278. }
  279. /**
  280. * 统计默认值
  281. */
  282. export type StatDefault = {
  283. /** 设备标识 */
  284. uuid : string
  285. /** uni-app 应用 Appid */
  286. ak : string
  287. /** 手机系统 */
  288. p : string
  289. /** 平台类型 */
  290. ut : string
  291. /** 原生平台包名、小程序 appid */
  292. mpn ?: string
  293. /** 统计 sdk 版本 */
  294. usv ?: string
  295. /** 应用版本,仅app */
  296. v ?: string
  297. /** 渠道信息 */
  298. ch ?: string
  299. /** 国家 */
  300. cn ?: string
  301. /** 省份 */
  302. pn ?: string
  303. /** 城市 */
  304. ct ?: string
  305. /** 上报数据时的时间戳 */
  306. t ?: number
  307. /** 页面标题 */
  308. tt ?: string
  309. /** 手机品牌 */
  310. brand ?: string
  311. /** 手机型号 */
  312. md ?: string
  313. /** 手机系统版本 */
  314. sv ?: string
  315. /** x程序 sdk version */
  316. mpsdk ?: string
  317. /** 小程序平台版本 ,如微信、支付宝 */
  318. mpv ?: string
  319. /** 语言 */
  320. lang ?: string
  321. /** pixelRatio 设备像素比 */
  322. pr ?: number
  323. /** windowWidth 可使用窗口宽度 */
  324. ww ?: number
  325. /** windowHeight 可使用窗口高度 */
  326. wh ?: number
  327. /** screenWidth 屏幕宽度 */
  328. sw ?: number
  329. /** screenHeight 屏幕高度 */
  330. sh ?: number
  331. /** 场景值 */
  332. sc ?: number
  333. /** 统计数据类型 */
  334. lt ?: string
  335. /** 老用户错误的的设备id */
  336. odid ?: string
  337. url ?: string
  338. /** 首次访问时间戳。需要保存在 storage 中。用户首次访问时,取当前时间。*/
  339. fvts ?: number
  340. /** 上次访问时间戳。需要保存在 storage 中。用户首次访问时,设置为0。*/
  341. lvts ?: number
  342. /** total visit count 用户到本次访问为止总共的访问次数。*/
  343. tvc ?: number
  344. /** 上报时机,参看 ReprotCstType */
  345. cst ?: number
  346. urlref_ts ?: number
  347. urlref ?: string
  348. // 标题相关
  349. /** pages.json 中定义的页面的 title,获取不到时,可以不传 */
  350. ttpj ?: string
  351. /** 通过接口 uni.setnavigationbartitle 设置的 title,获取不到时,可以不传 */
  352. ttn ?: string
  353. /** 通过 uni.report 上报的页面的 title,获取不到时,可以不传 */
  354. ttc ?: string
  355. /** title 组件中设置的 title,获取不到时,可以不传 */
  356. ttct ?: string
  357. /** push id */
  358. cid ?: string
  359. /** 自定义事件key */
  360. e_n ?: string
  361. /** 自定义事件value */
  362. e_v ?: string
  363. /** 纬度 */
  364. lat ?: string
  365. /** 经度 */
  366. lng ?: string
  367. /** 网络 */
  368. net ?: string
  369. /** 错误信息 */
  370. em ?: string
  371. /* 是否root ios为越狱 */
  372. root ?: number
  373. /*manifest.json 中应用版本名称。*/
  374. pv ?: string
  375. log ?: string
  376. did ?: string
  377. os ?: string
  378. }
  379. /**
  380. * 应用首次启动上报参数
  381. */
  382. export type AppShowReportParams = {
  383. /** uni-app 应用 Appid */
  384. uuid : string
  385. /** 设备标识 */
  386. ak : string
  387. /** 统计数据类型 */
  388. lt : string
  389. /** 平台类型 */
  390. ut : string
  391. /** x程序 sdk version */
  392. mpsdk : string
  393. /** 小程序平台版本 ,如微信、支付宝 */
  394. mpv : string
  395. /** 原生平台包名、小程序 appid */
  396. mpn : string
  397. /** 应用版本,仅app */
  398. v : string
  399. /** 手机系统 */
  400. p : string
  401. /** 手机系统版本 */
  402. sv : string
  403. /** 设备网络 */
  404. net : string
  405. /** 手机品牌 */
  406. brand : string
  407. /** 手机型号 */
  408. md : string
  409. /** 语言 */
  410. lang : string
  411. /** 纬度 */
  412. lat : string
  413. /** 经度 */
  414. lng : string
  415. /** pixelRatio 设备像素比 */
  416. pr : number
  417. /** windowWidth 可使用窗口宽度 */
  418. ww : number
  419. /** windowHeight 可使用窗口高度 */
  420. wh : number
  421. /** screenWidth 屏幕宽度 */
  422. sw : number
  423. /** screenHeight 屏幕高度 */
  424. sh : number
  425. /** 页面启动的url */
  426. url : string
  427. /** 页面标题 */
  428. tt : string
  429. /** 渠道信息 */
  430. ch : string
  431. /** 首次访问时间戳。需要保存在 storage 中。用户首次访问时,取当前时间。*/
  432. fvts : number
  433. /** 上次访问时间戳。需要保存在 storage 中。用户首次访问时,设置为0。*/
  434. lvts : number
  435. /** 国家 */
  436. cn : string
  437. /** 省份 */
  438. pn : string
  439. /** 城市 */
  440. ct : string
  441. /** 场景值 */
  442. sc : number
  443. /** total visit count 用户到本次访问为止总共的访问次数。*/
  444. tvc : number
  445. /** 统计 sdk 版本 */
  446. usv : string
  447. /** 上报数据时的时间戳 */
  448. t : number
  449. /** 老用户错误的的设备id */
  450. odid : string
  451. /** 上报时机,参看 ReprotCstType */
  452. cst : number
  453. }
  454. /**
  455. * 应用进入后台上报参数
  456. */
  457. export type AppHideReportParams = {
  458. /** uni-app 应用 Appid */
  459. ak : string
  460. /** 设备标识 */
  461. uuid : string
  462. /** 统计数据类型 */
  463. lt : string
  464. /** 平台类型 */
  465. ut : string
  466. /** 手机系统 */
  467. p : string
  468. /** 上个页面的完整 url */
  469. urlref : string
  470. /** 上个页面停留时间,单位为秒,不足1秒按1秒计。 */
  471. urlref_ts : number
  472. /** 渠道信息 */
  473. ch : string
  474. /** 统计 sdk 版本 */
  475. usv : string
  476. /** 上报数据时的时间戳。 */
  477. t : number
  478. }
  479. /**
  480. * 页面切换上报参数
  481. */
  482. export type PageReportParams = {
  483. /** uni-app 应用 Appid */
  484. ak : string
  485. /** 设备标识 */
  486. uuid : string
  487. /** 统计数据类型 */
  488. lt : string
  489. /** 平台类型 */
  490. ut : string
  491. /** 手机系统 */
  492. p : string
  493. /** 当前页面 url */
  494. url : string
  495. // 标题相关
  496. /** pages.json 中定义的页面的 title,获取不到时,可以不传 */
  497. ttpj : string
  498. /** 通过接口 uni.setnavigationbartitle 设置的 title,获取不到时,可以不传 */
  499. ttn : string
  500. /** 通过 uni.report 上报的页面的 title,获取不到时,可以不传 */
  501. ttc : string
  502. /** title 组件中设置的 title,获取不到时,可以不传 */
  503. ttct : string
  504. /** 上个页面的完整 url */
  505. urlref : string
  506. /** 上个页面停留时间,单位为秒,不足1秒按1秒计。 */
  507. urlref_ts : number
  508. /** 渠道信息 */
  509. ch : string
  510. /** 统计 sdk 版本 */
  511. usv : string
  512. /** 上报数据时的时间戳。 */
  513. t : number
  514. /** 上报时机,参看 ReprotCstType */
  515. cst ?: number
  516. }
  517. export type ErrorCallback = (is_err : boolean, code : ReportErrorCode) => void