目录
此内容是否有帮助?

# 留存分析模型 API

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

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

# 留存分析查询

接口URL

/open/retention-analyze?token=xxx

请求方式

POST

Content-Type

application/json

请求Query参数

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

token

# 请求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
}

# 请求参数说明

参数名
示例值
参数类型
是否必填
参数描述
eventView
-
Object

分组属性
endTime 2021-10-30 23:59:59
String

结束时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
filts -
List

全局筛选项
columnDesc app版本
String

字段显示名
columnName app_version
String

字段名
comparator equal
String

参考:模型查询API的筛选表达式
filterType SIMPLE
String

过滤模式,SIMPLE:简单,COMPOUND:复合
ftv ["V1.0"]
List

属性对比值
specifiedClusterDate 2022-01-24
String

集群指定日期
tableType event
String

表类型,event:事件表,user:用户表
timeUnit String

属性对比值单位,仅对relativeEvent*有效:day,hour,minute
firstDayOfWeek 1
Integer

当timeParticleSize为week时,指定周首日,1:星期一,2:星期二, ..,7:星期日,最小1,最大7
groupBy -
List

分组属性,可以有零个或者多个
columnDesc 浏览器
String

字段显示名
columnName browser
String

字段名
propertyRange String

自定义属性区间
specifiedClusterDate 2022-01-24
String

集群指定日期
tableType event
String

表类型,event:事件表,user:用户表
recentDay String

相对时间(此项不可与起始时间和结束时间同时为空)
relation and
String

逻辑关系,and:逻辑与,or:逻辑或
startTime 2021-10-01 00:00:00
String

起始时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
statType retention
String

统计类型,留存:retention,流失:lost
taIdMeasureVo -
Object

分析主体配置
columnDesc 用户唯一ID
String

字段显示名
columnName #user_id
String

字段名
tableType event
String

表类型,event:事件表,user:用户表
timeParticleSize week
String

分析的时间单位
minute:按1分钟
minute5:按5分钟(v3.5开始支持)
minute10:按10分钟(v3.5开始支持)
hour:按小时
day:按天
week:按周
month:按月
total:总计
unitNum 1
Integer

留存期限
events
-
List

事件指标列表
eventName login
String

事件名称,特别的,可以使用 anyEvent 表示任意事件
eventNameDisplay String

事件显示名
filts -
List

条件列表列表
columnDesc app_version
String

字段显示名
columnName app_version
String

字段名称
comparator equal
String

参考:模型查询API的筛选表达式
filterType SIMPLE
String

过滤模式,SIMPLE:简单,COMPOUND:复合
ftv ["V1.0"]
List

属性对比值
specifiedClusterDate 2022-01-26
String

集群指定日期
tableType event
String

表类型,event:事件表,user:用户表
timeUnit String

过滤时间单位
relation and
String

逻辑关系,and:逻辑与,or:逻辑或
relationUser and
String

用户筛选逻辑关系,and:逻辑与,or:逻辑或
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

同时展示聚合方法 analysis 取值:


描述
是否需要属性
TOTAL_TIMES
总次数

TRIG_USER_NUM
触发用户数

PER_CAPITA_TIMES
人均次数

SUM
数值总和

PER_CAPITA_NUM
人均值

STAGE_ACC
阶段累计总和

STAGE_ACC_PCV
阶段累计人均值

TRUE
为真数

FALSE
为假数

IS_NOT_EMPTY
不为空数

IS_EMPTY
为空数

# 成功响应示例

{
  "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
返回结果
result_generate_time 2022-01-01 00:00:00
String
计算结果生成时间
state_avg -
Object
结果map,key为type,value为留存分组
{type} -
List
type取值,0:留存,1:流失,2:统计
groupCols ["总体"]
List
分组列
initNum 0
Integer
初始值
isTotal 1
Integer
是否是汇总,1:是,0:否
lastValidDateVerticalIndexs ["-", "4"]
List
最后有效日期索引
values ["-", "0.998"]
List
值列表,"-"或数字
x ["2021-09-27"]
List
日期列表
y -
Object
y轴数据
{type} -
Object
type取值,0:留存,1:流失,2:统计
{date} -
List
key为日期
groupCols ["总体"]
List
分组列
includeToday false
Boolean
是否包含今日
initNum 7388
Integer
初始值
isTotal 1
Integer
是否是汇总,1:是,0:否
values ["7388"]
List
值列表
z ["login"]
List
事件名列表

错误响应示例

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

# 留存分析用户列表

接口URL

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

请求方式

POST

Content-Type

application/json

请求Query参数

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

token

# 请求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
}

# 请求参数说明

参数名
示例值
参数类型
是否必填
参数描述
projectId
0
String

参数描述
eventView
-
Object

分组属性表
startTime 2019-11-24 00:00:00
String

起始时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
endTime 2019-11-26 00:00:00
String

结束时间(格式:yyyy-MM-dd HH:mm:ss),相对时间为空时有效
recentDay 1-3
String

相对时间(此项不可与起始时间和结束时间同时为空)
statType retention
String
统计类型,留存:retention,流失:lost
timeParticleSize day
String

分析的时间单位
minute:按1分钟
minute5:按5分钟(v3.5开始支持)
minute10:按10分钟(v3.5开始支持)
hour:按小时
day:按天
week:按周
month:按月
total:总计
unitNum 7
Integer
留存期限
groupBy -
List

分组属性,可以有零个或者多个
columnName #province
String

字段名
tableType event
String

表类型,event:事件表,user:用户表
events
List

事件指标列表
type first
String

first:初始事件
second:回访事件
simultaneous_display:同时展示
init_date_stat:初始日期指标
eventName player_register
String

事件名称,特别的,可以使用 anyEvent 表示任意事件
relation and
String

逻辑关系,and:逻辑与,or:逻辑或
filts -
List

筛选项列表
columnName #province
String

字段名称
comparator equal
String

参考:模型查询API的筛选表达式
ftv ["江苏省"]
List

属性对比值
tableType event
String

表类型,event:事件表,user:用户表
sliceDate
"2019-11-26"
String

事件所在日期
sliceInterval
3
List

时段下标
0:初始事件用户数
1:当日
2:1日后
3:2日后
timeoutSeconds
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
返回信息