mixpanel-swift icon indicating copy to clipboard operation
mixpanel-swift copied to clipboard

Feature request: Ability to pass in URLSession to Mixpanel

Open RamblinWreck77 opened this issue 2 years ago • 0 comments

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

RamblinWreck77 avatar Nov 20 '23 20:11 RamblinWreck77