MixpanelVapor

MixpanelVapor 是一个库,用于从您的 Vapor 服务器端 Swift 应用程序向 Mixpanel 跟踪事件。

初始化

提供您的 Mixpanel 令牌(与您在客户端 Mixpanel 跟踪中使用的令牌相同)

import MixpanelVapor

public func configure(_ app: Application) throws {
    //...
                                           
    app.mixpanel.configuration = .init(token: "YOUR_MIXPANEL_TOKEN")
    
    // ...
}

用法

记录事件

await application.mixpanel.track(distinctId: "<user id>", name: "my_event", params: ["$user_id": profile.id, "a": 123])
await request.mixpanel.track(distinctId: "<user id>", name: "my_event", params: ["$user_id": profile.id, "a": 123])

// enhances the metadata (user agent, country, ...) by parsing the headers and ip from the request
await request.mixpanel.track(distinctId: "<user id>", name: "my_event", request: request, params: ["$user_id": profile.id, "a": 123])

识别用户

await application.mixpanel.peopleSet(distinctId: "<user id>", request: request, setParams: ["$email": "john@example.com", "num_cats": 5])

删除用户

await application.mixpanel.peopleDelete(distinctId: "<user id>")

可以在此处找到用于为 Mixpanel 身份分配名称、电子邮件和其他属性的 Mixpanel 属性列表。

目前,我只实现了满足我需求的基本功能集。 随着我对此包的需求增加,我将扩展此包,但非常欢迎贡献。