menu
Is this helpful?

# 留存分析模型 API

调用方法请参见Open API文档中的调用方法描述。

可阅读使用手册中 留存分析 了解使用场景。

# 留存分析查询

接口URL

/open/retention-analyze?token=xxx

请求方式

POST

Content-Type

application/json

请求Query参数

参数名 示例值 参数类型 是否必填 参数描述
token xxx String 查询密钥

# 请求Body参数

{
  "eventView":{
    "endTime":"2021-10-30 23:59:59",
    "filts":[
      {
        "columnDesc":"app版本",
        "columnName":"app_version",
        "comparator":"equal",
        "filterType":"SIMPLE",
        "ftv":[
          "V1.0"],
        "specifiedClusterDate":"2022-01-24",
        "tableType":"event",
        "timeUnit":""
      }],
    "firstDayOfWeek":1,
    "groupBy":[
      {
        "columnDesc":"浏览器",
        "columnName":"browser",
        "propertyRange":"",
        "specifiedClusterDate":"2022-01-24",
        "tableType":"event"
      }],
    "recentDay":"",
    "relation":"and",
    "startTime":"2021-10-01 00:00:00",
    "statType":"retention",
    "taIdMeasureVo":{
      "columnDesc":"用户唯一ID",
      "columnName":"#user_id",
      "tableType":"event"
    },
    "timeParticleSize":"week",
    "unitNum":1
  },
  "events":[
    {
      "eventName":"login",
      "eventNameDisplay":"",
      "filts":[
        {
          "columnDesc":"app_version",
          "columnName":"app_version",
          "comparator":"equal",
          "filterType":"SIMPLE",
          "ftv":["V1.0"],
          "specifiedClusterDate":"2022-01-26",
          "tableType":"event",
          "timeUnit":""
        }],
      "relation":"and",
      "relationUser":"and",
      "type":"first"
    },
    {
      "eventName":"logout",
      "eventNameDisplay":"",
      "filts":[
      ],
      "relation":"and",
      "relationUser":"and",
      "type":"second"
    },
    {
      "analysis":"TOTAL_TIMES",
      "analysisDesc":"总次数",
      "eventName":"activity_attend",
      "eventNameDisplay":"",
      "filts":[
      ],
      "quota":"",
      "relation":"and",
      "relationUser":"and",
      "type":"simultaneous_display"
    }],
    "projectId": 377,
    "limit": 2,
    "timeoutSeconds": 10,
    "useCache": true,
    "zoneOffset": 10
}

# 请求参数说明

$$参数名 示例值 参数类型 是否必填 参数描述
eventView - Object 指标公共属性部分
eventView.endTime 2021-10-30 23:59:59 String 结束时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
eventView.filts - List 全局筛选项
eventView.filts.columnDesc app版本 String 字段显示名
eventView.filts.columnName app_version String 字段名
eventView.filts.comparator equal String 参考:模型查询API的筛选表达式
eventView.filts.filterType SIMPLE String 过滤模式,SIMPLE:简单,COMPOUND:复合
eventView.filts.ftv ["V1.0"] List 用于属性比较边界的字面常量
eventView.filts.specifiedClusterDate 2022-01-24 String 指定对应日期的标签历史版本
eventView.filts.tableType event String 表类型枚举值
eventView.filts.timeUnit String 属性对比值单位,仅对relativeEvent*有效:day,hour,minute
eventView.firstDayOfWeek 1 Integer 当timeParticleSize为week时,指定周首日,1:星期一,2:星期二, ..,7:星期日,最小1,最大7
eventView.groupBy - List 分组属性,可以有零个或者多个
eventView.groupBy.columnDesc 浏览器 String 字段显示名
eventView.groupBy.columnName browser String 字段名
eventView.groupBy.propertyRange String 自定义属性区间
eventView.groupBy.specifiedClusterDate 2022-01-24 String 指定对应日期的标签历史版本
eventView.groupBy.tableType event String 表类型枚举值
eventView.recentDay String 相对时间(此项不可与起始时间和结束时间同时为空)
eventView.relation and String 逻辑关系,and:逻辑与,or:逻辑或
eventView.startTime 2021-10-01 00:00:00 String 起始时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
eventView.statType retention String 统计类型,留存:retention,流失:lost
eventView.taIdMeasureVo - Object 分析主体配置
eventView.taIdMeasureVo.columnDesc 用户唯一ID String 字段显示名
eventView.taIdMeasureVo.columnName #user_id String 字段名
eventView.taIdMeasureVo.tableType event String 表类型枚举值
eventView.timeParticleSize week String 分析的时间单位
  • day:按天

  • week:按周

  • month:按月

eventView.unitNum 1 Integer 留存期限
events - List 事件指标列表
events.eventName login String 指标事件名称,可以使用 anyEvent 表示任意事件
events.eventNameDisplay String 自定义指标显示名
events.analysis TRIG_USER_NUM String 分析角度,聚合操作,具体见留存同时展示聚合类型枚举值
events.analysisDesc 总次数 String 分析角度描述信息
events.quota String 指标属性(配合analysis,意思是哪个属性的哪个分析角度)
events.filts - List 条件列表列表
events.filts.columnDesc app_version String 字段显示名
events.filts.columnName app_version String 字段名称
events.filts.comparator equal String 参考:模型查询API的筛选表达式
events.filts.filterType SIMPLE String 过滤模式,SIMPLE:简单,COMPOUND:复合
events.filts.ftv ["V1.0"] List 用于属性比较边界的字面常量
events.filts.specifiedClusterDate 2022-01-26 String 指定对应日期的标签历史版本
events.filts.tableType event String 表类型枚举值
events.filts.timeUnit String 过滤时间单位
events.relation and String 逻辑关系,and:逻辑与,or:逻辑或
events.relationUser and String 用户筛选逻辑关系,and:逻辑与,or:逻辑或
events.type first String 留存事件类型,
  • first:初始事件

  • second:回访事件

  • simultaneous_display:同时展示

  • init_date_stat:初始日期指标

projectId 377 Integer 项目ID
limit 2 Integer 每分析对象的分组数上限,可选参数,默认为1000,最大为10000
timeoutSeconds 10 Integer 请求超时参数,超时则取消查询任务
useCache true Boolean 使用缓存,可选参数,默认为true
zoneOffset 10 Integer 时区

# 成功响应示例

{
  "data": {
    "result_generate_time": "2022-01-01 00:00:00",
    "state_avg": {
      "0": [
        {
          "groupCols": [
            "总体"
          ],
          "initNum": 0,
          "isTotal": 1,
          "lastValidDateVerticalIndexs": [
            "-",
            "4"
          ],
          "values": [
            "-",
            "0.998"
          ]
        },
        {
          "groupCols": [
            "Chrome"
          ],
          "initNum": 0,
          "isTotal": 0,
          "lastValidDateVerticalIndexs": [
            "-",
            "4"
          ],
          "values": [
            "-",
            "0.9981"
          ]
        }
      ],
      "1": [
        {
          "groupCols": [
            "总体"
          ],
          "initNum": 0,
          "isTotal": 1,
          "lastValidDateVerticalIndexs": [
            "-",
            "4"
          ],
          "values": [
            "-",
            "1"
          ]
        },
        {
          "groupCols": [
            "Chrome"
          ],
          "initNum": 0,
          "isTotal": 0,
          "lastValidDateVerticalIndexs": [
            "-",
            "4"
          ],
          "values": [
            "-",
            "1"
          ]
        }
      ],
      "2": [
        {
          "groupCols": [
            "总体"
          ],
          "initNum": 0,
          "isTotal": 1,
          "lastValidDateVerticalIndexs": [],
          "values": [
            "-",
            "132405.4"
          ]
        },
        {
          "groupCols": [
            "Chrome"
          ],
          "initNum": 0,
          "isTotal": 0,
          "lastValidDateVerticalIndexs": [],
          "values": [
            "-",
            "66343.2"
          ]
        }
      ]
    },
    "x": [
      "2021-09-27",
      "2021-10-04",
      "2021-10-11",
      "2021-10-18",
      "2021-10-25"
    ],
    "y": {
      "0": {
        "2021-09-27": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7388,
            "isTotal": 1,
            "values": [
              "7388",
              "7374"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3647,
            "isTotal": 0,
            "values": [
              "3647",
              "3642"
            ]
          }
        ],
        "2021-10-04": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7861,
            "isTotal": 1,
            "values": [
              "7861",
              "7844"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3939,
            "isTotal": 0,
            "values": [
              "3939",
              "3930"
            ]
          }
        ],
        "2021-10-11": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8013,
            "isTotal": 1,
            "values": [
              "8013",
              "7994"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4062,
            "isTotal": 0,
            "values": [
              "4062",
              "4054"
            ]
          }
        ],
        "2021-10-18": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8553,
            "isTotal": 1,
            "values": [
              "8553",
              "8543"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4225,
            "isTotal": 0,
            "values": [
              "4225",
              "4218"
            ]
          }
        ],
        "2021-10-25": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7414,
            "isTotal": 1,
            "values": [
              "7414",
              "7397"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3741,
            "isTotal": 0,
            "values": [
              "3741",
              "3733"
            ]
          }
        ]
      },
      "1": {
        "2021-09-27": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7388,
            "isTotal": 1,
            "values": [
              "7388",
              "7388"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3647,
            "isTotal": 0,
            "values": [
              "3647",
              "3647"
            ]
          }
        ],
        "2021-10-04": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7861,
            "isTotal": 1,
            "values": [
              "7861",
              "7861"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3939,
            "isTotal": 0,
            "values": [
              "3939",
              "3939"
            ]
          }
        ],
        "2021-10-11": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8013,
            "isTotal": 1,
            "values": [
              "8013",
              "8013"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4062,
            "isTotal": 0,
            "values": [
              "4062",
              "4062"
            ]
          }
        ],
        "2021-10-18": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8553,
            "isTotal": 1,
            "values": [
              "8553",
              "8553"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4225,
            "isTotal": 0,
            "values": [
              "4225",
              "4225"
            ]
          }
        ],
        "2021-10-25": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7414,
            "isTotal": 1,
            "values": [
              "7414",
              "7414"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3741,
            "isTotal": 0,
            "values": [
              "3741",
              "3741"
            ]
          }
        ]
      },
      "2": {
        "2021-09-27": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7388,
            "isTotal": 1,
            "values": [
              "0",
              "125324"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3647,
            "isTotal": 0,
            "values": [
              "0",
              "62105"
            ]
          }
        ],
        "2021-10-04": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7861,
            "isTotal": 1,
            "values": [
              "0",
              "132130"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3939,
            "isTotal": 0,
            "values": [
              "0",
              "65971"
            ]
          }
        ],
        "2021-10-11": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8013,
            "isTotal": 1,
            "values": [
              "0",
              "134691"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4062,
            "isTotal": 0,
            "values": [
              "0",
              "68566"
            ]
          }
        ],
        "2021-10-18": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 8553,
            "isTotal": 1,
            "values": [
              "0",
              "144030"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 4225,
            "isTotal": 0,
            "values": [
              "0",
              "71345"
            ]
          }
        ],
        "2021-10-25": [
          {
            "groupCols": [
              "总体"
            ],
            "includeToday": false,
            "initNum": 7414,
            "isTotal": 1,
            "values": [
              "0",
              "125852"
            ]
          },
          {
            "groupCols": [
              "Chrome"
            ],
            "includeToday": false,
            "initNum": 3741,
            "isTotal": 0,
            "values": [
              "0",
              "63729"
            ]
          }
        ]
      }
    },
    "z": [
      "login",
      "logout",
      "activity_attend"
    ]
  },
  "return_code": 0,
  "return_message": "success"
}

# 响应参数说明

$$参数名 示例值 参数类型 参数描述
return_code 0 Integer 返回码
return_message success String 返回信息
data - Object 返回结果
data.result_generate_time 2022-01-01 00:00:00 String 计算结果生成时间
data.state_avg - Object 结果map,key为type,value为留存分组
data.state_avg.{type} - List type取值,0:留存,1:流失,2:同时展示指标
data.state_avg.{type}.groupCols ["总体"] List 分组列
data.state_avg.{type}.initNum 0 Integer 初始值
data.state_avg.{type}.isTotal 1 Integer 是否是汇总,1:是,0:否
data.state_avg.{type}.lastValidDateVerticalIndexs ["-", "4"] List 最后完整数据日期索引
data.state_avg.{type}.values ["-", "0.998"] List 值列表,"-"或数字
data.x ["2021-09-27"] List 日期列表
data.y - Object y轴数据
data.y.{type} - Object type取值,0:留存,1:流失,2:统计
data.y.{type}.{date} - List key为日期
data.y.{type}.{date}.groupCols ["总体"] List 分组列
data.y.{type}.{date}.includeToday false Boolean 是否包含今日
data.y.{type}.{date}.initNum 7388 Integer 初始值
data.y.{type}.{date}.isTotal 1 Integer 是否是汇总,1:是,0:否
data.y.{type}.{date}.values ["7388"] List 值列表
data.z ["login"] List 事件名列表

错误响应示例

{
    "return_code": -1008,
    "return_message": "参数(token)为空"
}
参数名 示例值 参数类型 参数描述
return_code -1008 Integer 返回码
return_message 参数(token)为空 String 返回信息

# 留存分析全量下载

接口URL

/open/streaming-download/retention-analyze?token=xxx

请求方式

POST

Content-Type

application/json

请求Query参数

参数名 示例值 参数类型 是否必填 参数描述
token xxx String 查询密钥

# 请求Body参数

{
        "eventView": {
                "collectFirstDay": 1,
                "endTime": "2022-03-08 16:55:10",
                "filts": [],
                "groupBy": [{
                        "columnDesc": "渠道",
                        "columnName": "channel",
                        "propertyRange": "",
                        "specifiedClusterDate": "2022-03-09",
                        "tableType": "event"
                }],
                "recentDay": "1-7",
                "relation": "and",
                "startTime": "2022-03-02 16:55:10",
                "statType": "retention",
                "taIdMeasureVo": {
                        "columnDesc": "用户唯一ID",
                        "columnName": "#user_id",
                        "tableType": "event"
                },
                "timeParticleSize": "day",
                "unitNum": 7
        },
        "events": [{
                "eventName": "Recharge",
                "eventNameDisplay": "",
                "filts": [],
                "relation": "and",
                "relationUser": "and",
                "type": "first"
        }],
        "projectId": 390
}

# 请求参数说明

$$参数名 示例值 参数类型 是否必填 参数描述
eventView - Object 参数内容与留存分析查询接口一致
events - List 参数内容与留存分析查询接口一致
projectId 377 Integer 项目ID
zoneOffset 10 Integer 时区

# 响应

同TE系统留存分析全量下载

# 留存分析用户列表

接口URL

/open/retention-user-list?token=xxx

请求方式

POST

Content-Type

application/json

请求Query参数

参数名 示例值 参数类型 是否必填 参数描述
token xxx String 查询密钥

# 请求Body参数

{
  "projectId": 0,
  "eventView": {
    "startTime": "2019-11-24 00:00:00",
    "endTime": "2019-11-26 00:00:00",
    "recentDay": "1-3",
    "statType": "retention",
    "timeParticleSize": "day",
    "unitNum": 7,
    "groupBy": [
      {
        "columnName": "#province",
        "tableType": "event"
      }
    ]
  },
  "events": [
    {
      "type": "first",
      "relation": "and",
      "eventName": "player_register",
      "filts": [
        {
          "columnName": "#province",
          "comparator": "equal",
          "ftv": [
            "江苏省",
            "上海市"
          ],
          "tableType": "event"
        },
        {
          "columnName": "user_level",
          "comparator": "greater",
          "ftv": [
            "2"
          ],
          "tableType": "user"
        }
      ]
    },
    {
      "type": "second",
      "relation": "and",
      "eventName": "obtain_diamond",
      "filts": [
        {
          "columnName": "#os",
          "comparator": "equal",
          "ftv": [
            "android"
          ],
          "tableType": "event"
        },
        {
          "$ref": "$.events[0].filts[1]"
        }
      ]
    }
  ],
  "sliceDate": "2019-11-26",
  "sliceInterval": 3,
  "timeoutSeconds": 10,
  "zoneOffset": 10
}

# 请求参数说明

$$参数名 示例值 参数类型 是否必填 参数描述
projectId 0 String 参数描述
eventView - Object 参数内容与留存分析查询接口一致
events List 参数内容与留存分析查询接口一致
sliceDate "2019-11-26" String 哪个日期进行下钻
sliceGroupVal ["北京市"] List 哪个分组进行下钻
sliceInterval 3 List 哪个流程间隔进行下标
  • 0:初始事件用户数

  • 1:当日

  • 2:1日后

  • 3:2日后

timeoutSeconds 10 Integer 请求超时参数,超时则取消查询任务
zoneOffset 10 Integer 时区

# 成功响应示例

