更新时间:2023.05.29 20:48:39
为了更好的跟企业数据产品打通,更好的发挥数据价值,我们通过开放openapi的方式,提供基于本产品进行二次开发的能力,您可以通过调用openapi获取指标数据,以便集成在其他数据产品中。
Context-Path: /datafinder
Path:/openapi/v1/analysis
Method: POST
Content-type: application/json
Body:
请求参数均采用查询 DSL 进行描述
数据编码为 UTF-8
Response:
结构说明:
{ "code": 200, # 返回码,200代表查询返回正确,非200请参考message "data": [ { "error_message": null, # 错误消息 "region_info_map": {}, # 区域查询时区域id映射 "trace_id": "6bcbc580ab144afd8b8a792349ed9a5a", # 链路追踪标识 "query_id": "a00:p00:c00:q00", # 子查询标识 "result_status": "SUCCESS", # 子查询状态 "execute_time": 0, # 子查询执行时间 "data_item_list": [ # 子查询返回数据 { "filter_label": null, # 过滤标签 "group_by_key": "__all", # 分组key "data": [ # 指标数据 142099, 145940, 139035, 148457, 154313 ], "sum_value_square": 106673323444, # 指标平方和 "composed_item_key": null, "item_key": "a00:p00:c00:q00:f00_0", "show_name": "活跃用户数", "sum": 729844, # 指标求和值 "event_params": {}, "filter_value": null, "event_name_alias": "", "prefix_key": "active_user", "avg": 145968.8, # 指标平均值 "result_type_unit": null, "event_show_name": "应用启动", "event_indicator_params": {}, "composed_label": null, "show_label": "active_user", "suffix_key": "__all", "origin_profile_params": {}, "result_type": "event_users", "attr_value_name": "", "result_type_label": "活跃用户数", "is_disabled": null, "profile_params": {}, "event_label": "active_user", "origin_key": "__all", "event_id": null, "is_compute": null, "name": "active_user, __all", "event_name": "app_launch", "group_by_type": "user_attr" } ], "error_code": null, "date_index_list": [ # 数据时间索引值,与数据一一对应 "20200606", "20200607", "20200608", "20200609", "20200610" ] } ], "message": "success" # 错误消息 }
bc
为创建的 RangersClient, 其初始化请参考 “OpenAPI SDK 使用说明”, 各语言的 SDK 都提供了类似的接口
调用(Python):
dsl = { "version": 3, "app_ids": [164314], "use_app_cloud_id": True, "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 5, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "content": { "query_type": "event", "profile_groups_v2": [], "profile_filters": [], "queries": [ [ { "event_type": "origin", "show_name": "活跃用户数", "event_name": "app_launch", "groups_v2": [], "filters": [], "show_label": "active_user", "event_indicator": "event_users" } ] ], "option": { "skip_cache": False } } } # SaaS 逻辑 resp = bc.data_finder("/openapi/v1/analysis", body=dsl) print(resp.content)
注意:私有化和SaaS有所不同,需要分为两个接口来获取查询结果。
Context-Path: /datafinder
Path:/openapi/v1/analysis
Method: POST
Content-type: application/json
Body:
请求参数均采用查询 DSL 进行描述
数据编码为 UTF-8
Response:
{ "code": 200, "message": "success" "data": { "result_id": xxx } }
字段含义说明
Field | Type | Description |
---|---|---|
result_id | int | 查询结果ID |
Context-Path: /datafinder
Path:/openapi/v1/analysis/{result_id}/result
Method: GET
Content-type: application/json
Path-parameters:
Parameter | Type | Description | Required |
---|---|---|---|
result_id | int | 查询结果ID | true |
Response:
返回结构同SaaS的查询返回结构
bc
为创建的 RangersClient, 其初始化请参考 “OpenAPI SDK 使用说明”, 各语言的 SDK 都提供了类似的接口
调用(Python):
dsl = { "version": 3, "app_ids": [164314], "use_app_cloud_id": True, "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 5, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "content": { "query_type": "event", "profile_groups_v2": [], "profile_filters": [], "queries": [ [ { "event_type": "origin", "show_name": "活跃用户数", "event_name": "app_launch", "groups_v2": [], "filters": [], "show_label": "active_user", "event_indicator": "event_users" } ] ], "option": { "skip_cache": False } } } # 私有化逻辑 resp = bc.data_finder("/openapi/v1/analysis", body=dsl) result_id = resp.json()["data"]["result_id"] resp2 = bc.data_finder(f"/openapi/v1/analysis/{result_id}/result") print(resp2.content)
先打开浏览器的开发者工具(快捷键F12),然后配置好查询条件,查看页面的 datafinder/api/v1/analysis
请求,该请求的body即为该查询的DSL,可以直接拷贝使用。
具体参考各语言版本的 OpenAPI SDK
{ "version": 3, # 版本号 "app_ids": [164314], # 查询应用唯一标识 "use_app_cloud_id": True, # 使用应用云唯一标识 "periods": [ # 查询时间范围定义 { "granularity": "day", # 时间粒度,分钟/小时/天/周/月 "type": "last", # 时间规则 最近x天或者范围 "last": { # 最近x天定义 "amount": 5, # 查询数量 "unit": "day" # 查询单位 }, "timezone": "Asia/Shanghai" # 时区 } ], "content": { "query_type": "event", # 查询类型 "profile_groups_v2": [], # 公共属性分组 "profile_filters": [], # 公共属性过滤 "queries": [ # 查询定义 [ { "event_type": "origin", # 事件类型,原始事件,虚拟事件,圈选事件 "show_name": "活跃用户数", # 查询名称 "event_name": "app_launch", # 事件名称 "groups_v2": [], # 事件分组 "filters": [], # 事件过滤 "show_label": "active_user", # 结果标识 "event_indicator": "event_users" # 指标名称 } ] ], "option": { # 查询可选参数 "skip_cache": False # 不跳过缓存 } } }
DSL(Domain Specific Language) 简单来讲就是一个json格式的文本,来灵活的定义复杂的查询需求。
{ "version": 3, # DSL的版本,本文档中全部为3 "app_ids": [], # 目标app,支持多个 "use_app_cloud_id": true, # app_ids参数中是否为app_cloud_id。请设置为true,false仅供内部使用 "periods": [{}], # 查询时间段,支持多个 "content": {}, # 具体的查询内容字段,与contents传一个,结构相同 "contents": [{}], "option": {}, # json格式数据,请求相关的选项参数,不同的查询各不相同 "show_option": {} # json格式数据,在结果中原样返回 }
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
version | int | DSL的版本,本文档中全部为3 | true |
app_ids | int数组 | 目标app,支持多个 | true |
use_app_cloud_id | boolean | pp_ids参数中是否为app_cloud_id。false仅供内部使用 | |
periods | json的数组 | 查询时间段,支持多个 | true |
content | json | 具体的查询内容字段,与contents传一个,结构相同 | |
contents | json数组 | ||
option | json | 请求相关的选项参数,不同的查询各不相同 | |
show_option | json | 在结果中原样返回,前端展示使用,不影响查询结果 |
[{ "granularity": "", "type": "", "last": { "unit":"", "amount":int }, "range": [int,int] "timezone": "Asia/Shanghai", "interval": int, "real_time": boolean, "week_start": int }]
字段 | 取值与含义 | 是否必须 | 例子 |
---|---|---|---|
type | 时间范围类型。 | 否 | 默认range |
last | type为last时,有效。相对时间 | type为last是必须传 | { |
range | type为range时,有效。绝对时间 | {range: [1586102400, 1588780799]} | |
spans | type为past_range时有效。是一个list,传2个,第一个代表开始时间,第二个代表结束时间。每一个list的结构为:
|
| |
granularity | 时间粒度。对指定的时间范围按照时间粒度进行拆分
| 否 | 默认all |
interval | 时间粒度。以自定义的时间粒度进行拆分,时间单位秒,比如130秒 | 否 | |
timezone | 时间范围的时区 | 否 | 默认Asia/Shanghai |
real_time | 是否是实时查询,如果为true,只会查询实时的库。这部分会被option里面的real_time覆盖。 | 否 | |
week_start | granularity为周时,可以指定周的起始日期。比如5表示 周五-周四 | 否 | 默认1,周一到周日 |
align_unit | 对齐单元 |
{ "profile_groups_v2": [], #分组条件,只支持公共属性。 "profile_filters": [{}], #过滤条件 "orders": [], #排序规则 "query_type": "", #查询类型 "queries": [[],[]], #查询,二维数组。不同的查询类型需要设置不同的queries数组 "option": {}, #查询选项 "page": {}, #查询分页,limit相关配置 }
[{ "show_name": "1", "show_label": 1, "expression": { "logic": "and", "conditions": [{ "property_name": "custom_server_gender", "property_type": "profile", "property_operation": "=", "property_values": ["1"] }] } }]
说明
私有化里面 "property_type" : "profile" 需要修改为 "property_type": "user_profile"
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
show_name | string | 前端参数 | |
show_label | string | 前端参数 | |
expression | json | 条件表达式 | 是 |
logic | string | expression的conditions 的逻辑关系and/or | 是 |
conditions | json数组 | 具体的条件 | 是 |
单个条件
{ "property_name": "custom_server_gender", "property_type": "profile", "property_operation": "=", "property_values": ["1"] }
说明
私有化里面 "property_type" : "profile" 需要修改为 "property_type": "user_profile"
字段 | 类型 | 取值与含义 | 是否必须 | 例子 |
---|---|---|---|---|
property_name | string | 属性名称 | age、custom_server_gender | |
property_type | string | 属性类型 | profile表示用户属性(saas),在私有化里面使用user_profile | |
property_operation | string | 计算表达式 | 是 | 不同的property_type支持的property_operation不一样 |
property_values | string/int/float数组 | 属性的表达式的值 | 是 | |
property_value_type | 属性的表达式的值的类型
| 否 |
"profile_groups_v2": [ { "property_type":"profile", "property_name":"user_is_new" }, { "property_type":"profile", "property_name":"os_name" } ]
说明
私有化里面 "property_type" : "profile" 需要修改为 "property_type": "user_profile"
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
profile_groups_v2 | json数组 | 公共属性名称 |
查询的类型
事件查询:event
留存查询:retention
转换查询:funnel
用户路径查询:path_find
生命周期查询:life_cycle
web查询:web_session
topk查询:event_topk
LTV查询:ltv
归因查询:behavior_attribution
成分查询:composition
广告查询:advertise
置信度查询:confidence
查询条件,二维数组,不同的查询类型,需要组织对应的query数组。具体参考案例
{ "event_name": "any_event", "event_id":1, "event_type": "origin", "show_name": "总次数", "groups_v2": [], "filters": [], "show_label": "A", "event_indicator": "events", "measure_info": {} }
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
event_name | string | 事件名称 | |
event_id | int | 事件id | event_name和event_id必须有一个 |
event_type | string | 事件类型 | 是 |
groups_v2 | string数组 | 同profile_groups_v2,只能取事件属性、事件公共属性 | |
filter | 数组 | 同profile_filters | |
show_label | string | 前段参数 | |
event_indicator | string | 计算指标:
| 是 |
measure_info | 计算指标补充,在 event_indicator 为 measure 时使用
|
{ "event_indicator": "measure", "measure_info": { "measure_type": "sum", "property_name": "time" } }
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
measure_type | string | 测量尺度,可取值为: | 是 |
property_name | string | 计算属性 | 是 |
存放跟查询相关的特定的配置
{ }
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
refresh_cache | bool | 是否刷新缓存。查询默认会走缓存,当希望跳过缓存并且更新缓存数据的时候,可以设置refresh_cache为true | 否 |
window_period_type | 同granularity | 窗口时间单位 | 特定的查询下是必须的:转化、用户路径 |
window_period | 窗口时间 | 特定的查询下是必须的:转化、用户路径 | |
lifecycle_query_type | active/ lost | active 活跃用户; | 用户生命周期查询的时候是必须的 |
lifecycle_period | 是一个json对象,属性固定为granularity,period | "granularity": 时间粒度 | 用户生命周期查询的时候是必须的 |
存放跟查询分页相关的信息
"page": { "limit": 50, # 指定最大返回条数 "offset": 0 }
字段 | 类型 | 取值与含义 | 是否必须 |
---|---|---|---|
limit | int | 指定要返回的最大数据条数。默认为 50,最大支持50000 | 否 |
offset | int | 注意:offset 字段尚处于开发阶段,目前生产环境上无法生效 | 否 |
{ "use_app_cloud_id": true, "app_ids": [ 164314 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "content": { "profile_groups_v2": [], "profile_filters": [], "orders": [], "query_type": "event", "queries": [ [ { "event_name": "app_launch", "event_type": "origin", "show_name": "应用启动", "groups_v2": [], "filters": [], "show_label": "A", "event_indicator": "events", "measure_info": {}, "indicator_show_name": "总次数" } ] ], "option": { "refresh_cache": false, "fusion": false } } }
{ "app_ids": [ 164314 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "content": { "query_type": "retention", "profile_groups_v2": [], "profile_filters": [], "orders": [], "queries": [ [ { "show_label": "A", "event_name": "app_launch", "event_type": "origin", "groups_v2": [], "filters": [] }, { "show_label": "", "event_name": "any_active_event", "event_type": "origin", "groups_v2": [], "filters": [] } ] ], "page": { "limit": 50, "offset": 0 }, "option": { "refresh_cache": true, "fusion": false } }, "use_app_cloud_id": true }
{ "app_ids": [ 164314 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "content": { "query_type": "funnel", "profile_groups_v2": [], "profile_filters": [], "orders": [], "page": { "limit": 50, "offset": 0 }, "queries": [ [ { "show_label": "1", "event_id": 234950, "event_name": "app_launch", "event_type": "origin", "show_name": "", "groups_v2": [], "filters": [] }, { "show_label": "2", "event_id": 234950, "event_name": "app_launch", "event_type": "origin", "show_name": "", "groups_v2": [], "filters": [] } ] ], "option": { "window_period": 10, "window_period_type": "minute", "fusion": false, "refresh_cache": true } }, "use_app_cloud_id": true }
{ "app_ids": [ 164314 ], "periods": [ { "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai", "interval": "604800" } ], "version": 3, "content": { "profile_groups_v2": [], "profile_filters": [], "orders": [], "query_type": "path_find", "queries": [ [ { "event_type": "origin", "show_label": "A", "groups_v2": [], "filters": [] }, { "event_type": "origin", "show_label": "B", "groups_v2": [], "filters": [] } ] ], "option": { "refresh_cache": false, "hide_unselected": true, "window_period_type": "minute", "window_period": 10 } }, "use_app_cloud_id": true }
{ "app_ids": [ 164314 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "content": { "query_type": "life_cycle", "queries": [ [ { "event_id": 516129, "event_name": "any_active_event", "event_type": "origin", "groups_v2": [], "filters": [] } ] ], "profile_filters": [ ], "profile_groups_v2": [], "option": { "lifecycle_period": { "granularity": "day", "period": 1 }, "lifecycle_query_type": "active" } }, "use_app_cloud_id": true }
{ "app_ids": [ 164155 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "contents": [ { "profile_groups_v2": [], "profile_filters": [], "orders": [], "query_type": "web_session", "queries": [ [ { "event_type": "none", "show_name": "访客数", "groups_v2": [], "filters": [ { "expression": { "logic": "and", "conditions": [ { "property_values": [ null ], "property_type": "event_param", "property_name": "referer_type", "property_operation": "is not null" } ] } } ], "show_label": "uv", "event_indicator": "uv" } ] ], "option": { "refresh_cache": false, "fusion": true } } ], "use_app_cloud_id": true }
{ "app_ids": [ "164314" ], "use_app_cloud_id": true, "version": "3.0", "periods": [ { "granularity": "day", "align_unit": "day", "timezone": "Asia/Shanghai", "type": "last", "last": { "amount": 7, "unit": "day" } } ], "content": { "show_option": {}, "profile_groups_v2": [], "profile_filters": [], "orders": [], "query_type": "event_topk", "queries": [ [ { "event_type": "none", "event_indicator": "pv", "show_name": "", "show_label": "", "event_name": null, "groups_v2": [], "filters": [] } ] ], "option": { } } }
{ "app_ids": [ 164314 ], "periods": [ { "granularity": "day", "type": "last", "last": { "amount": 60, "unit": "day" }, "timezone": "Asia/Shanghai" } ], "version": 3, "content": { "query_type": "ltv", "profile_groups_v2": [], "profile_filters": [], "orders": [], "queries": [ [ { "show_label": "", "event_name": "purchase", "event_type": "origin", "groups_v2": [], "filters": [], "event_indicator": "measure", "measure_info": { "measure_type": "plain", "property_name": "currency_amount" } }, { "show_label": "", "event_name": "any_event", "event_type": "origin", "groups_v2": [], "filters": [] } ] ], "page": { "limit": 10, "offset": 2 }, "option": {} }, "use_app_cloud_id": true }
{ "use_app_cloud_id": true, "app_ids": [ 164314 ], "periods": [ { "granularity": "all", "type": "last", "last": { "amount": 7, "unit": "day" }, "timezone": "Asia/Shanghai", "interval": "604800" } ], "version": 3, "content": { "profile_groups_v2": [], "profile_filters": [], "orders": [], "query_type": "behavior_attribution", "queries": [ [ { "event_name": "purchase", "event_type": "origin", "show_name": "支付", "groups_v2": [], "event_indicator": "events", "show_label": "A", "measure_info": {}, "filters": [] } ], [], [ { "event_name": "app_launch", "event_type": "origin", "show_name": "应用启动", "groups_v2": [], "event_indicator": "events", "show_label": "A", "measure_info": {}, "filters": [] } ] ], "option": { "refresh_cache": true, "attribution_type": "last", "window_period": 0, "window_period_type": "day", "is_other_contact": false }, "page": { "limit": 50, "offset": 0 } } }
{ "app_ids": [ 164314 ], "periods": [ { "type": "last", "last": { "amount": 30, "unit": "day" }, "timezone": "Asia/Shanghai", "align_unit": "day", "granularity": "all" } ], "version": 3, "content": { "query_type": "composition", "profile_groups_v2": [ { "property_type" : "profile", "property_name": "age" } ], "profile_filters": [], "orders": [], "queries": [ [ { "event_type": "none" } ] ], "option": { "refresh_cache": false } }, "use_app_cloud_id": true }
说明
私有化里面 "property_type" : "profile" 需要修改为 "property_type": "user_profile"
{ "use_app_cloud_id": true, "app_ids": [ 164314 ], "periods": [ { //只支持all粒度,不支持按时间粒度分组 "granularity": "all", "type": "past_range", "spans": [ { "type": "past", "past": { "amount": 7, "unit": "day" } }, { "type": "past", "past": { "amount": 1, "unit": "day" } } ], "timezone": "Asia/Shanghai", "week_start": 1, "align_unit": "day" } ], "version": 3, "content": { "profile_groups_v2": [], "profile_filters": [], //自定义排序字段 "orders": [ { //field形式为{property_type}#{property_name}的形式,direction为desc(降序)或者asc(升序) "field": "profile#loc_city_id", "direction": "desc" } ], //自定义分页字段,limit最大为10000,超过10000按10000处理 "page": { "limit": 50, "offset": 0 }, //查询类型,仅支持openApi "query_type": "attribute", "queries": [ [ { "indicator_show_name": "", "measure_info": {}, "show_name": "", "show_label": "A", "event_name": "any_event", "event_type": "origin", "event_indicator": "None", "filters": [], //需要查询的属性 "groups_v2": [ { "property_compose_type": "origin", "property_name": "$event_name", "property_type": "common_param" }, { "property_compose_type": "origin", "property_name": "loc_city_id", "property_type": "profile" }, { "property_compose_type": "virtual", "property_name": "$_vp_zylvirtual", "property_type": "common_param" } ], "extra": {} } ] ], "option": { //是否分页(必传true) "is_paginate": true } }, "option": {} }
说明
该DSL特用于多个属性分组,且分组值数量较大的查询场景,在此特定场景下支持分页。
查询限制:
特别说明: