Skip to content

Feature request: Ability to pass in URLSession to Mixpanel #619

Open

Description

Generally speaking the fewer URLSession's the better, and some apps need to go beyond URLSession.shared to access advanced configuration that benefits their use case.

Currently, inside Network.swift tasks are queued up on URLSession.shared.dataTask { }

While this makes perfect sense as the default, it would be nice to be able to optionally provide your app's custom URLSession on mixpanel init and reuse that.

Perhaps something like:

    @discardableResult
    open class func initialize(token apiToken: String,
                               trackAutomaticEvents: Bool,
                               flushInterval: Double = 60,
                               instanceName: String? = nil,
                               optOutTrackingByDefault: Bool = false,
                               useUniqueDistinctId: Bool = false,
                               superProperties: Properties? = nil,
                               urlSession: URLSession = URLSession.shared,                  // By not passing in, .shared is used
                               serverURL: String? = nil) -> MixpanelInstance {
        return MixpanelManager.sharedInstance.initialize(token: apiToken,
                                                         flushInterval: flushInterval,
                                                         instanceName: ((instanceName != nil) ? instanceName! : apiToken),
                                                         trackAutomaticEvents: trackAutomaticEvents,
                                                         optOutTrackingByDefault: optOutTrackingByDefault,
                                                         useUniqueDistinctId: useUniqueDistinctId,
                                                         superProperties: superProperties,
                                                         serverURL: serverURL)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions