我准备进入mixpanel的下一个计划,因为有太多人,并且想先删除一些老用户。
是否有一种简单的方法/ script / api来批量删除旧用户?
答案 0 :(得分:9)
我写了两个可能派上用场的脚本; mixpanel-engage-query和mixpanel-engage-post。
使用第一个脚本(查询),您可以查询人员数据并获取个人资料列表,例如所有将$ last_seen设置为超过X个月的日期的用户。
使用第二个脚本(post),您可以在这些配置文件上批量执行操作,例如删除它们。请参阅自述文件an example of how to perform a batch delete。
答案 1 :(得分:8)
是的。查看HTTP spec,您会找到以下内容。
<强> $删除强>
string永久删除Mixpanel中的配置文件以及所有配置文件 它的属性。该值被忽略 - 配置文件由。确定 来自请求本身的$ distinct_id。
// This removes the user 13793 from Mixpanel
{
"$token": "36ada5b10da39a1347559321baf13063",
"$distinct_id": "13793",
"$delete": ""
}
批量请求
http://api.mixpanel.com/track/的事件端点和http://api.mixpanel.com/engage/的配置文件更新端点都接受批量更新。要将一批消息发送到端点,您应该使用POST而不是GET请求。不是发送单个JSON对象作为数据查询参数,而是发送一个对象的jSON列表,base64编码,作为application / x-www-form-urlencoded POST请求体的数据参数。
// Here's a list of events
[
{
"event": "Signed Up",
"properties": {
"distinct_id": "13793",
"token": "e3bc4100330c35722740fb8c6f5abddc",
"Referred By": "Friend",
"time": 1371002000
}
},
{
"event": "Uploaded Photo",
"properties": {
"distinct_id": "13793",
"token": "e3bc4100330c35722740fb8c6f5abddc",
"Topic": "Vacation",
"time": 1371002104
}
}
]
Base64编码,列表变为:
Ww0KICAgIHsNCiAgICAgICAgImV2ZW50IjogIlNpZ25lZCBVcCIsDQogICAgICAgICJwcm9wZXJ0aWVzIjogew0KICAgICAgICAgICAgImRpc3RpbmN0X2lkIjogIjEzNzkzIiwNCiAgICAgICAgICAgICJ0b2tlbiI6ICJlM2JjNDEwMDMzMGMzNTcyMjc0MGZiOGM2ZjVhYmRkYyIsDQogICAgICAgICAgICAiUmVmZXJyZWQgQnkiOiAiRnJpZW5kIiwNCiAgICAgICAgICAgICJ0aW1lIjogMTM3MTAwMjAwMA0KICAgICAgICB9DQogICAgfSwNCiAgICB7DQogICAgICAgICAiZXZlbnQiOiAiVXBsb2FkZWQgUGhvdG8iLA0KICAgICAgICAgICJwcm9wZXJ0aWVzIjogew0KICAgICAgICAgICAgICAiZGlzdGluY3RfaWQiOiAiMTM3OTMiLA0KICAgICAgICAgICAgICAidG9rZW4iOiAiZTNiYzQxMDAzMzBjMzU3MjI3NDBmYjhjNmY1YWJkZGMiLA0KICAgICAgICAgICAgICAiVG9waWMiOiAiVmFjYXRpb24iLA0KICAgICAgICAgICAgICAidGltZSI6IDEzNzEwMDIxMDQNCiAgICAgICAgICB9DQogICAgfQ0KXQ==
因此,作为批处理发送事件的POST请求的主体是:
data=Ww0KICAgIHsNCiAgICAgICAgImV2ZW50IjogIlNpZ25lZCBVcCIsDQogICAgICAgICJwcm9wZXJ0aWVzIjogew0KICAgICAgICAgICAgImRpc3RpbmN0X2lkIjogIjEzNzkzIiwNCiAgICAgICAgICAgICJ0b2tlbiI6ICJlM2JjNDEwMDMzMGMzNTcyMjc0MGZiOGM2ZjVhYmRkYyIsDQogICAgICAgICAgICAiUmVmZXJyZWQgQnkiOiAiRnJpZW5kIiwNCiAgICAgICAgICAgICJ0aW1lIjogMTM3MTAwMjAwMA0KICAgICAgICB9DQogICAgfSwNCiAgICB7DQogICAgICAgICAiZXZlbnQiOiAiVXBsb2FkZWQgUGhvdG8iLA0KICAgICAgICAgICJwcm9wZXJ0aWVzIjogew0KICAgICAgICAgICAgICAiZGlzdGluY3RfaWQiOiAiMTM3OTMiLA0KICAgICAgICAgICAgICAidG9rZW4iOiAiZTNiYzQxMDAzMzBjMzU3MjI3NDBmYjhjNmY1YWJkZGMiLA0KICAgICAgICAgICAgICAiVG9waWMiOiAiVmFjYXRpb24iLA0KICAgICAgICAgICAgICAidGltZSI6IDEzNzEwMDIxMDQNCiAgICAgICAgICB9DQogICAgfQ0KXQ==
两个端点一次最多可接受50条消息。通常,批处理请求将具有与事件关联的“时间”属性,或与配置文件更新关联的“$ time”属性。
答案 2 :(得分:1)
pip install mixpanel-api
此脚本将删除自2019年1月1日以来未见过的任何个人资料:
from mixpanel_api import Mixpanel
mixpanel = Mixpanel('MIXPANEL_SECRET', token='MIXPANEL_TOKEN')
deleted_count = mixpanel.people_delete(query_params={ 'selector' : 'user["$last_seen"]<"2019-01-01T00:00:00"'})
print(deleted_count)
用您自己的项目令牌替换 MIXPANEL_SECRET 和 MIXPANEL_TOKEN 。
答案 3 :(得分:0)
安装Mixpanel Python API(Click Here)
pip install mixpanel-api
创建一个python文件:delete_people.py,然后复制并粘贴以下代码,并根据您的项目配置进行更改,即秘密,令牌,过滤器参数等。
from mixpanel_api import Mixpanel
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%Y_%m_%d_%H_%M_%S")
if __name__ == '__main__':
#Mixpanel Project :
credentials = {
'API_secret': '<Your API Secret>',
'token': '<Your API Token>',
}
# first we are going to make a Mixpanel object instance
mlive = Mixpanel(credentials['API_secret'])
# Mixpanel object with token to delete people
ilive = Mixpanel(credentials['API_secret'],credentials['token'])
#Prepare parameters for delete condition
#<filter_by_cohort_here> - Get from mixpanel explore UI, from engage api xhr call (https://mixpanel.com/api/2.0/engage)
parameters = {'filter_by_cohort':'<filter_by_cohort_here>','include_all_users':'true','limit':0}
# Backup data before deleting
print("\n Creating backup of data\n")
mlive.export_people('backup_people_'+current_time+'.json', parameters)
# Delete people using parameters filter
print("\n Backup Completed! Deleting Data\n")
ilive.people_delete(query_params=parameters)
print("\n Data Deleted Successfully\n")
从终端运行以下命令
python delete_people.py
注意:mixpanel api的people_delete方法将在您放置此脚本的同一目录中自动创建backup_timestamp.json文件