Skip to content

Does Mixpanel Work with SwiftUI Widgets? #629

Open

Description

I wanted to track some things in my Widget built in SwiftUI. I apologize if this has already been answered, I did not find the answer online. Thanks in advance!

A basic example below...

struct MyWidget: Widget {
    
    init() {
        Mixpanel.initialize(token: Secrets.MixPanel, trackAutomaticEvents: true)
    }

    var body: some WidgetConfiguration {
        StaticConfiguration(
            kind: MyWidget.kind,
            provider: TimelineProvider()
        ) { entry in
            WidgetView(entry: entry)
        }
        .configurationDisplayName("My Widget")
        .description("")
        .supportedFamilies([.systemMedium])
        .contentMarginsDisabled()
    }

My view would be

struct WidgetView: View {
     var body: some View {
           VStack {
            }
            .onAppear {
                  // Log a Mixpanel Event inside Widget Target
            }

     } 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions