注意

推荐使用 uni统计2.0

# 统计

Since uni-app 2.2.3, uni statistics are supported. One report, master all data. For business introduction, see https://tongji.dcloud.net.cn

Custom events are an integral feature in statistics. Developers can customize the reporting of statistical data through this API, such as statistical login, registration, and clicking a button, which can be called custom events.

# uni.report( eventKey , param)

Parameter Description

parameters type description
eventKey String Event name, max length 255 characters
param String 、 Object 事件参数

提示

  • eventKey 为 String 类型,并且字符长度必须小于255
  • param 为 String 类型时,字符长度必须小于255
  • param 为 Object 类型时,该对象的值只能为 String 类型
  • Strings support special characters but not include (comma , colon : dot .)
  • When the eventKey is title, the content title is reported, which cannot be customized by the user. At this time, the data will be displayed in the home page of uni statistics - content statistics and content statistics in the left navigation. Easy to view content page data.
  • When the user uses uni.login(), the login event will be executed without parameters. If you need to report data with specific parameters, you need to manually call uni.report('login',{...})
  • When the user uses uni.share() or triggers onShareAppMessage, the share event will be executed without parameters. If you need to report data with specific parameters, you need to manually call uni.report('share',{...})
  • 用户在使用 uni.requestPayment() 会执行支付事件,不携带参数。如果如需上报携带具体参数的数据,需要手动调用 uni.report('pay_success',{...})uni.report('pay_fail',{...})

Example

// content statistics
// When eventKey is title, param can only be String type
uni.report('title','首页')

// Log in
uni.report('login',{
  'name':'uni-app',
  'age':'21',
  // ...
})

// share
uni.report('share','分享')

// payment successful
uni.report('pay_success','支付成功')
// or
uni.report('pay_success',{
  "订单金额":'20元',
  "订单名称":'鼠标',
  // ...
})

// payment failed
uni.report('pay_fail','支付失败')
// or
uni.report('pay_fail',{
  "订单金额":'20元',
  "订单名称":'鼠标',
  // ...
})

// register
uni.report('register',{
  'name':'uni-app',
  'age':'21',
  // ...
})

// search
uni.report('search','搜索内容')
// or
uni.report('search',{
})

自定义事件上报后:

  • 统计1.0在统计后台的事件和转换栏目中,可以看到上报的事件情况。
  • Statistics 2.0 In the uni statistics --> custom events column in the uni-admin background, you can see the reported events.

提示

# 支持 uni.report 的 uni-ui 组件

uni-ui 中内置了一些数据采集相关的组件,用户使用这些组件,并设置属性 stat:true,即可在使用相关组件时,自动上报相关自定义数据

# 非官方自定义统计

In addition to the official uni statistics, if developers also need to call the custom statistics of the applet platform to report data to the background of the applet, they need to use conditional compilation to call their own API on each end.

# 微信小程序平台:

# 支付宝小程序平台:

# 百度小程序平台:

# 抖音小程序平台:

# QQ小程序平台:

# App平台的友盟统计: