cloudbase.getStatistics

本接口应在服务器端调用,详细说明参见服务端API

本接口支持云调用。需开发者工具版本 >= 1.02.1904090(最新稳定版下载),wx-server-sdk >= 0.4.0

获取云开发数据接口

调用方式:

HTTPS 调用

请求地址

  1. POST https://api.weixin.qq.com/tcb/getstatistics?access_token=TOKEN

请求参数

属性类型默认值必填说明
access_tokenstring接口调用凭证
actionstring获取动作,目前支持(smsMarketingOverviewData:短信营销概览数据;smsMarketingConversionData:短信营销转化数据;smsMarketingRealTimeData:短信营销实时数据)
begin_datenumber开始时间戳
end_datenumber结束时间戳
page_offsetnumber分页 offset【action 取 smsMarketingOverviewData、smsMarketingConversionData 时必填】
page_limitnumber分页 limit【action 取 smsMarketingOverviewData、smsMarketingConversionData 时必填】
conditionObject查询条件

返回值

Object

返回的 JSON 数据包

属性类型说明
errcodenumber错误码
data_columnArray.<Object>数据列定义
data_valueArray.<Object>数据行
total_numnumber总行数

errcode 的合法值

说明最低版本
0请求成功
-1系统繁忙,此时请开发者稍候再试
10011没有数据

data_column 的结构

属性类型说明
col_idstring列 id
col_namestring列名
col_data_typestring数据类型(0:string;1:number;2:double)

data_value 的结构

属性类型说明
data_valueArray.<string>数据值

请求概览数据示例

  1. {
  2. "action":"smsMarketingOverviewData",
  3. "begin_date": 1614182400,
  4. "end_date": 1614268800,
  5. "page_offset":0,
  6. "page_limit":1000,
  7. "condition":
  8. {
  9. "env_id":"xxx",
  10. "activity_id":"xxx",
  11. "by_channel_id":"0"
  12. }
  13. }

请求概览数据(按渠道)示例

  1. {
  2. "action":"smsMarketingOverviewData",
  3. "begin_date": 1614182400,
  4. "end_date": 1614268800,
  5. "page_offset":0,
  6. "page_limit":1000,
  7. "condition":
  8. {
  9. "env_id":"xxx",
  10. "activity_id":"xxx",
  11. "by_channel_id":"1"
  12. }
  13. }

请求漏斗图数据示例

  1. {
  2. "action":"smsMarketingConversionData",
  3. "begin_date": 1614182400,
  4. "end_date": 1614268800,
  5. "page_offset":0,
  6. "page_limit":1000,
  7. "condition":
  8. {
  9. "env_id":"xxx",
  10. "activity_id":"xxx",
  11. "channel_id":"xxx"
  12. }
  13. }

请求打开 H5 实时数据示例

  1. {
  2. "action":"smsMarketingRealTimeData",
  3. "begin_date": 1614182400,
  4. "end_date": 1614268800,
  5. "condition":
  6. {
  7. "env_id":"xxx",
  8. "activity_id":"xxx",
  9. "channel_id":"xxx",
  10. "act_type":"h5"
  11. }
  12. }

返回漏斗数据示例

  1. {
  2. "data_column":[
  3. {
  4. "col_id":"appid",
  5. "col_name":"小程序id",
  6. "col_data_type":"0"
  7. },
  8. {
  9. "col_id":"env_id",
  10. "col_name":"环境id",
  11. "col_data_type":"0"
  12. },
  13. {
  14. "col_id":"activity_id",
  15. "col_name":"活动id",
  16. "col_data_type":"0"
  17. },
  18. {
  19. "col_id":"channel_id",
  20. "col_name":"渠道",
  21. "col_data_type":"0"
  22. },
  23. {
  24. "col_id":"h5_open_uercnt",
  25. "col_name":"h5打开人数",
  26. "col_data_type":"1"
  27. },
  28. {
  29. "col_id":"jump_wxapp_uercnt",
  30. "col_name":"小程序跳转人数",
  31. "col_data_type":"1"
  32. },
  33. {
  34. "col_id":"sms_send_uercnt",
  35. "col_name":"短信下发人数",
  36. "col_data_type":"1"
  37. },
  38. {
  39. "col_id":"sms_send_list",
  40. "col_name":"下发记录数组",
  41. "col_data_type":"0"
  42. },
  43. {
  44. "col_id":"jump_wxapp_uercnt_percent",
  45. "col_name":"跳转人数渠道占比",
  46. "col_data_type":"2"
  47. },
  48. {
  49. "col_id":"h5_open_uercnt_percent",
  50. "col_name":"h5打开人数渠道占比",
  51. "col_data_type":"2"
  52. },
  53. {
  54. "col_id":"h5_sms_rate",
  55. "col_name":"短信到h5转化率",
  56. "col_data_type":"2"
  57. },
  58. {
  59. "col_id":"jump_h5_rate",
  60. "col_name":"h5到跳转转化率",
  61. "col_data_type":"2"
  62. }
  63. ],
  64. "data_value":[
  65. {
  66. "data_value":[
  67. "xxxxxxxxxxxxxxxxxx",
  68. "wedcvfr",
  69. "21ded5cb6001691405171ba161c603d1",
  70. "_cms_sms_",
  71. "5000",
  72. "3000",
  73. "10000",
  74. "[task1:5000,task2:5000]",
  75. "0.535714",
  76. "0.625",
  77. "0.5",
  78. "0.6"
  79. ]
  80. }
  81. ],
  82. "total_num":1
  83. }

云调用

云调用是小程序·云开发提供的在云函数中调用微信开放接口的能力,需要在云函数中通过 wx-server-sdk 使用。

接口方法

  1. openapi.cloudbase.getStatistics

需在 config.json 中配置 cloudbase.getStatistics API 的权限,详情

请求参数

属性类型默认值必填说明
actionstring获取动作,目前支持(smsMarketingOverviewData:短信营销概览数据;smsMarketingConversionData:短信营销转化数据;smsMarketingRealTimeData:短信营销实时数据)
beginDatenumber开始时间戳
endDatenumber结束时间戳
pageOffsetnumber分页 offset【action 取 smsMarketingOverviewData、smsMarketingConversionData 时必填】
pageLimitnumber分页 limit【action 取 smsMarketingOverviewData、smsMarketingConversionData 时必填】
conditionObject查询条件

返回值

Object

返回的 JSON 数据包

属性类型说明
errCodenumber错误码
dataColumnArray.<Object>数据列定义
dataValueArray.<Object>数据行
totalNumnumber总行数

errCode 的合法值

说明最低版本
0成功

dataColumn 的结构

属性类型说明
colIdstring列 id
colNamestring列名
colDataTypestring数据类型(0:string;1:number;2:double)

dataValue 的结构

属性类型说明
dataValueArray.<string>数据值

异常

Object

抛出的异常

属性类型说明
errCodenumber错误码

errCode 的合法值

说明最低版本
-1系统繁忙,此时请开发者稍候再试
10011没有数据

请求概览数据示例

  1. const cloud = require('wx-server-sdk')
  2. cloud.init({
  3. env: cloud.DYNAMIC_CURRENT_ENV,
  4. })
  5. exports.main = async (event, context) => {
  6. try {
  7. const result = await cloud.openapi.cloudbase.getStatistics({
  8. action: 'smsMarketingOverviewData',
  9. condition: {
  10. envId: 'xxx',
  11. activityId: 'xxx',
  12. byChannelId: '0'
  13. },
  14. beginDate: 1614182400,
  15. endDate: 1614268800,
  16. pageOffset: 0,
  17. pageLimit: 1000
  18. })
  19. return result
  20. } catch (err) {
  21. return err
  22. }
  23. }

请求概览数据(按渠道)示例

  1. const cloud = require('wx-server-sdk')
  2. cloud.init({
  3. env: cloud.DYNAMIC_CURRENT_ENV,
  4. })
  5. exports.main = async (event, context) => {
  6. try {
  7. const result = await cloud.openapi.cloudbase.getStatistics({
  8. action: 'smsMarketingOverviewData',
  9. condition: {
  10. envId: 'xxx',
  11. activityId: 'xxx',
  12. byChannelId: '1'
  13. },
  14. beginDate: 1614182400,
  15. endDate: 1614268800,
  16. pageOffset: 0,
  17. pageLimit: 1000
  18. })
  19. return result
  20. } catch (err) {
  21. return err
  22. }
  23. }

请求漏斗图数据示例

  1. const cloud = require('wx-server-sdk')
  2. cloud.init({
  3. env: cloud.DYNAMIC_CURRENT_ENV,
  4. })
  5. exports.main = async (event, context) => {
  6. try {
  7. const result = await cloud.openapi.cloudbase.getStatistics({
  8. action: 'smsMarketingConversionData',
  9. condition: {
  10. envId: 'xxx',
  11. activityId: 'xxx',
  12. channelId: 'xxx'
  13. },
  14. beginDate: 1614182400,
  15. endDate: 1614268800,
  16. pageOffset: 0,
  17. pageLimit: 1000
  18. })
  19. return result
  20. } catch (err) {
  21. return err
  22. }
  23. }

请求打开 H5 实时数据示例

  1. const cloud = require('wx-server-sdk')
  2. cloud.init({
  3. env: cloud.DYNAMIC_CURRENT_ENV,
  4. })
  5. exports.main = async (event, context) => {
  6. try {
  7. const result = await cloud.openapi.cloudbase.getStatistics({
  8. action: 'smsMarketingRealTimeData',
  9. condition: {
  10. envId: 'xxx',
  11. activityId: 'xxx',
  12. channelId: 'xxx',
  13. actType: 'h5'
  14. },
  15. beginDate: 1614182400,
  16. endDate: 1614268800
  17. })
  18. return result
  19. } catch (err) {
  20. return err
  21. }
  22. }

返回漏斗数据示例

  1. {
  2. "dataColumn": [
  3. {
  4. "colId": "appid",
  5. "colName": "小程序id",
  6. "colDataType": "0"
  7. },
  8. {
  9. "colId": "env_id",
  10. "colName": "环境id",
  11. "colDataType": "0"
  12. },
  13. {
  14. "colId": "activity_id",
  15. "colName": "活动id",
  16. "colDataType": "0"
  17. },
  18. {
  19. "colId": "channel_id",
  20. "colName": "渠道",
  21. "colDataType": "0"
  22. },
  23. {
  24. "colId": "h5_open_uercnt",
  25. "colName": "h5打开人数",
  26. "colDataType": "1"
  27. },
  28. {
  29. "colId": "jump_wxapp_uercnt",
  30. "colName": "小程序跳转人数",
  31. "colDataType": "1"
  32. },
  33. {
  34. "colId": "sms_send_uercnt",
  35. "colName": "短信下发人数",
  36. "colDataType": "1"
  37. },
  38. {
  39. "colId": "sms_send_list",
  40. "colName": "下发记录数组",
  41. "colDataType": "0"
  42. },
  43. {
  44. "colId": "jump_wxapp_uercnt_percent",
  45. "colName": "跳转人数渠道占比",
  46. "colDataType": "2"
  47. },
  48. {
  49. "colId": "h5_open_uercnt_percent",
  50. "colName": "h5打开人数渠道占比",
  51. "colDataType": "2"
  52. },
  53. {
  54. "colId": "h5_sms_rate",
  55. "colName": "短信到h5转化率",
  56. "colDataType": "2"
  57. },
  58. {
  59. "colId": "jump_h5_rate",
  60. "colName": "h5到跳转转化率",
  61. "colDataType": "2"
  62. }
  63. ],
  64. "dataValue": [
  65. {
  66. "dataValue": [
  67. "xxxxxxxxxxxxxxxxxx",
  68. "wedcvfr",
  69. "21ded5cb6001691405171ba161c603d1",
  70. "_cms_sms_",
  71. "5000",
  72. "3000",
  73. "10000",
  74. "[task1:5000,task2:5000]",
  75. "0.535714",
  76. "0.625",
  77. "0.5",
  78. "0.6"
  79. ]
  80. }
  81. ],
  82. "totalNum": 1,
  83. "errMsg": "openapi.cloudbase.getStatistics:ok"
  84. }