{
  "data": {
    "datalist": [
      {
        "#account_id": "v47739399",
        "#distinct_id": "v88658799",
        "user_level": 11,
        "register_time": "2019-11-26 19:13:20",
        "diamond_num": 1182,
        "latest_login_time": "2019-11-26 20:16:19",
        "channel": "华为应用市场",
        "#user_id": 20459799
      },
      {
        "#account_id": "i7819568",
        "#distinct_id": "i14522048",
        "user_level": 4,
        "register_time": "2019-11-26 23:56:17",
        "diamond_num": 1006,
        "latest_login_time": "2019-11-26 23:59:59",
        "channel": "360手机助手",
        "#user_id": 3351248
      },
      {
        "#account_id": "g7812426",
        "#distinct_id": "g14508786",
        "user_level": 14,
        "register_time": "2019-11-26 17:54:13",
        "diamond_num": 245,
        "first_recharge_time": "2019-11-26 18:08:58",
        "latest_login_time": "2019-11-26 20:16:19",
        "channel": "小米应用商店",
        "#user_id": 3348186
      },
      {
        "#account_id": "a7812000",
        "#distinct_id": "a14508000",
        "user_level": 3,
        "register_time": "2019-11-26 17:27:28",
        "diamond_num": 1153,
        "latest_login_time": "2019-11-26 18:45:58",
        "channel": "app store",
        "#user_id": 3348000
      }
    ],
    "columMeta": {
      "#account_id": "账户ID",
      "#distinct_id": "访客ID",
      "user_level": "用户等级",
      "register_time": "注册时间",
      "diamond_num": "当前拥有钻石数",
      "first_recharge_time": "首次充值时间",
      "latest_login_time": "最后登录时间",
      "channel": "渠道"
    }
  },
  "return_code": 0,
  "return_message": "success"
}

# 响应参数说明

参数名 示例值 参数类型 参数描述
return_code 0 Integer 返回码
return_message success String 返回信息
data - Object 返回结果
data.datalist - List 用户信息
data.columMeta - Map 字段含义映射

错误响应示例

{
    "return_code": -1008,
    "return_message": "参数(token)为空"
}
参数名 示例值 参数类型 参数描述
return_code -1008 Integer 返回码
return_message 参数(token)为空 String 返回信息

# 留存分析用户列表下载

接口URL

/open/streaming-download/retention-user-list?token=xxx

请求方式

POST

Content-Type

application/json

请求Query参数

参数名 示例值 参数类型 是否必填 参数描述
token xxx String 查询密钥

# 请求Body参数

{
    "eventView": {
            "collectFirstDay": 1,
            "endTime": "2022-03-07 17:09:58",
            "filts": [],
            "groupBy": [],
            "recentDay": "1-7",
            "relation": "and",
            "startTime": "2022-03-01 17:09:58",
            "statType": "retention",
            "taIdMeasureVo": {
                    "columnDesc": "User ID",
                    "columnName": "#user_id",
                    "tableType": "event"
            },
            "timeParticleSize": "day",
            "unitNum": 7
    },
    "events": [{
            "eventName": "Login",
            "eventNameDisplay": "",
            "filts": [],
            "relation": "and",
            "relationUser": "and",
            "type": "first"
    }, {
            "eventName": "Recharge",
            "eventNameDisplay": "",
            "filts": [],
            "relation": "and",
            "relationUser": "and",
            "type": "second"
    }],
    "projectId": 319,
    "isLost": false,
    "sliceDate": "2022-03-01",
    "sliceInterval": 0,
    "selectedColumns": ["#account_id", "#distinct_id"],
    "zoneOffset": 10
}

# 请求参数说明

$$参数名 示例值 参数类型 是否必填 参数描述
eventView - Object 参数内容与留存分析查询接口一致
events - List 参数内容与留存分析查询接口一致
projectId 377 Integer 项目ID
isLost false boolean 是否流失
sliceDate "2019-11-26" String 事件所在日期
sliceGroupVal ["北京市"] List 哪个分组进行下钻
sliceInterval 0 Integer 哪个留存间隔进行下标
  • 0:初始事件用户数

  • 1:当前{日期单位}

  • 2:1{日期单位}后

  • 3:2{日期单位}后

selectedColumns ["#account_id"] List 所需下载的列
zoneOffset 10 Integer 时区

TIP

请求参数主体可以从TE系统留存分析页面导出,添加上isLost、sliceDate、sliceGroupVal、sliceInterval、selectedColumns几个参数

# 响应

同TE系统留存分析用户列表全量下载

# 留存分析通用枚举

# 留存同时展示聚合类型枚举值

描述 是否需要属性
TOTAL_TIMES 总次数
TRIG_USER_NUM 触发用户数
PER_CAPITA_TIMES 人均次数
SUM 数值总和
PER_CAPITA_NUM 人均值
STAGE_ACC 阶段累计总和
STAGE_ACC_PCV 阶段累计人均值
TRUE 为真数
FALSE 为假数
IS_NOT_EMPTY 不为空数
IS_EMPTY 为空数