9

我即将进入mixpanel的下一个计划,因为人太多,想先删除一些老用户。

有没有简单的方法/脚本/api批量删除老用户?

4

4 回答 4

10

我写了两个可能会派上用场的脚本;mixpanel-engage-querymixpanel-engage-post

使用第一个脚本(查询),您可以查询您的人员数据并获取配置文件列表,例如将 $last_seen 设置为 X 个月以前的日期的所有用户。

使用第二个脚本(帖子),您可以对这些配置文件批量执行操作,例如删除它们。有关如何执行批量删除的示例,请参阅自述文件。

于 2015-05-04T06:52:25.160 回答
8

就在这里。查看HTTP 规范,您会发现以下内容。

$删除

字符串 从 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”属性。

于 2014-02-27T23:15:58.537 回答
1

使用Mixpanel-api python 模块

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_SECRETMIXPANEL_TOKEN替换为您自己的项目令牌。

于 2019-05-27T09:13:55.360 回答
0

安装 Mixpanel Python API(点击这里

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 文件

于 2019-11-26T14:41:29.837 回答