MixpanelVapor

1.0.0

Mixpanel SDK intended for server-side Swift apps using Vapor
petrpavlik/MixpanelVapor

What's New

1.0.0

2024-05-05T09:00:42Z

This release breaks pretty much all of the APIs, so I decided to ship it as a new major version, which is 1.0 in this case.

Changes

  • Removed auth based on service accounts, use a mixpanel token the same way you'd do in a client code.
  • Event logging now uses /track endpoint instead of /import endpoint
  • Updated event tracking API to explicitly ask for distinctId, which identifies a user. Pass nil or an empty string to log events that are not tied to any user profile.
  • Added APIs to add and delete a user profile tied to your analytics events.

TODO:

  • API calls such as to set a user property once is not implemented, feel free to contribute, or I'll add them when I need them for something.

MixpanelVapor

MixpanelVapor is a library for tracking events to Mixpanel from your Vapor server-side Swift applications.

Initialization

Mixpanel recommends using a service account and their /import endpoint for server-side apps so that's what this package uses. It allows to add things like batch import of events at a large scale in the future.

import MixpanelVapor

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

Usage

Log an event

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])

Identify a user

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

Delete a user

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

A list of mixpanel properties to assign a name, email, and other properties to a mixpanel identity can be found here.

I'm only implemented very basic feature set that fits my needs at this point. Will extend this package as I have the need for it, but contributions are very welcome.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Wed Nov 20 2024 22:31:48 GMT-1000 (Hawaii-Aleutian Standard Time)