标签规则描述

规则描述部分是可嵌套的结构,较为复杂,此处单独进行描述。
在 “添加” 标签/用户群时,会用到规则描述。

rules\_relation\_node: 规则之间的逻辑关系

// 规则间逻辑关系
{
  "type": "rules_relation"
  "relation": string; // and/or
  "rules":[] // 只允许 type 为 "rules_relation" 和三种规则节点,不允许为空
}

rule\_node: 规则节点,分三种


// 属性规则
{
  "type": "profile_rule",
  "field": string, // 属性、标签/用户群或属性和标签/用户群的组合
  "function": string, // 规则函数(指标约束) 
  "params": [] // 规则条件值。List<Object>
}
// 事件规则
{
  "type": "event_rule",
  "measure": {
    "type": "event_measure",
    "event_name": string, // 事件名
    "aggregator": string, // 指标统计方式,如count, sum之类
    "field": string // optional. 某些指标统计方式对应的 field 可以为空
  },
  "time_function": string, // 时间区间函数
  "time_params": [], // 时间区间参数
  "function": string, // 规则函数 (指标约束)
  "params": [], // 规则条件。不出现指标
  "filters": [] // 筛选条件。可以为空列表,不为空时只有一个元素,filter_relation_node或filter_node
}
// 行为序列规则
{
  "type": "event_sequence_rule",
  "time_function": string, // 行为序列的时间函数
  "time_params": [], // 行为序列的时间区间参数
  "steps":
  [
    {
      "event": string, // 事件名1/虚拟事件1
      "filters": [] // 筛选条件,同上
    },
    {
      "event": string, // 事件名2/虚拟事件2
      "filters": [] // 筛选条件,同上
    }
  ]

filter\_realtion\_node: 同一事件的筛选条件的逻辑关系

{
  "type": "filters_relation",
  "relation": string; // and/or
  "subfilters":[] // 只允许type为filters_relation或filter
}

filter\_node: 事件或事件型指标的数据约束

{
  "type": "filter"
  "field": string, // 事件属性
  "function": string, // 筛选条件函数
  "params": [] // 筛选条件的值
}

规则中使用到的通用参数请参考:通用参数

创建标签

公共字段 字段名、字段含义、字段类型及可选值:

字段名

字段含义

字段类型

是否必填

可选值

其他说明

id标签 idnumber0创建可填 0 ,返回按照创建顺序返回实际标签 id
name标签英文名string
创建时不填写则不校验(默认给个不冲突的 name),如果填写了则会进行重名校验
cname标签中文名string
显示名
comment标签备注string

dir_id
目录ID
number
标签所在分组
cron调度周期string
cron 表达式 如:0 0 0 ? * 表示每天 0 点计算,如果是单次标签则可缺省
is_routine是否是例行标签boolean
如果是例行标签,则上面的 cron 必填
app_push_listapp push 配置列表list
用于推送
base_time标签计算的基准时间string
创建时不需填写(填写也无效)格式如:"2019-03-05 00:00:00"
unit标签更新周期stringDAY目前只支持 DAY
data_type标签数据类型stringBOOL, NUMBER, STRING, DATETIME,LIST参考 数据格式
source_type标签类型string

1--自定义标签值

9--基础指标值

10--首次末次特征

11--事件偏好属性

12--行为分布结果

7--sql创建

规则创建的标签

注:导入创建标签参考:「导入创建」标签

[PUT /v2​/user_tags​​]

  • Request (application/json)

自定义标签值标签

{
    "id":0,
    "cname":"显示名称",
    "name":"user_tag_xianshimingcheng",
    "source_type":1,//1--自定义标签值 9--基础指标值 10--首次末次特征 11--事件偏好属性 12--行为分布结果 7--sql创建
    "is_routine":true,//是否为例行计算
    "unit":"DAY",//最小计算周期,目前仅支持以天为周期的调度
    "dir_id":1,// 目录ID
    "data_type":"STRING",//标签数据类型 BOOL(布尔), NUMBER(熟知), STRING(字符串), DATETIME(时间), LIST(列表)
    "cron":"0 0 0 * * ? *",// 调度周期,cron 表达式格式,例行计算必填
    "rule_content_list":[// 规则信息
        {
            "value":"分层1",// 单值的取值
            "type":"rules_relation",//定义规则间的逻辑关系
            "relation":"and",//规则集之间的关系 and/or
            "rules":[// 规则集 
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "measure":{
                                "aggregator":"general",
                                "field":"",
                                "type":"event_measure",
                                "event_name":"buy"
                            },
                            "type":"event_rule",
                            "time_function":"relative_time",
                            "time_params":[
                                "1 day"
                            ],
                            "params":[
                                1
                            ],
                            "function":"least",
                            "filters":[

                            ]
                        }
                    ]
                }
            ]
        },
        {
            "value":"分层2",
            "type":"rules_relation",
            "relation":"and",
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"profile_rule",
                            "field":"user.$update_time",
                            "function":"equal",
                            "params":[
                                "10"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "app_push_list":null,
    "comment":"备注"
}

字段名

字段含义

字段类型

是否必填

可选值

其他说明

relation规则之间的关系string用于自定义标签值and/or规则集之间的关系
rule_content_list规则信息list必填
[分层1 json,分层2 json,...]
rules标签规则list必填
参考:标签规则描述

value分层名称string用于自定义标签值
单值的取值,例如"分层1"

基础指标值标签

{
	......
    "rule_content_list":[
        {
            "type":"basic_measures",
            "measure":{
                "type":"event_measure",
                "event_name":"ClickBanner",
                "aggregator":"general",// 指标类型--总次数:general,总和:SUM,最大:MAX,最小:MIN,均值:AVG,去重:uniqCount
                "field":""
            },
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"simple_event_rule",
                            "filters":[
                                {
                                    "type":"filter",
                                    "field":"event.WithdrawCash.WithdrawDate",
                                    "function":"greaterequal",
                                    "params":[
                                        "2015-04-01 00:03:00"
                                    ]
                                }
                            ],
                            "time_function":"relative_time",
                            "time_params":[
                                "1,0,hour"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
	......
}

首次末次特征标签

{
	......
    "rule_content_list":[
        {
            "type":"first_last_time_feature",
            "measure":{
                "type":"event_measure",
                "event_name":"ClickBanner",
                "aggregator":"first_time", // first_time, last_time, first_time_interval, last_time_interval
                "field":"event.ClickBanner.$time"
            },
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"simple_event_rule",
                            "filters":[
                                {
                                    "type":"filter",
                                    "field":"event.WithdrawCash.WithdrawDate",
                                    "function":"greaterequal",
                                    "params":[
                                        "2015-04-01 00:03:00"
                                    ]
                                }
                            ],
                            "time_function":"relative_time",
                            "time_params":[
                                "1,0,hour"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
	......
}

事件偏好属性标签

{
	......
    "rule_content_list":[
        {
            "type":"event_property_preferences",
            "measure":{
                "type":"event_measure",
                "event_name":"ClickBanner",
                "aggregator":"group_concat",
                "field":"event.BuyGold.$city"
            },
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"event_rule",
                            "measure":{
                                "type":"event_measure",
                                "event_name":"ClickBanner",
                                "aggregator":"rank_desc",
                                "field":"event.BuyGold.GoldPrice"
                            },
                            "filters":[
                                {
                                    "type":"filter",
                                    "field":"event.WithdrawCash.WithdrawDate",
                                    "function":"greaterequal",
                                    "params":[
                                        "2015-04-01 00:03:00"
                                    ]
                                }
                            ],
                            "params":[
                                20
                            ],
                            "function":"most",
                            "time_function":"relative_time",
                            "time_params":[
                                "1,0,hour"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
	......
}

行为分布结果

{
	......
    "rule_content_list":[
        {
            "type":"behavior_distribution_result",
            "measure":{
                "type":"event_measure",
                "event_name":"ClickBanner",
                "aggregator":"uniqcount", // 此处都是 uniqcount 这个值,表示是COUNT(DISTINCT)
                "field":"",
                "unit":"day" // 有 day, hour 两个值
            },
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"simple_event_rule",
                            "filters":[
                                {
                                    "type":"filter",
                                    "field":"event.WithdrawCash.WithdrawDate",
                                    "function":"greaterequal",
                                    "params":[
                                        "2015-04-01 00:03:00"
                                    ]
                                }
                            ],
                            "time_function":"relative_time",
                            "time_params":[
                                "1,0,hour"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
	......
}

基础指标指、首次末次特征、事件偏好属性、行为分布结果

字段名

字段含义

字段类型

是否必填

可选值

其他说明

rule_content_list规则信息list必填

type标签创建方式string必填
  • event_measure(基础值标签)
  • first_last_time_feature(首次末次特征值标签)
  • event_property_preferences(事件偏好属性标签)
  • behavior_distribution_result(行为分布结果)

measure标签值规则json必填

rules标签规则list必填
参考:标签规则描述

SQL计算结果标签

{
    "id":0,
    "cname":"标签5",
    "name":"user_tag_biaoqian5",
    "source_type":7,
    "is_routine":true,
    "unit":"DAY",//目前仅支持天的维度
    "dir_id":38,
    "data_type":"STRING",
    "cron":"0 0 0 * * ? *",
	"app_push_list":null,
	"comment":"备注",
    "sql":"select id as id,first_id as distinct_id,  $city as value from users"
}

sql 计算结果标签

字段名

字段含义

字段类型

是否必填

可选值

其他说明

sqlsql规则string必填
参考文档:使用 sql 创建用户标签
  • Response 200 (application/json)
返回标签元信息JSON,JSON信息请参考获取标签元信息返回结果

获取标签元信息

[GET ​/v2/user_tags​/{id}​]

  • Response 200 (application/json)
{
  "id":15,
  "dir_id":1,// 标签所在的目录对应的 id
  "name":"user_tag_biaoqian12", //标签名
  "cname":"标签12", // 标签显示名
  "user_name":"xxx@qq.com", // 标签创建用户
  "create_time":"2019-12-05 20:46:56", // 标签创建时间
  "data_type":"STRING", // 标签数据类型
  "unit":"DAY", // 标签计算的最小周期,目前UI界面没有,但是调用API可以指定标签的调度周期
  "source_type":1, // 标签数据来源类型:1 rule 筛选规则,2 query_result 查询结果,5 upload 上传创建,6 import 外部导入,7 SQL sql创建(不使用 0,3,4是为了避免升级操作,用 6 是因为 1.13 的 6 没有用到)
  "is_routine":true, // 是否为例行,只有 source_type 为 rule/sql 时,例行 才是有效的,其他 source_type 均为 非例行,无论是否为例行,分群均可具有多个 Partition,只是 例行分群会由系统自发定期创建新 Partition
  "status":"RUNNING",// 标签状态,pending 待审批,running 正常运行,suspend 已暂停
  "comment":"",// 备注
  "cron":"0 0 0 * * ? *",// 调度周期 
  "rule_content_list":[//多值规则列表
    {
      "value":"分层1",// 单值的取值
      "type":"rules_relation",// 定义规则间的逻辑关系
      "relation":"and",// 关系 and/or
      "rules":[// 规则节点列表
        {
          "type":"rules_relation",
          "relation":"and",
          "rules":[
            {
              "type":"profile_rule",
              "field":"user.$first_visit_time",
              "function":"equal",
              "params":[
                "2019-12-10 00:00:00:00"
              ]
            }
          ]
        },
        {
          "type":"rules_relation",
          "relation":"and",
          "rules":[
            {
              "measure":{
                "aggregator":"general",
                "field":"",
                "type":"event_measure",
                "event_name":"buy"
              },
              "type":"event_rule",
              "time_function":"relative_time",
              "time_params":[
                "1 day"
              ],
              "params":[
                1
              ],
              "function":"least",
              "filters":[

              ]
            }
          ]
        },
        {
          "type":"rules_relation",
          "relation":"and",
          "rules":[
            {
              "type":"event_sequence_rule",
              "time_function":"relative_time",
              "time_params":[
                "1 day"
              ],
              "steps":[
                {
                  "event":"buy",
                  "filters":[

                  ]
                },
                {
                  "event":"buy",
                  "filters":[

                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "failed_partition_count":0,// 失败的 partition 数
  "last_succeed_partition":{//最近一次成功计算的partition 信息
    "base_time":"2019-12-18 00:00:00",// 标签计算的基准时间 2018-08-28 11:00:00
    "start_time":"2019-12-18 01:00:26",// partition 计算开始时间
    "finished_time":"2019-12-18 01:00:30",// partition 计算结束时间
    "user_count":0, // 这个 partition 的总用户数
    "status":"SUCCEED", // Partition 状态,新建标签还未执行:new、执行中:computing、执行成功:succeed、执行失败:failed
    "rule_content_list":[// 计算规则
      {
        "value":"分层1",
        "type":"rules_relation",
        "relation":"and",
        "rules":[
          {
            "type":"rules_relation",
            "relation":"and",
            "rules":[
              {
                "type":"profile_rule",
                "field":"user.$first_visit_time",
                "function":"equal",
                "params":[
                  "2019-12-10 00:00:00:00"
                ]
              }
            ]
          },
          {
            "type":"rules_relation",
            "relation":"and",
            "rules":[
              {
                "measure":{
                  "aggregator":"general",
                  "field":"",
                  "type":"event_measure",
                  "event_name":"buy"
                },
                "type":"event_rule",
                "time_function":"relative_time",
                "time_params":[
                  "1 day"
                ],
                "params":[
                  1
                ],
                "function":"least",
                "filters":[

                ]
              }
            ]
          },
          {
            "type":"rules_relation",
            "relation":"and",
            "rules":[
              {
                "type":"event_sequence_rule",
                "time_function":"relative_time",
                "time_params":[
                  "1 day"
                ],
                "steps":[
                  {
                    "event":"buy",
                    "filters":[

                    ]
                  },
                  {
                    "event":"buy",
                    "filters":[

                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  },
  "last_partition_info":{
    "base_time":"2019-12-18 00:00:00",
    "start_time":"2019-12-18 01:00:26",
    "finished_time":"2019-12-18 01:00:30",
    "user_count":0,
    "status":"SUCCEED",
    "next_partition_base_time":"2019-12-19 00:00:00" // 下一次计算的 base_time
  }
}

获取标签详情

[POST /v2​/user_tags​/{id}​/report] 注意:该接口不支持高并发查询

  • Request (application/json)
{
  "from_date": "2019-12-16",// 设定时间范围,开始时间(含),格式:2019-12-16
  "to_date": "2019-12-18",// 设定时间范围,结束时间(含),格式:2019-12-18
  "bucket_param": [// 分组信息(同事件分析)。对于 data_type 为 timestamp 和 number 的标签支持离散分组,其他类型的标签只有默认分组
    0
  ],
  "limit": 0 //对返回的 value 数量进行限制,默认返回 1000 行
}
  • Response 200 (application/json)
{
  "aggregate_result":{//所有分层汇总的聚合结果
    "series":[
      "2019-12-16 00:00:00",
      "2019-12-17 00:00:00",
      "2019-12-18 00:00:00"
    ],
    "rows":[
      {
        "by_value":"$ALL",
        "partition_values":[
          {
            "user_count":0, // 用户数量
            "percent":100, // 占比
            "base_time":"2019-12-16 00:00:00", // partition 时间
            "finished_time":"2019-12-16 01:01:37"// 计算完成时间
          },
          {
            "user_count":0,
            "percent":100,
            "base_time":"2019-12-17 00:00:00",
            "finished_time":"2019-12-17 01:00:34"
          },
          {
            "user_count":0,
            "percent":100,
            "base_time":"2019-12-18 00:00:00",
            "finished_time":"2019-12-18 01:01:02"
          }
        ]
      }
    ]
  },
  "non_aggregate_result":{//分别显示各分层的一天纬度聚合结果
    "series":[
      "2019-12-16 00:00:00",
      "2019-12-17 00:00:00",
      "2019-12-18 00:00:00"
    ],
    "rows":[
      {
        "by_value":"分层2",
        "partition_values":[
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-16 00:00:00",
            "finished_time":"2019-12-16 01:01:37"
          },
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-17 00:00:00",
            "finished_time":"2019-12-17 01:00:34"
          },
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-18 00:00:00",
            "finished_time":"2019-12-18 01:01:02"
          }
        ]
      },
      {
        "by_value":"分层1",
        "partition_values":[
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-16 00:00:00",
            "finished_time":"2019-12-16 01:01:37"
          },
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-17 00:00:00",
            "finished_time":"2019-12-17 01:00:34"
          },
          {
            "user_count":0,
            "percent":0,
            "base_time":"2019-12-18 00:00:00",
            "finished_time":"2019-12-18 01:01:02"
          }
        ]
      }
    ]
  }
}

更新标签配置

[PUT /v2​/user_tags​/{id}​]

  • Request (application/json)
//字段注释见 获取标签元信息 Response
{
    "id":21,
    "dir_id":1,
    "name":"user_tag_xianshimingcheng",
    "cname":"显示名称",
    "user_name":"xxx@qq.com",
    "create_time":"2019-12-18 14:42:41",
    "data_type":"STRING",
    "unit":"DAY",
    "source_type":1,
    "is_routine":true,
    "status":"PENDING",
    "comment":"备注",
    "cron":"0 0 0 * * ? *",
    "rule_content_list":[
        {
            "value":"分层1",
            "type":"rules_relation",
            "relation":"and",
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "measure":{
                                "aggregator":"general",
                                "field":"",
                                "type":"event_measure",
                                "event_name":"buy"
                            },
                            "type":"event_rule",
                            "time_function":"relative_time",
                            "time_params":[
                                "1 day"
                            ],
                            "params":[
                                1
                            ],
                            "function":"least",
                            "filters":[

                            ]
                        }
                    ]
                }
            ]
        },
        {
            "value":"分层2",
            "type":"rules_relation",
            "relation":"and",
            "rules":[
                {
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"profile_rule",
                            "field":"user.$update_time",
                            "function":"equal",
                            "params":[
                                "10"
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "failed_partition_count":0,
    "last_succeed_partition":{
        "rule_content_list":[
            {
                "value":"分层1",
                "type":"rules_relation",
                "relation":"and",
                "rules":[
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "measure":{
                                    "aggregator":"general",
                                    "field":"",
                                    "type":"event_measure",
                                    "event_name":"buy"
                                },
                                "type":"event_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "params":[
                                    1
                                ],
                                "function":"least",
                                "filters":[

                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "value":"分层2",
                "type":"rules_relation",
                "relation":"and",
                "rules":[
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "type":"profile_rule",
                                "field":"user.$update_time",
                                "function":"equal",
                                "params":[
                                    "10"
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    "last_partition_info":{
        "base_time":"2019-12-18 00:00:00",
        "start_time":"2019-12-18 14:42:41",
        "finished_time":"2019-12-18 14:42:41",
        "user_count":0,
        "status":"NEW",
        "next_partition_base_time":"2019-12-19 00:00:00"
    }
}
  • Response 200 (application/json)
返回标签元信息JSON,JSON信息请参考获取标签元信息返回结果

删除标签

[DELETE /v2​/user_tags​/{id}​]

修改标签的调度状态

[PATCH ​/v2/user_tags​/{id}​]

  • Request (application/json)
{
    "status":"SUSPEND"// 状态有 RUNNING(开启) SUSPEND(暂停) 
}
  • Response 200 (application/json)
返回标签元信息JSON,JSON信息请参考获取标签元信息返回结果

获取所有/部分 partition

[GET ​/v2/user_tags​/{id}​/partitions]

  • Request 
/v2/user_tags​/{id}​/partitions?from_date=2019-12-17&to_date=2019-12-18&start=1&count=10
参数名是否必填类型描述
from_dateString 
  • 同时存在from_date 和 to_date 两个参数按照时间的范围查询
  • 如果传递其中一个参数,系统会提示异常
  • 没有传递参数则查询全量partition
to_dateString
orderString

可以传递desc 返回base_time倒序

startInteger

查询结果截取参数,start 从1 开始计数,从start开始返回count条数据

如果数量不足这返回start开始之后的全量数据

countInteger
  • Response 200 (application/json)
[
    {
        "base_time":"2019-12-17 00:00:00",
        "start_time":"2019-12-17 01:00:46",
        "finished_time":"2019-12-17 01:00:49",
        "user_count":0,
        "status":"SUCCEED",
        "rule_content_list":[
            {
                "value":"分层1",
                "type":"rules_relation",
                "relation":"and",
                "rules":[
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "type":"profile_rule",
                                "field":"user.$first_visit_time",
                                "function":"equal",
                                "params":[
                                    "2019-12-10 00:00:00:00"
                                ]
                            }
                        ]
                    },
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "measure":{
                                    "aggregator":"general",
                                    "field":"",
                                    "type":"event_measure",
                                    "event_name":"buy"
                                },
                                "type":"event_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "params":[
                                    1
                                ],
                                "function":"least",
                                "filters":[

                                ]
                            }
                        ]
                    },
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "type":"event_sequence_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "steps":[
                                    {
                                        "event":"buy",
                                        "filters":[

                                        ]
                                    },
                                    {
                                        "event":"buy",
                                        "filters":[

                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    },
    {
        "base_time":"2019-12-18 00:00:00",
        "start_time":"2019-12-18 01:00:26",
        "finished_time":"2019-12-18 01:00:30",
        "user_count":0,
        "status":"SUCCEED",
        "rule_content_list":[
            {
                "value":"分层1",
                "type":"rules_relation",
                "relation":"and",
                "rules":[
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "type":"profile_rule",
                                "field":"user.$first_visit_time",
                                "function":"equal",
                                "params":[
                                    "2019-12-10 00:00:00:00"
                                ]
                            }
                        ]
                    },
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "measure":{
                                    "aggregator":"general",
                                    "field":"",
                                    "type":"event_measure",
                                    "event_name":"buy"
                                },
                                "type":"event_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "params":[
                                    1
                                ],
                                "function":"least",
                                "filters":[

                                ]
                            }
                        ]
                    },
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "type":"event_sequence_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "steps":[
                                    {
                                        "event":"buy",
                                        "filters":[

                                        ]
                                    },
                                    {
                                        "event":"buy",
                                        "filters":[

                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
]

新增指定时间区间内的所有partition

[PUT ​/v2/user_tags​/{id}/partitions​]

参数名是否必填类型描述
from_dateString 

设定时间范围,开始时间(含)

格式:2018-05-04 04:00:00 或者 2018-05-04  均可

from_data 不能晚于 to_date

to_dateString

设定时间范围,结束时间(含)

格式:2018-05-06 04:00:00 或者 2018-05-06  均可

参数不能晚于今天

  • Response 200 
/v2​/user_tags​/{id}/partitions?from_date=2019-12-16&to_date=2019-12-18

检查标签执行状态

[GET ​/v2/user_tags​/{id}/status​]

  • Request
/v2/user_tags/{id}/status?base_time_list=2019-12-16
  • Response 200 (application/json)
[
  {
    "base_time": "2019-12-16 00:00:00",
    "user_count": 0,
    "status": "SUCCEED",
    "start_time": "2019-12-16 01:01:02",
    "finished_time": "2019-12-16 01:01:02"
  }
]

执行一个标签的指定 partition

[POST /v2​/user_tags​/{id}/execute​]

  • Request 
/v2/user_tags/{id}/execute?base_time_list=2019-12-13

获取标签完整的目录结构

[GET ​/v2/user_tags​/dirs​]

  • Request 
/v2/user_tags/dirs?need_user_tag=false
参数名是否必填类型描述
need_user_tagString 

目录结构内默认包含目录下的所有标签信息,设为 false 则只返回目录结构. 只在获取目录结构时使用

tag_statusString

标签状态,PENDING 待审批,RUNNING 正常运行,SUSPEND 已暂停

unitString标签更新周期, 取值范围: DAY 每日更新
source_typeInteger标签类型, 取值范围:1 rule 筛选规则,2 query_result 查询结果,5 upload 上传创建,6 import 外部导入,7 SQL sql创建(不使用 0,3,4是为了避免升级操作,用 6 是因为 1.13 的 6 没有用到)
last_partition_statusString状态,新建标签还未执行:NEW、执行中:COMPUTING、执行成功:SUCCEED、执行失败:FAILED
is_routineInteger是否例行标签或用户群 1是 0否
  • Response 200 (application/json)
[
  {
    "type": "DIR",
    "id": 1,
    "cname": "未分类",
    "is_default": true,
    "items": [
      {
        "type": "USER_TAG",
        "id": 12,
        "name": "user_tag_biaoqian3",
        "cname": "标签3",
        "data_type": "STRING",
        "is_permitted": false
      },
      {
        "type": "USER_TAG",
        "id": 13,
        "name": "user_tag_biaoqian4",
        "cname": "标签4",
        "data_type": "STRING",
        "is_permitted": false
      }
    ]
  },
  {
    "type": "DIR",
    "id": 8,
    "cname": "目录1",
    "items": [
      {
        "type": "USER_TAG",
        "id": 2,
        "name": "user_tag_xxx1_1",
        "cname": "xxx1_1",
        "data_type": "STRING",
        "is_permitted": true
      },
    ]
  },
  {
    "type": "DIR",
    "id": 9,
    "cname": "目录2",
    "items": [
      {
        "type": "USER_TAG",
        "id": 4,
        "name": "user_tag_xxx2_2",
        "cname": "xxx2_2",
        "data_type": "STRING",
        "is_permitted": false
      }
    ]
  }
]

获取标签列表

[GET ​/v2/user_tags​​]

  • Request (application/json)
/v2/user_tags?invisible=false
参数名是否必填类型描述
startInteger 

从第几个开始取数据

countInteger

取多少个

invisible
Boolean是否展示隐藏目录的标签(目前是是否显示用户画像的标签 false 为不显示)
  • Response 200 (application/json)
[
    {
        "id":2,
        "dir_id":8,
        "name":"user_tag_xionghuacheng1_1",
        "cname":"xionghuacheng1_1",
        "user_name":"xionghuacheng1@qq.com",
        "create_time":"2019-11-27 12:02:24",
        "data_type":"STRING",
        "unit":"DAY",
        "source_type":1,
        "is_routine":true,
        "status":"RUNNING",
        "comment":"",
        "cron":"0 0 0 * * ? *",
        "rule_content_list":[
            {
                "value":"分层1",
                "type":"rules_relation",
                "relation":"and",
                "rules":[
                    {
                        "type":"rules_relation",
                        "relation":"and",
                        "rules":[
                            {
                                "measure":{
                                    "aggregator":"general",
                                    "field":"",
                                    "type":"event_measure",
                                    "event_name":"buy"
                                },
                                "type":"event_rule",
                                "time_function":"relative_time",
                                "time_params":[
                                    "1 day"
                                ],
                                "params":[
                                    1
                                ],
                                "function":"least",
                                "filters":[

                                ]
                            }
                        ]
                    }
                ]
            }
        ],
        "failed_partition_count":0,
        "last_succeed_partition":{
            "base_time":"2019-12-18 00:00:00",
            "start_time":"2019-12-18 01:00:59",
            "finished_time":"2019-12-18 01:01:02",
            "user_count":0,
            "status":"SUCCEED",
            "rule_content_list":[
                {
                    "value":"分层1",
                    "type":"rules_relation",
                    "relation":"and",
                    "rules":[
                        {
                            "type":"rules_relation",
                            "relation":"and",
                            "rules":[
                                {
                                    "measure":{
                                        "aggregator":"general",
                                        "field":"",
                                        "type":"event_measure",
                                        "event_name":"buy"
                                    },
                                    "type":"event_rule",
                                    "time_function":"relative_time",
                                    "time_params":[
                                        "1 day"
                                    ],
                                    "params":[
                                        1
                                    ],
                                    "function":"least",
                                    "filters":[

                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "last_partition_info":{
            "base_time":"2019-12-18 00:00:00",
            "start_time":"2019-12-18 01:00:59",
            "finished_time":"2019-12-18 01:01:02",
            "user_count":0,
            "status":"SUCCEED",
            "next_partition_base_time":"2019-12-19 00:00:00"
        }
    }
]

导出标签用户

[POST ​​/v2/reports​/user_analytics​/users​] 注意:该接口不支持高并发查询

  • Request (application/json)
{
    "filter":{// 单层筛选条件
        "conditions":[
            {
                "field":"user.user_tag_tag24@2019-12-18 00:00:00",// 具体属性
                "function":"isSet"// 条件函数
            }
        ]
    },
    "from":"user_tags",
    "num_per_page":50,
    "page":0,// 第几页
    "all_page":false,// 是否显示所有页
    "profiles":[// 需要显示的列,用户属性列表
        "user.viplevel",
        "user.$device_id_list",
        "user.$name",
        "user.city",
        "user.province",
        "user.user_group_fenqun24"
    ],
    "limit":1000,// 列表总数
    "request_id":"1576665438553:312117",
    "use_cache":false
}
  • Response 200 (application/json)
{
    "page_num":1,// 页数
    "size":2,//总人数
    "column_name":[// 用户属性列表
        "viplevel",
        "$device_id_list",
        "$name",
        "city",
        "province",
        "behaviorGender"
    ],
    "permitted_properties":[// 用户属性权限,有权限的属性名
        "viplevel",
        "$device_id_list",
        "$name",
        "city",
        "province",
        "behaviorGender"
    ],
    "users":[// 用户列表
        {
            "id":"-8730216594566797645",
            "first_id":"00023177fb8b1c65",
            "profiles":{
                "$name":"吴掭歂",
                "province":"上海",
                "city":"石家庄",
                "behaviorGender":"男",
                "viplevel":"青铜"
            }
        },
        {
            "id":"-8832516550883297125",
            "first_id":"00144ec2ba6496ec",
            "profiles":{
                "$name":"姜俿搝",
                "province":"北京",
                "city":"上海",
                "behaviorGender":"女",
                "viplevel":"白银"
            }
        }
    ]
}

导出csv格式标签用户

[POST ​​/v2/reports​/user_analytics​/users​/csv​] 注意:该接口不支持高并发查询

  • Request (application/json)
{
    "filter":{
        "conditions":[
            {
                "field":"user.user_group_fenqun24@2019-12-18 00:00:00",
                "function":"isSet"
            }
        ]
    },
    "all_page":true
}
  • Response 200 
下载csv格式的文件

查询用户标签值信息

[POST ​​/v2/persona_info/user_tags​] 注意:该接口不支持高并发查询,建议一次查询最多查询20个标签值

  • Request (application/json)
{
	"user_id":"-5568802382350089752", // 神策ID
	"user_tag_ids":[10,11,21,25,17,19,7,13,18] //待查询标签IDs
}
  • Response 200 
{
  "user_tags": [
    {
      "tag_id": 21,
      "cname": "用户生命周期",
      "value": "新用户",
      "data_type": 2,
      "partition_info": {
        "base_time": "2020-03-23 00:00:00",
        "start_time": "2020-03-25 10:26:44",
        "finished_time": "2020-03-25 10:27:11",
        "user_count": 26829,
        "status": "SUCCEED"
      }
    },
    {
      "tag_id": 19,
      "cname": "收藏频次",
      "value": "3",
      "data_type": 1,
      "partition_info": {
        "base_time": "2020-03-27 00:00:00",
        "start_time": "2020-03-27 01:01:30",
        "finished_time": "2020-03-27 01:01:54",
        "user_count": 19685,
        "status": "SUCCEED"
      }
    },
    ...... 
	// 1、该接口会通过权限过滤,返回用户拥有权限的标签数据
	// 2、该接口只会返回用户拥有标签值的标签项
  ]
}